// (c) Copyright Microsoft Corporation. // This source is subject to the Microsoft Public License (Ms-PL). // Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details. // All other rights reserved. using System.Collections; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Windows.Data; using System.Windows.Media.Animation; using System.Windows.Shapes; #if DEFINITION_SERIES_COMPATIBILITY_MODE namespace System.Windows.Controls.DataVisualization.Charting #else namespace System.Windows.Controls.DataVisualization.Charting.Compatible #endif { /// /// Control that displays values as an line chart visualization. /// /// /// Based on the DefinitionSeries hierarchy. /// /// Preview [StyleTypedProperty(Property = DataPointStyleName, StyleTargetType = typeof(LineDataPoint))] [StyleTypedProperty(Property = LegendItemStyleName, StyleTargetType = typeof(LegendItem))] [StyleTypedProperty(Property = PolylineStyleName, StyleTargetType = typeof(Polyline))] public class LineSeries : StackedLineSeries { /// /// Name of the DataPointStyle property. /// private const string DataPointStyleName = "DataPointStyle"; /// /// Name of the LegendItemStyle property. /// private const string LegendItemStyleName = "LegendItemStyle"; /// /// Name of the PolylineStyle property. /// private const string PolylineStyleName = "PolylineStyle"; /// /// Field storing the single SeriesDefinition used by the series. /// private SeriesDefinition _definition; /// /// Initializes a new instance of the LineSeries class. /// public LineSeries() { SetBinding(DefinitionSeries.DependentAxisProperty, new Binding("DependentRangeAxis") { Source = this }); SetBinding(DefinitionSeries.SelectionModeProperty, new Binding("IsSelectionEnabled") { Source = this, Converter = new System.Windows.Controls.DataVisualization.Charting.Compatible.SelectionEnabledToSelectionModeConverter() }); _definition = new SeriesDefinition(); _definition.SetBinding(SeriesDefinition.ItemsSourceProperty, new Binding("ItemsSource") { Source = this }); _definition.SetBinding(SeriesDefinition.TitleProperty, new Binding("Title") { Source = this }); _definition.SetBinding(SeriesDefinition.DataPointStyleProperty, new Binding(DataPointStyleName) { Source = this }); _definition.SetBinding(SeriesDefinition.LegendItemStyleProperty, new Binding(LegendItemStyleName) { Source = this }); _definition.SetBinding(SeriesDefinition.DataShapeStyleProperty, new Binding(PolylineStyleName) { Source = this }); _definition.SetBinding(SeriesDefinition.TransitionDurationProperty, new Binding("TransitionDuration") { Source = this }); #if !NO_EASING_FUNCTIONS _definition.SetBinding(SeriesDefinition.TransitionEasingFunctionProperty, new Binding("TransitionEasingFunction") { Source = this }); #endif // For compatibility DependentValueBinding = new Binding(); IndependentValueBinding = new Binding(); SeriesDefinitions.Add(_definition); } /// /// Gets a sequence of IndependentValueGroups. /// protected override IEnumerable IndependentValueGroups { get { // Base implementation groups by independent value; when plotting a single series in isolation, that's not desirable return DataItems .Select(di => new IndependentValueGroup(di.ActualIndependentValue, new DataItem[] { di })); } } /// /// Gets or sets a sequence that provides the content of the series. /// public IEnumerable ItemsSource { get { return (IEnumerable)GetValue(ItemsSourceProperty); } set { SetValue(ItemsSourceProperty, value); } } /// /// Identifies the ItemsSource dependency property. /// public static readonly DependencyProperty ItemsSourceProperty = DependencyProperty.Register("ItemsSource", typeof(IEnumerable), typeof(LineSeries), null); /// /// Gets or sets the Binding that identifies the dependent values of the series. /// public Binding DependentValueBinding { get { return _definition.DependentValueBinding; } set { _definition.DependentValueBinding = value; } } /// /// Gets or sets the Binding path that identifies the dependent values of the series. /// public string DependentValuePath { get { return _definition.DependentValuePath; } set { _definition.DependentValuePath = value; } } /// /// Gets or sets the Binding that identifies the independent values of the series. /// public Binding IndependentValueBinding { get { return _definition.IndependentValueBinding; } set { _definition.IndependentValueBinding = value; } } /// /// Gets or sets the Binding path that identifies the independent values of the series. /// public string IndependentValuePath { get { return _definition.IndependentValuePath; } set { _definition.IndependentValuePath = value; } } /// /// Gets or sets the IRangeAxis to use as the dependent axis of the series. /// public IRangeAxis DependentRangeAxis { get { return (IRangeAxis)GetValue(DependentRangeAxisProperty); } set { SetValue(DependentRangeAxisProperty, value); } } /// /// Identifies the DependentRangeAxis dependency property. /// public static readonly DependencyProperty DependentRangeAxisProperty = DependencyProperty.Register("DependentRangeAxis", typeof(IRangeAxis), typeof(LineSeries), null); /// /// Gets or sets the title of the series. /// public object Title { get { return (object)GetValue(TitleProperty); } set { SetValue(TitleProperty, value); } } /// /// Identifies the Title dependency property. /// public static readonly DependencyProperty TitleProperty = DependencyProperty.Register("Title", typeof(object), typeof(LineSeries), null); /// /// Gets or sets the Style to use for the DataPoints of the series. /// public Style DataPointStyle { get { return (Style)GetValue(DataPointStyleProperty); } set { SetValue(DataPointStyleProperty, value); } } /// /// Identifies the DataPointStyle dependency property. /// public static readonly DependencyProperty DataPointStyleProperty = DependencyProperty.Register(DataPointStyleName, typeof(Style), typeof(LineSeries), null); /// /// Gets or sets the Style to use for the LegendItem of the series. /// public Style LegendItemStyle { get { return (Style)GetValue(LegendItemStyleProperty); } set { SetValue(LegendItemStyleProperty, value); } } /// /// Identifies the LegendItemStyle dependency property. /// public static readonly DependencyProperty LegendItemStyleProperty = DependencyProperty.Register(LegendItemStyleName, typeof(Style), typeof(LineSeries), null); /// /// Gets or sets a value indicating whether selection is enabled. /// public bool IsSelectionEnabled { get { return (bool)GetValue(IsSelectionEnabledProperty); } set { SetValue(IsSelectionEnabledProperty, value); } } /// /// Identifies the IsSelectionEnabled dependency property. /// public static readonly DependencyProperty IsSelectionEnabledProperty = DependencyProperty.Register("IsSelectionEnabled", typeof(bool), typeof(LineSeries), null); /// /// Gets or sets the Style to use for the Path of the series. /// [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.")] public Style PolylineStyle { get { return (Style)GetValue(PolylineStyleProperty); } set { SetValue(PolylineStyleProperty, value); } } /// /// Identifies the PolylineStyle dependency property. /// [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Polyline", Justification = "Matches spelling of same-named framework class.")] public static readonly DependencyProperty PolylineStyleProperty = DependencyProperty.Register(PolylineStyleName, typeof(Style), typeof(LineSeries), null); /// /// Gets or sets the TimeSpan to use for the duration of data transitions. /// public TimeSpan TransitionDuration { get { return (TimeSpan)GetValue(TransitionDurationProperty); } set { SetValue(TransitionDurationProperty, value); } } /// /// Identifies the TransitionDuration dependency property. /// public static readonly DependencyProperty TransitionDurationProperty = DependencyProperty.Register("TransitionDuration", typeof(TimeSpan), typeof(LineSeries), new PropertyMetadata(TimeSpan.FromSeconds(0.5))); #if !NO_EASING_FUNCTIONS /// /// Gets or sets the IEasingFunction to use for data transitions. /// public IEasingFunction TransitionEasingFunction { get { return (IEasingFunction)GetValue(TransitionEasingFunctionProperty); } set { SetValue(TransitionEasingFunctionProperty, value); } } /// /// Identifies the TransitionEasingFunction dependency property. /// public static readonly DependencyProperty TransitionEasingFunctionProperty = DependencyProperty.Register("TransitionEasingFunction", typeof(IEasingFunction), typeof(LineSeries), new PropertyMetadata(new QuadraticEase { EasingMode = EasingMode.EaseInOut })); #else /// /// Gets or sets a placeholder for the TransitionEasingFunction dependency property. /// internal IEasingFunction TransitionEasingFunction { get; set; } #endif } }