/// <summary> /// Gets the width of a unit in the chart /// </summary> /// <param name="source">axis orientation</param> /// <param name="chart">chart model to get the scale at</param> /// <param name="axis">axis instance</param> /// <returns></returns> public static double GetUnitWidth(AxisOrientationNew source, ChartCore chart, AxisCoreNew axis) { double min; double u = !double.IsNaN(axis.View.BarUnit) ? axis.View.BarUnit : (!double.IsNaN(axis.View.Unit) ? axis.View.Unit : 1); if (source == AxisOrientationNew.Y) { min = axis.BotLimit; return(ToDrawMargin(min, AxisOrientationNew.Y, chart, axis) - ToDrawMargin(min + u, AxisOrientationNew.Y, chart, axis)); } min = axis.BotLimit; return(ToDrawMargin(min + u, AxisOrientationNew.X, chart, axis) - ToDrawMargin(min, AxisOrientationNew.X, chart, axis)); }
/// <summary> /// Converts from chart values to chart control size. /// </summary> /// <param name="value">value to scale</param> /// <param name="source">axis orientation to scale value at</param> /// <param name="chart">chart model to scale value at</param> /// <param name="axis">axis model instance</param> /// <returns></returns> public static double ToPlotArea(double value, AxisOrientationNew source, ChartCore chart, AxisCoreNew axis) { var p1 = new CorePoint(); var p2 = new CorePoint(); if (source == AxisOrientationNew.Y) { p1.X = axis.TopLimit; p1.Y = chart.DrawMargin.Top; p2.X = axis.BotLimit; p2.Y = chart.DrawMargin.Top + chart.DrawMargin.Height; } else { p1.X = axis.TopLimit; p1.Y = chart.DrawMargin.Width + chart.DrawMargin.Left; p2.X = axis.BotLimit; p2.Y = chart.DrawMargin.Left; } var deltaX = p2.X - p1.X; // ReSharper disable once CompareOfFloatsByEqualityOperator var m = (p2.Y - p1.Y) / (deltaX == 0 ? double.MinValue : deltaX); return(m * (value - p1.X) + p1.Y); }
/// <summary> /// Converts from chart values to chart draw margin size. /// </summary> /// <param name="value">value to scale</param> /// <param name="source">axis orientation</param> /// <param name="chart">chart model to scale the value at</param> /// <param name="axis">axis instance to scale the value at</param> /// <returns></returns> public static double ToDrawMargin(double value, AxisOrientationNew source, ChartCore chart, AxisCoreNew axis) { var o = source == AxisOrientationNew.X ? chart.DrawMargin.Left : chart.DrawMargin.Top; return(ToPlotArea(value, source, chart, axis) - o); }