While a voronoi or quadtree can be used as a technique for single point events (i.e. tooltips), hit detection for paths/rects/etc (ex. GeoPath or Pie arcs) are more challenging.
Using the r-tree algorithm such as is available with Flatbush provides fast boundary box lookups, although you can get multiple results for overlapping boxes and will need to do a deeper compare (using something like geoContains())
Another technique is to draw a second (hidden) canvas with distinct colors and register data for each color in a lookup, and then use context.getImageData() to get the color for the pointer coordinates, and return the data. This has some challenges with canvas anti-aliasing on the edges, but is simpler (especially without needing a deeper comparison)
While a voronoi or quadtree can be used as a technique for single point events (i.e. tooltips), hit detection for paths/rects/etc (ex. GeoPath or Pie arcs) are more challenging.
Using the r-tree algorithm such as is available with Flatbush provides fast boundary box lookups, although you can get multiple results for overlapping boxes and will need to do a deeper compare (using something like
geoContains())Another technique is to draw a second (hidden) canvas with distinct colors and register data for each color in a lookup, and then use
context.getImageData()to get the color for the pointer coordinates, and return the data. This has some challenges with canvas anti-aliasing on the edges, but is simpler (especially without needing a deeper comparison)