Reputation: 18201
The Altair example gallery contains a nice example of how to use interval selections to create two plots where one allows you to define the scale of the other. I have been trying to add tooltips to both parts of the stacked chart by defining the tooltips as part of the base:
import altair as alt
from vega_datasets import data
source = data.sp500.url
brush = alt.selection(type='interval', encodings=['x'])
base = alt.Chart(source).mark_area().encode(
x = 'date:T',
y = 'price:Q',
tooltip = 'price:Q'
).properties(
width=600,
height=200
)
upper = base
lower = base.properties(
height=60
).add_selection(brush)
upper & lower
Doing so, the tooltips work as expected on lower
but not at all on upper
.
If, however, I remove the .add_selection(brush)
from lower
, the tooltips also work on upper
(which was unchanged), but that of course defeats the purpose of the example. I can also make the tooltips work on upper
by marking it as interactive, but again, that ruins what's nice about the example. Changing the definition of upper
to upper = base.encode(tooltip='price:Q')
does nothing.
How would I define the tooltip target in a way that makes tooltips show up on both
upper
andlower
?
Upvotes: 2
Views: 638
Reputation: 86320
The fact that the tooltips stop working is probably a bug, and it would be worth filing a Vega-Lite bug report
It appears you can work around this by adding a second empty selection to the upper chart:
upper = base.add_selection(alt.selection_single())
You can view the interactive result here.
Upvotes: 5