Skip to content

Commit 2ac3dd7

Browse files
authored
Merge pull request #1121 from plotly/null-frames
Minor fixes to allow null frames internally
2 parents 40aca01 + d128a77 commit 2ac3dd7

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

src/plot_api/plot_api.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -2398,6 +2398,8 @@ Plotly.animate = function(gd, frameOrGroupNameOrFrameList, animationOpts) {
23982398
for(i = 0; i < trans._frames.length; i++) {
23992399
frame = trans._frames[i];
24002400

2401+
if(!frame) continue;
2402+
24012403
if(allFrames || frame.group === frameOrGroupNameOrFrameList) {
24022404
frameList.push({
24032405
type: 'byname',
@@ -2561,7 +2563,7 @@ Plotly.addFrames = function(gd, frameList, indices) {
25612563
if(_hash[frame.name]) {
25622564
// If frame is present, overwrite its definition:
25632565
for(j = 0; j < _frames.length; j++) {
2564-
if(_frames[j].name === frame.name) break;
2566+
if((_frames[j] || {}).name === frame.name) break;
25652567
}
25662568
ops.push({type: 'replace', index: j, value: frame});
25672569
revops.unshift({type: 'replace', index: j, value: _frames[j]});

src/plots/plots.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1429,7 +1429,7 @@ plots.modifyFrames = function(gd, operations) {
14291429
break;*/
14301430
case 'replace':
14311431
frame = op.value;
1432-
var oldName = _frames[op.index].name;
1432+
var oldName = (_frames[op.index] || {}).name;
14331433
var newName = frame.name;
14341434
_frames[op.index] = _hash[newName] = frame;
14351435

test/jasmine/tests/animate_test.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -588,14 +588,16 @@ describe('Test animate API', function() {
588588
});
589589
});
590590

591-
describe('Test animate API', function() {
591+
describe('Animate API details', function() {
592592
'use strict';
593593

594594
var gd, mockCopy;
595595

596596
beforeEach(function(done) {
597597
gd = createGraphDiv();
598+
598599
mockCopy = Lib.extendDeep({}, mock);
600+
599601
Plotly.plot(gd, mockCopy.data, mockCopy.layout).then(function() {
600602
return Plotly.addFrames(gd, mockCopy.frames);
601603
}).then(done);
@@ -606,6 +608,15 @@ describe('Test animate API', function() {
606608
destroyGraphDiv();
607609
});
608610

611+
it('null frames should not break everything', function(done) {
612+
gd._transitionData._frames.push(null);
613+
614+
Plotly.animate(gd, null, {
615+
frame: {duration: 0},
616+
transition: {duration: 0}
617+
}).catch(fail).then(done);
618+
});
619+
609620
it('does not fail if strings are not used', function(done) {
610621
Plotly.addFrames(gd, [{name: 8, data: [{x: [8, 7, 6]}]}]).then(function() {
611622
// Verify it was added as a string name:

0 commit comments

Comments
 (0)