From 21231c13c78104099606c58296e4b7c521ff59c9 Mon Sep 17 00:00:00 2001 From: Philipp Rudiger Date: Tue, 15 Oct 2024 11:23:25 -0400 Subject: [PATCH] Fix popup positioning on polygons (#6411) --- holoviews/plotting/bokeh/callbacks.py | 20 +++++++++--- holoviews/tests/ui/bokeh/test_callback.py | 38 ++++++++++++++++++++++- 2 files changed, 53 insertions(+), 5 deletions(-) diff --git a/holoviews/plotting/bokeh/callbacks.py b/holoviews/plotting/bokeh/callbacks.py index 89541b5955..0386a20c10 100644 --- a/holoviews/plotting/bokeh/callbacks.py +++ b/holoviews/plotting/bokeh/callbacks.py @@ -1191,13 +1191,25 @@ def _watch_position(self): } if (!xs || !ys) { return } for (const i of indices) { - const tx = xs[i] + let ix = xs[i] + let iy = ys[i] + let tx, ty + if (typeof ix === 'number') { + tx = ix + ty = iy + } else { + while (ix.length && (typeof ix[0] !== 'number')) { + ix = ix[0] + iy = iy[0] + } + tx = Math.max(...ix) + ty = Math.max(...iy) + } if (!x || (tx > x)) { - x = xs[i] + x = tx } - const ty = ys[i] if (!y || (ty > y)) { - y = ys[i] + y = ty } } if (x && y) { diff --git a/holoviews/tests/ui/bokeh/test_callback.py b/holoviews/tests/ui/bokeh/test_callback.py index 19cd5f0c43..1fe6ba082b 100644 --- a/holoviews/tests/ui/bokeh/test_callback.py +++ b/holoviews/tests/ui/bokeh/test_callback.py @@ -262,7 +262,43 @@ def popup_form(name): hv_plot.click() expect(hv_plot).to_have_count(1) - locator = page.locator("#tap") + locator = page.locator(".markdown") + expect(locator).to_have_count(1) + + +@skip_popup +@pytest.mark.usefixtures("bokeh_backend") +def test_stream_popup_polygons_tap(serve_hv): + def popup_form(name): + return f"# {name}" + + points = hv.Polygons([(0, 0), (0, 1), (1, 1), (1, 0)]).opts(tools=["tap"]) + hv.streams.Tap(source=points, popup=popup_form("Tap")) + + page = serve_hv(points) + hv_plot = page.locator('.bk-events') + hv_plot.click() + expect(hv_plot).to_have_count(1) + + locator = page.locator(".markdown") + expect(locator).to_have_count(1) + + +@skip_popup +@pytest.mark.usefixtures("bokeh_backend") +def test_stream_popup_polygons_selection1d(serve_hv): + def popup_form(name): + return f"# {name}" + + points = hv.Polygons([(0, 0), (0, 1), (1, 1), (1, 0)]).opts(tools=["tap"]) + hv.streams.Selection1D(source=points, popup=popup_form("Tap")) + + page = serve_hv(points) + hv_plot = page.locator('.bk-events') + hv_plot.click() + expect(hv_plot).to_have_count(1) + + locator = page.locator(".markdown") expect(locator).to_have_count(1)