LinearAxis.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. // --------------------------------------------------------------------------------------------------------------------
  2. // <copyright file="LinearAxis.cs" company="OxyPlot">
  3. // Copyright (c) 2014 OxyPlot contributors
  4. // </copyright>
  5. // <summary>
  6. // This is a Avalonia wrapper of OxyPlot.LinearAxis.
  7. // </summary>
  8. // --------------------------------------------------------------------------------------------------------------------
  9. using Avalonia;
  10. namespace OxyPlot.Avalonia
  11. {
  12. /// <summary>
  13. /// This is a Avalonia wrapper of OxyPlot.LinearAxis.
  14. /// </summary>
  15. public class LinearAxis : Axis
  16. {
  17. /// <summary>
  18. /// Identifies the <see cref="FormatAsFractions"/> dependency property.
  19. /// </summary>
  20. public static readonly StyledProperty<bool> FormatAsFractionsProperty = AvaloniaProperty.Register<LinearAxis, bool>(nameof(FormatAsFractions), false);
  21. /// <summary>
  22. /// Identifies the <see cref="FractionUnit"/> dependency property.
  23. /// </summary>
  24. public static readonly StyledProperty<double> FractionUnitProperty = AvaloniaProperty.Register<LinearAxis, double>(nameof(FractionUnit), 1.0);
  25. /// <summary>
  26. /// Identifies the <see cref="FractionUnitSymbol"/> dependency property.
  27. /// </summary>
  28. public static readonly StyledProperty<string> FractionUnitSymbolProperty = AvaloniaProperty.Register<LinearAxis, string>(nameof(FractionUnitSymbol));
  29. /// <summary>
  30. /// Initializes a new instance of the <see cref = "LinearAxis" /> class.
  31. /// </summary>
  32. public LinearAxis()
  33. {
  34. InternalAxis = new Axes.LinearAxis();
  35. }
  36. /// <summary>
  37. /// Gets or sets a value indicating whether FormatAsFractions.
  38. /// </summary>
  39. public bool FormatAsFractions
  40. {
  41. get
  42. {
  43. return GetValue(FormatAsFractionsProperty);
  44. }
  45. set
  46. {
  47. SetValue(FormatAsFractionsProperty, value);
  48. }
  49. }
  50. /// <summary>
  51. /// Gets or sets FractionUnit.
  52. /// </summary>
  53. public double FractionUnit
  54. {
  55. get
  56. {
  57. return GetValue(FractionUnitProperty);
  58. }
  59. set
  60. {
  61. SetValue(FractionUnitProperty, value);
  62. }
  63. }
  64. /// <summary>
  65. /// Gets or sets FractionUnitSymbol.
  66. /// </summary>
  67. public string FractionUnitSymbol
  68. {
  69. get
  70. {
  71. return GetValue(FractionUnitSymbolProperty);
  72. }
  73. set
  74. {
  75. SetValue(FractionUnitSymbolProperty, value);
  76. }
  77. }
  78. /// <summary>
  79. /// Creates the internal axis.
  80. /// </summary>
  81. /// <returns>The internal axis.</returns>
  82. public override Axes.Axis CreateModel()
  83. {
  84. SynchronizeProperties();
  85. return InternalAxis;
  86. }
  87. /// <summary>
  88. /// Synchronizes the properties.
  89. /// </summary>
  90. protected override void SynchronizeProperties()
  91. {
  92. base.SynchronizeProperties();
  93. var a = (Axes.LinearAxis)InternalAxis;
  94. a.FormatAsFractions = FormatAsFractions;
  95. a.FractionUnit = FractionUnit;
  96. a.FractionUnitSymbol = FractionUnitSymbol;
  97. }
  98. }
  99. }