/// <summar
        /// Ensures that ISeriesHost is in a consistent state when axes collection is
        /// changed.
        /// </summary>
        /// <param name="sender">Event source.</param>
        /// <param name="e">Event arguments.</param>
        private void OnAxesCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (e.NewItems != null)
            {
                foreach (IAxis axis in e.NewItems)
                {
                    if (!InternalActualAxes.Contains(axis))
                    {
                        InternalActualAxes.Add(axis);
                    }
                }
            }
            if (e.OldItems != null)
            {
                foreach (IAxis axis in e.OldItems)
                {
                    if (!axis.IsUsed)
                    {
                        InternalActualAxes.Remove(axis);
                    }
                    else
                    {
                        throw new InvalidOperationException(Properties.Resources.Chart_OnAxesCollectionChanged_AnAxisCannotBeRemovedFromTheChartWhenItIsInUseByAnObject);
                    }
                }
            }

            NotifyCollectionChangedEventHandler handler = AxesChanged;

            if (handler != null)
            {
                handler(sender, e);
            }
        }
        /// <summary>
        /// Signals to the ISeriesHost that a series would like to use an axis.
        /// </summary>
        /// <param name="series">The series that would like to use the axis.
        /// </param>
        /// <param name="axis">The axis the series would like to use.</param>
        void ISeriesHost.RegisterWithAxis(Series series, IAxis axis)
        {
            if (series == null)
            {
                throw new ArgumentNullException("series");
            }
            if (axis == null)
            {
                throw new ArgumentNullException("axis");
            }

            axis.Register(series);
            if (!InternalActualAxes.Contains(axis))
            {
                InternalActualAxes.Add(axis);
            }
        }
Exemple #3
0
 /// <summary>
 /// Determines the location of an axis based on the existing axes in
 /// the chart.
 /// </summary>
 /// <param name="axis">The axis to determine the location of.</param>
 /// <returns>The location of the axis.</returns>
 private AxisLocation GetAutoAxisLocation(Axis axis)
 {
     if (axis.Orientation == AxisOrientation.X)
     {
         int numberOfTopAxes    = InternalActualAxes.OfType <Axis>().Where(currentAxis => currentAxis.Location == AxisLocation.Top).Count();
         int numberOfBottomAxes = InternalActualAxes.OfType <Axis>().Where(currentAxis => currentAxis.Location == AxisLocation.Bottom).Count();
         return((numberOfBottomAxes > numberOfTopAxes) ? AxisLocation.Top : AxisLocation.Bottom);
     }
     else if (axis.Orientation == AxisOrientation.Y)
     {
         int numberOfLeftAxes  = InternalActualAxes.OfType <Axis>().Where(currentAxis => currentAxis.Location == AxisLocation.Left).Count();
         int numberOfRightAxes = InternalActualAxes.OfType <Axis>().Where(currentAxis => currentAxis.Location == AxisLocation.Right).Count();
         return((numberOfLeftAxes > numberOfRightAxes) ? AxisLocation.Right : AxisLocation.Left);
     }
     else
     {
         return(AxisLocation.Auto);
     }
 }
        /// <summary>
        /// Signals to the Chart that a Series no longer needs to use the axis
        /// within this series host.
        /// </summary>
        /// <param name="series">The Series object that no longer needs to use
        /// the axis.</param>
        /// <param name="axis">The axis that the Series no longer needs to use.
        /// </param>
        void ISeriesHost.UnregisterWithAxis(Series series, IAxis axis)
        {
            if (series == null)
            {
                throw new ArgumentNullException("series");
            }
            if (axis == null)
            {
                throw new ArgumentNullException("axis");
            }
            if (!ActualAxes.Contains(axis))
            {
                throw new InvalidOperationException(Properties.Resources.Chart_UnregisterWithSeries_OneAxisCannotBeUsedByMultipleCharts);
            }

            axis.Unregister(series);
            // If axis is no longer used and is not in external axes collection
            if (!axis.IsUsed && !Axes.Contains(axis))
            {
                InternalActualAxes.Remove(axis);
            }
        }