public void CleanupAxes()
        {
            if (null != IndependentRangeAxis)
            {
                SeriesHost.UnregisterWithAxis(this, IndependentRangeAxis);

                IndependentRangeAxis = null;
            }

            if (null != InternalActualIndependentAxis)
            {
                SeriesHost.UnregisterWithAxis(this, InternalActualIndependentAxis);

                InternalActualIndependentAxis = null;
            }

            if (null != DependentRangeAxis)
            {
                SeriesHost.UnregisterWithAxis(this, DependentRangeAxis);

                DependentRangeAxis = null;
            }

            if (null != InternalActualDependentAxis)
            {
                SeriesHost.UnregisterWithAxis(this, InternalActualDependentAxis);

                InternalActualDependentAxis = null;
            }
        }
示例#2
0
 /// <summary>
 /// IndependentAxisProperty property changed handler.
 /// </summary>
 /// <param name="oldValue">Old value.</param>
 /// <param name="newValue">New value.</param>
 protected virtual void OnInternalIndependentAxisPropertyChanged(IAxis oldValue, IAxis newValue)
 {
     if (newValue != null &&
         InternalActualIndependentAxis != null &&
         InternalActualIndependentAxis != newValue &&
         InternalActualIndependentAxis.IsObjectRegistered(this))
     {
         InternalActualIndependentAxis.Invalidated -= OnAxisInvalidated;
         SeriesHost.UnregisterWithAxis(this, InternalActualIndependentAxis);
         GetAxes();
     }
 }
        /// <summary>
        /// Remove an axis from the collection if it is no longer used.
        /// </summary>
        /// <param name="sender">The axis that has had its registered
        /// listeners collection changed.</param>
        /// <param name="e">Information about the event.</param>
        private void AxisRegisteredListenersCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            IAxis axis = this.Where(currentAxis => currentAxis.RegisteredListeners == sender).First();

            if (e.OldItems != null)
            {
                if (!PersistentAxes.Contains(axis) && !SeriesHost.IsUsedByASeries(axis))
                {
                    this.Remove(axis);
                }
            }
        }
        /// <summary>
        /// Removes an item from the axes collection but throws an exception
        /// if a series in the series host is listening to it.
        /// </summary>
        /// <param name="index">The index of the item being removed.</param>
        protected override void RemoveItem(int index)
        {
            IAxis axis = this[index];

            if (SeriesHost.IsUsedByASeries(axis))
            {
                throw new InvalidOperationException(Resources.SeriesHostAxesCollection_RemoveItem_AxisCannotBeRemovedFromASeriesHostWhenOneOrMoreSeriesAreListeningToIt);
            }
            else if (PersistentAxes.Contains(axis))
            {
                throw new InvalidOperationException(Resources.SeriesHostAxesCollection_InvalidAttemptToRemovePermanentAxisFromSeriesHost);
            }
            else
            {
                base.RemoveItem(index);
            }
        }
 /// <summary>
 /// This method synchronizes the collection with the persistent axes
 /// collection when it is changed.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">Information about the event.</param>
 public void PersistentAxesCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
 {
     if (e.NewItems != null)
     {
         foreach (IAxis axis in e.NewItems)
         {
             if (!this.Contains(axis))
             {
                 this.Add(axis);
             }
         }
     }
     if (e.OldItems != null)
     {
         foreach (IAxis axis in e.OldItems)
         {
             if (this.Contains(axis) && !SeriesHost.IsUsedByASeries(axis))
             {
                 this.Remove(axis);
             }
         }
     }
 }
 /// <summary>
 /// Returns the style to use for all data points.
 /// </summary>
 /// <returns>The style to use for all data points.</returns>
 protected override Style GetDataPointStyleFromHost()
 {
     return(SeriesHost.NextStyle(typeof(ColumnDataPoint), true));
 }
