private FrameworkElement GetLabelVisual(ChartAnnotationLabelUpdateContext context) { if (this.labelPresenter == null) { this.labelPresenter = this.CreateLabelVisual(context); } ContentPresenter presenter = this.labelPresenter as ContentPresenter; if (presenter != null) { presenter.Content = this.GetLabelContent(context); presenter.ContentTemplate = context.Definition.Template; } else { TextBlock textBlock = this.labelPresenter as TextBlock; if (textBlock != null) { object label = this.GetLabelContent(context); textBlock.Text = label == null ? string.Empty : label.ToString(); } } return(this.labelPresenter); }
private object GetLabelContent(ChartAnnotationLabelUpdateContext context) { object label = this.Label; if (label != null && !string.IsNullOrEmpty(context.Definition.Format)) { return(string.Format(CultureInfo.CurrentUICulture, context.Definition.Format, label)); } return(label); }
private void ProcessLabel(ChartAnnotationLabelUpdateContext context) { context.Definition = this.LabelDefinition; if (context.Definition == null) { context.Definition = this.CreateDefaultLabelDefinition(); } this.ProcessLabelDefinition(context); }
private void ProcessLabelDefinition(ChartAnnotationLabelUpdateContext context) { FrameworkElement visual = this.GetLabelVisual(context); if (visual == null) { Debug.Assert(false, "No label visual created."); return; } this.ArrangeLabel(visual, context); }
private RadRect GetLabelSlot(RadSize labelSize, ChartAnnotationLabelUpdateContext context) { double strokeThickness = this.StrokeThickness; double strokeCompensation = 0; if (!this.IsStrokeInset) { strokeCompensation = strokeThickness / 2; } double x = GetLabelSlotX(context, labelSize, strokeThickness, strokeCompensation); double y = GetLabelSlotY(context, labelSize, strokeThickness, strokeCompensation); return(new RadRect(x, y, labelSize.Width, labelSize.Height)); }
private FrameworkElement CreateLabelVisual(ChartAnnotationLabelUpdateContext context) { FrameworkElement visual; DataTemplate template = context.Definition.Template; if (template != null) { visual = new ContentPresenter(); } else { visual = new TextBlock() { Style = context.Definition.DefaultVisualStyle }; } this.renderSurface.Children.Add(visual); return(visual); }
private void ArrangeLabel(FrameworkElement visual, ChartAnnotationLabelUpdateContext context) { RadSize size = MeasureVisual(visual); this.ArrangeUIElement(visual, this.GetLabelSlot(size, context)); }
private static double GetLabelSlotY(ChartAnnotationLabelUpdateContext context, RadSize labelSize, double strokeThickness, double strokeCompensation) { ChartAnnotationLabelLocation location = context.Definition.Location; RadRect annotationSlot = context.LayoutSlot; VerticalAlignment verticalAlignment = context.Definition.VerticalAlignment; double verticalOffset = context.Definition.VerticalOffset; double y = context.Location.Y; switch (location) { case ChartAnnotationLabelLocation.Top: { y = annotationSlot.Y - strokeCompensation - labelSize.Height; break; } case ChartAnnotationLabelLocation.Bottom: { y = annotationSlot.Bottom + strokeCompensation; break; } case ChartAnnotationLabelLocation.Left: case ChartAnnotationLabelLocation.Right: { switch (verticalAlignment) { case VerticalAlignment.Top: y = annotationSlot.Y; break; case VerticalAlignment.Center: y = annotationSlot.Y + ((annotationSlot.Height - labelSize.Height) / 2); break; case VerticalAlignment.Bottom: y = annotationSlot.Bottom - labelSize.Height; break; } break; } case ChartAnnotationLabelLocation.Inside: { switch (verticalAlignment) { case VerticalAlignment.Top: y = annotationSlot.Y + strokeThickness; break; case VerticalAlignment.Center: y = annotationSlot.Y + ((annotationSlot.Height - labelSize.Height) / 2); break; case VerticalAlignment.Bottom: y = annotationSlot.Bottom - strokeThickness - labelSize.Height; break; } break; } } y += verticalOffset; return(y); }
private static double GetLabelSlotX(ChartAnnotationLabelUpdateContext context, RadSize labelSize, double strokeThickness, double strokeCompensation) { ChartAnnotationLabelLocation location = context.Definition.Location; RadRect annotationSlot = context.LayoutSlot; HorizontalAlignment horizontalAlignment = context.Definition.HorizontalAlignment; double horizontalOffset = context.Definition.HorizontalOffset; double x = context.Location.X; switch (location) { case ChartAnnotationLabelLocation.Left: { x = annotationSlot.X - strokeCompensation - labelSize.Width; break; } case ChartAnnotationLabelLocation.Right: { x = annotationSlot.Right + strokeCompensation; break; } case ChartAnnotationLabelLocation.Top: case ChartAnnotationLabelLocation.Bottom: { switch (horizontalAlignment) { case HorizontalAlignment.Left: x = annotationSlot.X; break; case HorizontalAlignment.Center: x = annotationSlot.X + ((annotationSlot.Width - labelSize.Width) / 2); break; case HorizontalAlignment.Right: x = annotationSlot.Right - labelSize.Width; break; } break; } case ChartAnnotationLabelLocation.Inside: { switch (horizontalAlignment) { case HorizontalAlignment.Left: x = annotationSlot.X + strokeThickness; break; case HorizontalAlignment.Center: x = annotationSlot.X + ((annotationSlot.Width - labelSize.Width) / 2); break; case HorizontalAlignment.Right: x = annotationSlot.Right - strokeThickness - labelSize.Width; break; } break; } } x += horizontalOffset; return(x); }
internal override void UpdatePresenters() { ChartAnnotationLabelUpdateContext labelContext = new ChartAnnotationLabelUpdateContext(this.Model.originalLayoutSlot); this.ProcessLabel(labelContext); }