Added a context menu to the plot which allows the user to configure the time window for plotting.
authormoel.mich
Sun, 01 Jan 2012 15:46:42 +0000
changeset 326a41745e3828d
parent 325 4c31341a4800
child 327 e837e1e4b282
Added a context menu to the plot which allows the user to configure the time window for plotting.
GUI/MainForm.Designer.cs
GUI/MainForm.cs
GUI/PlotPanel.cs
     1.1 --- a/GUI/MainForm.Designer.cs	Sun Jan 01 10:14:42 2012 +0000
     1.2 +++ b/GUI/MainForm.Designer.cs	Sun Jan 01 15:46:42 2012 +0000
     1.3 @@ -108,8 +108,7 @@
     1.4        this.saveFileDialog = new System.Windows.Forms.SaveFileDialog();
     1.5        this.timer = new System.Windows.Forms.Timer(this.components);
     1.6        this.splitContainer = new OpenHardwareMonitor.GUI.SplitContainerAdv();
     1.7 -      this.treeView = new Aga.Controls.Tree.TreeViewAdv();
     1.8 -      this.plotPanel = new OpenHardwareMonitor.GUI.PlotPanel();
     1.9 +      this.treeView = new Aga.Controls.Tree.TreeViewAdv();      
    1.10        this.plotLocationMenuItem = new System.Windows.Forms.MenuItem();
    1.11        this.plotWindowMenuItem = new System.Windows.Forms.MenuItem();
    1.12        this.plotBottomMenuItem = new System.Windows.Forms.MenuItem();
    1.13 @@ -431,7 +430,6 @@
    1.14        // 
    1.15        // splitContainer.Panel2
    1.16        // 
    1.17 -      this.splitContainer.Panel2.Controls.Add(this.plotPanel);
    1.18        this.splitContainer.Panel2.Cursor = System.Windows.Forms.Cursors.Default;
    1.19        this.splitContainer.Size = new System.Drawing.Size(386, 483);
    1.20        this.splitContainer.SplitterDistance = 354;
    1.21 @@ -472,14 +470,6 @@
    1.22        this.treeView.MouseMove += new System.Windows.Forms.MouseEventHandler(this.treeView_MouseMove);
    1.23        this.treeView.MouseUp += new System.Windows.Forms.MouseEventHandler(this.treeView_MouseUp);
    1.24        // 
    1.25 -      // plotPanel
    1.26 -      // 
    1.27 -      this.plotPanel.Dock = System.Windows.Forms.DockStyle.Fill;
    1.28 -      this.plotPanel.Location = new System.Drawing.Point(0, 0);
    1.29 -      this.plotPanel.Name = "plotPanel";
    1.30 -      this.plotPanel.Size = new System.Drawing.Size(386, 124);
    1.31 -      this.plotPanel.TabIndex = 0;
    1.32 -      // 
    1.33        // plotLocationMenuItem
    1.34        // 
    1.35        this.plotLocationMenuItem.Index = 6;
    1.36 @@ -542,7 +532,6 @@
    1.37      private Aga.Controls.Tree.NodeControls.NodeTextBox nodeTextBoxMin;
    1.38      private Aga.Controls.Tree.NodeControls.NodeTextBox nodeTextBoxMax;
    1.39      private SplitContainerAdv splitContainer;
    1.40 -    private PlotPanel plotPanel;
    1.41      private System.Windows.Forms.MenuItem viewMenuItem;
    1.42      private System.Windows.Forms.MenuItem plotMenuItem;
    1.43      private Aga.Controls.Tree.NodeControls.NodeCheckBox nodeCheckBox;
     2.1 --- a/GUI/MainForm.cs	Sun Jan 01 10:14:42 2012 +0000
     2.2 +++ b/GUI/MainForm.cs	Sun Jan 01 15:46:42 2012 +0000
     2.3 @@ -63,6 +63,7 @@
     2.4      private UpdateVisitor updateVisitor = new UpdateVisitor();
     2.5      private SensorGadget gadget;
     2.6      private Form plotForm;
     2.7 +    private PlotPanel plotPanel;
     2.8  
     2.9      private UserOption showHiddenSensors;
    2.10      private UserOption showPlot;
    2.11 @@ -109,7 +110,10 @@
    2.12              
    2.13        this.Font = SystemFonts.MessageBoxFont;
    2.14        treeView.Font = SystemFonts.MessageBoxFont;
    2.15 -      plotPanel.Font = SystemFonts.MessageBoxFont;           
    2.16 +
    2.17 +      plotPanel = new PlotPanel(settings);
    2.18 +      plotPanel.Font = SystemFonts.MessageBoxFont;
    2.19 +      plotPanel.Dock = DockStyle.Fill;
    2.20        
    2.21        nodeCheckBox.IsVisibleValueNeeded += nodeCheckBox_IsVisibleValueNeeded;
    2.22        nodeCheckBox.CheckStateChanged += UpdatePlotSelection;
     3.1 --- a/GUI/PlotPanel.cs	Sun Jan 01 10:14:42 2012 +0000
     3.2 +++ b/GUI/PlotPanel.cs	Sun Jan 01 15:46:42 2012 +0000
     3.3 @@ -46,6 +46,8 @@
     3.4  namespace OpenHardwareMonitor.GUI {
     3.5    public class PlotPanel : UserControl {
     3.6  
     3.7 +    private PersistentSettings settings;
     3.8 +
     3.9      private DateTime now;
    3.10      private List<ISensor> clocks = new List<ISensor>();
    3.11      private List<ISensor> temperatures = new List<ISensor>();
    3.12 @@ -58,13 +60,19 @@
    3.13      private Brush lightBrush;
    3.14      private Pen lightPen;
    3.15  
    3.16 -    public PlotPanel() {
    3.17 +    private UserRadioGroup timeWindowRadioGroup;
    3.18 +
    3.19 +    public PlotPanel(PersistentSettings settings) {
    3.20 +      this.settings = settings;
    3.21 +
    3.22        this.SetStyle(ControlStyles.DoubleBuffer |
    3.23          ControlStyles.UserPaint |
    3.24          ControlStyles.AllPaintingInWmPaint |
    3.25          ControlStyles.ResizeRedraw, true);
    3.26        this.UpdateStyles();
    3.27  
    3.28 +      CreateContextMenu();
    3.29 +
    3.30        centerlower = new StringFormat();
    3.31        centerlower.Alignment = StringAlignment.Center;
    3.32        centerlower.LineAlignment = StringAlignment.Near;
    3.33 @@ -81,6 +89,34 @@
    3.34        lightPen = new Pen(Color.FromArgb(200, 200, 200));
    3.35      }
    3.36  
    3.37 +    private void CreateContextMenu() {
    3.38 +      MenuItem timeWindow = new MenuItem("Time Scale");
    3.39 +      
    3.40 +      MenuItem[] timeWindowMenuItems = 
    3.41 +        { new MenuItem("Auto"), 
    3.42 +          new MenuItem("5 min"),
    3.43 +          new MenuItem("10 min"),
    3.44 +          new MenuItem("20 min"),
    3.45 +          new MenuItem("30 min"),
    3.46 +          new MenuItem("45 min"),
    3.47 +          new MenuItem("1 h"),
    3.48 +          new MenuItem("1.5 h"),
    3.49 +          new MenuItem("2 h"),
    3.50 +          new MenuItem("3 h"),
    3.51 +          new MenuItem("6 h"),
    3.52 +          new MenuItem("12 h"),
    3.53 +          new MenuItem("24 h") };
    3.54 +
    3.55 +      foreach (MenuItem mi in timeWindowMenuItems)
    3.56 +        timeWindow.MenuItems.Add(mi);
    3.57 +
    3.58 +      timeWindowRadioGroup = new UserRadioGroup("timeWindow", 0, 
    3.59 +        timeWindowMenuItems, settings);
    3.60 +
    3.61 +      this.ContextMenu = new ContextMenu();
    3.62 +      this.ContextMenu.MenuItems.Add(timeWindow);
    3.63 +    }
    3.64 +
    3.65      private List<float> GetTemperatureGrid() {
    3.66  
    3.67        float? minTempNullable = null;
    3.68 @@ -125,26 +161,34 @@
    3.69  
    3.70      private List<float> GetTimeGrid() {
    3.71  
    3.72 -      float maxTime = 5;
    3.73 -      if (temperatures.Count > 0) {
    3.74 -        IEnumerator<SensorValue> enumerator =
    3.75 -          temperatures[0].Values.GetEnumerator();
    3.76 -        if (enumerator.MoveNext()) {
    3.77 -          maxTime = (float)(now - enumerator.Current.Time).TotalMinutes;
    3.78 +      float maxTime;
    3.79 +      if (timeWindowRadioGroup.Value == 0) { // Auto
    3.80 +        maxTime = 5;
    3.81 +        if (temperatures.Count > 0) {
    3.82 +          IEnumerator<SensorValue> enumerator =
    3.83 +            temperatures[0].Values.GetEnumerator();
    3.84 +          if (enumerator.MoveNext()) {
    3.85 +            maxTime = (float)(now - enumerator.Current.Time).TotalMinutes;
    3.86 +          }
    3.87          }
    3.88 +      } else {
    3.89 +        float[] maxTimes = 
    3.90 +          { 5, 10, 20, 30, 45, 60, 90, 120, 180, 360, 720, 1440 };
    3.91 +
    3.92 +        maxTime = maxTimes[timeWindowRadioGroup.Value - 1];
    3.93        }
    3.94  
    3.95        int countTime = 10;
    3.96        float deltaTime = 5;
    3.97 -      while (deltaTime + 1 < maxTime && deltaTime < 10)
    3.98 +      while (deltaTime + 1 <= maxTime && deltaTime < 10)
    3.99          deltaTime += 1;
   3.100 -      while (deltaTime + 2 < maxTime && deltaTime < 30)
   3.101 +      while (deltaTime + 2 <= maxTime && deltaTime < 30)
   3.102          deltaTime += 2;
   3.103 -      while (deltaTime + 5 < maxTime && deltaTime < 100)
   3.104 +      while (deltaTime + 5 <= maxTime && deltaTime < 100)
   3.105          deltaTime += 5;
   3.106 -      while (deltaTime + 50 < maxTime && deltaTime < 1000)
   3.107 +      while (deltaTime + 50 <= maxTime && deltaTime < 1000)
   3.108          deltaTime += 50;
   3.109 -      while (deltaTime + 100 < maxTime && deltaTime < 10000)
   3.110 +      while (deltaTime + 100 <= maxTime && deltaTime < 10000)
   3.111          deltaTime += 100;
   3.112  
   3.113        List<float> grid = new List<float>(countTime + 1);