From 567bb8b98dcade22fd636fbe67a99ca6856d3be6 Mon Sep 17 00:00:00 2001 From: Aaron Eversole Date: Mon, 8 Apr 2024 14:34:28 -0500 Subject: [PATCH] [ADDITION] Allow for the Chart Colors list to be reset * Added a ResetSeries property that when set to true, will cause the charts to redraw with a reset color list --- src/LiveChartsCore/CartesianChart.cs | 4 ++++ src/LiveChartsCore/Kernel/Sketches/IChartView.cs | 9 +++++++-- src/LiveChartsCore/PieChart.cs | 6 ++++++ .../SKCharts/SKCartesianChart.cs | 3 +++ .../LiveChartsCore.SkiaSharp/SKCharts/SKPieChart.cs | 3 +++ .../SKCharts/SKPolarChart.cs | 3 +++ .../CartesianChart.xaml.cs | 13 +++++++++++-- .../PieChart.xaml.cs | 10 ++++++++++ .../PolarChart.xaml.cs | 12 +++++++++++- 9 files changed, 58 insertions(+), 5 deletions(-) diff --git a/src/LiveChartsCore/CartesianChart.cs b/src/LiveChartsCore/CartesianChart.cs index 94abc5d20..9420678af 100644 --- a/src/LiveChartsCore/CartesianChart.cs +++ b/src/LiveChartsCore/CartesianChart.cs @@ -460,6 +460,10 @@ protected internal override void Measure() // get seriesBounds SetDrawMargin(ControlSize, new Margin()); + if (_chartView.ResetSeries) + { + _nextSeries = 0; + } foreach (var series in VisibleSeries.Cast>()) { if (series.SeriesId == -1) series.SeriesId = _nextSeries++; diff --git a/src/LiveChartsCore/Kernel/Sketches/IChartView.cs b/src/LiveChartsCore/Kernel/Sketches/IChartView.cs index 431197787..0b5dd05ef 100644 --- a/src/LiveChartsCore/Kernel/Sketches/IChartView.cs +++ b/src/LiveChartsCore/Kernel/Sketches/IChartView.cs @@ -35,6 +35,11 @@ namespace LiveChartsCore.Kernel.Sketches; /// public interface IChartView { + /// + /// Gets or sets the ability to stop the chart colors from resetting. + /// + bool ResetSeries { get; set; } + /// /// Gets the core. /// @@ -65,7 +70,7 @@ public interface IChartView LvcSize ControlSize { get; } /// - /// Gets or sets the draw margin, if this property is null, the library will calculate a margin, this margin is the distance + /// Gets or sets the draw margin, if this property is null, the library will calculate a margin, this margin is the distance /// between the view bounds and the drawable area. /// /// @@ -82,7 +87,7 @@ public interface IChartView TimeSpan AnimationsSpeed { get; set; } /// - /// Gets or sets the easing function, the library already provides many easing functions in the + /// Gets or sets the easing function, the library already provides many easing functions in the /// LiveCharts.EasingFunction static class. /// /// diff --git a/src/LiveChartsCore/PieChart.cs b/src/LiveChartsCore/PieChart.cs index bfbb00723..24c1f7834 100644 --- a/src/LiveChartsCore/PieChart.cs +++ b/src/LiveChartsCore/PieChart.cs @@ -165,6 +165,12 @@ protected internal override void Measure() IndexBounds = new Bounds(); PushoutBounds = new Bounds(); + if (_chartView.ResetSeries) + { + _nextSeries = 0; + _drawnSeries.Clear(); + } + foreach (var series in VisibleSeries.Cast>()) { if (series.SeriesId == -1) series.SeriesId = _nextSeries++; diff --git a/src/skiasharp/LiveChartsCore.SkiaSharp/SKCharts/SKCartesianChart.cs b/src/skiasharp/LiveChartsCore.SkiaSharp/SKCharts/SKCartesianChart.cs index dda1cfd7a..60d1d7d3e 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharp/SKCharts/SKCartesianChart.cs +++ b/src/skiasharp/LiveChartsCore.SkiaSharp/SKCharts/SKCartesianChart.cs @@ -75,6 +75,9 @@ public SKCartesianChart(ICartesianChartView view) : thi VisualElements = view.VisualElements; } + /// + public bool ResetSeries { get; set; } + /// public bool DesignerMode => false; diff --git a/src/skiasharp/LiveChartsCore.SkiaSharp/SKCharts/SKPieChart.cs b/src/skiasharp/LiveChartsCore.SkiaSharp/SKCharts/SKPieChart.cs index 72d64c24b..58ef982b3 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharp/SKCharts/SKPieChart.cs +++ b/src/skiasharp/LiveChartsCore.SkiaSharp/SKCharts/SKPieChart.cs @@ -73,6 +73,9 @@ public SKPieChart(IPieChartView view) : this() VisualElements = view.VisualElements; } + /// + public bool ResetSeries { get; set; } + /// public bool DesignerMode => false; diff --git a/src/skiasharp/LiveChartsCore.SkiaSharp/SKCharts/SKPolarChart.cs b/src/skiasharp/LiveChartsCore.SkiaSharp/SKCharts/SKPolarChart.cs index 2f6e45feb..d46f84dff 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharp/SKCharts/SKPolarChart.cs +++ b/src/skiasharp/LiveChartsCore.SkiaSharp/SKCharts/SKPolarChart.cs @@ -75,6 +75,9 @@ public SKPolarChart(IPolarChartView view) : this() VisualElements = view.VisualElements; } + /// + public bool ResetSeries { get; set; } + /// public bool DesignerMode => false; diff --git a/src/skiasharp/LiveChartsCore.SkiaSharpView.Maui/CartesianChart.xaml.cs b/src/skiasharp/LiveChartsCore.SkiaSharpView.Maui/CartesianChart.xaml.cs index 2d3b5e278..f1166ed5a 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharpView.Maui/CartesianChart.xaml.cs +++ b/src/skiasharp/LiveChartsCore.SkiaSharpView.Maui/CartesianChart.xaml.cs @@ -116,7 +116,7 @@ public CartesianChart() chartBehaviour.On(this); } - #region bindable properties + #region bindable properties /// /// The sync context property. @@ -386,7 +386,10 @@ public CartesianChart() BindableProperty.Create( nameof(VisualElementsPointerDownCommand), typeof(ICommand), typeof(CartesianChart), null); - #endregion + public static readonly BindableProperty ResetSeriesProperty = + BindableProperty.Create(nameof(ResetSeries), typeof(bool), typeof(CartesianChart), false); + +#endregion #region events @@ -415,6 +418,12 @@ public CartesianChart() /// bool IChartView.DesignerMode => false; + public bool ResetSeries + { + get => (bool)GetValue(ResetSeriesProperty); + set => SetValue(ResetSeriesProperty, value); + } + /// public IChart CoreChart => _core ?? throw new Exception("Core not set yet."); diff --git a/src/skiasharp/LiveChartsCore.SkiaSharpView.Maui/PieChart.xaml.cs b/src/skiasharp/LiveChartsCore.SkiaSharpView.Maui/PieChart.xaml.cs index 7f8779ea6..c2e520aa7 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharpView.Maui/PieChart.xaml.cs +++ b/src/skiasharp/LiveChartsCore.SkiaSharpView.Maui/PieChart.xaml.cs @@ -321,6 +321,9 @@ public PieChart() BindableProperty.Create( nameof(VisualElementsPointerDownCommand), typeof(ICommand), typeof(PieChart), null); + public static readonly BindableProperty ResetSeriesProperty = + BindableProperty.Create(nameof(ResetSeries), typeof(bool), typeof(PieChart), false); + #endregion #region events @@ -613,6 +616,13 @@ public ICommand? VisualElementsPointerDownCommand set => SetValue(VisualElementsPointerDownCommandProperty, value); } + /// + public bool ResetSeries + { + get => (bool)GetValue(ResetSeriesProperty); + set => SetValue(ResetSeriesProperty, value); + } + #endregion /// diff --git a/src/skiasharp/LiveChartsCore.SkiaSharpView.Maui/PolarChart.xaml.cs b/src/skiasharp/LiveChartsCore.SkiaSharpView.Maui/PolarChart.xaml.cs index 5413ec4bd..ab0332fa8 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharpView.Maui/PolarChart.xaml.cs +++ b/src/skiasharp/LiveChartsCore.SkiaSharpView.Maui/PolarChart.xaml.cs @@ -107,7 +107,7 @@ public PolarChart() chartBehaviour.On(this); } - #region bindable properties + #region bindable properties /// /// The sync context property. @@ -362,6 +362,9 @@ public PolarChart() BindableProperty.Create( nameof(VisualElementsPointerDownCommand), typeof(ICommand), typeof(PolarChart), null); + public static readonly BindableProperty ResetSeriesProperty = + BindableProperty.Create(nameof(ResetSeries), typeof(bool), typeof(PolarChart), false); + #endregion #region events @@ -391,6 +394,13 @@ public PolarChart() /// bool IChartView.DesignerMode => false; + /// + public bool ResetSeries + { + get => (bool)GetValue(ResetSeriesProperty); + set => SetValue(ResetSeriesProperty, value); + } + /// public IChart CoreChart => _core ?? throw new Exception("Core not set yet.");