From 50e23fa88f2ed49f29a648c4d001dec3a3511e8f Mon Sep 17 00:00:00 2001 From: John Stewien Date: Fri, 22 Aug 2025 13:35:02 +0930 Subject: [PATCH 1/3] #24 Added sample for testing changing the ItemsSource on a DevMarkerChart. Shows a performance issue. --- src/DynamicDataDisplay.Samples/App.xaml | 5 +- .../TestSwitchingMarkersDataSource.xaml | 43 +++++++++ .../TestSwitchingMarkersDataSource.xaml.cs | 91 +++++++++++++++++++ .../DynamicDataDisplay.Samples.csproj | 1 + 4 files changed, 139 insertions(+), 1 deletion(-) create mode 100644 src/DynamicDataDisplay.Samples/Demos/UserTests/TestSwitchingMarkersDataSource.xaml create mode 100644 src/DynamicDataDisplay.Samples/Demos/UserTests/TestSwitchingMarkersDataSource.xaml.cs diff --git a/src/DynamicDataDisplay.Samples/App.xaml b/src/DynamicDataDisplay.Samples/App.xaml index d6299c5..5dd52f1 100644 --- a/src/DynamicDataDisplay.Samples/App.xaml +++ b/src/DynamicDataDisplay.Samples/App.xaml @@ -51,7 +51,10 @@ - + + + + diff --git a/src/DynamicDataDisplay.Samples/Demos/UserTests/TestSwitchingMarkersDataSource.xaml b/src/DynamicDataDisplay.Samples/Demos/UserTests/TestSwitchingMarkersDataSource.xaml new file mode 100644 index 0000000..783c3da --- /dev/null +++ b/src/DynamicDataDisplay.Samples/Demos/UserTests/TestSwitchingMarkersDataSource.xaml @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/DynamicDataDisplay.Samples/Demos/UserTests/TestSwitchingMarkersDataSource.xaml.cs b/src/DynamicDataDisplay.Samples/Demos/UserTests/TestSwitchingMarkersDataSource.xaml.cs new file mode 100644 index 0000000..4d4f7e2 --- /dev/null +++ b/src/DynamicDataDisplay.Samples/Demos/UserTests/TestSwitchingMarkersDataSource.xaml.cs @@ -0,0 +1,91 @@ +using DynamicDataDisplay.Charts.Markers; +using System; +using System.Collections.Generic; +using System.Collections.Immutable; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Threading; + +namespace DynamicDataDisplay.Samples.Demos.UserTest +{ + /// + /// Interaction logic for DifferentBuildInMarkersPage.xaml + /// + public partial class TestSwitchingMarkersDataSource : Page + { + private const int _maxCount = 50; + private const int _minCount = 2; + private int _count = 1; + private int _countDirection = 1; + private int _startTime; + private DispatcherTimer _timer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(10) }; + private List _charts = new List(); + + public TestSwitchingMarkersDataSource() + { + InitializeComponent(); + Loaded += OnLoaded; + Unloaded += OnUnloaded; + } + + + private void OnLoaded(object sender, RoutedEventArgs e) + { + _startTime = Environment.TickCount; + + _charts.AddMany + ([ + chart1, + chart2, + chart3, + chart4, + chart5, + chart6, + chart7, + chart8, + ]); + + _timer.Tick += timer_Tick; + _timer.Start(); + } + + private void OnUnloaded(object sender, RoutedEventArgs e) + { + _timer.Tick -= timer_Tick; + _timer.Stop(); + } + + void timer_Tick(object sender, EventArgs e) + { + if (_count >= _maxCount) + { + _countDirection = -1; + } + else if (_count <= _minCount) + { + _countDirection = 1; + } + _count += _countDirection; + + for (int i = 0; i < _charts.Count; i++) + { + _charts[i].ItemsSource = CreateCollection(i+1); + } + } + + private ImmutableList CreateCollection(int dataSourceNumber) + { + int time = Environment.TickCount; + + var points = new Point[_count]; + + for (int i = 0; i < _count; i++) + { + double x = i / (double)_count; + points[i] = new Point(x, 0.1 * dataSourceNumber + 0.06 * Math.Sin(10 * x + Math.Sqrt(dataSourceNumber + 1) * 0.0005 * (time - _startTime))); + } + + return ImmutableList.Create(points); + } + } +} diff --git a/src/DynamicDataDisplay.Samples/DynamicDataDisplay.Samples.csproj b/src/DynamicDataDisplay.Samples/DynamicDataDisplay.Samples.csproj index 68cba35..12edf39 100644 --- a/src/DynamicDataDisplay.Samples/DynamicDataDisplay.Samples.csproj +++ b/src/DynamicDataDisplay.Samples/DynamicDataDisplay.Samples.csproj @@ -36,6 +36,7 @@ + From 7dece48a92206411acf5d480bf11b2c679b8abe0 Mon Sep 17 00:00:00 2001 From: John Stewien Date: Fri, 22 Aug 2025 10:23:07 +0930 Subject: [PATCH 2/3] #24 Fixed an issue on the DevMarkerChart where markers weren't being cleared when the DataSource changed. --- .../DevMarkerChart.cs | 37 ++++++++----------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/src/DynamicDataDisplay.Markers/DevMarkerChart.cs b/src/DynamicDataDisplay.Markers/DevMarkerChart.cs index ae5874b..3234645 100644 --- a/src/DynamicDataDisplay.Markers/DevMarkerChart.cs +++ b/src/DynamicDataDisplay.Markers/DevMarkerChart.cs @@ -34,27 +34,22 @@ public override void OnPlotterAttached(Plotter plotter) DrawAllMarkers(false); } - #region DataSource - - protected override void OnDataSourceChanged(PointDataSourceBase prevSource, PointDataSourceBase currSource) - { - base.OnDataSourceChanged(prevSource, currSource); - - if (currSource != null) - { - MakeStandartPredictions(currSource); - DrawAllMarkers(true); - } - else - { - // todo clear - } - - // this is for PieChart in legend. - RaiseDataSourceChanged(prevSource, currSource); - } - - private void MakeStandartPredictions(PointDataSourceBase currSource) + #region DataSource + + protected override void OnDataSourceChanged(PointDataSourceBase prevSource, PointDataSourceBase currSource) + { + // Clear any existing children before redrawing collection + CurrentItemsPanel?.Children.Clear(); + if (currSource != null) + { + MakeStandartPredictions(currSource); + DrawAllMarkers(true); + } + + base.OnDataSourceChanged(prevSource, currSource); + } + + private void MakeStandartPredictions(PointDataSourceBase currSource) { Type dataType = currSource.GetDataType() as Type; if (dataType != null) From 398f004cf09a7a830b96715d5c22ed478d8baef9 Mon Sep 17 00:00:00 2001 From: John Stewien Date: Fri, 22 Aug 2025 13:45:45 +0930 Subject: [PATCH 3/3] #24 Did a bit of tidying up on the sample --- .../TestSwitchingMarkersDataSource.xaml.cs | 44 +++++++++++++++---- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/src/DynamicDataDisplay.Samples/Demos/UserTests/TestSwitchingMarkersDataSource.xaml.cs b/src/DynamicDataDisplay.Samples/Demos/UserTests/TestSwitchingMarkersDataSource.xaml.cs index 4d4f7e2..97808e4 100644 --- a/src/DynamicDataDisplay.Samples/Demos/UserTests/TestSwitchingMarkersDataSource.xaml.cs +++ b/src/DynamicDataDisplay.Samples/Demos/UserTests/TestSwitchingMarkersDataSource.xaml.cs @@ -13,12 +13,33 @@ namespace DynamicDataDisplay.Samples.Demos.UserTest /// public partial class TestSwitchingMarkersDataSource : Page { + /// + /// Maximum number of markers to display in a line + /// private const int _maxCount = 50; + /// + /// Minimum number of markers to display in a line + /// private const int _minCount = 2; + /// + /// Current number of markers to display in a line + /// private int _count = 1; + /// + /// Used to increase or decrease the number of markers + /// private int _countDirection = 1; + /// + /// Time we started in CPU ticks, used for getting a relative time + /// private int _startTime; + /// + /// Timer used to update the markers + /// private DispatcherTimer _timer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(10) }; + /// + /// A list of chart controls that we are updating + /// private List _charts = new List(); public TestSwitchingMarkersDataSource() @@ -28,13 +49,13 @@ public TestSwitchingMarkersDataSource() Unloaded += OnUnloaded; } - + /// + /// Called when the control is loaded + /// private void OnLoaded(object sender, RoutedEventArgs e) { _startTime = Environment.TickCount; - - _charts.AddMany - ([ + _charts.AddMany([ chart1, chart2, chart3, @@ -42,20 +63,22 @@ private void OnLoaded(object sender, RoutedEventArgs e) chart5, chart6, chart7, - chart8, - ]); + chart8]); - _timer.Tick += timer_Tick; + _timer.Tick += Timer_Tick; _timer.Start(); } private void OnUnloaded(object sender, RoutedEventArgs e) { - _timer.Tick -= timer_Tick; + _timer.Tick -= Timer_Tick; _timer.Stop(); } - void timer_Tick(object sender, EventArgs e) + /// + /// Periodic chart updater + /// + private void Timer_Tick(object sender, EventArgs e) { if (_count >= _maxCount) { @@ -73,6 +96,9 @@ void timer_Tick(object sender, EventArgs e) } } + /// + /// Creates an immutable collection of points from the current time, and data source number + /// private ImmutableList CreateCollection(int dataSourceNumber) { int time = Environment.TickCount;