// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.
namespace System.Windows.Controls.DataVisualization.Charting
{
///
/// A set of extension methods for the DataPoint class.
///
internal static class FrameworkElementExtensions
{
///
/// Returns the actual margin for a given framework element and axis.
///
/// The framework element.
/// The axis along which to return the margin.
///
/// The margin for a given framework element and axis.
///
public static double GetActualMargin(this FrameworkElement element, IAxis axis)
{
double length = 0.0;
if (axis.Orientation == AxisOrientation.X)
{
length = element.ActualWidth;
}
else if (axis.Orientation == AxisOrientation.Y)
{
length = element.ActualHeight;
}
return length / 2.0;
}
///
/// Returns the margin for a given framework element and axis.
///
/// The framework element.
/// The axis along which to return the margin.
///
/// The margin for a given framework element and axis.
///
public static double GetMargin(this FrameworkElement element, IAxis axis)
{
double length = 0.0;
if (axis.Orientation == AxisOrientation.X)
{
length = !double.IsNaN(element.Width) ? element.Width : element.ActualWidth;
}
else if (axis.Orientation == AxisOrientation.Y)
{
length = !double.IsNaN(element.Height) ? element.Height : element.ActualHeight;
}
return length / 2.0;
}
}
}