Skip to content

Commit

Permalink
restore restart visuals
Browse files Browse the repository at this point in the history
  • Loading branch information
beto-rodriguez committed Aug 20, 2022
1 parent 2768e9d commit 043f2f3
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 9 deletions.
66 changes: 59 additions & 7 deletions src/LiveChartsCore/Kernel/Providers/DataFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

using System;
using System.Collections.Generic;
using System.Linq;
using LiveChartsCore.Defaults;
using LiveChartsCore.Drawing;
using LiveChartsCore.Kernel.Sketches;
Expand All @@ -42,6 +43,7 @@ public class DataFactory<TModel, TDrawingContext>
private readonly bool _isValueType = false;
private readonly Dictionary<object, Dictionary<int, MappedChartEntity>> _chartIndexEntityMap = new();
private readonly Dictionary<object, Dictionary<TModel, MappedChartEntity>> _chartRefEntityMap = new();
private ISeries? _series;

/// <summary>
/// Gets or sets the previous known bounds.
Expand Down Expand Up @@ -71,14 +73,9 @@ public DataFactory()
public virtual IEnumerable<ChartPoint> Fetch(ISeries<TModel> 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)
{
Expand Down Expand Up @@ -125,6 +122,7 @@ public virtual void DisposePoint(ChartPoint point)
/// <param name="chart"></param>
public virtual void Dispose(IChart chart)
{
_series = null;
if (_isTModelChartEntity) return;

if (_isValueType)
Expand Down Expand Up @@ -303,6 +301,60 @@ public virtual SeriesBounds GetPieBounds(
return new SeriesBounds(bounds, false);
}


/// <summary>
/// Clears the visuals in the cache.
/// </summary>
public void RestartVisuals()
{
if (_series is not null && _series.Values is IEnumerable<IChartEntity> entities)
{
foreach (var entity in entities)
{
foreach (var chartPoint in entity.ChartPoints?.Values ?? Enumerable.Empty<ChartPoint>())
{
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<ChartPoint>())
{
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<ChartPoint>())
{
if (chartPoint.Context.Visual is not IAnimatable visual) continue;
visual.RemoveTransition(null);
}
}
}
_chartRefEntityMap.Clear();
}

private IEnumerable<IChartEntity?> GetEntities(ISeries<TModel> series, IChart chart)
{
return _isTModelChartEntity
? EnumerateChartEntities(series, chart)
: (_isValueType
? EnumerateByValEntities(series, chart)
: EnumerateByRefEntities(series, chart));
}

private IEnumerable<IChartEntity> EnumerateChartEntities(ISeries<TModel> series, IChart chart)
{
if (series.Values is null) yield break;
Expand Down
4 changes: 2 additions & 2 deletions src/LiveChartsCore/Series.cs
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,8 @@ void ISeries.OnPointerLeft(ChartPoint point)
/// <inheritdoc cref="ISeries.RestartAnimations"/>
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();
}

/// <inheritdoc cref="ISeries.GetTooltipText(ChartPoint)"/>
Expand Down

0 comments on commit 043f2f3

Please sign in to comment.