Skip to content

Commit 1683005

Browse files
committed
Emit plotly_animatingframe event on animated frames
1 parent 920a333 commit 1683005

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/plot_api/plot_api.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2219,7 +2219,7 @@ Plotly.animate = function(gd, frameOrGroupNameOrFrameList, animationOpts) {
22192219

22202220
var nextFrame = {
22212221
frame: computedFrame,
2222-
name: frameList[i].name,
2222+
name: frameList[i].name || computedFrame.name,
22232223
frameOpts: frameOpts,
22242224
transitionOpts: transitionOpts,
22252225
};
@@ -2274,6 +2274,8 @@ Plotly.animate = function(gd, frameOrGroupNameOrFrameList, animationOpts) {
22742274
var newFrame = trans._currentFrame = trans._frameQueue.shift();
22752275

22762276
if(newFrame) {
2277+
gd.emit('plotly_animatingframe', newFrame.name);
2278+
22772279
trans._lastFrameAt = Date.now();
22782280
trans._timeToNext = newFrame.frameOpts.duration;
22792281

test/jasmine/tests/animate_test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,23 @@ describe('Test animate API', function() {
406406
});
407407
});
408408

409+
describe('frame events', function() {
410+
it('emits an event when a frame is transitioned to', function(done) {
411+
var frames = [];
412+
gd.on('plotly_animatingframe', function(name) {
413+
frames.push(name);
414+
});
415+
416+
Plotly.animate(gd, ['frame0', 'frame1', {name: 'test'}, {data: []}], {
417+
transition: {duration: 1},
418+
frame: {duration: 1}
419+
}).then(function() {
420+
expect(frames).toEqual(['frame0', 'frame1', 'test', undefined]);
421+
}).catch(fail).then(done);
422+
423+
});
424+
});
425+
409426
describe('frame vs. transition timing', function() {
410427
it('limits the transition duration to <= frame duration', function(done) {
411428
Plotly.animate(gd, ['frame0'], {

0 commit comments

Comments
 (0)