DataPointSeries.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. // --------------------------------------------------------------------------------------------------------------------
  2. // <copyright file="DataPointSeries.cs" company="OxyPlot">
  3. // Copyright (c) 2014 OxyPlot contributors
  4. // </copyright>
  5. // <summary>
  6. // Base class for data series
  7. // </summary>
  8. // --------------------------------------------------------------------------------------------------------------------
  9. using Avalonia;
  10. namespace OxyPlot.Avalonia
  11. {
  12. using System;
  13. /// <summary>
  14. /// Base class for data series
  15. /// </summary>
  16. public abstract class DataPointSeries : XYAxisSeries
  17. {
  18. /// <summary>
  19. /// Identifies the <see cref="CanTrackerInterpolatePoints"/> dependency property.
  20. /// </summary>
  21. public static readonly StyledProperty<bool> CanTrackerInterpolatePointsProperty = AvaloniaProperty.Register<DataPointSeries, bool>(nameof(CanTrackerInterpolatePoints), false);
  22. /// <summary>
  23. /// Identifies the <see cref="DataFieldX"/> dependency property.
  24. /// </summary>
  25. public static readonly StyledProperty<string> DataFieldXProperty = AvaloniaProperty.Register<DataPointSeries, string>(nameof(DataFieldX), null);
  26. /// <summary>
  27. /// Identifies the <see cref="DataFieldY"/> dependency property.
  28. /// </summary>
  29. public static readonly StyledProperty<string> DataFieldYProperty = AvaloniaProperty.Register<DataPointSeries, string>(nameof(DataFieldY), null);
  30. /// <summary>
  31. /// Identifies the <see cref="Mapping"/> dependency property.
  32. /// </summary>
  33. public static readonly StyledProperty<Func<object, DataPoint>> MappingProperty = AvaloniaProperty.Register<DataPointSeries, Func<object, DataPoint>>(nameof(Mapping));
  34. /// <summary>
  35. /// Gets or sets a value indicating whether the tracker can interpolate points.
  36. /// </summary>
  37. public bool CanTrackerInterpolatePoints
  38. {
  39. get
  40. {
  41. return GetValue(CanTrackerInterpolatePointsProperty);
  42. }
  43. set
  44. {
  45. SetValue(CanTrackerInterpolatePointsProperty, value);
  46. }
  47. }
  48. /// <summary>
  49. /// Gets or sets DataFieldX.
  50. /// </summary>
  51. public string DataFieldX
  52. {
  53. get
  54. {
  55. return GetValue(DataFieldXProperty);
  56. }
  57. set
  58. {
  59. SetValue(DataFieldXProperty, value);
  60. }
  61. }
  62. /// <summary>
  63. /// Gets or sets DataFieldY.
  64. /// </summary>
  65. public string DataFieldY
  66. {
  67. get
  68. {
  69. return GetValue(DataFieldYProperty);
  70. }
  71. set
  72. {
  73. SetValue(DataFieldYProperty, value);
  74. }
  75. }
  76. /// <summary>
  77. /// Gets or sets the mapping.
  78. /// </summary>
  79. /// <value>The mapping.</value>
  80. public Func<object, DataPoint> Mapping
  81. {
  82. get
  83. {
  84. return GetValue(MappingProperty);
  85. }
  86. set
  87. {
  88. SetValue(MappingProperty, value);
  89. }
  90. }
  91. /// <summary>
  92. /// Synchronizes the properties.
  93. /// </summary>
  94. /// <param name="series">The series.</param>
  95. protected override void SynchronizeProperties(OxyPlot.Series.Series series)
  96. {
  97. base.SynchronizeProperties(series);
  98. var s = (OxyPlot.Series.DataPointSeries)series;
  99. s.ItemsSource = Items;
  100. s.DataFieldX = DataFieldX;
  101. s.DataFieldY = DataFieldY;
  102. s.CanTrackerInterpolatePoints = CanTrackerInterpolatePoints;
  103. s.Mapping = Mapping;
  104. }
  105. static DataPointSeries()
  106. {
  107. CanTrackerInterpolatePointsProperty.Changed.AddClassHandler<DataPointSeries>(AppearanceChanged);
  108. DataFieldXProperty.Changed.AddClassHandler<DataPointSeries>(DataChanged);
  109. DataFieldYProperty.Changed.AddClassHandler<DataPointSeries>(DataChanged);
  110. }
  111. }
  112. }