ScatterErrorSeries.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. // --------------------------------------------------------------------------------------------------------------------
  2. // <copyright file="ScatterErrorSeries.cs" company="OxyPlot">
  3. // Copyright (c) 2014 OxyPlot contributors
  4. // </copyright>
  5. // <summary>
  6. // This is a Avalonia wrapper of OxyPlot.ScatterErrorSeries
  7. // </summary>
  8. // --------------------------------------------------------------------------------------------------------------------
  9. using Avalonia;
  10. namespace OxyPlot.Avalonia
  11. {
  12. using global::Avalonia.Media;
  13. using OxyPlot.Series;
  14. /// <summary>
  15. /// This is a Avalonia wrapper of OxyPlot.ScatterErrorSeries
  16. /// </summary>
  17. public class ScatterErrorSeries : ScatterSeries<ScatterErrorPoint>
  18. {
  19. /// <summary>
  20. /// Identifies the <see cref="DataFieldErrorX"/> dependency property.
  21. /// </summary>
  22. public static readonly StyledProperty<string> DataFieldErrorXProperty = AvaloniaProperty.Register<ScatterErrorSeries, string>(nameof(DataFieldErrorX), null);
  23. /// <summary>
  24. /// Identifies the <see cref="DataFieldErrorY"/> dependency property.
  25. /// </summary>
  26. public static readonly StyledProperty<string> DataFieldErrorYProperty = AvaloniaProperty.Register<ScatterErrorSeries, string>(nameof(DataFieldErrorY), null);
  27. /// <summary>
  28. /// Identifies the <see cref="ErrorBarColor"/> dependency property.
  29. /// </summary>
  30. public static readonly StyledProperty<Color> ErrorBarColorProperty = AvaloniaProperty.Register<ScatterErrorSeries, Color>(nameof(ErrorBarColor), Colors.Black);
  31. /// <summary>
  32. /// Identifies the <see cref="ErrorBarStopWidth"/> dependency property.
  33. /// </summary>
  34. public static readonly StyledProperty<double> ErrorBarStopWidthProperty = AvaloniaProperty.Register<ScatterErrorSeries, double>(nameof(ErrorBarStopWidth), 4.0);
  35. /// <summary>
  36. /// Identifies the <see cref="ErrorBarStrokeThickness"/> dependency property.
  37. /// </summary>
  38. public static readonly StyledProperty<double> ErrorBarStrokeThicknessProperty = AvaloniaProperty.Register<ScatterErrorSeries, double>(nameof(ErrorBarStrokeThickness), 1.0);
  39. /// <summary>
  40. /// Identifies the <see cref="MinimumErrorSize"/> dependency property.
  41. /// </summary>
  42. public static readonly StyledProperty<double> MinimumErrorSizeProperty = AvaloniaProperty.Register<ScatterErrorSeries, double>(nameof(MinimumErrorSize), 0d);
  43. /// <summary>
  44. /// Initializes a new instance of the <see cref="ScatterErrorSeries"/> class.
  45. /// </summary>
  46. public ScatterErrorSeries()
  47. {
  48. InternalSeries = new OxyPlot.Series.ScatterErrorSeries();
  49. }
  50. /// <summary>
  51. /// Gets or sets the data field X error.
  52. /// </summary>
  53. /// <value>
  54. /// The data field error.
  55. /// </value>
  56. public string DataFieldErrorX
  57. {
  58. get { return GetValue(DataFieldErrorXProperty); }
  59. set { SetValue(DataFieldErrorXProperty, value); }
  60. }
  61. /// <summary>
  62. /// Gets or sets the data field Y error.
  63. /// </summary>
  64. /// <value>
  65. /// The data field error.
  66. /// </value>
  67. public string DataFieldErrorY
  68. {
  69. get { return GetValue(DataFieldErrorYProperty); }
  70. set { SetValue(DataFieldErrorYProperty, value); }
  71. }
  72. /// <summary>
  73. /// Gets or sets the color of the error bar.
  74. /// </summary>
  75. /// <value>
  76. /// The color of the error bar.
  77. /// </value>
  78. public Color ErrorBarColor
  79. {
  80. get { return GetValue(ErrorBarColorProperty); }
  81. set { SetValue(ErrorBarColorProperty, value); }
  82. }
  83. /// <summary>
  84. /// Gets or sets the width of the error bar stop.
  85. /// </summary>
  86. /// <value>
  87. /// The width of the error bar stop.
  88. /// </value>
  89. public double ErrorBarStopWidth
  90. {
  91. get { return GetValue(ErrorBarStopWidthProperty); }
  92. set { SetValue(ErrorBarStopWidthProperty, value); }
  93. }
  94. /// <summary>
  95. /// Gets or sets the error bar stroke thickness.
  96. /// </summary>
  97. /// <value>
  98. /// The error bar stroke thickness.
  99. /// </value>
  100. public double ErrorBarStrokeThickness
  101. {
  102. get { return GetValue(ErrorBarStrokeThicknessProperty); }
  103. set { SetValue(ErrorBarStrokeThicknessProperty, value); }
  104. }
  105. /// <summary>
  106. /// Gets or sets the minimum size (relative to <see cref="ScatterSeries{T}.MarkerSize" />) of the error bars to be shown.
  107. /// </summary>
  108. public double MinimumErrorSize
  109. {
  110. get { return GetValue(MinimumErrorSizeProperty); }
  111. set { SetValue(MinimumErrorSizeProperty, value); }
  112. }
  113. /// <summary>
  114. /// Synchronizes the properties.
  115. /// </summary>
  116. /// <param name="series">The series.</param>
  117. protected override void SynchronizeProperties(OxyPlot.Series.Series series)
  118. {
  119. base.SynchronizeProperties(series);
  120. var s = (OxyPlot.Series.ScatterErrorSeries)series;
  121. s.DataFieldErrorX = DataFieldErrorX;
  122. s.DataFieldErrorY = DataFieldErrorY;
  123. s.ErrorBarColor = ErrorBarColor.ToOxyColor();
  124. s.ErrorBarStopWidth = ErrorBarStopWidth;
  125. s.ErrorBarStrokeThickness = ErrorBarStrokeThickness;
  126. s.MinimumErrorSize = MinimumErrorSize;
  127. }
  128. static ScatterErrorSeries()
  129. {
  130. DataFieldErrorXProperty.Changed.AddClassHandler<ScatterErrorSeries>(DataChanged);
  131. DataFieldErrorYProperty.Changed.AddClassHandler<ScatterErrorSeries>(DataChanged);
  132. ErrorBarColorProperty.Changed.AddClassHandler<ScatterErrorSeries>(AppearanceChanged);
  133. ErrorBarStopWidthProperty.Changed.AddClassHandler<ScatterErrorSeries>(AppearanceChanged);
  134. ErrorBarStrokeThicknessProperty.Changed.AddClassHandler<ScatterErrorSeries>(AppearanceChanged);
  135. MinimumErrorSizeProperty.Changed.AddClassHandler<ScatterErrorSeries>(AppearanceChanged);
  136. }
  137. }
  138. }