MouseDown issue with smooth curve

Jan 25, 2013 at 6:51 PM

I noticed that in the MouseDown example, if I enable curve smoothing, I can add new points but get an exception when trying to move a points around. I think the problem is with the e.HitTestResult.Index not being returned correctly (comments below). Is there an alternate way to get the index of the nearest point?

 

// Add a line series
            var s1 = new LineSeries("LineSeries1")
            {
                Color = OxyColors.SkyBlue,
                MarkerType = MarkerType.Circle,
                MarkerSize = 6,
                MarkerStroke = OxyColors.White,
                MarkerFill = OxyColors.SkyBlue,
                MarkerStrokeThickness = 1.5,
                Smooth = true //enable smoothing
            };
            s1.Points.Add(new DataPoint(0, 10));
            s1.Points.Add(new DataPoint(10, 40));
            s1.Points.Add(new DataPoint(40, 20));
            s1.Points.Add(new DataPoint(60, 30));
            model.Series.Add(s1);

            int indexOfPointToMove = -1;

            // Subscribe to the mouse down event on the line series
            s1.MouseDown += (s, e) =>
            {
                // only handle the left mouse button (right button can still be used to pan)
                if (e.ChangedButton == OxyMouseButton.Left)
                {
                    int indexOfNearestPoint = (int)Math.Round(e.HitTestResult.Index);
                    //indexOfNearestPoint: 297, Exception: Index was out of range. Must be non-negative and less than the size of the collection.
                    var nearestPoint = s1.Transform(s1.Points[indexOfNearestPoint]); 

 

 

Coordinator
Feb 10, 2013 at 11:31 PM
Yes, you get an index to the smoothed point collection.
I think the CanonicalSplineHelper must be extended to get the index in the original point collection. Or do you have other good ideas?