williamngan/pts

Canvas mouse events coord is wrong on layout change

ProtonGustave opened this issue · 1 comments

You calculate local coordinates there based on evt.pageX/evt.pageY and canvas page bounds. Element page bounds variable gets updated on "resize" page event(and manual "resize" calls), but page layout may be changed all the time(some data is loaded and element above chart became bigger for example).
Easiest fix is to use evt.offsetX/evt.offsetY, but this also highlight problem with "bounds" variable, better not to use it if possible since there is no performant tracker of element position.

You're right that it's not ideal as it'll take some manual calculations for advanced layout changes. I think I encountered some issue with offsetX/offsetY (maybe it's not supported by touch event, or some other issues).

Worth revisiting and improve this one!