diff --git a/hvplot/networkx.py b/hvplot/networkx.py index 06e648bdd..a65cc6bf9 100644 --- a/hvplot/networkx.py +++ b/hvplot/networkx.py @@ -6,6 +6,7 @@ from bokeh.models import HoverTool from holoviews import Graph, Labels, dim +from holoviews.core.util import dimension_sanitizer from holoviews.core.options import Store from holoviews.plotting.bokeh import GraphPlot, LabelsPlot from holoviews.plotting.bokeh.styles import markers @@ -331,7 +332,7 @@ def draw(G, pos=None, **kwargs): (d.label, d.name + '_values' if d in g.kdims else d.name) for d in g.kdims + g.vdims ] tooltips = [ - (label, '@{{dimension_sanitizer(name)}}') + (label, f'@{{{dimension_sanitizer(name)}}}') for label, name in tooltip_dims if name not in node_styles + edge_styles ] diff --git a/hvplot/tests/testnetworkx.py b/hvplot/tests/testnetworkx.py index 27aebfa4d..60f8e7fc0 100644 --- a/hvplot/tests/testnetworkx.py +++ b/hvplot/tests/testnetworkx.py @@ -24,3 +24,10 @@ def setUp(self): def test_nodes_are_not_sorted(self): plot = hvnx.draw(self.g) assert all(self.nodes == plot.nodes.dimension_values(2)) + + def test_default_hover_tooltip(self): + from bokeh.models import HoverTool + + plot = hvnx.draw(self.g) + hover = next(t for t in plot.opts['tools'] if isinstance(t, HoverTool)) + assert [('index', '@{index_hover}')] == hover.tooltips