Example #1
0
        /// <inheritdoc cref="IPieSeries{TDrawingContext}.Measure(PieChart{TDrawingContext})"/>
        public void Measure(PieChart <TDrawingContext> chart)
        {
            var drawLocation   = chart.DrawMaringLocation;
            var drawMarginSize = chart.DrawMarginSize;
            var minDimension   = drawMarginSize.Width < drawMarginSize.Height ? drawMarginSize.Width : drawMarginSize.Height;

            var maxPushout     = (float)chart.PushoutBounds.Max;
            var pushout        = (float)Pushout;
            var innerRadius    = (float)InnerRadius;
            var maxOuterRadius = (float)MaxOuterRadius;

            minDimension  = minDimension - (Stroke?.StrokeThickness ?? 0) * 2 - maxPushout * 2;
            minDimension *= maxOuterRadius;

            var actualZIndex = ZIndex == 0 ? ((ISeries)this).SeriesId : ZIndex;

            if (Fill != null)
            {
                Fill.ZIndex        = actualZIndex + 0.1;
                Fill.ClipRectangle = new RectangleF(drawLocation, drawMarginSize);
                chart.Canvas.AddDrawableTask(Fill);
            }
            if (Stroke != null)
            {
                Stroke.ZIndex        = actualZIndex + 0.2;
                Stroke.ClipRectangle = new RectangleF(drawLocation, drawMarginSize);
                chart.Canvas.AddDrawableTask(Stroke);
            }
            if (DataLabelsDrawableTask != null)
            {
                DataLabelsDrawableTask.ZIndex        = actualZIndex + 0.3;
                DataLabelsDrawableTask.ClipRectangle = new RectangleF(drawLocation, drawMarginSize);
                chart.Canvas.AddDrawableTask(DataLabelsDrawableTask);
            }

            var cx = drawLocation.X + drawMarginSize.Width * 0.5f;
            var cy = drawLocation.Y + drawMarginSize.Height * 0.5f;

            var stacker = chart.SeriesContext.GetStackPosition(this, GetStackGroup());

            if (stacker == null)
            {
                throw new NullReferenceException("Unexpected null stacker");
            }

            var toDeletePoints = new HashSet <ChartPoint>(everFetched);

            foreach (var point in Fetch(chart))
            {
                var visual = point.Context.Visual as TVisual;

                if (point.IsNull)
                {
                    if (visual != null)
                    {
                        visual.CenterX           = drawLocation.X + drawMarginSize.Width * 0.5f;
                        visual.CenterY           = drawLocation.Y + drawMarginSize.Height * 0.5f;
                        visual.X                 = cx;
                        visual.Y                 = cy;
                        visual.Width             = 0;
                        visual.Height            = 0;
                        visual.SweepAngle        = 0;
                        visual.StartAngle        = 0;
                        visual.PushOut           = 0;
                        visual.InnerRadius       = 0;
                        visual.RemoveOnCompleted = true;
                        point.Context.Visual     = null;
                    }
                    continue;
                }

                var stack        = stacker.GetStack(point);
                var stackedValue = stack.Start;
                var total        = stack.Total;
                var start        = stackedValue / total * 360;
                var end          = (stackedValue + point.PrimaryValue) / total * 360 - start;

                if (visual == null)
                {
                    var p = new TVisual
                    {
                        CenterX     = drawLocation.X + drawMarginSize.Width * 0.5f,
                        CenterY     = drawLocation.Y + drawMarginSize.Height * 0.5f,
                        X           = cx,
                        Y           = cy,
                        Width       = 0,
                        Height      = 0,
                        StartAngle  = 0,
                        SweepAngle  = 0,
                        PushOut     = 0,
                        InnerRadius = 0
                    };

                    visual = p;
                    point.Context.Visual = visual;
                    OnPointCreated(point);
                    p.CompleteAllTransitions();

                    _ = everFetched.Add(point);
                }

                if (Fill != null)
                {
                    Fill.AddGeometyToPaintTask(visual);
                }
                if (Stroke != null)
                {
                    Stroke.AddGeometyToPaintTask(visual);
                }

                var dougnutGeometry = visual;

                dougnutGeometry.PushOut           = pushout;
                dougnutGeometry.CenterX           = drawLocation.X + drawMarginSize.Width * 0.5f;
                dougnutGeometry.CenterY           = drawLocation.Y + drawMarginSize.Height * 0.5f;
                dougnutGeometry.X                 = (drawMarginSize.Width - minDimension) * 0.5f;
                dougnutGeometry.Y                 = (drawMarginSize.Height - minDimension) * 0.5f;
                dougnutGeometry.Width             = minDimension;
                dougnutGeometry.Height            = minDimension;
                dougnutGeometry.InnerRadius       = innerRadius;
                dougnutGeometry.PushOut           = pushout;
                dougnutGeometry.RemoveOnCompleted = false;
                dougnutGeometry.StartAngle        = start;
                dougnutGeometry.SweepAngle        = end;
                if (start == 0 && end == 360)
                {
                    dougnutGeometry.SweepAngle = 359.9999f;
                }

                point.Context.HoverArea = new SemicircleHoverArea().SetDimensions(cx, cy, start, start + end, minDimension * 0.5f);

                OnPointMeasured(point);
                _ = toDeletePoints.Remove(point);
            }

            var u = new Scaler();

            foreach (var point in toDeletePoints)
            {
                if (point.Context.Chart != chart.View)
                {
                    continue;
                }
                SoftDeletePoint(point, u, u);
                _ = everFetched.Remove(point);
            }
        }
Example #2
0
        public override void Measure(
            CartesianChart <TDrawingContext> chart, IAxis <TDrawingContext> secondaryAxis, IAxis <TDrawingContext> primaryAxis)
        {
            var drawLocation   = chart.DrawMaringLocation;
            var drawMarginSize = chart.DrawMarginSize;
            var secondaryScale = new ScaleContext(drawLocation, drawMarginSize, primaryAxis.Orientation, primaryAxis.DataBounds);
            var primaryScale   = new ScaleContext(drawLocation, drawMarginSize, secondaryAxis.Orientation, secondaryAxis.DataBounds);

            float uw  = secondaryScale.ScaleToUi(1f) - secondaryScale.ScaleToUi(0f);
            float uwm = 0.5f * uw;
            float sw  = Stroke?.StrokeWidth ?? 0;
            float p   = primaryScale.ScaleToUi(pivot);

            var   pos   = chart.SeriesContext.GetStackedColumnPostion(this);
            var   count = chart.SeriesContext.GetStackedColumnSeriesCount();
            float cp    = 0f;

            if (count > 1)
            {
                uw  = uw / count;
                uwm = 0.5f * uw;
                cp  = (pos - (count / 2f)) * uw + uwm;
            }

            if (uw > MaxColumnWidth)
            {
                uw  = unchecked ((float)MaxColumnWidth);
                uwm = uw / 2f;
            }

            if (Fill != null)
            {
                chart.Canvas.AddDrawableTask(Fill);
            }
            if (Stroke != null)
            {
                chart.Canvas.AddDrawableTask(Stroke);
            }
            if (DataLabelsBrush != null)
            {
                chart.Canvas.AddDrawableTask(DataLabelsBrush);
            }
            var dls = unchecked ((float)DataLabelsSize);

            var chartAnimation = new Animation(chart.EasingFunction, chart.AnimationsSpeed);
            var ts             = OnPointCreated ?? DefaultOnPointCreated;

            var stacker = chart.SeriesContext.GetStackPosition(this, GetStackGroup());

            if (stacker == null)
            {
                throw new NullReferenceException("Unexpected null stacker");
            }

            foreach (var point in Fetch(chart))
            {
                var secondary = secondaryScale.ScaleToUi(point.SecondaryValue);

                if (point.IsNull)
                {
                    if (point.Context.Visual != null)
                    {
                        point.Context.Visual.X                 = p;
                        point.Context.Visual.Y                 = secondary - uwm + cp;
                        point.Context.Visual.Width             = 0;
                        point.Context.Visual.Height            = uw;
                        point.Context.Visual.RemoveOnCompleted = true;
                        point.Context.Visual = null;
                    }
                    continue;
                }

                if (point.Context.Visual == null)
                {
                    var r = new TVisual
                    {
                        X      = p,
                        Y      = secondary - uwm + cp,
                        Width  = 0,
                        Height = uw
                    };

                    ts(r, chart.View);
                    r.CompleteAllTransitions();

                    point.Context.Visual = r;
                    if (Fill != null)
                    {
                        Fill.AddGeometyToPaintTask(r);
                    }
                    if (Stroke != null)
                    {
                        Stroke.AddGeometyToPaintTask(r);
                    }
                }

                var sizedGeometry = point.Context.Visual;

                var sy       = stacker.GetStack(point);
                var primaryI = primaryScale.ScaleToUi(sy.Start);
                var primaryJ = primaryScale.ScaleToUi(sy.End);
                var y        = secondary - uwm + cp;

                sizedGeometry.X                 = primaryJ;
                sizedGeometry.Y                 = y;
                sizedGeometry.Width             = primaryI - primaryJ;
                sizedGeometry.Height            = uw;
                sizedGeometry.RemoveOnCompleted = false;

                point.Context.HoverArea = new RectangleHoverArea().SetDimensions(secondary - uwm + cp, primaryJ, uw, primaryI - primaryJ);
                OnPointMeasured(point, sizedGeometry);
                chart.MeasuredDrawables.Add(sizedGeometry);

                if (DataLabelsBrush != null)
                {
                    if (point.Context.Label == null)
                    {
                        var l = new TLabel {
                            X = secondary - uwm + cp, Y = p
                        };

                        l.TransitionateProperties(nameof(l.X), nameof(l.Y))
                        .WithAnimation(a =>
                                       a.WithDuration(chart.AnimationsSpeed)
                                       .WithEasingFunction(chart.EasingFunction));

                        l.CompleteAllTransitions();
                        point.Context.Label = l;
                        DataLabelsBrush.AddGeometyToPaintTask(l);
                    }

                    point.Context.Label.Text     = DataLabelFormatter(point);
                    point.Context.Label.TextSize = dls;
                    point.Context.Label.Padding  = DataLabelsPadding;
                    var labelPosition = GetLabelPosition(
                        primaryJ, y, primaryI - primaryJ, uw, point.Context.Label.Measure(DataLabelsBrush), DataLabelsPosition, SeriesProperties, point.PrimaryValue > Pivot);
                    point.Context.Label.X = labelPosition.X;
                    point.Context.Label.Y = labelPosition.Y;

                    chart.MeasuredDrawables.Add(point.Context.Label);
                }
            }
        }
