Repository navigation
Discard cartesian pan and zoombox drags on touchcancel - #8221
Open
dominikvrbic wants to merge 16 commits into
Open
dominikvrbic wants to merge 16 commits into
dominikvrbic wants to merge 16 commits into
Conversation
dragElement listened for touchend but not for touchcancel. When the browser cancelled a touch drag, the pan preview and the zoombox stayed on screen, and gd._dragdata kept the drag offset. A later redraw then replayed the drag, so the traces sat away from the axis ranges. dragElement now accepts a cancelFn. On touchcancel it ends the drag and calls cancelFn instead of doneFn or clickFn. The cartesian dragbox removes the zoombox, and after a pan it redraws from gd.layout, which still holds the ranges from before the drag.
12 of 26 tasks
Cancel the active drag when its touch ends with touchcancel. Release the listeners even when a component has no cancel callback.
Keep preview ranges separate from input ranges. Restore the ranges and transforms on cancellation and report the original displayed ranges in the final preview event.
The transition rebuilds the axes from the layout. Report the ranges that it shows, not the ranges from before the pan.
The cancel restores the ranges, the points and the shapes without a plot call.
A failed spec can leave a drag active. Release it in destroyGraphDiv so that it does not affect the next spec in any suite.
The marker position alone does not show the translated clip path.
Pan and zoom use one path for the final plotly_relayouting. It runs after a transition ends and reports the ranges on the screen, also when an animation changed them during the drag. A drag without a nonempty preview emits no final event.
A new press of the same mouse button, or a touch without the owning contact, cancels the active drag and starts a new one. The new drag measures from its own start. A Cartesian drag keeps its restore state for mouse input too, so that the cancel restores its preview.
Before, a legend drag kept its document listeners and drag cover after a purge, and the next touchmove threw an error.
…e old one After a lost touchend, Chromium can give the next contact the same identifier. A touchstart that holds the owner identifier in changedTouches starts a new contact.
dominikvrbic
added a commit
to Jan-IngenHousz-Institute/open-jii
that referenced
this pull request
Dec 2, 2026
## Type of PR (check all applicable) - [x] Feature - [x] Bug Fix - [ ] Refactor - [x] Documentation Update - [ ] Performance Improvement - [x] Test Update - [ ] Chore - [ ] Other (please describe) ## Description A reference line can now be **Sloped** as well as horizontal or vertical. A sloped line follows y = slope × x + intercept in the chart's own units, such as the 1:1 line that readings from two methods should agree on. It has the same color, dash and label settings as the other lines. - Scatter, line, bubble and area charts offer Sloped. Box, violin and histogram don't. - A new sloped line starts at slope 1 and intercept 0, keeping any style already set on the row. - The line runs from edge to edge of every facet it crosses. Its label appears in the first facet it crosses. The data still decides the axis ranges. - While pan or zoom is in progress, the sloped line and label are hidden. They redraw at the resulting ranges when the interaction completes. - On a logarithmic axis the line follows its equation, so it can curve, and the parts at or below zero are left out. - When either axis shows dates or categories, Sloped is disabled. A saved sloped line is hidden, and the numeric-axes note appears only if the chart has a sloped line. - Slope and intercept must both be finite numbers. If either field is empty or invalid, the editor shows a field error and pauses autosave. - Saved horizontal and vertical lines draw exactly as before. ## Linear issues Closes OJD-2316 ## GitHub issues - plotly/plotly.js#8220 (upstream bug) ## Testing Instructions Environment: dev web, with edit access to an experiment whose table has two positive number columns, a date column and a group column. This touches Critical Flows tier 2. - [ ] On a scatter of the two number columns, add a Sloped reference line. Expected: a 1:1 line appears and the ticks stay put. - [ ] Enter another slope and intercept. Expected: the line follows that equation from edge to edge. - [ ] Clear either coefficient, then enter 0. Expected: a field error appears and autosave pauses. Entering 0 clears the error and autosave resumes. - [ ] Pan or zoom the chart. Expected: the sloped line and label hide during the gesture and reappear aligned with the data when it completes. - [ ] Set a color, a dash and a label. Expected: the line shows all three. - [ ] Split the chart into panels by the group column. Expected: the line appears in every panel it crosses, with its label in the first panel it crosses. - [ ] Set the Y axis to Log with a negative intercept. Expected: the line curves and stops where its values reach zero. - [ ] Put the date column on X. Expected: Sloped is disabled, the saved sloped line is hidden, and the note appears. Remove the sloped line. Expected: the note disappears. - [ ] Open the Reference lines section on Line, Bubble, Area and Histogram charts. Expected: Sloped is offered on the first three only. - [ ] Reload a chart with saved horizontal and vertical lines. Expected: each line stays at its saved value. ## Changes Made - `packages/ui` `charts/types.ts`: the reference line type gains a `sloped` variant with `slope` and `intercept`. - `packages/ui` `charts/sloped-reference-lines.ts` (new) projects each sloped line into every panel from the ranges Plotly has already worked out, in panel coordinates. Plotly counts shapes drawn in data units when it sizes an axis, and these don't. On a log axis it samples the equation. `cartesian-chart.tsx` and `plotly-chart.tsx` redraw the lines after Plotly lays the chart out. - `png-export.ts` keeps the on-screen ranges in PNG, SVG, JPEG and WebP downloads, so an exported line matches the screen. - The Reference lines row and section add the Sloped choice with Slope and Intercept inputs. A small axis-preview context tells the editor whether the drawn axes are numeric. - The four cartesian style shelves pass the chart type through, so only scatter, line, bubble and area offer Sloped. - Labels in en-US, de-DE and nl-NL, including the section's empty-state text, which no longer says lines are only vertical or horizontal. The guide in `apps/docs/content/guide/data-analysis/viewing-data.mdx` explains sloped lines. The create and update schemas reject incomplete sloped lines and require finite numeric coefficients. The read schema still accepts older saved charts with incomplete lines so users can open and repair them. No database migration is needed. ## Checklist - [x] I have added/updated tests for my changes - [x] My code follows the project's style guidelines - [x] I have updated the documentation accordingly - [x] I have tested these changes locally - [x] My changes generate no new warnings - [x] I have reviewed my own code - [x] My PR title and Linear relation lines follow the release metadata contract - [x] The Linear ticket carries `## How it was built` and `## Testing criteria` ## Screenshots/Recordings The chart editor on the local stack, with the data served from a fixture table of made-up field and reference sensor readings. Before this change, a reference line could only be horizontal or vertical. | A dashed 1:1 line on a method comparison | The same saved line on a date X axis | | --- | --- | | <img width="560" alt="Scatter of a field sensor against a reference sensor with a dashed grey line labeled 1:1 running edge to edge, and the Reference lines section showing Axis Sloped, Slope 1, Intercept 0, Dashed and the label 1:1" src="https://public.linear.app/4d34d487-d352-45fe-89b9-feddf0310761/7ff07986-a5bd-4802-9cb7-f2bf869188cd/67f3dfd1-a9f6-4f28-9b0d-50acee9f7c4c" /> | <img width="560" alt="Scatter of the field sensor over time with no reference line drawn, and the Reference lines section showing the note Sloped lines need numeric X and Y axes" src="https://public.linear.app/4d34d487-d352-45fe-89b9-feddf0310761/66b9c490-5568-46ea-be3d-b0fb3f858a74/bf65f9e5-5cd5-4680-a0c9-d00250840055" /> | ## Additional Notes **Known issue.** If the browser cancels a touch pan and the user then double-taps, Plotly 3.7.0 leaves the traces offset from the axes, so the line looks misplaced until the next pan or Reset axes. This is a Plotly bug, reported as plotly/plotly.js#8220 with a fix in plotly/plotly.js#8221. Verified: 430 tests in `packages/ui` and 133 in web, covering unchanged autorange, zoom and reset, panel geometry, mixed log axes, hiding on category axes, and an SVG download from a resized chart. Typechecks for web, `@repo/ui`, docs and `@repo/i18n` pass, as do ESLint and Prettier on the changed files and the docs build with its link and media checks. A separate review took two rounds. The first round found that the slope inputs weren't offered for numeric text columns and that a resized non-PNG export lost alignment. Both are fixed in 0caf8d0. **Merge order.** This PR and the Export figure PR for OJD-1795 both change `packages/ui/src/components/charts/png-export.ts` and `plotly-chart.tsx`, so whichever lands second needs a rebase. <!-- codesmith:footer --> --- <a href="https://dashboardbackend.blacksmith.sh/track/run-proof?expires=1798734069&installation_model_id=427137&pr_number=2571&ref=codesmith_pr_footer&repository=Jan-IngenHousz-Institute%2Fopen-jii&return_to=https%3A%2F%2Fgithub.com%2FJan-IngenHousz-Institute%2Fopen-jii%2Fpull%2F2571&variant=proof_this_pr&signature=90561a186a4cebcd80992cc673f9dd3981d8167b4bf76efdabb2b403ca5a1b0c"><picture><source media="(prefers-color-scheme: dark)" srcset="https://pr-comments-assets.blacksmith.sh/codesmith/proof-proof-this-pr-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://pr-comments-assets.blacksmith.sh/codesmith/proof-proof-this-pr-v2-light.svg"><img alt="Proof this PR" src="https://pr-comments-assets.blacksmith.sh/codesmith/proof-proof-this-pr-v2-dark-3x.png" width="121" height="28"></picture></a> <sup><a href="https://app.blacksmith.sh/Jan-IngenHousz-Institute/codesmith/open-jii/pr/2571?autoLogin=true&ref=codesmith_pr_footer">Open in [code]smith</a> · Need help on this PR? Tag <code>@codesmith-bot</code> with what you need.</sup> <!-- codesmith:autofix:disabled --> <!-- /codesmith:footer -->
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #8220
This change makes Cartesian drags handle
touchcancel. In version 4.3.1, the plot keeps the drag preview when the browser cancels the touch. The fix covers pan, box zoom, axis-end drags and axis-pan drags.Reproduction
The red lines cross at (5, 5). After a 150 px pan, Chromium cancels the touch. A double tap then resets the axes. Standalone reproduction
Left: 4.3.1. Right: this branch.
Behavior
A touch drag now belongs to the touch that started it. Other touches do not move, end or cancel the drag. A mouse drag ends only on
mouseup. While a drag is active in a plot, a second touch or another mouse button does not start a new drag.If the browser cancels the touch that started a drag,
dragElementremoves the document listeners of the drag and clears the drag state. It does not calldoneFn, so the cancel commits no edit. A component that suppliescancelFngets a call tocancelFn. A component withoutcancelFnkeeps its preview on the screen, but its next drag starts with no old state.Sometimes the browser does not deliver the end event of a drag, for example when the window loses focus. In that case, a new touch cancels the old touch drag and starts a new one. This also applies when the browser gives the new touch the identifier of the old touch. On a device without hover, the next press of the same mouse button does the same. The new drag measures from its own start point. On a device with hover, the drag cover gets the next mouse press, so the behavior stays the same as on
main.Plotly.purgeandPlotly.newPlotend an active drag before they clear the plot. Before this change, a legend drag kept its document listeners afterPlotly.purge, and the nexttouchmovethrew an error.Pan, axis-pan and axis-end drags
plotly_relayoutingwith the preview ranges, as before.Plotly.redraw. Thus aplotly_beforeplothandler cannot keep the preview.scaleanchorwithconstrain: 'domain'or'range') get their original ranges back. The drag does not changegd.layoutat any time.plotly_relayouting. It is the last event of the gesture.plotly_transitioned.Box zoom
plotly_relayouting, as before. This includes the empty payloads that zoom emits now.plotly_relayouting, after any running transition ends.Final event, for pan and for zoom
.range[0]and.range[1]for every axis that a nonempty preview reported. Thus, if the zoom box changed from xy to y only, x is in the payload too.All cancels
plotly_relayout,plotly_click,plotly_doubleclick,plotly_beforeplot,plotly_afterplotorplotly_redraw.Plotly.reactremoves the subplot of an active drag, the drag ends. Onmain, the drag stays active, and later moves emitplotly_relayoutingfor axes that no longer exist.fixedrangeon the two axes during a pan, the cancel or the release still removes the pan transform.relayout,reactor a resize during the drag, the cancel gives the same result as the same update without a drag.Callers of
dragElement.initAnnotations, colorbar, legend, shapes with shape outlines, the Cartesian dragbox with select, lasso and draw, geo, map, polar, ternary and sankey. Only the Cartesian dragbox supplies
cancelFn.Tests
New Jasmine specs in
cartesian_interact_test.jsanddragelement_test.jscover these cases:maintoo. The new assertion compares the client position before and after the cancel (+100 px onmain).scaleanchorandconstrain: 'domain'or'range', and axis pans on theewandnsdraggersmouseup, a losttouchend, a reused touch identifier, and a Cartesian pan after a lostmouseupplotly_beforeplothandler that returnsfalsePlotly.reactthat removes the subplot of an active pan or zoomPlotly.purgeduring a legend drag and during a pan, with touch and with a mousefixedrangeon the two axes during a pan, fortouchcancelandtouchend, with the clip and plot transformsfixedrangerelayout,reactand a resize during the drag, compared with the same update without a dragThe specs wait for the events, not for a fixed delay.
destroyGraphDivreleases a drag that a failed spec leaves active. Without this release, the drag can affect the next spec.I ran
cartesian_interact,dragelementandplot_promisetogether in Chromium 159 headless shell:mainat6c1837503The branch adds 40 specs. The one failure is the same on the two sources. It is the multicategory tick-label span spec (438.3 px against 430 ± 5.5 px), and it depends on the local fonts.
I also ran each new spec alone against the old source with the new test files. 39 of the 40 specs fail on
main. The spec that passes onmainmakes sure that atouchcanceldoes not end a mouse drag. The first version of this PR broke that behavior.36 of the 40 specs fail on the first version of this PR (
b6f50be85). Four specs pass there: its own twodragElementspecs, the unmoved zoom with interactive axes, and the pan that moved only during a transition.CI checks run locally
I ran the CI jobs on
mainand on this branch, withCI=1andTZ=America/Anchorage, Node 22 and Chromium 159 headless shell.mainlint,typecheck,test-syntax,schema-typegen-diff-check,entry-point-types-check,test-types,test-plain-obj,test-mocknoCIandnoCIdepThe shard split uses file sizes, so the new specs move some files to other shards. All 17 failures on
mainalso fail on the branch. They come from the local environment, for example fonts, automargin titles and uniformtext.The extra failure on the branch is "should be able to relayout imaginary axis ticks" in
smith_test. It also fails onmainwhen it runs with the same shard files. That shard has the same 6 failures on the two sources, and the spec uses no drag.I did not run
test-bundle, theflakyshard or the image tests. The CI run used3df6b6585. The later commits change only the draftlog and the touch identifier check indragElement. On those commits, I ran the three suites above andtest-syntaxagain.Follow-ups
dragElementnow release the gesture on cancel, but a moved preview, such as a legend position, stays on the screen. Rangeslider, sliders and parcoords have their own drag handlers, and this PR does not change them.mouseup, so the old drag continues.mainhas the same behavior.🐦 An agent wrote the initial patch.