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) 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..97808e4 --- /dev/null +++ b/src/DynamicDataDisplay.Samples/Demos/UserTests/TestSwitchingMarkersDataSource.xaml.cs @@ -0,0 +1,117 @@ +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 + { + /// + /// 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() + { + InitializeComponent(); + Loaded += OnLoaded; + Unloaded += OnUnloaded; + } + + /// + /// Called when the control is loaded + /// + 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(); + } + + /// + /// Periodic chart updater + /// + private 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); + } + } + + /// + /// Creates an immutable collection of points from the current time, and data source number + /// + 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 @@ +