/// <summary>
        /// Detects whether an item is being dragged over a legend item and
        /// selects the owner series as the drop target.
        /// </summary>
        /// <param name="args">Information about the drag event.</param>
        /// <returns>The drop target.</returns>
        protected override DataPointSeries GetDropTarget(SW.DragEventArgs args)
        {
            DependencyObject originalSource = (DependencyObject)args.OriginalSource;
            LegendItem       legendItem     = originalSource.GetVisualAncestorsAndSelf().OfType <LegendItem>().FirstOrDefault();

            if (legendItem != null)
            {
                DataPointSeries dataPointSeries = legendItem.Owner as DataPointSeries;
                if (dataPointSeries != null)
                {
                    return(dataPointSeries);
                }
            }

            DataPointSeries seriesAncestor = GetItemsControlAncestor(originalSource);

            if (seriesAncestor != null)
            {
                return(seriesAncestor);
            }

            if (Chart != null)
            {
                return(Chart.Series.OfType <DataPointSeries>().LastOrDefault());
            }

            return(null);
        }
 /// <summary>
 /// Initializes a new instance of the SeriesDefinition class.
 /// </summary>
 public SeriesDefinition()
 {
     _legendItem = new LegendItem { Owner = this };
     _legendItem.SetBinding(LegendItem.ContentProperty, new Binding("ActualTitle") { Source = this });
     _legendItem.SetBinding(LegendItem.StyleProperty, new Binding("ActualLegendItemStyle") { Source = this });
     _legendItems.Add(_legendItem);
 }
Beispiel #3
0
        /// <summary>
        /// Creates a legend item.
        /// </summary>
        /// <returns>A legend item for insertion in the legend items collection.
        /// </returns>
        protected virtual LegendItem CreateLegendItem()
        {
            LegendItem legendItem = new LegendItem();

            legendItem.SetStyle(LegendItemStyle);

            return(legendItem);
        }
Beispiel #4
0
        /// <summary>
        ///     Updates the indexes of all legend items when a change is made to the collection.
        /// </summary>
        private void UpdateLegendItemIndexes()
        {
            int index = 0;

            foreach (DataPoint dataPoint in ActiveDataPoints)
            {
                LegendItem legendItem = _dataPointLegendItems[dataPoint];
                legendItem.Content = dataPoint.IndependentValue ?? (index + 1);
                index++;
            }
        }
Beispiel #5
0
        /// <summary>
        ///     Removes data point's legend item when the data point is removed.
        /// </summary>
        /// <param name="dataPoint">The data point to remove.</param>
        protected override void RemoveDataPoint(DataPoint dataPoint)
        {
            base.RemoveDataPoint(dataPoint);
            if (dataPoint != null)
            {
                LegendItem legendItem = _dataPointLegendItems[dataPoint];
                _dataPointLegendItems.Remove(dataPoint);

                LegendItems.Remove(legendItem);
                UpdateLegendItemIndexes();
            }
        }
 /// <summary>
 /// Initializes a new instance of the SeriesDefinition class.
 /// </summary>
 public SeriesDefinition()
 {
     _legendItem = new LegendItem {
         Owner = this
     };
     _legendItem.SetBinding(LegendItem.ContentProperty, new Binding("ActualTitle")
     {
         Source = this
     });
     _legendItem.SetBinding(LegendItem.StyleProperty, new Binding("ActualLegendItemStyle")
     {
         Source = this
     });
     _legendItems.Add(_legendItem);
 }
Beispiel #7
0
        /// <summary>
        ///     Creates a legend item for each data point.
        /// </summary>
        /// <param name="dataPoint">The data point added.</param>
        protected override void AddDataPoint(DataPoint dataPoint)
        {
            base.AddDataPoint(dataPoint);
            var pieDataPoint = (PieDataPoint)dataPoint;

            int        index      = ActiveDataPoints.IndexOf(dataPoint) + 1;
            LegendItem legendItem = CreatePieLegendItem(dataPoint, index);

            // Grab a style enumerator if we don't have one already.
            if (_resourceDictionaryEnumerator == null)
            {
                _resourceDictionaryEnumerator = GetResourceDictionaryWithTargetType(this, typeof(PieDataPoint), true);
            }

            if (_resourceDictionaryEnumerator.MoveNext())
            {
                ResourceDictionary paletteResources =
#if SILVERLIGHT
                    _resourceDictionaryEnumerator.Current.ShallowCopy();
#else
                    _resourceDictionaryEnumerator.Current;
#endif
                pieDataPoint.PaletteResources = paletteResources;
                pieDataPoint.Resources.MergedDictionaries.Add(paletteResources);
            }
            else
            {
                pieDataPoint.PaletteResources = null;
            }
            pieDataPoint.ActualDataPointStyle = DataPointStyle ?? pieDataPoint.Resources[DataPointStyleName] as Style;
            pieDataPoint.SetBinding(StyleProperty,
                                    new Binding(PieDataPoint.ActualDataPointStyleName)
            {
                Source = pieDataPoint
            });
            pieDataPoint.ActualLegendItemStyle = LegendItemStyle ??
                                                 (pieDataPoint.Resources[LegendItemStyleName] as Style);
            legendItem.SetBinding(StyleProperty, new Binding(ActualLegendItemStyleName)
            {
                Source = pieDataPoint
            });

            _dataPointLegendItems[dataPoint] = legendItem;
            LegendItems.Add(legendItem);
            UpdateLegendItemIndexes();
        }
        /// <summary>
        /// Creates a legend item from a data point.
        /// </summary>
        /// <param name="dataPoint">The data point to use to create the legend item.</param>
        /// <param name="index">The 1-based index of the Control.</param>
        /// <returns>The series host legend item.</returns>
        private LegendItem CreatePieLegendItem(DataPoint dataPoint, int index)
        {
            LegendItem legendItem = CreateLegendItem();

            // Set the Content of the LegendItem
            legendItem.Content = dataPoint.IndependentValue ?? index;
            // Create a representative DataPoint for access to styled properties
            DataPoint legendDataPoint = CreateDataPoint();

            legendDataPoint.DataContext = dataPoint.DataContext;
            if (null != PlotArea)
            {
                // Bounce into the visual tree to get default Style applied
                PlotArea.Children.Add(legendDataPoint);
                PlotArea.Children.Remove(legendDataPoint);
            }
            legendDataPoint.SetStyle(dataPoint.Style);
            legendItem.DataContext = legendDataPoint;
            return(legendItem);
        }
