summaryrefslogtreecommitdiff
path: root/grapher/Models/Charts
diff options
context:
space:
mode:
authorJacob Palecki <[email protected]>2020-08-12 19:22:21 -0700
committerJacob Palecki <[email protected]>2020-08-12 19:22:21 -0700
commitcc531c79f2bd664551071ef315a54814bd9ab914 (patch)
treee6d1db3477e8ba41299d1d92eac4748a648c960b /grapher/Models/Charts
parentAdd ability to have x\y graphs (diff)
downloadrawaccel-cc531c79f2bd664551071ef315a54814bd9ab914.tar.xz
rawaccel-cc531c79f2bd664551071ef315a54814bd9ab914.zip
Reorganized solution into directories
Diffstat (limited to 'grapher/Models/Charts')
-rw-r--r--grapher/Models/Charts/AccelCharts.cs117
-rw-r--r--grapher/Models/Charts/ChartXY.cs142
2 files changed, 259 insertions, 0 deletions
diff --git a/grapher/Models/Charts/AccelCharts.cs b/grapher/Models/Charts/AccelCharts.cs
new file mode 100644
index 0000000..9952016
--- /dev/null
+++ b/grapher/Models/Charts/AccelCharts.cs
@@ -0,0 +1,117 @@
+using System;
+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;
+
+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)
+ {
+ ContaingForm = form;
+ SensitivityChart = sensitivityChart;
+ VelocityChart = velocityChart;
+ GainChart = gainChart;
+ EnableVelocityAndGain = enableVelocityAndGain;
+
+ 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();
+ ShowCombined();
+ }
+
+ public Form ContaingForm { get; }
+
+ public ChartXY SensitivityChart { get; }
+
+ public ChartXY VelocityChart { get; }
+
+ public ChartXY GainChart { get; }
+
+ public ToolStripMenuItem EnableVelocityAndGain { get; }
+
+ private int FormBorderHeight { get; }
+
+ 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()
+ {
+ SensitivityChart.SetSeparate();
+ VelocityChart.SetSeparate();
+ GainChart.SetSeparate();
+ UpdateFormWidth();
+ }
+
+ private void ShowCombined()
+ {
+ SensitivityChart.SetCombined();
+ VelocityChart.SetCombined();
+ GainChart.SetCombined();
+ UpdateFormWidth();
+ }
+
+ 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..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;
+ }
+ }
+}