Skip to content

Commit

Permalink
relayout: add support for calls with null for annotation / shape
Browse files Browse the repository at this point in the history
- to be part with other array containers
  • Loading branch information
etpinard committed Oct 26, 2016
1 parent 2cafbeb commit 010c792
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/plot_api/plot_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -1921,6 +1921,9 @@ function _relayout(gd, aobj) {
objList = layout[objType] || [],
obji = objList[objNum] || {};

// new API, remove annotation / shape with `null`
if(vi === null) aobj[ai] = 'remove';

// if p.parts is just an annotation number, and val is either
// 'add' or an entire annotation to add, the undo is 'remove'
// if val is 'remove' then undo is the whole annotation object
Expand Down
11 changes: 9 additions & 2 deletions test/jasmine/tests/annotations_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,18 @@ describe('annotations relayout', function() {
expect(countAnnotations()).toEqual(len + 1);

return Plotly.relayout(gd, 'annotations[' + 0 + ']', 'remove');
}).then(function() {
})
.then(function() {
expect(countAnnotations()).toEqual(len);

return Plotly.relayout(gd, 'annotations[' + 0 + ']', null);
})
.then(function() {
expect(countAnnotations()).toEqual(len - 1);

return Plotly.relayout(gd, { annotations: [] });
}).then(function() {
})
.then(function() {
expect(countAnnotations()).toEqual(0);

done();
Expand Down
17 changes: 13 additions & 4 deletions test/jasmine/tests/shapes_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,21 @@ describe('Test shapes:', function() {
expect(countShapePathsInUpperLayer()).toEqual(pathCount + 1);
expect(getLastShape(gd)).toEqual(shape);
expect(countShapes(gd)).toEqual(index + 1);
}).then(function() {
Plotly.relayout(gd, 'shapes[' + index + ']', 'remove');
}).then(function() {
})
.then(function() {
return Plotly.relayout(gd, 'shapes[' + index + ']', 'remove');
})
.then(function() {
expect(countShapePathsInUpperLayer()).toEqual(pathCount);
expect(countShapes(gd)).toEqual(index);
}).then(done);

return Plotly.relayout(gd, 'shapes[' + 1 + ']', null);
})
.then(function() {
expect(countShapePathsInUpperLayer()).toEqual(pathCount - 1);
expect(countShapes(gd)).toEqual(index - 1);
})
.then(done);
});

it('should be able to remove all shapes', function(done) {
Expand Down

0 comments on commit 010c792

Please sign in to comment.