Add theme and plot thickness options (#847)
* Add theme and plot thickness options * Cleanup * Fixed themes, and made it so the plot colors are updated when the theme is changed * I think supporting themes beyond dark, light, and black is unecessary for the time being. * recall theme from settings before instantiating plot * Check for null setting * committing to merge * Fix * Cleanup * Cleanup * Fix from comments. Thank you kamkie! * Fixing last UI bugs * Fix windowed plot not theming on relaunch, change theme, show plot
This commit is contained in:
@@ -16,6 +16,7 @@ using OxyPlot.Annotations;
|
||||
using OxyPlot.Axes;
|
||||
using OxyPlot.WindowsForms;
|
||||
using OxyPlot.Series;
|
||||
using LibreHardwareMonitor.UI.Themes;
|
||||
|
||||
namespace LibreHardwareMonitor.UI;
|
||||
|
||||
@@ -48,7 +49,7 @@ public class PlotPanel : UserControl
|
||||
SetDpi();
|
||||
_model = CreatePlotModel();
|
||||
|
||||
_plot = new PlotView { Dock = DockStyle.Fill, Model = _model, BackColor = Color.White, ContextMenuStrip = CreateMenu() };
|
||||
_plot = new PlotView { Dock = DockStyle.Fill, Model = _model, BackColor = Color.Black, ContextMenuStrip = CreateMenu() };
|
||||
_plot.MouseDown += (sender, e) =>
|
||||
{
|
||||
if (e.Button == MouseButtons.Right)
|
||||
@@ -72,6 +73,34 @@ public class PlotPanel : UserControl
|
||||
SuspendLayout();
|
||||
Controls.Add(_plot);
|
||||
ResumeLayout(true);
|
||||
_plot.ShowTracker(new TrackerHitResult());
|
||||
_plot.HideTracker();
|
||||
foreach (Control plotControl in _plot.Controls)
|
||||
{
|
||||
plotControl.BackColor = Theme.Current.PlotBackgroundColor;
|
||||
plotControl.ForeColor = Theme.Current.PlotTextColor;
|
||||
}
|
||||
ApplyTheme();
|
||||
}
|
||||
|
||||
public void ApplyTheme()
|
||||
{
|
||||
_model.Background = Theme.Current.PlotBackgroundColor.ToOxyColor();
|
||||
_model.PlotAreaBorderColor = Theme.Current.PlotBorderColor.ToOxyColor();
|
||||
foreach (Axis axis in _model.Axes)
|
||||
{
|
||||
axis.AxislineColor = Theme.Current.PlotBorderColor.ToOxyColor();
|
||||
axis.MajorGridlineColor = Theme.Current.PlotGridMajorColor.ToOxyColor();
|
||||
axis.MinorGridlineColor = Theme.Current.PlotGridMinorColor.ToOxyColor();
|
||||
axis.TextColor = Theme.Current.PlotTextColor.ToOxyColor();
|
||||
axis.TitleColor = Theme.Current.PlotTextColor.ToOxyColor();
|
||||
axis.MinorTicklineColor = Theme.Current.PlotBorderColor.ToOxyColor();
|
||||
axis.TicklineColor = Theme.Current.PlotBorderColor.ToOxyColor();
|
||||
}
|
||||
foreach (LineAnnotation annotation in _model.Annotations.Select(x => x as LineAnnotation).Where(x => x != null))
|
||||
{
|
||||
annotation.Color = Theme.Current.PlotBorderColor.ToOxyColor();
|
||||
}
|
||||
}
|
||||
|
||||
public void SetCurrentSettings()
|
||||
@@ -88,6 +117,7 @@ public class PlotPanel : UserControl
|
||||
private ContextMenuStrip CreateMenu()
|
||||
{
|
||||
ContextMenuStrip menu = new ContextMenuStrip();
|
||||
menu.Renderer = new ThemedToolStripRenderer();
|
||||
menu.Opening += (sender, e) =>
|
||||
{
|
||||
if (_cancelContextMenu)
|
||||
@@ -227,7 +257,7 @@ public class PlotPanel : UserControl
|
||||
ClipByXAxis = false,
|
||||
ClipByYAxis = false,
|
||||
LineStyle = LineStyle.Solid,
|
||||
Color = OxyColors.Black,
|
||||
Color = Theme.Current.PlotBorderColor.ToOxyColor(),
|
||||
YAxisKey = typeName,
|
||||
StrokeThickness = 2,
|
||||
};
|
||||
@@ -275,7 +305,7 @@ public class PlotPanel : UserControl
|
||||
_dpiYScale = _dpiY / defaultDpi;
|
||||
}
|
||||
|
||||
public void SetSensors(List<ISensor> sensors, IDictionary<ISensor, Color> colors)
|
||||
public void SetSensors(List<ISensor> sensors, IDictionary<ISensor, Color> colors, double strokeThickness)
|
||||
{
|
||||
_model.Series.Clear();
|
||||
var types = new HashSet<SensorType>();
|
||||
@@ -304,7 +334,7 @@ public class PlotPanel : UserControl
|
||||
{
|
||||
ItemsSource = sensor.Values.Select(value => CreateDataPoint(sensor.SensorType, value)),
|
||||
Color = colors[sensor].ToOxyColor(),
|
||||
StrokeThickness = 1,
|
||||
StrokeThickness = strokeThickness,
|
||||
YAxisKey = _axes[sensor.SensorType].Key,
|
||||
Title = sensor.Hardware.Name + " " + sensor.Name
|
||||
};
|
||||
@@ -325,6 +355,15 @@ public class PlotPanel : UserControl
|
||||
InvalidatePlot();
|
||||
}
|
||||
|
||||
public void UpdateStrokeThickness(double strokeThickness)
|
||||
{
|
||||
foreach (LineSeries series in _model.Series)
|
||||
{
|
||||
series.StrokeThickness = strokeThickness;
|
||||
}
|
||||
InvalidatePlot();
|
||||
}
|
||||
|
||||
private void UpdateAxesPosition()
|
||||
{
|
||||
if (_stackedAxes.Value)
|
||||
|
||||
Reference in New Issue
Block a user