Unable to use CustomJS callback on HoverTool with GraphRenderer

Hi,

I am attempting to use a CustomJS callback on a HoverTool that is connected to a plot containing a GraphRenderer.

Whenever I attach the callback, the following error appears several times (with each mouse movement) in the JS console:

Uncaught TypeError: Cannot read property 'coordinates' of undefined
    at b._emit_callback (bokeh-2.2.1.min.js:569)
    at b._inspect (bokeh-2.2.1.min.js:569)
    at b._move (bokeh-2.2.1.min.js:569)
    at b.<anonymous> (bokeh-2.2.1.min.js:497)
    at b.<anonymous> (bokeh-2.2.1.min.js:240)
    at o.emit (bokeh-2.2.1.min.js:181)
    at d.trigger (bokeh-2.2.1.min.js:497)
    at bokeh-2.2.1.min.js:497
    at Array.map (<anonymous>)
    at d._trigger (bokeh-2.2.1.min.js:497)

Here is a small example that replicates my issue. To demonstrate the problem, I’ve made the CustomJS code a simple log statement.

from bokeh.plotting import figure, show, from_networkx
from bokeh.models import Circle, Plot, Range1d, HoverTool, CustomJS
import networkx

nodes = [[0, 1], [0, 2], [1, 2],]
g = networkx.Graph()
for a, b in nodes:
    g.add_edge(a, b)

plot = Plot(
    plot_width=400,
    plot_height=400,
    x_range=Range1d(-1.1, 1.1),
    y_range=Range1d(-1.1, 1.1),
)
graph = from_networkx(g, networkx.circular_layout, scale=1, center=(0, 0))
graph.node_renderer.glyph = Circle(size=20)
plot.renderers.append(graph)

hover_tool = HoverTool(
    tooltips=None,
    renderers=[graph.node_renderer],
    callback=CustomJS(code="console.log('foo');")
)
plot.add_tools(hover_tool)

show(plot)

Any ideas? I’m not sure if this is a bug or if what I’m attempting to do isn’t right, so I thought I’d start here rather than open a GitHub issue.

This seems like a bug specific to graph renderers (since this non-graph example is working in the docs). A GH bug report is definitely advised (if you can also run with BOKEH_MINIFIED=no set you wlll get a bit more detailed JS console stack trace)

Thanks! I’ve created an issue. [BUG] Unable to use CustomJS callback on HoverTool with GraphRenderer · Issue #10481 · bokeh/bokeh · GitHub