From 958b1c366e985971ce274b4c2d38cb909435ba9c Mon Sep 17 00:00:00 2001 From: Jerry Vinokurov Date: Fri, 17 Jan 2025 12:29:03 -0500 Subject: [PATCH] fix: support the case of multiple line segments each with one vdim (#6492) --- holoviews/plotting/bokeh/path.py | 13 ++++++++++-- .../tests/plotting/bokeh/test_pathplot.py | 21 +++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/holoviews/plotting/bokeh/path.py b/holoviews/plotting/bokeh/path.py index 883d900d31..cebdace513 100644 --- a/holoviews/plotting/bokeh/path.py +++ b/holoviews/plotting/bokeh/path.py @@ -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) diff --git a/holoviews/tests/plotting/bokeh/test_pathplot.py b/holoviews/tests/plotting/bokeh/test_pathplot.py index 8185cdcee0..a743887485 100644 --- a/holoviews/tests/plotting/bokeh/test_pathplot.py +++ b/holoviews/tests/plotting/bokeh/test_pathplot.py @@ -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):