/Main/src/DynamicDataDisplay/Charts/Shapes/ViewportPolygon.cs
C# | 59 lines | 47 code | 6 blank | 6 comment | 5 complexity | e1ea60e8e62810128b8d7ff849703ed3 MD5 | raw file
Possible License(s): CC-BY-SA-3.0
1using System; 2using System.Collections.Generic; 3using System.Linq; 4using System.Text; 5using System.Windows.Media; 6using System.Windows; 7using System.Windows.Shapes; 8 9namespace Microsoft.Research.DynamicDataDisplay.Charts.Shapes 10{ 11 /// <summary> 12 /// Represents a closed filled figure with points in Viewport coordinates. 13 /// </summary> 14 public sealed class ViewportPolygon : ViewportPolylineBase 15 { 16 static ViewportPolygon() 17 { 18 Type type = typeof(ViewportPolygon); 19 Shape.FillProperty.AddOwner(type, new FrameworkPropertyMetadata(Brushes.Coral)); 20 } 21 22 /// <summary> 23 /// Initializes a new instance of the <see cref="ViewportPolygon"/> class. 24 /// </summary> 25 public ViewportPolygon() { } 26 27 protected override void UpdateUIRepresentationCore() 28 { 29 var transform = Plotter.Viewport.Transform; 30 31 PathGeometry geometry = PathGeometry; 32 33 PointCollection points = Points; 34 geometry.Clear(); 35 36 if (points == null) { } 37 else 38 { 39 PathFigure figure = new PathFigure(); 40 if (points.Count > 0) 41 { 42 figure.StartPoint = points[0].DataToScreen(transform); 43 if (points.Count > 1) 44 { 45 Point[] pointArray = new Point[points.Count - 1]; 46 for (int i = 1; i < points.Count; i++) 47 { 48 pointArray[i - 1] = points[i].DataToScreen(transform); 49 } 50 figure.Segments.Add(new PolyLineSegment(pointArray, true)); 51 figure.IsClosed = true; 52 } 53 } 54 geometry.Figures.Add(figure); 55 geometry.FillRule = this.FillRule; 56 } 57 } 58 } 59}