Skip to content

Commit

Permalink
Make DrawChart public static; add _SharedPropertiesTests
Browse files Browse the repository at this point in the history
Changed DrawChart method in ChangingPaintTasks to public static
for external access. Added _SharedPropertiesTests class with
Visibility and VisibilityAndPaintsTasks tests to verify chart
rendering and drawable count behavior. Imported necessary
namespaces for testing.
  • Loading branch information
beto-rodriguez committed Oct 17, 2024
1 parent b4c9c7d commit d08b62e
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ public void SectionsInstanceChanged()
geometries == canvas.CountGeometries());
}

private int DrawChart(InMemorySkiaSharpChart chart, bool animated = false)
public static int DrawChart(InMemorySkiaSharpChart chart, bool animated = false)
{
var coreChart = (Chart<SkiaSharpDrawingContext>)chart.CoreChart;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using LiveChartsCore.Defaults;
using LiveChartsCore.SkiaSharpView;
using LiveChartsCore.SkiaSharpView.SKCharts;
using LiveChartsCore.UnitTesting.CoreObjectsTests;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace LiveChartsCore.UnitTesting.SeriesTests;

[TestClass]
public class _SharedPropertiesTests
{
[TestMethod]
public void Visibility()
{
var values = new ObservableCollection<ObservableValue>();
var lineSeries = new LineSeries<ObservableValue>(values);

var chart = new SKCartesianChart
{
Series = [lineSeries],
Width = 1000,
Height = 1000
};

_ = chart.GetImage();

var changes = 0;

values.CollectionChanged +=
(object? sender, NotifyCollectionChangedEventArgs e) =>

Check warning on line 32 in tests/LiveChartsCore.UnitTesting/SeriesTests/_SharedPropertiesTests.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp, x86)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 32 in tests/LiveChartsCore.UnitTesting/SeriesTests/_SharedPropertiesTests.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp, x86)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 32 in tests/LiveChartsCore.UnitTesting/SeriesTests/_SharedPropertiesTests.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp, x64)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 32 in tests/LiveChartsCore.UnitTesting/SeriesTests/_SharedPropertiesTests.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp, x64)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
changes++;

values.Add(new(1));
_ = chart.GetImage();

Assert.IsTrue(changes == 1);

lineSeries.IsVisible = false;
_ = chart.GetImage();

lineSeries.IsVisible = true;
_ = chart.GetImage();

values.Add(new(1));
_ = chart.GetImage();

Assert.IsTrue(changes == 2);
}

[TestMethod]
public void VisbilityAndPaintsTasks()
{
var values = new ObservableCollection<DateTimePoint>() { new() };
var lineSeries = new ColumnSeries<DateTimePoint>(values);
var chart = new SKCartesianChart
{
Series = [lineSeries],
Width = 1000,
Height = 1000
};

_ = ChangingPaintTasks.DrawChart(chart, true);

var canvas = chart.CoreCanvas;
var drawables = canvas.DrawablesCount;
var geometries = canvas.CountGeometries();

lineSeries.IsVisible = false;
_ = ChangingPaintTasks.DrawChart(chart, true);

lineSeries.IsVisible = true;
_ = ChangingPaintTasks.DrawChart(chart, true);

Assert.IsTrue(
drawables == canvas.DrawablesCount &&
geometries == canvas.CountGeometries());
}
}

0 comments on commit d08b62e

Please sign in to comment.