From aaf9087463e1e712f224c1ff8439aba60af2a185 Mon Sep 17 00:00:00 2001 From: Ricky Reusser Date: Tue, 8 Nov 2016 13:32:30 -0500 Subject: [PATCH] Minor fixes to allow null frames internally --- src/plot_api/plot_api.js | 4 +++- src/plots/plots.js | 2 +- test/jasmine/tests/animate_test.js | 30 ++++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/plot_api/plot_api.js b/src/plot_api/plot_api.js index c707886b07f..7d9864dccb1 100644 --- a/src/plot_api/plot_api.js +++ b/src/plot_api/plot_api.js @@ -2399,6 +2399,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 1254552dcec..73d424ce164 100644 --- a/src/plots/plots.js +++ b/src/plots/plots.js @@ -1415,7 +1415,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 c5aeb5acb3b..1f7f9bf54b2 100644 --- a/test/jasmine/tests/animate_test.js +++ b/test/jasmine/tests/animate_test.js @@ -579,3 +579,33 @@ describe('Test animate API', function() { }); }); }); + +describe('null frames', 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); + }); + + afterEach(function() { + Plotly.purge(gd); + destroyGraphDiv(); + }); + + it('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); + }); +});