vega / vega-lite

A concise grammar of interactive graphics, built on Vega.
https://vega.github.io/vega-lite/
BSD 3-Clause "New" or "Revised" License
4.67k stars 608 forks source link

Add nearest property for tooltip. #6851

Open ghost opened 4 years ago

ghost commented 4 years ago

Suggestion

Add nearest property to tooltip:

{
  "mark": {"type": "line", "tooltip": {"content": "encoding", "nearest": true}},
  "encoding": {"x": {"field": "a"}, "y": {"field": "b"}}
}

Motivation

I have enabled tooltips on a line chart. However, the tooltip only appears when you hover over an actual data point, rather than over the line itself. The data points in a line are very small and often far apart, so having something like nearest might make it easier to activate the tooltip.

JeffreyPalmer commented 4 years ago

Is there a way to do this manually in the meantime?

eflister commented 3 years ago
domoritz commented 3 years ago

The nearest computation could have a limit above which we don't show the tooltip(ref https://github.com/vega/vega-lite/issues/4262)

joelostblom commented 6 months ago

I agree that a nearest property for the tooltip would be helpful. Currently it can be hard to hit the exact pixel of e.g. a line chart corner to show the tooltip. Especially together with a distance limit (https://github.com/vega/vega-lite/issues/4262) and some sort of indication of which data point the tool tip belongs to (e.g. with a call out wedge/arrow) would make the tooltips easier to use. I think how this is handled in plotly is quite intuitive in terms of both the distance of activation and the little arrow pointing at the data point.

https://github.com/vega/vega-lite/assets/4560057/13ac4f90-1bee-4857-b53a-66a2ebd44b8d

rgowtham commented 1 month ago

It would help to have this feature implemented - currently there seems to be workarounds that can achieve this as per this discussion - https://github.com/vega/altair/discussions/3597. But it would be helpful to have this implemented directly