I have a graph with multiple node types and I would like to be able to show the attributes by hovering varying according to the node type; in the general case the number of attributes varies according to the node type. I don't want to have an omnibus HoverTool that is the union of all the attributes for all of the node types.
Here is a simplified example:
from bokeh.io import output_file, save
from bokeh.models import Circle, HoverTool, Plot, Range1d
from bokeh.plotting import from_networkx
from networkx import Graph, spring_layout
G = Graph()
for item in [
(0, {'name': 'home', 'type': 'location', 'address': '1 Main St'}),
(1, {'name': 'house', 'type': 'structure', 'shape': 'cube'}),
(2, {'name': 'cat', 'type': 'inhabitant', 'variety': 'tabby'})]:
G.add_node(node_for_adding=item[0], **item[1])
for node in range(2):
G.add_edge(u_of_edge=node, v_of_edge=node + 1)
plot = Plot(width=400, height=400, x_range=Range1d(-2, 2), y_range=Range1d(-2, 2))
plot.add_tools(HoverTool())
graph = from_networkx(G, spring_layout, scale=1, center=(0, 0))
graph.node_renderer.glyph = Circle(size=15, fill_color='red')
plot.renderers.append(graph)
filename = 'networkx_graph.html'
output_file(filename=filename)
save(obj=plot, filename=filename)
I have tried adding a HoverTool per node type, but I don't know how to select the HoverTool according to the node type. And I've tried using an omnibus HoverTool, but I don't know how to omit the null/??? fields. I think ideally I would attach a list of HoverTools to the renderer rather than adding it do the plot, but that's not possible.