Added a context menu to the plot which allows the user to configure the time window for plotting.

This commit is contained in:
Michael Möller
2012-01-01 15:46:42 +00:00
parent a0b8e326eb
commit 0b184bb65e
3 changed files with 62 additions and 25 deletions

View File

@@ -108,8 +108,7 @@ namespace OpenHardwareMonitor.GUI {
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 @@ namespace OpenHardwareMonitor.GUI {
//
// 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 @@ namespace OpenHardwareMonitor.GUI {
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 @@ namespace OpenHardwareMonitor.GUI {
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;

View File

@@ -63,6 +63,7 @@ namespace OpenHardwareMonitor.GUI {
private UpdateVisitor updateVisitor = new UpdateVisitor();
private SensorGadget gadget;
private Form plotForm;
private PlotPanel plotPanel;
private UserOption showHiddenSensors;
private UserOption showPlot;
@@ -109,7 +110,10 @@ namespace OpenHardwareMonitor.GUI {
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;

View File

@@ -46,6 +46,8 @@ using OpenHardwareMonitor.Hardware;
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 @@ namespace OpenHardwareMonitor.GUI {
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 @@ namespace OpenHardwareMonitor.GUI {
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 @@ namespace OpenHardwareMonitor.GUI {
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);