HeatMapSeries.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. // --------------------------------------------------------------------------------------------------------------------
  2. // <copyright file="HeatMapSeries.cs" company="OxyPlot">
  3. // Copyright (c) 2014 OxyPlot contributors
  4. // </copyright>
  5. // <summary>
  6. // HeatMapSeries Avalonia wrapper
  7. // </summary>
  8. // --------------------------------------------------------------------------------------------------------------------
  9. using Avalonia;
  10. namespace OxyPlot.Avalonia
  11. {
  12. using global::Avalonia.Media;
  13. /// <summary>
  14. /// HeatMapSeries Avalonia wrapper
  15. /// </summary>
  16. public class HeatMapSeries : XYAxisSeries
  17. {
  18. /// <summary>
  19. /// Identifies this <see cref="DataProperty"/> dependency property.
  20. /// </summary>
  21. public static readonly StyledProperty<double[,]> DataProperty = AvaloniaProperty.Register<HeatMapSeries, double[,]>(nameof(Data), new double[0, 0], validate: val => val != null);
  22. /// <summary>
  23. /// Identifies this <see cref="X0Property"/> dependency property.
  24. /// </summary>
  25. public static readonly StyledProperty<double> X0Property = AvaloniaProperty.Register<HeatMapSeries, double>(nameof(X0), default);
  26. /// <summary>
  27. /// Identifies this <see cref="X1Property"/> dependency property.
  28. /// </summary>
  29. public static readonly StyledProperty<double> X1Property = AvaloniaProperty.Register<HeatMapSeries, double>(nameof(X1), default);
  30. /// <summary>
  31. /// Identifies this <see cref="Y0Property"/> dependency property.
  32. /// </summary>
  33. public static readonly StyledProperty<double> Y0Property = AvaloniaProperty.Register<HeatMapSeries, double>(nameof(Y0), default);
  34. /// <summary>
  35. /// Identifies this <see cref="Y1Property"/> dependency property.
  36. /// </summary>
  37. public static readonly StyledProperty<double> Y1Property = AvaloniaProperty.Register<HeatMapSeries, double>(nameof(Y1), default);
  38. /// <summary>
  39. /// Identifies this <see cref="ColorAxisKeyProperty"/> dependency property.
  40. /// </summary>
  41. public static readonly StyledProperty<string> ColorAxisKeyProperty = AvaloniaProperty.Register<HeatMapSeries, string>(nameof(ColorAxisKey), default);
  42. /// <summary>
  43. /// Identifies this <see cref="LowColorProperty"/> dependency property.
  44. /// </summary>
  45. public static readonly StyledProperty<Color> LowColorProperty = AvaloniaProperty.Register<HeatMapSeries, Color>(nameof(LowColor), default);
  46. /// <summary>
  47. /// Identifies this <see cref="HighColorProperty"/> dependency property.
  48. /// </summary>
  49. public static readonly StyledProperty<Color> HighColorProperty = AvaloniaProperty.Register<HeatMapSeries, Color>(nameof(HighColor), default);
  50. /// <summary>
  51. /// Initializes static members of the <see cref="HeatMapSeries"/> class.
  52. /// </summary>
  53. static HeatMapSeries()
  54. {
  55. TrackerFormatStringProperty.OverrideMetadata(typeof(HeatMapSeries), new StyledPropertyMetadata<string>(OxyPlot.Series.HeatMapSeries.DefaultTrackerFormatString));
  56. DataProperty.Changed.AddClassHandler<HeatMapSeries>(DataChanged);
  57. X0Property.Changed.AddClassHandler<HeatMapSeries>(AppearanceChanged);
  58. X1Property.Changed.AddClassHandler<HeatMapSeries>(AppearanceChanged);
  59. Y0Property.Changed.AddClassHandler<HeatMapSeries>(AppearanceChanged);
  60. Y1Property.Changed.AddClassHandler<HeatMapSeries>(AppearanceChanged);
  61. TrackerFormatStringProperty.Changed.AddClassHandler<HeatMapSeries>(AppearanceChanged);
  62. }
  63. /// <summary>
  64. /// Initializes a new instance of the <see cref = "HeatMapSeries" /> class.
  65. /// </summary>
  66. public HeatMapSeries()
  67. {
  68. Data = new double[0, 0];
  69. InternalSeries = new OxyPlot.Series.HeatMapSeries { Data = Data };
  70. }
  71. /// <summary>
  72. /// Gets or sets LowColor
  73. /// </summary>
  74. public Color LowColor
  75. {
  76. get
  77. {
  78. return GetValue(LowColorProperty);
  79. }
  80. set
  81. {
  82. SetValue(LowColorProperty, value);
  83. }
  84. }
  85. /// <summary>
  86. /// Gets or sets HighColor
  87. /// </summary>
  88. public Color HighColor
  89. {
  90. get
  91. {
  92. return GetValue(LowColorProperty);
  93. }
  94. set
  95. {
  96. SetValue(LowColorProperty, value);
  97. }
  98. }
  99. /// <summary>
  100. /// Gets or sets ColorAxisKey property.
  101. /// </summary>
  102. public string ColorAxisKey
  103. {
  104. get
  105. {
  106. return GetValue(ColorAxisKeyProperty);
  107. }
  108. set
  109. {
  110. SetValue(ColorAxisKeyProperty, value);
  111. }
  112. }
  113. /// <summary>
  114. /// Gets or sets X0.
  115. /// </summary>
  116. public double X0
  117. {
  118. get
  119. {
  120. return GetValue(X0Property);
  121. }
  122. set
  123. {
  124. SetValue(X0Property, value);
  125. }
  126. }
  127. /// <summary>
  128. /// Gets or sets X1
  129. /// </summary>
  130. public double X1
  131. {
  132. get
  133. {
  134. return GetValue(X1Property);
  135. }
  136. set
  137. {
  138. SetValue(X1Property, value);
  139. }
  140. }
  141. /// <summary>
  142. /// Gets or sets Y0
  143. /// </summary>
  144. public double Y0
  145. {
  146. get
  147. {
  148. return GetValue(Y0Property);
  149. }
  150. set
  151. {
  152. SetValue(Y0Property, value);
  153. }
  154. }
  155. /// <summary>
  156. /// Gets or sets Y1
  157. /// </summary>
  158. public double Y1
  159. {
  160. get
  161. {
  162. return GetValue(Y1Property);
  163. }
  164. set
  165. {
  166. SetValue(Y1Property, value);
  167. }
  168. }
  169. /// <summary>
  170. /// Gets or sets Data
  171. /// </summary>
  172. public double[,] Data
  173. {
  174. get
  175. {
  176. return GetValue(DataProperty);
  177. }
  178. set
  179. {
  180. SetValue(DataProperty, value);
  181. }
  182. }
  183. /// <summary>
  184. /// The create model.
  185. /// </summary>
  186. /// <returns>
  187. /// The <see cref="Series"/>.
  188. /// </returns>
  189. public override OxyPlot.Series.Series CreateModel()
  190. {
  191. SynchronizeProperties(InternalSeries);
  192. return InternalSeries;
  193. }
  194. /// <summary>
  195. /// The synchronize properties.
  196. /// </summary>
  197. /// <param name="series">
  198. /// The series.
  199. /// </param>
  200. protected override void SynchronizeProperties(OxyPlot.Series.Series series)
  201. {
  202. base.SynchronizeProperties(series);
  203. var s = (OxyPlot.Series.HeatMapSeries)series;
  204. s.Data = Data ?? new double[0, 0];
  205. s.X0 = X0;
  206. s.X1 = X1;
  207. s.Y0 = Y0;
  208. s.Y1 = Y1;
  209. }
  210. }
  211. }