mouseMove and CSS transforms don't get along
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 10.5k
- Forks
- 463
- PR merge metrics
- No merged PRs in 30d
Description
I have uPlots embedded in pages where I'm using a CSS transform to scale the entire page up or down. This mostly works, but the mouse position is not tracked correctly. Someone else hit the same problem and created a codepen: https://codepen.io/chrisdalke/pen/WNomELr look at the third chart and how the crosshair position is out of sync with the mouse pointer. Basically, uPlot uses page pixels but the whole uPlot is scaled by 2x so the cross hairs diverge from the pointer as you move right and down from the top-left corner. MouseMove should use "element coordinates" that are scaled by the browser just like the element is scaled.
(I have no association with the user that created that codepen, I just bumped into it as I was going to create my own codepen, saved me a bunch of work :-).
I played around a bit and the following fixes the issue for me. In cacheMouse https://github.com/leeoniya/uPlot/blob/master/src/uPlot.js#L2737-L2740 replace by:
if (e != null) {
_l = e.offsetX;
_t = e.offsetY;
}
I'm not a browser event whizz so I don't know what else this might break. The mozilla docs https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/offsetX are "clear as mud" to me...
Thanks for an amazing lib overall!!!
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in src/uPlot.js around cacheMouse at lines 2737-2740, then reproduce the third chart in the linked CodePen with a 2x CSS transform. Compare the event coordinate choices and verify that the crosshair stays aligned with the pointer as it moves across the chart, without breaking normal mouse tracking.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- data-visualization, frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100