Skip to content

Minor fixes to allow null frames internally #1121

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 9, 2016
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -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;
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
30 changes: 30 additions & 0 deletions test/jasmine/tests/animate_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});