/// <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.DrawMarginLocation; 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); uw -= (float)GroupPadding; puw -= (float)GroupPadding; 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.AddGeometryToPaintTask(visual); } if (Stroke != null) { Stroke.AddGeometryToPaintTask(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(animation => animation .WithDuration(AnimationsSpeed ?? chart.AnimationsSpeed) .WithEasingFunction(EasingFunction ?? chart.EasingFunction)); l.CompleteAllTransitions(); label = l; point.Context.Label = l; } DataLabelsDrawableTask.AddGeometryToPaintTask(label); 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); } }
/// <inheritdoc cref="ChartElement{TDrawingContext}.Measure(Chart{TDrawingContext})"/> public override void Measure(Chart <TDrawingContext> chart) { var cartesianChart = (CartesianChart <TDrawingContext>)chart; var primaryAxis = cartesianChart.YAxes[ScalesYAt]; var secondaryAxis = cartesianChart.XAxes[ScalesXAt]; var drawLocation = cartesianChart.DrawMarginLocation; var drawMarginSize = cartesianChart.DrawMarginSize; var secondaryScale = new Scaler(drawLocation, drawMarginSize, secondaryAxis); var primaryScale = new Scaler(drawLocation, drawMarginSize, primaryAxis); var previousPrimaryScale = primaryAxis.PreviousDataBounds is null ? null : new Scaler(drawLocation, drawMarginSize, primaryAxis, true); var previousSecondaryScale = secondaryAxis.PreviousDataBounds is null ? null : new Scaler(drawLocation, drawMarginSize, secondaryAxis, true); var helper = new MeasureHelper(secondaryScale, cartesianChart, this, secondaryAxis, primaryScale.ToPixels(pivot)); var pHelper = previousSecondaryScale == null || previousPrimaryScale == null ? null : new MeasureHelper( previousSecondaryScale, cartesianChart, this, secondaryAxis, previousPrimaryScale.ToPixels(pivot)); var actualZIndex = ZIndex == 0 ? ((ISeries)this).SeriesId : ZIndex; if (Fill is not null) { Fill.ZIndex = actualZIndex + 0.1; Fill.SetClipRectangle(cartesianChart.Canvas, new LvcRectangle(drawLocation, drawMarginSize)); cartesianChart.Canvas.AddDrawableTask(Fill); } if (Stroke is not null) { Stroke.ZIndex = actualZIndex + 0.2; Stroke.SetClipRectangle(cartesianChart.Canvas, new LvcRectangle(drawLocation, drawMarginSize)); cartesianChart.Canvas.AddDrawableTask(Stroke); } if (DataLabelsPaint is not null) { DataLabelsPaint.ZIndex = actualZIndex + 0.3; //DataLabelsPaint.SetClipRectangle(cartesianChart.Canvas, new LvcRectangle(drawLocation, drawMarginSize)); cartesianChart.Canvas.AddDrawableTask(DataLabelsPaint); } var dls = (float)DataLabelsSize; var toDeletePoints = new HashSet <ChartPoint>(everFetched); var rx = (float)Rx; var ry = (float)Ry; foreach (var point in Fetch(cartesianChart)) { var visual = point.Context.Visual as TVisual; var primary = primaryScale.ToPixels(point.PrimaryValue); var secondary = secondaryScale.ToPixels(point.SecondaryValue); var b = Math.Abs(primary - helper.p); if (point.IsNull) { if (visual is not null) { visual.X = secondary - helper.uwm + helper.cp; visual.Y = helper.p; visual.Width = helper.uw; visual.Height = 0; visual.RemoveOnCompleted = true; point.Context.Visual = null; } continue; } if (visual is null) { var xi = secondary - helper.uwm + helper.cp; var pi = helper.p; var uwi = helper.uw; var hi = 0f; if (previousSecondaryScale is not null && previousPrimaryScale is not null && pHelper is not null) { var previousPrimary = previousPrimaryScale.ToPixels(point.PrimaryValue); var bp = Math.Abs(previousPrimary - pHelper.p); var cyp = point.PrimaryValue > pivot ? previousPrimary : previousPrimary - bp; xi = previousSecondaryScale.ToPixels(point.SecondaryValue) - pHelper.uwm + pHelper.cp; pi = cartesianChart.IsZoomingOrPanning ? cyp : pHelper.p; uwi = pHelper.uw; hi = cartesianChart.IsZoomingOrPanning ? bp : 0; } var r = new TVisual { X = xi, Y = pi, Width = uwi, Height = hi }; if (_isRounded) { var rounded = (IRoundedRectangleChartPoint <TDrawingContext>)r; rounded.Rx = rx; rounded.Ry = ry; } visual = r; point.Context.Visual = visual; OnPointCreated(point); _ = everFetched.Add(point); } if (Fill is not null) { Fill.AddGeometryToPaintTask(cartesianChart.Canvas, visual); } if (Stroke is not null) { Stroke.AddGeometryToPaintTask(cartesianChart.Canvas, visual); } var cy = point.PrimaryValue > pivot ? primary : primary - b; var x = secondary - helper.uwm + helper.cp; visual.X = x; visual.Y = cy; visual.Width = helper.uw; visual.Height = b; if (_isRounded) { var rounded = (IRoundedRectangleChartPoint <TDrawingContext>)visual; rounded.Rx = rx; rounded.Ry = ry; } visual.RemoveOnCompleted = false; var ha = new RectangleHoverArea().SetDimensions(secondary - helper.uwm + helper.cp, cy, helper.uw, b); point.Context.HoverArea = ha; _ = toDeletePoints.Remove(point); if (DataLabelsPaint is not null) { var label = (TLabel?)point.Context.Label; if (label is null) { var l = new TLabel { X = secondary - helper.uwm + helper.cp, Y = helper.p, RotateTransform = (float)DataLabelsRotation }; _ = l.TransitionateProperties(nameof(l.X), nameof(l.Y)) .WithAnimation(animation => animation .WithDuration(AnimationsSpeed ?? cartesianChart.AnimationsSpeed) .WithEasingFunction(EasingFunction ?? cartesianChart.EasingFunction)); l.CompleteAllTransitions(); label = l; point.Context.Label = l; } DataLabelsPaint.AddGeometryToPaintTask(cartesianChart.Canvas, label); label.Text = DataLabelsFormatter(new TypedChartPoint <TModel, TVisual, TLabel, TDrawingContext>(point)); label.TextSize = dls; label.Padding = DataLabelsPadding; var labelPosition = GetLabelPosition( x, cy, helper.uw, b, label.Measure(DataLabelsPaint), DataLabelsPosition, SeriesProperties, point.PrimaryValue > Pivot, drawLocation, drawMarginSize); label.X = labelPosition.X; label.Y = labelPosition.Y; } OnPointMeasured(point); } foreach (var point in toDeletePoints) { if (point.Context.Chart != cartesianChart.View) { continue; } SoftDeleteOrDisposePoint(point, primaryScale, secondaryScale); _ = everFetched.Remove(point); } }
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, secondaryAxis.Orientation, secondaryAxis.DataBounds); var primaryScale = new ScaleContext(drawLocation, drawMarginSize, primaryAxis.Orientation, primaryAxis.DataBounds); float uw = secondaryScale.ScaleToUi(1f) - secondaryScale.ScaleToUi(0f); float uwm = 0.5f * uw; float sw = Stroke?.StrokeWidth ?? 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 > MaxBarWidth) { uw = unchecked ((float)MaxBarWidth); 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; 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 = secondary - uwm + cp; point.Context.Visual.Y = p; point.Context.Visual.Width = uw; point.Context.Visual.Height = 0; point.Context.Visual.RemoveOnCompleted = true; point.Context.Visual = null; } continue; } if (point.Context.Visual == null) { var r = new TVisual { X = secondary - uwm + cp, Y = p, Width = uw, Height = 0 }; 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 cy = point.PrimaryValue > Pivot ? primary : primary - b; var x = secondary - uwm + cp; sizedGeometry.X = x; sizedGeometry.Y = cy; sizedGeometry.Width = uw; sizedGeometry.Height = b; sizedGeometry.RemoveOnCompleted = false; var ha = new RectangleHoverArea().SetDimensions(secondary - uwm + cp, cy, uw, b); point.Context.HoverArea = ha; 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( x, cy, uw, b, 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); } } }
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.Orientation, secondaryAxis.DataBounds, secondaryAxis.IsInverted); var primaryScale = new Scaler( drawLocation, drawMarginSize, primaryAxis.Orientation, primaryAxis.DataBounds, primaryAxis.IsInverted); var previousSecondaryScale = secondaryAxis.PreviousDataBounds == null ? null : new Scaler( drawLocation, drawMarginSize, secondaryAxis.Orientation, secondaryAxis.PreviousDataBounds, secondaryAxis.IsInverted); var previousPrimaryScale = primaryAxis.PreviousDataBounds == null ? null : new Scaler( drawLocation, drawMarginSize, secondaryAxis.Orientation, primaryAxis.PreviousDataBounds, secondaryAxis.IsInverted); float uw = secondaryScale.ToPixels(1f) - secondaryScale.ToPixels(0f); float uwm = 0.5f * uw; float sw = Stroke?.StrokeThickness ?? 0; float p = primaryScale.ToPixels(pivot); var pos = chart.SeriesContext.GetColumnPostion(this); var count = chart.SeriesContext.GetColumnSeriesCount(); float cp = 0f; if (!IgnoresBarPosition && count > 1) { uw /= count; uwm = 0.5f * uw; cp = (pos - count / 2f) * uw + uwm; } if (uw > MaxBarWidth) { uw = unchecked ((float)MaxBarWidth); uwm = uw / 2f; } var actualZIndex = ZIndex == 0 ? ((ISeries)this).SeriesId : ZIndex; if (Fill != null) { Fill.ZIndex = actualZIndex + 0.1; chart.Canvas.AddDrawableTask(Fill); } if (Stroke != null) { Stroke.ZIndex = actualZIndex + 0.2; chart.Canvas.AddDrawableTask(Stroke); } if (DataLabelsDrawableTask != null) { DataLabelsDrawableTask.ZIndex = actualZIndex + 0.3; chart.Canvas.AddDrawableTask(DataLabelsDrawableTask); } var dls = unchecked ((float)DataLabelsSize); var chartAnimation = new Animation(chart.EasingFunction, chart.AnimationsSpeed); var toDeletePoints = new HashSet <ChartPoint>(everFetched); 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; if (previousPrimaryScale != null && previousSecondaryScale != null) { xi = previousSecondaryScale.ToPixels(point.SecondaryValue) - uwm + cp; } var r = new TVisual { X = xi, Y = p, Width = uw, Height = 0 }; visual = r; point.Context.Visual = visual; OnPointCreated(point); r.CompleteAllTransitions(); if (Fill != null) { Fill.AddGeometyToPaintTask(r); } if (Stroke != null) { Stroke.AddGeometyToPaintTask(r); } everFetched.Add(point); } 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.RemoveOnCompleted = false; var ha = new RectangleHoverArea().SetDimensions(secondary - uwm + cp, cy, uw, b); point.Context.HoverArea = ha; OnPointMeasured(point); toDeletePoints.Remove(point); chart.MeasuredDrawables.Add(visual); 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 = DataLabelFormatter(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; chart.MeasuredDrawables.Add(label); } } foreach (var point in toDeletePoints) { if (point.Context.Chart != chart.View) { continue; } SoftDeletePoint(point, primaryScale, secondaryScale); } }