Example #3
0
        /// <summary>
        /// Measures this series.
        /// </summary>
        /// <param name="chart">The chart.</param>
        /// <param name="secondaryAxis">The secondary axis.</param>
        /// <param name="primaryAxis">The primary axis.</param>
        /// <exception cref="NullReferenceException">Unexpected null stacker</exception>
        public override void Measure(
            CartesianChart <TDrawingContext> chart, IAxis <TDrawingContext> secondaryAxis, IAxis <TDrawingContext> primaryAxis)
        {
            var drawLocation           = chart.DrawMaringLocation;
            var drawMarginSize         = chart.DrawMarginSize;
            var secondaryScale         = new Scaler(drawLocation, drawMarginSize, secondaryAxis);
            var primaryScale           = new Scaler(drawLocation, drawMarginSize, primaryAxis);
            var previousSecondaryScale =
                secondaryAxis.PreviousDataBounds == null ? null : new Scaler(drawLocation, drawMarginSize, secondaryAxis);

            var uw  = secondaryScale.ToPixels(1f) - secondaryScale.ToPixels(0f);
            var uwm = 0.5f * uw;
            var sw  = Stroke?.StrokeThickness ?? 0;
            var p   = primaryScale.ToPixels(pivot);

            var pos   = chart.SeriesContext.GetStackedColumnPostion(this);
            var count = chart.SeriesContext.GetStackedColumnSeriesCount();
            var cp    = 0f;

            if (count > 1)
            {
                uw /= count;
                uwm = 0.5f * uw;
                cp  = (pos - count / 2f) * uw + uwm;
            }

            if (uw > MaxBarWidth)
            {
                uw  = (float)MaxBarWidth;
                uwm = uw / 2f;
            }

            var actualZIndex = ZIndex == 0 ? ((ISeries)this).SeriesId : ZIndex;

            if (Fill != null)
            {
                Fill.ZIndex        = actualZIndex + 0.1;
                Fill.ClipRectangle = new RectangleF(drawLocation, drawMarginSize);
                chart.Canvas.AddDrawableTask(Fill);
            }
            if (Stroke != null)
            {
                Stroke.ZIndex        = actualZIndex + 0.2;
                Stroke.ClipRectangle = new RectangleF(drawLocation, drawMarginSize);
                chart.Canvas.AddDrawableTask(Stroke);
            }
            if (DataLabelsDrawableTask != null)
            {
                DataLabelsDrawableTask.ZIndex        = actualZIndex + 0.3;
                DataLabelsDrawableTask.ClipRectangle = new RectangleF(drawLocation, drawMarginSize);
                chart.Canvas.AddDrawableTask(DataLabelsDrawableTask);
            }

            var dls            = (float)DataLabelsSize;
            var toDeletePoints = new HashSet <ChartPoint>(everFetched);

            var stacker = chart.SeriesContext.GetStackPosition(this, GetStackGroup());

            if (stacker == null)
            {
                throw new NullReferenceException("Unexpected null stacker");
            }

            var rx = (float)Rx;
            var ry = (float)Ry;

            foreach (var point in Fetch(chart))
            {
                var visual    = point.Context.Visual as TVisual;
                var secondary = secondaryScale.ToPixels(point.SecondaryValue);

                if (point.IsNull)
                {
                    if (visual != null)
                    {
                        visual.X                 = secondary - uwm + cp;
                        visual.Y                 = p;
                        visual.Width             = uw;
                        visual.Height            = 0;
                        visual.RemoveOnCompleted = true;
                        point.Context.Visual     = null;
                    }
                    continue;
                }

                if (visual == null)
                {
                    var xi = secondary - uwm + cp;
                    if (previousSecondaryScale != null)
                    {
                        xi = previousSecondaryScale.ToPixels(point.SecondaryValue) - uwm + cp;
                    }

                    var r = new TVisual
                    {
                        X      = xi,
                        Y      = p,
                        Width  = uw,
                        Height = 0,
                        Rx     = rx,
                        Ry     = ry
                    };

                    visual = r;
                    point.Context.Visual = visual;
                    OnPointCreated(point);
                    r.CompleteAllTransitions();

                    _ = everFetched.Add(point);
                }

                if (Fill != null)
                {
                    Fill.AddGeometyToPaintTask(visual);
                }
                if (Stroke != null)
                {
                    Stroke.AddGeometyToPaintTask(visual);
                }

                var sizedGeometry = visual;

                var sy       = stacker.GetStack(point);
                var primaryI = primaryScale.ToPixels(sy.Start);
                var primaryJ = primaryScale.ToPixels(sy.End);
                var x        = secondary - uwm + cp;

                sizedGeometry.X                 = x;
                sizedGeometry.Y                 = primaryJ;
                sizedGeometry.Width             = uw;
                sizedGeometry.Height            = primaryI - primaryJ;
                sizedGeometry.Rx                = rx;
                sizedGeometry.Ry                = ry;
                sizedGeometry.RemoveOnCompleted = false;

                point.Context.HoverArea = new RectangleHoverArea().SetDimensions(secondary - uwm + cp, primaryJ, uw, primaryI - primaryJ);

                OnPointMeasured(point);
                _ = toDeletePoints.Remove(point);

                if (DataLabelsDrawableTask != null)
                {
                    if (point.Context.Label is not TLabel label)
                    {
                        var l = new TLabel {
                            X = secondary - uwm + cp, Y = p
                        };

                        _ = l.TransitionateProperties(nameof(l.X), nameof(l.Y))
                            .WithAnimation(a =>
                                           a.WithDuration(chart.AnimationsSpeed)
                                           .WithEasingFunction(chart.EasingFunction));

                        l.CompleteAllTransitions();
                        label = l;
                        point.Context.Label = label;
                        DataLabelsDrawableTask.AddGeometyToPaintTask(l);
                    }

                    label.Text     = DataLabelsFormatter(point);
                    label.TextSize = dls;
                    label.Padding  = DataLabelsPadding;
                    var labelPosition = GetLabelPosition(
                        x, primaryJ, uw, primaryI - primaryJ, label.Measure(DataLabelsDrawableTask), DataLabelsPosition,
                        SeriesProperties, point.PrimaryValue > Pivot);
                    label.X = labelPosition.X;
                    label.Y = labelPosition.Y;
                }
            }

            foreach (var point in toDeletePoints)
            {
                if (point.Context.Chart != chart.View)
                {
                    continue;
                }
                SoftDeletePoint(point, primaryScale, secondaryScale);
                _ = everFetched.Remove(point);
            }
        }
