Box annotations hiding the tooltips

Hi,

I need to add some vertical bands on my plot. I used the BoxAnnotation for that purpose. The bands show but I am unable to see the Hover tooltips on the renderers that are in the bands.
I modified the box annotation example from the bokeh documentation to reproduce this issue. The modifications are:

  • added a tooltip on the line renderer
  • remove the bottom box annotation

The tooltip is displayed when hovering the line where there is no box annotation but it is not displayed if there is a box annotation.

I have been using box annotations because I need to display a dynamic number of annotations on a selector.

from bokeh.models import BoxAnnotation
from bokeh.models import HoverTool
from bokeh.plotting import figure, show
from bokeh.sampledata.glucose import data

TOOLS = "pan,wheel_zoom,box_zoom,reset,save"

#reduce data size
data = data.loc['2010-10-06':'2010-10-13'].reset_index()

p = figure(x_axis_type="datetime", tools=TOOLS)

r = p.line("datetime", "glucose", source=data, color="gray", legend_label="glucose")

p.add_tools(HoverTool(
    renderers=[r],
    tooltips="""
        <style>
            .bk-tooltip>div:not(:first-child) {display:none;}
        </style>

        glucose: <b>@{glucose}{safe}</b> <br>
        datetime: <b>@datetime{safe}</b> <br>
    """,
))


low_box = BoxAnnotation(top=80, fill_alpha=0.2, fill_color='#D55E00')
mid_box = BoxAnnotation(bottom=80, top=180, fill_alpha=0.2, fill_color='#0072B2')
high_box = BoxAnnotation(bottom=180, fill_alpha=0.2, fill_color='#D55E00')

#p.add_layout(low_box)
p.add_layout(mid_box)
p.add_layout(high_box)

p.title.text = "Glucose Range"
p.xgrid.grid_line_color=None
p.ygrid.grid_line_alpha=0.5
p.xaxis.axis_label = 'Time'
p.yaxis.axis_label = 'Value'
p.legend.level = "overlay"
p.legend.location = "top_left"

show(p)

Bokeh info:

Python version        :  3.11.10 | packaged by Anaconda, Inc. | (main, Oct  3 2024, 07:22:26) [MSC v.1929 64 bit (AMD64)]
IPython version       :  (not installed)
Tornado version       :  6.4.1
NumPy version         :  1.26.4
Bokeh version         :  3.6.3
BokehJS static path   :  C:\Users\gilles.faure\AppData\Local\miniconda3\envs\EO_py3.11_truck_simulator\Lib\site-packages\bokeh\server\static
node.js version       :  (not installed)
npm version           :  (not installed)
jupyter_bokeh version :  (not installed)
Operating system      :  Windows-10-10.0.22631-SP0

This is a current known bug, hopefully to be fixed in 3.8 (which is also planned to have a relatively short development cycle)

That said @mateusz offered some immediately relevant commentary in this reply:

https://github.com/bokeh/bokeh/issues/13980#issuecomment-2226960920

thanks Bryan