Skip to content

Commit

Permalink
[ADDITION] Allow for the Chart Colors list to be reset
Browse files Browse the repository at this point in the history
* Added a ResetSeries property that when set to true, will cause the charts to redraw with a reset color list
  • Loading branch information
AaronBastian committed Apr 8, 2024
1 parent 5836c7f commit f0783c8
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/LiveChartsCore/CartesianChart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ICartesianSeries<TDrawingContext>>())
{
if (series.SeriesId == -1) series.SeriesId = _nextSeries++;
Expand Down
9 changes: 7 additions & 2 deletions src/LiveChartsCore/Kernel/Sketches/IChartView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ namespace LiveChartsCore.Kernel.Sketches;
/// </summary>
public interface IChartView
{
/// <summary>
/// Gets or sets the ability to stop the chart colors from resetting.
/// </summary>
bool ResetSeries { get; set; }

/// <summary>
/// Gets the core.
/// </summary>
Expand Down Expand Up @@ -65,7 +70,7 @@ public interface IChartView
LvcSize ControlSize { get; }

/// <summary>
/// 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.
/// </summary>
/// <value>
Expand All @@ -82,7 +87,7 @@ public interface IChartView
TimeSpan AnimationsSpeed { get; set; }

/// <summary>
/// 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.
/// </summary>
/// <value>
Expand Down
5 changes: 5 additions & 0 deletions src/LiveChartsCore/PieChart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@ protected internal override void Measure()
IndexBounds = new Bounds();
PushoutBounds = new Bounds();

if (_chartView.ResetSeries)
{
_nextSeries = 0;
}

foreach (var series in VisibleSeries.Cast<IPieSeries<TDrawingContext>>())
{
if (series.SeriesId == -1) series.SeriesId = _nextSeries++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ public SKCartesianChart(ICartesianChartView<SkiaSharpDrawingContext> view) : thi
VisualElements = view.VisualElements;
}

/// <inheritdoc cref="IChartView.ResetSeries">
public bool ResetSeries { get; set; }

/// <inheritdoc cref="IChartView.DesignerMode" />
public bool DesignerMode => false;

Expand Down
3 changes: 3 additions & 0 deletions src/skiasharp/LiveChartsCore.SkiaSharp/SKCharts/SKPieChart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ public SKPieChart(IPieChartView<SkiaSharpDrawingContext> view) : this()
VisualElements = view.VisualElements;
}

/// <inheritdoc cref="IChartView.ResetSeries">
public bool ResetSeries { get; set; }

/// <inheritdoc cref="IChartView.DesignerMode" />
public bool DesignerMode => false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ public SKPolarChart(IPolarChartView<SkiaSharpDrawingContext> view) : this()
VisualElements = view.VisualElements;
}

/// <inheritdoc cref="IChartView.ResetSeries">
public bool ResetSeries { get; set; }

/// <inheritdoc cref="IChartView.DesignerMode" />
public bool DesignerMode => false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public CartesianChart()
chartBehaviour.On(this);
}

#region bindable properties
#region bindable properties

/// <summary>
/// The sync context property.
Expand Down Expand Up @@ -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

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

public bool ResetSeries
{
get => (bool)GetValue(ResetSeriesProperty);
set => SetValue(ResetSeriesProperty, value);
}

/// <inheritdoc cref="IChartView.CoreChart" />
public IChart CoreChart => _core ?? throw new Exception("Core not set yet.");

Expand Down
10 changes: 10 additions & 0 deletions src/skiasharp/LiveChartsCore.SkiaSharpView.Maui/PieChart.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -613,6 +616,13 @@ public ICommand? VisualElementsPointerDownCommand
set => SetValue(VisualElementsPointerDownCommandProperty, value);
}

/// <inheritdoc cref="IChartView.ResetSeries">
public bool ResetSeries
{
get => (bool)GetValue(ResetSeriesProperty);
set => SetValue(ResetSeriesProperty, value);
}

#endregion

/// <inheritdoc cref="IChartView{TDrawingContext}.GetPointsAt(LvcPoint, TooltipFindingStrategy)"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public PolarChart()
chartBehaviour.On(this);
}

#region bindable properties
#region bindable properties

/// <summary>
/// The sync context property.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -391,6 +394,13 @@ public PolarChart()
/// <inheritdoc cref="IChartView.DesignerMode" />
bool IChartView.DesignerMode => false;

/// <inheritdoc cref="IChartView.ResetSeries">
public bool ResetSeries
{
get => (bool)GetValue(ResetSeriesProperty);
set => SetValue(ResetSeriesProperty, value);
}

/// <inheritdoc cref="IChartView.CoreChart" />
public IChart CoreChart => _core ?? throw new Exception("Core not set yet.");

Expand Down

0 comments on commit f0783c8

Please sign in to comment.