PolylineAnnotation.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. // --------------------------------------------------------------------------------------------------------------------
  2. // <copyright file="PolylineAnnotation.cs" company="OxyPlot">
  3. // Copyright (c) 2014 OxyPlot contributors
  4. // </copyright>
  5. // <summary>
  6. // This is a Avalonia wrapper of OxyPlot.PolylineAnnotation
  7. // </summary>
  8. // --------------------------------------------------------------------------------------------------------------------
  9. using Avalonia;
  10. namespace OxyPlot.Avalonia
  11. {
  12. using global::Avalonia.Layout;
  13. using System.Collections.Generic;
  14. /// <summary>
  15. /// This is a Avalonia wrapper of OxyPlot.PolylineAnnotation
  16. /// </summary>
  17. public class PolylineAnnotation : PathAnnotation
  18. {
  19. /// <summary>
  20. /// Identifies the <see cref="InterpolationAlgorithm"/> dependency property.
  21. /// </summary>
  22. public static readonly StyledProperty<IInterpolationAlgorithm> InterpolationAlgorithmProperty = AvaloniaProperty.Register<PolylineAnnotation, IInterpolationAlgorithm>(nameof(InterpolationAlgorithm), null);
  23. /// <summary>
  24. /// Identifies the <see cref="MinimumSegmentLength"/> dependency property.
  25. /// </summary>
  26. public static readonly StyledProperty<double> MinimumSegmentLengthProperty = AvaloniaProperty.Register<PolylineAnnotation, double>(nameof(MinimumSegmentLength), 0d);
  27. /// <summary>
  28. /// Identifies the <see cref="Points"/> dependency property.
  29. /// </summary>
  30. public static readonly StyledProperty<IList<DataPoint>> PointsProperty = AvaloniaProperty.Register<PolylineAnnotation, IList<DataPoint>>(nameof(Points), new List<DataPoint>());
  31. /// <summary>
  32. /// Initializes static members of the <see cref="PolylineAnnotation"/> class.
  33. /// </summary>
  34. static PolylineAnnotation()
  35. {
  36. TextColorProperty.OverrideDefaultValue<PolylineAnnotation>(MoreColors.Automatic);
  37. TextColorProperty.Changed.AddClassHandler<PolylineAnnotation>(AppearanceChanged);
  38. TextHorizontalAlignmentProperty.OverrideDefaultValue<PolylineAnnotation>(HorizontalAlignment.Right);
  39. TextHorizontalAlignmentProperty.Changed.AddClassHandler<PolylineAnnotation>(AppearanceChanged);
  40. TextVerticalAlignmentProperty.OverrideDefaultValue<PolylineAnnotation>(VerticalAlignment.Top);
  41. TextVerticalAlignmentProperty.Changed.AddClassHandler<PolylineAnnotation>(AppearanceChanged);
  42. InterpolationAlgorithmProperty.Changed.AddClassHandler<PolylineAnnotation>(DataChanged);
  43. PointsProperty.Changed.AddClassHandler<PolylineAnnotation>(DataChanged);
  44. }
  45. /// <summary>
  46. /// Initializes a new instance of the <see cref="PolylineAnnotation" /> class.
  47. /// </summary>
  48. public PolylineAnnotation()
  49. {
  50. this.InternalAnnotation = new Annotations.PolylineAnnotation();
  51. }
  52. /// <summary>
  53. /// Gets or sets the points.
  54. /// </summary>
  55. /// <value>The points.</value>
  56. public IList<DataPoint> Points
  57. {
  58. get
  59. {
  60. return GetValue(PointsProperty);
  61. }
  62. set
  63. {
  64. SetValue(PointsProperty, value);
  65. }
  66. }
  67. /// <summary>
  68. /// Gets or sets the minimum length of the segment.
  69. /// Increasing this number will increase performance,
  70. /// but make the curve less accurate.
  71. /// </summary>
  72. /// <value>The minimum length of the segment.</value>
  73. public double MinimumSegmentLength
  74. {
  75. get { return GetValue(MinimumSegmentLengthProperty); }
  76. set { SetValue(MinimumSegmentLengthProperty, value); }
  77. }
  78. /// <summary>
  79. /// Gets or sets the interpolation algorithm.
  80. /// </summary>
  81. /// <value>Interpolation algorithm.</value>
  82. public IInterpolationAlgorithm InterpolationAlgorithm
  83. {
  84. get { return this.GetValue(InterpolationAlgorithmProperty); }
  85. set { this.SetValue(InterpolationAlgorithmProperty, value); }
  86. }
  87. /// <summary>
  88. /// Creates the internal annotation object.
  89. /// </summary>
  90. /// <returns>The annotation.</returns>
  91. public override Annotations.Annotation CreateModel()
  92. {
  93. this.SynchronizeProperties();
  94. return this.InternalAnnotation;
  95. }
  96. /// <summary>
  97. /// Synchronizes the properties.
  98. /// </summary>
  99. public override void SynchronizeProperties()
  100. {
  101. base.SynchronizeProperties();
  102. var a = (Annotations.PolylineAnnotation)this.InternalAnnotation;
  103. a.Points.Clear();
  104. a.Points.AddRange(this.Points);
  105. a.InterpolationAlgorithm = this.InterpolationAlgorithm;
  106. a.MinimumSegmentLength = this.MinimumSegmentLength;
  107. }
  108. }
  109. }