Currently, we index only the x/y point of the label/text mark. However, it would be much better to index the bounding box instead. Since we are not relying on native event listener on each element but rather a spatial index, this is the only way to set event listeners on labels.
This isn't trivial since we don't know the height/width of the text until we actually draw it with the correct font/size etc. I did some quick sleuthing and it turns out that there is a performant way using canvas.measureText() (https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/measureText). A reference implementation can be found at: https://github.com/FormidableLabs/measure-text.
Currently, we index only the x/y point of the label/text mark. However, it would be much better to index the bounding box instead. Since we are not relying on native event listener on each element but rather a spatial index, this is the only way to set event listeners on labels.
This isn't trivial since we don't know the height/width of the text until we actually draw it with the correct font/size etc. I did some quick sleuthing and it turns out that there is a performant way using
canvas.measureText()(https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/measureText). A reference implementation can be found at: https://github.com/FormidableLabs/measure-text.