Example #4
0
        /// <inheritdoc cref="ICartesianSeries{TDrawingContext}.Measure(CartesianChart{TDrawingContext}, IAxis{TDrawingContext}, IAxis{TDrawingContext})"/>
        public override void Measure(
            CartesianChart <TDrawingContext> chart, IAxis <TDrawingContext> secondaryAxis, IAxis <TDrawingContext> primaryAxis)
        {
            var drawLocation         = chart.DrawMaringLocation;
            var drawMarginSize       = chart.DrawMarginSize;
            var secondaryScale       = new Scaler(drawLocation, drawMarginSize, secondaryAxis);
            var primaryScale         = new Scaler(drawLocation, drawMarginSize, primaryAxis);
            var previousPrimaryScale =
                primaryAxis.PreviousDataBounds == null ? null : new Scaler(drawLocation, drawMarginSize, primaryAxis, true);
            var previousSecondaryScale =
                secondaryAxis.PreviousDataBounds == null ? null : new Scaler(drawLocation, drawMarginSize, secondaryAxis, true);

            var uw  = secondaryScale.ToPixels((float)secondaryAxis.UnitWidth) - secondaryScale.ToPixels(0f);
            var puw = previousSecondaryScale == null ? 0 : previousSecondaryScale.ToPixels((float)secondaryAxis.UnitWidth) - previousSecondaryScale.ToPixels(0f);
            var uwm = 0.5f * uw;

            var pos   = chart.SeriesContext.GetColumnPostion(this);
            var count = chart.SeriesContext.GetColumnSeriesCount();
            var cp    = 0f;

            if (!IgnoresBarPosition && count > 1)
            {
                uw  /= count;
                puw /= count;
                uwm  = 0.5f * uw;
                cp   = (pos - count / 2f) * uw + uwm;
            }

            if (uw > MaxBarWidth)
            {
                uw  = (float)MaxBarWidth;
                uwm = uw * 0.5f;
                puw = uw;
            }

            var sw = Stroke?.StrokeThickness ?? 0;
            var p  = primaryScale.ToPixels(pivot);

            var actualZIndex = ZIndex == 0 ? ((ISeries)this).SeriesId : ZIndex;

            if (Fill != null)
            {
                Fill.ZIndex        = actualZIndex + 0.1;
                Fill.ClipRectangle = new RectangleF(drawLocation, drawMarginSize);
                chart.Canvas.AddDrawableTask(Fill);
            }
            if (Stroke != null)
            {
                Stroke.ZIndex        = actualZIndex + 0.2;
                Stroke.ClipRectangle = new RectangleF(drawLocation, drawMarginSize);
                chart.Canvas.AddDrawableTask(Stroke);
            }
            if (DataLabelsDrawableTask != null)
            {
                DataLabelsDrawableTask.ZIndex        = actualZIndex + 0.3;
                DataLabelsDrawableTask.ClipRectangle = new RectangleF(drawLocation, drawMarginSize);
                chart.Canvas.AddDrawableTask(DataLabelsDrawableTask);
            }

            var dls            = (float)DataLabelsSize;
            var toDeletePoints = new HashSet <ChartPoint>(everFetched);

            var rx = (float)Rx;
            var ry = (float)Ry;

            foreach (var point in Fetch(chart))
            {
                var visual    = point.Context.Visual as TVisual;
                var primary   = primaryScale.ToPixels(point.PrimaryValue);
                var secondary = secondaryScale.ToPixels(point.SecondaryValue);
                var b         = Math.Abs(primary - p);

                if (point.IsNull)
                {
                    if (visual != null)
                    {
                        visual.X                 = secondary - uwm + cp;
                        visual.Y                 = p;
                        visual.Width             = uw;
                        visual.Height            = 0;
                        visual.RemoveOnCompleted = true;
                        point.Context.Visual     = null;
                    }
                    continue;
                }

                if (visual == null)
                {
                    var xi  = secondary - uwm + cp;
                    var pi  = p;
                    var uwi = uw;
                    var hi  = 0f;

                    if (previousSecondaryScale != null && previousPrimaryScale != null)
                    {
                        var previousP       = previousPrimaryScale.ToPixels(pivot);
                        var previousPrimary = previousPrimaryScale.ToPixels(point.PrimaryValue);
                        var bp  = Math.Abs(previousPrimary - previousP);
                        var cyp = point.PrimaryValue > pivot ? previousPrimary : previousPrimary - bp;

                        xi  = previousSecondaryScale.ToPixels(point.SecondaryValue) - uwm + cp;
                        pi  = chart.IsZoomingOrPanning ? cyp : previousP;
                        uwi = puw;
                        hi  = chart.IsZoomingOrPanning ? bp : 0;
                    }

                    var r = new TVisual
                    {
                        X      = xi,
                        Y      = pi,
                        Width  = uwi,
                        Height = 0,
                        Rx     = rx,
                        Ry     = ry
                    };

                    visual = r;
                    point.Context.Visual = visual;
                    OnPointCreated(point);
                    r.CompleteAllTransitions();

                    _ = everFetched.Add(point);
                }

                if (Fill != null)
                {
                    Fill.AddGeometyToPaintTask(visual);
                }
                if (Stroke != null)
                {
                    Stroke.AddGeometyToPaintTask(visual);
                }

                var cy = point.PrimaryValue > pivot ? primary : primary - b;
                var x  = secondary - uwm + cp;

                visual.X                 = x;
                visual.Y                 = cy;
                visual.Width             = uw;
                visual.Height            = b;
                visual.Rx                = rx;
                visual.Ry                = ry;
                visual.RemoveOnCompleted = false;

                var ha = new RectangleHoverArea().SetDimensions(secondary - uwm + cp, cy, uw, b);
                point.Context.HoverArea = ha;

                OnPointMeasured(point);
                _ = toDeletePoints.Remove(point);

                if (DataLabelsDrawableTask != null)
                {
                    var label = (TLabel?)point.Context.Label;

                    if (label == null)
                    {
                        var l = new TLabel {
                            X = secondary - uwm + cp, Y = p
                        };

                        _ = l.TransitionateProperties(nameof(l.X), nameof(l.Y))
                            .WithAnimation(a =>
                                           a.WithDuration(chart.AnimationsSpeed)
                                           .WithEasingFunction(chart.EasingFunction));

                        l.CompleteAllTransitions();
                        label = l;
                        point.Context.Label = l;
                        DataLabelsDrawableTask.AddGeometyToPaintTask(l);
                    }

                    label.Text     = DataLabelsFormatter(point);
                    label.TextSize = dls;
                    label.Padding  = DataLabelsPadding;
                    var labelPosition = GetLabelPosition(
                        x, cy, uw, b, label.Measure(DataLabelsDrawableTask), DataLabelsPosition, SeriesProperties, point.PrimaryValue > Pivot);
                    label.X = labelPosition.X;
                    label.Y = labelPosition.Y;
                }
            }

            foreach (var point in toDeletePoints)
            {
                if (point.Context.Chart != chart.View)
                {
                    continue;
                }
                SoftDeletePoint(point, primaryScale, secondaryScale);
                _ = everFetched.Remove(point);
            }
        }
