PageRenderTime 25ms CodeModel.GetById 16ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/Main/src/DynamicDataDisplay/Charts/Isolines/AdditionalLinesRenderer.cs

#
C# | 87 lines | 69 code | 17 blank | 1 comment | 11 complexity | 4f6883a253cec65a67d21d6c29615a7a MD5 | raw file
 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4using System.Text;
 5using System.Windows.Media;
 6using System.Windows;
 7using System.Windows.Data;
 8using System.Diagnostics;
 9
10namespace Microsoft.Research.DynamicDataDisplay.Charts.Isolines
11{
12	public class AdditionalLinesRenderer : IsolineRenderer
13	{
14		protected override void CreateUIRepresentation()
15		{
16			InvalidateVisual();
17		}
18
19		protected override void OnPlotterAttached()
20		{
21			base.OnPlotterAttached();
22
23			FrameworkElement parent = (FrameworkElement)Parent;
24			var renderer = (FrameworkElement)parent.FindName("PART_IsolineRenderer");
25
26			Binding contentBoundsBinding = new Binding { Path = new PropertyPath("(0)", Viewport2D.ContentBoundsProperty), Source = renderer };
27			SetBinding(Viewport2D.ContentBoundsProperty, contentBoundsBinding);
28			SetBinding(ViewportPanel.ViewportBoundsProperty, contentBoundsBinding);
29
30			Plotter2D.Viewport.EndPanning += Viewport_EndPanning;
31			Plotter2D.Viewport.PropertyChanged += Viewport_PropertyChanged;
32		}
33
34		void Viewport_PropertyChanged(object sender, ExtendedPropertyChangedEventArgs e)
35		{
36			if (e.PropertyName == "Visible")
37			{
38				if (Plotter2D.Viewport.PanningState == Viewport2DPanningState.NotPanning)
39					InvalidateVisual();
40			}
41		}
42
43		protected override void OnPlotterDetaching()
44		{
45			Plotter2D.Viewport.EndPanning -= Viewport_EndPanning;
46			Plotter2D.Viewport.PropertyChanged -= Viewport_PropertyChanged;
47
48			base.OnPlotterDetaching();
49		}
50
51		private void Viewport_EndPanning(object sender, EventArgs e)
52		{
53			InvalidateVisual();
54		}
55
56		protected override void OnRender(DrawingContext drawingContext)
57		{
58			if (Plotter2D == null) return;
59			if (DataSource == null) return;
60
61			var collection = (IsolineCollection)Parent.GetValue(IsolineCollectionProperty);
62			if (collection == null) return;
63
64			var bounds = ViewportPanel.GetViewportBounds(this);
65			if (bounds.IsEmpty) return;
66
67			var dc = drawingContext;
68			var strokeThickness = StrokeThickness;
69
70			var transform = Plotter2D.Transform.WithRects(bounds, new Rect(RenderSize));
71
72			//dc.DrawRectangle(null, new Pen(Brushes.Green, 2), new Rect(RenderSize));
73
74			var additionalLevels = GetAdditionalLevels(collection);
75			IsolineBuilder.DataSource = DataSource;
76			var additionalIsolineCollections = additionalLevels.Select(level =>
77			{
78				return IsolineBuilder.BuildIsoline(level);
79			});
80
81			foreach (var additionalCollection in additionalIsolineCollections)
82			{
83				RenderIsolineCollection(dc, strokeThickness, additionalCollection, transform);
84			}
85		}
86	}
87}