Skip to content

Commit

Permalink
fix: support the case of multiple line segments each with one vdim (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
grapesmoker authored Jan 17, 2025
1 parent becb5f3 commit 958b1c3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
13 changes: 11 additions & 2 deletions holoviews/plotting/bokeh/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,17 @@ def _element_transform(self, transform, element, ranges):
else:
new_data.append(d)
return np.array(new_data)
return np.concatenate([transform.apply(el, ranges=ranges, flat=True)
for el in element.split()])

transformed = []
for el in element.split():
new_el = transform.apply(el, ranges=ranges, flat=True)
if len(new_el) == 1:
kdim_length = len(el[el.kdims[0]])
transformed.append(np.tile(new_el, kdim_length - 1))
else:
transformed.append(new_el)

return np.concatenate(transformed)

def _hover_opts(self, element):
cdim = element.get_dimension(self.color_index)
Expand Down
21 changes: 21 additions & 0 deletions holoviews/tests/plotting/bokeh/test_pathplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,27 @@ def test_path_continuously_varying_color_legend_with_labels(self):
self.assertEqual(property_to_dict(item.label), legend)
self.assertEqual(item.renderers, [plot.handles['glyph_renderer']])

def test_path_multiple_segments_with_single_vdim(self):

# two segments, each with its own color
data = [{
'x': [0, 1, 1],
'y': [0, 0, 1],
'color': '#FF0000',
}, {
'x': [0, 0, 1],
'y': [0, 1, 1],
'color': '#0000FF',
}]

path = Path(data, vdims='color').opts(line_color='color')
plot = bokeh_renderer.get_plot(path)
cds = plot.handles['cds']
source = plot.handles['source']
np.testing.assert_equal(source.data['xs'], [np.array([0, 1]), np.array([1, 1]), np.array([0, 0]), np.array([0, 1])])
np.testing.assert_equal(source.data['ys'], [np.array([0, 0]), np.array([0, 1]), np.array([0, 1]), np.array([1, 1])])
assert list(cds.data['line_color']) == ['#FF0000', '#FF0000', '#0000FF', '#0000FF']


class TestPolygonPlot(TestBokehPlot):

Expand Down

0 comments on commit 958b1c3

Please sign in to comment.