PathAnnotation.cs 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. // --------------------------------------------------------------------------------------------------------------------
  2. // <copyright file="PathAnnotation.cs" company="OxyPlot">
  3. // Copyright (c) 2014 OxyPlot contributors
  4. // </copyright>
  5. // <summary>
  6. // This is a Avalonia wrapper of OxyPlot.PathAnnotation
  7. // </summary>
  8. // --------------------------------------------------------------------------------------------------------------------
  9. using Avalonia;
  10. namespace OxyPlot.Avalonia
  11. {
  12. using global::Avalonia.Media;
  13. using OxyPlot.Annotations;
  14. /// <summary>
  15. /// This is a Avalonia wrapper of OxyPlot.PathAnnotation
  16. /// </summary>
  17. public abstract class PathAnnotation : TextualAnnotation
  18. {
  19. /// <summary>
  20. /// Identifies the <see cref="Color"/> dependency property.
  21. /// </summary>
  22. public static readonly StyledProperty<Color> ColorProperty = AvaloniaProperty.Register<PathAnnotation, Color>(nameof(Color), Colors.Blue);
  23. /// <summary>
  24. /// Identifies the <see cref="ClipByXAxis"/> dependency property.
  25. /// </summary>
  26. public static readonly StyledProperty<bool> ClipByXAxisProperty = AvaloniaProperty.Register<PathAnnotation, bool>(nameof(ClipByXAxis), true);
  27. /// <summary>
  28. /// Identifies the <see cref="ClipByYAxis"/> dependency property.
  29. /// </summary>
  30. public static readonly StyledProperty<bool> ClipByYAxisProperty = AvaloniaProperty.Register<PathAnnotation, bool>(nameof(ClipByYAxis), true);
  31. /// <summary>
  32. /// Identifies the <see cref="LineJoin"/> dependency property.
  33. /// </summary>
  34. public static readonly StyledProperty<LineJoin> LineJoinProperty = AvaloniaProperty.Register<PathAnnotation, LineJoin>(nameof(LineJoin), LineJoin.Miter);
  35. /// <summary>
  36. /// Identifies the <see cref="LineStyle"/> dependency property.
  37. /// </summary>
  38. public static readonly StyledProperty<LineStyle> LineStyleProperty = AvaloniaProperty.Register<PathAnnotation, LineStyle>(nameof(LineStyle), LineStyle.Dash);
  39. /// <summary>
  40. /// Identifies the <see cref="StrokeThickness"/> dependency property.
  41. /// </summary>
  42. public static readonly StyledProperty<double> StrokeThicknessProperty = AvaloniaProperty.Register<PathAnnotation, double>(nameof(StrokeThickness), 1.0);
  43. /// <summary>
  44. /// Identifies the <see cref="TextMargin"/> dependency property.
  45. /// </summary>
  46. public static readonly StyledProperty<double> TextMarginProperty = AvaloniaProperty.Register<PathAnnotation, double>(nameof(TextMargin), 12.0);
  47. /// <summary>
  48. /// Identifies the <see cref="TextOrientation"/> dependency property.
  49. /// </summary>
  50. public static readonly StyledProperty<AnnotationTextOrientation> TextOrientationProperty = AvaloniaProperty.Register<PathAnnotation, AnnotationTextOrientation>(nameof(TextOrientation), AnnotationTextOrientation.AlongLine);
  51. /// <summary>
  52. /// Identifies the <see cref="TextLinePosition"/> dependency property.
  53. /// </summary>
  54. public static readonly StyledProperty<double> TextLinePositionProperty = AvaloniaProperty.Register<PathAnnotation, double>(nameof(TextLinePosition), 1.0);
  55. /// <summary>
  56. /// Gets or sets a value indicating whether to clip the annotation line by the X axis range.
  57. /// </summary>
  58. /// <value><c>true</c> if clipping by the X axis is enabled; otherwise, <c>false</c>.</value>
  59. public bool ClipByXAxis
  60. {
  61. get
  62. {
  63. return GetValue(ClipByXAxisProperty);
  64. }
  65. set
  66. {
  67. SetValue(ClipByXAxisProperty, value);
  68. }
  69. }
  70. /// <summary>
  71. /// Gets or sets a value indicating whether to clip the annotation line by the Y axis range.
  72. /// </summary>
  73. /// <value><c>true</c> if clipping by the Y axis is enabled; otherwise, <c>false</c>.</value>
  74. public bool ClipByYAxis
  75. {
  76. get
  77. {
  78. return GetValue(ClipByYAxisProperty);
  79. }
  80. set
  81. {
  82. SetValue(ClipByYAxisProperty, value);
  83. }
  84. }
  85. /// <summary>
  86. /// Gets or sets the annotation color.
  87. /// </summary>
  88. /// <value>The color.</value>
  89. public Color Color
  90. {
  91. get
  92. {
  93. return GetValue(ColorProperty);
  94. }
  95. set
  96. {
  97. SetValue(ColorProperty, value);
  98. }
  99. }
  100. /// <summary>
  101. /// Gets or sets the line join.
  102. /// </summary>
  103. /// <value>The line join.</value>
  104. public LineJoin LineJoin
  105. {
  106. get
  107. {
  108. return GetValue(LineJoinProperty);
  109. }
  110. set
  111. {
  112. SetValue(LineJoinProperty, value);
  113. }
  114. }
  115. /// <summary>
  116. /// Gets or sets LineStyle.
  117. /// </summary>
  118. public LineStyle LineStyle
  119. {
  120. get
  121. {
  122. return GetValue(LineStyleProperty);
  123. }
  124. set
  125. {
  126. SetValue(LineStyleProperty, value);
  127. }
  128. }
  129. /// <summary>
  130. /// Gets or sets StrokeThickness.
  131. /// </summary>
  132. public double StrokeThickness
  133. {
  134. get
  135. {
  136. return GetValue(StrokeThicknessProperty);
  137. }
  138. set
  139. {
  140. SetValue(StrokeThicknessProperty, value);
  141. }
  142. }
  143. /// <summary>
  144. /// Gets or sets the text margin (along the line).
  145. /// </summary>
  146. /// <value>The text margin.</value>
  147. public double TextMargin
  148. {
  149. get
  150. {
  151. return GetValue(TextMarginProperty);
  152. }
  153. set
  154. {
  155. SetValue(TextMarginProperty, value);
  156. }
  157. }
  158. /// <summary>
  159. /// Gets or sets the text orientation.
  160. /// </summary>
  161. /// <value>The text orientation.</value>
  162. public AnnotationTextOrientation TextOrientation
  163. {
  164. get
  165. {
  166. return GetValue(TextOrientationProperty);
  167. }
  168. set
  169. {
  170. SetValue(TextOrientationProperty, value);
  171. }
  172. }
  173. /// <summary>
  174. /// Gets or sets the text position relative to the line.
  175. /// </summary>
  176. /// <value>The text position in the interval [0,1].</value>
  177. /// <remarks>Positions smaller than 0.25 are left aligned at the start of the line
  178. /// Positions larger than 0.75 are right aligned at the end of the line
  179. /// Other positions are center aligned at the specified position</remarks>
  180. public double TextLinePosition
  181. {
  182. get
  183. {
  184. return GetValue(TextLinePositionProperty);
  185. }
  186. set
  187. {
  188. SetValue(TextLinePositionProperty, value);
  189. }
  190. }
  191. /// <summary>
  192. /// Creates the internal annotation object.
  193. /// </summary>
  194. /// <returns>The annotation.</returns>
  195. public override Annotations.Annotation CreateModel()
  196. {
  197. SynchronizeProperties();
  198. return InternalAnnotation;
  199. }
  200. /// <summary>
  201. /// Synchronizes the properties.
  202. /// </summary>
  203. public override void SynchronizeProperties()
  204. {
  205. base.SynchronizeProperties();
  206. var a = (Annotations.PathAnnotation)InternalAnnotation;
  207. a.Color = Color.ToOxyColor();
  208. a.ClipByXAxis = ClipByXAxis;
  209. a.ClipByYAxis = ClipByYAxis;
  210. a.StrokeThickness = StrokeThickness;
  211. a.LineStyle = LineStyle;
  212. a.LineJoin = LineJoin;
  213. a.TextLinePosition = TextLinePosition;
  214. a.TextOrientation = TextOrientation;
  215. a.TextMargin = TextMargin;
  216. }
  217. static PathAnnotation()
  218. {
  219. ColorProperty.Changed.AddClassHandler<PathAnnotation>(AppearanceChanged);
  220. ClipByXAxisProperty.Changed.AddClassHandler<PathAnnotation>(AppearanceChanged);
  221. ClipByYAxisProperty.Changed.AddClassHandler<PathAnnotation>(AppearanceChanged);
  222. LineJoinProperty.Changed.AddClassHandler<PathAnnotation>(AppearanceChanged);
  223. LineStyleProperty.Changed.AddClassHandler<PathAnnotation>(AppearanceChanged);
  224. StrokeThicknessProperty.Changed.AddClassHandler<PathAnnotation>(AppearanceChanged);
  225. TextMarginProperty.Changed.AddClassHandler<PathAnnotation>(AppearanceChanged);
  226. TextOrientationProperty.Changed.AddClassHandler<PathAnnotation>(AppearanceChanged);
  227. TextLinePositionProperty.Changed.AddClassHandler<PathAnnotation>(AppearanceChanged);
  228. }
  229. }
  230. }