Skip to content

Commit 2bc29b8

Browse files
committed
Limit transition duration to <= frame duration
1 parent 1fe652d commit 2bc29b8

File tree

3 files changed

+83
-45
lines changed

3 files changed

+83
-45
lines changed

src/plot_api/plot_api.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -2540,11 +2540,18 @@ Plotly.animate = function(gd, frameOrGroupNameOrFrameList, animationOpts) {
25402540
computedFrame = frameList[i].frame;
25412541
}
25422542

2543+
var frameOpts = getFrameOpts(i);
2544+
var transitionOpts = getTransitionOpts(i);
2545+
2546+
// It doesn't make much sense for the transition duration to be greater than
2547+
// the frame duration, so limit it:
2548+
transitionOpts.duration = Math.min(transitionOpts.duration, frameOpts.duration);
2549+
25432550
var nextFrame = {
25442551
frame: computedFrame,
25452552
name: frameList[i].name,
2546-
frameOpts: getFrameOpts(i),
2547-
transitionOpts: getTransitionOpts(i)
2553+
frameOpts: frameOpts,
2554+
transitionOpts: transitionOpts,
25482555
};
25492556

25502557
if(i === frameList.length - 1) {

test/jasmine/tests/animate_test.js

+74
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,48 @@ var delay = require('../assets/delay');
99

1010
var mock = require('@mocks/animation');
1111

12+
describe('Plots.supplyAnimationDefaults', function() {
13+
'use strict';
14+
15+
it('supplies transition defaults', function() {
16+
expect(Plots.supplyAnimationDefaults({})).toEqual({
17+
mode: 'afterall',
18+
transition: {
19+
duration: 500,
20+
easing: 'cubic-in-out'
21+
},
22+
frame: {
23+
duration: 500,
24+
redraw: true
25+
}
26+
});
27+
});
28+
29+
it('uses provided values', function() {
30+
expect(Plots.supplyAnimationDefaults({
31+
mode: 'next',
32+
transition: {
33+
duration: 600,
34+
easing: 'elastic-in-out'
35+
},
36+
frame: {
37+
duration: 700,
38+
redraw: false
39+
}
40+
})).toEqual({
41+
mode: 'next',
42+
transition: {
43+
duration: 600,
44+
easing: 'elastic-in-out'
45+
},
46+
frame: {
47+
duration: 700,
48+
redraw: false
49+
}
50+
});
51+
});
52+
});
53+
1254
describe('Test animate API', function() {
1355
'use strict';
1456

@@ -351,4 +393,36 @@ describe('Test animate API', function() {
351393
}).catch(fail).then(done);
352394
});
353395
});
396+
397+
describe('frame vs. transition timing', function() {
398+
it('limits the transition duration to <= frame duration', function(done) {
399+
Plotly.animate(gd, ['frame0'], {
400+
transition: {duration: 100000},
401+
frame: {duration: 50}
402+
}).then(function() {
403+
// Frame timing:
404+
expect(Plots.transition.calls.argsFor(0)[4].duration).toEqual(50);
405+
406+
// Transition timing:
407+
expect(Plots.transition.calls.argsFor(0)[5].duration).toEqual(50);
408+
409+
}).catch(fail).then(done);
410+
});
411+
412+
it('limits the transition duration to <= frame duration (matching per-config)', function(done) {
413+
Plotly.animate(gd, ['frame0', 'frame1'], {
414+
transition: [{duration: 100000}, {duration: 123456}],
415+
frame: [{duration: 50}, {duration: 40}]
416+
}).then(function() {
417+
// Frame timing:
418+
expect(Plots.transition.calls.argsFor(0)[4].duration).toEqual(50);
419+
expect(Plots.transition.calls.argsFor(1)[4].duration).toEqual(40);
420+
421+
// Transition timing:
422+
expect(Plots.transition.calls.argsFor(0)[5].duration).toEqual(50);
423+
expect(Plots.transition.calls.argsFor(1)[5].duration).toEqual(40);
424+
425+
}).catch(fail).then(done);
426+
});
427+
});
354428
});

test/jasmine/tests/transition_test.js

-43
Original file line numberDiff line numberDiff line change
@@ -8,49 +8,6 @@ var fail = require('../assets/fail_test');
88
var delay = require('../assets/delay');
99
var mock = require('@mocks/animation');
1010

11-
12-
describe('Plots.supplyAnimationTransitionDefaults', function() {
13-
'use strict';
14-
15-
it('supplies transition defaults', function() {
16-
expect(Plots.supplyAnimationDefaults({})).toEqual({
17-
mode: 'afterall',
18-
transition: {
19-
duration: 500,
20-
easing: 'cubic-in-out'
21-
},
22-
frame: {
23-
duration: 500,
24-
redraw: true
25-
}
26-
});
27-
});
28-
29-
it('uses provided values', function() {
30-
expect(Plots.supplyAnimationDefaults({
31-
mode: 'next',
32-
transition: {
33-
duration: 600,
34-
easing: 'elastic-in-out'
35-
},
36-
frame: {
37-
duration: 700,
38-
redraw: false
39-
}
40-
})).toEqual({
41-
mode: 'next',
42-
transition: {
43-
duration: 600,
44-
easing: 'elastic-in-out'
45-
},
46-
frame: {
47-
duration: 700,
48-
redraw: false
49-
}
50-
});
51-
});
52-
});
53-
5411
function runTests(transitionDuration) {
5512
describe('Plots.transition (duration = ' + transitionDuration + ')', function() {
5613
'use strict';

0 commit comments

Comments
 (0)