Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization/DynamicDataDisplay/Charts/MarkerPointGraph.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;
5
6namespace Microsoft.Research.DynamicDataDisplay
7{
8    public class MarkerPointsGraph : PointsGraphBase
9    {
10        /// <summary>
11        /// Initializes a new instance of the <see cref="MarkerPointsGraph"/> class.
12        /// </summary>
13        public MarkerPointsGraph() { }
14
15        /// <summary>
16        /// Initializes a new instance of the <see cref="MarkerPointsGraph"/> class.
17        /// </summary>
18        /// <param name="dataSource">The data source.</param>
19        public MarkerPointsGraph(IPointDataSource dataSource)
20        {
21            DataSource = dataSource;
22        }
23
24        public PointMarker Marker
25        {
26            get { return (PointMarker)GetValue(MarkerProperty); }
27            set { SetValue(MarkerProperty, value); }
28        }
29
30        public static readonly DependencyProperty MarkerProperty =
31            DependencyProperty.Register(
32              "Marker",
33              typeof(PointMarker),
34              typeof(MarkerPointsGraph),
35              new FrameworkPropertyMetadata { DefaultValue = null, AffectsRender = true }
36                  );
37
38        protected override void OnRenderCore(DrawingContext dc, RenderState state)
39        {
40            if (DataSource == null) return;
41            if (Marker == null) return;
42
43            Rect bounds = Rect.Empty;
44            using (IPointEnumerator enumerator = DataSource.GetEnumerator(GetContext()))
45            {
46                Point point = new Point();
47                while (enumerator.MoveNext())
48                {
49                    enumerator.GetCurrent(ref point);
50                    enumerator.ApplyMappings(Marker);
51
52                    Point screenPoint = point.Transform(state.Visible, state.Output);
53
54                    bounds = Rect.Union(bounds, point);
55                    Marker.Render(dc, screenPoint);
56                }
57            }
58
59            ContentBounds = bounds;
60        }
61    }
62}
Note: See TracBrowser for help on using the repository browser.