Skip to content

Commit

Permalink
Fix vectorfield hover (#6258)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahuang11 authored Jun 6, 2024
1 parent c37420b commit 17cc894
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
16 changes: 14 additions & 2 deletions holoviews/plotting/bokeh/chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,20 @@ def get_data(self, element, ranges, style):
elif cdim:
color = cdata.get(cdim.name)

data = {'x0': x0s, 'x1': x1s, 'y0': y0s, 'y1': y1s}
data = {
'x0': x0s,
'x1': x1s,
'y0': y0s,
'y1': y1s,
}
if 'hover' in self.handles:
data.update({
# tile to match the length of the segments
"x": np.tile(xs, 3),
"y": np.tile(ys, 3),
"Angle": np.tile(rads, 3),
"Magnitude": np.tile(lens, 3)
})
mapping = dict(x0='x0', x1='x1', y0='y0', y1='y1')
if cdim and color is not None:
data[cdim.name] = color
Expand All @@ -327,7 +340,6 @@ def get_data(self, element, ranges, style):
return (data, mapping, style)



class CurvePlot(ElementPlot):

padding = param.ClassSelector(default=(0, 0.1), class_=(int, float, tuple))
Expand Down
14 changes: 14 additions & 0 deletions holoviews/tests/plotting/bokeh/test_vectorfieldplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,17 @@ def test_vectorfield_color_index_color_clash(self):
"for 'line_color' option and declare a color_index; ignoring the color_index.\n"
)
self.assertEqual(log_msg, warning)

def test_vectorfield_no_hover_columns(self):
vectorfield = VectorField([(0, 0, 0), (0, 1, 1), (0, 2, 2)],
vdims='color').opts(tools=[])
plot = bokeh_renderer.get_plot(vectorfield)
keys = sorted(plot.handles["cds"].data)
assert keys == ["x0", "x1", "y0", "y1"]

def test_vectorfield_hover_columns(self):
vectorfield = VectorField([(0, 0, 0), (0, 1, 1), (0, 2, 2)],
vdims='color').opts(tools=["hover"])
plot = bokeh_renderer.get_plot(vectorfield)
keys = sorted(plot.handles["cds"].data)
assert keys == ["Angle", "Magnitude", "x", "x0", "x1", "y", "y0", "y1"]

0 comments on commit 17cc894

Please sign in to comment.