Added an option to disable stacked axes in the plot.

This commit is contained in:
Michael Möller
2013-06-09 16:44:19 +00:00
parent e72ae00be8
commit a9ae1a293f

View File

@@ -31,6 +31,8 @@ namespace OpenHardwareMonitor.GUI {
private readonly SortedDictionary<SensorType, LinearAxis> axes = private readonly SortedDictionary<SensorType, LinearAxis> axes =
new SortedDictionary<SensorType, LinearAxis>(); new SortedDictionary<SensorType, LinearAxis>();
private UserOption stackedAxes;
private DateTime now; private DateTime now;
public PlotPanel(PersistentSettings settings) { public PlotPanel(PersistentSettings settings) {
@@ -41,8 +43,9 @@ namespace OpenHardwareMonitor.GUI {
this.plot.Dock = DockStyle.Fill; this.plot.Dock = DockStyle.Fill;
this.plot.Model = model; this.plot.Model = model;
this.plot.BackColor = Color.White; this.plot.BackColor = Color.White;
this.plot.ContextMenu = new ContextMenu(); this.plot.ContextMenu = CreateMenu();
this.plot.ContextMenu.MenuItems.Add(CreateMenu());
UpdateAxesPosition();
this.SuspendLayout(); this.SuspendLayout();
this.Controls.Add(plot); this.Controls.Add(plot);
@@ -59,9 +62,19 @@ namespace OpenHardwareMonitor.GUI {
} }
} }
private MenuItem CreateMenu() { private ContextMenu CreateMenu() {
MenuItem timeWindow = new MenuItem("Time Window"); ContextMenu menu = new ContextMenu();
MenuItem stackedAxesMenuItem = new MenuItem("Stacked Axes");
stackedAxes = new UserOption("stackedAxes", true,
stackedAxesMenuItem, settings);
stackedAxes.Changed += (sender, e) => {
UpdateAxesPosition();
InvalidatePlot();
};
menu.MenuItems.Add(stackedAxesMenuItem);
MenuItem timeWindow = new MenuItem("Time Window");
MenuItem[] timeWindowMenuItems = MenuItem[] timeWindowMenuItems =
{ new MenuItem("Auto", { new MenuItem("Auto",
(s, e) => { timeAxis.Zoom(0, double.NaN); InvalidatePlot(); }), (s, e) => { timeAxis.Zoom(0, double.NaN); InvalidatePlot(); }),
@@ -89,11 +102,11 @@ namespace OpenHardwareMonitor.GUI {
(s, e) => { timeAxis.Zoom(0, 12 * 60 * 60); InvalidatePlot(); }), (s, e) => { timeAxis.Zoom(0, 12 * 60 * 60); InvalidatePlot(); }),
new MenuItem("24 h", new MenuItem("24 h",
(s, e) => { timeAxis.Zoom(0, 24 * 60 * 60); InvalidatePlot(); }) }; (s, e) => { timeAxis.Zoom(0, 24 * 60 * 60); InvalidatePlot(); }) };
foreach (MenuItem mi in timeWindowMenuItems) foreach (MenuItem mi in timeWindowMenuItems)
timeWindow.MenuItems.Add(mi); timeWindow.MenuItems.Add(mi);
menu.MenuItems.Add(timeWindow);
return timeWindow; return menu;
} }
private PlotModel CreatePlotModel() { private PlotModel CreatePlotModel() {
@@ -139,6 +152,7 @@ namespace OpenHardwareMonitor.GUI {
axis.MinorGridlineStyle = LineStyle.Solid; axis.MinorGridlineStyle = LineStyle.Solid;
axis.MinorGridlineThickness = 1; axis.MinorGridlineThickness = 1;
axis.MinorGridlineColor = timeAxis.MinorGridlineColor; axis.MinorGridlineColor = timeAxis.MinorGridlineColor;
axis.AxislineStyle = LineStyle.Solid;
axis.Title = type.ToString(); axis.Title = type.ToString();
axis.Key = type.ToString(); axis.Key = type.ToString();
@@ -181,20 +195,47 @@ namespace OpenHardwareMonitor.GUI {
types.Add(sensor.SensorType); types.Add(sensor.SensorType);
} }
var start = 0.0;
foreach (var pair in axes.Reverse()) { foreach (var pair in axes.Reverse()) {
var axis = pair.Value; var axis = pair.Value;
var type = pair.Key; var type = pair.Key;
axis.StartPosition = start; axis.IsAxisVisible = types.Contains(type);
axis.IsAxisVisible = types.Contains(type); }
var delta = axis.IsAxisVisible ? 1.0 / types.Count : 0;
start += delta;
axis.EndPosition = start;
}
UpdateAxesPosition();
InvalidatePlot(); InvalidatePlot();
} }
private void UpdateAxesPosition() {
if (stackedAxes.Value) {
var count = axes.Values.Count(axis => axis.IsAxisVisible);
var start = 0.0;
foreach (var pair in axes.Reverse()) {
var axis = pair.Value;
var type = pair.Key;
axis.StartPosition = start;
var delta = axis.IsAxisVisible ? 1.0 / count : 0;
start += delta;
axis.EndPosition = start;
axis.PositionTier = 0;
axis.MajorGridlineStyle = LineStyle.Solid;
axis.MinorGridlineStyle = LineStyle.Solid;
}
} else {
var tier = 0;
foreach (var pair in axes.Reverse()) {
var axis = pair.Value;
var type = pair.Key;
axis.StartPosition = 0;
axis.EndPosition = 1;
axis.PositionTier = tier;
if (axis.IsAxisVisible)
tier++;
axis.MajorGridlineStyle = LineStyle.None;
axis.MinorGridlineStyle = LineStyle.None;
}
}
}
public void InvalidatePlot() { public void InvalidatePlot() {
this.now = DateTime.UtcNow; this.now = DateTime.UtcNow;
this.plot.InvalidatePlot(true); this.plot.InvalidatePlot(true);