ArrowAnnotation.cs 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. // --------------------------------------------------------------------------------------------------------------------
  2. // <copyright file="ArrowAnnotation.cs" company="OxyPlot">
  3. // Copyright (c) 2014 OxyPlot contributors
  4. // </copyright>
  5. // <summary>
  6. // This is a Avalonia wrapper of OxyPlot.ArrowAnnotation
  7. // </summary>
  8. // --------------------------------------------------------------------------------------------------------------------
  9. using Avalonia;
  10. namespace OxyPlot.Avalonia
  11. {
  12. using global::Avalonia.Media;
  13. /// <summary>
  14. /// This is a Avalonia wrapper of OxyPlot.ArrowAnnotation
  15. /// </summary>
  16. public class ArrowAnnotation : TextualAnnotation
  17. {
  18. /// <summary>
  19. /// Identifies the <see cref="ArrowDirection"/> dependency property.
  20. /// </summary>
  21. public static readonly StyledProperty<ScreenVector> ArrowDirectionProperty = AvaloniaProperty.Register<ArrowAnnotation, ScreenVector>(nameof(ArrowDirection));
  22. /// <summary>
  23. /// Identifies the <see cref="Color"/> dependency property.
  24. /// </summary>
  25. public static readonly StyledProperty<Color> ColorProperty = AvaloniaProperty.Register<ArrowAnnotation, Color>(nameof(Color), Colors.Blue);
  26. /// <summary>
  27. /// Identifies the <see cref="EndPoint"/> dependency property.
  28. /// </summary>
  29. public static readonly StyledProperty<DataPoint> EndPointProperty = AvaloniaProperty.Register<ArrowAnnotation, DataPoint>(nameof(EndPoint));
  30. /// <summary>
  31. /// Identifies the <see cref="HeadLength"/> dependency property.
  32. /// </summary>
  33. public static readonly StyledProperty<double> HeadLengthProperty = AvaloniaProperty.Register<ArrowAnnotation, double>(nameof(HeadLength), 10.0);
  34. /// <summary>
  35. /// Identifies the <see cref="HeadWidth"/> dependency property.
  36. /// </summary>
  37. public static readonly StyledProperty<double> HeadWidthProperty = AvaloniaProperty.Register<ArrowAnnotation, double>(nameof(HeadWidth), 3.0);
  38. /// <summary>
  39. /// Identifies the <see cref="LineJoin"/> dependency property.
  40. /// </summary>
  41. public static readonly StyledProperty<LineJoin> LineJoinProperty = AvaloniaProperty.Register<ArrowAnnotation, LineJoin>(nameof(LineJoin), LineJoin.Miter);
  42. /// <summary>
  43. /// Identifies the <see cref="LineStyle"/> dependency property.
  44. /// </summary>
  45. public static readonly StyledProperty<LineStyle> LineStyleProperty = AvaloniaProperty.Register<ArrowAnnotation, LineStyle>(nameof(LineStyle), LineStyle.Solid);
  46. /// <summary>
  47. /// Identifies the <see cref="StartPoint"/> dependency property.
  48. /// </summary>
  49. public static readonly StyledProperty<DataPoint> StartPointProperty = AvaloniaProperty.Register<ArrowAnnotation, DataPoint>(nameof(StartPoint));
  50. /// <summary>
  51. /// Identifies the <see cref="StrokeThickness"/> dependency property.
  52. /// </summary>
  53. public static readonly StyledProperty<double> StrokeThicknessProperty = AvaloniaProperty.Register<ArrowAnnotation, double>(nameof(StrokeThickness), 2.0);
  54. /// <summary>
  55. /// Identifies the <see cref="Veeness"/> dependency property.
  56. /// </summary>
  57. public static readonly StyledProperty<double> VeenessProperty = AvaloniaProperty.Register<ArrowAnnotation, double>(nameof(Veeness), 0.0);
  58. /// <summary>
  59. /// Initializes static members of the <see cref="ArrowAnnotation"/> class.
  60. /// </summary>
  61. static ArrowAnnotation()
  62. {
  63. TextColorProperty.OverrideDefaultValue<ArrowAnnotation>(MoreColors.Automatic);
  64. TextColorProperty.Changed.AddClassHandler<ArrowAnnotation>(AppearanceChanged);
  65. ArrowDirectionProperty.Changed.AddClassHandler<ArrowAnnotation>(DataChanged);
  66. ColorProperty.Changed.AddClassHandler<ArrowAnnotation>(AppearanceChanged);
  67. EndPointProperty.Changed.AddClassHandler<ArrowAnnotation>(DataChanged);
  68. HeadLengthProperty.Changed.AddClassHandler<ArrowAnnotation>(AppearanceChanged);
  69. HeadWidthProperty.Changed.AddClassHandler<ArrowAnnotation>(AppearanceChanged);
  70. LineJoinProperty.Changed.AddClassHandler<ArrowAnnotation>(AppearanceChanged);
  71. LineStyleProperty.Changed.AddClassHandler<ArrowAnnotation>(AppearanceChanged);
  72. StartPointProperty.Changed.AddClassHandler<ArrowAnnotation>(DataChanged);
  73. StrokeThicknessProperty.Changed.AddClassHandler<ArrowAnnotation>(AppearanceChanged);
  74. VeenessProperty.Changed.AddClassHandler<ArrowAnnotation>(AppearanceChanged);
  75. }
  76. /// <summary>
  77. /// Initializes a new instance of the <see cref = "ArrowAnnotation" /> class.
  78. /// </summary>
  79. public ArrowAnnotation()
  80. {
  81. InternalAnnotation = new Annotations.ArrowAnnotation();
  82. }
  83. /// <summary>
  84. /// Gets or sets the arrow direction.
  85. /// </summary>
  86. public ScreenVector ArrowDirection
  87. {
  88. get
  89. {
  90. return GetValue(ArrowDirectionProperty);
  91. }
  92. set
  93. {
  94. SetValue(ArrowDirectionProperty, value);
  95. }
  96. }
  97. /// <summary>
  98. /// Gets or sets the color.
  99. /// </summary>
  100. public Color Color
  101. {
  102. get
  103. {
  104. return GetValue(ColorProperty);
  105. }
  106. set
  107. {
  108. SetValue(ColorProperty, value);
  109. }
  110. }
  111. /// <summary>
  112. /// Gets or sets the end point.
  113. /// </summary>
  114. public DataPoint EndPoint
  115. {
  116. get
  117. {
  118. return GetValue(EndPointProperty);
  119. }
  120. set
  121. {
  122. SetValue(EndPointProperty, value);
  123. }
  124. }
  125. /// <summary>
  126. /// Gets or sets the length of the head (relative to the stroke thickness).
  127. /// </summary>
  128. /// <value>The length of the head.</value>
  129. public double HeadLength
  130. {
  131. get
  132. {
  133. return GetValue(HeadLengthProperty);
  134. }
  135. set
  136. {
  137. SetValue(HeadLengthProperty, value);
  138. }
  139. }
  140. /// <summary>
  141. /// Gets or sets the width of the head (relative to the stroke thickness).
  142. /// </summary>
  143. /// <value>The width of the head.</value>
  144. public double HeadWidth
  145. {
  146. get
  147. {
  148. return GetValue(HeadWidthProperty);
  149. }
  150. set
  151. {
  152. SetValue(HeadWidthProperty, value);
  153. }
  154. }
  155. /// <summary>
  156. /// Gets or sets the line join.
  157. /// </summary>
  158. /// <value>The line join.</value>
  159. public LineJoin LineJoin
  160. {
  161. get
  162. {
  163. return GetValue(LineJoinProperty);
  164. }
  165. set
  166. {
  167. SetValue(LineJoinProperty, value);
  168. }
  169. }
  170. /// <summary>
  171. /// Gets or sets LineStyle.
  172. /// </summary>
  173. public LineStyle LineStyle
  174. {
  175. get
  176. {
  177. return GetValue(LineStyleProperty);
  178. }
  179. set
  180. {
  181. SetValue(LineStyleProperty, value);
  182. }
  183. }
  184. /// <summary>
  185. /// Gets or sets the start point.
  186. /// </summary>
  187. /// <remarks>This property is overridden by the ArrowDirection property, if set.</remarks>
  188. public DataPoint StartPoint
  189. {
  190. get
  191. {
  192. return GetValue(StartPointProperty);
  193. }
  194. set
  195. {
  196. SetValue(StartPointProperty, value);
  197. }
  198. }
  199. /// <summary>
  200. /// Gets or sets the stroke thickness.
  201. /// </summary>
  202. public double StrokeThickness
  203. {
  204. get
  205. {
  206. return GetValue(StrokeThicknessProperty);
  207. }
  208. set
  209. {
  210. SetValue(StrokeThicknessProperty, value);
  211. }
  212. }
  213. /// <summary>
  214. /// Gets or sets the 'veeness' of the arrow head (relative to thickness).
  215. /// </summary>
  216. public double Veeness
  217. {
  218. get
  219. {
  220. return GetValue(VeenessProperty);
  221. }
  222. set
  223. {
  224. SetValue(VeenessProperty, value);
  225. }
  226. }
  227. /// <summary>
  228. /// Creates the internal annotation object.
  229. /// </summary>
  230. /// <returns>The annotation.</returns>
  231. public override Annotations.Annotation CreateModel()
  232. {
  233. SynchronizeProperties();
  234. return InternalAnnotation;
  235. }
  236. /// <summary>
  237. /// Synchronizes the properties.
  238. /// </summary>
  239. public override void SynchronizeProperties()
  240. {
  241. base.SynchronizeProperties();
  242. var a = (Annotations.ArrowAnnotation)InternalAnnotation;
  243. a.StartPoint = StartPoint;
  244. a.EndPoint = EndPoint;
  245. a.ArrowDirection = ArrowDirection;
  246. a.HeadLength = HeadLength;
  247. a.HeadWidth = HeadWidth;
  248. a.Veeness = Veeness;
  249. a.Color = Color.ToOxyColor();
  250. a.StrokeThickness = StrokeThickness;
  251. a.LineStyle = LineStyle;
  252. a.LineJoin = LineJoin;
  253. }
  254. }
  255. }