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