LogarithmicAxis.cs 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. // --------------------------------------------------------------------------------------------------------------------
  2. // <copyright file="LogarithmicAxis.cs" company="OxyPlot">
  3. // Copyright (c) 2014 OxyPlot contributors
  4. // </copyright>
  5. // <summary>
  6. // This is a Avalonia wrapper of OxyPlot.LogarithmicAxis.
  7. // </summary>
  8. // --------------------------------------------------------------------------------------------------------------------
  9. using Avalonia;
  10. namespace OxyPlot.Avalonia
  11. {
  12. /// <summary>
  13. /// This is a Avalonia wrapper of OxyPlot.LogarithmicAxis.
  14. /// </summary>
  15. public class LogarithmicAxis : Axis
  16. {
  17. /// <summary>
  18. /// Identifies the <see cref="Base"/> dependency property.
  19. /// </summary>
  20. /// <value>The logarithmic base.</value>
  21. public static readonly StyledProperty<double> BaseProperty = AvaloniaProperty.Register<LogarithmicAxis, double>(nameof(Base), 10.0);
  22. /// <summary>
  23. /// Identifies the <see cref="PowerPadding"/> dependency property.
  24. /// </summary>
  25. public static readonly StyledProperty<bool> PowerPaddingProperty = AvaloniaProperty.Register<LogarithmicAxis, bool>(nameof(PowerPadding), true);
  26. /// <summary>
  27. /// Initializes a new instance of the <see cref = "LogarithmicAxis" /> class.
  28. /// </summary>
  29. public LogarithmicAxis()
  30. {
  31. InternalAxis = new Axes.LogarithmicAxis();
  32. FilterMinValue = 0;
  33. }
  34. /// <summary>
  35. /// Gets or sets Base.
  36. /// </summary>
  37. public double Base
  38. {
  39. get
  40. {
  41. return GetValue(BaseProperty);
  42. }
  43. set
  44. {
  45. SetValue(BaseProperty, value);
  46. }
  47. }
  48. /// <summary>
  49. /// Gets or sets a value indicating whether the ActualMaximum and ActualMinimum values should be padded to the nearest power of the Base.
  50. /// </summary>
  51. public bool PowerPadding
  52. {
  53. get
  54. {
  55. return GetValue(PowerPaddingProperty);
  56. }
  57. set
  58. {
  59. SetValue(PowerPaddingProperty, value);
  60. }
  61. }
  62. /// <summary>
  63. /// Creates the internal axis.
  64. /// </summary>
  65. /// <returns>The internal axis.</returns>
  66. public override Axes.Axis CreateModel()
  67. {
  68. SynchronizeProperties();
  69. return InternalAxis;
  70. }
  71. /// <summary>
  72. /// Synchronizes the properties.
  73. /// </summary>
  74. protected override void SynchronizeProperties()
  75. {
  76. base.SynchronizeProperties();
  77. var a = (Axes.LogarithmicAxis)InternalAxis;
  78. a.Base = Base;
  79. a.PowerPadding = PowerPadding;
  80. }
  81. static LogarithmicAxis()
  82. {
  83. BaseProperty.Changed.AddClassHandler<LogarithmicAxis>(DataChanged);
  84. PowerPaddingProperty.Changed.AddClassHandler<LogarithmicAxis>(DataChanged);
  85. }
  86. }
  87. }