From aa298de600e55f601611f366e9dd0bffbbd3ae7c Mon Sep 17 00:00:00 2001 From: JoeBroesele <56547187+JoeBroesele@users.noreply.github.com> Date: Sun, 27 Oct 2019 10:23:13 +0100 Subject: [PATCH] New features added to plot window. (#163) * New features added to plot window. In the context menu of the plot there are new options to select: * Show/hide the axes labels. * Enable/disable zooming of the time axis. * Enable/disable zooming of the value axes (y-axes). * Autoscale all value axes (y-axes). --- LibreHardwareMonitor/UI/PlotPanel.cs | 93 ++++++++++++++++++++++------ 1 file changed, 73 insertions(+), 20 deletions(-) diff --git a/LibreHardwareMonitor/UI/PlotPanel.cs b/LibreHardwareMonitor/UI/PlotPanel.cs index 6b6459c..5c1c6e0 100644 --- a/LibreHardwareMonitor/UI/PlotPanel.cs +++ b/LibreHardwareMonitor/UI/PlotPanel.cs @@ -26,6 +26,9 @@ namespace LibreHardwareMonitor.UI private readonly TimeSpanAxis _timeAxis = new TimeSpanAxis(); private readonly SortedDictionary _axes = new SortedDictionary(); private UserOption _stackedAxes; + private UserOption _showAxesLabels; + private UserOption _timeAxisEnableZoom; + private UserOption _yAxesEnableZoom; private DateTime _now; private float _dpiX; private float _dpiY; @@ -73,24 +76,60 @@ namespace LibreHardwareMonitor.UI }; menu.MenuItems.Add(stackedAxesMenuItem); - MenuItem timeWindow = new MenuItem("Time Window"); - MenuItem[] timeWindowMenuItems = - { new MenuItem("Auto", (s, e) => { _timeAxis.Zoom(0, double.NaN); InvalidatePlot(); }), - new MenuItem("5 min", (s, e) => { _timeAxis.Zoom(0, 5 * 60); InvalidatePlot(); }), - new MenuItem("10 min", (s, e) => { _timeAxis.Zoom(0, 10 * 60); InvalidatePlot(); }), - new MenuItem("20 min", (s, e) => { _timeAxis.Zoom(0, 20 * 60); InvalidatePlot(); }), - new MenuItem("30 min", (s, e) => { _timeAxis.Zoom(0, 30 * 60); InvalidatePlot(); }), - new MenuItem("45 min", (s, e) => { _timeAxis.Zoom(0, 45 * 60); InvalidatePlot(); }), - new MenuItem("1 h", (s, e) => { _timeAxis.Zoom(0, 60 * 60); InvalidatePlot(); }), - new MenuItem("1.5 h", (s, e) => { _timeAxis.Zoom(0, 1.5 * 60 * 60); InvalidatePlot(); }), - new MenuItem("2 h", (s, e) => { _timeAxis.Zoom(0, 2 * 60 * 60); InvalidatePlot(); }), - new MenuItem("3 h", (s, e) => { _timeAxis.Zoom(0, 3 * 60 * 60); InvalidatePlot(); }), - new MenuItem("6 h", (s, e) => { _timeAxis.Zoom(0, 6 * 60 * 60); InvalidatePlot(); }), - new MenuItem("12 h", (s, e) => { _timeAxis.Zoom(0, 12 * 60 * 60); InvalidatePlot(); }), - new MenuItem("24 h", (s, e) => { _timeAxis.Zoom(0, 24 * 60 * 60); InvalidatePlot(); }) }; - foreach (MenuItem mi in timeWindowMenuItems) - timeWindow.MenuItems.Add(mi); - menu.MenuItems.Add(timeWindow); + MenuItem showAxesLabelsMenuItem = new MenuItem("Show Axes Labels"); + _showAxesLabels = new UserOption("showAxesLabels", true, showAxesLabelsMenuItem, _settings); + _showAxesLabels.Changed += (sender, e) => + { + if (_showAxesLabels.Value) + _model.PlotMargins = new OxyThickness(double.NaN); + else + _model.PlotMargins = new OxyThickness(0); + }; + menu.MenuItems.Add(showAxesLabelsMenuItem); + + MenuItem timeAxisMenuItem = new MenuItem("Time Axis"); + MenuItem[] timeAxisMenuItems = + { new MenuItem("Enable Zoom"), + new MenuItem("Auto", (s, e) => { TimeAxisZoom(0, double.NaN); }), + new MenuItem("5 min", (s, e) => { TimeAxisZoom(0, 5 * 60); }), + new MenuItem("10 min", (s, e) => { TimeAxisZoom(0, 10 * 60); }), + new MenuItem("20 min", (s, e) => { TimeAxisZoom(0, 20 * 60); }), + new MenuItem("30 min", (s, e) => { TimeAxisZoom(0, 30 * 60); }), + new MenuItem("45 min", (s, e) => { TimeAxisZoom(0, 45 * 60); }), + new MenuItem("1 h", (s, e) => { TimeAxisZoom(0, 60 * 60); }), + new MenuItem("1.5 h", (s, e) => { TimeAxisZoom(0, 1.5 * 60 * 60); }), + new MenuItem("2 h", (s, e) => { TimeAxisZoom(0, 2 * 60 * 60); }), + new MenuItem("3 h", (s, e) => { TimeAxisZoom(0, 3 * 60 * 60); }), + new MenuItem("6 h", (s, e) => { TimeAxisZoom(0, 6 * 60 * 60); }), + new MenuItem("12 h", (s, e) => { TimeAxisZoom(0, 12 * 60 * 60); }), + new MenuItem("24 h", (s, e) => { TimeAxisZoom(0, 24 * 60 * 60); }) }; + + foreach (MenuItem mi in timeAxisMenuItems) + timeAxisMenuItem.MenuItems.Add(mi); + menu.MenuItems.Add(timeAxisMenuItem); + + _timeAxisEnableZoom = new UserOption("timeAxisEnableZoom", true, timeAxisMenuItems[0], _settings); + _timeAxisEnableZoom.Changed += (sender, e) => + { + _timeAxis.IsZoomEnabled = _timeAxisEnableZoom.Value; + }; + + MenuItem yAxesMenuItem = new MenuItem("Value Axes"); + MenuItem[] yAxesMenuItems = + { new MenuItem("Enable Zoom"), + new MenuItem("Autoscale All", (s, e) => { AutoscaleAllYAxes(); }) }; + + foreach (MenuItem mi in yAxesMenuItems) + yAxesMenuItem.MenuItems.Add(mi); + menu.MenuItems.Add(yAxesMenuItem); + + _yAxesEnableZoom = new UserOption("yAxesEnableZoom", true, yAxesMenuItems[0], _settings); + _yAxesEnableZoom.Changed += (sender, e) => + { + foreach (LinearAxis axis in _axes.Values) + axis.IsZoomEnabled = _yAxesEnableZoom.Value; + }; + return menu; } @@ -158,7 +197,6 @@ namespace LibreHardwareMonitor.UI model.Axes.Add(_timeAxis); foreach (LinearAxis axis in _axes.Values) model.Axes.Add(axis); - model.PlotMargins = new OxyThickness(0); model.IsLegendVisible = false; return model; @@ -275,7 +313,6 @@ namespace LibreHardwareMonitor.UI axis.MinorGridlineStyle = LineStyle.None; } } - } public void InvalidatePlot() @@ -295,5 +332,21 @@ namespace LibreHardwareMonitor.UI _plot?.InvalidatePlot(true); } + + public void TimeAxisZoom(double min, double max) + { + bool timeAxisIsZoomEnabled = _timeAxis.IsZoomEnabled; + + _timeAxis.IsZoomEnabled = true; + _timeAxis.Zoom(min, max); + InvalidatePlot(); + _timeAxis.IsZoomEnabled = timeAxisIsZoomEnabled; + } + + public void AutoscaleAllYAxes() + { + foreach (LinearAxis axis in _axes.Values) + axis.Zoom(double.NaN, double.NaN); + } } }