示例#7
0
        /// <summary>
        /// Acquires a range axis.
        /// </summary>
        /// <param name="assignedAxis">The axis assigned to the exposed
        /// axis property.</param>
        /// <param name="firstDataPoint">A data point used to determine
        /// where a date or numeric axis is required.</param>
        /// <param name="orientation">The desired orientation of the axis.
        /// </param>
        /// <param name="axisInitializationAction">A function that initializes
        /// a newly created axis.</param>
        /// <param name="axisPropertyAccessor">A function that returns the
        /// current value of the property used to store the axis.</param>
        /// <param name="axisPropertySetter">A function that accepts an axis
        /// value and assigns it to the property intended to store a reference
        /// to it.</param>
        /// <param name="dataPointAxisValueGetter">A function that accepts a
        /// Control and returns the value that will be plot on the axis.
        /// </param>
        protected void GetRangeAxis(
            IAxis assignedAxis,
            DataPoint firstDataPoint,
            AxisOrientation orientation,
            Func <IRangeAxis> axisInitializationAction,
            Func <IRangeAxis> axisPropertyAccessor,
            Action <IRangeAxis> axisPropertySetter,
            Func <DataPoint, object> dataPointAxisValueGetter)
        {
            if (assignedAxis != null)
            {
                if (assignedAxis.Orientation == orientation)
                {
                    IRangeAxis assignedRangeAxis = assignedAxis as IRangeAxis;
                    if (assignedRangeAxis != null)
                    {
                        object value = dataPointAxisValueGetter(firstDataPoint);
                        if (assignedRangeAxis.CanPlot(value))
                        {
                            axisPropertySetter(assignedRangeAxis);
                            if (!assignedAxis.IsObjectRegistered(this))
                            {
                                assignedRangeAxis.Invalidated += OnAxisInvalidated;
                                this.SeriesHost.RegisterWithAxis(this, (IAxis)assignedRangeAxis);
                            }
                            return;
                        }
                        else
                        {
                            throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Properties.Resources.DataPointSeriesWithAxes_AxisCannotPlotValue, value));
                        }
                    }
                    else
                    {
                        throw new InvalidOperationException(Properties.Resources.DataPointSeriesWithAxes_ExpectedAxesOfTypeICategoryAxis);
                    }
                }
                else
                {
                    throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Properties.Resources.DataPointSeriesWithAxes_AxisIsIncorrectOrientation, orientation));
                }
            }

            // If current axis is not suitable...
            if (axisPropertyAccessor() == null || !axisPropertyAccessor().CanPlot(dataPointAxisValueGetter(firstDataPoint)))
            {
                // Attempt to find suitable axis
                IRangeAxis axis =
                    SeriesHost.Axes
                    .Cast <IAxis>()
                    .Where(currentAxis => currentAxis.Orientation == orientation &&
                           currentAxis.CanPlot(dataPointAxisValueGetter(firstDataPoint)) &&
                           currentAxis.CanRegister(this))
                    .OfType <IRangeAxis>()
                    .FirstOrDefault();

                if (axis == null)
                {
                    axis             = axisInitializationAction();
                    axis.Orientation = orientation;
                }

                IAxis baseAxis = (IAxis)axis;
                // Unregister with current axis if it has one.
                if (axisPropertyAccessor() != null)
                {
                    axisPropertyAccessor().Invalidated -= OnAxisInvalidated;
                    SeriesHost.UnregisterWithAxis(this, baseAxis);
                }

                axisPropertySetter(axis);

                if (!axis.IsObjectRegistered(this))
                {
                    axis.Invalidated += OnAxisInvalidated;
                    SeriesHost.RegisterWithAxis(this, baseAxis);
                }
            }
        }
 /// <summary>
 /// Returns the style to use for all data points.
 /// </summary>
 /// <returns>The style to use for all data points.</returns>
 protected override IEnumerator <Style> GetStyleEnumeratorFromHost()
 {
     return(SeriesHost.GetStylesWithTargetType(typeof(T), true));
 }