TwoColorAreaSeries.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. // --------------------------------------------------------------------------------------------------------------------
  2. // <copyright file="TwoColorAreaSeries.cs" company="OxyPlot">
  3. // Copyright (c) 2014 OxyPlot contributors
  4. // </copyright>
  5. // <summary>
  6. // The Avalonia wrapper for OxyPlot.TwoColorAreaSeries.
  7. // </summary>
  8. // --------------------------------------------------------------------------------------------------------------------
  9. using Avalonia;
  10. using System.Linq;
  11. namespace OxyPlot.Avalonia
  12. {
  13. using global::Avalonia.Media;
  14. /// <summary>
  15. /// The Avalonia wrapper for OxyPlot.TwoColorAreaSeries.
  16. /// </summary>
  17. public class TwoColorAreaSeries : AreaSeries
  18. {
  19. /// <summary>
  20. /// Identifies the <see cref="Dashes2"/> dependency property.
  21. /// </summary>
  22. public static readonly StyledProperty<double[]> Dashes2Property = AvaloniaProperty.Register<TwoColorAreaSeries, double[]>(nameof(Dashes2));
  23. /// <summary>
  24. /// Identifies the <see cref="Fill"/> dependency property.
  25. /// </summary>
  26. public static readonly StyledProperty<Color> FillProperty = AvaloniaProperty.Register<TwoColorAreaSeries, Color>(nameof(Fill), MoreColors.Automatic);
  27. /// <summary>
  28. /// Identifies the <see cref="Fill2"/> dependency property.
  29. /// </summary>
  30. public static readonly StyledProperty<Color> Fill2Property = AvaloniaProperty.Register<TwoColorAreaSeries, Color>(nameof(Fill2), MoreColors.Automatic);
  31. /// <summary>
  32. /// Identifies the <see cref="LineStyle2"/> dependency property.
  33. /// </summary>
  34. public static readonly StyledProperty<LineStyle> LineStyle2Property = AvaloniaProperty.Register<TwoColorAreaSeries, LineStyle>(nameof(LineStyle2));
  35. /// <summary>
  36. /// Identifies the <see cref="Limit"/> dependency property.
  37. /// </summary>
  38. public static readonly AvaloniaProperty LimitProperty = AvaloniaProperty.Register<TwoColorAreaSeries, double>(nameof(Limit));
  39. /// <summary>
  40. /// Identifies the <see cref="MarkerFill2"/> dependency property.
  41. /// </summary>
  42. public static readonly StyledProperty<Color> MarkerFill2Property = AvaloniaProperty.Register<TwoColorAreaSeries, Color>(nameof(MarkerFill2), MoreColors.Automatic);
  43. /// <summary>
  44. /// Identifies the <see cref="MarkerStroke2"/> dependency property.
  45. /// </summary>
  46. public static readonly StyledProperty<Color> MarkerStroke2Property = AvaloniaProperty.Register<TwoColorAreaSeries, Color>(nameof(MarkerStroke2), MoreColors.Automatic);
  47. /// <summary>
  48. /// Initializes a new instance of the <see cref = "TwoColorAreaSeries" /> class.
  49. /// </summary>
  50. public TwoColorAreaSeries()
  51. {
  52. InternalSeries = new OxyPlot.Series.TwoColorAreaSeries();
  53. }
  54. /// <summary>
  55. /// Gets or sets the dash array for the rendered line that is below the limit (overrides <see cref="LineStyle" />).
  56. /// </summary>
  57. public double[] Dashes2
  58. {
  59. get
  60. {
  61. return GetValue(Dashes2Property);
  62. }
  63. set
  64. {
  65. SetValue(Dashes2Property, value);
  66. }
  67. }
  68. /// <summary>
  69. /// Gets or sets Fill above the limit line.
  70. /// </summary>
  71. public Color Fill
  72. {
  73. get
  74. {
  75. return GetValue(FillProperty);
  76. }
  77. set
  78. {
  79. SetValue(FillProperty, value);
  80. }
  81. }
  82. /// <summary>
  83. /// Gets or sets Fill below the limit line.
  84. /// </summary>
  85. public Color Fill2
  86. {
  87. get
  88. {
  89. return GetValue(Fill2Property);
  90. }
  91. set
  92. {
  93. SetValue(Fill2Property, value);
  94. }
  95. }
  96. /// <summary>
  97. /// Gets or sets Marker Fill which is below the limit line.
  98. /// </summary>
  99. public Color MarkerFill2
  100. {
  101. get
  102. {
  103. return GetValue(MarkerFill2Property);
  104. }
  105. set
  106. {
  107. SetValue(MarkerFill2Property, value);
  108. }
  109. }
  110. /// <summary>
  111. /// Gets or sets Marker Stroke which is below the limit line.
  112. /// </summary>
  113. public Color MarkerStroke2
  114. {
  115. get
  116. {
  117. return GetValue(MarkerStroke2Property);
  118. }
  119. set
  120. {
  121. SetValue(MarkerStroke2Property, value);
  122. }
  123. }
  124. /// <summary>
  125. /// Gets or sets the line style for the part of the line that is below the limit.
  126. /// </summary>
  127. public LineStyle LineStyle2
  128. {
  129. get
  130. {
  131. return (LineStyle)this.GetValue(LineStyle2Property);
  132. }
  133. set
  134. {
  135. this.SetValue(LineStyle2Property, value);
  136. }
  137. }
  138. /// <summary>
  139. /// Gets or sets a baseline for the series.
  140. /// </summary>
  141. public double Limit
  142. {
  143. get
  144. {
  145. return (double)this.GetValue(LimitProperty);
  146. }
  147. set
  148. {
  149. this.SetValue(LimitProperty, value);
  150. }
  151. }
  152. /// <summary>
  153. /// Synchronizes the properties.
  154. /// </summary>
  155. /// <param name="series">The series.</param>
  156. protected override void SynchronizeProperties(OxyPlot.Series.Series series)
  157. {
  158. base.SynchronizeProperties(series);
  159. var s = (OxyPlot.Series.TwoColorAreaSeries)series;
  160. s.Fill = Fill.ToOxyColor();
  161. s.Fill2 = Fill2.ToOxyColor();
  162. s.MarkerFill2 = MarkerFill2.ToOxyColor();
  163. s.MarkerStroke2 = MarkerStroke2.ToOxyColor();
  164. s.Limit = Limit;
  165. s.Dashes2 = Dashes2?.ToArray();
  166. s.LineStyle2 = LineStyle2;
  167. }
  168. static TwoColorAreaSeries()
  169. {
  170. FillProperty.Changed.AddClassHandler<TwoColorAreaSeries>(AppearanceChanged);
  171. Fill2Property.Changed.AddClassHandler<TwoColorAreaSeries>(AppearanceChanged);
  172. MarkerFill2Property.Changed.AddClassHandler<TwoColorAreaSeries>(AppearanceChanged);
  173. MarkerStroke2Property.Changed.AddClassHandler<TwoColorAreaSeries>(AppearanceChanged);
  174. LimitProperty.Changed.AddClassHandler<TwoColorAreaSeries>(AppearanceChanged);
  175. Dashes2Property.Changed.AddClassHandler<TwoColorAreaSeries>(AppearanceChanged);
  176. LineStyle2Property.Changed.AddClassHandler<TwoColorAreaSeries>(AppearanceChanged);
  177. }
  178. }
  179. }