diff --git a/src/components/annotations/draw.js b/src/components/annotations/draw.js index 328709e92ba..491dfc1eba8 100644 --- a/src/components/annotations/draw.js +++ b/src/components/annotations/draw.js @@ -69,7 +69,7 @@ function drawOne(gd, index) { fullLayout._infolayer.selectAll('.annotation[data-index="' + index + '"]').remove(); // remember a few things about what was already there, - var optionsIn = layout.annotations[index], + var optionsIn = (layout.annotations || [])[index], options = fullLayout.annotations[index]; // this annotation is gone - quit now after deleting it diff --git a/src/components/shapes/draw.js b/src/components/shapes/draw.js index fc019c7a1f8..774e31a3dc1 100644 --- a/src/components/shapes/draw.js +++ b/src/components/shapes/draw.js @@ -63,7 +63,7 @@ function drawOne(gd, index) { .selectAll('.shapelayer [data-index="' + index + '"]') .remove(); - var optionsIn = gd.layout.shapes[index], + var optionsIn = (gd.layout.shapes || [])[index], options = gd._fullLayout.shapes[index]; // this shape is gone - quit now after deleting it diff --git a/test/jasmine/tests/annotations_test.js b/test/jasmine/tests/annotations_test.js index 967b31323eb..cc9629d245f 100644 --- a/test/jasmine/tests/annotations_test.js +++ b/test/jasmine/tests/annotations_test.js @@ -200,6 +200,17 @@ describe('annotations relayout', function() { return Plotly.relayout(gd, {annotations: null}); }) + .then(function() { + expect(countAnnotations()).toEqual(0); + expect(Loggers.warn).not.toHaveBeenCalled(); + + return Plotly.relayout(gd, {'annotations[0]': ann}); + }) + .then(function() { + expect(countAnnotations()).toEqual(1); + + return Plotly.relayout(gd, {'annotations[0]': null}); + }) .then(function() { expect(countAnnotations()).toEqual(0); expect(Loggers.warn).not.toHaveBeenCalled(); diff --git a/test/jasmine/tests/shapes_test.js b/test/jasmine/tests/shapes_test.js index 7b35e5c0a61..ab3ffcf5b0d 100644 --- a/test/jasmine/tests/shapes_test.js +++ b/test/jasmine/tests/shapes_test.js @@ -320,6 +320,23 @@ describe('Test shapes:', function() { expect(countShapePathsInLowerLayer()).toEqual(0); expect(countShapePathsInSubplots()).toEqual(0); }) + .then(function() { + return Plotly.relayout(gd, {'shapes[0]': getRandomShape()}); + }) + .then(function() { + expect(countShapePathsInUpperLayer()).toEqual(1); + expect(countShapePathsInLowerLayer()).toEqual(0); + expect(countShapePathsInSubplots()).toEqual(0); + expect(gd.layout.shapes.length).toBe(1); + + return Plotly.relayout(gd, {'shapes[0]': null}); + }) + .then(function() { + expect(countShapePathsInUpperLayer()).toEqual(0); + expect(countShapePathsInLowerLayer()).toEqual(0); + expect(countShapePathsInSubplots()).toEqual(0); + expect(gd.layout.shapes).toBeUndefined(); + }) .catch(failTest) .then(done); });