Beispiel #9
0
        /// <summary>
        /// Creates a legend item from a data point.
        /// </summary>
        /// <param name="dataPoint">The data point to use to create the legend item.</param>
        /// <param name="index">The 1-based index of the Control.</param>
        /// <returns>The series host legend item.</returns>
        protected virtual LegendItem CreatePieLegendItem(DataPoint dataPoint, int index)
        {
            LegendItem legendItem = CreateLegendItem(this);

            // Set the Content of the LegendItem
            legendItem.Content = dataPoint.IndependentValue ?? index;
            // Create a representative DataPoint for access to styled properties
            DataPoint legendDataPoint = CreateDataPoint();

            legendDataPoint.DataContext = dataPoint.DataContext;
            if (null != PlotArea)
            {
                // Bounce into the visual tree to get default Style applied
                PlotArea.Children.Add(legendDataPoint);
                PlotArea.Children.Remove(legendDataPoint);
            }
            legendDataPoint.SetBinding(DataPoint.StyleProperty, new Binding(PieDataPoint.ActualDataPointStyleName)
            {
                Source = dataPoint
            });
            legendItem.DataContext = legendDataPoint;
            return(legendItem);
        }
Beispiel #10
0
        /// <summary>
        /// Creates a legend item for each data point.
        /// </summary>
        /// <param name="dataPoint">The data point added.</param>
        protected override void AddDataPoint(DataPoint dataPoint)
        {
            base.AddDataPoint(dataPoint);

            int index = ActiveDataPoints.IndexOf(dataPoint) + 1;

            // Grab a style enumerator if we don't have one already.
            if (_styleEnumerator == null)
            {
                _styleEnumerator = this.GetStylesWithTargetType(typeof(PieDataPoint), true);
            }

            if (_styleEnumerator.MoveNext())
            {
                Style style = _styleEnumerator.Current;
                dataPoint.SetStyle(style);
            }

            LegendItem legendItem = CreatePieLegendItem(dataPoint, index);

            _dataPointLegendItems[dataPoint] = legendItem;
            LegendItems.Add(legendItem);
            UpdateLegendItemIndexes();
        }
        /// <summary>
        /// Creates a legend item.
        /// </summary>
        /// <returns>A legend item for insertion in the legend items collection.
        /// </returns>
        protected virtual LegendItem CreateLegendItem()
        {
            LegendItem legendItem = new LegendItem();
            legendItem.SetStyle(LegendItemStyle);

            return legendItem;
        }
        /// <summary>
        /// Initializes a new instance of the FunctionSeries class.
        /// </summary>
        public FunctionSeries()
        {
            LegendItem = new LegendItem();
            LegendItems.Add(LegendItem);
            Clip = ClipGeometry = new RectangleGeometry();
            SizeChanged += OnSizeChanged;

            // Explicitly load the default template since the samples project
            // is an application and does not have a generic.xaml file.
            Template = XamlReader.Load(DefaultTemplate) as ControlTemplate;
            LineBrush = new SolidColorBrush(Colors.Purple);
        }
 /// <summary>
 /// Creates a legend item.
 /// </summary>
 /// <returns>A legend item for insertion in the legend items collection.
 /// </returns>
 /// <param name="owner">The owner of the new LegendItem.</param>
 protected virtual LegendItem CreateLegendItem(DataPointSeries owner)
 {
     LegendItem legendItem = new LegendItem() { Owner = owner };
     legendItem.SetBinding(LegendItem.StyleProperty, new Binding(ActualLegendItemStyleName) { Source = this });
     legendItem.SetBinding(LegendItem.ContentProperty, new Binding(TitleName) { Source = this });
     return legendItem;
 }