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; } }
/// <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> /// 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); } } }