Reputation: 35
I have a scatterplot with custom tooltips, when hovering over a bit of the screens where two dots overlap the tooltip for both are drawn on top of one another.
Is there a way to merge the two into one tooltip, as the default tooltip does, or force them to be drawn in non-intersecting ways?
Upvotes: 2
Views: 1058
Reputation: 8287
This code will never display more then 1 tooltip (Bokeh v1.3.0):
from bokeh.plotting import figure, show
from bokeh.models import CustomJS
data = dict(
x=[1, 2, 3],
y=[1, 2, 3],
color=['red', 'green', 'blue'], )
p = figure(tooltips=[('x','@x'),('y', '@y')])
p.circle('x', 'y', color='color', size=10, source = data)
code= '''if (cb_data.index.indices.length > 1) {
document.getElementsByClassName('bk-tooltip')[0].style.display = 'none';
}'''
p.hover.callback = CustomJS(code = code)
show(p)
Disadvantage of this solution is that when all dots exactly overlay each other no tooltips will be shown at all
Upvotes: 1
Reputation: 34568
As of Bokeh 1.4 there is not. There is an open issue regarding adding a hook for filtering hit-test results, e.g. to limit to only one result or some smaller fixed number of results. But that's a little different from providing a "visual dodge" that will make the whatever results not overlap. If that is your main problem, I would suggest suppressing the tooltips entirely, and using the callback
on the hover tool to update some other off-plot Div
with the information in a table or some other suitable condensed representation.
Upvotes: 1