/// <summary> /// Find the nearest DataPoint from each dataSeries from a xValue and yValue /// </summary> /// <param name="dataSeries"></param> /// <param name="internalXValue">internalXValue</param> /// <param name="internalYValue">internalYValue</param> /// <returns></returns> internal static DataPoint GetNearestDataPoint(DataSeries dataSeries, Double xValueAtMousePos, Double yValueAtMousePos) { DataPoint nearestDataPoint = null; // Get all DataPoints order by the XValue distance from the internalXValue. List <DataPoint> dataPointsAlongX = (from dp in dataSeries.InternalDataPoints where !(RenderHelper.IsFinancialCType(dp.Parent) && dp.InternalYValues == null) || !(!RenderHelper.IsFinancialCType(dp.Parent) && Double.IsNaN(dp.YValue)) orderby Math.Abs(dp.InternalXValue - xValueAtMousePos) select dp).ToList(); if (dataPointsAlongX.Count > 0) { // Get the internalXValue of the first DataPoint of the ordered list Double xValue = dataPointsAlongX[0].InternalXValue; // DataPoints along y pixel direction which have same XValue List <DataPoint> dataPointsAlongYAxisHavingSameXValue = new List <DataPoint>(); foreach (DataPoint dp in dataPointsAlongX) { if (dp.InternalXValue == xValue) { dataPointsAlongYAxisHavingSameXValue.Add(dp); } } if (!Double.IsNaN(yValueAtMousePos)) { // Sort according to YValue or YValues if (RenderHelper.IsFinancialCType(dataSeries)) { dataPointsAlongYAxisHavingSameXValue = (from dp in dataPointsAlongYAxisHavingSameXValue where (dp.InternalYValues != null) orderby Math.Abs(dp.InternalYValues.Max() - yValueAtMousePos) select dp).ToList(); } else { dataPointsAlongYAxisHavingSameXValue = (from dp in dataPointsAlongYAxisHavingSameXValue where !Double.IsNaN(dp.InternalYValue) orderby Math.Abs(dp.InternalYValue - yValueAtMousePos) select dp).ToList(); } } if (dataPointsAlongYAxisHavingSameXValue.Count > 0) { nearestDataPoint = dataPointsAlongYAxisHavingSameXValue.First(); } } return(nearestDataPoint); }
/// <summary> /// Get nearest DataPoint along XAxis /// </summary> /// <param name="dataPoints"></param> /// <param name="internalXValue"></param> /// <returns></returns> internal static DataPoint GetNearestDataPointAlongXAxis(List <DataPoint> dataPoints, Axis xAxis, Double internalXValue) { List <DataPoint> dataPointsAlongX = (from dp in dataPoints where !(RenderHelper.IsFinancialCType(dp.Parent) && dp.InternalYValues == null) || !(!RenderHelper.IsFinancialCType(dp.Parent) && Double.IsNaN(dp.YValue)) orderby Math.Abs(dp.InternalXValue - internalXValue) select dp).ToList(); if (dataPointsAlongX.Count > 0) { return(dataPointsAlongX.First()); } else { return(null); } }