SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, and now iOS Charting & Android Chart Components

0
0

I am creating a digital line editor based on the SimpleDataPointEditModifier posted on this site. Almost everything is working the way I want it to except the hit test. My plan is to derive a new class from the FastLineRenderableSeries, with IsDigitalLine = true set in the constructor. I will then override the hit test. There would be no need of a radius because a hit on the series would always be a hit on a point. Each point has a vertical line before it and a horizontal line after. Clicking any place on that vertical or horizontal line should select the point it belongs to instead of the nearest point by radius.

I think rewriting the hit test would go faster if I could see the code for the existing hit test. Is it possible to post that method here? Thanks.

  • You must to post comments
1
0

I was able to get something that seems to work well. If I find any rough spots I should be able to tweak it. I tried to attached my new series class and the modifier that works with it, but I could not get the attachment to work. Here is my hit test. public override HitTestInfo HitTest(Point rawPoint, double hitTestRadius, bool interpolate = false) { // it looks like HitTest is called to determine if the series IsSelected. This must be done in the base method // so we need to call it here. var hitTestInfo = base.HitTest(rawPoint, hitTestRadius, interpolate); var currentXValue = XAxis.GetCurrentCoordinateCalculator().GetDataValue(rawPoint.X); var currentYValue = YAxis.GetCurrentCoordinateCalculator().GetDataValue(rawPoint.Y); // use the x value to narrow down the selected index to one of two values, currentIndex and currentIndex + 1 var currentIndex = 0; for (var i = 0; i < DataSeries.Count – 1; i++) { var x1 = (double) DataSeries.XValues[i]; var x2 = (double) DataSeries.XValues[i + 1]; if (currentXValue >= x1 && currentXValue < x2) { var y1 = (double)DataSeries.YValues[i]; var y2 = (double)DataSeries.YValues[i + 1]; var deltaX1 = Math.Abs(currentXValue – x1); var deltaX2 = Math.Abs(currentXValue – x2); var deltaY1 = Math.Abs(currentYValue – y1); var deltaY2 = Math.Abs(currentYValue – y2); var minimumDistanceFromPoint1 = Math.Min(deltaX1, deltaY1); var minimumDistanceFromPoint2 = Math.Min(deltaX2, deltaY2); currentIndex = i; if (minimumDistanceFromPoint2 < minimumDistanceFromPoint1) currentIndex = i + 1; break; } } // overwrite value from base method hitTestInfo.DataSeriesIndex = currentIndex; hitTestInfo.XValue = (double)DataSeries.XValues[currentIndex]; hitTestInfo.YValue = (double)DataSeries.YValues[currentIndex]; var xPoint = XAxis.GetCurrentCoordinateCalculator().GetCoordinate((double)DataSeries.XValues[currentIndex]); var yPoint = YAxis.GetCurrentCoordinateCalculator().GetCoordinate((double)DataSeries.YValues[currentIndex]); hitTestInfo.HitTestPoint = new Point(xPoint, yPoint); return hitTestInfo; }

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.