Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        private void ProcessLabel(ChartAnnotationLabelUpdateContext context)
        {
            context.Definition = this.LabelDefinition;

            if (context.Definition == null)
            {
                context.Definition = this.CreateDefaultLabelDefinition();
            }

            this.ProcessLabelDefinition(context);
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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));
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
        private void ArrangeLabel(FrameworkElement visual, ChartAnnotationLabelUpdateContext context)
        {
            RadSize size = MeasureVisual(visual);

            this.ArrangeUIElement(visual, this.GetLabelSlot(size, context));
        }
Ejemplo n.º 8
0
        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);
        }
Ejemplo n.º 9
0
        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);
        }
Ejemplo n.º 10
0
        internal override void UpdatePresenters()
        {
            ChartAnnotationLabelUpdateContext labelContext = new ChartAnnotationLabelUpdateContext(this.Model.originalLayoutSlot);

            this.ProcessLabel(labelContext);
        }