Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization/DynamicDataDisplay/ViewportConstraints/ScaleInjectionConstraint.cs @ 13376

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

#2283 added GUI and charts; fixed MCTS

File size: 1.7 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5
6namespace 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}
Note: See TracBrowser for help on using the repository browser.