Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions draftlogs/8201_fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fix a wrong frame at the end of zero-duration axis transitions [[#8201](https://github.com/plotly/plotly.js/pull/8201)]
5 changes: 3 additions & 2 deletions src/plots/cartesian/transition_axes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
19 changes: 19 additions & 0 deletions test/jasmine/tests/transition_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down