/// <summary> /// Removes an axis from the Chart area. /// </summary> /// <param name="axis">The axis to remove from the ISeriesHost area.</param> private void RemoveAxisFromChartArea(Axis.Axis axis) { axis.LocationChanged -= axis_LocationChanged; axis.OrintationChanged -= axis_OrintationChanged; IRequireSeriesHost requiresSeriesHost = axis as IRequireSeriesHost; if (requiresSeriesHost != null) { requiresSeriesHost.SeriesHost = null; } _edgeAxes.Remove(axis); }
/// <summary> /// Adds an axis to the ISeriesHost area. /// </summary> /// <param name="axis">The axis to add to the ISeriesHost area.</param> private void AddAxisToChartArea(Axis.Axis axis) { IRequireSeriesHost requiresSeriesHost = axis as IRequireSeriesHost; if (requiresSeriesHost != null) { requiresSeriesHost.SeriesHost = this; } if (axis.Location == AxisLocation.Auto) { axis.Location = GetAutoAxisLocation(axis); } SetEdge(axis); axis.LocationChanged += axis_LocationChanged; axis.OrintationChanged +=axis_OrintationChanged; if (axis.Location != AxisLocation.Auto) { _edgeAxes.Add(axis); if (this.ChartArea != null) { this.ChartArea.Children.Add(axis); if (BackgroundElements.Count > 0) { foreach (UIElement element in BackgroundElements) { this.ChartArea.Children.Insert(0, element); } } } } }
/// <summary> /// Sets the Edge property of an axis based on its location and /// orientation. /// </summary> /// <param name="axis">The axis to set the edge property of.</param> private static void SetEdge(Axis.Axis axis) { switch (axis.Location) { case AxisLocation.Bottom: EdgePanel.SetEdge(axis, Edge.Bottom); break; case AxisLocation.Top: EdgePanel.SetEdge(axis, Edge.Top); break; case AxisLocation.Left: EdgePanel.SetEdge(axis, Edge.Left); break; case AxisLocation.Right: EdgePanel.SetEdge(axis, Edge.Right); break; } }
/// <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 axis) { if (axis.Orientation == AxisOrientation.X) { int numberOfTopAxes = InternalActualAxes.OfType<Axis.Axis>().Where(currentAxis => currentAxis.Location == AxisLocation.Top).Count(); int numberOfBottomAxes = InternalActualAxes.OfType<Axis.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.Axis>().Where(currentAxis => currentAxis.Location == AxisLocation.Left).Count(); int numberOfRightAxes = InternalActualAxes.OfType<Axis.Axis>().Where(currentAxis => currentAxis.Location == AxisLocation.Right).Count(); return (numberOfLeftAxes > numberOfRightAxes) ? AxisLocation.Right : AxisLocation.Left; } else { return AxisLocation.Auto; } }