From cc531c79f2bd664551071ef315a54814bd9ab914 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Wed, 12 Aug 2020 19:22:21 -0700 Subject: Reorganized solution into directories --- grapher/Models/Charts/ChartXY.cs | 142 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100644 grapher/Models/Charts/ChartXY.cs (limited to 'grapher/Models/Charts/ChartXY.cs') diff --git a/grapher/Models/Charts/ChartXY.cs b/grapher/Models/Charts/ChartXY.cs new file mode 100644 index 0000000..4bb1bd5 --- /dev/null +++ b/grapher/Models/Charts/ChartXY.cs @@ -0,0 +1,142 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using System.Windows.Forms.DataVisualization.Charting; + +namespace grapher +{ + public class ChartXY + { + public const int ChartSeparationHorizontal = 10; + + public ChartXY(Chart chartX, Chart chartY) + { + ChartX = chartX; + ChartY = chartY; + + ChartY.Top = ChartX.Top; + ChartY.Height = ChartX.Height; + ChartY.Width = ChartX.Width; + ChartY.Left = ChartX.Left + ChartX.Width + ChartSeparationHorizontal; + + SetupChart(ChartX); + SetupChart(ChartY); + } + + public Chart ChartX { get; } + + public Chart ChartY { get; } + + public static void SetupChart(Chart chart) + { + chart.ChartAreas[0].AxisX.RoundAxisValues(); + + chart.ChartAreas[0].AxisX.ScaleView.Zoomable = true; + chart.ChartAreas[0].AxisY.ScaleView.Zoomable = true; + + chart.ChartAreas[0].AxisY.ScaleView.MinSize = 0.01; + chart.ChartAreas[0].AxisY.ScaleView.SmallScrollSize = 0.001; + + chart.ChartAreas[0].CursorY.Interval = 0.001; + + chart.ChartAreas[0].CursorX.AutoScroll = true; + chart.ChartAreas[0].CursorY.AutoScroll = true; + + chart.ChartAreas[0].CursorX.IsUserSelectionEnabled = true; + chart.ChartAreas[0].CursorY.IsUserSelectionEnabled = true; + + chart.ChartAreas[0].CursorX.IsUserEnabled = true; + chart.ChartAreas[0].CursorY.IsUserEnabled = true; + } + + public int Height { + get + { + return ChartX.Height; + } + } + + public int Width { + get + { + if (Combined) + { + return ChartX.Width; + } + else + { + return ChartY.Left + ChartY.Width - ChartX.Left; + } + } + } + + public int Top { + get + { + return ChartX.Height; + } + } + + public int Left { + get + { + return ChartX.Left; + } + } + + public bool Combined { get; private set; } + + public void SetCombined() + { + if (!Combined) + { + ChartY.Hide(); + Combined = true; + } + } + + public void SetSeparate() + { + if (Combined) + { + if (ChartX.Visible) + { + ChartY.Show(); + } + + Combined = false; + } + } + + public void Hide() + { + ChartX.Hide(); + ChartY.Hide(); + } + + public void Show() + { + ChartX.Show(); + + if (!Combined) + { + ChartY.Show(); + } + } + + public void SetTop(int top) + { + ChartX.Top = top; + ChartY.Top = top; + } + + public void SetHeight(int height) + { + ChartX.Height = height; + ChartY.Height = height; + } + } +} -- cgit v1.2.3 From b6254f32a6cfbd40bd1919950b344160f38bf1e4 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Wed, 12 Aug 2020 19:51:38 -0700 Subject: Factor accel calculations into calculation classes --- grapher/Models/Charts/ChartXY.cs | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'grapher/Models/Charts/ChartXY.cs') diff --git a/grapher/Models/Charts/ChartXY.cs b/grapher/Models/Charts/ChartXY.cs index 4bb1bd5..a57801e 100644 --- a/grapher/Models/Charts/ChartXY.cs +++ b/grapher/Models/Charts/ChartXY.cs @@ -1,4 +1,5 @@ using System; +using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; @@ -89,6 +90,11 @@ namespace grapher public bool Combined { get; private set; } + public void Bind(IDictionary data) + { + ChartX.Series[0].Points.DataBindXY(data.Keys, data.Values); + } + public void SetCombined() { if (!Combined) -- cgit v1.2.3 From 30e1391b224ae028f4476e06a07415a0285ac6c9 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Wed, 12 Aug 2020 20:39:53 -0700 Subject: Almost working --- grapher/Models/Charts/ChartXY.cs | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'grapher/Models/Charts/ChartXY.cs') diff --git a/grapher/Models/Charts/ChartXY.cs b/grapher/Models/Charts/ChartXY.cs index a57801e..7bb7ac8 100644 --- a/grapher/Models/Charts/ChartXY.cs +++ b/grapher/Models/Charts/ChartXY.cs @@ -95,6 +95,12 @@ namespace grapher ChartX.Series[0].Points.DataBindXY(data.Keys, data.Values); } + public void BindXY(IDictionary dataX, IDictionary dataY) + { + ChartX.Series[0].Points.DataBindXY(dataX.Keys, dataX.Values); + ChartY.Series[0].Points.DataBindXY(dataY.Keys, dataY.Values); + } + public void SetCombined() { if (!Combined) -- cgit v1.2.3 From 93a22c08b3223b040c3a3644fc3c4ef82fc576f0 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Thu, 13 Aug 2020 01:52:49 -0700 Subject: Dot to show mouse move --- grapher/Models/Charts/ChartXY.cs | 90 ++++++++++++++++++++++++++++++---------- 1 file changed, 67 insertions(+), 23 deletions(-) (limited to 'grapher/Models/Charts/ChartXY.cs') diff --git a/grapher/Models/Charts/ChartXY.cs b/grapher/Models/Charts/ChartXY.cs index 7bb7ac8..2c0ce2c 100644 --- a/grapher/Models/Charts/ChartXY.cs +++ b/grapher/Models/Charts/ChartXY.cs @@ -1,18 +1,26 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Windows.Forms.DataVisualization.Charting; +using static grapher.AccelCharts; namespace grapher { public class ChartXY { + #region Consts + public const int ChartSeparationHorizontal = 10; + #endregion Consts + + #region Constructors + public ChartXY(Chart chartX, Chart chartY) { ChartX = chartX; @@ -27,31 +35,13 @@ namespace grapher SetupChart(ChartY); } - public Chart ChartX { get; } - - public Chart ChartY { get; } - - public static void SetupChart(Chart chart) - { - chart.ChartAreas[0].AxisX.RoundAxisValues(); - - chart.ChartAreas[0].AxisX.ScaleView.Zoomable = true; - chart.ChartAreas[0].AxisY.ScaleView.Zoomable = true; - - chart.ChartAreas[0].AxisY.ScaleView.MinSize = 0.01; - chart.ChartAreas[0].AxisY.ScaleView.SmallScrollSize = 0.001; - - chart.ChartAreas[0].CursorY.Interval = 0.001; + #endregion Constructors - chart.ChartAreas[0].CursorX.AutoScroll = true; - chart.ChartAreas[0].CursorY.AutoScroll = true; + #region Properties - chart.ChartAreas[0].CursorX.IsUserSelectionEnabled = true; - chart.ChartAreas[0].CursorY.IsUserSelectionEnabled = true; + public Chart ChartX { get; } - chart.ChartAreas[0].CursorX.IsUserEnabled = true; - chart.ChartAreas[0].CursorY.IsUserEnabled = true; - } + public Chart ChartY { get; } public int Height { get @@ -77,7 +67,7 @@ namespace grapher public int Top { get { - return ChartX.Height; + return ChartX.Top; } } @@ -90,6 +80,58 @@ namespace grapher public bool Combined { get; private set; } + #endregion Properties + + #region Methods + + public static void SetupChart(Chart chart) + { + chart.ChartAreas[0].AxisX.RoundAxisValues(); + + chart.ChartAreas[0].AxisX.ScaleView.Zoomable = true; + chart.ChartAreas[0].AxisY.ScaleView.Zoomable = true; + + chart.ChartAreas[0].AxisY.ScaleView.MinSize = 0.01; + chart.ChartAreas[0].AxisY.ScaleView.SmallScrollSize = 0.001; + + chart.ChartAreas[0].CursorY.Interval = 0.001; + + chart.ChartAreas[0].CursorX.AutoScroll = true; + chart.ChartAreas[0].CursorY.AutoScroll = true; + + chart.ChartAreas[0].CursorX.IsUserSelectionEnabled = true; + chart.ChartAreas[0].CursorY.IsUserSelectionEnabled = true; + + chart.ChartAreas[0].CursorX.IsUserEnabled = true; + chart.ChartAreas[0].CursorY.IsUserEnabled = true; + + chart.Series[1].Points.Clear(); + chart.Series[1].Points.AddXY(0, 0); + } + + public static void DrawPoint(Chart chart, ChartPoint point) + { + chart.Series[1].Points[0].XValue = point.X; + chart.Series[1].Points[0].YValues[0] = point.Y; + } + + public void DrawPoints(ChartPoint CombinedPoint, ChartPoint XPoint, ChartPoint YPoint) + { + if (Combined) + { + DrawPoint(ChartX, CombinedPoint); + } + else + { + DrawPoint(ChartX, XPoint); + } + + if (ChartY.Visible) + { + DrawPoint(ChartY, YPoint); + } + } + public void Bind(IDictionary data) { ChartX.Series[0].Points.DataBindXY(data.Keys, data.Values); @@ -150,5 +192,7 @@ namespace grapher ChartX.Height = height; ChartY.Height = height; } + + #endregion Methods } } -- cgit v1.2.3 From 6602649bd7f9a9849b25fe55a5e5e8a617f40b70 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Thu, 13 Aug 2020 13:39:40 -0700 Subject: All works smoothly --- grapher/Models/Charts/ChartXY.cs | 41 +++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) (limited to 'grapher/Models/Charts/ChartXY.cs') diff --git a/grapher/Models/Charts/ChartXY.cs b/grapher/Models/Charts/ChartXY.cs index 2c0ce2c..c0c8713 100644 --- a/grapher/Models/Charts/ChartXY.cs +++ b/grapher/Models/Charts/ChartXY.cs @@ -1,4 +1,6 @@ -using System; +using grapher.Models.Charts; +using grapher.Models.Mouse; +using System; using System.Collections; using System.Collections.Generic; using System.Drawing; @@ -80,6 +82,12 @@ namespace grapher public bool Combined { get; private set; } + private PointData CombinedPointData { get; set; } + + private PointData XPointData { get; set; } + + private PointData YPointData { get; set; } + #endregion Properties #region Methods @@ -109,26 +117,33 @@ namespace grapher chart.Series[1].Points.AddXY(0, 0); } - public static void DrawPoint(Chart chart, ChartPoint point) + public static void DrawPoint(Chart chart, PointData point) { - chart.Series[1].Points[0].XValue = point.X; - chart.Series[1].Points[0].YValues[0] = point.Y; + if (chart.Visible) + { + (var x, var y) = point.Get(); + chart.Series[1].Points.DataBindXY(x, y); + chart.Update(); + } } - public void DrawPoints(ChartPoint CombinedPoint, ChartPoint XPoint, ChartPoint YPoint) + public void SetPointBinds(PointData combined, PointData x, PointData y) { - if (Combined) + CombinedPointData = combined; + XPointData = x; + YPointData = y; + } + + public void DrawPoints() + { + if(Combined) { - DrawPoint(ChartX, CombinedPoint); + DrawPoint(ChartX, CombinedPointData); } else { - DrawPoint(ChartX, XPoint); - } - - if (ChartY.Visible) - { - DrawPoint(ChartY, YPoint); + DrawPoint(ChartX, XPointData); + DrawPoint(ChartY, YPointData); } } -- cgit v1.2.3 From 32323636b4b5390c114fc2a6d845b7621a983cdc Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Thu, 13 Aug 2020 20:56:41 -0700 Subject: Fix initial points, add poll time constant --- grapher/Models/Charts/ChartXY.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'grapher/Models/Charts/ChartXY.cs') diff --git a/grapher/Models/Charts/ChartXY.cs b/grapher/Models/Charts/ChartXY.cs index c0c8713..81874a2 100644 --- a/grapher/Models/Charts/ChartXY.cs +++ b/grapher/Models/Charts/ChartXY.cs @@ -121,7 +121,7 @@ namespace grapher { if (chart.Visible) { - (var x, var y) = point.Get(); + point.Get(out var x, out var y); chart.Series[1].Points.DataBindXY(x, y); chart.Update(); } -- cgit v1.2.3