Line | |
---|
1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using System.Windows;
|
---|
6 |
|
---|
7 | namespace Microsoft.Research.DynamicDataDisplay.ViewportConstraints
|
---|
8 | {
|
---|
9 | public sealed class ProportionsConstraint : ViewportConstraint
|
---|
10 | {
|
---|
11 | private double widthToHeightRatio = 1;
|
---|
12 | public double WidthToHeightRatio
|
---|
13 | {
|
---|
14 | get { return widthToHeightRatio; }
|
---|
15 | set
|
---|
16 | {
|
---|
17 | if (widthToHeightRatio != value)
|
---|
18 | {
|
---|
19 | widthToHeightRatio = value;
|
---|
20 | RaiseChanged();
|
---|
21 | }
|
---|
22 | }
|
---|
23 | }
|
---|
24 |
|
---|
25 | public override DataRect Apply(DataRect oldDataRect, DataRect newDataRect, Viewport2D viewport)
|
---|
26 | {
|
---|
27 | double ratio = newDataRect.Width / newDataRect.Height;
|
---|
28 | double coeff = Math.Sqrt(ratio);
|
---|
29 |
|
---|
30 | double newWidth = newDataRect.Width / coeff;
|
---|
31 | double newHeight = newDataRect.Height * coeff;
|
---|
32 |
|
---|
33 | Point center = newDataRect.GetCenter();
|
---|
34 | DataRect res = DataRect.FromCenterSize(center, newWidth, newHeight);
|
---|
35 | return res;
|
---|
36 | }
|
---|
37 | }
|
---|
38 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.