From 4e34ac7760005bb8180741f2a0618223caf6410a Mon Sep 17 00:00:00 2001 From: Bodison Date: Wed, 25 Nov 2026 23:11:36 +0000 Subject: [PATCH 1/2] Fix a wrong frame at the end of zero-duration axis transitions --- src/plots/cartesian/transition_axes.js | 5 +++-- test/jasmine/tests/transition_test.js | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/plots/cartesian/transition_axes.js b/src/plots/cartesian/transition_axes.js index f98969de352..79f807991b8 100644 --- a/src/plots/cartesian/transition_axes.js +++ b/src/plots/cartesian/transition_axes.js @@ -181,14 +181,15 @@ module.exports = function transitionAxes(gd, edits, transitionOpts, makeOnComple function doFrame() { t2 = Date.now(); - var tInterp = Math.min(1, (t2 - t1) / transitionOpts.duration); + var duration = transitionOpts.duration; + var tInterp = duration > 0 ? Math.min(1, (t2 - t1) / duration) : 1; var progress = easeFn(tInterp); for(var i = 0; i < edits.length; i++) { updateSubplot(edits[i], progress); } - if(t2 - t1 > transitionOpts.duration) { + if(tInterp >= 1) { transitionComplete(); raf = window.cancelAnimationFrame(doFrame); } else { diff --git a/test/jasmine/tests/transition_test.js b/test/jasmine/tests/transition_test.js index ceba1cc4a66..d1d2a55a97a 100644 --- a/test/jasmine/tests/transition_test.js +++ b/test/jasmine/tests/transition_test.js @@ -30,6 +30,25 @@ describe('Plots.transition', function() { destroyGraphDiv(); }); + it('resolves a zero-duration axis transition whose first frame runs right away', function(done) { + var traces = plotApiHelpers.coerceTraceIndices(gd, null); + var resolved = false; + + // the first frame then runs in the same millisecond the transition started + spyOn(Date, 'now').and.returnValue(Date.now()); + + Plots.transition(gd, null, {'xaxis.range': [0.2, 0.3]}, traces, {redraw: true}, {duration: 0, easing: 'cubic-in-out'}) + .then(function() { resolved = true; }); + + Promise.resolve() + .then(delay(100)) + .then(function() { + expect(resolved).toBe(true, 'transition resolved'); + expect(gd._fullLayout.xaxis.range).toEqual([0.2, 0.3]); + }) + .then(done, done.fail); + }); + // Run the whole set of tests twice: once with zero duration and once with // nonzero duration since the behavior should be identical, but there's a // very real possibility of race conditions or other timing issues. From 0fa6d03c9c4a3de4740b9601e3506c2049c5f6ab Mon Sep 17 00:00:00 2001 From: Bodison Date: Wed, 25 Nov 2026 23:26:15 +0000 Subject: [PATCH 2/2] Add draftlog --- draftlogs/8201_fix.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 draftlogs/8201_fix.md diff --git a/draftlogs/8201_fix.md b/draftlogs/8201_fix.md new file mode 100644 index 00000000000..d2b6b5890db --- /dev/null +++ b/draftlogs/8201_fix.md @@ -0,0 +1 @@ +- Fix a wrong frame at the end of zero-duration axis transitions [[#8201](https://github.com/plotly/plotly.js/pull/8201)]