Skip to content

Commit aaa09a8

Browse files
authored
Fix hover tooltips for NetworkX plots (#1439)
1 parent aba8d47 commit aaa09a8

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

hvplot/networkx.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from bokeh.models import HoverTool
88
from holoviews import Graph, Labels, dim
9+
from holoviews.core.util import dimension_sanitizer
910
from holoviews.core.options import Store
1011
from holoviews.plotting.bokeh import GraphPlot, LabelsPlot
1112
from holoviews.plotting.bokeh.styles import markers
@@ -331,7 +332,7 @@ def draw(G, pos=None, **kwargs):
331332
(d.label, d.name + '_values' if d in g.kdims else d.name) for d in g.kdims + g.vdims
332333
]
333334
tooltips = [
334-
(label, '@{{dimension_sanitizer(name)}}')
335+
(label, f'@{{{dimension_sanitizer(name)}}}')
335336
for label, name in tooltip_dims
336337
if name not in node_styles + edge_styles
337338
]

hvplot/tests/testnetworkx.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,10 @@ def setUp(self):
2424
def test_nodes_are_not_sorted(self):
2525
plot = hvnx.draw(self.g)
2626
assert all(self.nodes == plot.nodes.dimension_values(2))
27+
28+
def test_default_hover_tooltip(self):
29+
from bokeh.models import HoverTool
30+
31+
plot = hvnx.draw(self.g)
32+
hover = next(t for t in plot.opts['tools'] if isinstance(t, HoverTool))
33+
assert [('index', '@{index_hover}')] == hover.tooltips

0 commit comments

Comments
 (0)