Skip to content

Commit d4b9017

Browse files
authored
Merge pull request #1531 from plotly/delete-frames-handle-null
make deleteFrames(gd) delete all frames
2 parents 7f07d51 + c9bd993 commit d4b9017

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

src/plot_api/plot_api.js

+7
Original file line numberDiff line numberDiff line change
@@ -2764,6 +2764,13 @@ Plotly.deleteFrames = function(gd, frameList) {
27642764
var ops = [];
27652765
var revops = [];
27662766

2767+
if(!frameList) {
2768+
frameList = [];
2769+
for(i = 0; i < _frames.length; i++) {
2770+
frameList.push(i);
2771+
}
2772+
}
2773+
27672774
frameList = frameList.slice(0);
27682775
frameList.sort();
27692776

test/jasmine/tests/frame_api_test.js

+52
Original file line numberDiff line numberDiff line change
@@ -263,5 +263,57 @@ describe('Test frame api', function() {
263263
return Plotly.Queue.redo(gd);
264264
}).then(validate).catch(fail).then(done);
265265
});
266+
267+
it('deletes all frames if frameList is falsey', function(done) {
268+
var i;
269+
var n = 10;
270+
var frames = [];
271+
for(i = 0; i < n; i++) {
272+
frames.push({name: 'frame' + i});
273+
}
274+
275+
function validateCount(n) {
276+
return function() {
277+
expect(f.length).toEqual(n);
278+
};
279+
}
280+
281+
Plotly.addFrames(gd, frames).then(function() {
282+
// Delete with no args:
283+
return Plotly.deleteFrames(gd);
284+
}).then(validateCount(0)).then(function() {
285+
// Restore:
286+
return Plotly.Queue.undo(gd);
287+
}).then(validateCount(n)).then(function() {
288+
// Delete with null arg:
289+
return Plotly.deleteFrames(gd, null);
290+
}).then(validateCount(0)).then(function() {
291+
// Restore:
292+
return Plotly.Queue.undo(gd);
293+
}).then(validateCount(n)).then(function() {
294+
// Delete with undefined:
295+
return Plotly.deleteFrames(gd, undefined);
296+
}).then(validateCount(0)).catch(fail).then(done);
297+
});
298+
299+
it('deleteFrames is a no-op with empty array', function(done) {
300+
var i;
301+
var n = 10;
302+
var frames = [];
303+
for(i = 0; i < n; i++) {
304+
frames.push({name: 'frame' + i});
305+
}
306+
307+
function validateCount(n) {
308+
return function() {
309+
expect(f.length).toEqual(n);
310+
};
311+
}
312+
313+
Plotly.addFrames(gd, frames).then(function() {
314+
// Delete with no args:
315+
return Plotly.deleteFrames(gd, []);
316+
}).then(validateCount(n)).catch(fail).then(done);
317+
});
266318
});
267319
});

0 commit comments

Comments
 (0)