LineAnnotation.cs 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. // --------------------------------------------------------------------------------------------------------------------
  2. // <copyright file="LineAnnotation.cs" company="OxyPlot">
  3. // Copyright (c) 2014 OxyPlot contributors
  4. // </copyright>
  5. // <summary>
  6. // This is a Avalonia wrapper of OxyPlot.LineAnnotation
  7. // </summary>
  8. // --------------------------------------------------------------------------------------------------------------------
  9. using Avalonia;
  10. namespace OxyPlot.Avalonia
  11. {
  12. using global::Avalonia.Layout;
  13. using OxyPlot.Annotations;
  14. /// <summary>
  15. /// This is a Avalonia wrapper of OxyPlot.LineAnnotation
  16. /// </summary>
  17. public class LineAnnotation : PathAnnotation
  18. {
  19. /// <summary>
  20. /// Identifies the <see cref="Type"/> dependency property.
  21. /// </summary>
  22. public static readonly StyledProperty<LineAnnotationType> TypeProperty = AvaloniaProperty.Register<LineAnnotation, LineAnnotationType>(nameof(Type), LineAnnotationType.LinearEquation);
  23. /// <summary>
  24. /// Identifies the <see cref="Intercept"/> dependency property.
  25. /// </summary>
  26. public static readonly StyledProperty<double> InterceptProperty = AvaloniaProperty.Register<LineAnnotation, double>(nameof(Intercept), 0.0);
  27. /// <summary>
  28. /// Identifies the <see cref="MaximumX"/> dependency property.
  29. /// </summary>
  30. public static readonly StyledProperty<double> MaximumXProperty = AvaloniaProperty.Register<LineAnnotation, double>(nameof(MaximumX), double.MaxValue);
  31. /// <summary>
  32. /// Identifies the <see cref="MaximumY"/> dependency property.
  33. /// </summary>
  34. public static readonly StyledProperty<double> MaximumYProperty = AvaloniaProperty.Register<LineAnnotation, double>(nameof(MaximumY), double.MaxValue);
  35. /// <summary>
  36. /// Identifies the <see cref="MinimumX"/> dependency property.
  37. /// </summary>
  38. public static readonly StyledProperty<double> MinimumXProperty = AvaloniaProperty.Register<LineAnnotation, double>(nameof(MinimumX), double.MinValue);
  39. /// <summary>
  40. /// Identifies the <see cref="MinimumY"/> dependency property.
  41. /// </summary>
  42. public static readonly StyledProperty<double> MinimumYProperty = AvaloniaProperty.Register<LineAnnotation, double>(nameof(MinimumY), double.MinValue);
  43. /// <summary>
  44. /// Identifies the <see cref="Slope"/> dependency property.
  45. /// </summary>
  46. public static readonly StyledProperty<double> SlopeProperty = AvaloniaProperty.Register<LineAnnotation, double>(nameof(Slope), 0.0);
  47. /// <summary>
  48. /// Identifies the <see cref="X"/> dependency property.
  49. /// </summary>
  50. public static readonly StyledProperty<double> XProperty = AvaloniaProperty.Register<LineAnnotation, double>(nameof(X), 0.0);
  51. /// <summary>
  52. /// Identifies the <see cref="Y"/> dependency property.
  53. /// </summary>
  54. public static readonly StyledProperty<double> YProperty = AvaloniaProperty.Register<LineAnnotation, double>(nameof(Y), 0.0);
  55. /// <summary>
  56. /// Initializes static members of the <see cref="LineAnnotation"/> class.
  57. /// </summary>
  58. static LineAnnotation()
  59. {
  60. TextColorProperty.OverrideDefaultValue<LineAnnotation>(MoreColors.Automatic);
  61. TextColorProperty.Changed.AddClassHandler<LineAnnotation>(AppearanceChanged);
  62. TextHorizontalAlignmentProperty.OverrideDefaultValue<LineAnnotation>(HorizontalAlignment.Right);
  63. TextHorizontalAlignmentProperty.Changed.AddClassHandler<LineAnnotation>(AppearanceChanged);
  64. TextVerticalAlignmentProperty.OverrideDefaultValue<LineAnnotation>(VerticalAlignment.Top);
  65. TextVerticalAlignmentProperty.Changed.AddClassHandler<LineAnnotation>(AppearanceChanged);
  66. TypeProperty.Changed.AddClassHandler<LineAnnotation>(DataChanged);
  67. InterceptProperty.Changed.AddClassHandler<LineAnnotation>(DataChanged);
  68. MaximumXProperty.Changed.AddClassHandler<LineAnnotation>(DataChanged);
  69. MaximumYProperty.Changed.AddClassHandler<LineAnnotation>(DataChanged);
  70. MinimumXProperty.Changed.AddClassHandler<LineAnnotation>(DataChanged);
  71. MinimumYProperty.Changed.AddClassHandler<LineAnnotation>(DataChanged);
  72. SlopeProperty.Changed.AddClassHandler<LineAnnotation>(DataChanged);
  73. XProperty.Changed.AddClassHandler<LineAnnotation>(DataChanged);
  74. YProperty.Changed.AddClassHandler<LineAnnotation>(DataChanged);
  75. }
  76. /// <summary>
  77. /// Initializes a new instance of the <see cref = "LineAnnotation" /> class.
  78. /// </summary>
  79. public LineAnnotation()
  80. {
  81. InternalAnnotation = new Annotations.LineAnnotation();
  82. }
  83. /// <summary>
  84. /// Gets or sets Intercept.
  85. /// </summary>
  86. public double Intercept
  87. {
  88. get
  89. {
  90. return GetValue(InterceptProperty);
  91. }
  92. set
  93. {
  94. SetValue(InterceptProperty, value);
  95. }
  96. }
  97. /// <summary>
  98. /// Gets or sets MaximumX.
  99. /// </summary>
  100. public double MaximumX
  101. {
  102. get
  103. {
  104. return GetValue(MaximumXProperty);
  105. }
  106. set
  107. {
  108. SetValue(MaximumXProperty, value);
  109. }
  110. }
  111. /// <summary>
  112. /// Gets or sets MaximumY.
  113. /// </summary>
  114. public double MaximumY
  115. {
  116. get
  117. {
  118. return GetValue(MaximumYProperty);
  119. }
  120. set
  121. {
  122. SetValue(MaximumYProperty, value);
  123. }
  124. }
  125. /// <summary>
  126. /// Gets or sets MinimumX.
  127. /// </summary>
  128. public double MinimumX
  129. {
  130. get
  131. {
  132. return GetValue(MinimumXProperty);
  133. }
  134. set
  135. {
  136. SetValue(MinimumXProperty, value);
  137. }
  138. }
  139. /// <summary>
  140. /// Gets or sets MinimumY.
  141. /// </summary>
  142. public double MinimumY
  143. {
  144. get
  145. {
  146. return GetValue(MinimumYProperty);
  147. }
  148. set
  149. {
  150. SetValue(MinimumYProperty, value);
  151. }
  152. }
  153. /// <summary>
  154. /// Gets or sets Slope.
  155. /// </summary>
  156. public double Slope
  157. {
  158. get
  159. {
  160. return GetValue(SlopeProperty);
  161. }
  162. set
  163. {
  164. SetValue(SlopeProperty, value);
  165. }
  166. }
  167. /// <summary>
  168. /// Gets or sets Type.
  169. /// </summary>
  170. public LineAnnotationType Type
  171. {
  172. get
  173. {
  174. return GetValue(TypeProperty);
  175. }
  176. set
  177. {
  178. SetValue(TypeProperty, value);
  179. }
  180. }
  181. /// <summary>
  182. /// Gets or sets X.
  183. /// </summary>
  184. public double X
  185. {
  186. get
  187. {
  188. return GetValue(XProperty);
  189. }
  190. set
  191. {
  192. SetValue(XProperty, value);
  193. }
  194. }
  195. /// <summary>
  196. /// Gets or sets Y.
  197. /// </summary>
  198. public double Y
  199. {
  200. get
  201. {
  202. return GetValue(YProperty);
  203. }
  204. set
  205. {
  206. SetValue(YProperty, value);
  207. }
  208. }
  209. /// <summary>
  210. /// Creates the internal annotation object.
  211. /// </summary>
  212. /// <returns>The annotation.</returns>
  213. public override Annotations.Annotation CreateModel()
  214. {
  215. SynchronizeProperties();
  216. return InternalAnnotation;
  217. }
  218. /// <summary>
  219. /// Synchronizes the properties.
  220. /// </summary>
  221. public override void SynchronizeProperties()
  222. {
  223. base.SynchronizeProperties();
  224. var a = (Annotations.LineAnnotation)InternalAnnotation;
  225. a.Type = Type;
  226. a.Slope = Slope;
  227. a.Intercept = Intercept;
  228. a.X = X;
  229. a.Y = Y;
  230. a.MinimumX = MinimumX;
  231. a.MaximumX = MaximumX;
  232. a.MinimumY = MinimumY;
  233. a.MaximumY = MaximumY;
  234. }
  235. }
  236. }