public static AxisPoint getAxisPoint(Chart xChart, RangeAxis xAxis, Point xPoint) { if (xAxis == null) return null; if (xAxis is LinearAxis) { // some redundant basic checks LinearAxis lAxis = xAxis as LinearAxis; double? lMin; double? lMax; lMin = lAxis.ActualMinimum; lMax = lAxis.ActualMaximum; if ((!lMin.HasValue) || (!lMax.HasValue)) return null; if (lMin.Value >= lMax.Value) return null; return new AxisPointLinear(xChart, lAxis, xPoint, lMin.Value, lMax.Value); } if (xAxis is DateTimeAxis) { // some redundant basic checks DateTimeAxis lAxis = xAxis as DateTimeAxis; DateTime? lMin; DateTime? lMax; lMin = lAxis.ActualMinimum; lMax = lAxis.ActualMaximum; if ((!lMin.HasValue) || (!lMax.HasValue)) return null; if (lMin.Value >= lMax.Value) return null; return new AxisPointDateTime(xChart, lAxis, xPoint, lMin.Value, lMax.Value); } throw new Exception("Axis type not supported yet."); } //
public readonly double Length; // object pixel display units, larger than zero public AxisPoint(Chart xChart, RangeAxis xAxis, Point xPoint) { if (xAxis.Orientation == AxisOrientation.X) Length = xAxis.ActualWidth; else Length = xAxis.ActualHeight; if (Length <= 0) throw new Exception("Chart object length is zero or less."); MouseAbsoluteLocation = xChart.TranslatePoint(xPoint, xAxis); if (xAxis.Orientation == AxisOrientation.X) MouseAxisValueRelative = MouseAbsoluteLocation.X / Length; else MouseAxisValueRelative = 1.0 - (MouseAbsoluteLocation.Y / Length); if (MouseAxisValueRelative > 1.0) MouseAxisValueRelative = 1.0; else if (MouseAxisValueRelative < 0.0) MouseAxisValueRelative = 0.0; } // constructor