Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support the case of multiple line segments each with one vdim #6492

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = max([len(el[kdim]) for kdim in el.kdims])
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
Loading