Example #5
0
        public override void Measure(
            CartesianChart <TDrawingContext> chart, IAxis <TDrawingContext> xAxis, IAxis <TDrawingContext> yAxis)
        {
            var drawLocation   = chart.DrawMaringLocation;
            var drawMarginSize = chart.DrawMarginSize;
            var xScale         = new ScaleContext(drawLocation, drawMarginSize, xAxis.Orientation, xAxis.DataBounds);
            var yScale         = new ScaleContext(drawLocation, drawMarginSize, yAxis.Orientation, yAxis.DataBounds);

            float uw  = xScale.ScaleToUi(1f) - xScale.ScaleToUi(0f);
            float uwm = 0.5f * uw;
            float sw  = Stroke?.StrokeWidth ?? 0;
            float p   = yScale.ScaleToUi(unchecked ((float)Pivot));

            var   pos   = chart.SeriesContext.GetColumnPostion(this);
            var   count = chart.SeriesContext.GetColumnSeriesCount();
            float cp    = 0f;

            if (!IgnoresColumnPosition && count > 1)
            {
                uw  = uw / count;
                uwm = 0.5f * uw;
                cp  = (pos - (count / 2f)) * uw + uwm;
            }

            if (uw > MaxColumnWidth)
            {
                uw  = unchecked ((float)MaxColumnWidth);
                uwm = uw / 2f;
            }

            if (Fill != null)
            {
                chart.Canvas.AddDrawableTask(Fill);
            }
            if (Stroke != null)
            {
                chart.Canvas.AddDrawableTask(Stroke);
            }

            var chartAnimation = new Animation(chart.EasingFunction, chart.AnimationsSpeed);
            var ts             = TransitionsSetter ?? SetDefaultTransitions;

            foreach (var point in Fetch(chart))
            {
                var   x = xScale.ScaleToUi(point.SecondaryValue);
                var   y = yScale.ScaleToUi(point.PrimaryValue);
                float b = Math.Abs(y - p);

                if (point.PointContext.Visual == null)
                {
                    var r = new TVisual
                    {
                        X      = x - uwm + cp,
                        Y      = p,
                        Width  = uw,
                        Height = 0
                    };

                    ts(r, chartAnimation);

                    point.PointContext.Visual = r;
                    if (Fill != null)
                    {
                        Fill.AddGeometyToPaintTask(r);
                    }
                    if (Stroke != null)
                    {
                        Stroke.AddGeometyToPaintTask(r);
                    }
                }

                var sizedGeometry = point.PointContext.Visual;

                var cy = point.PrimaryValue > Pivot ? y : y - b;

                sizedGeometry.X      = x - uwm + cp;
                sizedGeometry.Y      = cy;
                sizedGeometry.Width  = uw;
                sizedGeometry.Height = b;

                point.PointContext.HoverArea = new RectangleHoverArea().SetDimensions(x - uwm + cp, cy, uw, b);
                OnPointMeasured(point, sizedGeometry);
                chart.MeasuredDrawables.Add(sizedGeometry);
            }

            if (HighlightFill != null)
            {
                chart.Canvas.AddDrawableTask(HighlightFill);
            }
            if (HighlightStroke != null)
            {
                chart.Canvas.AddDrawableTask(HighlightStroke);
            }
        }
