From f7f670c3ed99e618ed57b02c45d7c14d456c349e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alberto=20Rodr=C3=ADguez?= Date: Sun, 14 Aug 2022 16:54:53 -0500 Subject: [PATCH 01/25] zoom by section core and wpf view --- samples/WPFSample/Lines/Zoom/View.xaml | 2 +- src/LiveChartsCore/CartesianChart.cs | 145 +++++++++++++++++- src/LiveChartsCore/Chart.cs | 7 +- src/LiveChartsCore/LiveChartsCore.csproj | 2 +- .../CartesianChart.cs | 30 +++- .../LiveChartsCore.SkiaSharp.WPF/PieChart.cs | 3 +- .../PolarChart.cs | 5 +- .../SKCharts/SKCartesianChart.cs | 2 +- 8 files changed, 177 insertions(+), 19 deletions(-) diff --git a/samples/WPFSample/Lines/Zoom/View.xaml b/samples/WPFSample/Lines/Zoom/View.xaml index 4e630dc94..ce7346c5f 100644 --- a/samples/WPFSample/Lines/Zoom/View.xaml +++ b/samples/WPFSample/Lines/Zoom/View.xaml @@ -18,7 +18,7 @@ Grid.Row="1" Series="{Binding SeriesCollection}" TooltipPosition="Hidden" - ZoomMode="X"> + ZoomMode="Y"> diff --git a/src/LiveChartsCore/CartesianChart.cs b/src/LiveChartsCore/CartesianChart.cs index ade1d99ea..84be4cbb3 100644 --- a/src/LiveChartsCore/CartesianChart.cs +++ b/src/LiveChartsCore/CartesianChart.cs @@ -44,6 +44,7 @@ public class CartesianChart : Chart internal readonly HashSet> _everMeasuredAxes = new(); internal readonly HashSet> _everMeasuredSections = new(); private readonly ICartesianChartView _chartView; + private readonly ISizedGeometry _zoomingSection; private int _nextSeries = 0; private double _zoomingSpeed = 0; private readonly bool _requiresLegendMeasureAlways = false; @@ -58,16 +59,23 @@ public class CartesianChart : Chart /// The view. /// The default platform configuration. /// The canvas. + /// The zooming section. /// Forces the legends to redraw with every measure request. public CartesianChart( ICartesianChartView view, Action defaultPlatformConfig, MotionCanvas canvas, + ISizedGeometry? zoomingSection, bool requiresLegendMeasureAlways = false) : base(canvas, defaultPlatformConfig, view) { _chartView = view; _requiresLegendMeasureAlways = requiresLegendMeasureAlways; + _zoomingSection = zoomingSection ?? throw new Exception($"{nameof(zoomingSection)} is required."); + _zoomingSection.X = -1; + _zoomingSection.Y = -1; + _zoomingSection.Width = 0; + _zoomingSection.Height = 0; } /// @@ -227,7 +235,7 @@ public void Zoom(LvcPoint pivot, ZoomDirection direction, double? scaleFactor = maxt = max + ld * 0.5 * dir; } - if (maxt - mint < xi.DataBounds.MinDelta * 5) return; + if (direction == ZoomDirection.ZoomIn && maxt - mint < xi.DataBounds.MinDelta * 3) return; var xm = (max - min) * (isActive ? MaxAxisActiveBound : MaxAxisBound); if (maxt > xi.DataBounds.Max && direction == ZoomDirection.ZoomOut) maxt = xi.DataBounds.Max + xm; @@ -281,7 +289,7 @@ public void Zoom(LvcPoint pivot, ZoomDirection direction, double? scaleFactor = maxt = max + ld * 0.5 * dir; } - if (maxt - mint < yi.DataBounds.MinDelta * 5) return; + if (direction == ZoomDirection.ZoomIn && maxt - mint < yi.DataBounds.MinDelta * 3) return; var ym = (max - min) * (isActive ? MaxAxisActiveBound : MaxAxisBound); if (maxt > yi.DataBounds.Max && direction == ZoomDirection.ZoomOut) maxt = yi.DataBounds.Max + ym; @@ -782,4 +790,137 @@ public override void Unload() IsFirstDraw = true; } + + private LvcPoint? _sectionZoomingStart = null; + + internal override void InvokePointerDown(LvcPoint point, bool isSecondaryAction) + { + if (isSecondaryAction) + { + _sectionZoomingStart = point; + + _zoomingSection.X = point.X; + _zoomingSection.Y = point.Y; + + var xMode = (_zoomMode & ZoomAndPanMode.X) == ZoomAndPanMode.X; + var yMode = (_zoomMode & ZoomAndPanMode.Y) == ZoomAndPanMode.Y; + + if (!xMode) + { + _zoomingSection.X = DrawMarginLocation.X; + _zoomingSection.Width = DrawMarginSize.Width; + } + + if (!yMode) + { + _zoomingSection.Y = DrawMarginLocation.Y; + _zoomingSection.Height = DrawMarginSize.Height; + } + + Update(); + return; + } + + base.InvokePointerDown(point, isSecondaryAction); + } + + internal override void InvokePointerMove(LvcPoint point) + { + if (_sectionZoomingStart is not null) + { + var xMode = (_zoomMode & ZoomAndPanMode.X) == ZoomAndPanMode.X; + var yMode = (_zoomMode & ZoomAndPanMode.Y) == ZoomAndPanMode.Y; + + if (xMode) _zoomingSection.Width = point.X - _sectionZoomingStart.Value.X; + if (yMode) _zoomingSection.Height = point.Y - _sectionZoomingStart.Value.Y; + + Update(); + return; + } + + base.InvokePointerMove(point); + } + + internal override void InvokePointerUp(LvcPoint point, bool isSecondaryAction) + { + if (_sectionZoomingStart is not null) + { + if ((_zoomMode & ZoomAndPanMode.X) == ZoomAndPanMode.X) + { + for (var i = 0; i < XAxes.Length; i++) + { + var x = XAxes[i]; + + var xi = ScaleUIPoint(_sectionZoomingStart.Value, i, 0)[0]; + var xj = ScaleUIPoint(point, i, 0)[0]; + + double xMax, xMin; + + if (xi > xj) + { + xMax = xi; + xMin = xj; + } + else + { + xMax = xj; + xMin = xi; + } + + if (xMax > (x.MaxLimit ?? double.MaxValue)) xMax = x.MaxLimit ?? double.MaxValue; + if (xMin < (x.MinLimit ?? double.MinValue)) xMin = x.MinLimit ?? double.MinValue; + + if (xMax - xMin > x.DataBounds.MinDelta * 3) + { + x.MinLimit = xMin; + x.MaxLimit = xMax; + } + } + } + + if ((_zoomMode & ZoomAndPanMode.Y) == ZoomAndPanMode.Y) + { + for (var i = 0; i < YAxes.Length; i++) + { + var y = YAxes[i]; + + var yi = ScaleUIPoint(_sectionZoomingStart.Value, 0, i)[1]; + var yj = ScaleUIPoint(point, 0, i)[1]; + + double yMax, yMin; + + if (yi > yj) + { + yMax = yi; + yMin = yj; + } + else + { + yMax = yj; + yMin = yi; + } + + if (yMax > (y.MaxLimit ?? double.MaxValue)) yMax = y.MaxLimit ?? double.MaxValue; + if (yMin < (y.MinLimit ?? double.MinValue)) yMin = y.MinLimit ?? double.MinValue; + + if (yMax - yMin > y.DataBounds.MinDelta * 3) + { + y.MinLimit = yMin; + y.MaxLimit = yMax; + } + } + } + + _zoomingSection.X = -1; + _zoomingSection.Y = -1; + _zoomingSection.Width = 0; + _zoomingSection.Height = 0; + Update(); + + _sectionZoomingStart = null; + return; + } + + base.InvokePointerUp(point, isSecondaryAction); + } } diff --git a/src/LiveChartsCore/Chart.cs b/src/LiveChartsCore/Chart.cs index 10535b300..a6059b9f6 100644 --- a/src/LiveChartsCore/Chart.cs +++ b/src/LiveChartsCore/Chart.cs @@ -343,8 +343,7 @@ internal void ClearTooltipData() Canvas.Invalidate(); } - - internal void InvokePointerDown(LvcPoint point) + internal virtual void InvokePointerDown(LvcPoint point, bool isSecondaryAction) { PointerDown?.Invoke(point); @@ -366,12 +365,12 @@ internal void InvokePointerDown(LvcPoint point) View.OnDataPointerDown(iterable, point); } - internal void InvokePointerMove(LvcPoint point) + internal virtual void InvokePointerMove(LvcPoint point) { PointerMove?.Invoke(point); } - internal void InvokePointerUp(LvcPoint point) + internal virtual void InvokePointerUp(LvcPoint point, bool isSecondaryAction) { PointerUp?.Invoke(point); } diff --git a/src/LiveChartsCore/LiveChartsCore.csproj b/src/LiveChartsCore/LiveChartsCore.csproj index f94373969..d8f3a73ba 100644 --- a/src/LiveChartsCore/LiveChartsCore.csproj +++ b/src/LiveChartsCore/LiveChartsCore.csproj @@ -17,7 +17,7 @@ LiveChartsCore LiveChartsCore - 2.0.0-beta.350 + 2.0.0-beta.351 icon.png Simple, flexible, interactive and powerful data visualization for .Net, this is the core package probably you need another package also unless you are building your own backed. MIT diff --git a/src/skiasharp/LiveChartsCore.SkiaSharp.WPF/CartesianChart.cs b/src/skiasharp/LiveChartsCore.SkiaSharp.WPF/CartesianChart.cs index 3e94c1c46..7481c0f0e 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharp.WPF/CartesianChart.cs +++ b/src/skiasharp/LiveChartsCore.SkiaSharp.WPF/CartesianChart.cs @@ -32,6 +32,8 @@ using LiveChartsCore.Kernel.Sketches; using LiveChartsCore.Measure; using LiveChartsCore.SkiaSharpView.Drawing; +using LiveChartsCore.SkiaSharpView.Drawing.Geometries; +using LiveChartsCore.SkiaSharpView.Painting; namespace LiveChartsCore.SkiaSharpView.WPF; @@ -40,10 +42,11 @@ public class CartesianChart : Chart, ICartesianChartView _seriesObserver; - private CollectionDeepObserver _xObserver; - private CollectionDeepObserver _yObserver; - private CollectionDeepObserver> _sectionsObserver; + private readonly CollectionDeepObserver _seriesObserver; + private readonly CollectionDeepObserver _xObserver; + private readonly CollectionDeepObserver _yObserver; + private readonly CollectionDeepObserver> _sectionsObserver; + private readonly RectangleGeometry _zoomingSection = new(); #endregion @@ -299,10 +302,23 @@ protected override void InitializeCore() { if (canvas is null) throw new Exception("canvas not found"); + var zoomingSection = new RectangleGeometry { Width = 100, Height = 1000 }; + var p = new SolidColorPaint + { + IsFill = true, + Color = new SkiaSharp.SKColor(33, 150, 243, 50), + ZIndex = int.MaxValue + }; + p.AddGeometryToPaintTask(canvas.CanvasCore, zoomingSection); + canvas.CanvasCore.AddDrawableTask(p); + core = new CartesianChart( - this, LiveChartsSkiaSharp.DefaultPlatformBuilder, canvas.CanvasCore); + this, LiveChartsSkiaSharp.DefaultPlatformBuilder, canvas.CanvasCore, zoomingSection); legend = Template.FindName("legend", this) as IChartLegend; tooltip = Template.FindName("tooltip", this) as IChartTooltip; + + + core.Update(); } @@ -328,13 +344,13 @@ private void OnMouseDown(object sender, System.Windows.Input.MouseButtonEventArg { _ = CaptureMouse(); var p = e.GetPosition(this); - core?.InvokePointerDown(new LvcPoint((float)p.X, (float)p.Y)); + core?.InvokePointerDown(new LvcPoint((float)p.X, (float)p.Y), e.ChangedButton == MouseButton.Right); } private void OnMouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e) { var p = e.GetPosition(this); - core?.InvokePointerUp(new LvcPoint((float)p.X, (float)p.Y)); + core?.InvokePointerUp(new LvcPoint((float)p.X, (float)p.Y), e.ChangedButton == MouseButton.Right); ReleaseMouseCapture(); } diff --git a/src/skiasharp/LiveChartsCore.SkiaSharp.WPF/PieChart.cs b/src/skiasharp/LiveChartsCore.SkiaSharp.WPF/PieChart.cs index 858a84981..2c7f65839 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharp.WPF/PieChart.cs +++ b/src/skiasharp/LiveChartsCore.SkiaSharp.WPF/PieChart.cs @@ -26,6 +26,7 @@ using System.Collections.Specialized; using System.ComponentModel; using System.Windows; +using System.Windows.Input; using LiveChartsCore.Drawing; using LiveChartsCore.Kernel; using LiveChartsCore.Kernel.Sketches; @@ -157,6 +158,6 @@ protected override void OnUnloaded() private void OnMouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e) { var p = e.GetPosition(this); - core?.InvokePointerDown(new LvcPoint((float)p.X, (float)p.Y)); + core?.InvokePointerDown(new LvcPoint((float)p.X, (float)p.Y), e.ChangedButton == MouseButton.Right); } } diff --git a/src/skiasharp/LiveChartsCore.SkiaSharp.WPF/PolarChart.cs b/src/skiasharp/LiveChartsCore.SkiaSharp.WPF/PolarChart.cs index 14e24f402..febdf2ac8 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharp.WPF/PolarChart.cs +++ b/src/skiasharp/LiveChartsCore.SkiaSharp.WPF/PolarChart.cs @@ -26,6 +26,7 @@ using System.Collections.Specialized; using System.ComponentModel; using System.Windows; +using System.Windows.Input; using LiveChartsCore.Drawing; using LiveChartsCore.Kernel; using LiveChartsCore.Kernel.Sketches; @@ -285,13 +286,13 @@ private void OnMouseDown(object sender, System.Windows.Input.MouseButtonEventArg { _ = CaptureMouse(); var p = e.GetPosition(this); - core?.InvokePointerDown(new LvcPoint((float)p.X, (float)p.Y)); + core?.InvokePointerDown(new LvcPoint((float)p.X, (float)p.Y), e.ChangedButton == MouseButton.Right); } private void OnMouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e) { var p = e.GetPosition(this); - core?.InvokePointerUp(new LvcPoint((float)p.X, (float)p.Y)); + core?.InvokePointerUp(new LvcPoint((float)p.X, (float)p.Y), e.ChangedButton == MouseButton.Right); ReleaseMouseCapture(); } } diff --git a/src/skiasharp/LiveChartsCore.SkiaSharp/SKCharts/SKCartesianChart.cs b/src/skiasharp/LiveChartsCore.SkiaSharp/SKCharts/SKCartesianChart.cs index d15e48dfa..f86e32c4a 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharp/SKCharts/SKCartesianChart.cs +++ b/src/skiasharp/LiveChartsCore.SkiaSharp/SKCharts/SKCartesianChart.cs @@ -55,7 +55,7 @@ public SKCartesianChart() initializer.ApplyStyleToChart(this); Core = new CartesianChart( - this, LiveChartsSkiaSharp.DefaultPlatformBuilder, CoreCanvas); + this, LiveChartsSkiaSharp.DefaultPlatformBuilder, CoreCanvas, null); Core.Measuring += OnCoreMeasuring; Core.UpdateStarted += OnCoreUpdateStarted; Core.UpdateFinished += OnCoreUpdateFinished; From e8e85be495267261f013bcd493aa7085a4d9c55f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alberto=20Rodr=C3=ADguez?= Date: Sun, 14 Aug 2022 16:55:21 -0500 Subject: [PATCH 02/25] restore sample zoom --- samples/WPFSample/Lines/Zoom/View.xaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/WPFSample/Lines/Zoom/View.xaml b/samples/WPFSample/Lines/Zoom/View.xaml index ce7346c5f..4e630dc94 100644 --- a/samples/WPFSample/Lines/Zoom/View.xaml +++ b/samples/WPFSample/Lines/Zoom/View.xaml @@ -18,7 +18,7 @@ Grid.Row="1" Series="{Binding SeriesCollection}" TooltipPosition="Hidden" - ZoomMode="Y"> + ZoomMode="X"> From b51890768b29b58e969afa197d1b07d2bfad2ede Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alberto=20Rodr=C3=ADguez?= Date: Sun, 14 Aug 2022 17:39:48 -0500 Subject: [PATCH 03/25] apply section zoom to all platforms --- .../CartesianChart.axaml.cs | 18 ++++++++-- .../PieChart.axaml.cs | 2 +- .../PolarChart.axaml.cs | 4 +-- .../CartesianChart.cs | 8 ++--- .../CartesianChart.cs | 18 ++++++++-- .../PieChart.cs | 2 +- .../PolarChart.cs | 4 +-- .../CartesianChart.xaml.cs | 16 +++++++-- .../PieChart.xaml.cs | 2 +- .../PolarChart.xaml.cs | 2 +- .../CartesianChart.razor.cs | 14 +++++++- .../Chart.razor.cs | 4 +-- .../CartesianChart.cs | 18 ++++++++-- .../PieChart.cs | 2 +- .../PolarChart.cs | 4 +-- .../CartesianChart.xaml.cs | 16 +++++++-- .../PieChart.xaml.cs | 2 +- .../PolarChart.xaml.cs | 2 +- .../CartesianChart.xaml.cs | 30 ++++++++++++++-- .../PieChart.xaml.cs | 2 +- .../PolarChart.xaml.cs | 4 +-- .../CartesianChart.xaml.cs | 34 +++++++++++++++++-- .../PieChart.xaml.cs | 2 +- .../PolarChart.xaml.cs | 4 +-- .../CartesianChart.xaml.cs | 32 +++++++++++++++-- .../PieChart.xaml.cs | 4 +-- .../PolarChart.xaml.cs | 4 +-- 27 files changed, 202 insertions(+), 52 deletions(-) diff --git a/src/skiasharp/LiveChartsCore.SkiaSharp.Avalonia/CartesianChart.axaml.cs b/src/skiasharp/LiveChartsCore.SkiaSharp.Avalonia/CartesianChart.axaml.cs index cf5ec08e3..937f8420c 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharp.Avalonia/CartesianChart.axaml.cs +++ b/src/skiasharp/LiveChartsCore.SkiaSharp.Avalonia/CartesianChart.axaml.cs @@ -42,6 +42,7 @@ using LiveChartsCore.Measure; using LiveChartsCore.Motion; using LiveChartsCore.SkiaSharpView.Drawing; +using LiveChartsCore.SkiaSharpView.Painting; namespace LiveChartsCore.SkiaSharpView.Avalonia; @@ -739,9 +740,20 @@ void IChartView.InvokeOnUIThread(Action action) protected void InitializeCore() { var canvas = this.FindControl("canvas"); + + var zoomingSection = new Drawing.Geometries.RectangleGeometry(); + var zoomingSectionPaint = new SolidColorPaint + { + IsFill = true, + Color = new SkiaSharp.SKColor(33, 150, 243, 50), + ZIndex = int.MaxValue + }; + zoomingSectionPaint.AddGeometryToPaintTask(canvas.CanvasCore, zoomingSection); + canvas.CanvasCore.AddDrawableTask(zoomingSectionPaint); + _avaloniaCanvas = canvas; _core = new CartesianChart( - this, LiveChartsSkiaSharp.DefaultPlatformBuilder, canvas.CanvasCore); + this, LiveChartsSkiaSharp.DefaultPlatformBuilder, canvas.CanvasCore, zoomingSection); _core.Measuring += OnCoreMeasuring; _core.UpdateStarted += OnCoreUpdateStarted; @@ -816,7 +828,7 @@ private void CartesianChart_PointerPressed(object? sender, PointerPressedEventAr if (Application.Current.ApplicationLifetime is not IClassicDesktopStyleApplicationLifetime desktop) return; var p = e.GetPosition(this); foreach (var w in desktop.Windows) w.PointerReleased += Window_PointerReleased; - _core?.InvokePointerDown(new LvcPoint((float)p.X, (float)p.Y)); + _core?.InvokePointerDown(new LvcPoint((float)p.X, (float)p.Y), e.GetCurrentPoint(this).Properties.IsRightButtonPressed); } private void CartesianChart_PointerMoved(object? sender, PointerEventArgs e) @@ -830,7 +842,7 @@ private void Window_PointerReleased(object? sender, PointerReleasedEventArgs e) if (Application.Current.ApplicationLifetime is not IClassicDesktopStyleApplicationLifetime desktop) return; foreach (var w in desktop.Windows) w.PointerReleased -= Window_PointerReleased; var p = e.GetPosition(this); - _core?.InvokePointerUp(new LvcPoint((float)p.X, (float)p.Y)); + _core?.InvokePointerUp(new LvcPoint((float)p.X, (float)p.Y), e.GetCurrentPoint(this).Properties.IsRightButtonPressed); } private void CartesianChart_PointerLeave(object? sender, PointerEventArgs e) diff --git a/src/skiasharp/LiveChartsCore.SkiaSharp.Avalonia/PieChart.axaml.cs b/src/skiasharp/LiveChartsCore.SkiaSharp.Avalonia/PieChart.axaml.cs index c833b42c2..26955ce9a 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharp.Avalonia/PieChart.axaml.cs +++ b/src/skiasharp/LiveChartsCore.SkiaSharp.Avalonia/PieChart.axaml.cs @@ -712,7 +712,7 @@ private void Chart_PointerMoved(object? sender, PointerEventArgs e) private void Chart_PointerPressed(object sender, PointerPressedEventArgs e) { var p = e.GetPosition(this); - _core?.InvokePointerDown(new LvcPoint((float)p.X, (float)p.Y)); + _core?.InvokePointerDown(new LvcPoint((float)p.X, (float)p.Y), false); } private void OnCoreUpdateFinished(IChartView chart) diff --git a/src/skiasharp/LiveChartsCore.SkiaSharp.Avalonia/PolarChart.axaml.cs b/src/skiasharp/LiveChartsCore.SkiaSharp.Avalonia/PolarChart.axaml.cs index 000252cea..bdf997ff7 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharp.Avalonia/PolarChart.axaml.cs +++ b/src/skiasharp/LiveChartsCore.SkiaSharp.Avalonia/PolarChart.axaml.cs @@ -797,7 +797,7 @@ private void PolarChart_PointerPressed(object? sender, PointerPressedEventArgs e if (Application.Current.ApplicationLifetime is not IClassicDesktopStyleApplicationLifetime desktop) return; var p = e.GetPosition(this); foreach (var w in desktop.Windows) w.PointerReleased += Window_PointerReleased; - _core?.InvokePointerDown(new LvcPoint((float)p.X, (float)p.Y)); + _core?.InvokePointerDown(new LvcPoint((float)p.X, (float)p.Y), false); } private void PolarChart_PointerMoved(object? sender, PointerEventArgs e) @@ -811,7 +811,7 @@ private void Window_PointerReleased(object? sender, PointerReleasedEventArgs e) if (Application.Current.ApplicationLifetime is not IClassicDesktopStyleApplicationLifetime desktop) return; foreach (var w in desktop.Windows) w.PointerReleased -= Window_PointerReleased; var p = e.GetPosition(this); - _core?.InvokePointerUp(new LvcPoint((float)p.X, (float)p.Y)); + _core?.InvokePointerUp(new LvcPoint((float)p.X, (float)p.Y), false); } private void OnCoreUpdateFinished(IChartView chart) diff --git a/src/skiasharp/LiveChartsCore.SkiaSharp.WPF/CartesianChart.cs b/src/skiasharp/LiveChartsCore.SkiaSharp.WPF/CartesianChart.cs index 7481c0f0e..0c439c1ef 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharp.WPF/CartesianChart.cs +++ b/src/skiasharp/LiveChartsCore.SkiaSharp.WPF/CartesianChart.cs @@ -302,15 +302,15 @@ protected override void InitializeCore() { if (canvas is null) throw new Exception("canvas not found"); - var zoomingSection = new RectangleGeometry { Width = 100, Height = 1000 }; - var p = new SolidColorPaint + var zoomingSection = new RectangleGeometry(); + var zoomingSectionPaint = new SolidColorPaint { IsFill = true, Color = new SkiaSharp.SKColor(33, 150, 243, 50), ZIndex = int.MaxValue }; - p.AddGeometryToPaintTask(canvas.CanvasCore, zoomingSection); - canvas.CanvasCore.AddDrawableTask(p); + zoomingSectionPaint.AddGeometryToPaintTask(canvas.CanvasCore, zoomingSection); + canvas.CanvasCore.AddDrawableTask(zoomingSectionPaint); core = new CartesianChart( this, LiveChartsSkiaSharp.DefaultPlatformBuilder, canvas.CanvasCore, zoomingSection); diff --git a/src/skiasharp/LiveChartsCore.SkiaSharp.WinForms/CartesianChart.cs b/src/skiasharp/LiveChartsCore.SkiaSharp.WinForms/CartesianChart.cs index a386f9409..ae2e93c7e 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharp.WinForms/CartesianChart.cs +++ b/src/skiasharp/LiveChartsCore.SkiaSharp.WinForms/CartesianChart.cs @@ -31,6 +31,8 @@ using LiveChartsCore.Kernel.Sketches; using LiveChartsCore.Measure; using LiveChartsCore.SkiaSharpView.Drawing; +using LiveChartsCore.SkiaSharpView.Drawing.Geometries; +using LiveChartsCore.SkiaSharpView.Painting; namespace LiveChartsCore.SkiaSharpView.WinForms; @@ -172,8 +174,18 @@ public DrawMarginFrame? DrawMarginFrame /// protected override void InitializeCore() { + var zoomingSection = new RectangleGeometry(); + var zoomingSectionPaint = new SolidColorPaint + { + IsFill = true, + Color = new SkiaSharp.SKColor(33, 150, 243, 50), + ZIndex = int.MaxValue + }; + zoomingSectionPaint.AddGeometryToPaintTask(motionCanvas.CanvasCore, zoomingSection); + motionCanvas.CanvasCore.AddDrawableTask(zoomingSectionPaint); + core = new CartesianChart( - this, LiveChartsSkiaSharp.DefaultPlatformBuilder, motionCanvas.CanvasCore, true); + this, LiveChartsSkiaSharp.DefaultPlatformBuilder, motionCanvas.CanvasCore, zoomingSection, true); if (((IChartView)this).DesignerMode) return; core.Update(); } @@ -209,11 +221,11 @@ private void OnMouseWheel(object? sender, MouseEventArgs e) private void OnMouseDown(object? sender, MouseEventArgs e) { - core?.InvokePointerDown(new LvcPoint(e.Location.X, e.Location.Y)); + core?.InvokePointerDown(new LvcPoint(e.Location.X, e.Location.Y), e.Button == MouseButtons.Right); } private void OnMouseUp(object? sender, MouseEventArgs e) { - core?.InvokePointerUp(new LvcPoint(e.Location.X, e.Location.Y)); + core?.InvokePointerUp(new LvcPoint(e.Location.X, e.Location.Y), e.Button == MouseButtons.Right); } } diff --git a/src/skiasharp/LiveChartsCore.SkiaSharp.WinForms/PieChart.cs b/src/skiasharp/LiveChartsCore.SkiaSharp.WinForms/PieChart.cs index 7e7d7fec5..64fea2698 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharp.WinForms/PieChart.cs +++ b/src/skiasharp/LiveChartsCore.SkiaSharp.WinForms/PieChart.cs @@ -110,6 +110,6 @@ protected override void InitializeCore() private void OnMouseDown(object? sender, MouseEventArgs e) { - core?.InvokePointerDown(new LvcPoint(e.Location.X, e.Location.Y)); + core?.InvokePointerDown(new LvcPoint(e.Location.X, e.Location.Y), false); } } diff --git a/src/skiasharp/LiveChartsCore.SkiaSharp.WinForms/PolarChart.cs b/src/skiasharp/LiveChartsCore.SkiaSharp.WinForms/PolarChart.cs index 251e751fc..1f683cfcf 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharp.WinForms/PolarChart.cs +++ b/src/skiasharp/LiveChartsCore.SkiaSharp.WinForms/PolarChart.cs @@ -217,11 +217,11 @@ private void OnMouseWheel(object? sender, MouseEventArgs e) private void OnMouseDown(object? sender, MouseEventArgs e) { - core?.InvokePointerDown(new LvcPoint(e.Location.X, e.Location.Y)); + core?.InvokePointerDown(new LvcPoint(e.Location.X, e.Location.Y), false); } private void OnMouseUp(object? sender, MouseEventArgs e) { - core?.InvokePointerUp(new LvcPoint(e.Location.X, e.Location.Y)); + core?.InvokePointerUp(new LvcPoint(e.Location.X, e.Location.Y), false); } } diff --git a/src/skiasharp/LiveChartsCore.SkiaSharp.Xamarin.Forms/CartesianChart.xaml.cs b/src/skiasharp/LiveChartsCore.SkiaSharp.Xamarin.Forms/CartesianChart.xaml.cs index 761ecd66f..cc53d8772 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharp.Xamarin.Forms/CartesianChart.xaml.cs +++ b/src/skiasharp/LiveChartsCore.SkiaSharp.Xamarin.Forms/CartesianChart.xaml.cs @@ -33,6 +33,8 @@ using LiveChartsCore.Measure; using LiveChartsCore.Motion; using LiveChartsCore.SkiaSharpView.Drawing; +using LiveChartsCore.SkiaSharpView.Drawing.Geometries; +using LiveChartsCore.SkiaSharpView.Painting; using LiveChartsCore.SkiaSharpView.XamarinForms; using SkiaSharp.Views.Forms; using Xamarin.Essentials; @@ -771,8 +773,18 @@ void IChartView.InvokeOnUIThread(Action action) /// protected void InitializeCore() { + var zoomingSection = new RectangleGeometry(); + var zoomingSectionPaint = new SolidColorPaint + { + IsFill = true, + Color = new SkiaSharp.SKColor(33, 150, 243, 50), + ZIndex = int.MaxValue + }; + zoomingSectionPaint.AddGeometryToPaintTask(canvas.CanvasCore, zoomingSection); + canvas.CanvasCore.AddDrawableTask(zoomingSectionPaint); + core = new CartesianChart( - this, LiveChartsSkiaSharp.DefaultPlatformBuilder, canvas.CanvasCore); + this, LiveChartsSkiaSharp.DefaultPlatformBuilder, canvas.CanvasCore, zoomingSection); core.Update(); } @@ -886,7 +898,7 @@ private void OnSkCanvasTouched(object? sender, SKTouchEventArgs e) if (core is null) return; var location = new LvcPoint(e.Location.X, e.Location.Y); - core.InvokePointerDown(location); + core.InvokePointerDown(location, false); core.InvokePointerMove(location); Touched?.Invoke(this, e); diff --git a/src/skiasharp/LiveChartsCore.SkiaSharp.Xamarin.Forms/PieChart.xaml.cs b/src/skiasharp/LiveChartsCore.SkiaSharp.Xamarin.Forms/PieChart.xaml.cs index 9e7bbc187..2e1fce041 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharp.Xamarin.Forms/PieChart.xaml.cs +++ b/src/skiasharp/LiveChartsCore.SkiaSharp.Xamarin.Forms/PieChart.xaml.cs @@ -708,7 +708,7 @@ private void OnSkCanvasTouched(object? sender, SKTouchEventArgs e) if (core is null) return; var location = new LvcPoint(e.Location.X, e.Location.Y); - core.InvokePointerDown(location); + core.InvokePointerDown(location, false); core.InvokePointerMove(location); Touched?.Invoke(this, e); diff --git a/src/skiasharp/LiveChartsCore.SkiaSharp.Xamarin.Forms/PolarChart.xaml.cs b/src/skiasharp/LiveChartsCore.SkiaSharp.Xamarin.Forms/PolarChart.xaml.cs index 762dc7467..5581dbbfa 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharp.Xamarin.Forms/PolarChart.xaml.cs +++ b/src/skiasharp/LiveChartsCore.SkiaSharp.Xamarin.Forms/PolarChart.xaml.cs @@ -819,7 +819,7 @@ private void OnSkCanvasTouched(object? sender, SKTouchEventArgs e) if (core is null) return; var location = new LvcPoint(e.Location.X, e.Location.Y); - core.InvokePointerDown(location); + core.InvokePointerDown(location, false); core.InvokePointerMove(location); Touched?.Invoke(this, e); diff --git a/src/skiasharp/LiveChartsCore.SkiaSharpView.Blazor/CartesianChart.razor.cs b/src/skiasharp/LiveChartsCore.SkiaSharpView.Blazor/CartesianChart.razor.cs index 8e7b90bfa..a4cb3f599 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharpView.Blazor/CartesianChart.razor.cs +++ b/src/skiasharp/LiveChartsCore.SkiaSharpView.Blazor/CartesianChart.razor.cs @@ -28,6 +28,8 @@ using LiveChartsCore.Kernel.Sketches; using LiveChartsCore.Measure; using LiveChartsCore.SkiaSharpView.Drawing; +using LiveChartsCore.SkiaSharpView.Drawing.Geometries; +using LiveChartsCore.SkiaSharpView.Painting; using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components.Web; @@ -182,8 +184,18 @@ protected override void InitializeCore() { if (motionCanvas is null) throw new Exception("MotionCanvas component was not found"); + var zoomingSection = new RectangleGeometry(); + var zoomingSectionPaint = new SolidColorPaint + { + IsFill = true, + Color = new SkiaSharp.SKColor(33, 150, 243, 50), + ZIndex = int.MaxValue + }; + zoomingSectionPaint.AddGeometryToPaintTask(motionCanvas.CanvasCore, zoomingSection); + motionCanvas.CanvasCore.AddDrawableTask(zoomingSectionPaint); + core = new CartesianChart( - this, LiveChartsSkiaSharp.DefaultPlatformBuilder, motionCanvas.CanvasCore); + this, LiveChartsSkiaSharp.DefaultPlatformBuilder, motionCanvas.CanvasCore, zoomingSection); if (((IChartView)this).DesignerMode) return; core.Update(); } diff --git a/src/skiasharp/LiveChartsCore.SkiaSharpView.Blazor/Chart.razor.cs b/src/skiasharp/LiveChartsCore.SkiaSharpView.Blazor/Chart.razor.cs index de2867ec3..f1c66d874 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharpView.Blazor/Chart.razor.cs +++ b/src/skiasharp/LiveChartsCore.SkiaSharpView.Blazor/Chart.razor.cs @@ -306,7 +306,7 @@ private void OnCoreMeasuring(IChartView chart) /// protected virtual void OnPointerDown(PointerEventArgs e) { - core?.InvokePointerDown(new LvcPoint((float)e.OffsetX, (float)e.OffsetY)); + core?.InvokePointerDown(new LvcPoint((float)e.OffsetX, (float)e.OffsetY), e.Button == 2); _ = OnPointerDownCallback.InvokeAsync(e); } @@ -326,7 +326,7 @@ protected virtual void OnPointerMove(PointerEventArgs e) /// protected virtual void OnPointerUp(PointerEventArgs e) { - core?.InvokePointerUp(new LvcPoint((float)e.OffsetX, (float)e.OffsetY)); + core?.InvokePointerUp(new LvcPoint((float)e.OffsetX, (float)e.OffsetY), e.Button == 2); _ = OnPointerUpCallback.InvokeAsync(e); } diff --git a/src/skiasharp/LiveChartsCore.SkiaSharpView.Eto/CartesianChart.cs b/src/skiasharp/LiveChartsCore.SkiaSharpView.Eto/CartesianChart.cs index 73e6b1f7d..ac7243097 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharpView.Eto/CartesianChart.cs +++ b/src/skiasharp/LiveChartsCore.SkiaSharpView.Eto/CartesianChart.cs @@ -31,6 +31,8 @@ using LiveChartsCore.Kernel.Sketches; using LiveChartsCore.Measure; using LiveChartsCore.SkiaSharpView.Drawing; +using LiveChartsCore.SkiaSharpView.Drawing.Geometries; +using LiveChartsCore.SkiaSharpView.Painting; namespace LiveChartsCore.SkiaSharpView.Eto; @@ -164,8 +166,18 @@ public DrawMarginFrame? DrawMarginFrame /// protected override void InitializeCore() { + var zoomingSection = new RectangleGeometry(); + var zoomingSectionPaint = new SolidColorPaint + { + IsFill = true, + Color = new SkiaSharp.SKColor(33, 150, 243, 50), + ZIndex = int.MaxValue + }; + zoomingSectionPaint.AddGeometryToPaintTask(motionCanvas.CanvasCore, zoomingSection); + motionCanvas.CanvasCore.AddDrawableTask(zoomingSectionPaint); + core = new CartesianChart( - this, LiveChartsSkiaSharp.DefaultPlatformBuilder, motionCanvas.CanvasCore, true); + this, LiveChartsSkiaSharp.DefaultPlatformBuilder, motionCanvas.CanvasCore, zoomingSection, true); core.Update(); } @@ -213,11 +225,11 @@ private void OnMouseWheel(object? sender, MouseEventArgs e) private void OnMouseDown(object? sender, MouseEventArgs e) { - core?.InvokePointerDown(new LvcPoint(e.Location.X, e.Location.Y)); + core?.InvokePointerDown(new LvcPoint(e.Location.X, e.Location.Y), e.Buttons == MouseButtons.Alternate); } private void OnMouseUp(object? sender, MouseEventArgs e) { - core?.InvokePointerUp(new LvcPoint(e.Location.X, e.Location.Y)); + core?.InvokePointerUp(new LvcPoint(e.Location.X, e.Location.Y), e.Buttons == MouseButtons.Alternate); } } diff --git a/src/skiasharp/LiveChartsCore.SkiaSharpView.Eto/PieChart.cs b/src/skiasharp/LiveChartsCore.SkiaSharpView.Eto/PieChart.cs index a71d0ce1f..de3e03f49 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharpView.Eto/PieChart.cs +++ b/src/skiasharp/LiveChartsCore.SkiaSharpView.Eto/PieChart.cs @@ -114,6 +114,6 @@ protected override void OnUnloading() private void OnMouseDown(object? sender, MouseEventArgs e) { - core?.InvokePointerDown(new LvcPoint(e.Location.X, e.Location.Y)); + core?.InvokePointerDown(new LvcPoint(e.Location.X, e.Location.Y), false); } } diff --git a/src/skiasharp/LiveChartsCore.SkiaSharpView.Eto/PolarChart.cs b/src/skiasharp/LiveChartsCore.SkiaSharpView.Eto/PolarChart.cs index f7badd618..ff9e73293 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharpView.Eto/PolarChart.cs +++ b/src/skiasharp/LiveChartsCore.SkiaSharpView.Eto/PolarChart.cs @@ -220,11 +220,11 @@ private void OnMouseWheel(object? sender, MouseEventArgs e) private void OnMouseDown(object? sender, MouseEventArgs e) { - core?.InvokePointerDown(new LvcPoint(e.Location.X, e.Location.Y)); + core?.InvokePointerDown(new LvcPoint(e.Location.X, e.Location.Y), false); } private void OnMouseUp(object? sender, MouseEventArgs e) { - core?.InvokePointerUp(new LvcPoint(e.Location.X, e.Location.Y)); + core?.InvokePointerUp(new LvcPoint(e.Location.X, e.Location.Y), false); } } diff --git a/src/skiasharp/LiveChartsCore.SkiaSharpView.Maui/CartesianChart.xaml.cs b/src/skiasharp/LiveChartsCore.SkiaSharpView.Maui/CartesianChart.xaml.cs index 2d0bf9446..f461b1a12 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharpView.Maui/CartesianChart.xaml.cs +++ b/src/skiasharp/LiveChartsCore.SkiaSharpView.Maui/CartesianChart.xaml.cs @@ -34,6 +34,8 @@ using LiveChartsCore.Measure; using LiveChartsCore.Motion; using LiveChartsCore.SkiaSharpView.Drawing; +using LiveChartsCore.SkiaSharpView.Drawing.Geometries; +using LiveChartsCore.SkiaSharpView.Painting; using Microsoft.Maui; using Microsoft.Maui.ApplicationModel; using Microsoft.Maui.Controls; @@ -772,8 +774,18 @@ void IChartView.InvokeOnUIThread(Action action) /// protected void InitializeCore() { + var zoomingSection = new RectangleGeometry(); + var zoomingSectionPaint = new SolidColorPaint + { + IsFill = true, + Color = new SkiaSharp.SKColor(33, 150, 243, 50), + ZIndex = int.MaxValue + }; + zoomingSectionPaint.AddGeometryToPaintTask(canvas.CanvasCore, zoomingSection); + canvas.CanvasCore.AddDrawableTask(zoomingSectionPaint); + core = new CartesianChart( - this, LiveChartsSkiaSharp.DefaultPlatformBuilder, canvas.CanvasCore); + this, LiveChartsSkiaSharp.DefaultPlatformBuilder, canvas.CanvasCore, zoomingSection); core.Update(); } @@ -894,7 +906,7 @@ private void OnSkCanvasTouched(object? sender, SKTouchEventArgs e) if (core is null) return; var location = new LvcPoint(e.Location.X, e.Location.Y); - core.InvokePointerDown(location); + core.InvokePointerDown(location, false); core.InvokePointerMove(location); Touched?.Invoke(this, e); diff --git a/src/skiasharp/LiveChartsCore.SkiaSharpView.Maui/PieChart.xaml.cs b/src/skiasharp/LiveChartsCore.SkiaSharpView.Maui/PieChart.xaml.cs index c1f5e77ae..d7070e17c 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharpView.Maui/PieChart.xaml.cs +++ b/src/skiasharp/LiveChartsCore.SkiaSharpView.Maui/PieChart.xaml.cs @@ -705,7 +705,7 @@ private void OnSkCanvasTouched(object? sender, SKTouchEventArgs e) if (core is null) return; var location = new LvcPoint(e.Location.X, e.Location.Y); - core.InvokePointerDown(location); + core.InvokePointerDown(location, false); core.InvokePointerMove(location); Touched?.Invoke(this, e); diff --git a/src/skiasharp/LiveChartsCore.SkiaSharpView.Maui/PolarChart.xaml.cs b/src/skiasharp/LiveChartsCore.SkiaSharpView.Maui/PolarChart.xaml.cs index 61deed5d1..87cdfa3a1 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharpView.Maui/PolarChart.xaml.cs +++ b/src/skiasharp/LiveChartsCore.SkiaSharpView.Maui/PolarChart.xaml.cs @@ -815,7 +815,7 @@ private void OnSkCanvasTouched(object? sender, SKTouchEventArgs e) if (core is null) return; var location = new LvcPoint(e.Location.X, e.Location.Y); - core.InvokePointerDown(location); + core.InvokePointerDown(location, false); core.InvokePointerMove(location); Touched?.Invoke(this, e); diff --git a/src/skiasharp/LiveChartsCore.SkiaSharpView.Uno.WinUI/CartesianChart.xaml.cs b/src/skiasharp/LiveChartsCore.SkiaSharpView.Uno.WinUI/CartesianChart.xaml.cs index 74bc281f4..422804291 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharpView.Uno.WinUI/CartesianChart.xaml.cs +++ b/src/skiasharp/LiveChartsCore.SkiaSharpView.Uno.WinUI/CartesianChart.xaml.cs @@ -41,6 +41,8 @@ using Microsoft.UI.Xaml.Media; using LiveChartsCore.SkiaSharpView.Uno.WinUI.Helpers; using Windows.UI.Text; +using LiveChartsCore.SkiaSharpView.Painting; +using Microsoft.UI.Input; // The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236 @@ -885,8 +887,18 @@ private void OnLoaded(object sender, RoutedEventArgs e) if (_core is null) { + var zoomingSection = new Drawing.Geometries.RectangleGeometry(); + var zoomingSectionPaint = new SolidColorPaint + { + IsFill = true, + Color = new SkiaSharp.SKColor(33, 150, 243, 50), + ZIndex = int.MaxValue + }; + zoomingSectionPaint.AddGeometryToPaintTask(canvas.CanvasCore, zoomingSection); + canvas.CanvasCore.AddDrawableTask(zoomingSectionPaint); + _core = new CartesianChart( - this, LiveChartsSkiaSharp.DefaultPlatformBuilder, canvas.CanvasCore); + this, LiveChartsSkiaSharp.DefaultPlatformBuilder, canvas.CanvasCore, zoomingSection); if (SyncContext != null) _motionCanvas.CanvasCore.Sync = SyncContext; @@ -957,7 +969,13 @@ private void OnPointerPressed(object? sender, PointerRoutedEventArgs e) { _ = CapturePointer(e.Pointer); var p = e.GetCurrentPoint(this); - _core?.InvokePointerDown(new LvcPoint((float)p.Position.X, (float)p.Position.Y)); + var isRight = false; + if (e.Pointer.PointerDeviceType == PointerDeviceType.Mouse) + { + var properties = e.GetCurrentPoint(this).Properties; + isRight = properties.IsRightButtonPressed; + } + _core?.InvokePointerDown(new LvcPoint((float)p.Position.X, (float)p.Position.Y), isRight); } private void OnPointerMoved(object? sender, PointerRoutedEventArgs e) @@ -971,7 +989,13 @@ private void OnPointerMoved(object? sender, PointerRoutedEventArgs e) private void OnPointerReleased(object? sender, PointerRoutedEventArgs e) { var p = e.GetCurrentPoint(this); - _core?.InvokePointerUp(new LvcPoint((float)p.Position.X, (float)p.Position.Y)); + var isRight = false; + if (e.Pointer.PointerDeviceType == PointerDeviceType.Mouse) + { + var properties = e.GetCurrentPoint(this).Properties; + isRight = properties.IsRightButtonPressed; + } + _core?.InvokePointerUp(new LvcPoint((float)p.Position.X, (float)p.Position.Y), isRight); ReleasePointerCapture(e.Pointer); } diff --git a/src/skiasharp/LiveChartsCore.SkiaSharpView.Uno.WinUI/PieChart.xaml.cs b/src/skiasharp/LiveChartsCore.SkiaSharpView.Uno.WinUI/PieChart.xaml.cs index 03672d384..906f470f1 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharpView.Uno.WinUI/PieChart.xaml.cs +++ b/src/skiasharp/LiveChartsCore.SkiaSharpView.Uno.WinUI/PieChart.xaml.cs @@ -790,7 +790,7 @@ private void OnSizeChanged(object sender, SizeChangedEventArgs e) private void OnPointerPressed(object sender, PointerRoutedEventArgs e) { var p = e.GetCurrentPoint(this); - _core?.InvokePointerDown(new LvcPoint((float)p.Position.X, (float)p.Position.Y)); + _core?.InvokePointerDown(new LvcPoint((float)p.Position.X, (float)p.Position.Y), false); } private void OnPointerMoved(object sender, PointerRoutedEventArgs e) diff --git a/src/skiasharp/LiveChartsCore.SkiaSharpView.Uno.WinUI/PolarChart.xaml.cs b/src/skiasharp/LiveChartsCore.SkiaSharpView.Uno.WinUI/PolarChart.xaml.cs index bfa0d7c89..765516c33 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharpView.Uno.WinUI/PolarChart.xaml.cs +++ b/src/skiasharp/LiveChartsCore.SkiaSharpView.Uno.WinUI/PolarChart.xaml.cs @@ -910,13 +910,13 @@ private void OnPointerExited(object sender, PointerRoutedEventArgs e) private void OnPointerReleased(object sender, PointerRoutedEventArgs e) { var p = e.GetCurrentPoint(this); - _core?.InvokePointerUp(new LvcPoint((float)p.Position.X, (float)p.Position.Y)); + _core?.InvokePointerUp(new LvcPoint((float)p.Position.X, (float)p.Position.Y), false); } private void OnPointerPressed(object sender, PointerRoutedEventArgs e) { var p = e.GetCurrentPoint(this); - _core?.InvokePointerDown(new LvcPoint((float)p.Position.X, (float)p.Position.Y)); + _core?.InvokePointerDown(new LvcPoint((float)p.Position.X, (float)p.Position.Y), false); } private void OnWheelChanged(object sender, PointerRoutedEventArgs e) diff --git a/src/skiasharp/LiveChartsCore.SkiaSharpView.Uno/CartesianChart.xaml.cs b/src/skiasharp/LiveChartsCore.SkiaSharpView.Uno/CartesianChart.xaml.cs index 96e3fe00c..257d82fbf 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharpView.Uno/CartesianChart.xaml.cs +++ b/src/skiasharp/LiveChartsCore.SkiaSharpView.Uno/CartesianChart.xaml.cs @@ -34,7 +34,9 @@ using LiveChartsCore.Measure; using LiveChartsCore.Motion; using LiveChartsCore.SkiaSharpView.Drawing; +using LiveChartsCore.SkiaSharpView.Painting; using LiveChartsCore.SkiaSharpView.Uno.Helpers; +using Windows.Devices.Input; using Windows.UI.Text; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; @@ -884,8 +886,18 @@ private void OnLoaded(object sender, RoutedEventArgs e) if (_core is null) { + var zoomingSection = new Drawing.Geometries.RectangleGeometry(); + var zoomingSectionPaint = new SolidColorPaint + { + IsFill = true, + Color = new SkiaSharp.SKColor(33, 150, 243, 50), + ZIndex = int.MaxValue + }; + zoomingSectionPaint.AddGeometryToPaintTask(canvas.CanvasCore, zoomingSection); + canvas.CanvasCore.AddDrawableTask(zoomingSectionPaint); + _core = new CartesianChart( - this, LiveChartsSkiaSharp.DefaultPlatformBuilder, canvas.CanvasCore); + this, LiveChartsSkiaSharp.DefaultPlatformBuilder, canvas.CanvasCore, zoomingSection); if (SyncContext != null) _motionCanvas.CanvasCore.Sync = SyncContext; @@ -956,7 +968,15 @@ private void OnPointerPressed(object? sender, PointerRoutedEventArgs e) { _ = CapturePointer(e.Pointer); var p = e.GetCurrentPoint(this); - _core?.InvokePointerDown(new LvcPoint((float)p.Position.X, (float)p.Position.Y)); + + var isRight = false; + if (e.Pointer.PointerDeviceType == PointerDeviceType.Mouse) + { + var properties = e.GetCurrentPoint(this).Properties; + isRight = properties.IsRightButtonPressed; + } + + _core?.InvokePointerDown(new LvcPoint((float)p.Position.X, (float)p.Position.Y), isRight); } private void OnPointerMoved(object? sender, PointerRoutedEventArgs e) @@ -970,7 +990,15 @@ private void OnPointerMoved(object? sender, PointerRoutedEventArgs e) private void OnPointerReleased(object? sender, PointerRoutedEventArgs e) { var p = e.GetCurrentPoint(this); - _core?.InvokePointerUp(new LvcPoint((float)p.Position.X, (float)p.Position.Y)); + + var isRight = false; + if (e.Pointer.PointerDeviceType == PointerDeviceType.Mouse) + { + var properties = e.GetCurrentPoint(this).Properties; + isRight = properties.IsRightButtonPressed; + } + + _core?.InvokePointerUp(new LvcPoint((float)p.Position.X, (float)p.Position.Y), isRight); ReleasePointerCapture(e.Pointer); } diff --git a/src/skiasharp/LiveChartsCore.SkiaSharpView.Uno/PieChart.xaml.cs b/src/skiasharp/LiveChartsCore.SkiaSharpView.Uno/PieChart.xaml.cs index e026cae8b..089d3f6ac 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharpView.Uno/PieChart.xaml.cs +++ b/src/skiasharp/LiveChartsCore.SkiaSharpView.Uno/PieChart.xaml.cs @@ -789,7 +789,7 @@ private void OnSizeChanged(object sender, SizeChangedEventArgs e) private void OnPointerPressed(object sender, PointerRoutedEventArgs e) { var p = e.GetCurrentPoint(this); - _core?.InvokePointerDown(new LvcPoint((float)p.Position.X, (float)p.Position.Y)); + _core?.InvokePointerDown(new LvcPoint((float)p.Position.X, (float)p.Position.Y), false); } private void OnPointerMoved(object sender, PointerRoutedEventArgs e) diff --git a/src/skiasharp/LiveChartsCore.SkiaSharpView.Uno/PolarChart.xaml.cs b/src/skiasharp/LiveChartsCore.SkiaSharpView.Uno/PolarChart.xaml.cs index b1bb5cf84..3dcf5e4f2 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharpView.Uno/PolarChart.xaml.cs +++ b/src/skiasharp/LiveChartsCore.SkiaSharpView.Uno/PolarChart.xaml.cs @@ -909,13 +909,13 @@ private void OnPointerExited(object sender, PointerRoutedEventArgs e) private void OnPointerReleased(object sender, PointerRoutedEventArgs e) { var p = e.GetCurrentPoint(this); - _core?.InvokePointerUp(new LvcPoint((float)p.Position.X, (float)p.Position.Y)); + _core?.InvokePointerUp(new LvcPoint((float)p.Position.X, (float)p.Position.Y), false); } private void OnPointerPressed(object sender, PointerRoutedEventArgs e) { var p = e.GetCurrentPoint(this); - _core?.InvokePointerDown(new LvcPoint((float)p.Position.X, (float)p.Position.Y)); + _core?.InvokePointerDown(new LvcPoint((float)p.Position.X, (float)p.Position.Y), false); } private void OnWheelChanged(object sender, PointerRoutedEventArgs e) diff --git a/src/skiasharp/LiveChartsCore.SkiaSharpView.WinUI/CartesianChart.xaml.cs b/src/skiasharp/LiveChartsCore.SkiaSharpView.WinUI/CartesianChart.xaml.cs index af917eb76..368ec80e5 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharpView.WinUI/CartesianChart.xaml.cs +++ b/src/skiasharp/LiveChartsCore.SkiaSharpView.WinUI/CartesianChart.xaml.cs @@ -33,6 +33,8 @@ using LiveChartsCore.Measure; using LiveChartsCore.Motion; using LiveChartsCore.SkiaSharpView.Drawing; +using LiveChartsCore.SkiaSharpView.Painting; +using Microsoft.UI.Input; using Microsoft.UI.Text; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; @@ -885,8 +887,18 @@ private void OnLoaded(object sender, RoutedEventArgs e) if (_core is null) { + var zoomingSection = new Drawing.Geometries.RectangleGeometry(); + var zoomingSectionPaint = new SolidColorPaint + { + IsFill = true, + Color = new SkiaSharp.SKColor(33, 150, 243, 50), + ZIndex = int.MaxValue + }; + zoomingSectionPaint.AddGeometryToPaintTask(canvas.CanvasCore, zoomingSection); + canvas.CanvasCore.AddDrawableTask(zoomingSectionPaint); + _core = new CartesianChart( - this, LiveChartsSkiaSharp.DefaultPlatformBuilder, canvas.CanvasCore); + this, LiveChartsSkiaSharp.DefaultPlatformBuilder, canvas.CanvasCore, zoomingSection); //_legend = Template.FindName("legend", this) as IChartLegend; //_tooltip = Template.FindName("tooltip", this) as IChartTooltip; if (SyncContext != null) @@ -957,7 +969,15 @@ private void OnPointerExited(object sender, Microsoft.UI.Xaml.Input.PointerRoute private void OnPointerReleased(object sender, Microsoft.UI.Xaml.Input.PointerRoutedEventArgs e) { var p = e.GetCurrentPoint(this); - _core?.InvokePointerUp(new LvcPoint((float)p.Position.X, (float)p.Position.Y)); + + var isRight = false; + if (e.Pointer.PointerDeviceType == PointerDeviceType.Mouse) + { + var properties = e.GetCurrentPoint(this).Properties; + isRight = properties.IsRightButtonPressed; + } + + _core?.InvokePointerUp(new LvcPoint((float)p.Position.X, (float)p.Position.Y), isRight); ReleasePointerCapture(e.Pointer); } @@ -965,7 +985,13 @@ private void OnPointerPressed(object sender, Microsoft.UI.Xaml.Input.PointerRout { _ = CapturePointer(e.Pointer); var p = e.GetCurrentPoint(this); - _core?.InvokePointerDown(new LvcPoint((float)p.Position.X, (float)p.Position.Y)); + var isRight = false; + if (e.Pointer.PointerDeviceType == PointerDeviceType.Mouse) + { + var properties = e.GetCurrentPoint(this).Properties; + isRight = properties.IsRightButtonPressed; + } + _core?.InvokePointerDown(new LvcPoint((float)p.Position.X, (float)p.Position.Y), isRight); } private void OnWheelChanged(object sender, Microsoft.UI.Xaml.Input.PointerRoutedEventArgs e) diff --git a/src/skiasharp/LiveChartsCore.SkiaSharpView.WinUI/PieChart.xaml.cs b/src/skiasharp/LiveChartsCore.SkiaSharpView.WinUI/PieChart.xaml.cs index d76a4cfc9..9c18b466c 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharpView.WinUI/PieChart.xaml.cs +++ b/src/skiasharp/LiveChartsCore.SkiaSharpView.WinUI/PieChart.xaml.cs @@ -827,13 +827,13 @@ private void OnPointerExited(object sender, Microsoft.UI.Xaml.Input.PointerRoute private void OnPointerPressed(object sender, Microsoft.UI.Xaml.Input.PointerRoutedEventArgs e) { var p = e.GetCurrentPoint(this); - _core?.InvokePointerDown(new LvcPoint((float)p.Position.X, (float)p.Position.Y)); + _core?.InvokePointerDown(new LvcPoint((float)p.Position.X, (float)p.Position.Y), false); } private void OnPointerReleased(object sender, Microsoft.UI.Xaml.Input.PointerRoutedEventArgs e) { var p = e.GetCurrentPoint(this); - _core?.InvokePointerUp(new LvcPoint((float)p.Position.X, (float)p.Position.Y)); + _core?.InvokePointerUp(new LvcPoint((float)p.Position.X, (float)p.Position.Y), false); } private void OnUnloaded(object sender, RoutedEventArgs e) diff --git a/src/skiasharp/LiveChartsCore.SkiaSharpView.WinUI/PolarChart.xaml.cs b/src/skiasharp/LiveChartsCore.SkiaSharpView.WinUI/PolarChart.xaml.cs index 9cd826985..e9f49136b 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharpView.WinUI/PolarChart.xaml.cs +++ b/src/skiasharp/LiveChartsCore.SkiaSharpView.WinUI/PolarChart.xaml.cs @@ -914,13 +914,13 @@ private void OnPointerExited(object sender, Microsoft.UI.Xaml.Input.PointerRoute private void OnPointerReleased(object sender, Microsoft.UI.Xaml.Input.PointerRoutedEventArgs e) { var p = e.GetCurrentPoint(this); - _core?.InvokePointerUp(new LvcPoint((float)p.Position.X, (float)p.Position.Y)); + _core?.InvokePointerUp(new LvcPoint((float)p.Position.X, (float)p.Position.Y), false); } private void OnPointerPressed(object sender, Microsoft.UI.Xaml.Input.PointerRoutedEventArgs e) { var p = e.GetCurrentPoint(this); - _core?.InvokePointerDown(new LvcPoint((float)p.Position.X, (float)p.Position.Y)); + _core?.InvokePointerDown(new LvcPoint((float)p.Position.X, (float)p.Position.Y), false); } private void OnWheelChanged(object sender, Microsoft.UI.Xaml.Input.PointerRoutedEventArgs e) From 8616f954cb3a9380306d5293e8b0689fff58f59b Mon Sep 17 00:00:00 2001 From: beto-rodriguez Date: Tue, 16 Aug 2022 20:39:52 -0500 Subject: [PATCH 04/25] a better implementention of ICoordinate --- samples/ViewModelsSamples/Index.cs | 208 +++++++++--------- .../Lines/Basic/ViewModel.cs | 12 +- src/LiveChartsCore/AssemblyInfo.cs | 34 +-- src/LiveChartsCore/Defaults/DateTimePoint.cs | 37 +++- src/LiveChartsCore/Defaults/FinancialPoint.cs | 80 ++++++- .../Defaults/ObservablePoint.cs | 39 +++- .../Defaults/ObservablePolarPoint.cs | 37 +++- .../Defaults/ObservableValue.cs | 37 +++- src/LiveChartsCore/Defaults/TimeSpanPoint.cs | 37 +++- src/LiveChartsCore/Defaults/WeightedPoint.cs | 48 +++- src/LiveChartsCore/Kernel/Coordinate.cs | 2 +- .../Kernel/LiveChartsSettings.cs | 8 +- src/LiveChartsCore/LineSeries.cs | 1 - .../LiveChartsCore.SkiaSharp/AssemblyInfo.cs | 12 +- 14 files changed, 419 insertions(+), 173 deletions(-) diff --git a/samples/ViewModelsSamples/Index.cs b/samples/ViewModelsSamples/Index.cs index 4474da96c..b5471ebdc 100644 --- a/samples/ViewModelsSamples/Index.cs +++ b/samples/ViewModelsSamples/Index.cs @@ -4,111 +4,111 @@ public static class Index { public static string[] Samples = { - "Design/LinearGradients", - "Design/RadialGradients", + //"Design/LinearGradients", + //"Design/RadialGradients", "Lines/Basic", - "Lines/AutoUpdate", - "Lines/Straight", - "Lines/Properties", - "Lines/Area", - "Lines/Custom", - "Lines/Padding", - "Lines/XY", - "Lines/Zoom", - - "StepLines/Basic", - "StepLines/AutoUpdate", - "StepLines/Properties", - "StepLines/Area", - "StepLines/Custom", - "StepLines/Zoom", - - "StackedArea/Basic", - "StackedArea/StepArea", - - "Bars/Basic", - "Bars/AutoUpdate", - "Bars/Custom", - "Bars/WithBackground", - "Bars/Spacing", - "Bars/DelayedAnimation", - "Bars/Race", - "Bars/RowsWithLabels", - "Bars/Layered", - - "StackedBars/Basic", - "StackedBars/Groups", - - "Pies/Basic", - "Pies/AutoUpdate", - "Pies/Processing", - "Pies/Doughnut", - "Pies/Pushout", - "Pies/Custom", - "Pies/NightingaleRose", - "Pies/Gauges", - //"Pies/Gauge", - "Pies/Gauge1", - "Pies/Gauge2", - "Pies/Gauge3", - "Pies/Gauge4", - "Pies/Gauge5", - - "Scatter/Basic", - "Scatter/Bubbles", - "Scatter/AutoUpdate", - "Scatter/Custom", - - "Financial/BasicCandlesticks", - - "Heat/Basic", - - "Polar/Basic", - "Polar/RadialArea", - "Polar/Coordinates", - - "Axes/ColorsAndPosition", - "Axes/LabelsFormat", - "Axes/LabelsFormat2", - "Axes/NamedLabels", - "Axes/LabelsRotation", - "Axes/Multiple", - "Axes/Shared", - "Axes/DateTimeScaled", - "Axes/TimeSpanScaled", - "Axes/Logarithmic", - "Axes/Style", - "Axes/Paging", - - "Events/AddPointOnClick", - "Events/Cartesian", - "Events/Pie", - "Events/Polar", - - "General/Sections", - "General/Sections2", - "General/ChartToImage", - "General/Tooltips", - "General/Legends", - "General/Animations", - "General/Visibility", - "General/TemplatedTooltips", - "General/TemplatedLegends", - "General/UserDefinedTypes", - "General/NullPoints", - "General/MultiThreading", - "General/MultiThreading2", - - "VisualTest/TwoChartsOneSeries", - "VisualTest/ReattachVisual", - "VisualTest/DataTemplate", - "VisualTest/Tabs", - - //"Test/ChangeSeriesInstance", - //"Test/Dispose", - //"Test/MotionCanvasDispose", - - "Maps/World" + //"Lines/AutoUpdate", + //"Lines/Straight", + //"Lines/Properties", + //"Lines/Area", + //"Lines/Custom", + //"Lines/Padding", + //"Lines/XY", + //"Lines/Zoom", + + //"StepLines/Basic", + //"StepLines/AutoUpdate", + //"StepLines/Properties", + //"StepLines/Area", + //"StepLines/Custom", + //"StepLines/Zoom", + + //"StackedArea/Basic", + //"StackedArea/StepArea", + + //"Bars/Basic", + //"Bars/AutoUpdate", + //"Bars/Custom", + //"Bars/WithBackground", + //"Bars/Spacing", + //"Bars/DelayedAnimation", + //"Bars/Race", + //"Bars/RowsWithLabels", + //"Bars/Layered", + + //"StackedBars/Basic", + //"StackedBars/Groups", + + //"Pies/Basic", + //"Pies/AutoUpdate", + //"Pies/Processing", + //"Pies/Doughnut", + //"Pies/Pushout", + //"Pies/Custom", + //"Pies/NightingaleRose", + //"Pies/Gauges", + ////"Pies/Gauge", + //"Pies/Gauge1", + //"Pies/Gauge2", + //"Pies/Gauge3", + //"Pies/Gauge4", + //"Pies/Gauge5", + + //"Scatter/Basic", + //"Scatter/Bubbles", + //"Scatter/AutoUpdate", + //"Scatter/Custom", + + //"Financial/BasicCandlesticks", + + //"Heat/Basic", + + //"Polar/Basic", + //"Polar/RadialArea", + //"Polar/Coordinates", + + //"Axes/ColorsAndPosition", + //"Axes/LabelsFormat", + //"Axes/LabelsFormat2", + //"Axes/NamedLabels", + //"Axes/LabelsRotation", + //"Axes/Multiple", + //"Axes/Shared", + //"Axes/DateTimeScaled", + //"Axes/TimeSpanScaled", + //"Axes/Logarithmic", + //"Axes/Style", + //"Axes/Paging", + + //"Events/AddPointOnClick", + //"Events/Cartesian", + //"Events/Pie", + //"Events/Polar", + + //"General/Sections", + //"General/Sections2", + //"General/ChartToImage", + //"General/Tooltips", + //"General/Legends", + //"General/Animations", + //"General/Visibility", + //"General/TemplatedTooltips", + //"General/TemplatedLegends", + //"General/UserDefinedTypes", + //"General/NullPoints", + //"General/MultiThreading", + //"General/MultiThreading2", + + //"VisualTest/TwoChartsOneSeries", + //"VisualTest/ReattachVisual", + //"VisualTest/DataTemplate", + //"VisualTest/Tabs", + + ////"Test/ChangeSeriesInstance", + ////"Test/Dispose", + ////"Test/MotionCanvasDispose", + + //"Maps/World" }; } diff --git a/samples/ViewModelsSamples/Lines/Basic/ViewModel.cs b/samples/ViewModelsSamples/Lines/Basic/ViewModel.cs index 09319ef40..1699db57b 100644 --- a/samples/ViewModelsSamples/Lines/Basic/ViewModel.cs +++ b/samples/ViewModelsSamples/Lines/Basic/ViewModel.cs @@ -1,5 +1,6 @@ using CommunityToolkit.Mvvm.ComponentModel; using LiveChartsCore; +using LiveChartsCore.Defaults; using LiveChartsCore.SkiaSharpView; namespace ViewModelsSamples.Lines.Basic; @@ -9,9 +10,16 @@ public partial class ViewModel { public ISeries[] Series { get; set; } = { - new LineSeries + new LineSeries { - Values = new double[] { 2, 1, 3, 5, 3, 4, 6 }, + Values = new ObservablePoint[] + { + new ObservablePoint { X = 2, Y = 0 }, + new ObservablePoint { X = 3, Y = 3 }, + new ObservablePoint { X = 5, Y = null }, + new ObservablePoint { X = 6, Y = 4 }, + new ObservablePoint { X = 8, Y = 6 } + }, Fill = null } }; diff --git a/src/LiveChartsCore/AssemblyInfo.cs b/src/LiveChartsCore/AssemblyInfo.cs index d2b5a0840..65df3e29d 100644 --- a/src/LiveChartsCore/AssemblyInfo.cs +++ b/src/LiveChartsCore/AssemblyInfo.cs @@ -21,23 +21,23 @@ // SOFTWARE. using System.Runtime.CompilerServices; -#if !DEBUG -using System.Reflection; +//#if !DEBUG +//using System.Reflection; -[assembly: AssemblyKeyFile("./../../LiveCharts.snk")] -[assembly: InternalsVisibleTo("LiveChartsCore.SkiaSharpView, PublicKey=0024000004800000940000000602000000240000525341310004000001000100d53791eaa0d98b405ca858f39169be6af36ceb7a1bca3ca76c6905fd22fddf8c5e4ef2778a5d7a77ad12f08da711fecfc44795c7923739a2acac946b3f1719a6dfc238695bc69cf5d959b3fb6bc4d18d57a97ff8ed897e6b22a6b8155401ee368d77431e74178104b4adca73520b058b9be28d4ec129beb54871778167afa5ce")] -[assembly: InternalsVisibleTo("LiveChartsCore.SkiaSharpView.Avalonia, PublicKey=0024000004800000940000000602000000240000525341310004000001000100d53791eaa0d98b405ca858f39169be6af36ceb7a1bca3ca76c6905fd22fddf8c5e4ef2778a5d7a77ad12f08da711fecfc44795c7923739a2acac946b3f1719a6dfc238695bc69cf5d959b3fb6bc4d18d57a97ff8ed897e6b22a6b8155401ee368d77431e74178104b4adca73520b058b9be28d4ec129beb54871778167afa5ce")] -[assembly: InternalsVisibleTo("LiveChartsCore.SkiaSharpView.WinForms, PublicKey=0024000004800000940000000602000000240000525341310004000001000100d53791eaa0d98b405ca858f39169be6af36ceb7a1bca3ca76c6905fd22fddf8c5e4ef2778a5d7a77ad12f08da711fecfc44795c7923739a2acac946b3f1719a6dfc238695bc69cf5d959b3fb6bc4d18d57a97ff8ed897e6b22a6b8155401ee368d77431e74178104b4adca73520b058b9be28d4ec129beb54871778167afa5ce")] -[assembly: InternalsVisibleTo("LiveChartsCore.SkiaSharpView.WinUI, PublicKey=0024000004800000940000000602000000240000525341310004000001000100d53791eaa0d98b405ca858f39169be6af36ceb7a1bca3ca76c6905fd22fddf8c5e4ef2778a5d7a77ad12f08da711fecfc44795c7923739a2acac946b3f1719a6dfc238695bc69cf5d959b3fb6bc4d18d57a97ff8ed897e6b22a6b8155401ee368d77431e74178104b4adca73520b058b9be28d4ec129beb54871778167afa5ce")] -[assembly: InternalsVisibleTo("LiveChartsCore.SkiaSharpView.Uno, PublicKey=0024000004800000940000000602000000240000525341310004000001000100d53791eaa0d98b405ca858f39169be6af36ceb7a1bca3ca76c6905fd22fddf8c5e4ef2778a5d7a77ad12f08da711fecfc44795c7923739a2acac946b3f1719a6dfc238695bc69cf5d959b3fb6bc4d18d57a97ff8ed897e6b22a6b8155401ee368d77431e74178104b4adca73520b058b9be28d4ec129beb54871778167afa5ce")] -[assembly: InternalsVisibleTo("LiveChartsCore.SkiaSharpView.Uno.WinUI, PublicKey=0024000004800000940000000602000000240000525341310004000001000100d53791eaa0d98b405ca858f39169be6af36ceb7a1bca3ca76c6905fd22fddf8c5e4ef2778a5d7a77ad12f08da711fecfc44795c7923739a2acac946b3f1719a6dfc238695bc69cf5d959b3fb6bc4d18d57a97ff8ed897e6b22a6b8155401ee368d77431e74178104b4adca73520b058b9be28d4ec129beb54871778167afa5ce")] -[assembly: InternalsVisibleTo("LiveChartsCore.SkiaSharpView.WPF, PublicKey=0024000004800000940000000602000000240000525341310004000001000100d53791eaa0d98b405ca858f39169be6af36ceb7a1bca3ca76c6905fd22fddf8c5e4ef2778a5d7a77ad12f08da711fecfc44795c7923739a2acac946b3f1719a6dfc238695bc69cf5d959b3fb6bc4d18d57a97ff8ed897e6b22a6b8155401ee368d77431e74178104b4adca73520b058b9be28d4ec129beb54871778167afa5ce")] -[assembly: InternalsVisibleTo("LiveChartsCore.SkiaSharpView.XamarinForms, PublicKey=0024000004800000940000000602000000240000525341310004000001000100d53791eaa0d98b405ca858f39169be6af36ceb7a1bca3ca76c6905fd22fddf8c5e4ef2778a5d7a77ad12f08da711fecfc44795c7923739a2acac946b3f1719a6dfc238695bc69cf5d959b3fb6bc4d18d57a97ff8ed897e6b22a6b8155401ee368d77431e74178104b4adca73520b058b9be28d4ec129beb54871778167afa5ce")] -[assembly: InternalsVisibleTo("LiveChartsCore.SkiaSharpView.Eto, PublicKey=0024000004800000940000000602000000240000525341310004000001000100d53791eaa0d98b405ca858f39169be6af36ceb7a1bca3ca76c6905fd22fddf8c5e4ef2778a5d7a77ad12f08da711fecfc44795c7923739a2acac946b3f1719a6dfc238695bc69cf5d959b3fb6bc4d18d57a97ff8ed897e6b22a6b8155401ee368d77431e74178104b4adca73520b058b9be28d4ec129beb54871778167afa5ce")] -[assembly: InternalsVisibleTo("LiveChartsCore.SkiaSharpView.Blazor, PublicKey=0024000004800000940000000602000000240000525341310004000001000100d53791eaa0d98b405ca858f39169be6af36ceb7a1bca3ca76c6905fd22fddf8c5e4ef2778a5d7a77ad12f08da711fecfc44795c7923739a2acac946b3f1719a6dfc238695bc69cf5d959b3fb6bc4d18d57a97ff8ed897e6b22a6b8155401ee368d77431e74178104b4adca73520b058b9be28d4ec129beb54871778167afa5ce")] -[assembly: InternalsVisibleTo("LiveChartsCore.SkiaSharpView.Maui, PublicKey=0024000004800000940000000602000000240000525341310004000001000100d53791eaa0d98b405ca858f39169be6af36ceb7a1bca3ca76c6905fd22fddf8c5e4ef2778a5d7a77ad12f08da711fecfc44795c7923739a2acac946b3f1719a6dfc238695bc69cf5d959b3fb6bc4d18d57a97ff8ed897e6b22a6b8155401ee368d77431e74178104b4adca73520b058b9be28d4ec129beb54871778167afa5ce")] -[assembly: InternalsVisibleTo("LiveChartsCore.BackersPackage, PublicKey=0024000004800000940000000602000000240000525341310004000001000100d53791eaa0d98b405ca858f39169be6af36ceb7a1bca3ca76c6905fd22fddf8c5e4ef2778a5d7a77ad12f08da711fecfc44795c7923739a2acac946b3f1719a6dfc238695bc69cf5d959b3fb6bc4d18d57a97ff8ed897e6b22a6b8155401ee368d77431e74178104b4adca73520b058b9be28d4ec129beb54871778167afa5ce")] -#else +//[assembly: AssemblyKeyFile("./../../LiveCharts.snk")] +//[assembly: InternalsVisibleTo("LiveChartsCore.SkiaSharpView, PublicKey=0024000004800000940000000602000000240000525341310004000001000100d53791eaa0d98b405ca858f39169be6af36ceb7a1bca3ca76c6905fd22fddf8c5e4ef2778a5d7a77ad12f08da711fecfc44795c7923739a2acac946b3f1719a6dfc238695bc69cf5d959b3fb6bc4d18d57a97ff8ed897e6b22a6b8155401ee368d77431e74178104b4adca73520b058b9be28d4ec129beb54871778167afa5ce")] +//[assembly: InternalsVisibleTo("LiveChartsCore.SkiaSharpView.Avalonia, PublicKey=0024000004800000940000000602000000240000525341310004000001000100d53791eaa0d98b405ca858f39169be6af36ceb7a1bca3ca76c6905fd22fddf8c5e4ef2778a5d7a77ad12f08da711fecfc44795c7923739a2acac946b3f1719a6dfc238695bc69cf5d959b3fb6bc4d18d57a97ff8ed897e6b22a6b8155401ee368d77431e74178104b4adca73520b058b9be28d4ec129beb54871778167afa5ce")] +//[assembly: InternalsVisibleTo("LiveChartsCore.SkiaSharpView.WinForms, PublicKey=0024000004800000940000000602000000240000525341310004000001000100d53791eaa0d98b405ca858f39169be6af36ceb7a1bca3ca76c6905fd22fddf8c5e4ef2778a5d7a77ad12f08da711fecfc44795c7923739a2acac946b3f1719a6dfc238695bc69cf5d959b3fb6bc4d18d57a97ff8ed897e6b22a6b8155401ee368d77431e74178104b4adca73520b058b9be28d4ec129beb54871778167afa5ce")] +//[assembly: InternalsVisibleTo("LiveChartsCore.SkiaSharpView.WinUI, PublicKey=0024000004800000940000000602000000240000525341310004000001000100d53791eaa0d98b405ca858f39169be6af36ceb7a1bca3ca76c6905fd22fddf8c5e4ef2778a5d7a77ad12f08da711fecfc44795c7923739a2acac946b3f1719a6dfc238695bc69cf5d959b3fb6bc4d18d57a97ff8ed897e6b22a6b8155401ee368d77431e74178104b4adca73520b058b9be28d4ec129beb54871778167afa5ce")] +//[assembly: InternalsVisibleTo("LiveChartsCore.SkiaSharpView.Uno, PublicKey=0024000004800000940000000602000000240000525341310004000001000100d53791eaa0d98b405ca858f39169be6af36ceb7a1bca3ca76c6905fd22fddf8c5e4ef2778a5d7a77ad12f08da711fecfc44795c7923739a2acac946b3f1719a6dfc238695bc69cf5d959b3fb6bc4d18d57a97ff8ed897e6b22a6b8155401ee368d77431e74178104b4adca73520b058b9be28d4ec129beb54871778167afa5ce")] +//[assembly: InternalsVisibleTo("LiveChartsCore.SkiaSharpView.Uno.WinUI, PublicKey=0024000004800000940000000602000000240000525341310004000001000100d53791eaa0d98b405ca858f39169be6af36ceb7a1bca3ca76c6905fd22fddf8c5e4ef2778a5d7a77ad12f08da711fecfc44795c7923739a2acac946b3f1719a6dfc238695bc69cf5d959b3fb6bc4d18d57a97ff8ed897e6b22a6b8155401ee368d77431e74178104b4adca73520b058b9be28d4ec129beb54871778167afa5ce")] +//[assembly: InternalsVisibleTo("LiveChartsCore.SkiaSharpView.WPF, PublicKey=0024000004800000940000000602000000240000525341310004000001000100d53791eaa0d98b405ca858f39169be6af36ceb7a1bca3ca76c6905fd22fddf8c5e4ef2778a5d7a77ad12f08da711fecfc44795c7923739a2acac946b3f1719a6dfc238695bc69cf5d959b3fb6bc4d18d57a97ff8ed897e6b22a6b8155401ee368d77431e74178104b4adca73520b058b9be28d4ec129beb54871778167afa5ce")] +//[assembly: InternalsVisibleTo("LiveChartsCore.SkiaSharpView.XamarinForms, PublicKey=0024000004800000940000000602000000240000525341310004000001000100d53791eaa0d98b405ca858f39169be6af36ceb7a1bca3ca76c6905fd22fddf8c5e4ef2778a5d7a77ad12f08da711fecfc44795c7923739a2acac946b3f1719a6dfc238695bc69cf5d959b3fb6bc4d18d57a97ff8ed897e6b22a6b8155401ee368d77431e74178104b4adca73520b058b9be28d4ec129beb54871778167afa5ce")] +//[assembly: InternalsVisibleTo("LiveChartsCore.SkiaSharpView.Eto, PublicKey=0024000004800000940000000602000000240000525341310004000001000100d53791eaa0d98b405ca858f39169be6af36ceb7a1bca3ca76c6905fd22fddf8c5e4ef2778a5d7a77ad12f08da711fecfc44795c7923739a2acac946b3f1719a6dfc238695bc69cf5d959b3fb6bc4d18d57a97ff8ed897e6b22a6b8155401ee368d77431e74178104b4adca73520b058b9be28d4ec129beb54871778167afa5ce")] +//[assembly: InternalsVisibleTo("LiveChartsCore.SkiaSharpView.Blazor, PublicKey=0024000004800000940000000602000000240000525341310004000001000100d53791eaa0d98b405ca858f39169be6af36ceb7a1bca3ca76c6905fd22fddf8c5e4ef2778a5d7a77ad12f08da711fecfc44795c7923739a2acac946b3f1719a6dfc238695bc69cf5d959b3fb6bc4d18d57a97ff8ed897e6b22a6b8155401ee368d77431e74178104b4adca73520b058b9be28d4ec129beb54871778167afa5ce")] +//[assembly: InternalsVisibleTo("LiveChartsCore.SkiaSharpView.Maui, PublicKey=0024000004800000940000000602000000240000525341310004000001000100d53791eaa0d98b405ca858f39169be6af36ceb7a1bca3ca76c6905fd22fddf8c5e4ef2778a5d7a77ad12f08da711fecfc44795c7923739a2acac946b3f1719a6dfc238695bc69cf5d959b3fb6bc4d18d57a97ff8ed897e6b22a6b8155401ee368d77431e74178104b4adca73520b058b9be28d4ec129beb54871778167afa5ce")] +//[assembly: InternalsVisibleTo("LiveChartsCore.BackersPackage, PublicKey=0024000004800000940000000602000000240000525341310004000001000100d53791eaa0d98b405ca858f39169be6af36ceb7a1bca3ca76c6905fd22fddf8c5e4ef2778a5d7a77ad12f08da711fecfc44795c7923739a2acac946b3f1719a6dfc238695bc69cf5d959b3fb6bc4d18d57a97ff8ed897e6b22a6b8155401ee368d77431e74178104b4adca73520b058b9be28d4ec129beb54871778167afa5ce")] +//#else [assembly: InternalsVisibleTo("LiveChartsCore.SkiaSharpView")] [assembly: InternalsVisibleTo("LiveChartsCore.SkiaSharpView.Avalonia")] [assembly: InternalsVisibleTo("LiveChartsCore.SkiaSharpView.WinForms")] @@ -50,4 +50,4 @@ [assembly: InternalsVisibleTo("LiveChartsCore.SkiaSharpView.Blazor")] [assembly: InternalsVisibleTo("LiveChartsCore.SkiaSharpView.Maui")] [assembly: InternalsVisibleTo("LiveChartsCore.BackersPackage")] -#endif +//#endif diff --git a/src/LiveChartsCore/Defaults/DateTimePoint.cs b/src/LiveChartsCore/Defaults/DateTimePoint.cs index 971e31a3c..e2b79b32e 100644 --- a/src/LiveChartsCore/Defaults/DateTimePoint.cs +++ b/src/LiveChartsCore/Defaults/DateTimePoint.cs @@ -38,7 +38,7 @@ public class DateTimePoint : IChartEntity, INotifyPropertyChanged /// /// Initializes a new instance of the class. /// - public DateTimePoint() + public DateTimePoint() : this(DateTime.Now, 0) { } /// @@ -50,6 +50,7 @@ public DateTimePoint(DateTime dateTime, double? value) { _dateTime = dateTime; _value = value; + OnCoordinateChanged(); } /// @@ -58,7 +59,16 @@ public DateTimePoint(DateTime dateTime, double? value) /// /// The date time. /// - public DateTime DateTime { get => _dateTime; set { _dateTime = value; OnPropertyChanged(); } } + public DateTime DateTime + { + get => _dateTime; + set + { + _dateTime = value; + OnCoordinateChanged(); + OnPropertyChanged(); + } + } /// /// Gets or sets the value. @@ -66,7 +76,16 @@ public DateTimePoint(DateTime dateTime, double? value) /// /// The value. /// - public double? Value { get => _value; set { _value = value; OnPropertyChanged(); } } + public double? Value + { + get => _value; + set + { + _value = value; + OnCoordinateChanged(); + OnPropertyChanged(); + } + } /// public ChartPoint? ChartPoint { get; set; } @@ -75,7 +94,7 @@ public DateTimePoint(DateTime dateTime, double? value) public int EntityId { get; set; } /// - public Coordinate Coordinate => new(_dateTime.Ticks, _value ?? 0d); + public Coordinate Coordinate { get; protected set; } /// /// Occurs when a property value changes. @@ -91,4 +110,14 @@ protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName { PropertyChanged?.Invoke(propertyName, new PropertyChangedEventArgs(propertyName)); } + + /// + /// Called when the coordinate changes. + /// + protected virtual void OnCoordinateChanged() + { + Coordinate = _value is null + ? Coordinate.Empty + : new(_dateTime.Ticks, _value.Value); + } } diff --git a/src/LiveChartsCore/Defaults/FinancialPoint.cs b/src/LiveChartsCore/Defaults/FinancialPoint.cs index b1fd6219d..cf2e78b7e 100644 --- a/src/LiveChartsCore/Defaults/FinancialPoint.cs +++ b/src/LiveChartsCore/Defaults/FinancialPoint.cs @@ -32,16 +32,16 @@ namespace LiveChartsCore.Defaults; /// public class FinancialPoint : IChartEntity, INotifyPropertyChanged { - private double _high; - private double _open; - private double _close; - private double _low; + private double? _high; + private double? _open; + private double? _close; + private double? _low; private DateTime _date; /// /// Initializes a new instance of the class. /// - public FinancialPoint() + public FinancialPoint() : this(DateTime.Now, 0, 0, 0, 0) { } /// @@ -52,13 +52,14 @@ public FinancialPoint() /// The open. /// The close. /// The low. - public FinancialPoint(DateTime date, double high, double open, double close, double low) + public FinancialPoint(DateTime date, double? high, double? open, double? close, double? low) { _date = date; _high = high; _open = open; _close = close; _low = low; + OnCoordinateChanged(); } /// @@ -67,7 +68,16 @@ public FinancialPoint(DateTime date, double high, double open, double close, dou /// /// The date. /// - public DateTime Date { get => _date; set { _date = value; OnPropertyChanged(); } } + public DateTime Date + { + get => _date; + set + { + _date = value; + OnCoordinateChanged(); + OnPropertyChanged(); + } + } /// /// Gets or sets the high. @@ -75,7 +85,16 @@ public FinancialPoint(DateTime date, double high, double open, double close, dou /// /// The high. /// - public double High { get => _high; set { _high = value; OnPropertyChanged(); } } + public double? High + { + get => _high; + set + { + _high = value; + OnCoordinateChanged(); + OnPropertyChanged(); + } + } /// /// Gets or sets the open. @@ -83,7 +102,16 @@ public FinancialPoint(DateTime date, double high, double open, double close, dou /// /// The open. /// - public double Open { get => _open; set { _open = value; OnPropertyChanged(); } } + public double? Open + { + get => _open; + set + { + _open = value; + OnCoordinateChanged(); + OnPropertyChanged(); + } + } /// /// Gets or sets the close. @@ -91,7 +119,16 @@ public FinancialPoint(DateTime date, double high, double open, double close, dou /// /// The close. /// - public double Close { get => _close; set { _close = value; OnPropertyChanged(); } } + public double? Close + { + get => _close; + set + { + _close = value; + OnCoordinateChanged(); + OnPropertyChanged(); + } + } /// /// Gets or sets the low. @@ -99,7 +136,16 @@ public FinancialPoint(DateTime date, double high, double open, double close, dou /// /// The low. /// - public double Low { get => _low; set { _low = value; OnPropertyChanged(); } } + public double? Low + { + get => _low; + set + { + _low = value; + OnCoordinateChanged(); + OnPropertyChanged(); + } + } /// public ChartPoint? ChartPoint { get; set; } @@ -108,7 +154,7 @@ public FinancialPoint(DateTime date, double high, double open, double close, dou public int EntityId { get; set; } /// - public Coordinate Coordinate => new(_high, _date.Ticks, _open, _close, _low); + public Coordinate Coordinate { get; protected set; } /// /// Occurs when a property value changes. @@ -124,4 +170,14 @@ protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName { PropertyChanged?.Invoke(propertyName, new PropertyChangedEventArgs(propertyName)); } + + /// + /// Called when the coordinate changes. + /// + protected virtual void OnCoordinateChanged() + { + Coordinate = _open is null || _high is null || _low is null || _close is null + ? Coordinate.Empty + : new(_high.Value, _date.Ticks, _open.Value, _close.Value, _low.Value); + } } diff --git a/src/LiveChartsCore/Defaults/ObservablePoint.cs b/src/LiveChartsCore/Defaults/ObservablePoint.cs index 2f0eb7fd6..e0f3a0cd3 100644 --- a/src/LiveChartsCore/Defaults/ObservablePoint.cs +++ b/src/LiveChartsCore/Defaults/ObservablePoint.cs @@ -38,7 +38,7 @@ public class ObservablePoint : IChartEntity, INotifyPropertyChanged /// /// Initializes a new instance of the class. /// - public ObservablePoint() + public ObservablePoint() : this(0d, 0d) { } /// @@ -50,6 +50,7 @@ public ObservablePoint(double? x, double? y) { _x = x; _y = y; + OnCoordinateChanged(); } /// @@ -58,7 +59,16 @@ public ObservablePoint(double? x, double? y) /// /// The x. /// - public double? X { get => _x; set { _x = value; OnPropertyChanged(); } } + public double? X + { + get => _x; + set + { + _x = value; + OnCoordinateChanged(); + OnPropertyChanged(); + } + } /// /// Gets or sets the y coordinate. @@ -66,7 +76,16 @@ public ObservablePoint(double? x, double? y) /// /// The y. /// - public double? Y { get => _y; set { _y = value; OnPropertyChanged(); } } + public double? Y + { + get => _y; + set + { + _y = value; + OnCoordinateChanged(); + OnPropertyChanged(); + } + } /// public ChartPoint? ChartPoint { get; set; } @@ -75,7 +94,7 @@ public ObservablePoint(double? x, double? y) public int EntityId { get; set; } /// - public Coordinate Coordinate => new(_x ?? 0d, _y ?? 0d); + public Coordinate Coordinate { get; private set; } /// /// Occurs when a property value changes. @@ -84,11 +103,21 @@ public ObservablePoint(double? x, double? y) public event PropertyChangedEventHandler? PropertyChanged; /// - /// Called when a property changed. + /// Called when a property changes. /// /// Name of the property. protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null) { PropertyChanged?.Invoke(propertyName, new PropertyChangedEventArgs(propertyName)); } + + /// + /// Called when the coordinate changes. + /// + protected virtual void OnCoordinateChanged() + { + Coordinate = _x is null || _y is null + ? Coordinate.Empty + : new(_x.Value, _y.Value); + } } diff --git a/src/LiveChartsCore/Defaults/ObservablePolarPoint.cs b/src/LiveChartsCore/Defaults/ObservablePolarPoint.cs index 7003f928b..d03711be4 100644 --- a/src/LiveChartsCore/Defaults/ObservablePolarPoint.cs +++ b/src/LiveChartsCore/Defaults/ObservablePolarPoint.cs @@ -37,7 +37,7 @@ public class ObservablePolarPoint : IChartEntity, INotifyPropertyChanged /// /// Initializes a new instance of the class. /// - public ObservablePolarPoint() + public ObservablePolarPoint() : this(0, 0) { } /// @@ -49,17 +49,36 @@ public ObservablePolarPoint(double? angle, double? radius) { _angle = angle; _radius = radius; + OnCoordinateChanged(); } /// /// Gets or sets the angle. /// - public double? Angle { get => _angle; set { _angle = value; OnPropertyChanged(); } } + public double? Angle + { + get => _angle; + set + { + _angle = value; + OnCoordinateChanged(); + OnPropertyChanged(); + } + } /// /// Gets or sets the Radius. /// - public double? Radius { get => _radius; set { _radius = value; OnPropertyChanged(); } } + public double? Radius + { + get => _radius; + set + { + _radius = value; + OnCoordinateChanged(); + OnPropertyChanged(); + } + } /// public ChartPoint? ChartPoint { get; set; } @@ -68,7 +87,7 @@ public ObservablePolarPoint(double? angle, double? radius) public int EntityId { get; set; } /// - public Coordinate Coordinate => new(_radius ?? 0d, _angle ?? 0d, 0d, 0d, 0d); + public Coordinate Coordinate { get; protected set; } /// /// Called when a property changes. @@ -82,4 +101,14 @@ protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } + + /// + /// Called when the coordinate changes. + /// + protected virtual void OnCoordinateChanged() + { + Coordinate = _radius is null || _angle is null + ? Coordinate.Empty + : new(_radius.Value, _angle.Value); + } } diff --git a/src/LiveChartsCore/Defaults/ObservableValue.cs b/src/LiveChartsCore/Defaults/ObservableValue.cs index b3ea86fbd..7f64b3ee5 100644 --- a/src/LiveChartsCore/Defaults/ObservableValue.cs +++ b/src/LiveChartsCore/Defaults/ObservableValue.cs @@ -33,11 +33,12 @@ namespace LiveChartsCore.Defaults; public class ObservableValue : IChartEntity, INotifyPropertyChanged { private double? _value; + private int _entityId; /// /// Initializes a new instance of the class. /// - public ObservableValue() + public ObservableValue() : this(0) { } /// @@ -47,6 +48,7 @@ public ObservableValue() public ObservableValue(double? value) { _value = value; + OnCoordinateChanged(); } /// @@ -55,16 +57,33 @@ public ObservableValue(double? value) /// /// The value. /// - public double? Value { get => _value; set { _value = value; OnPropertyChanged(); } } + public double? Value + { + get => _value; + set + { + _value = value; + OnCoordinateChanged(); + OnPropertyChanged(); + } + } /// public ChartPoint? ChartPoint { get; set; } /// - public int EntityId { get; set; } + public int EntityId + { + get => _entityId; + set + { + _entityId = value; + OnCoordinateChanged(); + } + } /// - public Coordinate Coordinate => new(EntityId, _value ?? 0d); + public Coordinate Coordinate { get; protected set; } /// /// Occurs when a property value changes. @@ -80,4 +99,14 @@ protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName { PropertyChanged?.Invoke(propertyName, new PropertyChangedEventArgs(propertyName)); } + + /// + /// Called when the coordinate changes. + /// + protected virtual void OnCoordinateChanged() + { + Coordinate = _value is null + ? Coordinate.Empty + : new(_entityId, _value.Value); + } } diff --git a/src/LiveChartsCore/Defaults/TimeSpanPoint.cs b/src/LiveChartsCore/Defaults/TimeSpanPoint.cs index 2b483ce8c..0ef4bf5c5 100644 --- a/src/LiveChartsCore/Defaults/TimeSpanPoint.cs +++ b/src/LiveChartsCore/Defaults/TimeSpanPoint.cs @@ -38,7 +38,7 @@ public class TimeSpanPoint : IChartEntity, INotifyPropertyChanged /// /// Initializes a new instance of the class. /// - public TimeSpanPoint() + public TimeSpanPoint() : this(TimeSpan.Zero, 0) { } /// @@ -50,6 +50,7 @@ public TimeSpanPoint(TimeSpan timeSpan, double? value) { _timeSpan = timeSpan; _value = value; + OnCoordinateChanged(); } /// @@ -58,7 +59,16 @@ public TimeSpanPoint(TimeSpan timeSpan, double? value) /// /// The date time. /// - public TimeSpan TimeSpan { get => _timeSpan; set { _timeSpan = value; OnPropertyChanged(); } } + public TimeSpan TimeSpan + { + get => _timeSpan; + set + { + _timeSpan = value; + OnCoordinateChanged(); + OnPropertyChanged(); + } + } /// /// Gets or sets the value. @@ -66,7 +76,16 @@ public TimeSpanPoint(TimeSpan timeSpan, double? value) /// /// The value. /// - public double? Value { get => _value; set { _value = value; OnPropertyChanged(); } } + public double? Value + { + get => _value; + set + { + _value = value; + OnCoordinateChanged(); + OnPropertyChanged(); + } + } /// public ChartPoint? ChartPoint { get; set; } @@ -75,7 +94,7 @@ public TimeSpanPoint(TimeSpan timeSpan, double? value) public int EntityId { get; set; } /// - public Coordinate Coordinate => new(_timeSpan.Ticks, _value ?? 0d); + public Coordinate Coordinate { get; protected set; } /// /// Occurs when a property value changes. @@ -91,4 +110,14 @@ protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName { PropertyChanged?.Invoke(propertyName, new PropertyChangedEventArgs(propertyName)); } + + /// + /// Called when the coordinate changes. + /// + protected virtual void OnCoordinateChanged() + { + Coordinate = _value is null + ? Coordinate.Empty + : new(_timeSpan.Ticks, _value ?? 0d); + } } diff --git a/src/LiveChartsCore/Defaults/WeightedPoint.cs b/src/LiveChartsCore/Defaults/WeightedPoint.cs index f570e54c8..7e7450162 100644 --- a/src/LiveChartsCore/Defaults/WeightedPoint.cs +++ b/src/LiveChartsCore/Defaults/WeightedPoint.cs @@ -39,7 +39,7 @@ public class WeightedPoint : IChartEntity, INotifyPropertyChanged /// /// Initializes a new instance of the class. /// - public WeightedPoint() + public WeightedPoint() : this(0, 0, 0) { } /// @@ -53,6 +53,7 @@ public WeightedPoint(double? x, double? y, double? weight) _x = x; _y = y; _weight = weight; + OnCoordinateChanged(); } /// @@ -61,7 +62,16 @@ public WeightedPoint(double? x, double? y, double? weight) /// /// The x. /// - public double? X { get => _x; set { _x = value; OnPropertyChanged(); } } + public double? X + { + get => _x; + set + { + _x = value; + OnCoordinateChanged(); + OnPropertyChanged(); + } + } /// /// Gets or sets the y. @@ -69,7 +79,16 @@ public WeightedPoint(double? x, double? y, double? weight) /// /// The y. /// - public double? Y { get => _y; set { _y = value; OnPropertyChanged(); } } + public double? Y + { + get => _y; + set + { + _y = value; + OnCoordinateChanged(); + OnPropertyChanged(); + } + } /// /// Gets or sets the weight. @@ -77,7 +96,16 @@ public WeightedPoint(double? x, double? y, double? weight) /// /// The weight. /// - public double? Weight { get => _weight; set { _weight = value; OnPropertyChanged(); } } + public double? Weight + { + get => _weight; + set + { + _weight = value; + OnCoordinateChanged(); + OnPropertyChanged(); + } + } /// public ChartPoint? ChartPoint { get; set; } @@ -86,7 +114,7 @@ public WeightedPoint(double? x, double? y, double? weight) public int EntityId { get; set; } /// - public Coordinate Coordinate => new(_x ?? 0, _y ?? 0, _weight ?? 0); + public Coordinate Coordinate { get; protected set; } /// /// Occurs when a property value changes. @@ -102,4 +130,14 @@ protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName { PropertyChanged?.Invoke(propertyName, new PropertyChangedEventArgs(propertyName)); } + + /// + /// Called when the coordinate changes. + /// + protected virtual void OnCoordinateChanged() + { + Coordinate = _x is null || _y is null + ? Coordinate.Empty + : new(_x ?? 0, _y ?? 0, _weight ?? 0); + } } diff --git a/src/LiveChartsCore/Kernel/Coordinate.cs b/src/LiveChartsCore/Kernel/Coordinate.cs index b0a1d6307..4f944bb15 100644 --- a/src/LiveChartsCore/Kernel/Coordinate.cs +++ b/src/LiveChartsCore/Kernel/Coordinate.cs @@ -73,7 +73,7 @@ private Coordinate(bool isEmpty) : this(0, 0, 0, 0, 0) /// /// Gets an empty coordinate instance. /// - public static readonly Coordinate Empty = new(true); + public static Coordinate Empty => new(true); /// /// Evaluates whether the instance is empty. diff --git a/src/LiveChartsCore/Kernel/LiveChartsSettings.cs b/src/LiveChartsCore/Kernel/LiveChartsSettings.cs index 97d857186..dd8cb0851 100644 --- a/src/LiveChartsCore/Kernel/LiveChartsSettings.cs +++ b/src/LiveChartsCore/Kernel/LiveChartsSettings.cs @@ -460,11 +460,11 @@ public LiveChartsSettings AddDefaultMappers() throw new Exception( $"A {nameof(FinancialPoint)} can not be null"); - point.PrimaryValue = model.High; + point.PrimaryValue = model.High.Value; point.SecondaryValue = model.Date.Ticks; - point.TertiaryValue = model.Open; - point.QuaternaryValue = model.Close; - point.QuinaryValue = model.Low; + point.TertiaryValue = model.Open.Value; + point.QuaternaryValue = model.Close.Value; + point.QuinaryValue = model.Low.Value; }); } } diff --git a/src/LiveChartsCore/LineSeries.cs b/src/LiveChartsCore/LineSeries.cs index f815da20c..45854a291 100644 --- a/src/LiveChartsCore/LineSeries.cs +++ b/src/LiveChartsCore/LineSeries.cs @@ -249,7 +249,6 @@ public override void Measure(Chart chart) var visual = (TVisualPoint?)data.TargetPoint.Context.Visual; - if (visual is null) { var v = new TVisualPoint(); diff --git a/src/skiasharp/LiveChartsCore.SkiaSharp/AssemblyInfo.cs b/src/skiasharp/LiveChartsCore.SkiaSharp/AssemblyInfo.cs index 9f5a39c7a..aaf8049af 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharp/AssemblyInfo.cs +++ b/src/skiasharp/LiveChartsCore.SkiaSharp/AssemblyInfo.cs @@ -21,12 +21,12 @@ // SOFTWARE. using System.Runtime.CompilerServices; -#if !DEBUG -using System.Reflection; +//#if !DEBUG +//using System.Reflection; -[assembly: AssemblyKeyFile("./../../../LiveCharts.snk")] -[assembly: InternalsVisibleTo("LiveChartsCore.BackersPackage, PublicKey=0024000004800000940000000602000000240000525341310004000001000100d53791eaa0d98b405ca858f39169be6af36ceb7a1bca3ca76c6905fd22fddf8c5e4ef2778a5d7a77ad12f08da711fecfc44795c7923739a2acac946b3f1719a6dfc238695bc69cf5d959b3fb6bc4d18d57a97ff8ed897e6b22a6b8155401ee368d77431e74178104b4adca73520b058b9be28d4ec129beb54871778167afa5ce")] -#else +//[assembly: AssemblyKeyFile("./../../../LiveCharts.snk")] +//[assembly: InternalsVisibleTo("LiveChartsCore.BackersPackage, PublicKey=0024000004800000940000000602000000240000525341310004000001000100d53791eaa0d98b405ca858f39169be6af36ceb7a1bca3ca76c6905fd22fddf8c5e4ef2778a5d7a77ad12f08da711fecfc44795c7923739a2acac946b3f1719a6dfc238695bc69cf5d959b3fb6bc4d18d57a97ff8ed897e6b22a6b8155401ee368d77431e74178104b4adca73520b058b9be28d4ec129beb54871778167afa5ce")] +//#else [assembly: InternalsVisibleTo("LiveChartsCore.BackersPackage")] -#endif +//#endif From f5f57dd2414b94a2069f94f7fe1cab687177886e Mon Sep 17 00:00:00 2001 From: beto-rodriguez Date: Tue, 16 Aug 2022 21:04:50 -0500 Subject: [PATCH 05/25] use empty coordinate --- samples/ViewModelsSamples/Index.cs | 208 +++++++++--------- src/LiveChartsCore/ColumnSeries.cs | 2 +- src/LiveChartsCore/FinancialSeries.cs | 2 +- src/LiveChartsCore/HeatSeries.cs | 2 +- src/LiveChartsCore/Kernel/ChartPoint.cs | 1 + .../Kernel/LiveChartsSettings.cs | 111 ---------- .../Measure/MeasureExtensions.cs | 2 +- src/LiveChartsCore/PieSeries.cs | 2 +- src/LiveChartsCore/PolarLineSeries.cs | 2 +- src/LiveChartsCore/RowSeries.cs | 2 +- src/LiveChartsCore/ScatterSeries.cs | 2 +- 11 files changed, 113 insertions(+), 223 deletions(-) diff --git a/samples/ViewModelsSamples/Index.cs b/samples/ViewModelsSamples/Index.cs index b5471ebdc..4474da96c 100644 --- a/samples/ViewModelsSamples/Index.cs +++ b/samples/ViewModelsSamples/Index.cs @@ -4,111 +4,111 @@ public static class Index { public static string[] Samples = { - //"Design/LinearGradients", - //"Design/RadialGradients", + "Design/LinearGradients", + "Design/RadialGradients", "Lines/Basic", - //"Lines/AutoUpdate", - //"Lines/Straight", - //"Lines/Properties", - //"Lines/Area", - //"Lines/Custom", - //"Lines/Padding", - //"Lines/XY", - //"Lines/Zoom", - - //"StepLines/Basic", - //"StepLines/AutoUpdate", - //"StepLines/Properties", - //"StepLines/Area", - //"StepLines/Custom", - //"StepLines/Zoom", - - //"StackedArea/Basic", - //"StackedArea/StepArea", - - //"Bars/Basic", - //"Bars/AutoUpdate", - //"Bars/Custom", - //"Bars/WithBackground", - //"Bars/Spacing", - //"Bars/DelayedAnimation", - //"Bars/Race", - //"Bars/RowsWithLabels", - //"Bars/Layered", - - //"StackedBars/Basic", - //"StackedBars/Groups", - - //"Pies/Basic", - //"Pies/AutoUpdate", - //"Pies/Processing", - //"Pies/Doughnut", - //"Pies/Pushout", - //"Pies/Custom", - //"Pies/NightingaleRose", - //"Pies/Gauges", - ////"Pies/Gauge", - //"Pies/Gauge1", - //"Pies/Gauge2", - //"Pies/Gauge3", - //"Pies/Gauge4", - //"Pies/Gauge5", - - //"Scatter/Basic", - //"Scatter/Bubbles", - //"Scatter/AutoUpdate", - //"Scatter/Custom", - - //"Financial/BasicCandlesticks", - - //"Heat/Basic", - - //"Polar/Basic", - //"Polar/RadialArea", - //"Polar/Coordinates", - - //"Axes/ColorsAndPosition", - //"Axes/LabelsFormat", - //"Axes/LabelsFormat2", - //"Axes/NamedLabels", - //"Axes/LabelsRotation", - //"Axes/Multiple", - //"Axes/Shared", - //"Axes/DateTimeScaled", - //"Axes/TimeSpanScaled", - //"Axes/Logarithmic", - //"Axes/Style", - //"Axes/Paging", - - //"Events/AddPointOnClick", - //"Events/Cartesian", - //"Events/Pie", - //"Events/Polar", - - //"General/Sections", - //"General/Sections2", - //"General/ChartToImage", - //"General/Tooltips", - //"General/Legends", - //"General/Animations", - //"General/Visibility", - //"General/TemplatedTooltips", - //"General/TemplatedLegends", - //"General/UserDefinedTypes", - //"General/NullPoints", - //"General/MultiThreading", - //"General/MultiThreading2", - - //"VisualTest/TwoChartsOneSeries", - //"VisualTest/ReattachVisual", - //"VisualTest/DataTemplate", - //"VisualTest/Tabs", - - ////"Test/ChangeSeriesInstance", - ////"Test/Dispose", - ////"Test/MotionCanvasDispose", - - //"Maps/World" + "Lines/AutoUpdate", + "Lines/Straight", + "Lines/Properties", + "Lines/Area", + "Lines/Custom", + "Lines/Padding", + "Lines/XY", + "Lines/Zoom", + + "StepLines/Basic", + "StepLines/AutoUpdate", + "StepLines/Properties", + "StepLines/Area", + "StepLines/Custom", + "StepLines/Zoom", + + "StackedArea/Basic", + "StackedArea/StepArea", + + "Bars/Basic", + "Bars/AutoUpdate", + "Bars/Custom", + "Bars/WithBackground", + "Bars/Spacing", + "Bars/DelayedAnimation", + "Bars/Race", + "Bars/RowsWithLabels", + "Bars/Layered", + + "StackedBars/Basic", + "StackedBars/Groups", + + "Pies/Basic", + "Pies/AutoUpdate", + "Pies/Processing", + "Pies/Doughnut", + "Pies/Pushout", + "Pies/Custom", + "Pies/NightingaleRose", + "Pies/Gauges", + //"Pies/Gauge", + "Pies/Gauge1", + "Pies/Gauge2", + "Pies/Gauge3", + "Pies/Gauge4", + "Pies/Gauge5", + + "Scatter/Basic", + "Scatter/Bubbles", + "Scatter/AutoUpdate", + "Scatter/Custom", + + "Financial/BasicCandlesticks", + + "Heat/Basic", + + "Polar/Basic", + "Polar/RadialArea", + "Polar/Coordinates", + + "Axes/ColorsAndPosition", + "Axes/LabelsFormat", + "Axes/LabelsFormat2", + "Axes/NamedLabels", + "Axes/LabelsRotation", + "Axes/Multiple", + "Axes/Shared", + "Axes/DateTimeScaled", + "Axes/TimeSpanScaled", + "Axes/Logarithmic", + "Axes/Style", + "Axes/Paging", + + "Events/AddPointOnClick", + "Events/Cartesian", + "Events/Pie", + "Events/Polar", + + "General/Sections", + "General/Sections2", + "General/ChartToImage", + "General/Tooltips", + "General/Legends", + "General/Animations", + "General/Visibility", + "General/TemplatedTooltips", + "General/TemplatedLegends", + "General/UserDefinedTypes", + "General/NullPoints", + "General/MultiThreading", + "General/MultiThreading2", + + "VisualTest/TwoChartsOneSeries", + "VisualTest/ReattachVisual", + "VisualTest/DataTemplate", + "VisualTest/Tabs", + + //"Test/ChangeSeriesInstance", + //"Test/Dispose", + //"Test/MotionCanvasDispose", + + "Maps/World" }; } diff --git a/src/LiveChartsCore/ColumnSeries.cs b/src/LiveChartsCore/ColumnSeries.cs index bdf795fc2..86e0b7453 100644 --- a/src/LiveChartsCore/ColumnSeries.cs +++ b/src/LiveChartsCore/ColumnSeries.cs @@ -115,7 +115,7 @@ public override void Measure(Chart chart) var secondary = secondaryScale.ToPixels(point.SecondaryValue); var b = Math.Abs(primary - helper.p); - if (point.IsNull) + if (point.Coordinate.IsEmpty || point.IsNull) { if (visual is not null) { diff --git a/src/LiveChartsCore/FinancialSeries.cs b/src/LiveChartsCore/FinancialSeries.cs index 1de6e2078..2b4fbe89f 100644 --- a/src/LiveChartsCore/FinancialSeries.cs +++ b/src/LiveChartsCore/FinancialSeries.cs @@ -166,7 +166,7 @@ public override void Measure(Chart chart) var low = primaryScale.ToPixels(point.QuinaryValue); var middle = open; - if (point.IsNull) + if (point.Coordinate.IsEmpty || point.IsNull) { if (visual is not null) { diff --git a/src/LiveChartsCore/HeatSeries.cs b/src/LiveChartsCore/HeatSeries.cs index f923486a4..48a27bcf8 100644 --- a/src/LiveChartsCore/HeatSeries.cs +++ b/src/LiveChartsCore/HeatSeries.cs @@ -128,7 +128,7 @@ public override void Measure(Chart chart) var baseColor = HeatFunctions.InterpolateColor(tertiary, _weightBounds, HeatMap, _heatStops); - if (point.IsNull) + if (point.Coordinate.IsEmpty || point.IsNull) { if (visual is not null) { diff --git a/src/LiveChartsCore/Kernel/ChartPoint.cs b/src/LiveChartsCore/Kernel/ChartPoint.cs index f960e373d..533f18dd7 100644 --- a/src/LiveChartsCore/Kernel/ChartPoint.cs +++ b/src/LiveChartsCore/Kernel/ChartPoint.cs @@ -56,6 +56,7 @@ public ChartPoint(IChartView chart, ISeries series) /// /// true if this instance is empty; otherwise, false. /// + [Obsolete($"Replaced by {nameof(Coordinate)}.{nameof(Coordinate.Empty)}")] public bool IsEmpty { get; set; } /// diff --git a/src/LiveChartsCore/Kernel/LiveChartsSettings.cs b/src/LiveChartsCore/Kernel/LiveChartsSettings.cs index dd8cb0851..98e03e32c 100644 --- a/src/LiveChartsCore/Kernel/LiveChartsSettings.cs +++ b/src/LiveChartsCore/Kernel/LiveChartsSettings.cs @@ -354,117 +354,6 @@ public LiveChartsSettings AddDefaultMappers() point.IsNull = false; point.PrimaryValue = unchecked((double)model.Value); point.SecondaryValue = point.Context.Index; - }) - .HasMap((model, point) => - { - if (model is null) - throw new Exception( - $"A {nameof(WeightedPoint)} can not be null, instead set to null to any of its properties."); - - if (model.Weight is null || model.X is null || model.Y is null) - { - point.IsNull = true; - return; - } - - point.IsNull = false; - point.PrimaryValue = model.Y.Value; - point.SecondaryValue = model.X.Value; - point.TertiaryValue = model.Weight.Value; - }) - .HasMap((model, point) => - { - if (model is null) - throw new Exception( - $"A {nameof(ObservableValue)} can not be null, instead set to null to any of its properties."); - - if (model.Value is null) - { - point.IsNull = true; - return; - } - - point.IsNull = false; - point.PrimaryValue = model.Value.Value; - point.SecondaryValue = point.Context.Index; - }) - .HasMap((model, point) => - { - if (model is null) - throw new Exception( - $"A {nameof(ObservablePoint)} can not be null, instead set to null to any of its properties."); - - if (model.X is null || model.Y is null) - { - point.IsNull = true; - return; - } - - point.IsNull = false; - point.PrimaryValue = model.Y.Value; - point.SecondaryValue = model.X.Value; - }) - .HasMap((model, point) => - { - if (model is null) - throw new Exception( - $"A {nameof(ObservablePolarPoint)} can not be null, instead set to null to any of its properties."); - - if (model.Angle is null || model.Radius is null) - { - point.IsNull = true; - return; - } - - point.IsNull = false; - point.PrimaryValue = model.Radius.Value; - point.SecondaryValue = model.Angle.Value; - }) - .HasMap((model, point) => - { - if (model is null) - throw new Exception( - $"A {nameof(DateTimePoint)} can not be null, instead set to null the " + - $"{nameof(DateTimePoint.Value)} property."); - - if (model.Value is null) - { - point.IsNull = true; - return; - } - - point.IsNull = false; - point.PrimaryValue = model.Value.Value; - point.SecondaryValue = model.DateTime.Ticks; - }) - .HasMap((model, point) => - { - if (model is null) - throw new Exception( - $"A {nameof(TimeSpanPoint)} can not be null, instead set to null the " + - $"{nameof(TimeSpanPoint.Value)} property."); - - if (model.Value is null) - { - point.IsNull = true; - return; - } - - point.IsNull = false; - point.PrimaryValue = model.Value.Value; - point.SecondaryValue = model.TimeSpan.Ticks; - }) - .HasMap((model, point) => - { - if (model is null) - throw new Exception( - $"A {nameof(FinancialPoint)} can not be null"); - - point.PrimaryValue = model.High.Value; - point.SecondaryValue = model.Date.Ticks; - point.TertiaryValue = model.Open.Value; - point.QuaternaryValue = model.Close.Value; - point.QuinaryValue = model.Low.Value; }); } } diff --git a/src/LiveChartsCore/Measure/MeasureExtensions.cs b/src/LiveChartsCore/Measure/MeasureExtensions.cs index c2143700b..0f38c6b2c 100644 --- a/src/LiveChartsCore/Measure/MeasureExtensions.cs +++ b/src/LiveChartsCore/Measure/MeasureExtensions.cs @@ -85,7 +85,7 @@ private static IEnumerable YieldReturnUntilNextNullChartPoint( { while (builder.Enumerator.MoveNext()) { - if (builder.Enumerator.Current.IsNull) + if (builder.Enumerator.Current.Coordinate.IsEmpty || builder.Enumerator.Current.IsNull) { var wasEmpty = builder.IsEmpty; builder.IsEmpty = true; diff --git a/src/LiveChartsCore/PieSeries.cs b/src/LiveChartsCore/PieSeries.cs index 75d4ef79b..53178a74c 100644 --- a/src/LiveChartsCore/PieSeries.cs +++ b/src/LiveChartsCore/PieSeries.cs @@ -232,7 +232,7 @@ public override void Measure(Chart chart) { var visual = point.Context.Visual as TVisual; - if (point.IsNull) + if (point.Coordinate.IsEmpty || point.IsNull) { if (visual is not null) { diff --git a/src/LiveChartsCore/PolarLineSeries.cs b/src/LiveChartsCore/PolarLineSeries.cs index fe92d3c8f..7ca8d7a8c 100644 --- a/src/LiveChartsCore/PolarLineSeries.cs +++ b/src/LiveChartsCore/PolarLineSeries.cs @@ -857,7 +857,7 @@ private IEnumerable SplitEachNull( foreach (var point in points) { - if (point.IsNull) + if (point.Coordinate.IsEmpty || point.IsNull) { if (point.Context.Visual is TVisualPoint visual) { diff --git a/src/LiveChartsCore/RowSeries.cs b/src/LiveChartsCore/RowSeries.cs index 979204eb3..82e016803 100644 --- a/src/LiveChartsCore/RowSeries.cs +++ b/src/LiveChartsCore/RowSeries.cs @@ -116,7 +116,7 @@ public override void Measure(Chart chart) var secondary = secondaryScale.ToPixels(point.SecondaryValue); var b = Math.Abs(primary - helper.p); - if (point.IsNull) + if (point.Coordinate.IsEmpty || point.IsNull) { if (visual is not null) { diff --git a/src/LiveChartsCore/ScatterSeries.cs b/src/LiveChartsCore/ScatterSeries.cs index 8ef7a1ae8..e201b0800 100644 --- a/src/LiveChartsCore/ScatterSeries.cs +++ b/src/LiveChartsCore/ScatterSeries.cs @@ -129,7 +129,7 @@ public override void Measure(Chart chart) var x = xScale.ToPixels(point.SecondaryValue); var y = yScale.ToPixels(point.PrimaryValue); - if (point.IsNull) + if (point.Coordinate.IsEmpty || point.IsNull) { if (visual is not null) { From a9bfc43a9c9e3e811f3fd75e7726527e560826f6 Mon Sep 17 00:00:00 2001 From: beto-rodriguez Date: Tue, 16 Aug 2022 21:20:22 -0500 Subject: [PATCH 06/25] restore basic line sample --- samples/ViewModelsSamples/Lines/Basic/ViewModel.cs | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/samples/ViewModelsSamples/Lines/Basic/ViewModel.cs b/samples/ViewModelsSamples/Lines/Basic/ViewModel.cs index 1699db57b..09319ef40 100644 --- a/samples/ViewModelsSamples/Lines/Basic/ViewModel.cs +++ b/samples/ViewModelsSamples/Lines/Basic/ViewModel.cs @@ -1,6 +1,5 @@ using CommunityToolkit.Mvvm.ComponentModel; using LiveChartsCore; -using LiveChartsCore.Defaults; using LiveChartsCore.SkiaSharpView; namespace ViewModelsSamples.Lines.Basic; @@ -10,16 +9,9 @@ public partial class ViewModel { public ISeries[] Series { get; set; } = { - new LineSeries + new LineSeries { - Values = new ObservablePoint[] - { - new ObservablePoint { X = 2, Y = 0 }, - new ObservablePoint { X = 3, Y = 3 }, - new ObservablePoint { X = 5, Y = null }, - new ObservablePoint { X = 6, Y = 4 }, - new ObservablePoint { X = 8, Y = 6 } - }, + Values = new double[] { 2, 1, 3, 5, 3, 4, 6 }, Fill = null } }; From 893e875ce66294311888ac191332af6af372f314 Mon Sep 17 00:00:00 2001 From: beto-rodriguez Date: Tue, 16 Aug 2022 23:45:29 -0500 Subject: [PATCH 07/25] adds support for null types, datafactory cleanup --- .../ChartEntity.cs} | 42 ++-- .../Defaults/ObservablePolarPoint.cs | 2 +- src/LiveChartsCore/Kernel/ChartPoint.cs | 28 ++- .../Kernel/ChartPointContext.cs | 8 + .../Kernel/LiveChartsSettings.cs | 88 +++---- .../{ChartProvider.cs => ChartEngine.cs} | 9 +- .../Kernel/Providers/DataFactory.cs | 230 +++++++++--------- src/LiveChartsCore/Series.cs | 4 +- .../SkiaSharpProvider.cs | 12 +- 9 files changed, 214 insertions(+), 209 deletions(-) rename src/LiveChartsCore/{Kernel/Providers/EntitiesDataFactory.cs => Defaults/ChartEntity.cs} (51%) rename src/LiveChartsCore/Kernel/Providers/{ChartProvider.cs => ChartEngine.cs} (85%) diff --git a/src/LiveChartsCore/Kernel/Providers/EntitiesDataFactory.cs b/src/LiveChartsCore/Defaults/ChartEntity.cs similarity index 51% rename from src/LiveChartsCore/Kernel/Providers/EntitiesDataFactory.cs rename to src/LiveChartsCore/Defaults/ChartEntity.cs index 5ed731fd4..6dc2542ff 100644 --- a/src/LiveChartsCore/Kernel/Providers/EntitiesDataFactory.cs +++ b/src/LiveChartsCore/Defaults/ChartEntity.cs @@ -20,37 +20,27 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -using System.Collections.Generic; -using LiveChartsCore.Drawing; -using LiveChartsCore.Kernel.Sketches; +using LiveChartsCore.Kernel; -namespace LiveChartsCore.Kernel.Providers; +namespace LiveChartsCore.Defaults; /// -/// Just a cleaner but optimized for objects. +/// Defines the class.. /// -public class EntitiesDataFactory : DataFactory - where TDrawingContext : DrawingContext +public class ChartEntity : IChartEntity { - /// - public override IEnumerable Fetch(ISeries series, IChart chart) - { - if (series.Values is null) yield break; - var index = 0; + /// + /// Gets or sets the entity id. + /// + public int EntityId { get; set; } - foreach (var value in series.Values) - { - if (value is not IChartEntity entity) continue; + /// + /// Gets or sets the chart point. + /// + public ChartPoint? ChartPoint { get; set; } - entity.ChartPoint ??= new ChartPoint(chart.View, series); - entity.ChartPoint.Context.DataSource = entity; - entity.ChartPoint.Context.Index = index; - entity.EntityId = index; - entity.ChartPoint.Coordinate = entity.Coordinate; - - yield return entity.ChartPoint; - - index++; - } - } + /// + /// Gets the coordinate. + /// + public Coordinate Coordinate => ChartPoint?.Coordinate ?? Coordinate.Empty; } diff --git a/src/LiveChartsCore/Defaults/ObservablePolarPoint.cs b/src/LiveChartsCore/Defaults/ObservablePolarPoint.cs index d03711be4..6003dec6d 100644 --- a/src/LiveChartsCore/Defaults/ObservablePolarPoint.cs +++ b/src/LiveChartsCore/Defaults/ObservablePolarPoint.cs @@ -109,6 +109,6 @@ protected virtual void OnCoordinateChanged() { Coordinate = _radius is null || _angle is null ? Coordinate.Empty - : new(_radius.Value, _angle.Value); + : new(_angle.Value, _radius.Value); } } diff --git a/src/LiveChartsCore/Kernel/ChartPoint.cs b/src/LiveChartsCore/Kernel/ChartPoint.cs index 533f18dd7..b3eb355ba 100644 --- a/src/LiveChartsCore/Kernel/ChartPoint.cs +++ b/src/LiveChartsCore/Kernel/ChartPoint.cs @@ -41,13 +41,18 @@ public ChartPoint(IChartView chart, ISeries series) Context = new ChartPointContext(chart, series); } + internal ChartPoint() + { + Context = new ChartPointContext(); + } + /// /// Gets or sets a value indicating whether this instance is null. /// /// /// true if this instance is null; otherwise, false. /// - [Obsolete($"Renamed to {nameof(IsEmpty)}")] + [Obsolete($"Replaced by {nameof(Coordinate)}.{nameof(Coordinate.Empty)}")] public bool IsNull { get => IsEmpty; set => IsEmpty = value; } /// @@ -68,7 +73,6 @@ public ChartPoint(IChartView chart, ISeries series) public double PrimaryValue { get => Coordinate.PrimaryValue; - [Obsolete($"Coordinate setters are obsolete, please set the {nameof(Coordinate)} property instead.")] set => OnCoordinateChanged( new Coordinate(value, Coordinate.SecondaryValue, Coordinate.TertiaryValue, Coordinate.QuaternaryValue, Coordinate.QuinaryValue)); } @@ -82,7 +86,6 @@ public double PrimaryValue public double SecondaryValue { get => Coordinate.SecondaryValue; - [Obsolete($"Coordinate setters are obsolete, please set the {nameof(Coordinate)} property instead.")] set => OnCoordinateChanged( new Coordinate(Coordinate.PrimaryValue, value, Coordinate.TertiaryValue, Coordinate.QuaternaryValue, Coordinate.QuinaryValue)); } @@ -96,7 +99,6 @@ public double SecondaryValue public double TertiaryValue { get => Coordinate.TertiaryValue; - [Obsolete($"Coordinate setters are obsolete, please set the {nameof(Coordinate)} property instead.")] set => OnCoordinateChanged( new Coordinate(Coordinate.PrimaryValue, Coordinate.SecondaryValue, value, Coordinate.QuaternaryValue, Coordinate.QuinaryValue)); } @@ -110,7 +112,6 @@ public double TertiaryValue public double QuaternaryValue { get => Coordinate.QuaternaryValue; - [Obsolete($"Coordinate setters are obsolete, please set the {nameof(Coordinate)} property instead.")] set => OnCoordinateChanged( new Coordinate(Coordinate.PrimaryValue, Coordinate.SecondaryValue, Coordinate.TertiaryValue, value, Coordinate.QuinaryValue)); } @@ -124,7 +125,6 @@ public double QuaternaryValue public double QuinaryValue { get => Coordinate.QuinaryValue; - [Obsolete($"Coordinate setters are obsolete, please set the {nameof(Coordinate)} property instead.")] set => OnCoordinateChanged( new Coordinate(Coordinate.PrimaryValue, Coordinate.SecondaryValue, Coordinate.TertiaryValue, Coordinate.QuaternaryValue, value)); } @@ -159,7 +159,21 @@ public double QuinaryValue public ChartPointContext Context { get; } /// - public Coordinate Coordinate { get; set; } + public Coordinate Coordinate { get; internal set; } + + /// + /// Marks the point as null or empty, it will be ignored in the UI. + /// + public ChartPoint AsEmpty() + { + Coordinate = Coordinate.Empty; + return this; + } + + /// + /// Gets a new instance of an empty chart point. + /// + public static ChartPoint Empty => new ChartPoint().AsEmpty(); /// /// Gets the distance to a given point. diff --git a/src/LiveChartsCore/Kernel/ChartPointContext.cs b/src/LiveChartsCore/Kernel/ChartPointContext.cs index 365e9467b..9c21a56c4 100644 --- a/src/LiveChartsCore/Kernel/ChartPointContext.cs +++ b/src/LiveChartsCore/Kernel/ChartPointContext.cs @@ -41,6 +41,14 @@ public ChartPointContext(IChartView chart, ISeries series) Series = series; } + internal ChartPointContext() + { + // dummy empty constructor.. + // This is used only when the IChartEntity was null + Chart = null!; + Series = null!; + } + /// /// Gets the chart. /// diff --git a/src/LiveChartsCore/Kernel/LiveChartsSettings.cs b/src/LiveChartsCore/Kernel/LiveChartsSettings.cs index 98e03e32c..e4ed2493b 100644 --- a/src/LiveChartsCore/Kernel/LiveChartsSettings.cs +++ b/src/LiveChartsCore/Kernel/LiveChartsSettings.cs @@ -143,20 +143,20 @@ internal Action GetMap() : (Action)mapper; } - internal LiveChartsSettings HasProvider(ChartProvider factory) + internal LiveChartsSettings HasProvider(ChartEngine factory) where TDrawingContext : DrawingContext { _currentProvider = factory; return this; } - internal ChartProvider GetProvider() + internal ChartEngine GetProvider() where TDrawingContext : DrawingContext { return _currentProvider is null ? throw new NotImplementedException( - $"There is no a {nameof(ChartProvider)} registered.") - : (ChartProvider)_currentProvider; + $"There is no a {nameof(ChartEngine)} registered.") + : (ChartEngine)_currentProvider; } /// @@ -286,74 +286,80 @@ public LiveChartsSettings AddDefaultMappers() }) .HasMap((model, point) => { - point.PrimaryValue = unchecked((double)model); + point.PrimaryValue = (double)model; point.SecondaryValue = point.Context.Index; }) .HasMap((model, point) => { - if (model is null) + if (model is not null) { - point.IsNull = true; - return; + point.PrimaryValue = model.Value; + point.SecondaryValue = point.Context.Index; + } + else + { + _ = point.AsEmpty(); } - point.IsNull = false; - point.PrimaryValue = model.Value; - point.SecondaryValue = point.Context.Index; }) .HasMap((model, point) => { - if (model is null) + if (model is not null) { - point.IsNull = true; - return; + point.PrimaryValue = model.Value; + point.SecondaryValue = point.Context.Index; + } + else + { + _ = point.AsEmpty(); } - point.IsNull = false; - point.PrimaryValue = model.Value; - point.SecondaryValue = point.Context.Index; }) .HasMap((model, point) => { - if (model is null) + if (model is not null) { - point.IsNull = true; - return; + point.PrimaryValue = model.Value; + point.SecondaryValue = point.Context.Index; + } + else + { + _ = point.AsEmpty(); } - point.IsNull = false; - point.PrimaryValue = model.Value; - point.SecondaryValue = point.Context.Index; }) .HasMap((model, point) => { - if (model is null) + if (model is not null) { - point.IsNull = true; - return; + point.PrimaryValue = model.Value; + point.SecondaryValue = point.Context.Index; + } + else + { + _ = point.AsEmpty(); } - point.IsNull = false; - point.PrimaryValue = model.Value; - point.SecondaryValue = point.Context.Index; }) .HasMap((model, point) => { - if (model is null) + if (model is not null) { - point.IsNull = true; - return; + point.PrimaryValue = model.Value; + point.SecondaryValue = point.Context.Index; + } + else + { + _ = point.AsEmpty(); } - point.IsNull = false; - point.PrimaryValue = model.Value; - point.SecondaryValue = point.Context.Index; }) .HasMap((model, point) => { - if (model is null) + if (model is not null) { - point.IsNull = true; - return; + point.PrimaryValue = (double)model.Value; + point.SecondaryValue = point.Context.Index; + } + else + { + _ = point.AsEmpty(); } - point.IsNull = false; - point.PrimaryValue = unchecked((double)model.Value); - point.SecondaryValue = point.Context.Index; }); } } diff --git a/src/LiveChartsCore/Kernel/Providers/ChartProvider.cs b/src/LiveChartsCore/Kernel/Providers/ChartEngine.cs similarity index 85% rename from src/LiveChartsCore/Kernel/Providers/ChartProvider.cs rename to src/LiveChartsCore/Kernel/Providers/ChartEngine.cs index ab294b1ba..09028bd68 100644 --- a/src/LiveChartsCore/Kernel/Providers/ChartProvider.cs +++ b/src/LiveChartsCore/Kernel/Providers/ChartEngine.cs @@ -20,7 +20,6 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -using System.ComponentModel; using LiveChartsCore.Drawing; using LiveChartsCore.Geo; using LiveChartsCore.Kernel.Sketches; @@ -31,7 +30,7 @@ namespace LiveChartsCore.Kernel.Providers; /// Defines the chart provider class. /// /// The type of the drawing context. -public abstract class ChartProvider +public abstract class ChartEngine where TDrawingContext : DrawingContext { /// @@ -41,11 +40,7 @@ public abstract class ChartProvider /// public virtual DataFactory GetDefaultDataFactory() { - var isChartEntity = typeof(IChartEntity).IsAssignableFrom(typeof(TModel)); - - return isChartEntity - ? new EntitiesDataFactory() // <- this is the way to go - : new DataFactory(); // <- this factory is just here to support older versions and by val types. + return new DataFactory(); } /// diff --git a/src/LiveChartsCore/Kernel/Providers/DataFactory.cs b/src/LiveChartsCore/Kernel/Providers/DataFactory.cs index 7843063c6..6ba055ab6 100644 --- a/src/LiveChartsCore/Kernel/Providers/DataFactory.cs +++ b/src/LiveChartsCore/Kernel/Providers/DataFactory.cs @@ -22,6 +22,7 @@ using System; using System.Collections.Generic; +using LiveChartsCore.Defaults; using LiveChartsCore.Drawing; using LiveChartsCore.Kernel.Sketches; using LiveChartsCore.Measure; @@ -37,30 +38,10 @@ namespace LiveChartsCore.Kernel.Providers; public class DataFactory where TDrawingContext : DrawingContext { - /// - /// Gets the by value map. - /// - protected Dictionary> ByChartbyValueVisualMap { get; } = new(); - -#nullable disable - - // note #270422 - // We use the ByChartbyValueVisualMap for nullable and value types - // for reference types we use the ByChartByReferenceVisualMap it does not allows nulls, it throws in the mapper - // when it founds a null type and then it warns you on how to use it. - // this is a current limitation and could be supported in future verions. - - /// - /// Gets the by reference map. - /// - protected Dictionary> ByChartByReferenceVisualMap { get; } = new(); - -#nullable restore - - /// - /// Indicates whether the factory uses value or reference types. - /// - protected bool IsValueType { get; private set; } = false; + private readonly bool _isTModelChartEntity = false; + private readonly bool _isValueType = false; + private Dictionary> ChartIndexEntityMap { get; } = new(); + private Dictionary> ChartRefEntityMap { get; } = new(); /// /// Gets or sets the previous known bounds. @@ -72,11 +53,13 @@ public class DataFactory /// public DataFactory() { - var t = typeof(TModel); - IsValueType = t.IsValueType; - var bounds = new DimensionalBounds(true); PreviousKnownBounds = bounds; + + var t = typeof(TModel); + _isValueType = t.IsValueType; + + _isTModelChartEntity = typeof(IChartEntity).IsAssignableFrom(typeof(TModel)); } /// @@ -89,58 +72,16 @@ public virtual IEnumerable Fetch(ISeries series, IChart char { if (series.Values is null) yield break; - var canvas = (MotionCanvas)chart.Canvas; + var dataSource = _isTModelChartEntity + ? EnumerateChartEntities(series, chart) + : (_isValueType + ? EnumerateByValEntities(series, chart) + : EnumerateByRefEntities(series, chart)); - var mapper = series.Mapping ?? LiveCharts.CurrentSettings.GetMap(); - var index = 0; - - if (IsValueType) + foreach (var value in dataSource) { - _ = ByChartbyValueVisualMap.TryGetValue(canvas.Sync, out var d); - if (d is null) - { - d = new Dictionary(); - ByChartbyValueVisualMap[canvas.Sync] = d; - } - var byValueVisualMap = d; - - foreach (var item in series.Values) - { - if (!byValueVisualMap.TryGetValue(index, out var cp)) - byValueVisualMap[index] = cp = new ChartPoint(chart.View, series); - - cp.Context.Index = index++; - cp.Context.DataSource = item; - - mapper(item, cp); - - yield return cp; - } - } - else - { - _ = ByChartByReferenceVisualMap.TryGetValue(canvas.Sync, out var d); - if (d is null) - { -#nullable disable - // see note #270422 - d = new Dictionary(); -#nullable restore - ByChartByReferenceVisualMap[canvas.Sync] = d; - } - var byReferenceVisualMap = d; - - foreach (var item in series.Values) - { - if (!byReferenceVisualMap.TryGetValue(item, out var cp)) - byReferenceVisualMap[item] = cp = new ChartPoint(chart.View, series); - - cp.Context.Index = index++; - cp.Context.DataSource = item; - mapper(item, cp); - - yield return cp; - } + if (value is null) yield return ChartPoint.Empty; + yield return value?.ChartPoint ?? ChartPoint.Empty; } } @@ -151,23 +92,13 @@ public virtual IEnumerable Fetch(ISeries series, IChart char /// public virtual void DisposePoint(ChartPoint point) { - if (IsValueType) - { - var canvas = (MotionCanvas)point.Context.Chart.CoreChart.Canvas; - _ = ByChartbyValueVisualMap.TryGetValue(canvas.Sync, out var d); - var byValueVisualMap = d; - if (byValueVisualMap is null) return; - _ = byValueVisualMap.Remove(point.Context.Index); - } - else - { - if (point.Context.DataSource is null) return; - var canvas = (MotionCanvas)point.Context.Chart.CoreChart.Canvas; - _ = ByChartByReferenceVisualMap.TryGetValue(canvas.Sync, out var d); - var byReferenceVisualMap = d; - if (byReferenceVisualMap is null) return; - _ = byReferenceVisualMap.Remove((TModel)point.Context.DataSource); - } + if (_isTModelChartEntity) return; + + var canvas = (MotionCanvas)point.Context.Chart.CoreChart.Canvas; + _ = ChartIndexEntityMap.TryGetValue(canvas.Sync, out var d); + var byValueVisualMap = d; + if (byValueVisualMap is null) return; + _ = byValueVisualMap.Remove(point.Context.Index); } /// @@ -176,16 +107,10 @@ public virtual void DisposePoint(ChartPoint point) /// public virtual void Dispose(IChart chart) { - if (IsValueType) - { - var canvas = (MotionCanvas)chart.Canvas; - _ = ByChartbyValueVisualMap.Remove(canvas.Sync); - } - else - { - var canvas = (MotionCanvas)chart.Canvas; - _ = ByChartByReferenceVisualMap.Remove(canvas.Sync); - } + if (_isTModelChartEntity) return; + + var canvas = (MotionCanvas)chart.Canvas; + _ = ChartIndexEntityMap.Remove(canvas.Sync); } /// @@ -346,30 +271,97 @@ public virtual SeriesBounds GetPieBounds( return new SeriesBounds(bounds, false); } - /// - /// Clears the visuals in the cache. - /// - /// - public virtual void RestartVisuals() + private IEnumerable EnumerateChartEntities(ISeries series, IChart chart) { - foreach (var byReferenceVisualMap in ByChartByReferenceVisualMap) + if (series.Values is null) yield break; + var entities = (IEnumerable)series.Values; + var index = 0; + + foreach (var entity in entities) { - foreach (var item in byReferenceVisualMap.Value) + if (entity is null) continue; + + entity.ChartPoint ??= new ChartPoint(chart.View, series); + entity.ChartPoint.Context.DataSource = entity; + entity.ChartPoint.Context.Index = index; + entity.EntityId = index++; + entity.ChartPoint.Coordinate = entity.Coordinate; + + yield return entity; + } + } + + private IEnumerable EnumerateByValEntities(ISeries series, IChart chart) + { + if (series.Values is null) yield break; + + var canvas = (MotionCanvas)chart.Canvas; + var mapper = series.Mapping ?? LiveCharts.CurrentSettings.GetMap(); + var index = 0; + + _ = ChartIndexEntityMap.TryGetValue(canvas.Sync, out var d); + if (d is null) + { + d = new Dictionary(); + ChartIndexEntityMap[canvas.Sync] = d; + } + var IndexEntityMap = d; + + foreach (var item in series.Values) + { + if (!IndexEntityMap.TryGetValue(index, out var entity)) { - if (item.Value.Context.Visual is not IAnimatable visual) continue; - visual.RemoveTransition(null); + IndexEntityMap[index] = entity = new ChartEntity(); } - byReferenceVisualMap.Value.Clear(); + + entity.ChartPoint ??= new ChartPoint(chart.View, series); + entity.ChartPoint.Context.DataSource = item; + entity.EntityId = index; + entity.ChartPoint.Context.Index = index++; + + mapper(item, entity.ChartPoint); + + yield return entity; + } + } + + private IEnumerable EnumerateByRefEntities(ISeries series, IChart chart) + { + if (series.Values is null) yield break; + + var canvas = (MotionCanvas)chart.Canvas; + var mapper = series.Mapping ?? LiveCharts.CurrentSettings.GetMap(); + var index = 0; + + _ = ChartRefEntityMap.TryGetValue(canvas.Sync, out var d); + if (d is null) + { + d = new Dictionary(); + ChartRefEntityMap[canvas.Sync] = d; } + var IndexEntityMap = d; - foreach (var byValueVisualMap in ByChartbyValueVisualMap) + foreach (var item in series.Values) { - foreach (var item in byValueVisualMap.Value) + if (item is null) { - if (item.Value.Context.Visual is not IAnimatable visual) continue; - visual.RemoveTransition(null); + yield return new ChartEntity { ChartPoint = new ChartPoint().AsEmpty() }; + continue; } - byValueVisualMap.Value.Clear(); + + if (!IndexEntityMap.TryGetValue(item, out var entity)) + { + IndexEntityMap[item] = entity = new ChartEntity(); + } + + entity.ChartPoint ??= new ChartPoint(chart.View, series); + entity.ChartPoint.Context.DataSource = item; + entity.EntityId = index; + entity.ChartPoint.Context.Index = index++; + + mapper(item, entity.ChartPoint); + + yield return entity; } } } diff --git a/src/LiveChartsCore/Series.cs b/src/LiveChartsCore/Series.cs index 3e19b1377..592780f29 100644 --- a/src/LiveChartsCore/Series.cs +++ b/src/LiveChartsCore/Series.cs @@ -342,8 +342,8 @@ void ISeries.OnPointerLeft(ChartPoint point) /// public void RestartAnimations() { - if (DataFactory is null) throw new Exception("Data provider not found"); - DataFactory.RestartVisuals(); + //if (DataFactory is null) throw new Exception("Data provider not found"); + //DataFactory.Fetch( } /// diff --git a/src/skiasharp/LiveChartsCore.SkiaSharp/SkiaSharpProvider.cs b/src/skiasharp/LiveChartsCore.SkiaSharp/SkiaSharpProvider.cs index 2c96333a3..fa3912ad0 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharp/SkiaSharpProvider.cs +++ b/src/skiasharp/LiveChartsCore.SkiaSharp/SkiaSharpProvider.cs @@ -30,28 +30,28 @@ namespace LiveChartsCore.SkiaSharpView; -/// -public class SkiaSharpProvider : ChartProvider +/// +public class SkiaSharpProvider : ChartEngine { - /// + /// public override IMapFactory GetDefaultMapFactory() { return new MapFactory(); } - /// + /// public override ICartesianAxis GetDefaultCartesianAxis() { return new Axis(); } - /// + /// public override IPolarAxis GetDefaultPolarAxis() { return new PolarAxis(); } - /// + /// public override IPaint GetSolidColorPaint(LvcColor color) { return new SolidColorPaint(new SKColor(color.R, color.G, color.B, color.A)); From 55debadb9e49acbd363b5d8d797cb219a97bd804 Mon Sep 17 00:00:00 2001 From: beto-rodriguez Date: Wed, 17 Aug 2022 09:40:10 -0500 Subject: [PATCH 08/25] dispose by ref points --- .../Kernel/Providers/ChartEngine.cs | 2 +- .../Kernel/Providers/DataFactory.cs | 30 +++++++++++++++---- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/LiveChartsCore/Kernel/Providers/ChartEngine.cs b/src/LiveChartsCore/Kernel/Providers/ChartEngine.cs index 09028bd68..38496ad74 100644 --- a/src/LiveChartsCore/Kernel/Providers/ChartEngine.cs +++ b/src/LiveChartsCore/Kernel/Providers/ChartEngine.cs @@ -27,7 +27,7 @@ namespace LiveChartsCore.Kernel.Providers; /// -/// Defines the chart provider class. +/// Defines the class. /// /// The type of the drawing context. public abstract class ChartEngine diff --git a/src/LiveChartsCore/Kernel/Providers/DataFactory.cs b/src/LiveChartsCore/Kernel/Providers/DataFactory.cs index 6ba055ab6..a566ae726 100644 --- a/src/LiveChartsCore/Kernel/Providers/DataFactory.cs +++ b/src/LiveChartsCore/Kernel/Providers/DataFactory.cs @@ -80,8 +80,13 @@ public virtual IEnumerable Fetch(ISeries series, IChart char foreach (var value in dataSource) { - if (value is null) yield return ChartPoint.Empty; - yield return value?.ChartPoint ?? ChartPoint.Empty; + if (value is null) + { + yield return ChartPoint.Empty; + continue; + } + + yield return value.ChartPoint ?? ChartPoint.Empty; } } @@ -95,10 +100,23 @@ public virtual void DisposePoint(ChartPoint point) if (_isTModelChartEntity) return; var canvas = (MotionCanvas)point.Context.Chart.CoreChart.Canvas; - _ = ChartIndexEntityMap.TryGetValue(canvas.Sync, out var d); - var byValueVisualMap = d; - if (byValueVisualMap is null) return; - _ = byValueVisualMap.Remove(point.Context.Index); + + if (_isValueType) + { + _ = ChartIndexEntityMap.TryGetValue(canvas.Sync, out var d); + var map = d; + if (map is null) return; + _ = map.Remove(point.Context.Index); + } + else + { + _ = ChartRefEntityMap.TryGetValue(canvas.Sync, out var d); + var map = d; + if (map is null) return; + var src = (TModel?)point.Context.DataSource; + if (src is null) return; + _ = map.Remove(src); + } } /// From 103f01cbe421c05f970f2e4f3a057b1c684324d7 Mon Sep 17 00:00:00 2001 From: beto-rodriguez Date: Wed, 17 Aug 2022 10:08:02 -0500 Subject: [PATCH 09/25] use dummy rectangle zooming section --- src/LiveChartsCore/Kernel/Providers/DataFactory.cs | 12 ++++++++++-- .../SKCharts/SKCartesianChart.cs | 3 ++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/LiveChartsCore/Kernel/Providers/DataFactory.cs b/src/LiveChartsCore/Kernel/Providers/DataFactory.cs index a566ae726..d8b0bbe45 100644 --- a/src/LiveChartsCore/Kernel/Providers/DataFactory.cs +++ b/src/LiveChartsCore/Kernel/Providers/DataFactory.cs @@ -127,8 +127,16 @@ public virtual void Dispose(IChart chart) { if (_isTModelChartEntity) return; - var canvas = (MotionCanvas)chart.Canvas; - _ = ChartIndexEntityMap.Remove(canvas.Sync); + if (_isValueType) + { + var canvas = (MotionCanvas)chart.Canvas; + _ = ChartIndexEntityMap.Remove(canvas.Sync); + } + else + { + var canvas = (MotionCanvas)chart.Canvas; + _ = ChartRefEntityMap.Remove(canvas.Sync); + } } /// diff --git a/src/skiasharp/LiveChartsCore.SkiaSharp/SKCharts/SKCartesianChart.cs b/src/skiasharp/LiveChartsCore.SkiaSharp/SKCharts/SKCartesianChart.cs index f86e32c4a..73750c536 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharp/SKCharts/SKCartesianChart.cs +++ b/src/skiasharp/LiveChartsCore.SkiaSharp/SKCharts/SKCartesianChart.cs @@ -30,6 +30,7 @@ using LiveChartsCore.Measure; using LiveChartsCore.Motion; using LiveChartsCore.SkiaSharpView.Drawing; +using LiveChartsCore.SkiaSharpView.Drawing.Geometries; using SkiaSharp; namespace LiveChartsCore.SkiaSharpView.SKCharts; @@ -55,7 +56,7 @@ public SKCartesianChart() initializer.ApplyStyleToChart(this); Core = new CartesianChart( - this, LiveChartsSkiaSharp.DefaultPlatformBuilder, CoreCanvas, null); + this, LiveChartsSkiaSharp.DefaultPlatformBuilder, CoreCanvas, new RectangleGeometry()); Core.Measuring += OnCoreMeasuring; Core.UpdateStarted += OnCoreUpdateStarted; Core.UpdateFinished += OnCoreUpdateFinished; From bd97e13cb60c16e25747e73d0c8454c469208ff1 Mon Sep 17 00:00:00 2001 From: beto-rodriguez Date: Wed, 17 Aug 2022 14:12:53 -0500 Subject: [PATCH 10/25] simplify ichartentity/icoordinate --- .../TwoChartsOneSeries/ViewModel.cs | 19 +++- src/LiveChartsCore/Defaults/ChartEntity.cs | 19 ++-- src/LiveChartsCore/Defaults/DateTimePoint.cs | 49 +++------- src/LiveChartsCore/Defaults/FinancialPoint.cs | 88 ++++-------------- .../Defaults/ObservablePoint.cs | 51 +++-------- .../Defaults/ObservablePolarPoint.cs | 45 ++-------- .../Defaults/ObservableValue.cs | 47 +++------- src/LiveChartsCore/Defaults/TimeSpanPoint.cs | 47 +++------- src/LiveChartsCore/Defaults/WeightedPoint.cs | 62 +++---------- .../Kernel/ChartEntityMetadata.cs | 89 +++++++++++++++++++ src/LiveChartsCore/Kernel/ChartPoint.cs | 2 +- src/LiveChartsCore/Kernel/IChartEntity.cs | 11 +-- src/LiveChartsCore/Kernel/ICoordinate.cs | 34 ------- .../Kernel/Providers/DataFactory.cs | 70 +++++++-------- 14 files changed, 229 insertions(+), 404 deletions(-) create mode 100644 src/LiveChartsCore/Kernel/ChartEntityMetadata.cs delete mode 100644 src/LiveChartsCore/Kernel/ICoordinate.cs diff --git a/samples/ViewModelsSamples/VisualTest/TwoChartsOneSeries/ViewModel.cs b/samples/ViewModelsSamples/VisualTest/TwoChartsOneSeries/ViewModel.cs index dde2342e0..8ccf833e2 100644 --- a/samples/ViewModelsSamples/VisualTest/TwoChartsOneSeries/ViewModel.cs +++ b/samples/ViewModelsSamples/VisualTest/TwoChartsOneSeries/ViewModel.cs @@ -1,6 +1,7 @@ using System; using CommunityToolkit.Mvvm.ComponentModel; using LiveChartsCore; +using LiveChartsCore.Defaults; using LiveChartsCore.SkiaSharpView; namespace ViewModelsSamples.VisualTest.TwoChartsOneSeries; @@ -10,17 +11,29 @@ public partial class ViewModel { public ViewModel() { - var values = new int[100]; + //var values = new int[100]; + //var r = new Random(); + //var t = 0; + + //for (var i = 0; i < 100; i++) + //{ + // t += r.Next(-90, 100); + // values[i] = t; + //} + + //Series = new ISeries[] { new StepLineSeries { Values = values } }; + + var values = new ObservableValue[100]; var r = new Random(); var t = 0; for (var i = 0; i < 100; i++) { t += r.Next(-90, 100); - values[i] = t; + values[i] = new(t); } - Series = new ISeries[] { new StepLineSeries { Values = values } }; + Series = new ISeries[] { new StepLineSeries { Values = values } }; } public ISeries[] Series { get; set; } diff --git a/src/LiveChartsCore/Defaults/ChartEntity.cs b/src/LiveChartsCore/Defaults/ChartEntity.cs index 6dc2542ff..835b67401 100644 --- a/src/LiveChartsCore/Defaults/ChartEntity.cs +++ b/src/LiveChartsCore/Defaults/ChartEntity.cs @@ -25,22 +25,13 @@ namespace LiveChartsCore.Defaults; /// -/// Defines the class.. +/// Defines the class. /// public class ChartEntity : IChartEntity { - /// - /// Gets or sets the entity id. - /// - public int EntityId { get; set; } + private ChartEntityMetadata? _chartMetadata; - /// - /// Gets or sets the chart point. - /// - public ChartPoint? ChartPoint { get; set; } - - /// - /// Gets the coordinate. - /// - public Coordinate Coordinate => ChartPoint?.Coordinate ?? Coordinate.Empty; + /// + public ChartEntityMetadata ChartMetadata => + _chartMetadata ??= new(() => ChartMetadata.ChartPoint?.Coordinate ?? Coordinate.Empty); } diff --git a/src/LiveChartsCore/Defaults/DateTimePoint.cs b/src/LiveChartsCore/Defaults/DateTimePoint.cs index e2b79b32e..fe27bb049 100644 --- a/src/LiveChartsCore/Defaults/DateTimePoint.cs +++ b/src/LiveChartsCore/Defaults/DateTimePoint.cs @@ -34,11 +34,12 @@ public class DateTimePoint : IChartEntity, INotifyPropertyChanged { private DateTime _dateTime; private double? _value; + private ChartEntityMetadata? _chartMetadata; /// /// Initializes a new instance of the class. /// - public DateTimePoint() : this(DateTime.Now, 0) + public DateTimePoint() { } /// @@ -48,9 +49,8 @@ public DateTimePoint() : this(DateTime.Now, 0) /// The value. public DateTimePoint(DateTime dateTime, double? value) { - _dateTime = dateTime; - _value = value; - OnCoordinateChanged(); + DateTime = dateTime; + Value = value; } /// @@ -59,16 +59,7 @@ public DateTimePoint(DateTime dateTime, double? value) /// /// The date time. /// - public DateTime DateTime - { - get => _dateTime; - set - { - _dateTime = value; - OnCoordinateChanged(); - OnPropertyChanged(); - } - } + public DateTime DateTime { get => _dateTime; set { _dateTime = value; OnPropertyChanged(); } } /// /// Gets or sets the value. @@ -76,25 +67,7 @@ public DateTime DateTime /// /// The value. /// - public double? Value - { - get => _value; - set - { - _value = value; - OnCoordinateChanged(); - OnPropertyChanged(); - } - } - - /// - public ChartPoint? ChartPoint { get; set; } - - /// - public int EntityId { get; set; } - - /// - public Coordinate Coordinate { get; protected set; } + public double? Value { get => _value; set { _value = value; OnPropertyChanged(); } } /// /// Occurs when a property value changes. @@ -102,6 +75,9 @@ public double? Value /// public event PropertyChangedEventHandler? PropertyChanged; + /// + public ChartEntityMetadata ChartMetadata => _chartMetadata ??= new(this, AsCoordinate); + /// /// Called when a property changed. /// @@ -111,12 +87,9 @@ protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName PropertyChanged?.Invoke(propertyName, new PropertyChangedEventArgs(propertyName)); } - /// - /// Called when the coordinate changes. - /// - protected virtual void OnCoordinateChanged() + private Coordinate AsCoordinate() { - Coordinate = _value is null + return _value is null ? Coordinate.Empty : new(_dateTime.Ticks, _value.Value); } diff --git a/src/LiveChartsCore/Defaults/FinancialPoint.cs b/src/LiveChartsCore/Defaults/FinancialPoint.cs index cf2e78b7e..0f60014b4 100644 --- a/src/LiveChartsCore/Defaults/FinancialPoint.cs +++ b/src/LiveChartsCore/Defaults/FinancialPoint.cs @@ -37,11 +37,12 @@ public class FinancialPoint : IChartEntity, INotifyPropertyChanged private double? _close; private double? _low; private DateTime _date; + private ChartEntityMetadata? _chartMetadata; /// /// Initializes a new instance of the class. /// - public FinancialPoint() : this(DateTime.Now, 0, 0, 0, 0) + public FinancialPoint() { } /// @@ -54,12 +55,11 @@ public FinancialPoint() : this(DateTime.Now, 0, 0, 0, 0) /// The low. public FinancialPoint(DateTime date, double? high, double? open, double? close, double? low) { - _date = date; - _high = high; - _open = open; - _close = close; - _low = low; - OnCoordinateChanged(); + Date = date; + High = high; + Open = open; + Close = close; + Low = low; } /// @@ -68,16 +68,7 @@ public FinancialPoint(DateTime date, double? high, double? open, double? close, /// /// The date. /// - public DateTime Date - { - get => _date; - set - { - _date = value; - OnCoordinateChanged(); - OnPropertyChanged(); - } - } + public DateTime Date { get => _date; set { _date = value; OnPropertyChanged(); } } /// /// Gets or sets the high. @@ -85,16 +76,7 @@ public DateTime Date /// /// The high. /// - public double? High - { - get => _high; - set - { - _high = value; - OnCoordinateChanged(); - OnPropertyChanged(); - } - } + public double? High { get => _high; set { _high = value; OnPropertyChanged(); } } /// /// Gets or sets the open. @@ -102,16 +84,7 @@ public double? High /// /// The open. /// - public double? Open - { - get => _open; - set - { - _open = value; - OnCoordinateChanged(); - OnPropertyChanged(); - } - } + public double? Open { get => _open; set { _open = value; OnPropertyChanged(); } } /// /// Gets or sets the close. @@ -119,16 +92,7 @@ public double? Open /// /// The close. /// - public double? Close - { - get => _close; - set - { - _close = value; - OnCoordinateChanged(); - OnPropertyChanged(); - } - } + public double? Close { get => _close; set { _close = value; OnPropertyChanged(); } } /// /// Gets or sets the low. @@ -136,25 +100,7 @@ public double? Close /// /// The low. /// - public double? Low - { - get => _low; - set - { - _low = value; - OnCoordinateChanged(); - OnPropertyChanged(); - } - } - - /// - public ChartPoint? ChartPoint { get; set; } - - /// - public int EntityId { get; set; } - - /// - public Coordinate Coordinate { get; protected set; } + public double? Low { get => _low; set { _low = value; OnPropertyChanged(); } } /// /// Occurs when a property value changes. @@ -162,6 +108,9 @@ public double? Low /// public event PropertyChangedEventHandler? PropertyChanged; + /// + public ChartEntityMetadata ChartMetadata => _chartMetadata ??= new(this, AsCoordinate); + /// /// Called when a property changed. /// @@ -171,12 +120,9 @@ protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName PropertyChanged?.Invoke(propertyName, new PropertyChangedEventArgs(propertyName)); } - /// - /// Called when the coordinate changes. - /// - protected virtual void OnCoordinateChanged() + private Coordinate AsCoordinate() { - Coordinate = _open is null || _high is null || _low is null || _close is null + return _open is null || _high is null || _low is null || _close is null ? Coordinate.Empty : new(_high.Value, _date.Ticks, _open.Value, _close.Value, _low.Value); } diff --git a/src/LiveChartsCore/Defaults/ObservablePoint.cs b/src/LiveChartsCore/Defaults/ObservablePoint.cs index e0f3a0cd3..e54815c1c 100644 --- a/src/LiveChartsCore/Defaults/ObservablePoint.cs +++ b/src/LiveChartsCore/Defaults/ObservablePoint.cs @@ -34,11 +34,12 @@ public class ObservablePoint : IChartEntity, INotifyPropertyChanged { private double? _x; private double? _y; + private ChartEntityMetadata? _chartMetadata; /// /// Initializes a new instance of the class. /// - public ObservablePoint() : this(0d, 0d) + public ObservablePoint() { } /// @@ -48,9 +49,8 @@ public ObservablePoint() : this(0d, 0d) /// The y coordinate. public ObservablePoint(double? x, double? y) { - _x = x; - _y = y; - OnCoordinateChanged(); + X = x; + Y = y; } /// @@ -59,16 +59,7 @@ public ObservablePoint(double? x, double? y) /// /// The x. /// - public double? X - { - get => _x; - set - { - _x = value; - OnCoordinateChanged(); - OnPropertyChanged(); - } - } + public double? X { get => _x; set { _x = value; OnPropertyChanged(); } } /// /// Gets or sets the y coordinate. @@ -76,25 +67,7 @@ public double? X /// /// The y. /// - public double? Y - { - get => _y; - set - { - _y = value; - OnCoordinateChanged(); - OnPropertyChanged(); - } - } - - /// - public ChartPoint? ChartPoint { get; set; } - - /// - public int EntityId { get; set; } - - /// - public Coordinate Coordinate { get; private set; } + public double? Y { get => _y; set { _y = value; OnPropertyChanged(); } } /// /// Occurs when a property value changes. @@ -102,6 +75,9 @@ public double? Y /// public event PropertyChangedEventHandler? PropertyChanged; + /// + public ChartEntityMetadata ChartMetadata => _chartMetadata ??= new(this, AsCoordinate); + /// /// Called when a property changes. /// @@ -111,13 +87,10 @@ protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName PropertyChanged?.Invoke(propertyName, new PropertyChangedEventArgs(propertyName)); } - /// - /// Called when the coordinate changes. - /// - protected virtual void OnCoordinateChanged() + private Coordinate AsCoordinate() { - Coordinate = _x is null || _y is null + return _x is null || _y is null ? Coordinate.Empty - : new(_x.Value, _y.Value); + : new Coordinate(_x.Value, _y.Value); } } diff --git a/src/LiveChartsCore/Defaults/ObservablePolarPoint.cs b/src/LiveChartsCore/Defaults/ObservablePolarPoint.cs index 6003dec6d..60a921108 100644 --- a/src/LiveChartsCore/Defaults/ObservablePolarPoint.cs +++ b/src/LiveChartsCore/Defaults/ObservablePolarPoint.cs @@ -33,11 +33,12 @@ public class ObservablePolarPoint : IChartEntity, INotifyPropertyChanged { private double? _angle; private double? _radius; + private ChartEntityMetadata? _chartMetadata; /// /// Initializes a new instance of the class. /// - public ObservablePolarPoint() : this(0, 0) + public ObservablePolarPoint() { } /// @@ -49,51 +50,26 @@ public ObservablePolarPoint(double? angle, double? radius) { _angle = angle; _radius = radius; - OnCoordinateChanged(); } /// /// Gets or sets the angle. /// - public double? Angle - { - get => _angle; - set - { - _angle = value; - OnCoordinateChanged(); - OnPropertyChanged(); - } - } + public double? Angle { get => _angle; set { _angle = value; OnPropertyChanged(); } } /// /// Gets or sets the Radius. /// - public double? Radius - { - get => _radius; - set - { - _radius = value; - OnCoordinateChanged(); - OnPropertyChanged(); - } - } - - /// - public ChartPoint? ChartPoint { get; set; } - - /// - public int EntityId { get; set; } - - /// - public Coordinate Coordinate { get; protected set; } + public double? Radius { get => _radius; set { _radius = value; OnPropertyChanged(); } } /// /// Called when a property changes. /// public event PropertyChangedEventHandler? PropertyChanged; + /// + public ChartEntityMetadata ChartMetadata => _chartMetadata ??= new(this, AsCoordinate); + /// /// Raises the property changed event. /// @@ -102,12 +78,9 @@ protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } - /// - /// Called when the coordinate changes. - /// - protected virtual void OnCoordinateChanged() + private Coordinate AsCoordinate() { - Coordinate = _radius is null || _angle is null + return _radius is null || _angle is null ? Coordinate.Empty : new(_angle.Value, _radius.Value); } diff --git a/src/LiveChartsCore/Defaults/ObservableValue.cs b/src/LiveChartsCore/Defaults/ObservableValue.cs index 7f64b3ee5..ab4228716 100644 --- a/src/LiveChartsCore/Defaults/ObservableValue.cs +++ b/src/LiveChartsCore/Defaults/ObservableValue.cs @@ -33,12 +33,12 @@ namespace LiveChartsCore.Defaults; public class ObservableValue : IChartEntity, INotifyPropertyChanged { private double? _value; - private int _entityId; + private ChartEntityMetadata? _chartMetadata; /// /// Initializes a new instance of the class. /// - public ObservableValue() : this(0) + public ObservableValue() { } /// @@ -47,8 +47,7 @@ public ObservableValue() : this(0) /// The value. public ObservableValue(double? value) { - _value = value; - OnCoordinateChanged(); + Value = value; } /// @@ -57,33 +56,7 @@ public ObservableValue(double? value) /// /// The value. /// - public double? Value - { - get => _value; - set - { - _value = value; - OnCoordinateChanged(); - OnPropertyChanged(); - } - } - - /// - public ChartPoint? ChartPoint { get; set; } - - /// - public int EntityId - { - get => _entityId; - set - { - _entityId = value; - OnCoordinateChanged(); - } - } - - /// - public Coordinate Coordinate { get; protected set; } + public double? Value { get => _value; set { _value = value; OnPropertyChanged(); } } /// /// Occurs when a property value changes. @@ -91,6 +64,9 @@ public int EntityId /// public event PropertyChangedEventHandler? PropertyChanged; + /// + public ChartEntityMetadata ChartMetadata => _chartMetadata ??= new(this, AsCoordinate); + /// /// Called when am property changed. /// @@ -100,13 +76,10 @@ protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName PropertyChanged?.Invoke(propertyName, new PropertyChangedEventArgs(propertyName)); } - /// - /// Called when the coordinate changes. - /// - protected virtual void OnCoordinateChanged() + private Coordinate AsCoordinate() { - Coordinate = _value is null + return _value is null ? Coordinate.Empty - : new(_entityId, _value.Value); + : new(ChartMetadata.EntityIndex, _value.Value); } } diff --git a/src/LiveChartsCore/Defaults/TimeSpanPoint.cs b/src/LiveChartsCore/Defaults/TimeSpanPoint.cs index 0ef4bf5c5..86c440450 100644 --- a/src/LiveChartsCore/Defaults/TimeSpanPoint.cs +++ b/src/LiveChartsCore/Defaults/TimeSpanPoint.cs @@ -34,11 +34,12 @@ public class TimeSpanPoint : IChartEntity, INotifyPropertyChanged { private TimeSpan _timeSpan; private double? _value; + private ChartEntityMetadata? _chartMetadata; /// /// Initializes a new instance of the class. /// - public TimeSpanPoint() : this(TimeSpan.Zero, 0) + public TimeSpanPoint() { } /// @@ -48,9 +49,8 @@ public TimeSpanPoint() : this(TimeSpan.Zero, 0) /// The value. public TimeSpanPoint(TimeSpan timeSpan, double? value) { - _timeSpan = timeSpan; - _value = value; - OnCoordinateChanged(); + TimeSpan = timeSpan; + Value = value; } /// @@ -59,16 +59,7 @@ public TimeSpanPoint(TimeSpan timeSpan, double? value) /// /// The date time. /// - public TimeSpan TimeSpan - { - get => _timeSpan; - set - { - _timeSpan = value; - OnCoordinateChanged(); - OnPropertyChanged(); - } - } + public TimeSpan TimeSpan { get => _timeSpan; set { _timeSpan = value; OnPropertyChanged(); } } /// /// Gets or sets the value. @@ -76,25 +67,10 @@ public TimeSpan TimeSpan /// /// The value. /// - public double? Value - { - get => _value; - set - { - _value = value; - OnCoordinateChanged(); - OnPropertyChanged(); - } - } + public double? Value { get => _value; set { _value = value; OnPropertyChanged(); } } - /// - public ChartPoint? ChartPoint { get; set; } - - /// - public int EntityId { get; set; } - - /// - public Coordinate Coordinate { get; protected set; } + /// + public ChartEntityMetadata ChartMetadata => _chartMetadata ??= new(this, AsCoordinate); /// /// Occurs when a property value changes. @@ -111,12 +87,9 @@ protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName PropertyChanged?.Invoke(propertyName, new PropertyChangedEventArgs(propertyName)); } - /// - /// Called when the coordinate changes. - /// - protected virtual void OnCoordinateChanged() + private Coordinate AsCoordinate() { - Coordinate = _value is null + return _value is null ? Coordinate.Empty : new(_timeSpan.Ticks, _value ?? 0d); } diff --git a/src/LiveChartsCore/Defaults/WeightedPoint.cs b/src/LiveChartsCore/Defaults/WeightedPoint.cs index 7e7450162..78606f1eb 100644 --- a/src/LiveChartsCore/Defaults/WeightedPoint.cs +++ b/src/LiveChartsCore/Defaults/WeightedPoint.cs @@ -35,11 +35,12 @@ public class WeightedPoint : IChartEntity, INotifyPropertyChanged private double? _x; private double? _y; private double? _weight; + private ChartEntityMetadata? _chartMetadata; /// /// Initializes a new instance of the class. /// - public WeightedPoint() : this(0, 0, 0) + public WeightedPoint() { } /// @@ -50,10 +51,9 @@ public WeightedPoint() : this(0, 0, 0) /// The weight. public WeightedPoint(double? x, double? y, double? weight) { - _x = x; - _y = y; - _weight = weight; - OnCoordinateChanged(); + X = x; + Y = y; + Weight = weight; } /// @@ -62,16 +62,7 @@ public WeightedPoint(double? x, double? y, double? weight) /// /// The x. /// - public double? X - { - get => _x; - set - { - _x = value; - OnCoordinateChanged(); - OnPropertyChanged(); - } - } + public double? X { get => _x; set { _x = value; OnPropertyChanged(); } } /// /// Gets or sets the y. @@ -79,16 +70,7 @@ public double? X /// /// The y. /// - public double? Y - { - get => _y; - set - { - _y = value; - OnCoordinateChanged(); - OnPropertyChanged(); - } - } + public double? Y { get => _y; set { _y = value; OnPropertyChanged(); } } /// /// Gets or sets the weight. @@ -96,25 +78,7 @@ public double? Y /// /// The weight. /// - public double? Weight - { - get => _weight; - set - { - _weight = value; - OnCoordinateChanged(); - OnPropertyChanged(); - } - } - - /// - public ChartPoint? ChartPoint { get; set; } - - /// - public int EntityId { get; set; } - - /// - public Coordinate Coordinate { get; protected set; } + public double? Weight { get => _weight; set { _weight = value; OnPropertyChanged(); } } /// /// Occurs when a property value changes. @@ -122,6 +86,9 @@ public double? Weight /// public event PropertyChangedEventHandler? PropertyChanged; + /// + public ChartEntityMetadata ChartMetadata => _chartMetadata ??= new(this, AsCoordinate); + /// /// Called when a property changed. /// @@ -131,12 +98,9 @@ protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName PropertyChanged?.Invoke(propertyName, new PropertyChangedEventArgs(propertyName)); } - /// - /// Called when the coordinate changes. - /// - protected virtual void OnCoordinateChanged() + private Coordinate AsCoordinate() { - Coordinate = _x is null || _y is null + return _x is null || _y is null ? Coordinate.Empty : new(_x ?? 0, _y ?? 0, _weight ?? 0); } diff --git a/src/LiveChartsCore/Kernel/ChartEntityMetadata.cs b/src/LiveChartsCore/Kernel/ChartEntityMetadata.cs new file mode 100644 index 000000000..f903ac0a2 --- /dev/null +++ b/src/LiveChartsCore/Kernel/ChartEntityMetadata.cs @@ -0,0 +1,89 @@ +// The MIT License(MIT) +// +// Copyright(c) 2021 Alberto Rodriguez Orozco & LiveCharts Contributors +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +using System; +using System.ComponentModel; + +namespace LiveChartsCore.Kernel; + +/// +/// Defines the class. +/// +public class ChartEntityMetadata +{ + private readonly Func _coordinateBuilder; + private int _entityIndex = -1; + + /// + /// Initializes a new instance of the class. + /// + /// The coordinate builder. + public ChartEntityMetadata(Func coordinateBuilder) + { + _coordinateBuilder = coordinateBuilder; + } + + /// + /// Initializes a new instance of the class. + /// + /// The entity. + /// The coordinate builder. + public ChartEntityMetadata(INotifyPropertyChanged entity, Func coordinateBuilder) + { + _coordinateBuilder = coordinateBuilder; + entity.PropertyChanged += OnEntityPropertyChanged; + } + + /// + /// Gets the entity index, a consecutive integer based on the position of the entity in the data collection. + /// + public int EntityIndex + { + get => _entityIndex; + internal set + { + var changed = _entityIndex != value; + _entityIndex = value; + if (changed) OnCoordinateChanged(); + } + } + + /// + /// Gets the chart point. + /// + public ChartPoint? ChartPoint { get; internal set; } = null; + + /// + /// Gets the coordinate. + /// + public Coordinate Coordinate { get; private set; } = Coordinate.Empty; + + private void OnEntityPropertyChanged(object sender, PropertyChangedEventArgs e) + { + OnCoordinateChanged(); + } + + private void OnCoordinateChanged() + { + Coordinate = _coordinateBuilder(); + } +} diff --git a/src/LiveChartsCore/Kernel/ChartPoint.cs b/src/LiveChartsCore/Kernel/ChartPoint.cs index b3eb355ba..b4900b0e9 100644 --- a/src/LiveChartsCore/Kernel/ChartPoint.cs +++ b/src/LiveChartsCore/Kernel/ChartPoint.cs @@ -29,7 +29,7 @@ namespace LiveChartsCore.Kernel; /// /// Defines a point in a chart. /// -public class ChartPoint : ICoordinate +public class ChartPoint { /// /// Initializes a new instance of the class. diff --git a/src/LiveChartsCore/Kernel/IChartEntity.cs b/src/LiveChartsCore/Kernel/IChartEntity.cs index c0665ddee..fd6698fb4 100644 --- a/src/LiveChartsCore/Kernel/IChartEntity.cs +++ b/src/LiveChartsCore/Kernel/IChartEntity.cs @@ -25,15 +25,10 @@ namespace LiveChartsCore.Kernel; /// /// Defines a point with a visual representation in the user interface. /// -public interface IChartEntity : ICoordinate +public interface IChartEntity { /// - /// Gets or sets the entity id. + /// Gets the chart entity metadata, just some information LiveCharts needs to make this object a chart point. /// - public int EntityId { get; set; } - - /// - /// Gets or sets the chart point. - /// - public ChartPoint? ChartPoint { get; set; } + public ChartEntityMetadata ChartMetadata { get; } } diff --git a/src/LiveChartsCore/Kernel/ICoordinate.cs b/src/LiveChartsCore/Kernel/ICoordinate.cs deleted file mode 100644 index b9d967fc5..000000000 --- a/src/LiveChartsCore/Kernel/ICoordinate.cs +++ /dev/null @@ -1,34 +0,0 @@ -// The MIT License(MIT) -// -// Copyright(c) 2021 Alberto Rodriguez Orozco & LiveCharts Contributors -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -namespace LiveChartsCore.Kernel; - -/// -/// Defines an object with a coordinate coordinate. -/// -public interface ICoordinate -{ - /// - /// Gets the coordinate. - /// - public Coordinate Coordinate { get; } -} diff --git a/src/LiveChartsCore/Kernel/Providers/DataFactory.cs b/src/LiveChartsCore/Kernel/Providers/DataFactory.cs index d8b0bbe45..ae73cd9c9 100644 --- a/src/LiveChartsCore/Kernel/Providers/DataFactory.cs +++ b/src/LiveChartsCore/Kernel/Providers/DataFactory.cs @@ -40,13 +40,9 @@ public class DataFactory { private readonly bool _isTModelChartEntity = false; private readonly bool _isValueType = false; - private Dictionary> ChartIndexEntityMap { get; } = new(); - private Dictionary> ChartRefEntityMap { get; } = new(); - - /// - /// Gets or sets the previous known bounds. - /// - public DimensionalBounds PreviousKnownBounds { get; set; } + private readonly Dictionary> _chartIndexEntityMap = new(); + private readonly Dictionary> _chartRefEntityMap = new(); + private DimensionalBounds _previousKnownBounds; /// /// Initializes a new instance of the class. @@ -54,7 +50,7 @@ public class DataFactory public DataFactory() { var bounds = new DimensionalBounds(true); - PreviousKnownBounds = bounds; + _previousKnownBounds = bounds; var t = typeof(TModel); _isValueType = t.IsValueType; @@ -86,7 +82,7 @@ public virtual IEnumerable Fetch(ISeries series, IChart char continue; } - yield return value.ChartPoint ?? ChartPoint.Empty; + yield return value.ChartMetadata.ChartPoint ?? ChartPoint.Empty; } } @@ -103,14 +99,14 @@ public virtual void DisposePoint(ChartPoint point) if (_isValueType) { - _ = ChartIndexEntityMap.TryGetValue(canvas.Sync, out var d); + _ = _chartIndexEntityMap.TryGetValue(canvas.Sync, out var d); var map = d; if (map is null) return; _ = map.Remove(point.Context.Index); } else { - _ = ChartRefEntityMap.TryGetValue(canvas.Sync, out var d); + _ = _chartRefEntityMap.TryGetValue(canvas.Sync, out var d); var map = d; if (map is null) return; var src = (TModel?)point.Context.DataSource; @@ -130,12 +126,12 @@ public virtual void Dispose(IChart chart) if (_isValueType) { var canvas = (MotionCanvas)chart.Canvas; - _ = ChartIndexEntityMap.Remove(canvas.Sync); + _ = _chartIndexEntityMap.Remove(canvas.Sync); } else { var canvas = (MotionCanvas)chart.Canvas; - _ = ChartRefEntityMap.Remove(canvas.Sync); + _ = _chartRefEntityMap.Remove(canvas.Sync); } } @@ -198,8 +194,8 @@ public virtual SeriesBounds GetCartesianBounds( } return !hasData - ? new SeriesBounds(PreviousKnownBounds, true) - : new SeriesBounds(PreviousKnownBounds = bounds, false); + ? new SeriesBounds(_previousKnownBounds, true) + : new SeriesBounds(_previousKnownBounds = bounds, false); } /// @@ -258,8 +254,8 @@ public virtual SeriesBounds GetFinancialBounds( } return !hasData - ? new SeriesBounds(PreviousKnownBounds, true) - : new SeriesBounds(PreviousKnownBounds = bounds, false); + ? new SeriesBounds(_previousKnownBounds, true) + : new SeriesBounds(_previousKnownBounds = bounds, false); } /// @@ -307,11 +303,11 @@ private IEnumerable EnumerateChartEntities(ISeries series, { if (entity is null) continue; - entity.ChartPoint ??= new ChartPoint(chart.View, series); - entity.ChartPoint.Context.DataSource = entity; - entity.ChartPoint.Context.Index = index; - entity.EntityId = index++; - entity.ChartPoint.Coordinate = entity.Coordinate; + entity.ChartMetadata.ChartPoint ??= new ChartPoint(chart.View, series); + entity.ChartMetadata.ChartPoint.Context.DataSource = entity; + entity.ChartMetadata.ChartPoint.Context.Index = index; + entity.ChartMetadata.EntityIndex = index++; + entity.ChartMetadata.ChartPoint.Coordinate = entity.ChartMetadata.Coordinate; yield return entity; } @@ -325,11 +321,11 @@ private IEnumerable EnumerateChartEntities(ISeries series, var mapper = series.Mapping ?? LiveCharts.CurrentSettings.GetMap(); var index = 0; - _ = ChartIndexEntityMap.TryGetValue(canvas.Sync, out var d); + _ = _chartIndexEntityMap.TryGetValue(canvas.Sync, out var d); if (d is null) { d = new Dictionary(); - ChartIndexEntityMap[canvas.Sync] = d; + _chartIndexEntityMap[canvas.Sync] = d; } var IndexEntityMap = d; @@ -340,12 +336,12 @@ private IEnumerable EnumerateChartEntities(ISeries series, IndexEntityMap[index] = entity = new ChartEntity(); } - entity.ChartPoint ??= new ChartPoint(chart.View, series); - entity.ChartPoint.Context.DataSource = item; - entity.EntityId = index; - entity.ChartPoint.Context.Index = index++; + entity.ChartMetadata.ChartPoint ??= new ChartPoint(chart.View, series); + entity.ChartMetadata.ChartPoint.Context.DataSource = item; + entity.ChartMetadata.EntityIndex = index; + entity.ChartMetadata.ChartPoint.Context.Index = index++; - mapper(item, entity.ChartPoint); + mapper(item, entity.ChartMetadata.ChartPoint); yield return entity; } @@ -359,11 +355,11 @@ private IEnumerable EnumerateChartEntities(ISeries series, var mapper = series.Mapping ?? LiveCharts.CurrentSettings.GetMap(); var index = 0; - _ = ChartRefEntityMap.TryGetValue(canvas.Sync, out var d); + _ = _chartRefEntityMap.TryGetValue(canvas.Sync, out var d); if (d is null) { d = new Dictionary(); - ChartRefEntityMap[canvas.Sync] = d; + _chartRefEntityMap[canvas.Sync] = d; } var IndexEntityMap = d; @@ -371,7 +367,7 @@ private IEnumerable EnumerateChartEntities(ISeries series, { if (item is null) { - yield return new ChartEntity { ChartPoint = new ChartPoint().AsEmpty() }; + yield return new ChartEntity(); continue; } @@ -380,12 +376,12 @@ private IEnumerable EnumerateChartEntities(ISeries series, IndexEntityMap[item] = entity = new ChartEntity(); } - entity.ChartPoint ??= new ChartPoint(chart.View, series); - entity.ChartPoint.Context.DataSource = item; - entity.EntityId = index; - entity.ChartPoint.Context.Index = index++; + entity.ChartMetadata.ChartPoint ??= new ChartPoint(chart.View, series); + entity.ChartMetadata.ChartPoint.Context.DataSource = item; + entity.ChartMetadata.EntityIndex = index; + entity.ChartMetadata.ChartPoint.Context.Index = index++; - mapper(item, entity.ChartPoint); + mapper(item, entity.ChartMetadata.ChartPoint); yield return entity; } From 6ba50efa46dfb48aa783e05f3a9e0b8f743e8151 Mon Sep 17 00:00:00 2001 From: beto-rodriguez Date: Wed, 17 Aug 2022 19:17:15 -0500 Subject: [PATCH 11/25] another change to ichartentity --- src/LiveChartsCore/Defaults/ChartEntity.cs | 11 ++- src/LiveChartsCore/Defaults/DateTimePoint.cs | 22 ++--- src/LiveChartsCore/Defaults/FinancialPoint.cs | 21 ++--- .../Defaults/ObservablePoint.cs | 21 ++--- .../Defaults/ObservablePolarPoint.cs | 25 +++--- .../Defaults/ObservableValue.cs | 35 ++++++-- src/LiveChartsCore/Defaults/TimeSpanPoint.cs | 19 ++-- src/LiveChartsCore/Defaults/WeightedPoint.cs | 19 ++-- .../Kernel/ChartEntityMetadata.cs | 89 ------------------- src/LiveChartsCore/Kernel/IChartEntity.cs | 14 ++- .../Kernel/Providers/DataFactory.cs | 48 +++++----- .../AssemblyInfo.cs | 10 +-- 12 files changed, 144 insertions(+), 190 deletions(-) delete mode 100644 src/LiveChartsCore/Kernel/ChartEntityMetadata.cs diff --git a/src/LiveChartsCore/Defaults/ChartEntity.cs b/src/LiveChartsCore/Defaults/ChartEntity.cs index 835b67401..d904d2964 100644 --- a/src/LiveChartsCore/Defaults/ChartEntity.cs +++ b/src/LiveChartsCore/Defaults/ChartEntity.cs @@ -29,9 +29,12 @@ namespace LiveChartsCore.Defaults; /// public class ChartEntity : IChartEntity { - private ChartEntityMetadata? _chartMetadata; + /// + public int EntityIndex { get; set; } - /// - public ChartEntityMetadata ChartMetadata => - _chartMetadata ??= new(() => ChartMetadata.ChartPoint?.Coordinate ?? Coordinate.Empty); + /// + public ChartPoint? ChartPoint { get; set; } + + /// + public Coordinate Coordinate => ChartPoint?.Coordinate ?? Coordinate.Empty; } diff --git a/src/LiveChartsCore/Defaults/DateTimePoint.cs b/src/LiveChartsCore/Defaults/DateTimePoint.cs index fe27bb049..a8fbf0642 100644 --- a/src/LiveChartsCore/Defaults/DateTimePoint.cs +++ b/src/LiveChartsCore/Defaults/DateTimePoint.cs @@ -34,7 +34,6 @@ public class DateTimePoint : IChartEntity, INotifyPropertyChanged { private DateTime _dateTime; private double? _value; - private ChartEntityMetadata? _chartMetadata; /// /// Initializes a new instance of the class. @@ -51,6 +50,7 @@ public DateTimePoint(DateTime dateTime, double? value) { DateTime = dateTime; Value = value; + Coordinate = value is null ? Coordinate.Empty : new(dateTime.Ticks, value.Value); } /// @@ -69,28 +69,28 @@ public DateTimePoint(DateTime dateTime, double? value) /// public double? Value { get => _value; set { _value = value; OnPropertyChanged(); } } + /// + public int EntityIndex { get; set; } + + /// + public ChartPoint? ChartPoint { get; set; } + + /// + public Coordinate Coordinate { get; private set; } = Coordinate.Empty; + /// /// Occurs when a property value changes. /// /// public event PropertyChangedEventHandler? PropertyChanged; - /// - public ChartEntityMetadata ChartMetadata => _chartMetadata ??= new(this, AsCoordinate); - /// /// Called when a property changed. /// /// Name of the property. protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null) { + Coordinate = _value is null ? Coordinate.Empty : new(_dateTime.Ticks, _value.Value); PropertyChanged?.Invoke(propertyName, new PropertyChangedEventArgs(propertyName)); } - - private Coordinate AsCoordinate() - { - return _value is null - ? Coordinate.Empty - : new(_dateTime.Ticks, _value.Value); - } } diff --git a/src/LiveChartsCore/Defaults/FinancialPoint.cs b/src/LiveChartsCore/Defaults/FinancialPoint.cs index 0f60014b4..17389bc21 100644 --- a/src/LiveChartsCore/Defaults/FinancialPoint.cs +++ b/src/LiveChartsCore/Defaults/FinancialPoint.cs @@ -37,7 +37,6 @@ public class FinancialPoint : IChartEntity, INotifyPropertyChanged private double? _close; private double? _low; private DateTime _date; - private ChartEntityMetadata? _chartMetadata; /// /// Initializes a new instance of the class. @@ -102,28 +101,30 @@ public FinancialPoint(DateTime date, double? high, double? open, double? close, /// public double? Low { get => _low; set { _low = value; OnPropertyChanged(); } } + /// + public int EntityIndex { get; set; } + + /// + public ChartPoint? ChartPoint { get; set; } + + /// + public Coordinate Coordinate { get; private set; } = Coordinate.Empty; + /// /// Occurs when a property value changes. /// /// public event PropertyChangedEventHandler? PropertyChanged; - /// - public ChartEntityMetadata ChartMetadata => _chartMetadata ??= new(this, AsCoordinate); - /// /// Called when a property changed. /// /// Name of the property. protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null) { - PropertyChanged?.Invoke(propertyName, new PropertyChangedEventArgs(propertyName)); - } - - private Coordinate AsCoordinate() - { - return _open is null || _high is null || _low is null || _close is null + Coordinate = _open is null || _high is null || _low is null || _close is null ? Coordinate.Empty : new(_high.Value, _date.Ticks, _open.Value, _close.Value, _low.Value); + PropertyChanged?.Invoke(propertyName, new PropertyChangedEventArgs(propertyName)); } } diff --git a/src/LiveChartsCore/Defaults/ObservablePoint.cs b/src/LiveChartsCore/Defaults/ObservablePoint.cs index e54815c1c..2fb971850 100644 --- a/src/LiveChartsCore/Defaults/ObservablePoint.cs +++ b/src/LiveChartsCore/Defaults/ObservablePoint.cs @@ -34,7 +34,6 @@ public class ObservablePoint : IChartEntity, INotifyPropertyChanged { private double? _x; private double? _y; - private ChartEntityMetadata? _chartMetadata; /// /// Initializes a new instance of the class. @@ -69,28 +68,30 @@ public ObservablePoint(double? x, double? y) /// public double? Y { get => _y; set { _y = value; OnPropertyChanged(); } } + /// + public int EntityIndex { get; set; } + + /// + public ChartPoint? ChartPoint { get; set; } + + /// + public Coordinate Coordinate { get; private set; } = Coordinate.Empty; + /// /// Occurs when a property value changes. /// /// public event PropertyChangedEventHandler? PropertyChanged; - /// - public ChartEntityMetadata ChartMetadata => _chartMetadata ??= new(this, AsCoordinate); - /// /// Called when a property changes. /// /// Name of the property. protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null) { - PropertyChanged?.Invoke(propertyName, new PropertyChangedEventArgs(propertyName)); - } - - private Coordinate AsCoordinate() - { - return _x is null || _y is null + Coordinate = _x is null || _y is null ? Coordinate.Empty : new Coordinate(_x.Value, _y.Value); + PropertyChanged?.Invoke(propertyName, new PropertyChangedEventArgs(propertyName)); } } diff --git a/src/LiveChartsCore/Defaults/ObservablePolarPoint.cs b/src/LiveChartsCore/Defaults/ObservablePolarPoint.cs index 60a921108..d70308d50 100644 --- a/src/LiveChartsCore/Defaults/ObservablePolarPoint.cs +++ b/src/LiveChartsCore/Defaults/ObservablePolarPoint.cs @@ -33,7 +33,6 @@ public class ObservablePolarPoint : IChartEntity, INotifyPropertyChanged { private double? _angle; private double? _radius; - private ChartEntityMetadata? _chartMetadata; /// /// Initializes a new instance of the class. @@ -48,8 +47,8 @@ public ObservablePolarPoint() /// The radius. public ObservablePolarPoint(double? angle, double? radius) { - _angle = angle; - _radius = radius; + Angle = angle; + Radius = radius; } /// @@ -62,26 +61,28 @@ public ObservablePolarPoint(double? angle, double? radius) /// public double? Radius { get => _radius; set { _radius = value; OnPropertyChanged(); } } + /// + public int EntityIndex { get; set; } + + /// + public ChartPoint? ChartPoint { get; set; } + + /// + public Coordinate Coordinate { get; private set; } = Coordinate.Empty; + /// /// Called when a property changes. /// public event PropertyChangedEventHandler? PropertyChanged; - /// - public ChartEntityMetadata ChartMetadata => _chartMetadata ??= new(this, AsCoordinate); - /// /// Raises the property changed event. /// protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null) { - PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); - } - - private Coordinate AsCoordinate() - { - return _radius is null || _angle is null + Coordinate = _radius is null || _angle is null ? Coordinate.Empty : new(_angle.Value, _radius.Value); + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } } diff --git a/src/LiveChartsCore/Defaults/ObservableValue.cs b/src/LiveChartsCore/Defaults/ObservableValue.cs index ab4228716..554102f81 100644 --- a/src/LiveChartsCore/Defaults/ObservableValue.cs +++ b/src/LiveChartsCore/Defaults/ObservableValue.cs @@ -33,7 +33,7 @@ namespace LiveChartsCore.Defaults; public class ObservableValue : IChartEntity, INotifyPropertyChanged { private double? _value; - private ChartEntityMetadata? _chartMetadata; + private int _entityIndex; /// /// Initializes a new instance of the class. @@ -58,28 +58,49 @@ public ObservableValue(double? value) /// public double? Value { get => _value; set { _value = value; OnPropertyChanged(); } } + /// + public int EntityIndex + { + get => _entityIndex; + set + { + // the coordinate of this type depends on the index of element in the data collection. + // we update the coordinate if the index changed. + if (value == _entityIndex) return; + _entityIndex = value; + OnCoordinateChanged(); + } + } + + /// + public ChartPoint? ChartPoint { get; set; } + + /// + public Coordinate Coordinate { get; private set; } = Coordinate.Empty; + /// /// Occurs when a property value changes. /// /// public event PropertyChangedEventHandler? PropertyChanged; - /// - public ChartEntityMetadata ChartMetadata => _chartMetadata ??= new(this, AsCoordinate); - /// /// Called when am property changed. /// /// Name of the property. protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null) { + OnCoordinateChanged(); PropertyChanged?.Invoke(propertyName, new PropertyChangedEventArgs(propertyName)); } - private Coordinate AsCoordinate() + /// + /// Called when the coordinate changed. + /// + protected virtual void OnCoordinateChanged() { - return _value is null + Coordinate = _value is null ? Coordinate.Empty - : new(ChartMetadata.EntityIndex, _value.Value); + : new(EntityIndex, _value.Value); } } diff --git a/src/LiveChartsCore/Defaults/TimeSpanPoint.cs b/src/LiveChartsCore/Defaults/TimeSpanPoint.cs index 86c440450..6be71ef0e 100644 --- a/src/LiveChartsCore/Defaults/TimeSpanPoint.cs +++ b/src/LiveChartsCore/Defaults/TimeSpanPoint.cs @@ -34,7 +34,6 @@ public class TimeSpanPoint : IChartEntity, INotifyPropertyChanged { private TimeSpan _timeSpan; private double? _value; - private ChartEntityMetadata? _chartMetadata; /// /// Initializes a new instance of the class. @@ -69,8 +68,14 @@ public TimeSpanPoint(TimeSpan timeSpan, double? value) /// public double? Value { get => _value; set { _value = value; OnPropertyChanged(); } } - /// - public ChartEntityMetadata ChartMetadata => _chartMetadata ??= new(this, AsCoordinate); + /// + public int EntityIndex { get; set; } + + /// + public ChartPoint? ChartPoint { get; set; } + + /// + public Coordinate Coordinate { get; private set; } = Coordinate.Empty; /// /// Occurs when a property value changes. @@ -84,13 +89,9 @@ public TimeSpanPoint(TimeSpan timeSpan, double? value) /// Name of the property. protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null) { - PropertyChanged?.Invoke(propertyName, new PropertyChangedEventArgs(propertyName)); - } - - private Coordinate AsCoordinate() - { - return _value is null + Coordinate = _value is null ? Coordinate.Empty : new(_timeSpan.Ticks, _value ?? 0d); + PropertyChanged?.Invoke(propertyName, new PropertyChangedEventArgs(propertyName)); } } diff --git a/src/LiveChartsCore/Defaults/WeightedPoint.cs b/src/LiveChartsCore/Defaults/WeightedPoint.cs index 78606f1eb..b0cf31625 100644 --- a/src/LiveChartsCore/Defaults/WeightedPoint.cs +++ b/src/LiveChartsCore/Defaults/WeightedPoint.cs @@ -35,7 +35,6 @@ public class WeightedPoint : IChartEntity, INotifyPropertyChanged private double? _x; private double? _y; private double? _weight; - private ChartEntityMetadata? _chartMetadata; /// /// Initializes a new instance of the class. @@ -86,8 +85,14 @@ public WeightedPoint(double? x, double? y, double? weight) /// public event PropertyChangedEventHandler? PropertyChanged; - /// - public ChartEntityMetadata ChartMetadata => _chartMetadata ??= new(this, AsCoordinate); + /// + public int EntityIndex { get; set; } + + /// + public ChartPoint? ChartPoint { get; set; } + + /// + public Coordinate Coordinate { get; private set; } = Coordinate.Empty; /// /// Called when a property changed. @@ -95,13 +100,9 @@ public WeightedPoint(double? x, double? y, double? weight) /// Name of the property. protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null) { - PropertyChanged?.Invoke(propertyName, new PropertyChangedEventArgs(propertyName)); - } - - private Coordinate AsCoordinate() - { - return _x is null || _y is null + Coordinate = _x is null || _y is null ? Coordinate.Empty : new(_x ?? 0, _y ?? 0, _weight ?? 0); + PropertyChanged?.Invoke(propertyName, new PropertyChangedEventArgs(propertyName)); } } diff --git a/src/LiveChartsCore/Kernel/ChartEntityMetadata.cs b/src/LiveChartsCore/Kernel/ChartEntityMetadata.cs deleted file mode 100644 index f903ac0a2..000000000 --- a/src/LiveChartsCore/Kernel/ChartEntityMetadata.cs +++ /dev/null @@ -1,89 +0,0 @@ -// The MIT License(MIT) -// -// Copyright(c) 2021 Alberto Rodriguez Orozco & LiveCharts Contributors -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -using System; -using System.ComponentModel; - -namespace LiveChartsCore.Kernel; - -/// -/// Defines the class. -/// -public class ChartEntityMetadata -{ - private readonly Func _coordinateBuilder; - private int _entityIndex = -1; - - /// - /// Initializes a new instance of the class. - /// - /// The coordinate builder. - public ChartEntityMetadata(Func coordinateBuilder) - { - _coordinateBuilder = coordinateBuilder; - } - - /// - /// Initializes a new instance of the class. - /// - /// The entity. - /// The coordinate builder. - public ChartEntityMetadata(INotifyPropertyChanged entity, Func coordinateBuilder) - { - _coordinateBuilder = coordinateBuilder; - entity.PropertyChanged += OnEntityPropertyChanged; - } - - /// - /// Gets the entity index, a consecutive integer based on the position of the entity in the data collection. - /// - public int EntityIndex - { - get => _entityIndex; - internal set - { - var changed = _entityIndex != value; - _entityIndex = value; - if (changed) OnCoordinateChanged(); - } - } - - /// - /// Gets the chart point. - /// - public ChartPoint? ChartPoint { get; internal set; } = null; - - /// - /// Gets the coordinate. - /// - public Coordinate Coordinate { get; private set; } = Coordinate.Empty; - - private void OnEntityPropertyChanged(object sender, PropertyChangedEventArgs e) - { - OnCoordinateChanged(); - } - - private void OnCoordinateChanged() - { - Coordinate = _coordinateBuilder(); - } -} diff --git a/src/LiveChartsCore/Kernel/IChartEntity.cs b/src/LiveChartsCore/Kernel/IChartEntity.cs index fd6698fb4..a60f0c17e 100644 --- a/src/LiveChartsCore/Kernel/IChartEntity.cs +++ b/src/LiveChartsCore/Kernel/IChartEntity.cs @@ -28,7 +28,17 @@ namespace LiveChartsCore.Kernel; public interface IChartEntity { /// - /// Gets the chart entity metadata, just some information LiveCharts needs to make this object a chart point. + /// Gets the entity index, a consecutive integer based on the position of the entity in the data collection. /// - public ChartEntityMetadata ChartMetadata { get; } + public int EntityIndex { get; set; } + + /// + /// Gets the chart point. + /// + public ChartPoint? ChartPoint { get; set; } + + /// + /// Gets the coordinate. + /// + Coordinate Coordinate { get; } } diff --git a/src/LiveChartsCore/Kernel/Providers/DataFactory.cs b/src/LiveChartsCore/Kernel/Providers/DataFactory.cs index ae73cd9c9..4af7a9afd 100644 --- a/src/LiveChartsCore/Kernel/Providers/DataFactory.cs +++ b/src/LiveChartsCore/Kernel/Providers/DataFactory.cs @@ -42,7 +42,11 @@ public class DataFactory private readonly bool _isValueType = false; private readonly Dictionary> _chartIndexEntityMap = new(); private readonly Dictionary> _chartRefEntityMap = new(); - private DimensionalBounds _previousKnownBounds; + + /// + /// Gets or sets the previous known bounds. + /// + protected DimensionalBounds PreviousKnownBounds { get; set; } = new DimensionalBounds(true); /// /// Initializes a new instance of the class. @@ -50,7 +54,7 @@ public class DataFactory public DataFactory() { var bounds = new DimensionalBounds(true); - _previousKnownBounds = bounds; + PreviousKnownBounds = bounds; var t = typeof(TModel); _isValueType = t.IsValueType; @@ -82,7 +86,7 @@ public virtual IEnumerable Fetch(ISeries series, IChart char continue; } - yield return value.ChartMetadata.ChartPoint ?? ChartPoint.Empty; + yield return value.ChartPoint ?? ChartPoint.Empty; } } @@ -194,8 +198,8 @@ public virtual SeriesBounds GetCartesianBounds( } return !hasData - ? new SeriesBounds(_previousKnownBounds, true) - : new SeriesBounds(_previousKnownBounds = bounds, false); + ? new SeriesBounds(PreviousKnownBounds, true) + : new SeriesBounds(PreviousKnownBounds = bounds, false); } /// @@ -254,8 +258,8 @@ public virtual SeriesBounds GetFinancialBounds( } return !hasData - ? new SeriesBounds(_previousKnownBounds, true) - : new SeriesBounds(_previousKnownBounds = bounds, false); + ? new SeriesBounds(PreviousKnownBounds, true) + : new SeriesBounds(PreviousKnownBounds = bounds, false); } /// @@ -303,11 +307,11 @@ private IEnumerable EnumerateChartEntities(ISeries series, { if (entity is null) continue; - entity.ChartMetadata.ChartPoint ??= new ChartPoint(chart.View, series); - entity.ChartMetadata.ChartPoint.Context.DataSource = entity; - entity.ChartMetadata.ChartPoint.Context.Index = index; - entity.ChartMetadata.EntityIndex = index++; - entity.ChartMetadata.ChartPoint.Coordinate = entity.ChartMetadata.Coordinate; + entity.ChartPoint ??= new ChartPoint(chart.View, series); + entity.ChartPoint.Context.DataSource = entity; + entity.ChartPoint.Context.Index = index; + entity.EntityIndex = index++; + entity.ChartPoint.Coordinate = entity.Coordinate; yield return entity; } @@ -336,12 +340,12 @@ private IEnumerable EnumerateChartEntities(ISeries series, IndexEntityMap[index] = entity = new ChartEntity(); } - entity.ChartMetadata.ChartPoint ??= new ChartPoint(chart.View, series); - entity.ChartMetadata.ChartPoint.Context.DataSource = item; - entity.ChartMetadata.EntityIndex = index; - entity.ChartMetadata.ChartPoint.Context.Index = index++; + entity.ChartPoint ??= new ChartPoint(chart.View, series); + entity.ChartPoint.Context.DataSource = item; + entity.EntityIndex = index; + entity.ChartPoint.Context.Index = index++; - mapper(item, entity.ChartMetadata.ChartPoint); + mapper(item, entity.ChartPoint); yield return entity; } @@ -376,12 +380,12 @@ private IEnumerable EnumerateChartEntities(ISeries series, IndexEntityMap[item] = entity = new ChartEntity(); } - entity.ChartMetadata.ChartPoint ??= new ChartPoint(chart.View, series); - entity.ChartMetadata.ChartPoint.Context.DataSource = item; - entity.ChartMetadata.EntityIndex = index; - entity.ChartMetadata.ChartPoint.Context.Index = index++; + entity.ChartPoint ??= new ChartPoint(chart.View, series); + entity.ChartPoint.Context.DataSource = item; + entity.EntityIndex = index; + entity.ChartPoint.Context.Index = index++; - mapper(item, entity.ChartMetadata.ChartPoint); + mapper(item, entity.ChartPoint); yield return entity; } diff --git a/src/skiasharp/LiveChartsCore.SkiaSharp.WPF/AssemblyInfo.cs b/src/skiasharp/LiveChartsCore.SkiaSharp.WPF/AssemblyInfo.cs index ef2b24be4..262458c50 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharp.WPF/AssemblyInfo.cs +++ b/src/skiasharp/LiveChartsCore.SkiaSharp.WPF/AssemblyInfo.cs @@ -33,9 +33,9 @@ // app, or any theme specific resource dictionaries) )] -#if !DEBUG -[assembly: AssemblyKeyFile("./../../../LiveCharts.snk")] -[assembly: InternalsVisibleTo("LiveChartsCore.BackersPackage, PublicKey=0024000004800000940000000602000000240000525341310004000001000100d53791eaa0d98b405ca858f39169be6af36ceb7a1bca3ca76c6905fd22fddf8c5e4ef2778a5d7a77ad12f08da711fecfc44795c7923739a2acac946b3f1719a6dfc238695bc69cf5d959b3fb6bc4d18d57a97ff8ed897e6b22a6b8155401ee368d77431e74178104b4adca73520b058b9be28d4ec129beb54871778167afa5ce")] -#else +//#if !DEBUG +//[assembly: AssemblyKeyFile("./../../../LiveCharts.snk")] +//[assembly: InternalsVisibleTo("LiveChartsCore.BackersPackage, PublicKey=0024000004800000940000000602000000240000525341310004000001000100d53791eaa0d98b405ca858f39169be6af36ceb7a1bca3ca76c6905fd22fddf8c5e4ef2778a5d7a77ad12f08da711fecfc44795c7923739a2acac946b3f1719a6dfc238695bc69cf5d959b3fb6bc4d18d57a97ff8ed897e6b22a6b8155401ee368d77431e74178104b4adca73520b058b9be28d4ec129beb54871778167afa5ce")] +//#else [assembly: InternalsVisibleTo("LiveChartsCore.BackersPackage")] -#endif +//#endif From 77592827eee3aa7f563d139f21634cebef7a45a5 Mon Sep 17 00:00:00 2001 From: beto-rodriguez Date: Thu, 18 Aug 2022 09:38:11 -0500 Subject: [PATCH 12/25] one visual per chart --- src/LiveChartsCore/Defaults/ChartEntity.cs | 15 ++++-- src/LiveChartsCore/Defaults/DateTimePoint.cs | 6 ++- src/LiveChartsCore/Defaults/FinancialPoint.cs | 6 ++- .../Defaults/ObservablePoint.cs | 6 ++- .../Defaults/ObservablePolarPoint.cs | 6 ++- .../Defaults/ObservableValue.cs | 6 ++- src/LiveChartsCore/Defaults/TimeSpanPoint.cs | 6 ++- src/LiveChartsCore/Defaults/WeightedPoint.cs | 6 ++- src/LiveChartsCore/Kernel/Extensions.cs | 19 +++++-- src/LiveChartsCore/Kernel/IChartEntity.cs | 7 ++- .../Kernel/Providers/DataFactory.cs | 52 +++++++++++++------ 11 files changed, 95 insertions(+), 40 deletions(-) diff --git a/src/LiveChartsCore/Defaults/ChartEntity.cs b/src/LiveChartsCore/Defaults/ChartEntity.cs index d904d2964..d7cf8a534 100644 --- a/src/LiveChartsCore/Defaults/ChartEntity.cs +++ b/src/LiveChartsCore/Defaults/ChartEntity.cs @@ -20,21 +20,26 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. +using System.Collections.Generic; +using System.Linq; using LiveChartsCore.Kernel; +using LiveChartsCore.Kernel.Sketches; namespace LiveChartsCore.Defaults; /// -/// Defines the class. +/// Defines the class, a helper class to map any object that does not implements , +/// when you need a better performance you should implement in your DTOs, the default objects in the library +/// already implement . /// -public class ChartEntity : IChartEntity +public sealed class ChartEntity : IChartEntity { /// public int EntityIndex { get; set; } - /// - public ChartPoint? ChartPoint { get; set; } + /// + public Dictionary? ChartPoints { get; set; } /// - public Coordinate Coordinate => ChartPoint?.Coordinate ?? Coordinate.Empty; + public Coordinate Coordinate => ChartPoints?.Values.FirstOrDefault()?.Coordinate ?? Coordinate.Empty; } diff --git a/src/LiveChartsCore/Defaults/DateTimePoint.cs b/src/LiveChartsCore/Defaults/DateTimePoint.cs index a8fbf0642..e81b8b22f 100644 --- a/src/LiveChartsCore/Defaults/DateTimePoint.cs +++ b/src/LiveChartsCore/Defaults/DateTimePoint.cs @@ -21,9 +21,11 @@ // SOFTWARE. using System; +using System.Collections.Generic; using System.ComponentModel; using System.Runtime.CompilerServices; using LiveChartsCore.Kernel; +using LiveChartsCore.Kernel.Sketches; namespace LiveChartsCore.Defaults; @@ -72,8 +74,8 @@ public DateTimePoint(DateTime dateTime, double? value) /// public int EntityIndex { get; set; } - /// - public ChartPoint? ChartPoint { get; set; } + /// + public Dictionary? ChartPoints { get; set; } /// public Coordinate Coordinate { get; private set; } = Coordinate.Empty; diff --git a/src/LiveChartsCore/Defaults/FinancialPoint.cs b/src/LiveChartsCore/Defaults/FinancialPoint.cs index 17389bc21..7deba81cd 100644 --- a/src/LiveChartsCore/Defaults/FinancialPoint.cs +++ b/src/LiveChartsCore/Defaults/FinancialPoint.cs @@ -21,9 +21,11 @@ // SOFTWARE. using System; +using System.Collections.Generic; using System.ComponentModel; using System.Runtime.CompilerServices; using LiveChartsCore.Kernel; +using LiveChartsCore.Kernel.Sketches; namespace LiveChartsCore.Defaults; @@ -104,8 +106,8 @@ public FinancialPoint(DateTime date, double? high, double? open, double? close, /// public int EntityIndex { get; set; } - /// - public ChartPoint? ChartPoint { get; set; } + /// + public Dictionary? ChartPoints { get; set; } /// public Coordinate Coordinate { get; private set; } = Coordinate.Empty; diff --git a/src/LiveChartsCore/Defaults/ObservablePoint.cs b/src/LiveChartsCore/Defaults/ObservablePoint.cs index 2fb971850..03ec2a013 100644 --- a/src/LiveChartsCore/Defaults/ObservablePoint.cs +++ b/src/LiveChartsCore/Defaults/ObservablePoint.cs @@ -20,9 +20,11 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. +using System.Collections.Generic; using System.ComponentModel; using System.Runtime.CompilerServices; using LiveChartsCore.Kernel; +using LiveChartsCore.Kernel.Sketches; namespace LiveChartsCore.Defaults; @@ -71,8 +73,8 @@ public ObservablePoint(double? x, double? y) /// public int EntityIndex { get; set; } - /// - public ChartPoint? ChartPoint { get; set; } + /// + public Dictionary? ChartPoints { get; set; } /// public Coordinate Coordinate { get; private set; } = Coordinate.Empty; diff --git a/src/LiveChartsCore/Defaults/ObservablePolarPoint.cs b/src/LiveChartsCore/Defaults/ObservablePolarPoint.cs index d70308d50..4e239d51a 100644 --- a/src/LiveChartsCore/Defaults/ObservablePolarPoint.cs +++ b/src/LiveChartsCore/Defaults/ObservablePolarPoint.cs @@ -20,9 +20,11 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. +using System.Collections.Generic; using System.ComponentModel; using System.Runtime.CompilerServices; using LiveChartsCore.Kernel; +using LiveChartsCore.Kernel.Sketches; namespace LiveChartsCore.Defaults; @@ -64,8 +66,8 @@ public ObservablePolarPoint(double? angle, double? radius) /// public int EntityIndex { get; set; } - /// - public ChartPoint? ChartPoint { get; set; } + /// + public Dictionary? ChartPoints { get; set; } /// public Coordinate Coordinate { get; private set; } = Coordinate.Empty; diff --git a/src/LiveChartsCore/Defaults/ObservableValue.cs b/src/LiveChartsCore/Defaults/ObservableValue.cs index 554102f81..48e5de37a 100644 --- a/src/LiveChartsCore/Defaults/ObservableValue.cs +++ b/src/LiveChartsCore/Defaults/ObservableValue.cs @@ -20,9 +20,11 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. +using System.Collections.Generic; using System.ComponentModel; using System.Runtime.CompilerServices; using LiveChartsCore.Kernel; +using LiveChartsCore.Kernel.Sketches; namespace LiveChartsCore.Defaults; @@ -72,8 +74,8 @@ public int EntityIndex } } - /// - public ChartPoint? ChartPoint { get; set; } + /// + public Dictionary? ChartPoints { get; set; } /// public Coordinate Coordinate { get; private set; } = Coordinate.Empty; diff --git a/src/LiveChartsCore/Defaults/TimeSpanPoint.cs b/src/LiveChartsCore/Defaults/TimeSpanPoint.cs index 6be71ef0e..4dc69f222 100644 --- a/src/LiveChartsCore/Defaults/TimeSpanPoint.cs +++ b/src/LiveChartsCore/Defaults/TimeSpanPoint.cs @@ -21,9 +21,11 @@ // SOFTWARE. using System; +using System.Collections.Generic; using System.ComponentModel; using System.Runtime.CompilerServices; using LiveChartsCore.Kernel; +using LiveChartsCore.Kernel.Sketches; namespace LiveChartsCore.Defaults; @@ -71,8 +73,8 @@ public TimeSpanPoint(TimeSpan timeSpan, double? value) /// public int EntityIndex { get; set; } - /// - public ChartPoint? ChartPoint { get; set; } + /// + public Dictionary? ChartPoints { get; set; } /// public Coordinate Coordinate { get; private set; } = Coordinate.Empty; diff --git a/src/LiveChartsCore/Defaults/WeightedPoint.cs b/src/LiveChartsCore/Defaults/WeightedPoint.cs index b0cf31625..9f614b1b0 100644 --- a/src/LiveChartsCore/Defaults/WeightedPoint.cs +++ b/src/LiveChartsCore/Defaults/WeightedPoint.cs @@ -20,9 +20,11 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. +using System.Collections.Generic; using System.ComponentModel; using System.Runtime.CompilerServices; using LiveChartsCore.Kernel; +using LiveChartsCore.Kernel.Sketches; namespace LiveChartsCore.Defaults; @@ -88,8 +90,8 @@ public WeightedPoint(double? x, double? y, double? weight) /// public int EntityIndex { get; set; } - /// - public ChartPoint? ChartPoint { get; set; } + /// + public Dictionary? ChartPoints { get; set; } /// public Coordinate Coordinate { get; private set; } = Coordinate.Empty; diff --git a/src/LiveChartsCore/Kernel/Extensions.cs b/src/LiveChartsCore/Kernel/Extensions.cs index f92687dea..2982dea7d 100644 --- a/src/LiveChartsCore/Kernel/Extensions.cs +++ b/src/LiveChartsCore/Kernel/Extensions.cs @@ -30,7 +30,7 @@ namespace LiveChartsCore.Kernel; /// -/// LiveCharts kerner extensions. +/// LiveCharts kernel extensions. /// public static class Extensions { @@ -301,7 +301,7 @@ public static TooltipFindingStrategy GetTooltipFindingStrategy(this IEnumerable< /// /// Finds the closest point to the specified location in UI coordinates. /// - /// The points to look in to.bcv + /// The points to look in to. /// The location. /// public static ChartPoint FindClosestTo(this IEnumerable points, LvcPoint point) @@ -312,7 +312,7 @@ public static ChartPoint FindClosestTo(this IEnumerable points, LvcP /// /// Finds the closest point to the specified location in UI coordinates. /// - /// The points to look in to.bcv + /// The points to look in to. /// The location. /// public static ChartPoint FindClosestTo( @@ -359,7 +359,7 @@ public static Scaler GetNextScaler(this ICartesianAxis axis, Ca } /// - /// Returns an enumeration with only the fisrt element. + /// Returns an enumeration with only the first element. /// /// The source type. /// The target type. @@ -375,6 +375,17 @@ public static IEnumerable SelectFirst(this IEnumerable source, Fun } } + /// + /// Gets the point for the given view. + /// + /// The points dictionary. + /// The view. + /// + public static ChartPoint? GetPointForView(this Dictionary dictionary, IChartView view) + { + return dictionary.TryGetValue(view, out var point) ? point : null; + } + private static ChartPoint _findClosestTo(this IEnumerable points, LvcPoint point) { var o = points.Select(p => new { distance = p.DistanceTo(point), point = p }).OrderBy(p => p.distance).ToArray(); diff --git a/src/LiveChartsCore/Kernel/IChartEntity.cs b/src/LiveChartsCore/Kernel/IChartEntity.cs index a60f0c17e..4a76d3829 100644 --- a/src/LiveChartsCore/Kernel/IChartEntity.cs +++ b/src/LiveChartsCore/Kernel/IChartEntity.cs @@ -20,6 +20,9 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. +using System.Collections.Generic; +using LiveChartsCore.Kernel.Sketches; + namespace LiveChartsCore.Kernel; /// @@ -33,9 +36,9 @@ public interface IChartEntity public int EntityIndex { get; set; } /// - /// Gets the chart point. + /// Gets the chart points dictionary. /// - public ChartPoint? ChartPoint { get; set; } + public Dictionary? ChartPoints { get; set; } /// /// Gets the coordinate. diff --git a/src/LiveChartsCore/Kernel/Providers/DataFactory.cs b/src/LiveChartsCore/Kernel/Providers/DataFactory.cs index 4af7a9afd..24c50c10d 100644 --- a/src/LiveChartsCore/Kernel/Providers/DataFactory.cs +++ b/src/LiveChartsCore/Kernel/Providers/DataFactory.cs @@ -86,7 +86,7 @@ public virtual IEnumerable Fetch(ISeries series, IChart char continue; } - yield return value.ChartPoint ?? ChartPoint.Empty; + yield return value.ChartPoints?.GetPointForView(chart.View) ?? ChartPoint.Empty; } } @@ -307,11 +307,17 @@ private IEnumerable EnumerateChartEntities(ISeries series, { if (entity is null) continue; - entity.ChartPoint ??= new ChartPoint(chart.View, series); - entity.ChartPoint.Context.DataSource = entity; - entity.ChartPoint.Context.Index = index; + entity.ChartPoints ??= new Dictionary(); + if (!entity.ChartPoints.TryGetValue(chart.View, out var point)) + { + point = new ChartPoint(chart.View, series); + entity.ChartPoints[chart.View] = point; + } + + point.Context.DataSource = entity; + point.Context.Index = index; entity.EntityIndex = index++; - entity.ChartPoint.Coordinate = entity.Coordinate; + point.Coordinate = entity.Coordinate; yield return entity; } @@ -337,15 +343,23 @@ private IEnumerable EnumerateChartEntities(ISeries series, { if (!IndexEntityMap.TryGetValue(index, out var entity)) { - IndexEntityMap[index] = entity = new ChartEntity(); + IndexEntityMap[index] = entity = new ChartEntity + { + ChartPoints = new Dictionary() + }; } - entity.ChartPoint ??= new ChartPoint(chart.View, series); - entity.ChartPoint.Context.DataSource = item; + if (!entity.ChartPoints!.TryGetValue(chart.View, out var point)) + { + point = new ChartPoint(chart.View, series); + entity.ChartPoints[chart.View] = point; + } + + point.Context.DataSource = item; entity.EntityIndex = index; - entity.ChartPoint.Context.Index = index++; + point.Context.Index = index++; - mapper(item, entity.ChartPoint); + mapper(item, point); yield return entity; } @@ -377,15 +391,23 @@ private IEnumerable EnumerateChartEntities(ISeries series, if (!IndexEntityMap.TryGetValue(item, out var entity)) { - IndexEntityMap[item] = entity = new ChartEntity(); + IndexEntityMap[item] = entity = new ChartEntity + { + ChartPoints = new Dictionary() + }; + } + + if (!entity.ChartPoints!.TryGetValue(chart.View, out var point)) + { + point = new ChartPoint(chart.View, series); + entity.ChartPoints[chart.View] = point; } - entity.ChartPoint ??= new ChartPoint(chart.View, series); - entity.ChartPoint.Context.DataSource = item; + point.Context.DataSource = item; entity.EntityIndex = index; - entity.ChartPoint.Context.Index = index++; + point.Context.Index = index++; - mapper(item, entity.ChartPoint); + mapper(item, point); yield return entity; } From b747d1428ad93f1a1d9d39738e3d56e641e5b071 Mon Sep 17 00:00:00 2001 From: beto-rodriguez Date: Thu, 18 Aug 2022 19:12:36 -0500 Subject: [PATCH 13/25] just cleaning things up --- src/LiveChartsCore/ColumnSeries.cs | 2 +- .../{ChartEntity.cs => MappedChartEntity.cs} | 13 ++- src/LiveChartsCore/FinancialSeries.cs | 2 +- src/LiveChartsCore/HeatSeries.cs | 2 +- src/LiveChartsCore/Kernel/ChartPoint.cs | 87 ++++++++++--------- .../Kernel/ChartPointContext.cs | 17 +++- src/LiveChartsCore/Kernel/Coordinate.cs | 10 +-- .../Kernel/LiveChartsSettings.cs | 84 +++++------------- .../Kernel/Providers/DataFactory.cs | 44 ++++++---- .../Measure/MeasureExtensions.cs | 2 +- src/LiveChartsCore/PieSeries.cs | 2 +- src/LiveChartsCore/PolarLineSeries.cs | 2 +- src/LiveChartsCore/RowSeries.cs | 2 +- src/LiveChartsCore/ScatterSeries.cs | 2 +- 14 files changed, 132 insertions(+), 139 deletions(-) rename src/LiveChartsCore/Defaults/{ChartEntity.cs => MappedChartEntity.cs} (77%) diff --git a/src/LiveChartsCore/ColumnSeries.cs b/src/LiveChartsCore/ColumnSeries.cs index 86e0b7453..39cf035f2 100644 --- a/src/LiveChartsCore/ColumnSeries.cs +++ b/src/LiveChartsCore/ColumnSeries.cs @@ -115,7 +115,7 @@ public override void Measure(Chart chart) var secondary = secondaryScale.ToPixels(point.SecondaryValue); var b = Math.Abs(primary - helper.p); - if (point.Coordinate.IsEmpty || point.IsNull) + if (point.IsEmpty) { if (visual is not null) { diff --git a/src/LiveChartsCore/Defaults/ChartEntity.cs b/src/LiveChartsCore/Defaults/MappedChartEntity.cs similarity index 77% rename from src/LiveChartsCore/Defaults/ChartEntity.cs rename to src/LiveChartsCore/Defaults/MappedChartEntity.cs index d7cf8a534..ecfeb7c0b 100644 --- a/src/LiveChartsCore/Defaults/ChartEntity.cs +++ b/src/LiveChartsCore/Defaults/MappedChartEntity.cs @@ -21,18 +21,17 @@ // SOFTWARE. using System.Collections.Generic; -using System.Linq; using LiveChartsCore.Kernel; using LiveChartsCore.Kernel.Sketches; namespace LiveChartsCore.Defaults; /// -/// Defines the class, a helper class to map any object that does not implements , +/// Defines the class, a helper class to map any object that does not implements , /// when you need a better performance you should implement in your DTOs, the default objects in the library /// already implement . /// -public sealed class ChartEntity : IChartEntity +public sealed class MappedChartEntity : IChartEntity { /// public int EntityIndex { get; set; } @@ -41,5 +40,11 @@ public sealed class ChartEntity : IChartEntity public Dictionary? ChartPoints { get; set; } /// - public Coordinate Coordinate => ChartPoints?.Values.FirstOrDefault()?.Coordinate ?? Coordinate.Empty; + public Coordinate Coordinate { get; private set; } = Coordinate.Empty; + + internal void UpdateCoordinate(ChartPoint chartPoint) + { + Coordinate = new Coordinate( + chartPoint.PrimaryValue, chartPoint.SecondaryValue, chartPoint.TertiaryValue, chartPoint.QuaternaryValue, chartPoint.QuinaryValue); + } } diff --git a/src/LiveChartsCore/FinancialSeries.cs b/src/LiveChartsCore/FinancialSeries.cs index 2b4fbe89f..59f263f2b 100644 --- a/src/LiveChartsCore/FinancialSeries.cs +++ b/src/LiveChartsCore/FinancialSeries.cs @@ -166,7 +166,7 @@ public override void Measure(Chart chart) var low = primaryScale.ToPixels(point.QuinaryValue); var middle = open; - if (point.Coordinate.IsEmpty || point.IsNull) + if (point.IsEmpty) { if (visual is not null) { diff --git a/src/LiveChartsCore/HeatSeries.cs b/src/LiveChartsCore/HeatSeries.cs index 48a27bcf8..ef018ccdd 100644 --- a/src/LiveChartsCore/HeatSeries.cs +++ b/src/LiveChartsCore/HeatSeries.cs @@ -128,7 +128,7 @@ public override void Measure(Chart chart) var baseColor = HeatFunctions.InterpolateColor(tertiary, _weightBounds, HeatMap, _heatStops); - if (point.Coordinate.IsEmpty || point.IsNull) + if (point.IsEmpty) { if (visual is not null) { diff --git a/src/LiveChartsCore/Kernel/ChartPoint.cs b/src/LiveChartsCore/Kernel/ChartPoint.cs index b4900b0e9..cdfcbd132 100644 --- a/src/LiveChartsCore/Kernel/ChartPoint.cs +++ b/src/LiveChartsCore/Kernel/ChartPoint.cs @@ -31,29 +31,51 @@ namespace LiveChartsCore.Kernel; /// public class ChartPoint { + private Coordinate _localCoordinate = Coordinate.Empty; + + /// + /// Overrides whether the coordinate is empty. + /// + protected bool IsLocalEmpty; + /// /// Initializes a new instance of the class. /// /// The chart. /// The series. - public ChartPoint(IChartView chart, ISeries series) + /// The entity. + public ChartPoint(IChartView chart, ISeries series, IChartEntity entity) { - Context = new ChartPointContext(chart, series); + Context = new ChartPointContext(chart, series, entity); } - internal ChartPoint() + /// + /// Initializes a new instance of the class. + /// + /// The point. + protected ChartPoint(ChartPoint point) : this(point.Context.Chart, point.Context.Series, point.Context.Entity) + { + IsLocalEmpty = point.IsLocalEmpty; + } + + private ChartPoint() { Context = new ChartPointContext(); } + /// + /// Gets a new instance of an empty chart point. + /// + public static ChartPoint Empty => new() { IsLocalEmpty = true }; + /// /// Gets or sets a value indicating whether this instance is null. /// /// /// true if this instance is null; otherwise, false. /// - [Obsolete($"Replaced by {nameof(Coordinate)}.{nameof(Coordinate.Empty)}")] - public bool IsNull { get => IsEmpty; set => IsEmpty = value; } + [Obsolete($"Use IsEmpty instead")] + public bool IsNull => IsEmpty; /// /// Gets or sets a value indicating whether this instance is empty. @@ -61,8 +83,7 @@ internal ChartPoint() /// /// true if this instance is empty; otherwise, false. /// - [Obsolete($"Replaced by {nameof(Coordinate)}.{nameof(Coordinate.Empty)}")] - public bool IsEmpty { get; set; } + public bool IsEmpty => IsLocalEmpty || Context.Entity.Coordinate.IsEmpty; /// /// Gets or sets the primary value. @@ -72,9 +93,10 @@ internal ChartPoint() /// public double PrimaryValue { - get => Coordinate.PrimaryValue; + get => _localCoordinate.IsEmpty ? Context.Entity.Coordinate.PrimaryValue : _localCoordinate.PrimaryValue; set => OnCoordinateChanged( - new Coordinate(value, Coordinate.SecondaryValue, Coordinate.TertiaryValue, Coordinate.QuaternaryValue, Coordinate.QuinaryValue)); + new Coordinate(value, _localCoordinate.SecondaryValue, _localCoordinate.TertiaryValue, + _localCoordinate.QuaternaryValue, _localCoordinate.QuinaryValue)); } /// @@ -85,9 +107,10 @@ public double PrimaryValue /// public double SecondaryValue { - get => Coordinate.SecondaryValue; + get => _localCoordinate.IsEmpty ? Context.Entity.Coordinate.SecondaryValue : _localCoordinate.SecondaryValue; set => OnCoordinateChanged( - new Coordinate(Coordinate.PrimaryValue, value, Coordinate.TertiaryValue, Coordinate.QuaternaryValue, Coordinate.QuinaryValue)); + new Coordinate(_localCoordinate.PrimaryValue, value, _localCoordinate.TertiaryValue, + _localCoordinate.QuaternaryValue, _localCoordinate.QuinaryValue)); } /// @@ -98,9 +121,10 @@ public double SecondaryValue /// public double TertiaryValue { - get => Coordinate.TertiaryValue; + get => _localCoordinate.IsEmpty ? Context.Entity.Coordinate.TertiaryValue : _localCoordinate.TertiaryValue; set => OnCoordinateChanged( - new Coordinate(Coordinate.PrimaryValue, Coordinate.SecondaryValue, value, Coordinate.QuaternaryValue, Coordinate.QuinaryValue)); + new Coordinate(_localCoordinate.PrimaryValue, _localCoordinate.SecondaryValue, value, + _localCoordinate.QuaternaryValue, _localCoordinate.QuinaryValue)); } /// @@ -111,9 +135,10 @@ public double TertiaryValue /// public double QuaternaryValue { - get => Coordinate.QuaternaryValue; + get => _localCoordinate.IsEmpty ? Context.Entity.Coordinate.QuaternaryValue : _localCoordinate.QuaternaryValue; set => OnCoordinateChanged( - new Coordinate(Coordinate.PrimaryValue, Coordinate.SecondaryValue, Coordinate.TertiaryValue, value, Coordinate.QuinaryValue)); + new Coordinate(_localCoordinate.PrimaryValue, _localCoordinate.SecondaryValue, + _localCoordinate.TertiaryValue, value, _localCoordinate.QuinaryValue)); } /// @@ -124,9 +149,10 @@ public double QuaternaryValue /// public double QuinaryValue { - get => Coordinate.QuinaryValue; + get => _localCoordinate.IsEmpty ? Context.Entity.Coordinate.QuinaryValue : _localCoordinate.QuinaryValue; set => OnCoordinateChanged( - new Coordinate(Coordinate.PrimaryValue, Coordinate.SecondaryValue, Coordinate.TertiaryValue, Coordinate.QuaternaryValue, value)); + new Coordinate(_localCoordinate.PrimaryValue, _localCoordinate.SecondaryValue, + _localCoordinate.TertiaryValue, _localCoordinate.QuaternaryValue, value)); } /// @@ -158,23 +184,6 @@ public double QuinaryValue /// public ChartPointContext Context { get; } - /// - public Coordinate Coordinate { get; internal set; } - - /// - /// Marks the point as null or empty, it will be ignored in the UI. - /// - public ChartPoint AsEmpty() - { - Coordinate = Coordinate.Empty; - return this; - } - - /// - /// Gets a new instance of an empty chart point. - /// - public static ChartPoint Empty => new ChartPoint().AsEmpty(); - /// /// Gets the distance to a given point. /// @@ -187,7 +196,10 @@ public double DistanceTo(LvcPoint point) private void OnCoordinateChanged(Coordinate coordinate) { - Coordinate = coordinate; + // ToDo: + // how can this be improved??? + // does this have a significant performance impact? + _localCoordinate = coordinate; } } @@ -203,12 +215,9 @@ public class ChartPoint : ChartPoint /// Initializes a new instance of the class. /// /// The point. - public ChartPoint(ChartPoint point) : base(point.Context.Chart, point.Context.Series) + public ChartPoint(ChartPoint point) : base(point) { - IsNull = point.IsNull; - Coordinate = point.Coordinate; StackedValue = point.StackedValue; - Context.Index = point.Context.Index; Context.DataSource = point.Context.DataSource; Context.Visual = point.Context.Visual; Context.Label = point.Context.Label; diff --git a/src/LiveChartsCore/Kernel/ChartPointContext.cs b/src/LiveChartsCore/Kernel/ChartPointContext.cs index 9c21a56c4..2735c1b88 100644 --- a/src/LiveChartsCore/Kernel/ChartPointContext.cs +++ b/src/LiveChartsCore/Kernel/ChartPointContext.cs @@ -20,6 +20,8 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. +using System; +using LiveChartsCore.Defaults; using LiveChartsCore.Kernel.Drawing; using LiveChartsCore.Kernel.Sketches; @@ -35,10 +37,12 @@ public class ChartPointContext /// /// The chart. /// The series. - public ChartPointContext(IChartView chart, ISeries series) + /// The entity. + public ChartPointContext(IChartView chart, ISeries series, IChartEntity entity) { Chart = chart; Series = series; + Entity = entity; } internal ChartPointContext() @@ -47,6 +51,7 @@ internal ChartPointContext() // This is used only when the IChartEntity was null Chart = null!; Series = null!; + Entity = new MappedChartEntity(); } /// @@ -66,15 +71,21 @@ internal ChartPointContext() public ISeries Series { get; } /// - /// Gets the position of the point the collection that was used when the point was drawn. + /// Gets the . /// - public int Index { get; internal set; } + public IChartEntity Entity { get; } /// /// Gets the DataSource. /// public object? DataSource { get; internal set; } + /// + /// Gets the position of the point the collection that was used when the point was drawn. + /// + [Obsolete("Use Entity.EntityIndex")] + public int Index => Entity?.EntityIndex ?? 0; + /// /// Gets the visual. /// diff --git a/src/LiveChartsCore/Kernel/Coordinate.cs b/src/LiveChartsCore/Kernel/Coordinate.cs index 4f944bb15..7d476240e 100644 --- a/src/LiveChartsCore/Kernel/Coordinate.cs +++ b/src/LiveChartsCore/Kernel/Coordinate.cs @@ -27,10 +27,6 @@ namespace LiveChartsCore.Kernel; /// public readonly struct Coordinate { -#pragma warning disable IDE0032 // Use auto property - private readonly bool _isEmpty; -#pragma warning restore IDE0032 // Use auto property - /// /// Initializes a new instance of the struct. /// @@ -67,7 +63,7 @@ public Coordinate(double x, double y, double weight) : this(y, x, weight, 0, 0) private Coordinate(bool isEmpty) : this(0, 0, 0, 0, 0) { - _isEmpty = isEmpty; + IsEmpty = isEmpty; } /// @@ -78,9 +74,7 @@ private Coordinate(bool isEmpty) : this(0, 0, 0, 0, 0) /// /// Evaluates whether the instance is empty. /// -#pragma warning disable IDE0032 // Use auto property - public readonly bool IsEmpty => _isEmpty; -#pragma warning restore IDE0032 // Use auto property + public readonly bool IsEmpty { get; } /// /// Gets or sets the primary value, normally the Y coordinate or the value in a gauge. diff --git a/src/LiveChartsCore/Kernel/LiveChartsSettings.cs b/src/LiveChartsCore/Kernel/LiveChartsSettings.cs index e4ed2493b..d70e61bed 100644 --- a/src/LiveChartsCore/Kernel/LiveChartsSettings.cs +++ b/src/LiveChartsCore/Kernel/LiveChartsSettings.cs @@ -262,104 +262,68 @@ public LiveChartsSettings AddDefaultMappers() HasMap((model, point) => { point.PrimaryValue = model; - point.SecondaryValue = point.Context.Index; + point.SecondaryValue = point.Context.Entity.EntityIndex; }) .HasMap((model, point) => { point.PrimaryValue = model; - point.SecondaryValue = point.Context.Index; + point.SecondaryValue = point.Context.Entity.EntityIndex; }) .HasMap((model, point) => { point.PrimaryValue = model; - point.SecondaryValue = point.Context.Index; + point.SecondaryValue = point.Context.Entity.EntityIndex; }) .HasMap((model, point) => { point.PrimaryValue = model; - point.SecondaryValue = point.Context.Index; + point.SecondaryValue = point.Context.Entity.EntityIndex; }) .HasMap((model, point) => { point.PrimaryValue = model; - point.SecondaryValue = point.Context.Index; + point.SecondaryValue = point.Context.Entity.EntityIndex; }) .HasMap((model, point) => { point.PrimaryValue = (double)model; - point.SecondaryValue = point.Context.Index; + point.SecondaryValue = point.Context.Entity.EntityIndex; }) .HasMap((model, point) => { - if (model is not null) - { - point.PrimaryValue = model.Value; - point.SecondaryValue = point.Context.Index; - } - else - { - _ = point.AsEmpty(); - } + if (model is null) throw new Exception("Unexpected exception"); + point.PrimaryValue = model.Value; + point.SecondaryValue = point.Context.Entity.EntityIndex; }) .HasMap((model, point) => { - if (model is not null) - { - point.PrimaryValue = model.Value; - point.SecondaryValue = point.Context.Index; - } - else - { - _ = point.AsEmpty(); - } + if (model is null) throw new Exception("Unexpected exception"); + point.PrimaryValue = model.Value; + point.SecondaryValue = point.Context.Entity.EntityIndex; }) .HasMap((model, point) => { - if (model is not null) - { - point.PrimaryValue = model.Value; - point.SecondaryValue = point.Context.Index; - } - else - { - _ = point.AsEmpty(); - } + if (model is null) throw new Exception("Unexpected exception"); + point.PrimaryValue = model.Value; + point.SecondaryValue = point.Context.Entity.EntityIndex; }) .HasMap((model, point) => { - if (model is not null) - { - point.PrimaryValue = model.Value; - point.SecondaryValue = point.Context.Index; - } - else - { - _ = point.AsEmpty(); - } + if (model is null) throw new Exception("Unexpected exception"); + point.PrimaryValue = model.Value; + point.SecondaryValue = point.Context.Entity.EntityIndex; }) .HasMap((model, point) => { - if (model is not null) - { - point.PrimaryValue = model.Value; - point.SecondaryValue = point.Context.Index; - } - else - { - _ = point.AsEmpty(); - } + if (model is null) throw new Exception("Unexpected exception"); + point.PrimaryValue = model.Value; + point.SecondaryValue = point.Context.Entity.EntityIndex; }) .HasMap((model, point) => { - if (model is not null) - { - point.PrimaryValue = (double)model.Value; - point.SecondaryValue = point.Context.Index; - } - else - { - _ = point.AsEmpty(); - } + if (model is null) throw new Exception("Unexpected exception"); + point.PrimaryValue = (double)model.Value; + point.SecondaryValue = point.Context.Entity.EntityIndex; }); } } diff --git a/src/LiveChartsCore/Kernel/Providers/DataFactory.cs b/src/LiveChartsCore/Kernel/Providers/DataFactory.cs index 24c50c10d..26201ee17 100644 --- a/src/LiveChartsCore/Kernel/Providers/DataFactory.cs +++ b/src/LiveChartsCore/Kernel/Providers/DataFactory.cs @@ -40,8 +40,8 @@ public class DataFactory { private readonly bool _isTModelChartEntity = false; private readonly bool _isValueType = false; - private readonly Dictionary> _chartIndexEntityMap = new(); - private readonly Dictionary> _chartRefEntityMap = new(); + private readonly Dictionary> _chartIndexEntityMap = new(); + private readonly Dictionary> _chartRefEntityMap = new(); /// /// Gets or sets the previous known bounds. @@ -106,7 +106,7 @@ public virtual void DisposePoint(ChartPoint point) _ = _chartIndexEntityMap.TryGetValue(canvas.Sync, out var d); var map = d; if (map is null) return; - _ = map.Remove(point.Context.Index); + _ = map.Remove(point.Context.Entity.EntityIndex); } else { @@ -168,6 +168,8 @@ public virtual SeriesBounds GetCartesianBounds( foreach (var point in series.Fetch(chart)) { + if (point.IsEmpty) continue; + var primary = point.PrimaryValue; var secondary = point.SecondaryValue; var tertiary = point.TertiaryValue; @@ -227,6 +229,8 @@ public virtual SeriesBounds GetFinancialBounds( ChartPoint? previous = null; foreach (var point in series.Fetch(chart)) { + if (point.IsEmpty) continue; + var primaryMax = point.PrimaryValue; var primaryMin = point.QuinaryValue; var secondary = point.SecondaryValue; @@ -280,6 +284,8 @@ public virtual SeriesBounds GetPieBounds( foreach (var point in series.Fetch(chart)) { + if (point.IsEmpty) continue; + _ = stack.StackPoint(point); bounds.PrimaryBounds.AppendValue(point.PrimaryValue); bounds.SecondaryBounds.AppendValue(point.SecondaryValue); @@ -310,14 +316,12 @@ private IEnumerable EnumerateChartEntities(ISeries series, entity.ChartPoints ??= new Dictionary(); if (!entity.ChartPoints.TryGetValue(chart.View, out var point)) { - point = new ChartPoint(chart.View, series); + point = new ChartPoint(chart.View, series, entity); entity.ChartPoints[chart.View] = point; } point.Context.DataSource = entity; - point.Context.Index = index; entity.EntityIndex = index++; - point.Coordinate = entity.Coordinate; yield return entity; } @@ -334,16 +338,22 @@ private IEnumerable EnumerateChartEntities(ISeries series, _ = _chartIndexEntityMap.TryGetValue(canvas.Sync, out var d); if (d is null) { - d = new Dictionary(); + d = new Dictionary(); _chartIndexEntityMap[canvas.Sync] = d; } var IndexEntityMap = d; foreach (var item in series.Values) { + if (item is null) + { + yield return new MappedChartEntity(); + continue; + } + if (!IndexEntityMap.TryGetValue(index, out var entity)) { - IndexEntityMap[index] = entity = new ChartEntity + IndexEntityMap[index] = entity = new MappedChartEntity { ChartPoints = new Dictionary() }; @@ -351,15 +361,15 @@ private IEnumerable EnumerateChartEntities(ISeries series, if (!entity.ChartPoints!.TryGetValue(chart.View, out var point)) { - point = new ChartPoint(chart.View, series); + point = new ChartPoint(chart.View, series, entity); entity.ChartPoints[chart.View] = point; } point.Context.DataSource = item; - entity.EntityIndex = index; - point.Context.Index = index++; + entity.EntityIndex = index++; mapper(item, point); + entity.UpdateCoordinate(point); yield return entity; } @@ -376,7 +386,7 @@ private IEnumerable EnumerateChartEntities(ISeries series, _ = _chartRefEntityMap.TryGetValue(canvas.Sync, out var d); if (d is null) { - d = new Dictionary(); + d = new Dictionary(); _chartRefEntityMap[canvas.Sync] = d; } var IndexEntityMap = d; @@ -385,13 +395,13 @@ private IEnumerable EnumerateChartEntities(ISeries series, { if (item is null) { - yield return new ChartEntity(); + yield return new MappedChartEntity(); continue; } if (!IndexEntityMap.TryGetValue(item, out var entity)) { - IndexEntityMap[item] = entity = new ChartEntity + IndexEntityMap[item] = entity = new MappedChartEntity { ChartPoints = new Dictionary() }; @@ -399,15 +409,15 @@ private IEnumerable EnumerateChartEntities(ISeries series, if (!entity.ChartPoints!.TryGetValue(chart.View, out var point)) { - point = new ChartPoint(chart.View, series); + point = new ChartPoint(chart.View, series, entity); entity.ChartPoints[chart.View] = point; } point.Context.DataSource = item; - entity.EntityIndex = index; - point.Context.Index = index++; + entity.EntityIndex = index++; mapper(item, point); + entity.UpdateCoordinate(point); yield return entity; } diff --git a/src/LiveChartsCore/Measure/MeasureExtensions.cs b/src/LiveChartsCore/Measure/MeasureExtensions.cs index 0f38c6b2c..e5b5c116c 100644 --- a/src/LiveChartsCore/Measure/MeasureExtensions.cs +++ b/src/LiveChartsCore/Measure/MeasureExtensions.cs @@ -85,7 +85,7 @@ private static IEnumerable YieldReturnUntilNextNullChartPoint( { while (builder.Enumerator.MoveNext()) { - if (builder.Enumerator.Current.Coordinate.IsEmpty || builder.Enumerator.Current.IsNull) + if (builder.Enumerator.Current.IsEmpty) { var wasEmpty = builder.IsEmpty; builder.IsEmpty = true; diff --git a/src/LiveChartsCore/PieSeries.cs b/src/LiveChartsCore/PieSeries.cs index 53178a74c..fd95d62fd 100644 --- a/src/LiveChartsCore/PieSeries.cs +++ b/src/LiveChartsCore/PieSeries.cs @@ -232,7 +232,7 @@ public override void Measure(Chart chart) { var visual = point.Context.Visual as TVisual; - if (point.Coordinate.IsEmpty || point.IsNull) + if (point.IsEmpty) { if (visual is not null) { diff --git a/src/LiveChartsCore/PolarLineSeries.cs b/src/LiveChartsCore/PolarLineSeries.cs index 7ca8d7a8c..6e8c24f8f 100644 --- a/src/LiveChartsCore/PolarLineSeries.cs +++ b/src/LiveChartsCore/PolarLineSeries.cs @@ -857,7 +857,7 @@ private IEnumerable SplitEachNull( foreach (var point in points) { - if (point.Coordinate.IsEmpty || point.IsNull) + if (point.IsEmpty) { if (point.Context.Visual is TVisualPoint visual) { diff --git a/src/LiveChartsCore/RowSeries.cs b/src/LiveChartsCore/RowSeries.cs index 82e016803..cdda9b4f3 100644 --- a/src/LiveChartsCore/RowSeries.cs +++ b/src/LiveChartsCore/RowSeries.cs @@ -116,7 +116,7 @@ public override void Measure(Chart chart) var secondary = secondaryScale.ToPixels(point.SecondaryValue); var b = Math.Abs(primary - helper.p); - if (point.Coordinate.IsEmpty || point.IsNull) + if (point.IsEmpty) { if (visual is not null) { diff --git a/src/LiveChartsCore/ScatterSeries.cs b/src/LiveChartsCore/ScatterSeries.cs index e201b0800..5de00b001 100644 --- a/src/LiveChartsCore/ScatterSeries.cs +++ b/src/LiveChartsCore/ScatterSeries.cs @@ -129,7 +129,7 @@ public override void Measure(Chart chart) var x = xScale.ToPixels(point.SecondaryValue); var y = yScale.ToPixels(point.PrimaryValue); - if (point.Coordinate.IsEmpty || point.IsNull) + if (point.IsEmpty) { if (visual is not null) { From 314bac2fa4120302469cb3bb74da6f37b71d971e Mon Sep 17 00:00:00 2001 From: beto-rodriguez Date: Fri, 19 Aug 2022 15:05:20 -0500 Subject: [PATCH 14/25] fixes #515 --- src/LiveChartsCore/Kernel/Providers/DataFactory.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/LiveChartsCore/Kernel/Providers/DataFactory.cs b/src/LiveChartsCore/Kernel/Providers/DataFactory.cs index 26201ee17..ffc4c3181 100644 --- a/src/LiveChartsCore/Kernel/Providers/DataFactory.cs +++ b/src/LiveChartsCore/Kernel/Providers/DataFactory.cs @@ -311,7 +311,11 @@ private IEnumerable EnumerateChartEntities(ISeries series, foreach (var entity in entities) { - if (entity is null) continue; + if (entity is null) + { + index++; + continue; + } entity.ChartPoints ??= new Dictionary(); if (!entity.ChartPoints.TryGetValue(chart.View, out var point)) @@ -348,6 +352,7 @@ private IEnumerable EnumerateChartEntities(ISeries series, if (item is null) { yield return new MappedChartEntity(); + index++; continue; } @@ -396,6 +401,7 @@ private IEnumerable EnumerateChartEntities(ISeries series, if (item is null) { yield return new MappedChartEntity(); + index++; continue; } From f39dbcfcd28a21356461205fff4fab6afd653803 Mon Sep 17 00:00:00 2001 From: beto-rodriguez Date: Fri, 19 Aug 2022 15:23:22 -0500 Subject: [PATCH 15/25] fixes #525 --- .../Drawing/Geometries/DoughnutGeometry.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/skiasharp/LiveChartsCore.SkiaSharp/Drawing/Geometries/DoughnutGeometry.cs b/src/skiasharp/LiveChartsCore.SkiaSharp/Drawing/Geometries/DoughnutGeometry.cs index 9262611d7..b0ed7a61f 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharp/Drawing/Geometries/DoughnutGeometry.cs +++ b/src/skiasharp/LiveChartsCore.SkiaSharp/Drawing/Geometries/DoughnutGeometry.cs @@ -136,7 +136,7 @@ public override void OnDraw(SkiaSharpDrawingContext context, SKPaint paint) (float)(cx + Math.Cos((sweepAngle + startAngle) * toRadians) * wedge), (float)(cy + Math.Sin((sweepAngle + startAngle) * toRadians) * wedge)); path.ArcTo( - new SKPoint { X = wedge + pushout, Y = wedge + pushout }, + new SKPoint { X = wedge, Y = wedge }, 0, sweepAngle > 180 ? SKPathArcSize.Large : SKPathArcSize.Small, SKPathDirection.CounterClockwise, From 2a0f5f76e8a5dbbbf54b6a468c71e972cea92ba7 Mon Sep 17 00:00:00 2001 From: beto-rodriguez Date: Fri, 19 Aug 2022 18:27:22 -0500 Subject: [PATCH 16/25] fixes #552 --- .../LiveChartsCore.SkiaSharpView.Blazor/Chart.razor | 2 +- .../Chart.razor.css | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/skiasharp/LiveChartsCore.SkiaSharpView.Blazor/Chart.razor b/src/skiasharp/LiveChartsCore.SkiaSharpView.Blazor/Chart.razor index 885c03b80..936640f1c 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharpView.Blazor/Chart.razor +++ b/src/skiasharp/LiveChartsCore.SkiaSharpView.Blazor/Chart.razor @@ -29,7 +29,7 @@ blazor bug? --> -
+
diff --git a/src/skiasharp/LiveChartsCore.SkiaSharpView.Blazor/Chart.razor.css b/src/skiasharp/LiveChartsCore.SkiaSharpView.Blazor/Chart.razor.css index 88b24c328..8645b108a 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharpView.Blazor/Chart.razor.css +++ b/src/skiasharp/LiveChartsCore.SkiaSharpView.Blazor/Chart.razor.css @@ -1,8 +1,17 @@ -::deep canvas { +::deep.lvc-content { + height: 100%; + width: 100%; +} + +::deep canvas { + height: 100%; width: 100%; } ::deep .lvc-chart-container { + height: 100%; + width: 100%; + display: -ms-flexbox; display: -webkit-flex; display: flex; @@ -45,7 +54,9 @@ } ::deep .lvc-canvas-container { + height: 100%; width: 100%; + -webkit-order: 0; -ms-flex-order: 0; order: 0; From 259569a2fc54505b2eadeef2beddb74a185da64c Mon Sep 17 00:00:00 2001 From: beto-rodriguez Date: Fri, 19 Aug 2022 20:21:46 -0500 Subject: [PATCH 17/25] fizes #555 --- src/LiveChartsCore/Motion/MotionProperty.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/LiveChartsCore/Motion/MotionProperty.cs b/src/LiveChartsCore/Motion/MotionProperty.cs index 37c1e1606..d73d9095e 100644 --- a/src/LiveChartsCore/Motion/MotionProperty.cs +++ b/src/LiveChartsCore/Motion/MotionProperty.cs @@ -122,7 +122,7 @@ public T GetMovement(Animatable animatable) { if (Animation is null || Animation.EasingFunction is null || fromValue is null || IsCompleted) return OnGetMovement(1); - if (_requiresToInitialize) + if (_requiresToInitialize || _startTime == long.MinValue) { _startTime = animatable.CurrentTime; _endTime = animatable.CurrentTime + Animation._duration; From 44810ed9bb6690730e86ee24841cd1bc7ad8c54a Mon Sep 17 00:00:00 2001 From: beto-rodriguez Date: Fri, 19 Aug 2022 20:58:43 -0500 Subject: [PATCH 18/25] fixes #562 --- .../LiveChartsCore.SkiaSharp.WinForms/MotionCanvas.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/skiasharp/LiveChartsCore.SkiaSharp.WinForms/MotionCanvas.cs b/src/skiasharp/LiveChartsCore.SkiaSharp.WinForms/MotionCanvas.cs index 53ef15125..76aacb197 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharp.WinForms/MotionCanvas.cs +++ b/src/skiasharp/LiveChartsCore.SkiaSharp.WinForms/MotionCanvas.cs @@ -48,7 +48,6 @@ public partial class MotionCanvas : UserControl public MotionCanvas() { InitializeComponent(); - CanvasCore.Invalidated += CanvasCore_Invalidated; } /// @@ -91,6 +90,13 @@ protected override void OnParentChanged(EventArgs e) base.OnParentChanged(e); } + /// + protected override void CreateHandle() + { + base.CreateHandle(); + CanvasCore.Invalidated += CanvasCore_Invalidated; + } + /// protected override void OnHandleDestroyed(EventArgs e) { From bc62f0a21e0d6dc8ab1f058119ea3c1b37d94125 Mon Sep 17 00:00:00 2001 From: beto-rodriguez Date: Fri, 19 Aug 2022 23:20:52 -0500 Subject: [PATCH 19/25] fixes #570 --- src/LiveChartsCore/CartesianChart.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/LiveChartsCore/CartesianChart.cs b/src/LiveChartsCore/CartesianChart.cs index 84be4cbb3..66bb943d6 100644 --- a/src/LiveChartsCore/CartesianChart.cs +++ b/src/LiveChartsCore/CartesianChart.cs @@ -696,9 +696,9 @@ protected internal override void Measure() } var drawablePlane = (IPlane)axis; - _ = _everMeasuredAxes.Add(drawablePlane); if (drawablePlane.IsVisible) { + _everMeasuredAxes.Add(drawablePlane); drawablePlane.Measure(this); _ = toDeleteAxes.Remove(drawablePlane); } From 1909c4161850d70f95a583ab6379115e6a57033e Mon Sep 17 00:00:00 2001 From: beto-rodriguez Date: Sat, 20 Aug 2022 00:18:54 -0500 Subject: [PATCH 20/25] fixes #578 --- src/LiveChartsCore/Measure/MeasureExtensions.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/LiveChartsCore/Measure/MeasureExtensions.cs b/src/LiveChartsCore/Measure/MeasureExtensions.cs index e5b5c116c..ae9f52e8f 100644 --- a/src/LiveChartsCore/Measure/MeasureExtensions.cs +++ b/src/LiveChartsCore/Measure/MeasureExtensions.cs @@ -22,6 +22,7 @@ using System; using System.Collections.Generic; +using System.Linq; using LiveChartsCore.Kernel; namespace LiveChartsCore.Measure; @@ -52,7 +53,7 @@ public static IEnumerable> SplitByNullGaps( /// internal static IEnumerable AsSplineData(this IEnumerable source) { - using var e = source.GetEnumerator(); + using var e = source.Where(x => !x.IsEmpty).GetEnumerator(); if (!e.MoveNext()) yield break; var data = new SplineData(e.Current); From d2b2c9b3aa250f685516acb1935a882fdefd0533 Mon Sep 17 00:00:00 2001 From: beto-rodriguez Date: Sat, 20 Aug 2022 13:43:37 -0500 Subject: [PATCH 21/25] fixes #575 --- .../LiveChartsCore.SkiaSharpView.Blazor/Chart.razor | 2 +- .../LiveChartsCore.SkiaSharpView.Blazor/Chart.razor.cs | 2 +- .../MotionCanvas.razor | 4 ++-- .../MotionCanvas.razor.cs | 8 ++++---- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/skiasharp/LiveChartsCore.SkiaSharpView.Blazor/Chart.razor b/src/skiasharp/LiveChartsCore.SkiaSharpView.Blazor/Chart.razor index 936640f1c..766b40562 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharpView.Blazor/Chart.razor +++ b/src/skiasharp/LiveChartsCore.SkiaSharpView.Blazor/Chart.razor @@ -40,7 +40,7 @@ OnPointerDownCallback="OnPointerDown" OnPointerMoveCallback="OnPointerMove" OnPointerUpCallback="OnPointerUp" - OnPointerLeaveCallback="OnPointerLeave" + OnPointerOutCallback="OnPointerOut" OnWheelCallback="OnWheel">
diff --git a/src/skiasharp/LiveChartsCore.SkiaSharpView.Blazor/Chart.razor.cs b/src/skiasharp/LiveChartsCore.SkiaSharpView.Blazor/Chart.razor.cs index f1c66d874..1a949ef14 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharpView.Blazor/Chart.razor.cs +++ b/src/skiasharp/LiveChartsCore.SkiaSharpView.Blazor/Chart.razor.cs @@ -345,7 +345,7 @@ protected virtual void OnDisposing() { } /// Called when the pointer leaves the control. ///
/// - protected virtual void OnPointerLeave(PointerEventArgs e) + protected virtual void OnPointerOut(PointerEventArgs e) { HideTooltip(); core?.InvokePointerLeft(); diff --git a/src/skiasharp/LiveChartsCore.SkiaSharpView.Blazor/MotionCanvas.razor b/src/skiasharp/LiveChartsCore.SkiaSharpView.Blazor/MotionCanvas.razor index bdaed0f2a..f424fa192 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharpView.Blazor/MotionCanvas.razor +++ b/src/skiasharp/LiveChartsCore.SkiaSharpView.Blazor/MotionCanvas.razor @@ -40,7 +40,7 @@ @onpointerdown="OnPointerDown" @onpointermove="OnPointerMove" @onpointerup="OnPointerUp" - @onpointerleave="OnPointerLeave" + @onpointerout="OnPointerOut" @onmousewheel="OnWheel"> } @@ -52,7 +52,7 @@ else @onpointerdown="OnPointerDown" @onpointermove="OnPointerMove" @onpointerup="OnPointerUp" - @onpointerleave="OnPointerLeave" + @onpointerout="OnPointerOut" @onmousewheel="OnWheel" > } diff --git a/src/skiasharp/LiveChartsCore.SkiaSharpView.Blazor/MotionCanvas.razor.cs b/src/skiasharp/LiveChartsCore.SkiaSharpView.Blazor/MotionCanvas.razor.cs index ecf0a2f6a..d8b5e7e24 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharpView.Blazor/MotionCanvas.razor.cs +++ b/src/skiasharp/LiveChartsCore.SkiaSharpView.Blazor/MotionCanvas.razor.cs @@ -106,7 +106,7 @@ public List> PaintTasks /// Gets or sets the pointer leave callback. ///
[Parameter] - public EventCallback OnPointerLeaveCallback { get; set; } + public EventCallback OnPointerOutCallback { get; set; } /// /// Called when the pointer goes down. @@ -145,12 +145,12 @@ protected virtual void OnWheel(WheelEventArgs e) } /// - /// Called when the pointer leves the control. + /// Called when the pointer leaves the control. /// /// - protected virtual void OnPointerLeave(PointerEventArgs e) + protected virtual void OnPointerOut(PointerEventArgs e) { - _ = OnPointerLeaveCallback.InvokeAsync(e); + _ = OnPointerOutCallback.InvokeAsync(e); } private void OnPaintGlSurface(SKPaintGLSurfaceEventArgs e) From 668c73a2a76b6d5dcc7ac5e4991e777fa9c0d3e5 Mon Sep 17 00:00:00 2001 From: beto-rodriguez Date: Sat, 20 Aug 2022 15:54:22 -0500 Subject: [PATCH 22/25] prevents throw for #579 --- src/LiveChartsCore/Kernel/Extensions.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/LiveChartsCore/Kernel/Extensions.cs b/src/LiveChartsCore/Kernel/Extensions.cs index 2982dea7d..aedc535b7 100644 --- a/src/LiveChartsCore/Kernel/Extensions.cs +++ b/src/LiveChartsCore/Kernel/Extensions.cs @@ -141,15 +141,19 @@ public static AxisTick GetTick(this ICartesianAxis axis, LvcSize controlSize, Bo var min = axis.MinLimit is null ? bounds.Min : axis.MinLimit.Value; var range = max - min; + if (range == 0) range = min; + var separations = axis.Orientation == AxisOrientation.Y ? Math.Round(controlSize.Height / (12 * Cf), 0) : Math.Round(controlSize.Width / (20 * Cf), 0); + var minimum = range / separations; var magnitude = Math.Pow(10, Math.Floor(Math.Log(minimum) / Math.Log(10))); var residual = minimum / magnitude; var tick = residual > 5 ? 10 * magnitude : residual > 2 ? 5 * magnitude : residual > 1 ? 2 * magnitude : magnitude; + return new AxisTick { Value = tick, Magnitude = magnitude }; } From 2768e9d613521d0186492b100567a87fe494dadf Mon Sep 17 00:00:00 2001 From: beto-rodriguez Date: Sat, 20 Aug 2022 17:08:27 -0500 Subject: [PATCH 23/25] imprive docs, helps #583 --- src/LiveChartsCore/Measure/Scaler.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/LiveChartsCore/Measure/Scaler.cs b/src/LiveChartsCore/Measure/Scaler.cs index 79c2e413c..e65f64319 100644 --- a/src/LiveChartsCore/Measure/Scaler.cs +++ b/src/LiveChartsCore/Measure/Scaler.cs @@ -180,7 +180,7 @@ internal Scaler() public double MinVal { get; private set; } /// - /// Converts to pixels. + /// Measures an absolute value in pixels. /// /// The value. /// @@ -195,9 +195,9 @@ public float MeasureInPixels(double value) } /// - /// Converts to pixels. + /// Converts a given value (in chart values) to pixels. /// - /// The value. + /// The value in chart values. /// public float ToPixels(double value) { @@ -205,9 +205,9 @@ public float ToPixels(double value) } /// - /// Converts to chart values. + /// Converts a given value (in pixels) to chart values. /// - /// The pixels. + /// The value in pixels. /// public double ToChartValues(double pixels) { From 043f2f359065f6fbb4582716296ccd1840890c97 Mon Sep 17 00:00:00 2001 From: beto-rodriguez Date: Sat, 20 Aug 2022 18:03:47 -0500 Subject: [PATCH 24/25] restore restart visuals --- .../Kernel/Providers/DataFactory.cs | 66 +++++++++++++++++-- src/LiveChartsCore/Series.cs | 4 +- 2 files changed, 61 insertions(+), 9 deletions(-) diff --git a/src/LiveChartsCore/Kernel/Providers/DataFactory.cs b/src/LiveChartsCore/Kernel/Providers/DataFactory.cs index ffc4c3181..92d62947d 100644 --- a/src/LiveChartsCore/Kernel/Providers/DataFactory.cs +++ b/src/LiveChartsCore/Kernel/Providers/DataFactory.cs @@ -22,6 +22,7 @@ using System; using System.Collections.Generic; +using System.Linq; using LiveChartsCore.Defaults; using LiveChartsCore.Drawing; using LiveChartsCore.Kernel.Sketches; @@ -42,6 +43,7 @@ public class DataFactory private readonly bool _isValueType = false; private readonly Dictionary> _chartIndexEntityMap = new(); private readonly Dictionary> _chartRefEntityMap = new(); + private ISeries? _series; /// /// Gets or sets the previous known bounds. @@ -71,14 +73,9 @@ public DataFactory() public virtual IEnumerable Fetch(ISeries series, IChart chart) { if (series.Values is null) yield break; + _series = series; - var dataSource = _isTModelChartEntity - ? EnumerateChartEntities(series, chart) - : (_isValueType - ? EnumerateByValEntities(series, chart) - : EnumerateByRefEntities(series, chart)); - - foreach (var value in dataSource) + foreach (var value in GetEntities(series, chart)) { if (value is null) { @@ -125,6 +122,7 @@ public virtual void DisposePoint(ChartPoint point) /// public virtual void Dispose(IChart chart) { + _series = null; if (_isTModelChartEntity) return; if (_isValueType) @@ -303,6 +301,60 @@ public virtual SeriesBounds GetPieBounds( return new SeriesBounds(bounds, false); } + + /// + /// Clears the visuals in the cache. + /// + public void RestartVisuals() + { + if (_series is not null && _series.Values is IEnumerable entities) + { + foreach (var entity in entities) + { + foreach (var chartPoint in entity.ChartPoints?.Values ?? Enumerable.Empty()) + { + if (chartPoint.Context.Visual is not IAnimatable visual) continue; + visual.RemoveTransition(null); + } + } + } + + foreach (var item in _chartIndexEntityMap.Values) + { + foreach (var index in item.Values) + { + foreach (var chartPoint in index.ChartPoints?.Values ?? Enumerable.Empty()) + { + if (chartPoint.Context.Visual is not IAnimatable visual) continue; + visual.RemoveTransition(null); + } + } + } + _chartIndexEntityMap.Clear(); + + foreach (var item in _chartRefEntityMap.Values) + { + foreach (var index in item.Values) + { + foreach (var chartPoint in index.ChartPoints?.Values ?? Enumerable.Empty()) + { + if (chartPoint.Context.Visual is not IAnimatable visual) continue; + visual.RemoveTransition(null); + } + } + } + _chartRefEntityMap.Clear(); + } + + private IEnumerable GetEntities(ISeries series, IChart chart) + { + return _isTModelChartEntity + ? EnumerateChartEntities(series, chart) + : (_isValueType + ? EnumerateByValEntities(series, chart) + : EnumerateByRefEntities(series, chart)); + } + private IEnumerable EnumerateChartEntities(ISeries series, IChart chart) { if (series.Values is null) yield break; diff --git a/src/LiveChartsCore/Series.cs b/src/LiveChartsCore/Series.cs index 592780f29..3e19b1377 100644 --- a/src/LiveChartsCore/Series.cs +++ b/src/LiveChartsCore/Series.cs @@ -342,8 +342,8 @@ void ISeries.OnPointerLeft(ChartPoint point) /// public void RestartAnimations() { - //if (DataFactory is null) throw new Exception("Data provider not found"); - //DataFactory.Fetch( + if (DataFactory is null) throw new Exception("Data provider not found"); + DataFactory.RestartVisuals(); } /// From 152169598b1e752b25dcc25f1db4eb2c1958b72c Mon Sep 17 00:00:00 2001 From: beto-rodriguez Date: Sat, 20 Aug 2022 18:35:02 -0500 Subject: [PATCH 25/25] 2.0.0-beta.360 --- src/LiveChartsCore/AssemblyInfo.cs | 34 +++++++++---------- src/LiveChartsCore/LiveChartsCore.csproj | 2 +- ...veChartsCore.SkiaSharpView.Avalonia.csproj | 2 +- .../AssemblyInfo.cs | 10 +++--- .../LiveChartsCore.SkiaSharpView.WPF.csproj | 4 +-- ...veChartsCore.SkiaSharpView.WinForms.csproj | 2 +- ...rtsCore.SkiaSharpView.Xamarin.Forms.csproj | 2 +- .../LiveChartsCore.SkiaSharp/AssemblyInfo.cs | 12 +++---- .../LiveChartsCore.SkiaSharpView.csproj | 2 +- ...LiveChartsCore.SkiaSharpView.Blazor.csproj | 2 +- .../LiveChartsCore.SkiaSharpView.Eto.csproj | 2 +- .../LiveChartsCore.SkiaSharpView.Maui.csproj | 2 +- .../LiveChartsCore.SkiaSharpView.Maui.nuspec | 12 +++---- ...eChartsCore.SkiaSharpView.Uno.WinUI.csproj | 4 +-- .../LiveChartsCore.SkiaSharpView.Uno.csproj | 4 +-- .../LiveChartsCore.SkiaSharpView.WinUI.csproj | 2 +- .../LiveChartsCore.SkiaSharpView.WinUI.nuspec | 6 ++-- 17 files changed, 52 insertions(+), 52 deletions(-) diff --git a/src/LiveChartsCore/AssemblyInfo.cs b/src/LiveChartsCore/AssemblyInfo.cs index 65df3e29d..d2b5a0840 100644 --- a/src/LiveChartsCore/AssemblyInfo.cs +++ b/src/LiveChartsCore/AssemblyInfo.cs @@ -21,23 +21,23 @@ // SOFTWARE. using System.Runtime.CompilerServices; -//#if !DEBUG -//using System.Reflection; +#if !DEBUG +using System.Reflection; -//[assembly: AssemblyKeyFile("./../../LiveCharts.snk")] -//[assembly: InternalsVisibleTo("LiveChartsCore.SkiaSharpView, PublicKey=0024000004800000940000000602000000240000525341310004000001000100d53791eaa0d98b405ca858f39169be6af36ceb7a1bca3ca76c6905fd22fddf8c5e4ef2778a5d7a77ad12f08da711fecfc44795c7923739a2acac946b3f1719a6dfc238695bc69cf5d959b3fb6bc4d18d57a97ff8ed897e6b22a6b8155401ee368d77431e74178104b4adca73520b058b9be28d4ec129beb54871778167afa5ce")] -//[assembly: InternalsVisibleTo("LiveChartsCore.SkiaSharpView.Avalonia, PublicKey=0024000004800000940000000602000000240000525341310004000001000100d53791eaa0d98b405ca858f39169be6af36ceb7a1bca3ca76c6905fd22fddf8c5e4ef2778a5d7a77ad12f08da711fecfc44795c7923739a2acac946b3f1719a6dfc238695bc69cf5d959b3fb6bc4d18d57a97ff8ed897e6b22a6b8155401ee368d77431e74178104b4adca73520b058b9be28d4ec129beb54871778167afa5ce")] -//[assembly: InternalsVisibleTo("LiveChartsCore.SkiaSharpView.WinForms, PublicKey=0024000004800000940000000602000000240000525341310004000001000100d53791eaa0d98b405ca858f39169be6af36ceb7a1bca3ca76c6905fd22fddf8c5e4ef2778a5d7a77ad12f08da711fecfc44795c7923739a2acac946b3f1719a6dfc238695bc69cf5d959b3fb6bc4d18d57a97ff8ed897e6b22a6b8155401ee368d77431e74178104b4adca73520b058b9be28d4ec129beb54871778167afa5ce")] -//[assembly: InternalsVisibleTo("LiveChartsCore.SkiaSharpView.WinUI, PublicKey=0024000004800000940000000602000000240000525341310004000001000100d53791eaa0d98b405ca858f39169be6af36ceb7a1bca3ca76c6905fd22fddf8c5e4ef2778a5d7a77ad12f08da711fecfc44795c7923739a2acac946b3f1719a6dfc238695bc69cf5d959b3fb6bc4d18d57a97ff8ed897e6b22a6b8155401ee368d77431e74178104b4adca73520b058b9be28d4ec129beb54871778167afa5ce")] -//[assembly: InternalsVisibleTo("LiveChartsCore.SkiaSharpView.Uno, PublicKey=0024000004800000940000000602000000240000525341310004000001000100d53791eaa0d98b405ca858f39169be6af36ceb7a1bca3ca76c6905fd22fddf8c5e4ef2778a5d7a77ad12f08da711fecfc44795c7923739a2acac946b3f1719a6dfc238695bc69cf5d959b3fb6bc4d18d57a97ff8ed897e6b22a6b8155401ee368d77431e74178104b4adca73520b058b9be28d4ec129beb54871778167afa5ce")] -//[assembly: InternalsVisibleTo("LiveChartsCore.SkiaSharpView.Uno.WinUI, PublicKey=0024000004800000940000000602000000240000525341310004000001000100d53791eaa0d98b405ca858f39169be6af36ceb7a1bca3ca76c6905fd22fddf8c5e4ef2778a5d7a77ad12f08da711fecfc44795c7923739a2acac946b3f1719a6dfc238695bc69cf5d959b3fb6bc4d18d57a97ff8ed897e6b22a6b8155401ee368d77431e74178104b4adca73520b058b9be28d4ec129beb54871778167afa5ce")] -//[assembly: InternalsVisibleTo("LiveChartsCore.SkiaSharpView.WPF, PublicKey=0024000004800000940000000602000000240000525341310004000001000100d53791eaa0d98b405ca858f39169be6af36ceb7a1bca3ca76c6905fd22fddf8c5e4ef2778a5d7a77ad12f08da711fecfc44795c7923739a2acac946b3f1719a6dfc238695bc69cf5d959b3fb6bc4d18d57a97ff8ed897e6b22a6b8155401ee368d77431e74178104b4adca73520b058b9be28d4ec129beb54871778167afa5ce")] -//[assembly: InternalsVisibleTo("LiveChartsCore.SkiaSharpView.XamarinForms, PublicKey=0024000004800000940000000602000000240000525341310004000001000100d53791eaa0d98b405ca858f39169be6af36ceb7a1bca3ca76c6905fd22fddf8c5e4ef2778a5d7a77ad12f08da711fecfc44795c7923739a2acac946b3f1719a6dfc238695bc69cf5d959b3fb6bc4d18d57a97ff8ed897e6b22a6b8155401ee368d77431e74178104b4adca73520b058b9be28d4ec129beb54871778167afa5ce")] -//[assembly: InternalsVisibleTo("LiveChartsCore.SkiaSharpView.Eto, PublicKey=0024000004800000940000000602000000240000525341310004000001000100d53791eaa0d98b405ca858f39169be6af36ceb7a1bca3ca76c6905fd22fddf8c5e4ef2778a5d7a77ad12f08da711fecfc44795c7923739a2acac946b3f1719a6dfc238695bc69cf5d959b3fb6bc4d18d57a97ff8ed897e6b22a6b8155401ee368d77431e74178104b4adca73520b058b9be28d4ec129beb54871778167afa5ce")] -//[assembly: InternalsVisibleTo("LiveChartsCore.SkiaSharpView.Blazor, PublicKey=0024000004800000940000000602000000240000525341310004000001000100d53791eaa0d98b405ca858f39169be6af36ceb7a1bca3ca76c6905fd22fddf8c5e4ef2778a5d7a77ad12f08da711fecfc44795c7923739a2acac946b3f1719a6dfc238695bc69cf5d959b3fb6bc4d18d57a97ff8ed897e6b22a6b8155401ee368d77431e74178104b4adca73520b058b9be28d4ec129beb54871778167afa5ce")] -//[assembly: InternalsVisibleTo("LiveChartsCore.SkiaSharpView.Maui, PublicKey=0024000004800000940000000602000000240000525341310004000001000100d53791eaa0d98b405ca858f39169be6af36ceb7a1bca3ca76c6905fd22fddf8c5e4ef2778a5d7a77ad12f08da711fecfc44795c7923739a2acac946b3f1719a6dfc238695bc69cf5d959b3fb6bc4d18d57a97ff8ed897e6b22a6b8155401ee368d77431e74178104b4adca73520b058b9be28d4ec129beb54871778167afa5ce")] -//[assembly: InternalsVisibleTo("LiveChartsCore.BackersPackage, PublicKey=0024000004800000940000000602000000240000525341310004000001000100d53791eaa0d98b405ca858f39169be6af36ceb7a1bca3ca76c6905fd22fddf8c5e4ef2778a5d7a77ad12f08da711fecfc44795c7923739a2acac946b3f1719a6dfc238695bc69cf5d959b3fb6bc4d18d57a97ff8ed897e6b22a6b8155401ee368d77431e74178104b4adca73520b058b9be28d4ec129beb54871778167afa5ce")] -//#else +[assembly: AssemblyKeyFile("./../../LiveCharts.snk")] +[assembly: InternalsVisibleTo("LiveChartsCore.SkiaSharpView, PublicKey=0024000004800000940000000602000000240000525341310004000001000100d53791eaa0d98b405ca858f39169be6af36ceb7a1bca3ca76c6905fd22fddf8c5e4ef2778a5d7a77ad12f08da711fecfc44795c7923739a2acac946b3f1719a6dfc238695bc69cf5d959b3fb6bc4d18d57a97ff8ed897e6b22a6b8155401ee368d77431e74178104b4adca73520b058b9be28d4ec129beb54871778167afa5ce")] +[assembly: InternalsVisibleTo("LiveChartsCore.SkiaSharpView.Avalonia, PublicKey=0024000004800000940000000602000000240000525341310004000001000100d53791eaa0d98b405ca858f39169be6af36ceb7a1bca3ca76c6905fd22fddf8c5e4ef2778a5d7a77ad12f08da711fecfc44795c7923739a2acac946b3f1719a6dfc238695bc69cf5d959b3fb6bc4d18d57a97ff8ed897e6b22a6b8155401ee368d77431e74178104b4adca73520b058b9be28d4ec129beb54871778167afa5ce")] +[assembly: InternalsVisibleTo("LiveChartsCore.SkiaSharpView.WinForms, PublicKey=0024000004800000940000000602000000240000525341310004000001000100d53791eaa0d98b405ca858f39169be6af36ceb7a1bca3ca76c6905fd22fddf8c5e4ef2778a5d7a77ad12f08da711fecfc44795c7923739a2acac946b3f1719a6dfc238695bc69cf5d959b3fb6bc4d18d57a97ff8ed897e6b22a6b8155401ee368d77431e74178104b4adca73520b058b9be28d4ec129beb54871778167afa5ce")] +[assembly: InternalsVisibleTo("LiveChartsCore.SkiaSharpView.WinUI, PublicKey=0024000004800000940000000602000000240000525341310004000001000100d53791eaa0d98b405ca858f39169be6af36ceb7a1bca3ca76c6905fd22fddf8c5e4ef2778a5d7a77ad12f08da711fecfc44795c7923739a2acac946b3f1719a6dfc238695bc69cf5d959b3fb6bc4d18d57a97ff8ed897e6b22a6b8155401ee368d77431e74178104b4adca73520b058b9be28d4ec129beb54871778167afa5ce")] +[assembly: InternalsVisibleTo("LiveChartsCore.SkiaSharpView.Uno, PublicKey=0024000004800000940000000602000000240000525341310004000001000100d53791eaa0d98b405ca858f39169be6af36ceb7a1bca3ca76c6905fd22fddf8c5e4ef2778a5d7a77ad12f08da711fecfc44795c7923739a2acac946b3f1719a6dfc238695bc69cf5d959b3fb6bc4d18d57a97ff8ed897e6b22a6b8155401ee368d77431e74178104b4adca73520b058b9be28d4ec129beb54871778167afa5ce")] +[assembly: InternalsVisibleTo("LiveChartsCore.SkiaSharpView.Uno.WinUI, PublicKey=0024000004800000940000000602000000240000525341310004000001000100d53791eaa0d98b405ca858f39169be6af36ceb7a1bca3ca76c6905fd22fddf8c5e4ef2778a5d7a77ad12f08da711fecfc44795c7923739a2acac946b3f1719a6dfc238695bc69cf5d959b3fb6bc4d18d57a97ff8ed897e6b22a6b8155401ee368d77431e74178104b4adca73520b058b9be28d4ec129beb54871778167afa5ce")] +[assembly: InternalsVisibleTo("LiveChartsCore.SkiaSharpView.WPF, PublicKey=0024000004800000940000000602000000240000525341310004000001000100d53791eaa0d98b405ca858f39169be6af36ceb7a1bca3ca76c6905fd22fddf8c5e4ef2778a5d7a77ad12f08da711fecfc44795c7923739a2acac946b3f1719a6dfc238695bc69cf5d959b3fb6bc4d18d57a97ff8ed897e6b22a6b8155401ee368d77431e74178104b4adca73520b058b9be28d4ec129beb54871778167afa5ce")] +[assembly: InternalsVisibleTo("LiveChartsCore.SkiaSharpView.XamarinForms, PublicKey=0024000004800000940000000602000000240000525341310004000001000100d53791eaa0d98b405ca858f39169be6af36ceb7a1bca3ca76c6905fd22fddf8c5e4ef2778a5d7a77ad12f08da711fecfc44795c7923739a2acac946b3f1719a6dfc238695bc69cf5d959b3fb6bc4d18d57a97ff8ed897e6b22a6b8155401ee368d77431e74178104b4adca73520b058b9be28d4ec129beb54871778167afa5ce")] +[assembly: InternalsVisibleTo("LiveChartsCore.SkiaSharpView.Eto, PublicKey=0024000004800000940000000602000000240000525341310004000001000100d53791eaa0d98b405ca858f39169be6af36ceb7a1bca3ca76c6905fd22fddf8c5e4ef2778a5d7a77ad12f08da711fecfc44795c7923739a2acac946b3f1719a6dfc238695bc69cf5d959b3fb6bc4d18d57a97ff8ed897e6b22a6b8155401ee368d77431e74178104b4adca73520b058b9be28d4ec129beb54871778167afa5ce")] +[assembly: InternalsVisibleTo("LiveChartsCore.SkiaSharpView.Blazor, PublicKey=0024000004800000940000000602000000240000525341310004000001000100d53791eaa0d98b405ca858f39169be6af36ceb7a1bca3ca76c6905fd22fddf8c5e4ef2778a5d7a77ad12f08da711fecfc44795c7923739a2acac946b3f1719a6dfc238695bc69cf5d959b3fb6bc4d18d57a97ff8ed897e6b22a6b8155401ee368d77431e74178104b4adca73520b058b9be28d4ec129beb54871778167afa5ce")] +[assembly: InternalsVisibleTo("LiveChartsCore.SkiaSharpView.Maui, PublicKey=0024000004800000940000000602000000240000525341310004000001000100d53791eaa0d98b405ca858f39169be6af36ceb7a1bca3ca76c6905fd22fddf8c5e4ef2778a5d7a77ad12f08da711fecfc44795c7923739a2acac946b3f1719a6dfc238695bc69cf5d959b3fb6bc4d18d57a97ff8ed897e6b22a6b8155401ee368d77431e74178104b4adca73520b058b9be28d4ec129beb54871778167afa5ce")] +[assembly: InternalsVisibleTo("LiveChartsCore.BackersPackage, PublicKey=0024000004800000940000000602000000240000525341310004000001000100d53791eaa0d98b405ca858f39169be6af36ceb7a1bca3ca76c6905fd22fddf8c5e4ef2778a5d7a77ad12f08da711fecfc44795c7923739a2acac946b3f1719a6dfc238695bc69cf5d959b3fb6bc4d18d57a97ff8ed897e6b22a6b8155401ee368d77431e74178104b4adca73520b058b9be28d4ec129beb54871778167afa5ce")] +#else [assembly: InternalsVisibleTo("LiveChartsCore.SkiaSharpView")] [assembly: InternalsVisibleTo("LiveChartsCore.SkiaSharpView.Avalonia")] [assembly: InternalsVisibleTo("LiveChartsCore.SkiaSharpView.WinForms")] @@ -50,4 +50,4 @@ [assembly: InternalsVisibleTo("LiveChartsCore.SkiaSharpView.Blazor")] [assembly: InternalsVisibleTo("LiveChartsCore.SkiaSharpView.Maui")] [assembly: InternalsVisibleTo("LiveChartsCore.BackersPackage")] -//#endif +#endif diff --git a/src/LiveChartsCore/LiveChartsCore.csproj b/src/LiveChartsCore/LiveChartsCore.csproj index d8f3a73ba..e1a67044f 100644 --- a/src/LiveChartsCore/LiveChartsCore.csproj +++ b/src/LiveChartsCore/LiveChartsCore.csproj @@ -17,7 +17,7 @@ LiveChartsCore LiveChartsCore - 2.0.0-beta.351 + 2.0.0-beta.360 icon.png Simple, flexible, interactive and powerful data visualization for .Net, this is the core package probably you need another package also unless you are building your own backed. MIT diff --git a/src/skiasharp/LiveChartsCore.SkiaSharp.Avalonia/LiveChartsCore.SkiaSharpView.Avalonia.csproj b/src/skiasharp/LiveChartsCore.SkiaSharp.Avalonia/LiveChartsCore.SkiaSharpView.Avalonia.csproj index 6a1de95f9..0231e4262 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharp.Avalonia/LiveChartsCore.SkiaSharpView.Avalonia.csproj +++ b/src/skiasharp/LiveChartsCore.SkiaSharp.Avalonia/LiveChartsCore.SkiaSharpView.Avalonia.csproj @@ -6,7 +6,7 @@ netcoreapp2.0;netstandard2.0;net462; LiveChartsCore.SkiaSharpView.Avalonia LiveChartsCore.SkiaSharpView.Avalonia - 2.0.0-beta.350 + 2.0.0-beta.360 icon.png Simple, flexible, interactive and powerful data visualization for AvaloniaUI. MIT diff --git a/src/skiasharp/LiveChartsCore.SkiaSharp.WPF/AssemblyInfo.cs b/src/skiasharp/LiveChartsCore.SkiaSharp.WPF/AssemblyInfo.cs index 262458c50..ef2b24be4 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharp.WPF/AssemblyInfo.cs +++ b/src/skiasharp/LiveChartsCore.SkiaSharp.WPF/AssemblyInfo.cs @@ -33,9 +33,9 @@ // app, or any theme specific resource dictionaries) )] -//#if !DEBUG -//[assembly: AssemblyKeyFile("./../../../LiveCharts.snk")] -//[assembly: InternalsVisibleTo("LiveChartsCore.BackersPackage, PublicKey=0024000004800000940000000602000000240000525341310004000001000100d53791eaa0d98b405ca858f39169be6af36ceb7a1bca3ca76c6905fd22fddf8c5e4ef2778a5d7a77ad12f08da711fecfc44795c7923739a2acac946b3f1719a6dfc238695bc69cf5d959b3fb6bc4d18d57a97ff8ed897e6b22a6b8155401ee368d77431e74178104b4adca73520b058b9be28d4ec129beb54871778167afa5ce")] -//#else +#if !DEBUG +[assembly: AssemblyKeyFile("./../../../LiveCharts.snk")] +[assembly: InternalsVisibleTo("LiveChartsCore.BackersPackage, PublicKey=0024000004800000940000000602000000240000525341310004000001000100d53791eaa0d98b405ca858f39169be6af36ceb7a1bca3ca76c6905fd22fddf8c5e4ef2778a5d7a77ad12f08da711fecfc44795c7923739a2acac946b3f1719a6dfc238695bc69cf5d959b3fb6bc4d18d57a97ff8ed897e6b22a6b8155401ee368d77431e74178104b4adca73520b058b9be28d4ec129beb54871778167afa5ce")] +#else [assembly: InternalsVisibleTo("LiveChartsCore.BackersPackage")] -//#endif +#endif diff --git a/src/skiasharp/LiveChartsCore.SkiaSharp.WPF/LiveChartsCore.SkiaSharpView.WPF.csproj b/src/skiasharp/LiveChartsCore.SkiaSharp.WPF/LiveChartsCore.SkiaSharpView.WPF.csproj index a54060cb8..73ff10f2c 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharp.WPF/LiveChartsCore.SkiaSharpView.WPF.csproj +++ b/src/skiasharp/LiveChartsCore.SkiaSharp.WPF/LiveChartsCore.SkiaSharpView.WPF.csproj @@ -1,4 +1,4 @@ - + enable @@ -7,7 +7,7 @@ net462;netcoreapp3.1 LiveChartsCore.SkiaSharpView.WPF LiveChartsCore.SkiaSharpView.WPF - 2.0.0-beta.350 + 2.0.0-beta.360 icon.png Simple, flexible, interactive and powerful data visualization for WPF. MIT diff --git a/src/skiasharp/LiveChartsCore.SkiaSharp.WinForms/LiveChartsCore.SkiaSharpView.WinForms.csproj b/src/skiasharp/LiveChartsCore.SkiaSharp.WinForms/LiveChartsCore.SkiaSharpView.WinForms.csproj index 3e185bba2..4e1eb2839 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharp.WinForms/LiveChartsCore.SkiaSharpView.WinForms.csproj +++ b/src/skiasharp/LiveChartsCore.SkiaSharp.WinForms/LiveChartsCore.SkiaSharpView.WinForms.csproj @@ -9,7 +9,7 @@ net462;netcoreapp3.1 LiveChartsCore.SkiaSharpView.WinForms LiveChartsCore.SkiaSharpView.WinForms - 2.0.0-beta.350 + 2.0.0-beta.360 icon.png Simple, flexible, interactive and powerful data visualization for WindowsForms. MIT diff --git a/src/skiasharp/LiveChartsCore.SkiaSharp.Xamarin.Forms/LiveChartsCore.SkiaSharpView.Xamarin.Forms.csproj b/src/skiasharp/LiveChartsCore.SkiaSharp.Xamarin.Forms/LiveChartsCore.SkiaSharpView.Xamarin.Forms.csproj index 486329f01..7a22729d5 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharp.Xamarin.Forms/LiveChartsCore.SkiaSharpView.Xamarin.Forms.csproj +++ b/src/skiasharp/LiveChartsCore.SkiaSharp.Xamarin.Forms/LiveChartsCore.SkiaSharpView.Xamarin.Forms.csproj @@ -6,7 +6,7 @@ netstandard2.0; LiveChartsCore.SkiaSharpView.XamarinForms LiveChartsCore.SkiaSharpView.XamarinForms - 2.0.0-beta.350 + 2.0.0-beta.360 icon.png Simple, flexible, interactive and powerful data visualization for XamarinForms. MIT diff --git a/src/skiasharp/LiveChartsCore.SkiaSharp/AssemblyInfo.cs b/src/skiasharp/LiveChartsCore.SkiaSharp/AssemblyInfo.cs index aaf8049af..9f5a39c7a 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharp/AssemblyInfo.cs +++ b/src/skiasharp/LiveChartsCore.SkiaSharp/AssemblyInfo.cs @@ -21,12 +21,12 @@ // SOFTWARE. using System.Runtime.CompilerServices; -//#if !DEBUG -//using System.Reflection; +#if !DEBUG +using System.Reflection; -//[assembly: AssemblyKeyFile("./../../../LiveCharts.snk")] -//[assembly: InternalsVisibleTo("LiveChartsCore.BackersPackage, PublicKey=0024000004800000940000000602000000240000525341310004000001000100d53791eaa0d98b405ca858f39169be6af36ceb7a1bca3ca76c6905fd22fddf8c5e4ef2778a5d7a77ad12f08da711fecfc44795c7923739a2acac946b3f1719a6dfc238695bc69cf5d959b3fb6bc4d18d57a97ff8ed897e6b22a6b8155401ee368d77431e74178104b4adca73520b058b9be28d4ec129beb54871778167afa5ce")] -//#else +[assembly: AssemblyKeyFile("./../../../LiveCharts.snk")] +[assembly: InternalsVisibleTo("LiveChartsCore.BackersPackage, PublicKey=0024000004800000940000000602000000240000525341310004000001000100d53791eaa0d98b405ca858f39169be6af36ceb7a1bca3ca76c6905fd22fddf8c5e4ef2778a5d7a77ad12f08da711fecfc44795c7923739a2acac946b3f1719a6dfc238695bc69cf5d959b3fb6bc4d18d57a97ff8ed897e6b22a6b8155401ee368d77431e74178104b4adca73520b058b9be28d4ec129beb54871778167afa5ce")] +#else [assembly: InternalsVisibleTo("LiveChartsCore.BackersPackage")] -//#endif +#endif diff --git a/src/skiasharp/LiveChartsCore.SkiaSharp/LiveChartsCore.SkiaSharpView.csproj b/src/skiasharp/LiveChartsCore.SkiaSharp/LiveChartsCore.SkiaSharpView.csproj index 2d2b40c47..6a7dd1d74 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharp/LiveChartsCore.SkiaSharpView.csproj +++ b/src/skiasharp/LiveChartsCore.SkiaSharp/LiveChartsCore.SkiaSharpView.csproj @@ -17,7 +17,7 @@ LiveChartsCore.SkiaSharpView LiveChartsCore.SkiaSharpView - 2.0.0-beta.350 + 2.0.0-beta.360 icon.png Simple, flexible, interactive and powerful data visualization for .Net, this package contains the SkiaSharp backend. MIT diff --git a/src/skiasharp/LiveChartsCore.SkiaSharpView.Blazor/LiveChartsCore.SkiaSharpView.Blazor.csproj b/src/skiasharp/LiveChartsCore.SkiaSharpView.Blazor/LiveChartsCore.SkiaSharpView.Blazor.csproj index b634db37f..0aac1770c 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharpView.Blazor/LiveChartsCore.SkiaSharpView.Blazor.csproj +++ b/src/skiasharp/LiveChartsCore.SkiaSharpView.Blazor/LiveChartsCore.SkiaSharpView.Blazor.csproj @@ -17,7 +17,7 @@ net6.0 enable enable - 2.0.0-beta.350 + 2.0.0-beta.360 icon.png Simple, flexible, interactive and powerful data visualization for Blazor. MIT diff --git a/src/skiasharp/LiveChartsCore.SkiaSharpView.Eto/LiveChartsCore.SkiaSharpView.Eto.csproj b/src/skiasharp/LiveChartsCore.SkiaSharpView.Eto/LiveChartsCore.SkiaSharpView.Eto.csproj index 81db5e525..7bdafac65 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharpView.Eto/LiveChartsCore.SkiaSharpView.Eto.csproj +++ b/src/skiasharp/LiveChartsCore.SkiaSharpView.Eto/LiveChartsCore.SkiaSharpView.Eto.csproj @@ -7,7 +7,7 @@ netstandard2.0 LiveChartsCore.SkiaSharpView.Eto LiveChartsCore.SkiaSharpView.Eto - 2.0.0-beta.350 + 2.0.0-beta.360 icon.png Simple, flexible, interactive and powerful data visualization for Eto.Forms. MIT diff --git a/src/skiasharp/LiveChartsCore.SkiaSharpView.Maui/LiveChartsCore.SkiaSharpView.Maui.csproj b/src/skiasharp/LiveChartsCore.SkiaSharpView.Maui/LiveChartsCore.SkiaSharpView.Maui.csproj index 9f6f87250..99b700148 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharpView.Maui/LiveChartsCore.SkiaSharpView.Maui.csproj +++ b/src/skiasharp/LiveChartsCore.SkiaSharpView.Maui/LiveChartsCore.SkiaSharpView.Maui.csproj @@ -14,7 +14,7 @@ 10.0.17763.0 10.0.17763.0 - 2.0.0-beta.350 + 2.0.0-beta.360 icon.png Simple, flexible, interactive and powerful data visualization for Maui. MIT diff --git a/src/skiasharp/LiveChartsCore.SkiaSharpView.Maui/LiveChartsCore.SkiaSharpView.Maui.nuspec b/src/skiasharp/LiveChartsCore.SkiaSharpView.Maui/LiveChartsCore.SkiaSharpView.Maui.nuspec index 584e533d1..76aa350b8 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharpView.Maui/LiveChartsCore.SkiaSharpView.Maui.nuspec +++ b/src/skiasharp/LiveChartsCore.SkiaSharpView.Maui/LiveChartsCore.SkiaSharpView.Maui.nuspec @@ -2,7 +2,7 @@ LiveChartsCore.SkiaSharpView.Maui - 2.0.0-beta.350 + 2.0.0-beta.360 LiveChartsCore.SkiaSharpView.Maui BetoRodriguez true @@ -17,23 +17,23 @@ - + - + - + - + - + diff --git a/src/skiasharp/LiveChartsCore.SkiaSharpView.Uno.WinUI/LiveChartsCore.SkiaSharpView.Uno.WinUI.csproj b/src/skiasharp/LiveChartsCore.SkiaSharpView.Uno.WinUI/LiveChartsCore.SkiaSharpView.Uno.WinUI.csproj index 457c1ece3..07026f72e 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharpView.Uno.WinUI/LiveChartsCore.SkiaSharpView.Uno.WinUI.csproj +++ b/src/skiasharp/LiveChartsCore.SkiaSharpView.Uno.WinUI/LiveChartsCore.SkiaSharpView.Uno.WinUI.csproj @@ -1,4 +1,4 @@ - + net6.0-windows10.0.18362;netstandard2.0;net6.0-ios;net6.0-macos;net6.0-maccatalyst;net6.0-android @@ -6,7 +6,7 @@ enable 10.0 - 2.0.0-beta.350 + 2.0.0-beta.360 icon.png Simple, flexible, interactive and powerful data visualization for Uno.WinUI. MIT diff --git a/src/skiasharp/LiveChartsCore.SkiaSharpView.Uno/LiveChartsCore.SkiaSharpView.Uno.csproj b/src/skiasharp/LiveChartsCore.SkiaSharpView.Uno/LiveChartsCore.SkiaSharpView.Uno.csproj index 4b066759c..408b942da 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharpView.Uno/LiveChartsCore.SkiaSharpView.Uno.csproj +++ b/src/skiasharp/LiveChartsCore.SkiaSharpView.Uno/LiveChartsCore.SkiaSharpView.Uno.csproj @@ -1,4 +1,4 @@ - + - - + +