diff --git a/src/plot_api/plot_api.js b/src/plot_api/plot_api.js index 9b9ef72ffda..263c0164a01 100644 --- a/src/plot_api/plot_api.js +++ b/src/plot_api/plot_api.js @@ -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 diff --git a/test/jasmine/tests/annotations_test.js b/test/jasmine/tests/annotations_test.js index 2da994bf5f7..72a7ab7675e 100644 --- a/test/jasmine/tests/annotations_test.js +++ b/test/jasmine/tests/annotations_test.js @@ -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(); diff --git a/test/jasmine/tests/shapes_test.js b/test/jasmine/tests/shapes_test.js index b2058b03bc4..1eb8dab4ce1 100644 --- a/test/jasmine/tests/shapes_test.js +++ b/test/jasmine/tests/shapes_test.js @@ -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) {