Example #6
0
        public void Measure(PieChart <TDrawingContext> chart)
        {
            var drawLocation   = chart.DrawMaringLocation;
            var drawMarginSize = chart.DrawMarginSize;
            var minDimension   = drawMarginSize.Width < drawMarginSize.Height ? drawMarginSize.Width : drawMarginSize.Height;

            var maxPushout     = (float)chart.PushoutBounds.Max;
            var pushout        = (float)PushOut;
            var innerRadius    = (float)InnerRadius;
            var maxOuterRadius = (float)MaxOuterRadius;

            minDimension  = minDimension - (Stroke?.StrokeWidth ?? 0) * 2 - maxPushout * 2;
            minDimension *= maxOuterRadius;

            if (Fill != null)
            {
                chart.Canvas.AddDrawableTask(Fill);
            }
            if (Stroke != null)
            {
                chart.Canvas.AddDrawableTask(Stroke);
            }

            var chartAnimation = new Animation(chart.EasingFunction, chart.AnimationsSpeed);
            var ts             = TransitionsSetter ?? SetDefaultTransitions;

            var cx = drawLocation.X + drawMarginSize.Width * 0.5f;
            var cy = drawLocation.Y + drawMarginSize.Height * 0.5f;

            var stacker = chart.SeriesContext.GetStackPosition(this, GetStackGroup());

            if (stacker == null)
            {
                throw new NullReferenceException("Unexpected null stacker");
            }

            foreach (var point in Fetch(chart))
            {
                if (point.PointContext.Visual == null)
                {
                    var p = new TVisual
                    {
                        CenterX     = drawLocation.X + drawMarginSize.Width * 0.5f,
                        CenterY     = drawLocation.Y + drawMarginSize.Height * 0.5f,
                        X           = cx,
                        Y           = cy,
                        Width       = 0,
                        Height      = 0,
                        SweepAngle  = 0,
                        StartAngle  = 0,
                        PushOut     = 0,
                        InnerRadius = 0
                    };

                    ts(p, chartAnimation);
                    p.CompleteTransitions(
                        nameof(p.CenterX), nameof(p.CenterY),
                        nameof(p.X), nameof(p.Y),
                        nameof(p.Width), nameof(p.Height),
                        nameof(p.StartAngle), nameof(p.SweepAngle),
                        nameof(p.PushOut), nameof(p.InnerRadius));

                    point.PointContext.Visual = p;
                    if (Fill != null)
                    {
                        Fill.AddGeometyToPaintTask(p);
                    }
                    if (Stroke != null)
                    {
                        Stroke.AddGeometyToPaintTask(p);
                    }
                }

                var dougnutGeometry = point.PointContext.Visual;

                var stack        = stacker.GetStack(point);
                var stackedValue = stack.Start;
                var total        = stack.Total;

                dougnutGeometry.PushOut     = pushout;
                dougnutGeometry.CenterX     = drawLocation.X + drawMarginSize.Width * 0.5f;
                dougnutGeometry.CenterY     = drawLocation.Y + drawMarginSize.Height * 0.5f;
                dougnutGeometry.X           = (drawMarginSize.Width - minDimension) * 0.5f;
                dougnutGeometry.Y           = (drawMarginSize.Height - minDimension) * 0.5f;
                dougnutGeometry.Width       = minDimension;
                dougnutGeometry.Height      = minDimension;
                dougnutGeometry.InnerRadius = innerRadius;
                dougnutGeometry.PushOut     = pushout;
                var start = (stackedValue / total) * 360;
                var end   = ((stackedValue + point.PrimaryValue) / total) * 360 - start;
                dougnutGeometry.StartAngle = start;
                dougnutGeometry.SweepAngle = end;
                if (start == 0 && end == 360)
                {
                    dougnutGeometry.SweepAngle = 359.9999f;
                }

                point.PointContext.HoverArea = new SemicircleHoverArea().SetDimensions(cx, cy, start, start + end, minDimension * 0.5f);
                OnPointMeasured(point, dougnutGeometry);
                chart.MeasuredDrawables.Add(dougnutGeometry);

                stackedValue += point.PrimaryValue;
            }

            if (HighlightFill != null)
            {
                chart.Canvas.AddDrawableTask(HighlightFill);
            }
            if (HighlightStroke != null)
            {
                chart.Canvas.AddDrawableTask(HighlightStroke);
            }
        }
