vega-lite icon indicating copy to clipboard operation
vega-lite copied to clipboard

Add nearest property for tooltip.

Open ghost opened this issue 4 years ago • 5 comments

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.

ghost avatar Sep 07 '20 00:09 ghost

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

JeffreyPalmer avatar Oct 12 '20 20:10 JeffreyPalmer

  • you would only want the tooltip when actually touching the line, as opposed to a tooltip for whatever line you are nearest
  • a slight enhancement would be to consider the datapoints on both sides of the contact point, if they disagree at a tooltip field, show something like "field: value 1 - value 2" or maybe an interpolation btw the values

eflister avatar Oct 28 '20 17:10 eflister

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

domoritz avatar Oct 28 '20 18:10 domoritz

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

joelostblom avatar Apr 09 '24 03:04 joelostblom

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

rgowtham avatar Sep 18 '24 22:09 rgowtham