d3-brush icon indicating copy to clipboard operation
d3-brush copied to clipboard

Brushing uses wrong mouse coordinates if perspective transformations are applied

Open s9ferech opened this issue 3 years ago • 3 comments

If I zoom in on a visualization through CSS perspective transformations then brushing on that visualizations will behave weird because the wrong mouse coordinates will be used. I created a small example to demonstrate this. When brushing over the circle, the selection does not follow the cursor.

s9ferech avatar Apr 16 '21 13:04 s9ferech

Confirmed in d3v6. Do you have an idea to solve this?

I think the issue is in d3.pointer, not specifically d3.brush.

It's fun to see that it doesn't happen with 2D transforms, like transform: rotate(45deg), where the brush seems to correctly follow the mouse.

Fil avatar Apr 19 '21 14:04 Fil

Related https://github.com/d3/d3-selection/issues/67 https://github.com/d3/d3-selection/issues/68 https://github.com/d3/d3-selection/issues/72 https://github.com/d3/d3-selection/issues/81

There’s a long history of browsers not implementing getScreenCTM correctly, and generally speaking I don’t think D3 should attempt to workaround browser bugs or quirks: D3 is not a compatibility layer.

mbostock avatar Apr 19 '21 14:04 mbostock

The properties MouseEvent.offsetX and MouseEvent.offsetY seem to provide the right coordinates in Chrome and Firefox. I suppose they could be used to fix this without much trouble. But their specification is currently still experimental.

s9ferech avatar Apr 19 '21 16:04 s9ferech