From 648f43b862f889bc817e4c319119839ca4b37b08 Mon Sep 17 00:00:00 2001 From: Mark Monteiro Date: Mon, 26 Jul 2021 10:33:14 -0400 Subject: [PATCH] Use a virtual method for measuring each paint task in DrawMarginFrame This refactoring makes it easier for sub-classes to implement custom rendering logic --- src/LiveChartsCore/DrawMarginFrame.cs | 59 +++++++++++++++++---------- 1 file changed, 37 insertions(+), 22 deletions(-) diff --git a/src/LiveChartsCore/DrawMarginFrame.cs b/src/LiveChartsCore/DrawMarginFrame.cs index 16e89e575..b410c68db 100644 --- a/src/LiveChartsCore/DrawMarginFrame.cs +++ b/src/LiveChartsCore/DrawMarginFrame.cs @@ -114,38 +114,53 @@ public abstract class DrawMarginFrame : DrawMar /// The chart. public override void Measure(Chart chart) { - var drawLocation = chart.DrawMarginLocation; - var drawMarginSize = chart.DrawMarginSize; - if (Fill is not null) { - Fill.ZIndex = -3; - - _fillSizedGeometry ??= new TSizedGeometry(); - - _fillSizedGeometry.X = drawLocation.X; - _fillSizedGeometry.Y = drawLocation.Y; - _fillSizedGeometry.Width = drawMarginSize.Width; - _fillSizedGeometry.Height = drawMarginSize.Height; - - Fill.AddGeometryToPaintTask(chart.Canvas, _fillSizedGeometry); + MeasureFill(chart); chart.Canvas.AddDrawableTask(Fill); } if (Stroke is not null) { - Stroke.ZIndex = -2; + MeasureStroke(chart); + chart.Canvas.AddDrawableTask(Stroke); + } + } - _strokeSizedGeometry ??= new TSizedGeometry(); + /// + /// Measures the of the draw margin for the specified chart. + /// + /// The chart. + protected virtual void MeasureFill(Chart chart) + { + Fill!.ZIndex = -3; - _strokeSizedGeometry.X = drawLocation.X; - _strokeSizedGeometry.Y = drawLocation.Y; - _strokeSizedGeometry.Width = drawMarginSize.Width; - _strokeSizedGeometry.Height = drawMarginSize.Height; + _fillSizedGeometry ??= new TSizedGeometry(); - Stroke.AddGeometryToPaintTask(chart.Canvas, _strokeSizedGeometry); - chart.Canvas.AddDrawableTask(Stroke); - } + _fillSizedGeometry.X = chart.DrawMarginLocation.X; + _fillSizedGeometry.Y = chart.DrawMarginLocation.Y; + _fillSizedGeometry.Width = chart.DrawMarginSize.Width; + _fillSizedGeometry.Height = chart.DrawMarginSize.Height; + + Fill.AddGeometryToPaintTask(chart.Canvas, _fillSizedGeometry); + } + + /// + /// Measures the of the draw margin for the specified chart. + /// + /// The chart. + protected virtual void MeasureStroke(Chart chart) + { + Stroke!.ZIndex = -2; + + _strokeSizedGeometry ??= new TSizedGeometry(); + + _strokeSizedGeometry.X = chart.DrawMarginLocation.X; + _strokeSizedGeometry.Y = chart.DrawMarginLocation.Y; + _strokeSizedGeometry.Width = chart.DrawMarginSize.Width; + _strokeSizedGeometry.Height = chart.DrawMarginSize.Height; + + Stroke.AddGeometryToPaintTask(chart.Canvas, _strokeSizedGeometry); } } }