From cee8069de185f76729a1bd39f080579bb56ba118 Mon Sep 17 00:00:00 2001 From: Jerry Vinokurov Date: Thu, 16 Jan 2025 17:03:21 -0500 Subject: [PATCH 1/2] support the case of multiple line segments each with one vdim --- 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..caf0f4c246 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 = 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) 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): From 77c8a20926c68af0e7c27488274b70655afe1cf9 Mon Sep 17 00:00:00 2001 From: Jerry Vinokurov Date: Fri, 17 Jan 2025 11:16:13 -0500 Subject: [PATCH 2/2] Update holoviews/plotting/bokeh/path.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Simon Høxbro Hansen --- holoviews/plotting/bokeh/path.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/holoviews/plotting/bokeh/path.py b/holoviews/plotting/bokeh/path.py index caf0f4c246..cebdace513 100644 --- a/holoviews/plotting/bokeh/path.py +++ b/holoviews/plotting/bokeh/path.py @@ -57,7 +57,7 @@ def _element_transform(self, transform, element, ranges): 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]) + kdim_length = len(el[el.kdims[0]]) transformed.append(np.tile(new_el, kdim_length - 1)) else: transformed.append(new_el)