1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 |
|
---|
6 | namespace Microsoft.Research.DynamicDataDisplay.ViewportConstraints
|
---|
7 | {
|
---|
8 | public class ScaleInjectionConstraint : ViewportConstraint
|
---|
9 | {
|
---|
10 | private Viewport2D parentViewport;
|
---|
11 | public ScaleInjectionConstraint(Viewport2D parentViewport)
|
---|
12 | {
|
---|
13 | if (parentViewport == null)
|
---|
14 | throw new ArgumentNullException("parentViewport");
|
---|
15 |
|
---|
16 | this.parentViewport = parentViewport;
|
---|
17 | parentViewport.PropertyChanged += parentViewport_PropertyChanged;
|
---|
18 | }
|
---|
19 |
|
---|
20 | private void parentViewport_PropertyChanged(object sender, ExtendedPropertyChangedEventArgs e)
|
---|
21 | {
|
---|
22 | if (e.PropertyName == "Visible")
|
---|
23 | {
|
---|
24 | RaiseChanged();
|
---|
25 | }
|
---|
26 | }
|
---|
27 |
|
---|
28 | public void SetHorizontalTransform(double parentMin, double childMin, double parentMax, double childMax)
|
---|
29 | {
|
---|
30 | xScale = (childMax - childMin) / (parentMax - parentMin);
|
---|
31 | xShift = childMin - parentMin;
|
---|
32 | }
|
---|
33 |
|
---|
34 | public void SetVerticalTransform(double parentMin, double childMin, double parentMax, double childMax)
|
---|
35 | {
|
---|
36 | yScale = (childMax - childMin) / (parentMax - parentMin);
|
---|
37 | yShift = childMin - parentMin;
|
---|
38 | }
|
---|
39 |
|
---|
40 | private double xShift = 0;
|
---|
41 | private double xScale = 1;
|
---|
42 | private double yShift = 0;
|
---|
43 | private double yScale = 1;
|
---|
44 |
|
---|
45 | public override DataRect Apply(DataRect previousDataRect, DataRect proposedDataRect, Viewport2D viewport)
|
---|
46 | {
|
---|
47 | DataRect parentVisible = parentViewport.Visible;
|
---|
48 |
|
---|
49 | double xmin = parentVisible.XMin * xScale + xShift;
|
---|
50 | double xmax = parentVisible.XMax * xScale + xShift;
|
---|
51 | double ymin = parentVisible.YMin * yScale + yShift;
|
---|
52 | double ymax = parentVisible.YMax * yScale + yShift;
|
---|
53 |
|
---|
54 | return DataRect.Create(xmin, ymin, xmax, ymax);
|
---|
55 | }
|
---|
56 | }
|
---|
57 | }
|
---|