plotly/plotly.js
在 GitHub 查看[BUG]: Select tools don't select all points within area when selection crosses the antimeridian
Closed
#7,904 建立於 2026年7月14日
buggood first issuegood for agent
倉庫指標
- Star
- (15,964 star)
- PR 合併指標
- (平均合併 35天 19小時) (30 天內合併 36 個 PR)
描述
Description
When a scattermap (or densitymap) view crosses the ±180° antimeridian the box-select and lasso-select tools do not select points that are visibly inside the drawn region. The selection contains only points from one side of the antimeridian, depending on where the map is centered.
Screenshots/Video
https://github.com/user-attachments/assets/bcd538c6-c24e-4c98-9e54-0860d87c6ef9
Steps to reproduce
- Create a
scattermaptrace with points that straddle ±180°, e.g.:{ "data": [{ "type": "scattermap", "lat": [-36.85, -18.14, -16.5, -13.3, -13.83, -21.14], "lon": [174.76, 178.44, 179.9, -176.2, -171.77, -175.2], "mode": "markers", "marker": { "size": 10 } }], "layout": { "dragmode": "select", "width": 900, "height": 600 } } - Pan so that all points are visible around the antimeridian
- Draw a selection box that visually encloses all six points
- Observe that the
plotly_selectedevent either fires with an empty selection or with only the subset of points on one side of ±180°
Notes
- Root cause suspicion:
src/plots/map/map.js:625(updateFx) builds the selection rect frominvert(pxpy)which callsmap.unproject, returning[lng, lat]in[-180, 180]. When the two corners of the drag straddle ±180°, the resulting rect hasxmin > xmax(e.g.,[[179, ...], [-179, ...]]). Downstream selection code assumesxmin < xmax, so the rect either matches nothing or matches the "wrong" 340° arc. The per-point normalization insrc/traces/scattermap/select.js:27(Lib.modHalf(lonlat[0], 360)) doesn't help because the rect coordinates themselves haven't been unwrapped. - Fix likely lives in
src/plots/map/map.jsupdateFx/fillRangeItems— unwrap the rect'sxmax(add 360°) whenxmax < xmin, so downstreamxmin < lon < xmax(with lon similarly unwrapped when needed) matches all enclosed points - Also verify the lasso path (
poly.map(invert)), which has the same underlying problem: consecutive polygon vertices can jump ±360° across the antimeridian