PolygonAnnotation.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. // --------------------------------------------------------------------------------------------------------------------
  2. // <copyright file="PolygonAnnotation.cs" company="OxyPlot">
  3. // Copyright (c) 2014 OxyPlot contributors
  4. // </copyright>
  5. // <summary>
  6. // This is a Avalonia wrapper of OxyPlot.PolygonAnnotation
  7. // </summary>
  8. // --------------------------------------------------------------------------------------------------------------------
  9. using Avalonia;
  10. namespace OxyPlot.Avalonia
  11. {
  12. using System.Collections.Generic;
  13. /// <summary>
  14. /// This is a Avalonia wrapper of OxyPlot.PolygonAnnotation
  15. /// </summary>
  16. public class PolygonAnnotation : ShapeAnnotation
  17. {
  18. /// <summary>
  19. /// Identifies the <see cref="LineJoin"/> dependency property.
  20. /// </summary>
  21. public static readonly StyledProperty<LineJoin> LineJoinProperty = AvaloniaProperty.Register<PolygonAnnotation, LineJoin>(nameof(LineJoin), LineJoin.Miter);
  22. /// <summary>
  23. /// Identifies the <see cref="LineStyle"/> dependency property.
  24. /// </summary>
  25. public static readonly StyledProperty<LineStyle> LineStyleProperty = AvaloniaProperty.Register<PolygonAnnotation, LineStyle>(nameof(LineStyle), LineStyle.Solid);
  26. /// <summary>
  27. /// Identifies the <see cref="Points"/> dependency property.
  28. /// </summary>
  29. public static readonly StyledProperty<IList<DataPoint>> PointsProperty = AvaloniaProperty.Register<PolygonAnnotation, IList<DataPoint>>(nameof(Points), new List<DataPoint>());
  30. /// <summary>
  31. /// Initializes static members of the <see cref="PolygonAnnotation"/> class.
  32. /// </summary>
  33. static PolygonAnnotation()
  34. {
  35. TextColorProperty.OverrideDefaultValue<PolygonAnnotation>(MoreColors.Automatic);
  36. TextColorProperty.Changed.AddClassHandler<PolygonAnnotation>(AppearanceChanged);
  37. LineJoinProperty.Changed.AddClassHandler<PolygonAnnotation>(AppearanceChanged);
  38. LineStyleProperty.Changed.AddClassHandler<PolygonAnnotation>(AppearanceChanged);
  39. PointsProperty.Changed.AddClassHandler<PolygonAnnotation>(DataChanged);
  40. }
  41. /// <summary>
  42. /// Initializes a new instance of the <see cref = "PolygonAnnotation" /> class.
  43. /// </summary>
  44. public PolygonAnnotation()
  45. {
  46. InternalAnnotation = new Annotations.PolygonAnnotation();
  47. }
  48. /// <summary>
  49. /// Gets or sets the line join.
  50. /// </summary>
  51. /// <value>The line join.</value>
  52. public LineJoin LineJoin
  53. {
  54. get
  55. {
  56. return GetValue(LineJoinProperty);
  57. }
  58. set
  59. {
  60. SetValue(LineJoinProperty, value);
  61. }
  62. }
  63. /// <summary>
  64. /// Gets or sets the line style.
  65. /// </summary>
  66. public LineStyle LineStyle
  67. {
  68. get
  69. {
  70. return GetValue(LineStyleProperty);
  71. }
  72. set
  73. {
  74. SetValue(LineStyleProperty, value);
  75. }
  76. }
  77. /// <summary>
  78. /// Gets or sets the points.
  79. /// </summary>
  80. public IList<DataPoint> Points
  81. {
  82. get
  83. {
  84. return GetValue(PointsProperty);
  85. }
  86. set
  87. {
  88. SetValue(PointsProperty, value);
  89. }
  90. }
  91. /// <summary>
  92. /// Creates the internal annotation object.
  93. /// </summary>
  94. /// <returns>The annotation.</returns>
  95. public override Annotations.Annotation CreateModel()
  96. {
  97. SynchronizeProperties();
  98. return InternalAnnotation;
  99. }
  100. /// <summary>
  101. /// Synchronizes the properties.
  102. /// </summary>
  103. public override void SynchronizeProperties()
  104. {
  105. base.SynchronizeProperties();
  106. var a = (Annotations.PolygonAnnotation)InternalAnnotation;
  107. a.Points.Clear();
  108. a.Points.AddRange(Points);
  109. a.LineStyle = LineStyle;
  110. a.LineJoin = LineJoin;
  111. }
  112. }
  113. }