Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization/DynamicDataDisplay/InjectedPlotter.cs @ 13777

Last change on this file since 13777 was 12503, checked in by aballeit, 10 years ago

#2283 added GUI and charts; fixed MCTS

File size: 6.0 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Windows.Controls;
6using Microsoft.Research.DynamicDataDisplay.Common;
7using System.Windows.Data;
8using System.Windows;
9using System.Windows.Threading;
10using System.Windows.Media;
11using System.ComponentModel;
12
13namespace Microsoft.Research.DynamicDataDisplay
14{
15  /// <summary>
16  /// Represents a nested plotter, which can control the way how its children are drawn in dependency of parent ChartPlotter Visible rect.
17  /// This plotter is designed to work inside of some other plotter.
18  /// <remarks>
19  /// There are 8 properties (ParentXMin, SelfXMin, etc) which can be used to tune the size and position of inner plotter
20  /// in dependence on parent Plotter's Visible rect.
21  /// For example, you can specify that when parent x coordinates are from 0.0 to 1.0, inner plotter's visible x coordinates are
22  /// from -1.0 to 2.0. This data will be used to calculate next positions of inner plotter's children charts.
23  /// </remarks>
24  /// </summary>
25  [SkipPropertyCheck]
26  public class InjectedPlotter : InjectedPlotterBase, IPlotterElement
27  {
28    private double xScale = 1.0;
29    private double xShift = 0.0;
30    private double yScale = 1.0;
31    private double yShift = 0.0;
32
33    /// <summary>
34    /// Initializes a new instance of the <see cref="InjectedPlotter"/> class.
35    /// </summary>
36    public InjectedPlotter() : base() { }
37
38    protected override DataRect CoerceVisible(DataRect newVisible, DataRect baseVisible)
39    {
40      DataRect result = newVisible;
41
42      if (Plotter == null)
43        return baseVisible;
44
45      DataRect outerVisible = Plotter.Viewport.Visible;
46
47      double xMin = outerVisible.XMin * xScale + xShift;
48      double xMax = outerVisible.XMax * xScale + xShift;
49      double yMin = outerVisible.YMin * yScale + yShift;
50      double yMax = outerVisible.YMax * yScale + yShift;
51
52      outerVisible = DataRect.Create(xMin, yMin, xMax, yMax);
53
54      switch (ConjunctionMode)
55      {
56        case ViewportConjunctionMode.None:
57          result = baseVisible;
58          break;
59        case ViewportConjunctionMode.X:
60          result = new DataRect(outerVisible.XMin, baseVisible.YMin, outerVisible.Width, baseVisible.Height);
61          break;
62        case ViewportConjunctionMode.Y:
63          result = new DataRect(baseVisible.XMin, outerVisible.YMin, baseVisible.Width, outerVisible.Height);
64          break;
65        case ViewportConjunctionMode.XY:
66          result = outerVisible;
67          break;
68        default:
69          break;
70      }
71
72      return result;
73    }
74
75    private void UpdateTransform()
76    {
77      xScale = (SelfXMax - SelfXMin) / (ParentXMax - ParentXMin);
78      xShift = SelfXMin - ParentXMin;
79
80      yScale = (SelfYMax - SelfYMin) / (ParentYMax - ParentYMin);
81      yShift = SelfYMin - ParentYMin;
82    }
83
84    protected override void OnConjunctionModeChanged()
85    {
86      CoerceVisible();
87    }
88
89    #region Properties
90
91    #region Conversion properties
92
93    public double ParentXMin
94    {
95      get { return (double)GetValue(ParentXMinProperty); }
96      set { SetValue(ParentXMinProperty, value); }
97    }
98
99    public static readonly DependencyProperty ParentXMinProperty = DependencyProperty.Register(
100      "ParentXMin",
101      typeof(double),
102      typeof(InjectedPlotter),
103      new FrameworkPropertyMetadata(0.0, OnTransformChanged));
104
105    public double ParentXMax
106    {
107      get { return (double)GetValue(ParentXMaxProperty); }
108      set { SetValue(ParentXMaxProperty, value); }
109    }
110
111    public static readonly DependencyProperty ParentXMaxProperty = DependencyProperty.Register(
112      "ParentXMax",
113      typeof(double),
114      typeof(InjectedPlotter),
115      new FrameworkPropertyMetadata(1.0, OnTransformChanged));
116
117    public double SelfXMin
118    {
119      get { return (double)GetValue(SelfXMinProperty); }
120      set { SetValue(SelfXMinProperty, value); }
121    }
122
123    public static readonly DependencyProperty SelfXMinProperty = DependencyProperty.Register(
124      "SelfXMin",
125      typeof(double),
126      typeof(InjectedPlotter),
127      new FrameworkPropertyMetadata(0.0, OnTransformChanged));
128
129    public double SelfXMax
130    {
131      get { return (double)GetValue(SelfXMaxProperty); }
132      set { SetValue(SelfXMaxProperty, value); }
133    }
134
135    public static readonly DependencyProperty SelfXMaxProperty = DependencyProperty.Register(
136      "SelfXMax",
137      typeof(double),
138      typeof(InjectedPlotter),
139      new FrameworkPropertyMetadata(1.0, OnTransformChanged));
140
141    public double ParentYMin
142    {
143      get { return (double)GetValue(ParentYMinProperty); }
144      set { SetValue(ParentYMinProperty, value); }
145    }
146
147    public static readonly DependencyProperty ParentYMinProperty = DependencyProperty.Register(
148      "ParentYMin",
149      typeof(double),
150      typeof(InjectedPlotter),
151      new FrameworkPropertyMetadata(0.0, OnTransformChanged));
152
153    public double ParentYMax
154    {
155      get { return (double)GetValue(ParentYMaxProperty); }
156      set { SetValue(ParentYMaxProperty, value); }
157    }
158
159    public static readonly DependencyProperty ParentYMaxProperty = DependencyProperty.Register(
160      "ParentYMax",
161      typeof(double),
162      typeof(InjectedPlotter),
163      new FrameworkPropertyMetadata(1.0, OnTransformChanged));
164
165    public double SelfYMin
166    {
167      get { return (double)GetValue(SelfYMinProperty); }
168      set { SetValue(SelfYMinProperty, value); }
169    }
170
171    public static readonly DependencyProperty SelfYMinProperty = DependencyProperty.Register(
172      "SelfYMin",
173      typeof(double),
174      typeof(InjectedPlotter),
175      new FrameworkPropertyMetadata(0.0, OnTransformChanged));
176
177    public double SelfYMax
178    {
179      get { return (double)GetValue(SelfYMaxProperty); }
180      set { SetValue(SelfYMaxProperty, value); }
181    }
182
183    public static readonly DependencyProperty SelfYMaxProperty = DependencyProperty.Register(
184      "SelfYMax",
185      typeof(double),
186      typeof(InjectedPlotter),
187      new FrameworkPropertyMetadata(1.0, OnTransformChanged));
188
189    private static void OnTransformChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
190    {
191      InjectedPlotter plotter = (InjectedPlotter)d;
192      plotter.UpdateTransform();
193    }
194
195    #endregion
196
197    #endregion
198  }
199}
Note: See TracBrowser for help on using the repository browser.