/// <summary> /// Initializes a new instance of the AreaSeries class. /// </summary> public AreaSeries() { SetBinding(DefinitionSeries.DependentAxisProperty, new Binding { Path = new PropertyPath("DependentRangeAxis"), Source = this }); SetBinding(DefinitionSeries.SelectionModeProperty, new Binding { Path = new PropertyPath("IsSelectionEnabled"), Source = this, Converter = new 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(PathStyleName) { 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); }
/// <summary> /// Creates and adds DataItems for the specified SeriesDefinition's items. /// </summary> /// <param name="definition">Specified SeriesDefinition.</param> /// <param name="items">Sequence of items.</param> /// <param name="startingIndex">Starting index.</param> private void AddDataItems(SeriesDefinition definition, IEnumerable<object> items, int startingIndex) { int index = startingIndex; foreach (object item in items) { DataItems.Add(new DataItem(definition) { Value = item, Index = index }); index++; } // Because properties (like DependentValueBinding) may still be getting set //Dispatcher.BeginInvoke((Action)AddedDataItems); AddedDataItems(); }
internal void SeriesDefinitionItemsSourceCollectionChanged(SeriesDefinition definition, NotifyCollectionChangedAction action, IList oldItems, int oldStartingIndex, IList newItems, int newStartingIndex) { if (NotifyCollectionChangedAction.Replace == action) { // Perform in-place replacements foreach (DataItem dataItem in DataItems.Where(di => (di.SeriesDefinition == definition) && (newStartingIndex <= di.Index) && (di.Index < newStartingIndex + newItems.Count))) { dataItem.Value = newItems[dataItem.Index - newStartingIndex]; } } else { if (NotifyCollectionChangedAction.Reset == action) { // Set up parameters to allow normal old/new item handling to be used Debug.Assert(null == oldItems, "Reset action with non-null oldItems."); oldItems = DataItems.Where(di => (di.SeriesDefinition == definition)).ToArray(); oldStartingIndex = 0; newItems = definition.ItemsSource.CastWrapper<object>().ToArray(); newStartingIndex = 0; } if (null != oldItems) { // Get rid of old items foreach (DataItem oldDataItem in DataItems.Where(di => (di.SeriesDefinition == definition) && (oldStartingIndex <= di.Index) && (di.Index < oldStartingIndex + oldItems.Count))) { oldDataItem.Index = -1; if (null != oldDataItem.DataPoint) { oldDataItem.DataPoint.State = (int)DataPointState.Hiding; } } // Adjust index of shifted items foreach (DataItem dataItem in DataItems.Where(di => (di.SeriesDefinition == definition) && (oldStartingIndex + oldItems.Count <= di.Index))) { dataItem.Index -= oldItems.Count; } } if (null != newItems) { // Adjust index of shifted items foreach (DataItem dataItem in DataItems.Where(di => (di.SeriesDefinition == definition) && (newStartingIndex <= di.Index))) { dataItem.Index += newItems.Count; } // Add new items AddDataItems(definition, newItems.CastWrapper<object>(), newStartingIndex); } } #if DEBUG // Validate all DataItem index and value properties foreach (var group in DataItems.Where(di => 0 <= di.Index).OrderBy(di => di.Index).GroupBy(di => di.SeriesDefinition)) { object[] items = group.Key.ItemsSource.CastWrapper<object>().ToArray(); int i = 0; foreach (DataItem dataItem in group) { Debug.Assert(i == dataItem.Index, "DataItem index mis-match."); Debug.Assert(dataItem.Value.Equals(items[i]), "DataItem value mis-match."); i++; } } #endif }
/// <summary> /// Handles changes to the ItemsSource of a SeriesDefinition. /// </summary> /// <param name="definition">SeriesDefinition owner.</param> /// <param name="oldValue">Old value.</param> /// <param name="newValue">New value.</param> internal void SeriesDefinitionItemsSourceChanged(SeriesDefinition definition, IEnumerable oldValue, IEnumerable newValue) { if (null != oldValue) { foreach (DataItem dataItem in DataItems.Where(di => di.SeriesDefinition == definition).ToArray()) { DataItems.Remove(dataItem); } RemovedDataItems(); } if (null != newValue) { // No need to add items if SeriesHost null; setting SeriesHost will take care of that if (null != SeriesHost) { AddDataItems(definition, newValue.CastWrapper<object>(), 0); } } }
/// <summary> /// Updates the palette properties of the specified SeriesDefinition. /// </summary> /// <param name="definition">Specified SeriesDefinition.</param> private void UpdatePaletteProperties(SeriesDefinition definition) { ResourceDictionary resources = null; if (null != SeriesHost) { Type dataPointType = CreateDataPoint().GetType(); using (IEnumerator<ResourceDictionary> enumerator = SeriesHost.GetResourceDictionariesWhere(dictionary => { Style style = dictionary["DataPointStyle"] as Style; if (null != style) { return (null != style.TargetType) && (style.TargetType.GetTypeInfo().IsAssignableFrom(dataPointType.GetTypeInfo())); } return false; })) { if (enumerator.MoveNext()) { resources = enumerator.Current; } } } definition.PaletteDataPointStyle = (null != resources) && resources.ContainsKey("DataPointStyle") ? resources["DataPointStyle"] as Style : null; definition.PaletteDataShapeStyle = (null != resources) && resources.ContainsKey("DataShapeStyle") ? resources["DataShapeStyle"] as Style : null; definition.PaletteLegendItemStyle = (null != resources) && resources.ContainsKey("LegendItemStyle") ? resources["LegendItemStyle"] as Style : null; }
/// <summary> /// Initializes a new instance of the DataItem class. /// </summary> /// <param name="seriesDefinition">SeriesDefinition owner.</param> public DataItem(SeriesDefinition seriesDefinition) { SeriesDefinition = seriesDefinition; CenterPoint = new Point(double.NaN, double.NaN); }
/// <summary> /// Updates the placement of the DataItems (data points) of the series. /// </summary> /// <param name="dataItems">DataItems in need of an update.</param> protected override void UpdateDataItemPlacement(IEnumerable <DefinitionSeries.DataItem> dataItems) { if ((null != ActualDependentAxis) && (null != ActualIndependentAxis)) { double plotAreaMaximumDependentCoordinate = ActualDependentAxis.GetPlotAreaCoordinate(ActualDependentRangeAxis.Range.Maximum).Value; double lineTopBuffer = 1; List <Point>[] points = new List <Point> [SeriesDefinitions.Count]; for (int i = 0; i < points.Length; i++) { points[i] = new List <Point>(); } foreach (IndependentValueGroup group in IndependentValueGroupsOrderedByIndependentValue) { double sum = IsStacked100 ? group.DataItems.Sum(di => Math.Abs(ValueHelper.ToDouble(di.DataPoint.ActualDependentValue))) : 1; if (0 == sum) { sum = 1; } double x = ActualIndependentAxis.GetPlotAreaCoordinate(group.IndependentValue).Value; if (ValueHelper.CanGraph(x)) { double lastValue = 0; Point lastPoint = new Point(x, Math.Max(plotAreaMaximumDependentCoordinate - ActualDependentRangeAxis.GetPlotAreaCoordinate(lastValue).Value, lineTopBuffer)); int i = -1; SeriesDefinition lastDefinition = null; foreach (DataItem dataItem in group.DataItems) { if (lastDefinition != dataItem.SeriesDefinition) { i++; } while (dataItem.SeriesDefinition != SeriesDefinitions[i]) { points[i].Add(lastPoint); i++; } DataPoint dataPoint = dataItem.DataPoint; double value = IsStacked100 ? (ValueHelper.ToDouble(dataItem.DataPoint.ActualDependentValue) * (100 / sum)) : ValueHelper.ToDouble(dataItem.DataPoint.ActualDependentValue); if (ValueHelper.CanGraph(value)) { value += lastValue; dataItem.ActualStackedDependentValue = value; double y = ActualDependentRangeAxis.GetPlotAreaCoordinate(value).Value; lastValue = value; lastPoint.Y = Math.Max(plotAreaMaximumDependentCoordinate - y, lineTopBuffer); points[i].Add(lastPoint); dataItem.CenterPoint = new Point(x, plotAreaMaximumDependentCoordinate - y); double left = dataItem.CenterPoint.X - (dataPoint.ActualWidth / 2); double top = dataItem.CenterPoint.Y - (dataPoint.ActualHeight / 2); Canvas.SetLeft(dataItem.Container, Math.Round(left)); Canvas.SetTop(dataItem.Container, Math.Round(top)); dataPoint.Visibility = Visibility.Visible; } else { points[i].Add(lastPoint); dataPoint.Visibility = Visibility.Collapsed; } lastDefinition = dataItem.SeriesDefinition; } } else { foreach (DataPoint dataPoint in group.DataItems.Select(di => di.DataPoint)) { dataPoint.Visibility = Visibility.Collapsed; } } } UpdateShape(points); } }