Skip to content

Commit

Permalink
Fix hover tooltips for NetworkX plots (#1439)
Browse files Browse the repository at this point in the history
  • Loading branch information
Palmr authored Oct 11, 2024
1 parent aba8d47 commit aaa09a8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion hvplot/networkx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
]
Expand Down
7 changes: 7 additions & 0 deletions hvplot/tests/testnetworkx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit aaa09a8

Please sign in to comment.