summaryrefslogtreecommitdiff
path: root/grapher/Models/Charts
diff options
context:
space:
mode:
Diffstat (limited to 'grapher/Models/Charts')
-rw-r--r--grapher/Models/Charts/AccelCharts.cs203
-rw-r--r--grapher/Models/Charts/ChartXY.cs213
-rw-r--r--grapher/Models/Charts/EstimatedPoints.cs25
3 files changed, 441 insertions, 0 deletions
diff --git a/grapher/Models/Charts/AccelCharts.cs b/grapher/Models/Charts/AccelCharts.cs
new file mode 100644
index 0000000..1aa3909
--- /dev/null
+++ b/grapher/Models/Charts/AccelCharts.cs
@@ -0,0 +1,203 @@
+using grapher.Models.Calculations;
+using grapher.Models.Charts;
+using System;
+using System.Collections.Generic;
+using System.Drawing;
+using System.Linq;
+using System.Security.Permissions;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+using System.Windows.Forms.DataVisualization.Charting;
+
+namespace grapher
+{
+ public class AccelCharts
+ {
+ public const int ChartSeparationVertical = 10;
+
+ /// <summary> Needed to show full contents in form. Unsure why. </summary>
+ public const int FormHeightPadding = 35;
+
+ public AccelCharts(
+ Form form,
+ ChartXY sensitivityChart,
+ ChartXY velocityChart,
+ ChartXY gainChart,
+ ToolStripMenuItem enableVelocityAndGain,
+ ICollection<CheckBox> checkBoxesXY)
+ {
+ Estimated = new EstimatedPoints();
+ EstimatedX = new EstimatedPoints();
+ EstimatedY = new EstimatedPoints();
+ AccelData = new AccelData(Estimated, EstimatedX, EstimatedY);
+
+ ContaingForm = form;
+ SensitivityChart = sensitivityChart;
+ VelocityChart = velocityChart;
+ GainChart = gainChart;
+ EnableVelocityAndGain = enableVelocityAndGain;
+ CheckBoxesXY = checkBoxesXY;
+
+ SensitivityChart.SetPointBinds(Estimated.Sensitivity, EstimatedX.Sensitivity, EstimatedY.Sensitivity);
+ VelocityChart.SetPointBinds(Estimated.Velocity, EstimatedX.Velocity, EstimatedY.Velocity);
+ GainChart.SetPointBinds(Estimated.Gain, EstimatedX.Gain, EstimatedY.Gain);
+
+ SensitivityChart.SetTop(0);
+ VelocityChart.SetHeight(SensitivityChart.Height);
+ VelocityChart.SetTop(SensitivityChart.Height + ChartSeparationVertical);
+ GainChart.SetHeight(SensitivityChart.Height);
+ GainChart.SetTop(VelocityChart.Top + VelocityChart.Height + ChartSeparationVertical);
+
+ Rectangle screenRectangle = ContaingForm.RectangleToScreen(ContaingForm.ClientRectangle);
+ FormBorderHeight = screenRectangle.Top - ContaingForm.Top;
+
+ EnableVelocityAndGain.Click += new System.EventHandler(OnEnableClick);
+ EnableVelocityAndGain.CheckedChanged += new System.EventHandler(OnEnableCheckStateChange);
+
+ HideVelocityAndGain();
+ Combined = false;
+ ShowCombined();
+ }
+
+ public Form ContaingForm { get; }
+
+ public ChartXY SensitivityChart { get; }
+
+ public ChartXY VelocityChart { get; }
+
+ public ChartXY GainChart { get; }
+
+ public ToolStripMenuItem EnableVelocityAndGain { get; }
+
+ public AccelData AccelData { get; }
+
+ private EstimatedPoints Estimated { get; }
+
+ private EstimatedPoints EstimatedX { get; }
+
+ private EstimatedPoints EstimatedY { get; }
+
+ private ICollection<CheckBox> CheckBoxesXY { get; }
+
+ private bool Combined { get; set; }
+
+ private int FormBorderHeight { get; }
+
+ public void MakeDots(int x, int y, double timeInMs)
+ {
+ if (Combined)
+ {
+ AccelData.CalculateDots(x, y, timeInMs);
+ }
+ else
+ {
+ AccelData.CalculateDotsXY(x, y, timeInMs);
+ }
+ }
+
+ public void DrawPoints()
+ {
+ SensitivityChart.DrawPoints();
+ VelocityChart.DrawPoints();
+ GainChart.DrawPoints();
+ }
+
+ public void Bind()
+ {
+ if (Combined)
+ {
+ SensitivityChart.Bind(AccelData.Combined.AccelPoints);
+ VelocityChart.Bind(AccelData.Combined.VelocityPoints);
+ GainChart.Bind(AccelData.Combined.GainPoints);
+ }
+ else
+ {
+ SensitivityChart.BindXY(AccelData.X.AccelPoints, AccelData.Y.AccelPoints);
+ VelocityChart.BindXY(AccelData.X.VelocityPoints, AccelData.Y.VelocityPoints);
+ GainChart.BindXY(AccelData.X.GainPoints, AccelData.Y.GainPoints);
+ }
+ }
+
+ public void RefreshXY()
+ {
+ if (CheckBoxesXY.All(box => box.Checked))
+ {
+ ShowCombined();
+ }
+ else
+ {
+ ShowXandYSeparate();
+ }
+ }
+
+ private void OnEnableClick(object sender, EventArgs e)
+ {
+ EnableVelocityAndGain.Checked = !EnableVelocityAndGain.Checked;
+ }
+
+ private void OnEnableCheckStateChange(object sender, EventArgs e)
+ {
+ if (EnableVelocityAndGain.Checked)
+ {
+ ShowVelocityAndGain();
+ }
+ else
+ {
+ HideVelocityAndGain();
+ }
+ }
+
+ private void ShowVelocityAndGain()
+ {
+ VelocityChart.Show();
+ GainChart.Show();
+ ContaingForm.Height = SensitivityChart.Height +
+ ChartSeparationVertical +
+ VelocityChart.Height +
+ ChartSeparationVertical +
+ GainChart.Height +
+ FormBorderHeight;
+ }
+
+ private void HideVelocityAndGain()
+ {
+ VelocityChart.Hide();
+ GainChart.Hide();
+ ContaingForm.Height = SensitivityChart.Height + FormBorderHeight;
+ }
+
+ private void ShowXandYSeparate()
+ {
+ if (Combined)
+ {
+ Combined = false;
+
+ SensitivityChart.SetSeparate();
+ VelocityChart.SetSeparate();
+ GainChart.SetSeparate();
+ UpdateFormWidth();
+ Bind();
+ }
+ }
+
+ private void ShowCombined()
+ {
+ if (!Combined)
+ {
+ Combined = true;
+
+ SensitivityChart.SetCombined();
+ VelocityChart.SetCombined();
+ GainChart.SetCombined();
+ UpdateFormWidth();
+ Bind();
+ }
+ }
+
+ private void UpdateFormWidth()
+ {
+ ContaingForm.Width = SensitivityChart.Left + SensitivityChart.Width;
+ }
+ }
+}
diff --git a/grapher/Models/Charts/ChartXY.cs b/grapher/Models/Charts/ChartXY.cs
new file mode 100644
index 0000000..81874a2
--- /dev/null
+++ b/grapher/Models/Charts/ChartXY.cs
@@ -0,0 +1,213 @@
+using grapher.Models.Charts;
+using grapher.Models.Mouse;
+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;
+ 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);
+ }
+
+ #endregion Constructors
+
+ #region Properties
+
+ public Chart ChartX { get; }
+
+ public Chart ChartY { get; }
+
+ 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.Top;
+ }
+ }
+
+ public int Left {
+ get
+ {
+ return ChartX.Left;
+ }
+ }
+
+ 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
+
+ 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, PointData point)
+ {
+ if (chart.Visible)
+ {
+ point.Get(out var x, out var y);
+ chart.Series[1].Points.DataBindXY(x, y);
+ chart.Update();
+ }
+ }
+
+ public void SetPointBinds(PointData combined, PointData x, PointData y)
+ {
+ CombinedPointData = combined;
+ XPointData = x;
+ YPointData = y;
+ }
+
+ public void DrawPoints()
+ {
+ if(Combined)
+ {
+ DrawPoint(ChartX, CombinedPointData);
+ }
+ else
+ {
+ DrawPoint(ChartX, XPointData);
+ DrawPoint(ChartY, YPointData);
+ }
+ }
+
+ public void Bind(IDictionary data)
+ {
+ 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)
+ {
+ 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;
+ }
+
+ #endregion Methods
+ }
+}
diff --git a/grapher/Models/Charts/EstimatedPoints.cs b/grapher/Models/Charts/EstimatedPoints.cs
new file mode 100644
index 0000000..fa0718b
--- /dev/null
+++ b/grapher/Models/Charts/EstimatedPoints.cs
@@ -0,0 +1,25 @@
+using grapher.Models.Mouse;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace grapher.Models.Charts
+{
+ public class EstimatedPoints
+ {
+ public EstimatedPoints()
+ {
+ Sensitivity = new PointData();
+ Velocity = new PointData();
+ Gain = new PointData();
+ }
+
+ public PointData Sensitivity { get; }
+
+ public PointData Velocity { get; }
+
+ public PointData Gain { get; }
+ }
+}