core-plot - detect touch on line between points of a CPTScatterPlot (iOS)?

StackOverflow https://stackoverflow.com/questions/21786755

  •  11-10-2022
  •  | 
  •  

Frage

I have a line graph made with CPTScatterPlot. I can detect touches on the plot points easily enough, but I want to also respond to touches on the line connecting the points.

Is there an easy way to do that?

I know I can use indexOfVisiblePointClosestToPlotAreaPoint to find the plot point closest to the user's touch. Converting to view coordinates and doing the same with the next (or previous) plot point, I can calculate whether or not the user's touch is on the line connecting those two points with something like:

(pt2.x - pt1.x)*(touchPoint.y - pt1.y) - (pt2.y - pt1.y)*(touchPoint.x - pt1.x)

where pt1 and pt2 are the view coords of the two plot points, and touchPoint is the point where the user touched somewhere between them (pt1.x <= touchPoint.x <= pt2.x).

This will work, but I'm thinking there must be an easier way - it seems as if Core Plot should be able to do this for me.

Is there an easier way to do this, or do I have to do it the hard way? If I have to do it the hard way, would this be something worth submitting as an enhancement to the core plot team? If so, I'll implement it in CPTScatterPlot and send in a patch. Otherwise I'll just do it in my own classes and handle it myself.

War es hilfreich?

Lösung

Core Plot does not currently support this feature, although there is an open issue requesting it. If you come up with a solution you want to share, pull requests are welcome.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top