PageRenderTime 58ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/Main/src/DynamicDataDisplay/Charts/Axes/GeneralAxis.cs

#
C# | 148 lines | 99 code | 22 blank | 27 comment | 3 complexity | f0871069381bc17b57645daf84c05be0 MD5 | raw file
Possible License(s): CC-BY-SA-3.0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows.Controls;
  6. using System.ComponentModel;
  7. namespace Microsoft.Research.DynamicDataDisplay.Charts.Axes
  8. {
  9. /// <summary>
  10. /// Represents a base class for all DynamicDataDisplay's axes.
  11. /// Has several axis-specific and all WPF-specific properties.
  12. /// </summary>
  13. public abstract class GeneralAxis : ContentControl, IPlotterElement
  14. {
  15. /// <summary>
  16. /// Initializes a new instance of the <see cref="GeneralAxis"/> class.
  17. /// </summary>
  18. protected GeneralAxis() { }
  19. #region Placement property
  20. private AxisPlacement placement = AxisPlacement.Bottom;
  21. /// <summary>
  22. /// Gets or sets the placement of axis - place in ChartPlotter where it should be placed.
  23. /// </summary>
  24. /// <value>The placement.</value>
  25. public AxisPlacement Placement
  26. {
  27. get { return placement; }
  28. set
  29. {
  30. if (placement != value)
  31. {
  32. ValidatePlacement(value);
  33. AxisPlacement oldPlacement = placement;
  34. placement = value;
  35. OnPlacementChanged(oldPlacement, placement);
  36. }
  37. }
  38. }
  39. protected virtual void OnPlacementChanged(AxisPlacement oldPlacement, AxisPlacement newPlacement) { }
  40. protected Panel GetPanelByPlacement(AxisPlacement placement)
  41. {
  42. Panel panel = null;
  43. switch (placement)
  44. {
  45. case AxisPlacement.Left:
  46. panel = ParentPlotter.LeftPanel;
  47. break;
  48. case AxisPlacement.Right:
  49. panel = ParentPlotter.RightPanel;
  50. break;
  51. case AxisPlacement.Top:
  52. panel = ParentPlotter.TopPanel;
  53. break;
  54. case AxisPlacement.Bottom:
  55. panel = ParentPlotter.BottomPanel;
  56. break;
  57. default:
  58. break;
  59. }
  60. return panel;
  61. }
  62. /// <summary>
  63. /// Validates the placement - e.g., vertical axis should not be placed from top or bottom, etc.
  64. /// If proposed placement is wrong, throws an ArgumentException.
  65. /// </summary>
  66. /// <param name="newPlacement">The new placement.</param>
  67. protected virtual void ValidatePlacement(AxisPlacement newPlacement) { }
  68. #endregion
  69. protected void RaiseTicksChanged()
  70. {
  71. TicksChanged.Raise(this);
  72. }
  73. public abstract void ForceUpdate();
  74. /// <summary>
  75. /// Occurs when ticks changes.
  76. /// </summary>
  77. [EditorBrowsable(EditorBrowsableState.Never)]
  78. public event EventHandler TicksChanged;
  79. /// <summary>
  80. /// Gets the screen coordinates of axis ticks.
  81. /// </summary>
  82. /// <value>The screen ticks.</value>
  83. [EditorBrowsable(EditorBrowsableState.Never)]
  84. public abstract double[] ScreenTicks { get; }
  85. /// <summary>
  86. /// Gets the screen coordinates of minor ticks.
  87. /// </summary>
  88. /// <value>The minor screen ticks.</value>
  89. [EditorBrowsable(EditorBrowsableState.Never)]
  90. public abstract MinorTickInfo<double>[] MinorScreenTicks { get; }
  91. public abstract bool UseSmoothPanning
  92. {
  93. get;
  94. set;
  95. }
  96. #region IPlotterElement Members
  97. private Plotter2D plotter;
  98. [EditorBrowsable(EditorBrowsableState.Never)]
  99. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  100. public Plotter2D ParentPlotter
  101. {
  102. get { return plotter; }
  103. }
  104. void IPlotterElement.OnPlotterAttached(Plotter plotter)
  105. {
  106. this.plotter = (Plotter2D)plotter;
  107. OnPlotterAttached(this.plotter);
  108. }
  109. protected virtual void OnPlotterAttached(Plotter2D plotter) { }
  110. void IPlotterElement.OnPlotterDetaching(Plotter plotter)
  111. {
  112. OnPlotterDetaching(this.plotter);
  113. this.plotter = null;
  114. }
  115. protected virtual void OnPlotterDetaching(Plotter2D plotter) { }
  116. public Plotter2D Plotter
  117. {
  118. get { return plotter; }
  119. }
  120. Plotter IPlotterElement.Plotter
  121. {
  122. get { return plotter; }
  123. }
  124. #endregion
  125. }
  126. }