Skip to content

Commit

Permalink
Fix popup positioning on polygons (#6411)
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr authored Oct 15, 2024
1 parent 75888ac commit 21231c1
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 5 deletions.
20 changes: 16 additions & 4 deletions holoviews/plotting/bokeh/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
38 changes: 37 additions & 1 deletion holoviews/tests/ui/bokeh/test_callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down

0 comments on commit 21231c1

Please sign in to comment.