/// <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(AxisOrientation source, ChartCore chart, AxisCore axis) { double min; double u = !double.IsNaN(axis.View.BarUnit) ? axis.View.BarUnit : (!double.IsNaN(axis.View.Unit) ? axis.View.Unit : 1); if (source == AxisOrientation.Y) { min = axis.BotLimit; return(ToDrawMargin(min, AxisOrientation.Y, chart, axis) - ToDrawMargin(min + u, AxisOrientation.Y, chart, axis)); } min = axis.BotLimit; return(ToDrawMargin(min + u, AxisOrientation.X, chart, axis) - ToDrawMargin(min, AxisOrientation.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, AxisOrientation source, ChartCore chart, AxisCore axis) { var p1 = new CorePoint(); var p2 = new CorePoint(); if (source == AxisOrientation.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, AxisOrientation source, ChartCore chart, AxisCore axis) { var o = source == AxisOrientation.X ? chart.DrawMargin.Left : chart.DrawMargin.Top; return(ToPlotArea(value, source, chart, axis) - o); }