Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization/DynamicDataDisplay/DependentPlotter.cs @ 13467

Last change on this file since 13467 was 12503, checked in by aballeit, 9 years ago

#2283 added GUI and charts; fixed MCTS

File size: 2.7 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Diagnostics;
6
7namespace Microsoft.Research.DynamicDataDisplay
8{
9  /// <summary>
10  /// Represents a special embedded kind of plotter.
11  /// Follows an outer's plotter Visible change when this is general panning or zooming via MouseNavigation.
12  /// Does not reacts on panning or zooming only in one direction (via AxisNavigation or KeyboardNavigation.
13  /// </summary>
14  public class DependentPlotter : InjectedPlotterBase
15  {
16    /// <summary>
17    /// Initializes a new instance of the <see cref="DependentPlotter"/> class.
18    /// </summary>
19    public DependentPlotter() : base() { }
20
21    protected override DataRect CoerceVisible(DataRect newVisible, DataRect baseVisible)
22    {
23      return baseVisible;
24    }
25
26    private bool IsHandledChangeType(ChangeType changeType)
27    {
28      bool handled = false;
29      switch (changeType)
30      {
31        case ChangeType.Pan:
32        case ChangeType.Zoom:
33          handled = true;
34          break;
35        case ChangeType.PanX:
36        case ChangeType.ZoomX:
37          handled = (ConjunctionMode == ViewportConjunctionMode.X) || (ConjunctionMode == ViewportConjunctionMode.XY);
38          break;
39        case ChangeType.PanY:
40        case ChangeType.ZoomY:
41          handled = (ConjunctionMode == ViewportConjunctionMode.Y) || (ConjunctionMode == ViewportConjunctionMode.XY);
42          break;
43      }
44      return handled;
45    }
46
47    protected override void OuterViewport_PropertyChanged(ExtendedPropertyChangedEventArgs e)
48    {
49      if(e.PropertyName != Viewport2D.VisiblePropertyName)
50        return;
51
52      if (IsHandledChangeType(e.ChangeType))
53      {
54        DataRect newRect = (DataRect)e.NewValue;
55        DataRect oldRect = (DataRect)e.OldValue;
56
57        double ratioX = newRect.Width / oldRect.Width;
58        double ratioY = newRect.Height / oldRect.Height;
59        double shiftX = (newRect.XMin - oldRect.XMin) / oldRect.Width;
60        double shiftY = (newRect.YMin - oldRect.YMin) / oldRect.Height;
61
62        DataRect visible = Viewport.Visible;
63
64        visible.XMin += shiftX * visible.Width;
65        visible.YMin += shiftY * visible.Height;
66        visible.Width *= ratioX;
67        visible.Height *= ratioY;
68
69        Viewport.Visible = visible;
70      }
71    }
72
73    public override void OnPlotterAttached(Plotter plotter)
74    {
75      base.OnPlotterAttached(plotter);
76
77      Plotter.Viewport.FittedToView += Viewport_FittedToView;
78    }
79
80    public override void OnPlotterDetaching(Plotter plotter)
81    {
82      Plotter.Viewport.FittedToView -= Viewport_FittedToView;
83
84      base.OnPlotterDetaching(plotter);
85    }
86
87    private void Viewport_FittedToView(object sender, EventArgs e)
88    {
89      FitToView();
90    }
91
92    protected override void OnConjunctionModeChanged()
93    {
94      // do nothing
95    }
96  }
97}
Note: See TracBrowser for help on using the repository browser.