Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization/DynamicDataDisplay/Charts/MarkerPointsGraph.cs @ 12503

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

#2283 added GUI and charts; fixed MCTS

File size: 2.1 KB
Line 
1using System.Windows;
2using System.Windows.Media;
3using Microsoft.Research.DynamicDataDisplay.DataSources;
4using Microsoft.Research.DynamicDataDisplay.PointMarkers;
5using Microsoft.Research.DynamicDataDisplay.Common;
6
7namespace Microsoft.Research.DynamicDataDisplay
8{
9  public class MarkerPointsGraph : PointsGraphBase
10  {
11    /// <summary>
12    /// Initializes a new instance of the <see cref="MarkerPointsGraph"/> class.
13    /// </summary>
14    public MarkerPointsGraph()
15    {
16      ManualTranslate = true;
17    }
18
19    /// <summary>
20    /// Initializes a new instance of the <see cref="MarkerPointsGraph"/> class.
21    /// </summary>
22    /// <param name="dataSource">The data source.</param>
23    public MarkerPointsGraph(IPointDataSource dataSource)
24      : this()
25    {
26      DataSource = dataSource;
27    }
28
29    protected override void OnVisibleChanged(DataRect newRect, DataRect oldRect)
30    {
31      base.OnVisibleChanged(newRect, oldRect);
32      InvalidateVisual();
33    }
34
35    public PointMarker Marker
36    {
37      get { return (PointMarker)GetValue(MarkerProperty); }
38      set { SetValue(MarkerProperty, value); }
39    }
40
41    public static readonly DependencyProperty MarkerProperty =
42      DependencyProperty.Register(
43        "Marker",
44        typeof(PointMarker),
45        typeof(MarkerPointsGraph),
46        new FrameworkPropertyMetadata { DefaultValue = null, AffectsRender = true }
47          );
48
49    protected override void OnRenderCore(DrawingContext dc, RenderState state)
50    {
51      if (DataSource == null) return;
52      if (Marker == null) return;
53
54      var transform = Plotter2D.Viewport.Transform;
55
56      DataRect bounds = DataRect.Empty;
57      using (IPointEnumerator enumerator = DataSource.GetEnumerator(GetContext()))
58      {
59        Point point = new Point();
60        while (enumerator.MoveNext())
61        {
62          enumerator.GetCurrent(ref point);
63          enumerator.ApplyMappings(Marker);
64
65          //Point screenPoint = point.Transform(state.Visible, state.Output);
66          Point screenPoint = point.DataToScreen(transform);
67
68          bounds = DataRect.Union(bounds, point);
69          Marker.Render(dc, screenPoint);
70        }
71      }
72
73      Viewport2D.SetContentBounds(this, bounds);
74    }
75  }
76}
Note: See TracBrowser for help on using the repository browser.