PageRenderTime 42ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/Silverlight4/Source/Controls.DataVisualization.Toolkit/Charting/Series/Compatible/LineSeries.cs

https://github.com/kvervo/HorizontalLoopingSelector
C# | 268 lines | 139 code | 29 blank | 100 comment | 0 complexity | ed7568d18f6ee914270bd44141d2c428 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.Collections;
  6. using System.Collections.Generic;
  7. using System.Diagnostics.CodeAnalysis;
  8. using System.Linq;
  9. using System.Windows.Data;
  10. using System.Windows.Media.Animation;
  11. using System.Windows.Shapes;
  12. #if DEFINITION_SERIES_COMPATIBILITY_MODE
  13. namespace System.Windows.Controls.DataVisualization.Charting
  14. #else
  15. namespace System.Windows.Controls.DataVisualization.Charting.Compatible
  16. #endif
  17. {
  18. /// <summary>
  19. /// Control that displays values as an line chart visualization.
  20. /// </summary>
  21. /// <remarks>
  22. /// Based on the DefinitionSeries hierarchy.
  23. /// </remarks>
  24. /// <QualityBand>Preview</QualityBand>
  25. [StyleTypedProperty(Property = DataPointStyleName, StyleTargetType = typeof(LineDataPoint))]
  26. [StyleTypedProperty(Property = LegendItemStyleName, StyleTargetType = typeof(LegendItem))]
  27. [StyleTypedProperty(Property = PolylineStyleName, StyleTargetType = typeof(Polyline))]
  28. public class LineSeries : StackedLineSeries
  29. {
  30. /// <summary>
  31. /// Name of the DataPointStyle property.
  32. /// </summary>
  33. private const string DataPointStyleName = "DataPointStyle";
  34. /// <summary>
  35. /// Name of the LegendItemStyle property.
  36. /// </summary>
  37. private const string LegendItemStyleName = "LegendItemStyle";
  38. /// <summary>
  39. /// Name of the PolylineStyle property.
  40. /// </summary>
  41. private const string PolylineStyleName = "PolylineStyle";
  42. /// <summary>
  43. /// Field storing the single SeriesDefinition used by the series.
  44. /// </summary>
  45. private SeriesDefinition _definition;
  46. /// <summary>
  47. /// Initializes a new instance of the LineSeries class.
  48. /// </summary>
  49. public LineSeries()
  50. {
  51. SetBinding(DefinitionSeries.DependentAxisProperty, new Binding("DependentRangeAxis") { Source = this });
  52. SetBinding(DefinitionSeries.SelectionModeProperty, new Binding("IsSelectionEnabled") { Source = this, Converter = new System.Windows.Controls.DataVisualization.Charting.Compatible.SelectionEnabledToSelectionModeConverter() });
  53. _definition = new SeriesDefinition();
  54. _definition.SetBinding(SeriesDefinition.ItemsSourceProperty, new Binding("ItemsSource") { Source = this });
  55. _definition.SetBinding(SeriesDefinition.TitleProperty, new Binding("Title") { Source = this });
  56. _definition.SetBinding(SeriesDefinition.DataPointStyleProperty, new Binding(DataPointStyleName) { Source = this });
  57. _definition.SetBinding(SeriesDefinition.LegendItemStyleProperty, new Binding(LegendItemStyleName) { Source = this });
  58. _definition.SetBinding(SeriesDefinition.DataShapeStyleProperty, new Binding(PolylineStyleName) { Source = this });
  59. _definition.SetBinding(SeriesDefinition.TransitionDurationProperty, new Binding("TransitionDuration") { Source = this });
  60. #if !NO_EASING_FUNCTIONS
  61. _definition.SetBinding(SeriesDefinition.TransitionEasingFunctionProperty, new Binding("TransitionEasingFunction") { Source = this });
  62. #endif
  63. // For compatibility
  64. DependentValueBinding = new Binding();
  65. IndependentValueBinding = new Binding();
  66. SeriesDefinitions.Add(_definition);
  67. }
  68. /// <summary>
  69. /// Gets a sequence of IndependentValueGroups.
  70. /// </summary>
  71. protected override IEnumerable<IndependentValueGroup> IndependentValueGroups
  72. {
  73. get
  74. {
  75. // Base implementation groups by independent value; when plotting a single series in isolation, that's not desirable
  76. return DataItems
  77. .Select(di => new IndependentValueGroup(di.ActualIndependentValue, new DataItem[] { di }));
  78. }
  79. }
  80. /// <summary>
  81. /// Gets or sets a sequence that provides the content of the series.
  82. /// </summary>
  83. public IEnumerable ItemsSource
  84. {
  85. get { return (IEnumerable)GetValue(ItemsSourceProperty); }
  86. set { SetValue(ItemsSourceProperty, value); }
  87. }
  88. /// <summary>
  89. /// Identifies the ItemsSource dependency property.
  90. /// </summary>
  91. public static readonly DependencyProperty ItemsSourceProperty =
  92. DependencyProperty.Register("ItemsSource", typeof(IEnumerable), typeof(LineSeries), null);
  93. /// <summary>
  94. /// Gets or sets the Binding that identifies the dependent values of the series.
  95. /// </summary>
  96. public Binding DependentValueBinding
  97. {
  98. get { return _definition.DependentValueBinding; }
  99. set { _definition.DependentValueBinding = value; }
  100. }
  101. /// <summary>
  102. /// Gets or sets the Binding path that identifies the dependent values of the series.
  103. /// </summary>
  104. public string DependentValuePath
  105. {
  106. get { return _definition.DependentValuePath; }
  107. set { _definition.DependentValuePath = value; }
  108. }
  109. /// <summary>
  110. /// Gets or sets the Binding that identifies the independent values of the series.
  111. /// </summary>
  112. public Binding IndependentValueBinding
  113. {
  114. get { return _definition.IndependentValueBinding; }
  115. set { _definition.IndependentValueBinding = value; }
  116. }
  117. /// <summary>
  118. /// Gets or sets the Binding path that identifies the independent values of the series.
  119. /// </summary>
  120. public string IndependentValuePath
  121. {
  122. get { return _definition.IndependentValuePath; }
  123. set { _definition.IndependentValuePath = value; }
  124. }
  125. /// <summary>
  126. /// Gets or sets the IRangeAxis to use as the dependent axis of the series.
  127. /// </summary>
  128. public IRangeAxis DependentRangeAxis
  129. {
  130. get { return (IRangeAxis)GetValue(DependentRangeAxisProperty); }
  131. set { SetValue(DependentRangeAxisProperty, value); }
  132. }
  133. /// <summary>
  134. /// Identifies the DependentRangeAxis dependency property.
  135. /// </summary>
  136. public static readonly DependencyProperty DependentRangeAxisProperty =
  137. DependencyProperty.Register("DependentRangeAxis", typeof(IRangeAxis), typeof(LineSeries), null);
  138. /// <summary>
  139. /// Gets or sets the title of the series.
  140. /// </summary>
  141. public object Title
  142. {
  143. get { return (object)GetValue(TitleProperty); }
  144. set { SetValue(TitleProperty, value); }
  145. }
  146. /// <summary>
  147. /// Identifies the Title dependency property.
  148. /// </summary>
  149. public static readonly DependencyProperty TitleProperty =
  150. DependencyProperty.Register("Title", typeof(object), typeof(LineSeries), null);
  151. /// <summary>
  152. /// Gets or sets the Style to use for the DataPoints of the series.
  153. /// </summary>
  154. public Style DataPointStyle
  155. {
  156. get { return (Style)GetValue(DataPointStyleProperty); }
  157. set { SetValue(DataPointStyleProperty, value); }
  158. }
  159. /// <summary>
  160. /// Identifies the DataPointStyle dependency property.
  161. /// </summary>
  162. public static readonly DependencyProperty DataPointStyleProperty =
  163. DependencyProperty.Register(DataPointStyleName, typeof(Style), typeof(LineSeries), null);
  164. /// <summary>
  165. /// Gets or sets the Style to use for the LegendItem of the series.
  166. /// </summary>
  167. public Style LegendItemStyle
  168. {
  169. get { return (Style)GetValue(LegendItemStyleProperty); }
  170. set { SetValue(LegendItemStyleProperty, value); }
  171. }
  172. /// <summary>
  173. /// Identifies the LegendItemStyle dependency property.
  174. /// </summary>
  175. public static readonly DependencyProperty LegendItemStyleProperty =
  176. DependencyProperty.Register(LegendItemStyleName, typeof(Style), typeof(LineSeries), null);
  177. /// <summary>
  178. /// Gets or sets a value indicating whether selection is enabled.
  179. /// </summary>
  180. public bool IsSelectionEnabled
  181. {
  182. get { return (bool)GetValue(IsSelectionEnabledProperty); }
  183. set { SetValue(IsSelectionEnabledProperty, value); }
  184. }
  185. /// <summary>
  186. /// Identifies the IsSelectionEnabled dependency property.
  187. /// </summary>
  188. public static readonly DependencyProperty IsSelectionEnabledProperty =
  189. DependencyProperty.Register("IsSelectionEnabled", typeof(bool), typeof(LineSeries), null);
  190. /// <summary>
  191. /// Gets or sets the Style to use for the Path of the series.
  192. /// </summary>
  193. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Polyline", Scope = "member", Target = "System.Windows.Controls.DataVisualization.Charting.Compatible.LineSeries.#PolylineStyle", Justification = "Matches spelling of same-named framework class.")]
  194. public Style PolylineStyle
  195. {
  196. get { return (Style)GetValue(PolylineStyleProperty); }
  197. set { SetValue(PolylineStyleProperty, value); }
  198. }
  199. /// <summary>
  200. /// Identifies the PolylineStyle dependency property.
  201. /// </summary>
  202. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Polyline", Justification = "Matches spelling of same-named framework class.")]
  203. public static readonly DependencyProperty PolylineStyleProperty =
  204. DependencyProperty.Register(PolylineStyleName, typeof(Style), typeof(LineSeries), null);
  205. /// <summary>
  206. /// Gets or sets the TimeSpan to use for the duration of data transitions.
  207. /// </summary>
  208. public TimeSpan TransitionDuration
  209. {
  210. get { return (TimeSpan)GetValue(TransitionDurationProperty); }
  211. set { SetValue(TransitionDurationProperty, value); }
  212. }
  213. /// <summary>
  214. /// Identifies the TransitionDuration dependency property.
  215. /// </summary>
  216. public static readonly DependencyProperty TransitionDurationProperty =
  217. DependencyProperty.Register("TransitionDuration", typeof(TimeSpan), typeof(LineSeries), new PropertyMetadata(TimeSpan.FromSeconds(0.5)));
  218. #if !NO_EASING_FUNCTIONS
  219. /// <summary>
  220. /// Gets or sets the IEasingFunction to use for data transitions.
  221. /// </summary>
  222. public IEasingFunction TransitionEasingFunction
  223. {
  224. get { return (IEasingFunction)GetValue(TransitionEasingFunctionProperty); }
  225. set { SetValue(TransitionEasingFunctionProperty, value); }
  226. }
  227. /// <summary>
  228. /// Identifies the TransitionEasingFunction dependency property.
  229. /// </summary>
  230. public static readonly DependencyProperty TransitionEasingFunctionProperty =
  231. DependencyProperty.Register("TransitionEasingFunction", typeof(IEasingFunction), typeof(LineSeries), new PropertyMetadata(new QuadraticEase { EasingMode = EasingMode.EaseInOut }));
  232. #else
  233. /// <summary>
  234. /// Gets or sets a placeholder for the TransitionEasingFunction dependency property.
  235. /// </summary>
  236. internal IEasingFunction TransitionEasingFunction { get; set; }
  237. #endif
  238. }
  239. }