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.7k stars 618 forks source link

Nearest and Tooltip interact in an undesirable way #5109

Open mpickering opened 5 years ago

mpickering commented 5 years ago

The nearest selection and tooltips interact in a surprising manner.

Example Chart

There are two layers the chart, a stacked area chart and a rule chart. The desired behaviour is that

  1. The nearest rule is highlighted (I didn't include this in the example but it works)
  2. The tooltip displays information about the area chart on hover.

The actual behaviour:

  1. The nearest rule is highlighted
  2. The tooltip constantly displays information about the rule as it is "selected"

My understanding was that defining a selection should have no visible change to the rendering of the chart. Any effect should be configured by the user using the various conditional operations. This special(?) behaviour for tooltips violates the expectation.

I suspect there would be similar bad interactions if I defined another nearest selection for the "area" layer. In that case I would expect the selection to only scope over the area chart so that there would be no conflict between the two selections.

domoritz commented 5 years ago

@kanitw @arvind Is this expected behavior? Is there a simple to change the behavior?

arvind commented 5 years ago

The nearest transform operates by adding transparent cells generated by a voronoi decomposition. These cells necessarily capture events to drive selection processing and in #4726 we made sure that the voronoi cells persisted the tooltip for the unit spec they are defined in. One could disable tooltips for the layer in which a nearest selection is defined, but as the transparent event-capturing voronoi cells will continue to be generated and overlay the visualization, @mpickering desired behavior is still not possible.

I agree this doesn't seem like a desirable outcome but I don't have a good idea yet of how to fix it while still preserving a way to drive accelerated selections... I'm open to ideas!

mpickering commented 5 years ago

I don't the implementation well enough to suggest a solution. Why does the transparent layer capture all mouse events? Should mouse events not be propagated through all layers? Then if multiple layers define a tooltip the one highest on the stack should be preferred.

arvind commented 5 years ago

Indeed, that's a great suggestion. Unfortunately, the Vega stack implements our custom scenegraph model that does not yet implement full support for event propagation (capturing/bubbling, see vega/vega#1494) ergo why I'm a little stuck for alternative workarounds currently :)