public static IEnumerable<AxisLabel> GetAxisLabels(Axis axis) { return axis.GetVisualDescendents().OfType<AxisLabel>(); }
/// <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.LocationChanged -= AxisLocationChanged; axis.OrientationChanged -= AxisOrientationChanged; IRequireSeriesHost requiresSeriesHost = axis as IRequireSeriesHost; if (requiresSeriesHost != null) { requiresSeriesHost.SeriesHost = null; } _edgeAxes.Remove(axis); }
/// <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> /// 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) { IRequireSeriesHost requiresSeriesHost = axis as IRequireSeriesHost; if (requiresSeriesHost != null) { requiresSeriesHost.SeriesHost = this; } if (axis.Location == AxisLocation.Auto) { axis.Location = GetAutoAxisLocation(axis); } SetEdge(axis); axis.LocationChanged += AxisLocationChanged; axis.OrientationChanged += AxisOrientationChanged; if (axis.Location != AxisLocation.Auto) { _edgeAxes.Add(axis); } }
/// <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) { 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> /// Rebuilds the chart area if an axis orientation is changed. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="args">Information about the event.</param> private void AxisOrientationChanged(object sender, RoutedPropertyChangedEventArgs <AxisOrientation> args) { Axis axis = (Axis)sender; axis.Location = GetAutoAxisLocation(axis); }