PageRenderTime 45ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

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