PageRenderTime 102ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/WinRT XAML Toolkit - 1.3.6.0 - Source.zip/WinRTXamlToolkit.Controls.DataVisualization/Charting/Axis/Axis.cs

https://gitlab.com/prabaprakash/Real_Metro_Player
C# | 239 lines | 123 code | 24 blank | 92 comment | 8 complexity | c267028834ba30d000f025c3b1ac8bc3 MD5 | raw file
  1. // (c) Copyright Microsoft Corporation.
  2. // This source is subject to the Microsoft Public License (Ms-PL).
  3. // Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
  4. // All other rights reserved.
  5. using System;
  6. using System.Collections;
  7. using System.Collections.Generic;
  8. using System.Diagnostics;
  9. using System.Diagnostics.CodeAnalysis;
  10. using System.Windows;
  11. using System.Collections.ObjectModel;
  12. using System.Collections.Specialized;
  13. using Windows.UI.Xaml.Controls;
  14. using System.ComponentModel;
  15. using Windows.UI.Xaml;
  16. namespace WinRTXamlToolkit.Controls.DataVisualization.Charting
  17. {
  18. /// <summary>
  19. /// An axis class used to determine the plot area coordinate of values.
  20. /// </summary>
  21. public abstract class Axis : Control, IAxis
  22. {
  23. #region public AxisLocation Location
  24. /// <summary>
  25. /// Gets or sets the axis location.
  26. /// </summary>
  27. public AxisLocation Location
  28. {
  29. get { return (AxisLocation)GetValue(LocationProperty); }
  30. set { SetValue(LocationProperty, value); }
  31. }
  32. /// <summary>
  33. /// Identifies the Location dependency property.
  34. /// </summary>
  35. public static readonly DependencyProperty LocationProperty =
  36. DependencyProperty.Register(
  37. "Location",
  38. typeof(AxisLocation),
  39. typeof(Axis),
  40. new PropertyMetadata(AxisLocation.Auto, OnLocationPropertyChanged));
  41. /// <summary>
  42. /// LocationProperty property changed handler.
  43. /// </summary>
  44. /// <param name="d">Axis that changed its Location.</param>
  45. /// <param name="e">Event arguments.</param>
  46. private static void OnLocationPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  47. {
  48. Axis source = (Axis)d;
  49. AxisLocation oldValue = (AxisLocation)e.OldValue;
  50. AxisLocation newValue = (AxisLocation)e.NewValue;
  51. source.OnLocationPropertyChanged(oldValue, newValue);
  52. }
  53. /// <summary>
  54. /// LocationProperty property changed handler.
  55. /// </summary>
  56. /// <param name="oldValue">Old value.</param>
  57. /// <param name="newValue">New value.</param>
  58. protected virtual void OnLocationPropertyChanged(AxisLocation oldValue, AxisLocation newValue)
  59. {
  60. RoutedPropertyChangedEventHandler<AxisLocation> handler = this.LocationChanged;
  61. if (handler != null)
  62. {
  63. handler(this, new RoutedPropertyChangedEventArgs<AxisLocation>(oldValue, newValue));
  64. }
  65. }
  66. /// <summary>
  67. /// This event is raised when the location property is changed.
  68. /// </summary>
  69. public event RoutedPropertyChangedEventHandler<AxisLocation> LocationChanged;
  70. #endregion public AxisLocation Location
  71. /// <summary>
  72. /// Gets the list of child axes belonging to this axis.
  73. /// </summary>
  74. public ObservableCollection<IAxis> DependentAxes { get; private set; }
  75. #region public AxisOrientation Orientation
  76. /// <summary>
  77. /// Gets or sets the orientation of the axis.
  78. /// </summary>
  79. public AxisOrientation Orientation
  80. {
  81. get { return (AxisOrientation)GetValue(OrientationProperty); }
  82. set { SetValue(OrientationProperty, value); }
  83. }
  84. /// <summary>
  85. /// Identifies the Orientation dependency property.
  86. /// </summary>
  87. public static readonly DependencyProperty OrientationProperty =
  88. DependencyProperty.Register(
  89. "Orientation",
  90. typeof(AxisOrientation),
  91. typeof(Axis),
  92. new PropertyMetadata(AxisOrientation.None, OnOrientationPropertyChanged));
  93. /// <summary>
  94. /// OrientationProperty property changed handler.
  95. /// </summary>
  96. /// <param name="d">Axis that changed its Orientation.</param>
  97. /// <param name="e">Event arguments.</param>
  98. private static void OnOrientationPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  99. {
  100. Axis source = (Axis)d;
  101. AxisOrientation oldValue = (AxisOrientation)e.OldValue;
  102. AxisOrientation newValue = (AxisOrientation)e.NewValue;
  103. source.OnOrientationPropertyChanged(oldValue, newValue);
  104. }
  105. /// <summary>
  106. /// OrientationProperty property changed handler.
  107. /// </summary>
  108. /// <param name="oldValue">Old value.</param>
  109. /// <param name="newValue">New value.</param>
  110. protected virtual void OnOrientationPropertyChanged(AxisOrientation oldValue, AxisOrientation newValue)
  111. {
  112. RoutedPropertyChangedEventHandler<AxisOrientation> handler = OrientationChanged;
  113. if (handler != null)
  114. {
  115. handler(this, new RoutedPropertyChangedEventArgs<AxisOrientation>(oldValue, newValue));
  116. }
  117. }
  118. /// <summary>
  119. /// This event is raised when the Orientation property is changed.
  120. /// </summary>
  121. public event RoutedPropertyChangedEventHandler<AxisOrientation> OrientationChanged;
  122. #endregion public AxisOrientation Orientation
  123. /// <summary>
  124. /// Raises the invalidated event.
  125. /// </summary>
  126. /// <param name="args">Information about the event.</param>
  127. protected virtual void OnInvalidated(RoutedEventArgs args)
  128. {
  129. foreach (IAxisListener listener in RegisteredListeners)
  130. {
  131. listener.AxisInvalidated(this);
  132. }
  133. }
  134. /// <summary>
  135. /// Gets or the collection of series that are using the Axis.
  136. /// </summary>
  137. public ObservableCollection<IAxisListener> RegisteredListeners { get; private set; }
  138. /// <summary>
  139. /// Returns a value indicating whether the axis can plot a value.
  140. /// </summary>
  141. /// <param name="value">The value to plot.</param>
  142. /// <returns>A value indicating whether the axis can plot a value.
  143. /// </returns>
  144. public abstract bool CanPlot(object value);
  145. /// <summary>
  146. /// The plot area coordinate of a value.
  147. /// </summary>
  148. /// <param name="value">The value for which to retrieve the plot area
  149. /// coordinate.</param>
  150. /// <returns>The plot area coordinate.</returns>
  151. public abstract UnitValue GetPlotAreaCoordinate(object value);
  152. /// <summary>
  153. /// Instantiates a new instance of the Axis class.
  154. /// </summary>
  155. protected Axis()
  156. {
  157. RegisteredListeners = new UniqueObservableCollection<IAxisListener>();
  158. this.RegisteredListeners.CollectionChanged += RegisteredListenersCollectionChanged;
  159. this.DependentAxes = new ObservableCollection<IAxis>();
  160. this.DependentAxes.CollectionChanged += OnChildAxesCollectionChanged;
  161. }
  162. /// <summary>
  163. /// Child axes collection changed.
  164. /// </summary>
  165. /// <param name="sender">The source of the event.</param>
  166. /// <param name="e">Information about the event.</param>
  167. private void OnChildAxesCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
  168. {
  169. this.OnDependentAxesCollectionChanged();
  170. }
  171. /// <summary>
  172. /// Child axes collection changed.
  173. /// </summary>
  174. protected virtual void OnDependentAxesCollectionChanged()
  175. {
  176. }
  177. /// <summary>
  178. /// This event is raised when the registered listeners collection is
  179. /// changed.
  180. /// </summary>
  181. /// <param name="sender">The source of the event.</param>
  182. /// <param name="e">Information about the event.</param>
  183. private void RegisteredListenersCollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
  184. {
  185. if (e.OldItems != null)
  186. {
  187. foreach (IAxisListener obj in e.OldItems)
  188. {
  189. OnObjectUnregistered(obj);
  190. }
  191. }
  192. if (e.NewItems != null)
  193. {
  194. foreach (IAxisListener obj in e.NewItems)
  195. {
  196. OnObjectRegistered(obj);
  197. }
  198. }
  199. }
  200. /// <summary>
  201. /// This method is invoked when a series is registered.
  202. /// </summary>
  203. /// <param name="series">The series that has been registered.</param>
  204. protected virtual void OnObjectRegistered(IAxisListener series)
  205. {
  206. }
  207. /// <summary>
  208. /// This method is invoked when a series is unregistered.
  209. /// </summary>
  210. /// <param name="series">The series that has been unregistered.</param>
  211. protected virtual void OnObjectUnregistered(IAxisListener series)
  212. {
  213. }
  214. }
  215. }