Example #7
0
        public override void Measure(
            IChartView <TDrawingContext> view,
            IAxis <TDrawingContext> xAxis,
            IAxis <TDrawingContext> yAxis,
            SeriesContext <TDrawingContext> context,
            HashSet <IDrawable <TDrawingContext> > drawBucket)
        {
            var drawLocation   = view.Core.DrawMaringLocation;
            var drawMarginSize = view.Core.DrawMarginSize;
            var xScale         = new ScaleContext(drawLocation, drawMarginSize, xAxis.Orientation, xAxis.DataBounds);
            var yScale         = new ScaleContext(drawLocation, drawMarginSize, yAxis.Orientation, yAxis.DataBounds);

            float uw  = xScale.ScaleToUi(1f) - xScale.ScaleToUi(0f);
            float uwm = 0.5f * uw;
            float sw  = Stroke?.StrokeWidth ?? 0;
            float p   = yScale.ScaleToUi(unchecked ((float)Pivot));

            var   pos   = context.GetColumnPostion(this);
            var   count = context.GetColumnSeriesCount();
            float cp    = 0f;

            if (!IgnoresColumnPosition && count > 1)
            {
                uw  = uw / count;
                uwm = 0.5f * uw;
                cp  = (pos - (count / 2f)) * uw + uwm;
            }

            if (uw > MaxColumnWidth)
            {
                uw  = unchecked ((float)MaxColumnWidth);
                uwm = uw / 2f;
            }

            if (Fill != null)
            {
                view.CoreCanvas.AddPaintTask(Fill);
            }
            if (Stroke != null)
            {
                view.CoreCanvas.AddPaintTask(Stroke);
            }

            var chartAnimation = new Animation(view.EasingFunction, view.AnimationsSpeed);
            var ts             = TransitionsSetter ?? SetDefaultTransitions;

            foreach (var point in GetPonts())
            {
                var   x = xScale.ScaleToUi(point.X);
                var   y = yScale.ScaleToUi(point.Y);
                float b = Math.Abs(y - p);

                if (point.Visual == null)
                {
                    var r = new TVisual
                    {
                        X      = x - uwm + cp,
                        Y      = p,
                        Width  = uw,
                        Height = 0
                    };

                    ts(r, chartAnimation);

                    point.HoverArea = new HoverArea();
                    point.Visual    = r;
                    if (Fill != null)
                    {
                        Fill.AddGeometyToPaintTask(r);
                    }
                    if (Stroke != null)
                    {
                        Stroke.AddGeometyToPaintTask(r);
                    }
                }

                var sizedGeometry = (TVisual)point.Visual;

                var cy = point.Y > Pivot ? y : y - b;

                sizedGeometry.X      = x - uwm + cp;
                sizedGeometry.Y      = cy;
                sizedGeometry.Width  = uw;
                sizedGeometry.Height = b;

                point.HoverArea.SetDimensions(x - uwm + cp, cy, uw, b);
                OnPointMeasured(point, sizedGeometry);
                drawBucket.Add(sizedGeometry);
            }

            if (HighlightFill != null)
            {
                view.CoreCanvas.AddPaintTask(HighlightFill);
            }
            if (HighlightStroke != null)
            {
                view.CoreCanvas.AddPaintTask(HighlightStroke);
            }
        }
Example #8
0
        /// <inheritdoc cref="IPieSeries{TDrawingContext}.Measure(PieChart{TDrawingContext})"/>
        public void Measure(PieChart <TDrawingContext> chart)
        {
            var drawLocation   = chart.DrawMaringLocation;
            var drawMarginSize = chart.DrawMarginSize;
            var minDimension   = drawMarginSize.Width < drawMarginSize.Height ? drawMarginSize.Width : drawMarginSize.Height;

            var maxPushout     = (float)chart.PushoutBounds.Max;
            var pushout        = (float)Pushout;
            var innerRadius    = (float)InnerRadius;
            var maxOuterRadius = (float)MaxOuterRadius;

            minDimension  = minDimension - (Stroke?.StrokeThickness ?? 0) * 2 - maxPushout * 2;
            minDimension *= maxOuterRadius;

            if (Fill != null)
            {
                chart.Canvas.AddDrawableTask(Fill);
            }
            if (Stroke != null)
            {
                chart.Canvas.AddDrawableTask(Stroke);
            }

            var cx = drawLocation.X + drawMarginSize.Width * 0.5f;
            var cy = drawLocation.Y + drawMarginSize.Height * 0.5f;

            var stacker = chart.SeriesContext.GetStackPosition(this, GetStackGroup());

            if (stacker == null)
            {
                throw new NullReferenceException("Unexpected null stacker");
            }

            foreach (var point in Fetch(chart))
            {
                if (point.IsNull)
                {
                    if (point.Context.Visual != null)
                    {
                        point.Context.Visual.CenterX           = drawLocation.X + drawMarginSize.Width * 0.5f;
                        point.Context.Visual.CenterY           = drawLocation.Y + drawMarginSize.Height * 0.5f;
                        point.Context.Visual.X                 = cx;
                        point.Context.Visual.Y                 = cy;
                        point.Context.Visual.Width             = 0;
                        point.Context.Visual.Height            = 0;
                        point.Context.Visual.SweepAngle        = 0;
                        point.Context.Visual.StartAngle        = 0;
                        point.Context.Visual.PushOut           = 0;
                        point.Context.Visual.InnerRadius       = 0;
                        point.Context.Visual.RemoveOnCompleted = true;
                        point.Context.Visual = null;
                    }
                    continue;
                }

                if (point.Context.Visual == null)
                {
                    var p = new TVisual
                    {
                        CenterX     = drawLocation.X + drawMarginSize.Width * 0.5f,
                        CenterY     = drawLocation.Y + drawMarginSize.Height * 0.5f,
                        X           = cx,
                        Y           = cy,
                        Width       = 0,
                        Height      = 0,
                        SweepAngle  = 0,
                        StartAngle  = 0,
                        PushOut     = 0,
                        InnerRadius = 0
                    };

                    point.Context.Visual = p;
                    OnPointCreated(point);
                    p.CompleteAllTransitions();

                    if (Fill != null)
                    {
                        Fill.AddGeometyToPaintTask(p);
                    }
                    if (Stroke != null)
                    {
                        Stroke.AddGeometyToPaintTask(p);
                    }
                }

                var dougnutGeometry = point.Context.Visual;

                var stack        = stacker.GetStack(point);
                var stackedValue = stack.Start;
                var total        = stack.Total;

                dougnutGeometry.PushOut           = pushout;
                dougnutGeometry.CenterX           = drawLocation.X + drawMarginSize.Width * 0.5f;
                dougnutGeometry.CenterY           = drawLocation.Y + drawMarginSize.Height * 0.5f;
                dougnutGeometry.X                 = (drawMarginSize.Width - minDimension) * 0.5f;
                dougnutGeometry.Y                 = (drawMarginSize.Height - minDimension) * 0.5f;
                dougnutGeometry.Width             = minDimension;
                dougnutGeometry.Height            = minDimension;
                dougnutGeometry.InnerRadius       = innerRadius;
                dougnutGeometry.PushOut           = pushout;
                dougnutGeometry.RemoveOnCompleted = false;
                var start = stackedValue / total * 360;
                var end   = (stackedValue + point.PrimaryValue) / total * 360 - start;
                dougnutGeometry.StartAngle = start;
                dougnutGeometry.SweepAngle = end;
                if (start == 0 && end == 360)
                {
                    dougnutGeometry.SweepAngle = 359.9999f;
                }

                point.Context.HoverArea = new SemicircleHoverArea().SetDimensions(cx, cy, start, start + end, minDimension * 0.5f);

                OnPointMeasured(point);
                chart.MeasuredDrawables.Add(dougnutGeometry);
            }
        }
