internal int CurveIndexFromCanvasPoint(Point canvasPoint)
        {
            Point  graphPoint = canvasToGraph.Transform(canvasPoint);
            double value      = curve.SortedValues == SortedValues.X ? graphPoint.X : graphPoint.Y;
            int    index      = Curve.GetInterpolatedIndex(curve.TransformedSorted, value);

            if (index == (curve.xTransformed.Length - 1))
            {
                return(curve.SortedToUnsorted[curve.xTransformed.Length - 1]);
            }
            // otherwise return nearest:
            if ((curve.TransformedSorted[index + 1] - value) < (value - curve.TransformedSorted[index]))
            {
                return(curve.SortedToUnsorted[index + 1]);
            }
            else
            {
                return(curve.SortedToUnsorted[index]);
            }
        }