ThreeColorLineSeries.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. // --------------------------------------------------------------------------------------------------------------------
  2. // <copyright file="ThreeColorLineSeries.cs" company="OxyPlot">
  3. // Copyright (c) 2014 OxyPlot contributors
  4. // </copyright>
  5. // <summary>
  6. // The Avalonia wrapper for OxyPlot.ThreeColorLineSeries.
  7. // </summary>
  8. // --------------------------------------------------------------------------------------------------------------------
  9. using Avalonia;
  10. namespace OxyPlot.Avalonia
  11. {
  12. using global::Avalonia.Media;
  13. /// <summary>
  14. /// The Avalonia wrapper for OxyPlot.ThreeColorLineSeries.
  15. /// </summary>
  16. public class ThreeColorLineSeries : LineSeries
  17. {
  18. /// <summary>
  19. /// Identifies the <see cref="ColorLo"/> dependency property.
  20. /// </summary>
  21. public static readonly StyledProperty<Color> ColorLoProperty = AvaloniaProperty.Register<ThreeColorLineSeries, Color>(nameof(ColorLo), Colors.Blue);
  22. /// <summary>
  23. /// Identifies the <see cref="ColorHi"/> dependency property.
  24. /// </summary>
  25. public static readonly StyledProperty<Color> ColorHiProperty = AvaloniaProperty.Register<ThreeColorLineSeries, Color>(nameof(ColorHi), Colors.Red);
  26. /// <summary>
  27. /// Identifies the <see cref="LimitLo"/> dependency property.
  28. /// </summary>
  29. public static readonly StyledProperty<double> LimitLoProperty = AvaloniaProperty.Register<ThreeColorLineSeries, double>(nameof(LimitLo), 0.0);
  30. /// <summary>
  31. /// Identifies the <see cref="LimitHi"/> dependency property.
  32. /// </summary>
  33. public static readonly StyledProperty<double> LimitHiProperty = AvaloniaProperty.Register<ThreeColorLineSeries, double>(nameof(LimitHi), 0.0);
  34. /// <summary>
  35. /// Identifies the <see cref="LineStyleLo"/> dependency property.
  36. /// </summary>
  37. public static readonly StyledProperty<LineStyle> LineStyleLoProperty = AvaloniaProperty.Register<ThreeColorLineSeries, LineStyle>(nameof(LineStyleLo), LineStyle.Solid);
  38. /// <summary>
  39. /// Identifies the <see cref="LineStyleHi"/> dependency property.
  40. /// </summary>
  41. public static readonly StyledProperty<LineStyle> LineStyleHiProperty = AvaloniaProperty.Register<ThreeColorLineSeries, LineStyle>(nameof(LineStyleHi), LineStyle.Solid);
  42. /// <summary>
  43. /// Initializes a new instance of the <see cref = "ThreeColorLineSeries" /> class.
  44. /// </summary>
  45. public ThreeColorLineSeries()
  46. {
  47. InternalSeries = new OxyPlot.Series.ThreeColorLineSeries();
  48. }
  49. /// <summary>
  50. /// Gets or sets ColorLo.
  51. /// </summary>
  52. public Color ColorLo
  53. {
  54. get
  55. {
  56. return GetValue(ColorLoProperty);
  57. }
  58. set
  59. {
  60. SetValue(ColorLoProperty, value);
  61. }
  62. }
  63. /// <summary>
  64. /// Gets or sets ColorHi.
  65. /// </summary>
  66. public Color ColorHi
  67. {
  68. get
  69. {
  70. return GetValue(ColorHiProperty);
  71. }
  72. set
  73. {
  74. SetValue(ColorHiProperty, value);
  75. }
  76. }
  77. /// <summary>
  78. /// Gets or sets LimitLo.
  79. /// </summary>
  80. public double LimitLo
  81. {
  82. get
  83. {
  84. return GetValue(LimitLoProperty);
  85. }
  86. set
  87. {
  88. SetValue(LimitLoProperty, value);
  89. }
  90. }
  91. /// <summary>
  92. /// Gets or sets LimitHi.
  93. /// </summary>
  94. public double LimitHi
  95. {
  96. get
  97. {
  98. return GetValue(LimitHiProperty);
  99. }
  100. set
  101. {
  102. SetValue(LimitHiProperty, value);
  103. }
  104. }
  105. /// <summary>
  106. /// Gets or sets LineStyleLo.
  107. /// </summary>
  108. public LineStyle LineStyleLo
  109. {
  110. get
  111. {
  112. return GetValue(LineStyleLoProperty);
  113. }
  114. set
  115. {
  116. SetValue(LineStyleLoProperty, value);
  117. }
  118. }
  119. /// <summary>
  120. /// Gets or sets LineStyleHi.
  121. /// </summary>
  122. public LineStyle LineStyleHi
  123. {
  124. get
  125. {
  126. return GetValue(LineStyleHiProperty);
  127. }
  128. set
  129. {
  130. SetValue(LineStyleHiProperty, value);
  131. }
  132. }
  133. /// <summary>
  134. /// Synchronizes the properties.
  135. /// </summary>
  136. /// <param name="series">The series.</param>
  137. protected override void SynchronizeProperties(OxyPlot.Series.Series series)
  138. {
  139. base.SynchronizeProperties(series);
  140. var s = (OxyPlot.Series.ThreeColorLineSeries)series;
  141. s.LimitLo = LimitLo;
  142. s.ColorLo = ColorLo.ToOxyColor();
  143. s.LimitHi = LimitHi;
  144. s.ColorHi = ColorHi.ToOxyColor();
  145. }
  146. static ThreeColorLineSeries()
  147. {
  148. ColorLoProperty.Changed.AddClassHandler<ThreeColorLineSeries>(AppearanceChanged);
  149. ColorHiProperty.Changed.AddClassHandler<ThreeColorLineSeries>(AppearanceChanged);
  150. LimitLoProperty.Changed.AddClassHandler<ThreeColorLineSeries>(AppearanceChanged);
  151. LimitHiProperty.Changed.AddClassHandler<ThreeColorLineSeries>(AppearanceChanged);
  152. LineStyleLoProperty.Changed.AddClassHandler<ThreeColorLineSeries>(AppearanceChanged);
  153. LineStyleHiProperty.Changed.AddClassHandler<ThreeColorLineSeries>(AppearanceChanged);
  154. }
  155. }
  156. }