Skip to content

Commit 567bb8b

Browse files
committed
[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
1 parent 5836c7f commit 567bb8b

File tree

9 files changed

+58
-5
lines changed

9 files changed

+58
-5
lines changed

src/LiveChartsCore/CartesianChart.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,10 @@ protected internal override void Measure()
460460
// get seriesBounds
461461
SetDrawMargin(ControlSize, new Margin());
462462

463+
if (_chartView.ResetSeries)
464+
{
465+
_nextSeries = 0;
466+
}
463467
foreach (var series in VisibleSeries.Cast<ICartesianSeries<TDrawingContext>>())
464468
{
465469
if (series.SeriesId == -1) series.SeriesId = _nextSeries++;

src/LiveChartsCore/Kernel/Sketches/IChartView.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ namespace LiveChartsCore.Kernel.Sketches;
3535
/// </summary>
3636
public interface IChartView
3737
{
38+
/// <summary>
39+
/// Gets or sets the ability to stop the chart colors from resetting.
40+
/// </summary>
41+
bool ResetSeries { get; set; }
42+
3843
/// <summary>
3944
/// Gets the core.
4045
/// </summary>
@@ -65,7 +70,7 @@ public interface IChartView
6570
LvcSize ControlSize { get; }
6671

6772
/// <summary>
68-
/// Gets or sets the draw margin, if this property is null, the library will calculate a margin, this margin is the distance
73+
/// Gets or sets the draw margin, if this property is null, the library will calculate a margin, this margin is the distance
6974
/// between the view bounds and the drawable area.
7075
/// </summary>
7176
/// <value>
@@ -82,7 +87,7 @@ public interface IChartView
8287
TimeSpan AnimationsSpeed { get; set; }
8388

8489
/// <summary>
85-
/// Gets or sets the easing function, the library already provides many easing functions in the
90+
/// Gets or sets the easing function, the library already provides many easing functions in the
8691
/// LiveCharts.EasingFunction static class.
8792
/// </summary>
8893
/// <value>

src/LiveChartsCore/PieChart.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,12 @@ protected internal override void Measure()
165165
IndexBounds = new Bounds();
166166
PushoutBounds = new Bounds();
167167

168+
if (_chartView.ResetSeries)
169+
{
170+
_nextSeries = 0;
171+
_drawnSeries.Clear();
172+
}
173+
168174
foreach (var series in VisibleSeries.Cast<IPieSeries<TDrawingContext>>())
169175
{
170176
if (series.SeriesId == -1) series.SeriesId = _nextSeries++;

src/skiasharp/LiveChartsCore.SkiaSharp/SKCharts/SKCartesianChart.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ public SKCartesianChart(ICartesianChartView<SkiaSharpDrawingContext> view) : thi
7575
VisualElements = view.VisualElements;
7676
}
7777

78+
/// <inheritdoc cref="IChartView.ResetSeries">
79+
public bool ResetSeries { get; set; }
80+
7881
/// <inheritdoc cref="IChartView.DesignerMode" />
7982
public bool DesignerMode => false;
8083

src/skiasharp/LiveChartsCore.SkiaSharp/SKCharts/SKPieChart.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ public SKPieChart(IPieChartView<SkiaSharpDrawingContext> view) : this()
7373
VisualElements = view.VisualElements;
7474
}
7575

76+
/// <inheritdoc cref="IChartView.ResetSeries">
77+
public bool ResetSeries { get; set; }
78+
7679
/// <inheritdoc cref="IChartView.DesignerMode" />
7780
public bool DesignerMode => false;
7881

src/skiasharp/LiveChartsCore.SkiaSharp/SKCharts/SKPolarChart.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ public SKPolarChart(IPolarChartView<SkiaSharpDrawingContext> view) : this()
7575
VisualElements = view.VisualElements;
7676
}
7777

78+
/// <inheritdoc cref="IChartView.ResetSeries">
79+
public bool ResetSeries { get; set; }
80+
7881
/// <inheritdoc cref="IChartView.DesignerMode" />
7982
public bool DesignerMode => false;
8083

src/skiasharp/LiveChartsCore.SkiaSharpView.Maui/CartesianChart.xaml.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public CartesianChart()
116116
chartBehaviour.On(this);
117117
}
118118

