Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/plot_api/plot_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so, technically, not just null is special. Any non-numeric i would make trans._frames[i] falsy?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i can't be non-numeric since it's the array index. This is a check to see if the accessed frame is falsey. Perhaps a better check is if (!Lib.isPlainObject(frame)).


if(allFrames || frame.group === frameOrGroupNameOrFrameList) {
frameList.push({
type: 'byname',
Expand Down Expand Up @@ -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]});
Expand Down
2 changes: 1 addition & 1 deletion src/plots/plots.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
13 changes: 12 additions & 1 deletion test/jasmine/tests/animate_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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:
Expand Down