GUI/PlotPanel.cs
changeset 400 f4e2e3e69651
parent 398 ac9b3b647906
     1.1 --- a/GUI/PlotPanel.cs	Sun Jun 09 17:17:32 2013 +0000
     1.2 +++ b/GUI/PlotPanel.cs	Sun Jun 09 17:44:05 2013 +0000
     1.3 @@ -23,7 +23,8 @@
     1.4  namespace OpenHardwareMonitor.GUI {
     1.5    public class PlotPanel : UserControl {
     1.6  
     1.7 -    private PersistentSettings settings;
     1.8 +    private readonly PersistentSettings settings;
     1.9 +    private readonly UnitManager unitManager;
    1.10  
    1.11      private readonly Plot plot;
    1.12      private readonly PlotModel model;
    1.13 @@ -35,8 +36,10 @@
    1.14  
    1.15      private DateTime now;
    1.16  
    1.17 -    public PlotPanel(PersistentSettings settings) {
    1.18 +    public PlotPanel(PersistentSettings settings, UnitManager unitManager) {
    1.19        this.settings = settings;
    1.20 +      this.unitManager = unitManager;
    1.21 +
    1.22        this.model = CreatePlotModel();
    1.23  
    1.24        this.plot = new Plot();
    1.25 @@ -183,9 +186,17 @@
    1.26  
    1.27        foreach (ISensor sensor in sensors) {
    1.28          var series = new LineSeries();
    1.29 -        series.ItemsSource = sensor.Values.Select(value => new DataPoint {
    1.30 -          X = (now - value.Time).TotalSeconds, Y = value.Value
    1.31 -        });
    1.32 +        if (sensor.SensorType == SensorType.Temperature) {
    1.33 +          series.ItemsSource = sensor.Values.Select(value => new DataPoint {
    1.34 +            X = (now - value.Time).TotalSeconds,
    1.35 +            Y = unitManager.TemperatureUnit == TemperatureUnit.Celsius ? 
    1.36 +              value.Value : UnitManager.CelsiusToFahrenheit(value.Value).Value
    1.37 +          });
    1.38 +        } else {
    1.39 +          series.ItemsSource = sensor.Values.Select(value => new DataPoint {
    1.40 +            X = (now - value.Time).TotalSeconds, Y = value.Value
    1.41 +          });
    1.42 +        }
    1.43          series.Color = colors[sensor].ToOxyColor();
    1.44          series.StrokeThickness = 1;
    1.45          series.YAxisKey = axes[sensor.SensorType].Key;
    1.46 @@ -198,7 +209,7 @@
    1.47        foreach (var pair in axes.Reverse()) {
    1.48          var axis = pair.Value;
    1.49          var type = pair.Key;
    1.50 -        axis.IsAxisVisible = types.Contains(type);     
    1.51 +        axis.IsAxisVisible = types.Contains(type);
    1.52        } 
    1.53  
    1.54        UpdateAxesPosition();
    1.55 @@ -225,11 +236,16 @@
    1.56          foreach (var pair in axes.Reverse()) {
    1.57            var axis = pair.Value;
    1.58            var type = pair.Key;
    1.59 -          axis.StartPosition = 0;
    1.60 -          axis.EndPosition = 1;
    1.61 -          axis.PositionTier = axis.IsAxisVisible ? tier : 0;
    1.62 -          if (axis.IsAxisVisible)
    1.63 +          if (axis.IsAxisVisible) {
    1.64 +            axis.StartPosition = 0;
    1.65 +            axis.EndPosition = 1;
    1.66 +            axis.PositionTier = tier;
    1.67              tier++;
    1.68 +          } else {
    1.69 +            axis.StartPosition = 0;
    1.70 +            axis.EndPosition = 0;
    1.71 +            axis.PositionTier = 0;
    1.72 +          }
    1.73            axis.MajorGridlineStyle = LineStyle.None;
    1.74            axis.MinorGridlineStyle = LineStyle.None;          
    1.75          }
    1.76 @@ -239,6 +255,15 @@
    1.77  
    1.78      public void InvalidatePlot() {
    1.79        this.now = DateTime.UtcNow;
    1.80 +
    1.81 +      foreach (var pair in axes) {
    1.82 +        var axis = pair.Value;
    1.83 +        var type = pair.Key;
    1.84 +        if (type == SensorType.Temperature)
    1.85 +          axis.Unit = unitManager.TemperatureUnit == TemperatureUnit.Celsius ?
    1.86 +          "°C" : "°F";
    1.87 +      }
    1.88 +
    1.89        this.plot.InvalidatePlot(true);
    1.90      }
    1.91