119-
#region bindable properties
119+
#region bindable properties
120120

121121
/// <summary>
122122
/// The sync context property.
@@ -386,7 +386,10 @@ public CartesianChart()
386386
BindableProperty.Create(
387387
nameof(VisualElementsPointerDownCommand), typeof(ICommand), typeof(CartesianChart), null);
388388

389-
#endregion
389+
public static readonly BindableProperty ResetSeriesProperty =
390+
BindableProperty.Create(nameof(ResetSeries), typeof(bool), typeof(CartesianChart), false);
391+
392+
#endregion
390393

391394
#region events
392395

@@ -415,6 +418,12 @@ public CartesianChart()
415418
/// <inheritdoc cref="IChartView.DesignerMode" />
416419
bool IChartView.DesignerMode => false;
417420

421+
public bool ResetSeries
422+
{
423+
get => (bool)GetValue(ResetSeriesProperty);
424+
set => SetValue(ResetSeriesProperty, value);
425+
}
426+
418427
/// <inheritdoc cref="IChartView.CoreChart" />
419428
public IChart CoreChart => _core ?? throw new Exception("Core not set yet.");
420429

src/skiasharp/LiveChartsCore.SkiaSharpView.Maui/PieChart.xaml.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,9 @@ public PieChart()
321321
BindableProperty.Create(
322322
nameof(VisualElementsPointerDownCommand), typeof(ICommand), typeof(PieChart), null);
323323

324+
public static readonly BindableProperty ResetSeriesProperty =
325+
BindableProperty.Create(nameof(ResetSeries), typeof(bool), typeof(PieChart), false);
326+
324327
#endregion
325328

326329
#region events
@@ -613,6 +616,13 @@ public ICommand? VisualElementsPointerDownCommand
613616
set => SetValue(VisualElementsPointerDownCommandProperty, value);
614617
}
615618

619+
/// <inheritdoc cref="IChartView.ResetSeries">
620+
public bool ResetSeries
621+
{
622+
get => (bool)GetValue(ResetSeriesProperty);
623+
set => SetValue(ResetSeriesProperty, value);
624+
}
625+
616626
#endregion
617627

618628
/// <inheritdoc cref="IChartView{TDrawingContext}.GetPointsAt(LvcPoint, TooltipFindingStrategy)"/>

src/skiasharp/LiveChartsCore.SkiaSharpView.Maui/PolarChart.xaml.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public PolarChart()
107107
chartBehaviour.On(this);
108108
}
109109

110-
#region bindable properties
110+
#region bindable properties
111111

112112
/// <summary>
113113
/// The sync context property.
@@ -362,6 +362,9 @@ public PolarChart()
362362
BindableProperty.Create(
363363
nameof(VisualElementsPointerDownCommand), typeof(ICommand), typeof(PolarChart), null);
364364

365+
public static readonly BindableProperty ResetSeriesProperty =
366+
BindableProperty.Create(nameof(ResetSeries), typeof(bool), typeof(PolarChart), false);
367+
365368
#endregion
366369

367370
#region events
@@ -391,6 +394,13 @@ public PolarChart()
391394
/// <inheritdoc cref="IChartView.DesignerMode" />
392395
bool IChartView.DesignerMode => false;
393396

397+
/// <inheritdoc cref="IChartView.ResetSeries">
398+
public bool ResetSeries
399+
{
400+
get => (bool)GetValue(ResetSeriesProperty);
401+
set => SetValue(ResetSeriesProperty, value);
402+
}
403+
394404
/// <inheritdoc cref="IChartView.CoreChart" />
395405
public IChart CoreChart => _core ?? throw new Exception("Core not set yet.");
396406

0 commit comments

Comments
 (0)