palantir / plottable

:bar_chart: A library of modular chart components built on D3
http://plottablejs.org/
MIT License
2.96k stars 224 forks source link

Use entityNearest() rather than entityNearestByXThenY() for LinePlot.entitiesAt() #3558

Open mcintyret opened 3 years ago

mcintyret commented 3 years ago

Usinig entityNearestByXThenY causes some weird behaviour - if the cursor is marginally closer in the x domain to another point than the one the user intended to click on, that point will be the one that gets selected - even if it is hundreds of pixels away in the y domain.

Even worse, the tooltip-on-hover codepath just uses entityNearest(), so the intuitive nearest point has a tooltip, but then clicking selects a different point.

I went through the git history and couldn't see any reason why the "by x then y" approach was taken, but may well be missing something.

Hovering showing the nearest point: image

After clicking at that exact same cursor location: image

After this PR, the selected point is the expected one.

blueprint-bot commented 3 years ago

Use entityNearest() rather than entityNearestByXThenWhy() for LinePlot.entitiesAt()

Demo: quicktests | fiddle