PointAnnotation.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. // --------------------------------------------------------------------------------------------------------------------
  2. // <copyright file="PointAnnotation.cs" company="OxyPlot">
  3. // Copyright (c) 2014 OxyPlot contributors
  4. // </copyright>
  5. // <summary>
  6. // This is a Avalonia wrapper of <see cref="OxyPlot.Annotations.PointAnnotation" />.
  7. // </summary>
  8. // --------------------------------------------------------------------------------------------------------------------
  9. using Avalonia;
  10. namespace OxyPlot.Avalonia
  11. {
  12. using global::Avalonia.Layout;
  13. /// <summary>
  14. /// This is a Avalonia wrapper of <see cref="OxyPlot.Annotations.PointAnnotation" />.
  15. /// </summary>
  16. public class PointAnnotation : ShapeAnnotation
  17. {
  18. /// <summary>
  19. /// Identifies the <see cref="X"/> dependency property.
  20. /// </summary>
  21. public static readonly StyledProperty<double> XProperty = AvaloniaProperty.Register<PointAnnotation, double>(nameof(X), 0.0);
  22. /// <summary>
  23. /// Identifies the <see cref="Y"/> dependency property.
  24. /// </summary>
  25. public static readonly StyledProperty<double> YProperty = AvaloniaProperty.Register<PointAnnotation, double>(nameof(Y), 0.0);
  26. /// <summary>
  27. /// Identifies the <see cref="Size"/> dependency property.
  28. /// </summary>
  29. public static readonly StyledProperty<double> SizeProperty = AvaloniaProperty.Register<PointAnnotation, double>(nameof(Size), 4d);
  30. /// <summary>
  31. /// Identifies the <see cref="TextMargin"/> dependency property.
  32. /// </summary>
  33. public static readonly StyledProperty<double> TextMarginProperty = AvaloniaProperty.Register<PointAnnotation, double>(nameof(TextMargin), 2d);
  34. /// <summary>
  35. /// Identifies the <see cref="Shape"/> dependency property.
  36. /// </summary>
  37. public static readonly StyledProperty<MarkerType> ShapeProperty = AvaloniaProperty.Register<PointAnnotation, MarkerType>(nameof(Shape), MarkerType.Circle);
  38. /// <summary>
  39. /// Initializes static members of the <see cref="PointAnnotation"/> class.
  40. /// </summary>
  41. static PointAnnotation()
  42. {
  43. TextColorProperty.OverrideDefaultValue<PointAnnotation>(MoreColors.Automatic);
  44. TextColorProperty.Changed.AddClassHandler<PointAnnotation>(AppearanceChanged);
  45. TextVerticalAlignmentProperty.OverrideDefaultValue<PointAnnotation>(VerticalAlignment.Top);
  46. TextVerticalAlignmentProperty.Changed.AddClassHandler<PointAnnotation>(AppearanceChanged);
  47. XProperty.Changed.AddClassHandler<PointAnnotation>(DataChanged);
  48. YProperty.Changed.AddClassHandler<PointAnnotation>(DataChanged);
  49. SizeProperty.Changed.AddClassHandler<PointAnnotation>(AppearanceChanged);
  50. TextMarginProperty.Changed.AddClassHandler<PointAnnotation>(AppearanceChanged);
  51. ShapeProperty.Changed.AddClassHandler<PointAnnotation>(AppearanceChanged);
  52. }
  53. /// <summary>
  54. /// Initializes a new instance of the <see cref="PointAnnotation" /> class.
  55. /// </summary>
  56. public PointAnnotation()
  57. {
  58. InternalAnnotation = new Annotations.PointAnnotation();
  59. }
  60. /// <summary>
  61. /// Gets or sets the size.
  62. /// </summary>
  63. public double Size
  64. {
  65. get
  66. {
  67. return GetValue(SizeProperty);
  68. }
  69. set
  70. {
  71. SetValue(SizeProperty, value);
  72. }
  73. }
  74. /// <summary>
  75. /// Gets or sets the text margin.
  76. /// </summary>
  77. public double TextMargin
  78. {
  79. get
  80. {
  81. return GetValue(TextMarginProperty);
  82. }
  83. set
  84. {
  85. SetValue(TextMarginProperty, value);
  86. }
  87. }
  88. /// <summary>
  89. /// Gets or sets the shape.
  90. /// </summary>
  91. public MarkerType Shape
  92. {
  93. get
  94. {
  95. return GetValue(ShapeProperty);
  96. }
  97. set
  98. {
  99. SetValue(ShapeProperty, value);
  100. }
  101. }
  102. /// <summary>
  103. /// Gets or sets the X coordinate.
  104. /// </summary>
  105. public double X
  106. {
  107. get
  108. {
  109. return GetValue(XProperty);
  110. }
  111. set
  112. {
  113. SetValue(XProperty, value);
  114. }
  115. }
  116. /// <summary>
  117. /// Gets or sets the Y coordinate.
  118. /// </summary>
  119. public double Y
  120. {
  121. get
  122. {
  123. return GetValue(YProperty);
  124. }
  125. set
  126. {
  127. SetValue(YProperty, value);
  128. }
  129. }
  130. /// <summary>
  131. /// Creates the internal annotation object.
  132. /// </summary>
  133. /// <returns>The annotation.</returns>
  134. public override Annotations.Annotation CreateModel()
  135. {
  136. SynchronizeProperties();
  137. return InternalAnnotation;
  138. }
  139. /// <summary>
  140. /// Synchronizes the properties.
  141. /// </summary>
  142. public override void SynchronizeProperties()
  143. {
  144. base.SynchronizeProperties();
  145. var a = (Annotations.PointAnnotation)InternalAnnotation;
  146. a.X = X;
  147. a.Y = Y;
  148. a.Size = Size;
  149. a.TextMargin = TextMargin;
  150. a.Shape = Shape;
  151. }
  152. }
  153. }