# HG changeset patch
# User moel.mich
# Date 1325432802 0
# Node ID a41745e3828dbe6f06d489fdfbbdd32fb96a7cef
# Parent  4c31341a48007a626bbe61c9e7df4eac2b06e612
Added a context menu to the plot which allows the user to configure the time window for plotting.

diff -r 4c31341a4800 -r a41745e3828d GUI/MainForm.Designer.cs
--- a/GUI/MainForm.Designer.cs	Sun Jan 01 10:14:42 2012 +0000
+++ b/GUI/MainForm.Designer.cs	Sun Jan 01 15:46:42 2012 +0000
@@ -108,8 +108,7 @@
       this.saveFileDialog = new System.Windows.Forms.SaveFileDialog();
       this.timer = new System.Windows.Forms.Timer(this.components);
       this.splitContainer = new OpenHardwareMonitor.GUI.SplitContainerAdv();
-      this.treeView = new Aga.Controls.Tree.TreeViewAdv();
-      this.plotPanel = new OpenHardwareMonitor.GUI.PlotPanel();
+      this.treeView = new Aga.Controls.Tree.TreeViewAdv();      
       this.plotLocationMenuItem = new System.Windows.Forms.MenuItem();
       this.plotWindowMenuItem = new System.Windows.Forms.MenuItem();
       this.plotBottomMenuItem = new System.Windows.Forms.MenuItem();
@@ -431,7 +430,6 @@
       // 
       // splitContainer.Panel2
       // 
-      this.splitContainer.Panel2.Controls.Add(this.plotPanel);
       this.splitContainer.Panel2.Cursor = System.Windows.Forms.Cursors.Default;
       this.splitContainer.Size = new System.Drawing.Size(386, 483);
       this.splitContainer.SplitterDistance = 354;
@@ -472,14 +470,6 @@
       this.treeView.MouseMove += new System.Windows.Forms.MouseEventHandler(this.treeView_MouseMove);
       this.treeView.MouseUp += new System.Windows.Forms.MouseEventHandler(this.treeView_MouseUp);
       // 
-      // plotPanel
-      // 
-      this.plotPanel.Dock = System.Windows.Forms.DockStyle.Fill;
-      this.plotPanel.Location = new System.Drawing.Point(0, 0);
-      this.plotPanel.Name = "plotPanel";
-      this.plotPanel.Size = new System.Drawing.Size(386, 124);
-      this.plotPanel.TabIndex = 0;
-      // 
       // plotLocationMenuItem
       // 
       this.plotLocationMenuItem.Index = 6;
@@ -542,7 +532,6 @@
     private Aga.Controls.Tree.NodeControls.NodeTextBox nodeTextBoxMin;
     private Aga.Controls.Tree.NodeControls.NodeTextBox nodeTextBoxMax;
     private SplitContainerAdv splitContainer;
-    private PlotPanel plotPanel;
     private System.Windows.Forms.MenuItem viewMenuItem;
     private System.Windows.Forms.MenuItem plotMenuItem;
     private Aga.Controls.Tree.NodeControls.NodeCheckBox nodeCheckBox;
diff -r 4c31341a4800 -r a41745e3828d GUI/MainForm.cs
--- a/GUI/MainForm.cs	Sun Jan 01 10:14:42 2012 +0000
+++ b/GUI/MainForm.cs	Sun Jan 01 15:46:42 2012 +0000
@@ -63,6 +63,7 @@
     private UpdateVisitor updateVisitor = new UpdateVisitor();
     private SensorGadget gadget;
     private Form plotForm;
+    private PlotPanel plotPanel;
 
     private UserOption showHiddenSensors;
     private UserOption showPlot;
@@ -109,7 +110,10 @@
             
       this.Font = SystemFonts.MessageBoxFont;
       treeView.Font = SystemFonts.MessageBoxFont;
-      plotPanel.Font = SystemFonts.MessageBoxFont;           
+
+      plotPanel = new PlotPanel(settings);
+      plotPanel.Font = SystemFonts.MessageBoxFont;
+      plotPanel.Dock = DockStyle.Fill;
       
       nodeCheckBox.IsVisibleValueNeeded += nodeCheckBox_IsVisibleValueNeeded;
       nodeCheckBox.CheckStateChanged += UpdatePlotSelection;
