LinearBarSeries.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. // --------------------------------------------------------------------------------------------------------------------
  2. // <copyright file="LinearBarSeries.cs" company="OxyPlot">
  3. // Copyright (c) 2014 OxyPlot contributors
  4. // </copyright>
  5. // <summary>
  6. // This is a Avalonia wrapper of OxyPlot.Series.LinearBarSeries
  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.Series.LinearBarSeries
  15. /// </summary>
  16. public class LinearBarSeries : DataPointSeries
  17. {
  18. /// <summary>
  19. /// Identifies the <see cref="BarWidth" /> dependency property.
  20. /// </summary>
  21. public static readonly StyledProperty<double> BarWidthProperty = AvaloniaProperty.Register<LinearBarSeries, double>(nameof(BarWidth), 1.0);
  22. /// <summary>
  23. /// Identifies the <see cref="FillColor"/> dependency property.
  24. /// </summary>
  25. public static readonly StyledProperty<Color> FillColorProperty = AvaloniaProperty.Register<LinearBarSeries, Color>(nameof(FillColor), MoreColors.Automatic);
  26. /// <summary>
  27. /// Identifies the <see cref="StrokeColor" /> dependency property.
  28. /// </summary>
  29. public static readonly StyledProperty<Color> StrokeColorProperty = AvaloniaProperty.Register<LinearBarSeries, Color>(nameof(StrokeColor), Colors.Black);
  30. /// <summary>
  31. /// Identifies the <see cref="StrokeThickness"/> dependency property.
  32. /// </summary>
  33. public static readonly StyledProperty<double> StrokeThicknessProperty = AvaloniaProperty.Register<LinearBarSeries, double>(nameof(StrokeThickness), 1.0);
  34. /// <summary>
  35. /// Identifies the <see cref="NegativeFillColor"/> dependency property.
  36. /// </summary>
  37. public static readonly StyledProperty<Color> NegativeFillColorProperty = AvaloniaProperty.Register<LinearBarSeries, Color>(nameof(NegativeFillColor), MoreColors.Undefined);
  38. /// <summary>
  39. /// Identifies the <see cref="NegativeStrokeColor"/> dependency property.
  40. /// </summary>
  41. public static readonly StyledProperty<Color> NegativeStrokeColorProperty = AvaloniaProperty.Register<LinearBarSeries, Color>(nameof(NegativeStrokeColor), MoreColors.Undefined);
  42. /// <summary>
  43. /// Initializes a new instance of the <see cref="LinearBarSeries" /> class.
  44. /// </summary>
  45. public LinearBarSeries()
  46. {
  47. InternalSeries = new OxyPlot.Series.LinearBarSeries();
  48. }
  49. /// <summary>
  50. /// Gets or sets the bar width.
  51. /// </summary>
  52. public double BarWidth
  53. {
  54. get
  55. {
  56. return GetValue(BarWidthProperty);
  57. }
  58. set
  59. {
  60. SetValue(BarWidthProperty, value);
  61. }
  62. }
  63. /// <summary>
  64. /// Gets or sets the fill color.
  65. /// </summary>
  66. public Color FillColor
  67. {
  68. get
  69. {
  70. return GetValue(FillColorProperty);
  71. }
  72. set
  73. {
  74. SetValue(FillColorProperty, value);
  75. }
  76. }
  77. /// <summary>
  78. /// Gets or sets the stroke color.
  79. /// </summary>
  80. public Color StrokeColor
  81. {
  82. get
  83. {
  84. return GetValue(StrokeColorProperty);
  85. }
  86. set
  87. {
  88. SetValue(StrokeColorProperty, value);
  89. }
  90. }
  91. /// <summary>
  92. /// Gets or sets the stroke thickness.
  93. /// </summary>
  94. public double StrokeThickness
  95. {
  96. get
  97. {
  98. return GetValue(StrokeThicknessProperty);
  99. }
  100. set
  101. {
  102. SetValue(StrokeThicknessProperty, value);
  103. }
  104. }
  105. /// <summary>
  106. /// Gets or sets the negative fill color.
  107. /// </summary>
  108. public Color NegativeFillColor
  109. {
  110. get
  111. {
  112. return GetValue(NegativeFillColorProperty);
  113. }
  114. set
  115. {
  116. SetValue(NegativeFillColorProperty, value);
  117. }
  118. }
  119. /// <summary>
  120. /// Gets or sets the negative stroke color.
  121. /// </summary>
  122. public Color NegativeStrokeColor
  123. {
  124. get
  125. {
  126. return GetValue(NegativeStrokeColorProperty);
  127. }
  128. set
  129. {
  130. SetValue(NegativeStrokeColorProperty, value);
  131. }
  132. }
  133. /// <summary>
  134. /// Creates the internal series.
  135. /// </summary>
  136. /// <returns>The internal series.</returns>
  137. public override OxyPlot.Series.Series CreateModel()
  138. {
  139. SynchronizeProperties(InternalSeries);
  140. return InternalSeries;
  141. }
  142. /// <summary>
  143. /// Synchronizes the properties.
  144. /// </summary>
  145. /// <param name="series">The series.</param>
  146. protected override void SynchronizeProperties(OxyPlot.Series.Series series)
  147. {
  148. base.SynchronizeProperties(series);
  149. var s = (OxyPlot.Series.LinearBarSeries)series;
  150. s.BarWidth = BarWidth;
  151. s.FillColor = FillColor.ToOxyColor();
  152. s.StrokeColor = StrokeColor.ToOxyColor();
  153. s.StrokeThickness = StrokeThickness;
  154. s.NegativeFillColor = NegativeFillColor.ToOxyColor();
  155. s.NegativeStrokeColor = NegativeStrokeColor.ToOxyColor();
  156. }
  157. static LinearBarSeries()
  158. {
  159. BarWidthProperty.Changed.AddClassHandler<LinearBarSeries>(AppearanceChanged);
  160. FillColorProperty.Changed.AddClassHandler<LinearBarSeries>(AppearanceChanged);
  161. StrokeColorProperty.Changed.AddClassHandler<LinearBarSeries>(AppearanceChanged);
  162. StrokeThicknessProperty.Changed.AddClassHandler<LinearBarSeries>(AppearanceChanged);
  163. NegativeFillColorProperty.Changed.AddClassHandler<LinearBarSeries>(AppearanceChanged);
  164. NegativeStrokeColorProperty.Changed.AddClassHandler<LinearBarSeries>(AppearanceChanged);
  165. }
  166. }
  167. }