Reputation: 77
I am using hvplot (version 0.4.0) with a networkx undirected graph (networkx version 2.1). When plotting the graph using the bokeh backend, I would like the hover to display the node name and not "index:number".
All the examples online in the docs have "index:number", I have tried to pass the names to the "labels" kwargs but that results in an error:
DataError: Supplied data does not contain specified dimensions, the following dimensions were not found:
import networkx as nx
import hvplot.networkx as hvnx
import holoviews as hv
hv.extension('bokeh')
GG = nx.Graph()
GG.add_edge('A','B')
GG.add_edge('B','C')
GG.add_edge('C','A')
hvnx.draw(GG)
Looping through the GG object, provides the following info
for ii in GG.nodes():
print(ii,type(ii))
A <class 'str'>
C <class 'str'>
B <class 'str'>
for ee in GG.edges():
print(ee,type(ee))
('A', 'C') <class 'tuple'>
('A', 'B') <class 'tuple'>
('C', 'B') <class 'tuple'>
Upvotes: 0
Views: 1359
Reputation: 11
My solution
var selected_nodes = cb_data.source.selected["1d"].indices.map(function (selected_node_index) {
return cb_data.source.data.index_hover[selected_node_index];
});
see cb_data.source.selected["1d"].indices
Upvotes: 0
Reputation: 4080
It seems like what you are trying to do should be the default behavior and likely represents some regression in HoloViews. That said the actual hover index data is actually being added to the plot it's just not referenced correctly. In your example you can make sure it is used correctly by explicitly declaring a bokeh HoverTool
:
from bokeh.models import HoverTool
GG = nx.Graph()
GG.add_edge('A','B')
GG.add_edge('B','C')
GG.add_edge('C','A')
hvnx.draw(GG).opts(tools=[HoverTool(tooltips=[('index', '@index_hover')])])
I have already filed an issue to make a note of this regression and you should expect this to be fixed in holoviews 1.12.0.
Upvotes: 1