diff -r 4c31341a4800 -r a41745e3828d GUI/PlotPanel.cs
--- a/GUI/PlotPanel.cs	Sun Jan 01 10:14:42 2012 +0000
+++ b/GUI/PlotPanel.cs	Sun Jan 01 15:46:42 2012 +0000
@@ -46,6 +46,8 @@
 namespace OpenHardwareMonitor.GUI {
   public class PlotPanel : UserControl {
 
+    private PersistentSettings settings;
+
     private DateTime now;
     private List<ISensor> clocks = new List<ISensor>();
     private List<ISensor> temperatures = new List<ISensor>();
@@ -58,13 +60,19 @@
     private Brush lightBrush;
     private Pen lightPen;
 
-    public PlotPanel() {
+    private UserRadioGroup timeWindowRadioGroup;
+
+    public PlotPanel(PersistentSettings settings) {
+      this.settings = settings;
+
       this.SetStyle(ControlStyles.DoubleBuffer |
         ControlStyles.UserPaint |
         ControlStyles.AllPaintingInWmPaint |
         ControlStyles.ResizeRedraw, true);
       this.UpdateStyles();
 
+      CreateContextMenu();
+
       centerlower = new StringFormat();
       centerlower.Alignment = StringAlignment.Center;
       centerlower.LineAlignment = StringAlignment.Near;
@@ -81,6 +89,34 @@
       lightPen = new Pen(Color.FromArgb(200, 200, 200));
     }
 
+    private void CreateContextMenu() {
+      MenuItem timeWindow = new MenuItem("Time Scale");
+      
+      MenuItem[] timeWindowMenuItems = 
+        { new MenuItem("Auto"), 
+          new MenuItem("5 min"),
+          new MenuItem("10 min"),
+          new MenuItem("20 min"),
+          new MenuItem("30 min"),
+          new MenuItem("45 min"),
+          new MenuItem("1 h"),
+          new MenuItem("1.5 h"),
+          new MenuItem("2 h"),
+          new MenuItem("3 h"),
+          new MenuItem("6 h"),
+          new MenuItem("12 h"),
+          new MenuItem("24 h") };
+
+      foreach (MenuItem mi in timeWindowMenuItems)
+        timeWindow.MenuItems.Add(mi);
+
+      timeWindowRadioGroup = new UserRadioGroup("timeWindow", 0, 
+        timeWindowMenuItems, settings);
+
+      this.ContextMenu = new ContextMenu();
+      this.ContextMenu.MenuItems.Add(timeWindow);
+    }
+
     private List<float> GetTemperatureGrid() {
 
       float? minTempNullable = null;
@@ -125,26 +161,34 @@
 
     private List<float> GetTimeGrid() {
 
-      float maxTime = 5;
-      if (temperatures.Count > 0) {
-        IEnumerator<SensorValue> enumerator =
-          temperatures[0].Values.GetEnumerator();
-        if (enumerator.MoveNext()) {
-          maxTime = (float)(now - enumerator.Current.Time).TotalMinutes;
+      float maxTime;
+      if (timeWindowRadioGroup.Value == 0) { // Auto
+        maxTime = 5;
+        if (temperatures.Count > 0) {
+          IEnumerator<SensorValue> enumerator =
+            temperatures[0].Values.GetEnumerator();
+          if (enumerator.MoveNext()) {
+            maxTime = (float)(now - enumerator.Current.Time).TotalMinutes;
+          }
         }
+      } else {
+        float[] maxTimes = 
+          { 5, 10, 20, 30, 45, 60, 90, 120, 180, 360, 720, 1440 };
+
+        maxTime = maxTimes[timeWindowRadioGroup.Value - 1];
       }
 
       int countTime = 10;
       float deltaTime = 5;
-      while (deltaTime + 1 < maxTime && deltaTime < 10)
+      while (deltaTime + 1 <= maxTime && deltaTime < 10)
         deltaTime += 1;
-      while (deltaTime + 2 < maxTime && deltaTime < 30)
+      while (deltaTime + 2 <= maxTime && deltaTime < 30)
         deltaTime += 2;
-      while (deltaTime + 5 < maxTime && deltaTime < 100)
+      while (deltaTime + 5 <= maxTime && deltaTime < 100)
         deltaTime += 5;
-      while (deltaTime + 50 < maxTime && deltaTime < 1000)
+      while (deltaTime + 50 <= maxTime && deltaTime < 1000)
         deltaTime += 50;
-      while (deltaTime + 100 < maxTime && deltaTime < 10000)
+      while (deltaTime + 100 <= maxTime && deltaTime < 10000)
         deltaTime += 100;
 
       List<float> grid = new List<float>(countTime + 1);