FunctionAnnotation.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. // --------------------------------------------------------------------------------------------------------------------
  2. // <copyright file="FunctionAnnotation.cs" company="OxyPlot">
  3. // Copyright (c) 2014 OxyPlot contributors
  4. // </copyright>
  5. // <summary>
  6. // This is a Avalonia wrapper of OxyPlot.PathAnnotation
  7. // </summary>
  8. // --------------------------------------------------------------------------------------------------------------------
  9. using Avalonia;
  10. namespace OxyPlot.Avalonia
  11. {
  12. using global::Avalonia.Layout;
  13. using OxyPlot.Annotations;
  14. using System;
  15. /// <summary>
  16. /// This is a Avalonia wrapper of OxyPlot.PathAnnotation
  17. /// </summary>
  18. public class FunctionAnnotation : PathAnnotation
  19. {
  20. /// <summary>
  21. /// Identifies the <see cref="Type"/> dependency property.
  22. /// </summary>
  23. public static readonly StyledProperty<FunctionAnnotationType> TypeProperty = AvaloniaProperty.Register<FunctionAnnotation, FunctionAnnotationType>(nameof(Type), FunctionAnnotationType.EquationX);
  24. /// <summary>
  25. /// Identifies the <see cref="Equation"/> dependency property.
  26. /// </summary>
  27. public static readonly StyledProperty<Func<double, double>> EquationProperty = AvaloniaProperty.Register<FunctionAnnotation, Func<double, double>>(nameof(Equation));
  28. /// <summary>
  29. /// Identifies the <see cref="Resolution"/> dependency property.
  30. /// </summary>
  31. public static readonly StyledProperty<int> ResolutionProperty = AvaloniaProperty.Register<FunctionAnnotation, int>(nameof(Resolution), 400);
  32. /// <summary>
  33. /// Initializes static members of the <see cref="FunctionAnnotation"/> class.
  34. /// </summary>
  35. static FunctionAnnotation()
  36. {
  37. TextColorProperty.OverrideDefaultValue<FunctionAnnotation>(MoreColors.Automatic);
  38. TextColorProperty.Changed.AddClassHandler<FunctionAnnotation>(AppearanceChanged);
  39. TextHorizontalAlignmentProperty.OverrideDefaultValue<FunctionAnnotation>(HorizontalAlignment.Right);
  40. TextHorizontalAlignmentProperty.Changed.AddClassHandler<FunctionAnnotation>(AppearanceChanged);
  41. TextVerticalAlignmentProperty.OverrideDefaultValue<FunctionAnnotation>(VerticalAlignment.Top);
  42. TextVerticalAlignmentProperty.Changed.AddClassHandler<FunctionAnnotation>(AppearanceChanged);
  43. TypeProperty.Changed.AddClassHandler<FunctionAnnotation>(DataChanged);
  44. }
  45. /// <summary>
  46. /// Initializes a new instance of the <see cref="FunctionAnnotation" /> class.
  47. /// </summary>
  48. public FunctionAnnotation()
  49. {
  50. InternalAnnotation = new Annotations.FunctionAnnotation();
  51. }
  52. /// <summary>
  53. /// Gets or sets the equation.
  54. /// </summary>
  55. /// <value>The equation.</value>
  56. public Func<double, double> Equation
  57. {
  58. get
  59. {
  60. return GetValue(EquationProperty);
  61. }
  62. set
  63. {
  64. SetValue(EquationProperty, value);
  65. }
  66. }
  67. /// <summary>
  68. /// Gets or sets the resolution.
  69. /// </summary>
  70. /// <value>The resolution.</value>
  71. public int Resolution
  72. {
  73. get
  74. {
  75. return GetValue(ResolutionProperty);
  76. }
  77. set
  78. {
  79. SetValue(ResolutionProperty, value);
  80. }
  81. }
  82. /// <summary>
  83. /// Gets or sets Type.
  84. /// </summary>
  85. public FunctionAnnotationType Type
  86. {
  87. get
  88. {
  89. return GetValue(TypeProperty);
  90. }
  91. set
  92. {
  93. SetValue(TypeProperty, value);
  94. }
  95. }
  96. /// <summary>
  97. /// Creates the internal annotation object.
  98. /// </summary>
  99. /// <returns>The annotation.</returns>
  100. public override Annotations.Annotation CreateModel()
  101. {
  102. SynchronizeProperties();
  103. return InternalAnnotation;
  104. }
  105. /// <summary>
  106. /// Synchronizes the properties.
  107. /// </summary>
  108. public override void SynchronizeProperties()
  109. {
  110. base.SynchronizeProperties();
  111. var a = (Annotations.FunctionAnnotation)InternalAnnotation;
  112. a.Type = Type;
  113. a.Equation = Equation;
  114. a.Resolution = Resolution;
  115. }
  116. }
  117. }