GUI/PlotPanel.cs
changeset 397 243b6d5afa7c
parent 395 d1f25b504845
child 398 ac9b3b647906
     1.1 --- a/GUI/PlotPanel.cs	Sun Jun 09 16:10:43 2013 +0000
     1.2 +++ b/GUI/PlotPanel.cs	Sun Jun 09 16:44:19 2013 +0000
     1.3 @@ -31,6 +31,8 @@
     1.4      private readonly SortedDictionary<SensorType, LinearAxis> axes =
     1.5        new SortedDictionary<SensorType, LinearAxis>();
     1.6  
     1.7 +    private UserOption stackedAxes;
     1.8 +
     1.9      private DateTime now;
    1.10  
    1.11      public PlotPanel(PersistentSettings settings) {
    1.12 @@ -41,8 +43,9 @@
    1.13        this.plot.Dock = DockStyle.Fill;
    1.14        this.plot.Model = model;
    1.15        this.plot.BackColor = Color.White;
    1.16 -      this.plot.ContextMenu = new ContextMenu();
    1.17 -      this.plot.ContextMenu.MenuItems.Add(CreateMenu());
    1.18 +      this.plot.ContextMenu = CreateMenu();
    1.19 +
    1.20 +      UpdateAxesPosition();
    1.21  
    1.22        this.SuspendLayout();
    1.23        this.Controls.Add(plot);
    1.24 @@ -59,9 +62,19 @@
    1.25        }
    1.26      }
    1.27  
    1.28 -    private MenuItem CreateMenu() {
    1.29 +    private ContextMenu CreateMenu() {
    1.30 +      ContextMenu menu = new ContextMenu();
    1.31 +
    1.32 +      MenuItem stackedAxesMenuItem = new MenuItem("Stacked Axes");
    1.33 +      stackedAxes = new UserOption("stackedAxes", true,
    1.34 +        stackedAxesMenuItem, settings);
    1.35 +      stackedAxes.Changed += (sender, e) => {
    1.36 +        UpdateAxesPosition();
    1.37 +        InvalidatePlot();
    1.38 +      };
    1.39 +      menu.MenuItems.Add(stackedAxesMenuItem);
    1.40 +
    1.41        MenuItem timeWindow = new MenuItem("Time Window");
    1.42 -
    1.43        MenuItem[] timeWindowMenuItems =
    1.44          { new MenuItem("Auto", 
    1.45              (s, e) => { timeAxis.Zoom(0, double.NaN); InvalidatePlot(); }),
    1.46 @@ -89,11 +102,11 @@
    1.47              (s, e) => { timeAxis.Zoom(0, 12 * 60 * 60); InvalidatePlot(); }),
    1.48            new MenuItem("24 h", 
    1.49              (s, e) => { timeAxis.Zoom(0, 24 * 60 * 60); InvalidatePlot(); }) };
    1.50 -
    1.51        foreach (MenuItem mi in timeWindowMenuItems)
    1.52          timeWindow.MenuItems.Add(mi);
    1.53 +      menu.MenuItems.Add(timeWindow);
    1.54  
    1.55 -      return timeWindow;
    1.56 +      return menu;
    1.57      }
    1.58  
    1.59      private PlotModel CreatePlotModel() {
    1.60 @@ -139,6 +152,7 @@
    1.61          axis.MinorGridlineStyle = LineStyle.Solid;
    1.62          axis.MinorGridlineThickness = 1;
    1.63          axis.MinorGridlineColor = timeAxis.MinorGridlineColor;
    1.64 +        axis.AxislineStyle = LineStyle.Solid;
    1.65          axis.Title = type.ToString();
    1.66          axis.Key = type.ToString();
    1.67  
    1.68 @@ -181,18 +195,45 @@
    1.69          types.Add(sensor.SensorType);
    1.70        }
    1.71  
    1.72 -      var start = 0.0;
    1.73        foreach (var pair in axes.Reverse()) {
    1.74          var axis = pair.Value;
    1.75          var type = pair.Key;
    1.76 -        axis.StartPosition = start;
    1.77 -        axis.IsAxisVisible = types.Contains(type);
    1.78 -        var delta = axis.IsAxisVisible ? 1.0 / types.Count : 0;
    1.79 -        start += delta;
    1.80 -        axis.EndPosition = start;
    1.81 +        axis.IsAxisVisible = types.Contains(type);     
    1.82 +      } 
    1.83 +
    1.84 +      UpdateAxesPosition();
    1.85 +      InvalidatePlot();
    1.86 +    }
    1.87 +
    1.88 +    private void UpdateAxesPosition() {
    1.89 +      if (stackedAxes.Value) {
    1.90 +        var count = axes.Values.Count(axis => axis.IsAxisVisible);
    1.91 +        var start = 0.0;
    1.92 +        foreach (var pair in axes.Reverse()) {
    1.93 +          var axis = pair.Value;
    1.94 +          var type = pair.Key;
    1.95 +          axis.StartPosition = start;
    1.96 +          var delta = axis.IsAxisVisible ? 1.0 / count : 0;
    1.97 +          start += delta;
    1.98 +          axis.EndPosition = start;
    1.99 +          axis.PositionTier = 0;
   1.100 +          axis.MajorGridlineStyle = LineStyle.Solid;
   1.101 +          axis.MinorGridlineStyle = LineStyle.Solid;   
   1.102 +        }
   1.103 +      } else {
   1.104 +        var tier = 0;
   1.105 +        foreach (var pair in axes.Reverse()) {
   1.106 +          var axis = pair.Value;
   1.107 +          var type = pair.Key;
   1.108 +          axis.StartPosition = 0;
   1.109 +          axis.EndPosition = 1;
   1.110 +          axis.PositionTier = tier;
   1.111 +          if (axis.IsAxisVisible)
   1.112 +            tier++;
   1.113 +          axis.MajorGridlineStyle = LineStyle.None;
   1.114 +          axis.MinorGridlineStyle = LineStyle.None;          
   1.115 +        }
   1.116        }
   1.117 -
   1.118 -      InvalidatePlot();
   1.119      }
   1.120  
   1.121      public void InvalidatePlot() {