Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ADDITION] Allow for the Chart Colors list to be reset #1480

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
6 changes: 6 additions & 0 deletions src/LiveChartsCore/PieChart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<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