diff --git a/src/plot_api/plot_api.js b/src/plot_api/plot_api.js index fa45556f741..aa4d2219010 100644 --- a/src/plot_api/plot_api.js +++ b/src/plot_api/plot_api.js @@ -2398,6 +2398,8 @@ Plotly.animate = function(gd, frameOrGroupNameOrFrameList, animationOpts) { for(i = 0; i < trans._frames.length; i++) { frame = trans._frames[i]; + if(!frame) continue; + if(allFrames || frame.group === frameOrGroupNameOrFrameList) { frameList.push({ type: 'byname', @@ -2561,7 +2563,7 @@ Plotly.addFrames = function(gd, frameList, indices) { if(_hash[frame.name]) { // If frame is present, overwrite its definition: for(j = 0; j < _frames.length; j++) { - if(_frames[j].name === frame.name) break; + if((_frames[j] || {}).name === frame.name) break; } ops.push({type: 'replace', index: j, value: frame}); revops.unshift({type: 'replace', index: j, value: _frames[j]}); diff --git a/src/plots/plots.js b/src/plots/plots.js index 4034d8dc40d..157489c285d 100644 --- a/src/plots/plots.js +++ b/src/plots/plots.js @@ -1429,7 +1429,7 @@ plots.modifyFrames = function(gd, operations) { break;*/ case 'replace': frame = op.value; - var oldName = _frames[op.index].name; + var oldName = (_frames[op.index] || {}).name; var newName = frame.name; _frames[op.index] = _hash[newName] = frame; diff --git a/test/jasmine/tests/animate_test.js b/test/jasmine/tests/animate_test.js index c8e926579d9..752bf8d6496 100644 --- a/test/jasmine/tests/animate_test.js +++ b/test/jasmine/tests/animate_test.js @@ -588,14 +588,16 @@ describe('Test animate API', function() { }); }); -describe('Test animate API', function() { +describe('Animate API details', function() { 'use strict'; var gd, mockCopy; beforeEach(function(done) { gd = createGraphDiv(); + mockCopy = Lib.extendDeep({}, mock); + Plotly.plot(gd, mockCopy.data, mockCopy.layout).then(function() { return Plotly.addFrames(gd, mockCopy.frames); }).then(done); @@ -606,6 +608,15 @@ describe('Test animate API', function() { destroyGraphDiv(); }); + it('null frames should not break everything', function(done) { + gd._transitionData._frames.push(null); + + Plotly.animate(gd, null, { + frame: {duration: 0}, + transition: {duration: 0} + }).catch(fail).then(done); + }); + it('does not fail if strings are not used', function(done) { Plotly.addFrames(gd, [{name: 8, data: [{x: [8, 7, 6]}]}]).then(function() { // Verify it was added as a string name: