1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using Microsoft.Research.DynamicDataDisplay.Common.Palettes;
|
---|
6 | using Microsoft.Research.DynamicDataDisplay.DataSources;
|
---|
7 | using DataSource = Microsoft.Research.DynamicDataDisplay.DataSources.IDataSource2D<double>;
|
---|
8 | using System.Windows;
|
---|
9 | using Microsoft.Research.DynamicDataDisplay.Charts.Shapes;
|
---|
10 |
|
---|
11 | namespace Microsoft.Research.DynamicDataDisplay.Charts.Isolines
|
---|
12 | {
|
---|
13 | public abstract class IsolineGraphBase : ContentGraph
|
---|
14 | {
|
---|
15 | protected IsolineGraphBase() { }
|
---|
16 |
|
---|
17 | private IsolineCollection collection = new IsolineCollection();
|
---|
18 | protected IsolineCollection Collection
|
---|
19 | {
|
---|
20 | get { return collection; }
|
---|
21 | set { collection = value; }
|
---|
22 | }
|
---|
23 |
|
---|
24 | private readonly IsolineBuilder isolineBuilder = new IsolineBuilder();
|
---|
25 | protected IsolineBuilder IsolineBuilder
|
---|
26 | {
|
---|
27 | get { return isolineBuilder; }
|
---|
28 | }
|
---|
29 |
|
---|
30 | private readonly IsolineTextAnnotater annotater = new IsolineTextAnnotater();
|
---|
31 | protected IsolineTextAnnotater Annotater
|
---|
32 | {
|
---|
33 | get { return annotater; }
|
---|
34 | }
|
---|
35 |
|
---|
36 | #region Properties
|
---|
37 |
|
---|
38 | #region IsolineCollection property
|
---|
39 |
|
---|
40 | public IsolineCollection IsolineCollection
|
---|
41 | {
|
---|
42 | get { return (IsolineCollection)GetValue(IsolineCollectionProperty); }
|
---|
43 | set { SetValue(IsolineCollectionProperty, value); }
|
---|
44 | }
|
---|
45 |
|
---|
46 | public static readonly DependencyProperty IsolineCollectionProperty = DependencyProperty.Register(
|
---|
47 | "IsolineCollection",
|
---|
48 | typeof(IsolineCollection),
|
---|
49 | typeof(IsolineGraphBase),
|
---|
50 | new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.Inherits));
|
---|
51 |
|
---|
52 | #endregion // end of IsolineCollection property
|
---|
53 |
|
---|
54 | #region WayBeforeTextMultiplier
|
---|
55 |
|
---|
56 | public double WayBeforeTextMultiplier
|
---|
57 | {
|
---|
58 | get { return (double)GetValue(WayBeforeTextMultiplierProperty); }
|
---|
59 | set { SetValue(WayBeforeTextMultiplierProperty, value); }
|
---|
60 | }
|
---|
61 |
|
---|
62 | public static readonly DependencyProperty WayBeforeTextMultiplierProperty = DependencyProperty.Register(
|
---|
63 | "WayBeforeTextCoeff",
|
---|
64 | typeof(double),
|
---|
65 | typeof(IsolineGraphBase),
|
---|
66 | new FrameworkPropertyMetadata(1.0, FrameworkPropertyMetadataOptions.Inherits, OnIsolinePropertyChanged));
|
---|
67 |
|
---|
68 | #endregion // end of WayBeforeTextCoeff
|
---|
69 |
|
---|
70 | private static void OnIsolinePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
---|
71 | {
|
---|
72 | // todo do smth here
|
---|
73 | }
|
---|
74 |
|
---|
75 | #region Palette property
|
---|
76 |
|
---|
77 | public IPalette Palette
|
---|
78 | {
|
---|
79 | get { return (IPalette)GetValue(PaletteProperty); }
|
---|
80 | set { SetValue(PaletteProperty, value); }
|
---|
81 | }
|
---|
82 |
|
---|
83 | public static readonly DependencyProperty PaletteProperty = DependencyProperty.Register(
|
---|
84 | "Palette",
|
---|
85 | typeof(IPalette),
|
---|
86 | typeof(IsolineGraphBase),
|
---|
87 | new FrameworkPropertyMetadata(new HsbPalette(), FrameworkPropertyMetadataOptions.Inherits, OnIsolinePropertyChanged), ValidatePalette);
|
---|
88 |
|
---|
89 | private static bool ValidatePalette(object value)
|
---|
90 | {
|
---|
91 | return value != null;
|
---|
92 | }
|
---|
93 |
|
---|
94 | #endregion // end of Palette property
|
---|
95 |
|
---|
96 | #region DataSource property
|
---|
97 |
|
---|
98 | public DataSource DataSource
|
---|
99 | {
|
---|
100 | get { return (DataSource)GetValue(DataSourceProperty); }
|
---|
101 | set { SetValue(DataSourceProperty, value); }
|
---|
102 | }
|
---|
103 |
|
---|
104 | public static readonly DependencyProperty DataSourceProperty = DependencyProperty.Register(
|
---|
105 | "DataSource",
|
---|
106 | typeof(DataSource),
|
---|
107 | typeof(IsolineGraphBase),
|
---|
108 | new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.Inherits, OnDataSourceChanged));
|
---|
109 |
|
---|
110 | private static void OnDataSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
---|
111 | {
|
---|
112 | IsolineGraphBase owner = (IsolineGraphBase)d;
|
---|
113 | owner.OnDataSourceChanged((DataSource)e.OldValue, (DataSource)e.NewValue);
|
---|
114 | }
|
---|
115 |
|
---|
116 | protected virtual void OnDataSourceChanged(IDataSource2D<double> prevDataSource, IDataSource2D<double> currDataSource)
|
---|
117 | {
|
---|
118 | if (prevDataSource != null)
|
---|
119 | prevDataSource.Changed -= OnDataSourceChanged;
|
---|
120 | if (currDataSource != null)
|
---|
121 | currDataSource.Changed += OnDataSourceChanged;
|
---|
122 |
|
---|
123 | UpdateDataSource();
|
---|
124 | CreateUIRepresentation();
|
---|
125 |
|
---|
126 | RaiseEvent(new RoutedEventArgs(BackgroundRenderer.UpdateRequested));
|
---|
127 | }
|
---|
128 |
|
---|
129 | #endregion // end of DataSource property
|
---|
130 |
|
---|
131 | #region DrawLabels property
|
---|
132 |
|
---|
133 | public bool DrawLabels
|
---|
134 | {
|
---|
135 | get { return (bool)GetValue(DrawLabelsProperty); }
|
---|
136 | set { SetValue(DrawLabelsProperty, value); }
|
---|
137 | }
|
---|
138 |
|
---|
139 | public static readonly DependencyProperty DrawLabelsProperty = DependencyProperty.Register(
|
---|
140 | "DrawLabels",
|
---|
141 | typeof(bool),
|
---|
142 | typeof(IsolineGraphBase),
|
---|
143 | new FrameworkPropertyMetadata(true, FrameworkPropertyMetadataOptions.Inherits, OnIsolinePropertyChanged));
|
---|
144 |
|
---|
145 | #endregion // end of DrawLabels property
|
---|
146 |
|
---|
147 | #region LabelStringFormat
|
---|
148 |
|
---|
149 | public string LabelStringFormat
|
---|
150 | {
|
---|
151 | get { return (string)GetValue(LabelStringFormatProperty); }
|
---|
152 | set { SetValue(LabelStringFormatProperty, value); }
|
---|
153 | }
|
---|
154 |
|
---|
155 | public static readonly DependencyProperty LabelStringFormatProperty = DependencyProperty.Register(
|
---|
156 | "LabelStringFormat",
|
---|
157 | typeof(string),
|
---|
158 | typeof(IsolineGraphBase),
|
---|
159 | new FrameworkPropertyMetadata("F", FrameworkPropertyMetadataOptions.Inherits, OnIsolinePropertyChanged));
|
---|
160 |
|
---|
161 | #endregion // end of LabelStringFormat
|
---|
162 |
|
---|
163 | #region UseBezierCurves
|
---|
164 |
|
---|
165 | public bool UseBezierCurves
|
---|
166 | {
|
---|
167 | get { return (bool)GetValue(UseBezierCurvesProperty); }
|
---|
168 | set { SetValue(UseBezierCurvesProperty, value); }
|
---|
169 | }
|
---|
170 |
|
---|
171 | public static readonly DependencyProperty UseBezierCurvesProperty = DependencyProperty.Register(
|
---|
172 | "UseBezierCurves",
|
---|
173 | typeof(bool),
|
---|
174 | typeof(IsolineGraphBase),
|
---|
175 | new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.Inherits));
|
---|
176 |
|
---|
177 | #endregion // end of UseBezierCurves
|
---|
178 |
|
---|
179 | public double LabelsScaling
|
---|
180 | {
|
---|
181 | get { return (double)GetValue(LabelsScalingProperty); }
|
---|
182 | set { SetValue(LabelsScalingProperty, value); }
|
---|
183 | }
|
---|
184 |
|
---|
185 | public static readonly DependencyProperty LabelsScalingProperty = DependencyProperty.Register(
|
---|
186 | "LabelsScaling",
|
---|
187 | typeof(double),
|
---|
188 | typeof(IsolineGraphBase),
|
---|
189 | new FrameworkPropertyMetadata(1.0, FrameworkPropertyMetadataOptions.Inherits));
|
---|
190 |
|
---|
191 |
|
---|
192 | #endregion // end of Properties
|
---|
193 |
|
---|
194 | #region DataSource
|
---|
195 |
|
---|
196 | //private DataSource dataSource = null;
|
---|
197 | ///// <summary>
|
---|
198 | ///// Gets or sets the data source.
|
---|
199 | ///// </summary>
|
---|
200 | ///// <value>The data source.</value>
|
---|
201 | //public DataSource DataSource
|
---|
202 | //{
|
---|
203 | // get { return dataSource; }
|
---|
204 | // set
|
---|
205 | // {
|
---|
206 | // if (dataSource != value)
|
---|
207 | // {
|
---|
208 | // DetachDataSource(dataSource);
|
---|
209 | // dataSource = value;
|
---|
210 | // AttachDataSource(dataSource);
|
---|
211 |
|
---|
212 | // UpdateDataSource();
|
---|
213 | // }
|
---|
214 | // }
|
---|
215 | //}
|
---|
216 |
|
---|
217 | #region MissingValue property
|
---|
218 |
|
---|
219 | public double MissingValue
|
---|
220 | {
|
---|
221 | get { return (double)GetValue(MissingValueProperty); }
|
---|
222 | set { SetValue(MissingValueProperty, value); }
|
---|
223 | }
|
---|
224 |
|
---|
225 | public static readonly DependencyProperty MissingValueProperty = DependencyProperty.Register(
|
---|
226 | "MissingValue",
|
---|
227 | typeof(double),
|
---|
228 | typeof(IsolineGraphBase),
|
---|
229 | new FrameworkPropertyMetadata(Double.NaN, FrameworkPropertyMetadataOptions.Inherits, OnMissingValueChanged));
|
---|
230 |
|
---|
231 | private static void OnMissingValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
---|
232 | {
|
---|
233 | IsolineGraphBase owner = (IsolineGraphBase)d;
|
---|
234 | owner.UpdateDataSource();
|
---|
235 | }
|
---|
236 |
|
---|
237 | #endregion // end of MissineValue property
|
---|
238 |
|
---|
239 | public void SetDataSource(DataSource dataSource, double missingValue)
|
---|
240 | {
|
---|
241 | DataSource = dataSource;
|
---|
242 | MissingValue = missingValue;
|
---|
243 |
|
---|
244 | UpdateDataSource();
|
---|
245 | }
|
---|
246 |
|
---|
247 | /// <summary>
|
---|
248 | /// This method is called when data source changes.
|
---|
249 | /// </summary>
|
---|
250 | protected virtual void UpdateDataSource()
|
---|
251 | {
|
---|
252 | }
|
---|
253 |
|
---|
254 | protected virtual void CreateUIRepresentation() { }
|
---|
255 |
|
---|
256 | protected virtual void OnDataSourceChanged(object sender, EventArgs e)
|
---|
257 | {
|
---|
258 | UpdateDataSource();
|
---|
259 | }
|
---|
260 |
|
---|
261 | #endregion
|
---|
262 |
|
---|
263 | #region StrokeThickness
|
---|
264 |
|
---|
265 | /// <summary>
|
---|
266 | /// Gets or sets thickness of isoline lines.
|
---|
267 | /// </summary>
|
---|
268 | /// <value>The stroke thickness.</value>
|
---|
269 | public double StrokeThickness
|
---|
270 | {
|
---|
271 | get { return (double)GetValue(StrokeThicknessProperty); }
|
---|
272 | set { SetValue(StrokeThicknessProperty, value); }
|
---|
273 | }
|
---|
274 |
|
---|
275 | /// <summary>
|
---|
276 | /// Identifies the StrokeThickness dependency property.
|
---|
277 | /// </summary>
|
---|
278 | public static readonly DependencyProperty StrokeThicknessProperty =
|
---|
279 | DependencyProperty.Register(
|
---|
280 | "StrokeThickness",
|
---|
281 | typeof(double),
|
---|
282 | typeof(IsolineGraphBase),
|
---|
283 | new FrameworkPropertyMetadata(2.0, OnLineThicknessChanged));
|
---|
284 |
|
---|
285 | private static void OnLineThicknessChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
---|
286 | {
|
---|
287 | IsolineGraphBase graph = (IsolineGraphBase)d;
|
---|
288 | graph.OnLineThicknessChanged();
|
---|
289 | }
|
---|
290 |
|
---|
291 | protected virtual void OnLineThicknessChanged() { }
|
---|
292 |
|
---|
293 | #endregion
|
---|
294 | }
|
---|
295 | }
|
---|