I am using using HTML5 Canvas to plot lines. A single line is formed by calling drawLine() on multiple intermediate points. For example:
(0,0) -> (10, 10) -> (10, 5) -> (20, 12)
would show up as one line on the plot.
All the (x,y) co-ordinates of a line are stored in an array.
I want to provide the users with the ability to select a line when they click on it. It becomes difficult to do this in HTML5 Canvas as the line is not represented by an object. The only option that I am left with is to first find that (x,y) coordinate of any line that is closest to the (x,y) of a mousedown event. Once I detect which line the user has selected, then I need to redraw the line with a bold color or put a translucent color around it. But, I am assuming that this would be too time-intensive, as it involves looping over all (x,y) coordinates of all lines.
I am looking for ways that can help me achieve the above in a more time-efficient manner. Should I consider using SVG in HTML5?
Any suggestions would be appreciated.