Repository navigation
Description
Description
plotly.js does not handle touchcancel on cartesian subplots. If the browser cancels a touch pan, the pan preview stays on screen and gd._dragdata keeps the pan offset. No plotly_relayout fires.
A double tap then resets the axis ranges, but the trace layer keeps the pan offset. Shapes, annotations and hover labels follow the axes, so they no longer line up with the traces. A later Plotly.redraw replays the drag from gd._dragdata.
Box zoom has the same gap. After touchcancel, the zoombox stays on screen and gd._dragdata stays set.
The browser sends touchcancel instead of touchend when it takes a touch away from the page, for example for a system gesture.
Screenshots/Video
plotly.js 4.3.1 after a cancelled 150 px pan and a double tap. The red crosshair is a shape at (5, 5), and the hover label for (5, 5) sits on it. The marker for (5, 5) sits 150 px to the right.
Steps to reproduce
Repro: https://github.com/dominikvrbic/plotly-touchcancel-repro (one HTML page with plotly.js from cdn.plot.ly, plus a Playwright script that sends real touch input to Chromium through the Chrome DevTools Protocol)
npm install
npx playwright install chromium
npm run repro- Plot a scatter trace with
dragmode: 'pan' - Touch the plot and pan 150 px
- Let the browser cancel the touch. The repro sends
Input.dispatchTouchEventwithtype: 'touchCancel'. - Note that the plot stays translated and
gd._dragdatastays set - Double tap the plot
- Note that the axes reset, but the markers stay 150 px away from the axis positions
Offset of the marker at (5, 5) from the position that the axis ranges give:
| 3.7.0 | 4.3.1 | |
|---|---|---|
after touchcancel |
150 px | 150 px |
| after the double tap | 150 px | 150 px |
gd._dragdata set after touchcancel |
yes | yes |
plotly_relayout events after touchcancel |
0 | 0 |
Expected: a cancelled touch discards the preview, and the plot looks the same as before the touch.
Notes
- Versions: plotly.js 3.7.0 and 4.3.1 (the latest release). Chromium 159 with touch emulation, on Linux.
- Real-world case: feat(web): add sloped chart reference lines Jan-IngenHousz-Institute/open-jii#2571 draws sloped reference lines from the axis ranges. After a cancelled touch pan, the review measured 70.98 px between a line and its markers on three fresh charts.
- Cause:
dragElement.initinsrc/components/dragelement/index.jslistens formouseupandtouchend, but not fortouchcancel. A cancelled drag never reachesdoneFnor any cleanup. - I searched open and closed issues and pull requests for
touchcancel,pointercanceland_dragdataand found no report. - I have a fix with jasmine tests and can open a pull request.

Activity
feat(web): add sloped chart reference lines (#2571)