Example #9
0
        public override void Measure(
            CartesianChart <TDrawingContext> chart, IAxis <TDrawingContext> secondaryAxis, IAxis <TDrawingContext> primaryAxis)
        {
            var drawLocation   = chart.DrawMaringLocation;
            var drawMarginSize = chart.DrawMarginSize;
            var secondaryScale = new ScaleContext(drawLocation, drawMarginSize, primaryAxis.Orientation, primaryAxis.DataBounds);
            var primaryScale   = new ScaleContext(drawLocation, drawMarginSize, secondaryAxis.Orientation, secondaryAxis.DataBounds);

            float uw  = secondaryScale.ScaleToUi(1f) - secondaryScale.ScaleToUi(0f);
            float uwm = 0.5f * uw;
            float sw  = Stroke?.StrokeThickness ?? 0;
            float p   = primaryScale.ScaleToUi(unchecked ((float)Pivot));

            var   pos   = chart.SeriesContext.GetColumnPostion(this);
            var   count = chart.SeriesContext.GetColumnSeriesCount();
            float cp    = 0f;

            if (!IgnoresBarPosition && count > 1)
            {
                uw  = uw / count;
                uwm = 0.5f * uw;
                cp  = (pos - count / 2f) * uw + uwm;
            }

            if (uw < -1 * MaxBarWidth)
            {
                uw  = unchecked ((float)MaxBarWidth * -1);
                uwm = uw / 2f;
            }

            if (Fill != null)
            {
                chart.Canvas.AddDrawableTask(Fill);
            }
            if (Stroke != null)
            {
                chart.Canvas.AddDrawableTask(Stroke);
            }
            if (DataLabelsDrawableTask != null)
            {
                chart.Canvas.AddDrawableTask(DataLabelsDrawableTask);
            }
            var dls = unchecked ((float)DataLabelsSize);

            foreach (var point in Fetch(chart))
            {
                var   primary   = primaryScale.ScaleToUi(point.PrimaryValue);
                var   secondary = secondaryScale.ScaleToUi(point.SecondaryValue);
                float b         = Math.Abs(primary - p);

                if (point.IsNull)
                {
                    if (point.Context.Visual != null)
                    {
                        point.Context.Visual.X                 = p;
                        point.Context.Visual.Y                 = secondary - uwm + cp;
                        point.Context.Visual.Width             = 0;
                        point.Context.Visual.Height            = uw;
                        point.Context.Visual.RemoveOnCompleted = true;
                    }
                    continue;
                }

                if (point.Context.Visual == null)
                {
                    var r = new TVisual
                    {
                        X      = p,
                        Y      = secondary - uwm + cp,
                        Width  = 0,
                        Height = uw
                    };

                    point.Context.Visual = r;
                    OnPointCreated(point);
                    r.CompleteAllTransitions();

                    if (Fill != null)
                    {
                        Fill.AddGeometyToPaintTask(r);
                    }
                    if (Stroke != null)
                    {
                        Stroke.AddGeometyToPaintTask(r);
                    }
                }

                var sizedGeometry = point.Context.Visual;

                var cx = point.PrimaryValue > Pivot ? primary - b : primary;
                var y  = secondary - uwm + cp;

                sizedGeometry.X      = cx;
                sizedGeometry.Y      = y;
                sizedGeometry.Width  = b;
                sizedGeometry.Height = uw;

                point.Context.HoverArea = new RectangleHoverArea().SetDimensions(primary, secondary - uwm + cp, b, uw);

                OnPointMeasured(point);
                chart.MeasuredDrawables.Add(sizedGeometry);

                if (DataLabelsDrawableTask != null)
                {
                    if (point.Context.Label == null)
                    {
                        var l = new TLabel {
                            X = p, Y = secondary - uwm + cp
                        };

                        l.TransitionateProperties(nameof(l.X), nameof(l.Y))
                        .WithAnimation(a =>
                                       a.WithDuration(chart.AnimationsSpeed)
                                       .WithEasingFunction(chart.EasingFunction));

                        l.CompleteAllTransitions();
                        point.Context.Label = l;
                        DataLabelsDrawableTask.AddGeometyToPaintTask(l);
                    }

                    point.Context.Label.Text     = DataLabelFormatter(point);
                    point.Context.Label.TextSize = dls;
                    point.Context.Label.Padding  = DataLabelsPadding;
                    var labelPosition = GetLabelPosition(
                        cx, y, b, uw, point.Context.Label.Measure(DataLabelsDrawableTask), DataLabelsPosition, SeriesProperties, point.PrimaryValue > Pivot);
                    point.Context.Label.X = labelPosition.X;
                    point.Context.Label.Y = labelPosition.Y;

                    chart.MeasuredDrawables.Add(point.Context.Label);
                }
            }
        }