diff --git a/src/components/shapes/index.js b/src/components/shapes/index.js index b0097ac5665..79bb28fd0e5 100644 --- a/src/components/shapes/index.js +++ b/src/components/shapes/index.js @@ -94,6 +94,12 @@ function linearToData(ax) { return ax.type === 'category' ? ax.l2c : ax.l2d; } shapes.drawAll = function(gd) { var fullLayout = gd._fullLayout; + + // Remove previous shapes before drawing new in shapes in fullLayout.shapes + fullLayout._shapeUpperLayer.selectAll('path').remove(); + fullLayout._shapeLowerLayer.selectAll('path').remove(); + fullLayout._subplotShapeLayer.selectAll('path').remove(); + for(var i = 0; i < fullLayout.shapes.length; i++) { shapes.draw(gd, i); } diff --git a/src/plot_api/plot_api.js b/src/plot_api/plot_api.js index 69c11bf277e..cc42a7e39c4 100644 --- a/src/plot_api/plot_api.js +++ b/src/plot_api/plot_api.js @@ -2630,6 +2630,10 @@ function makePlotFramework(gd) { // single ternary layer for the whole plot fullLayout._ternarylayer = fullLayout._paper.append('g').classed('ternarylayer', true); + // shape layers in subplots + fullLayout._subplotShapeLayer = fullLayout._paper + .selectAll('.shapelayer-subplot'); + // upper shape layer // (only for shapes to be drawn above the whole plot, including subplots) fullLayout._shapeUpperLayer = fullLayout._paper.append('g') @@ -2815,10 +2819,6 @@ function makeCartesianPlotFramwork(gd, subplots) { .style('fill', 'none') .classed('crisp', true); }); - - // shape layers in subplots - fullLayout._subplotShapeLayer = fullLayout._paper - .selectAll('.shapelayer-subplot'); } // layoutStyles: styling for plot layout elements diff --git a/test/jasmine/tests/shapes_test.js b/test/jasmine/tests/shapes_test.js index 13511fb3699..8447c94e772 100644 --- a/test/jasmine/tests/shapes_test.js +++ b/test/jasmine/tests/shapes_test.js @@ -187,6 +187,14 @@ describe('Test shapes:', function() { }).then(done); }); + it('should be able to remove all shapes', function(done) { + Plotly.relayout(gd, { shapes: [] }).then(function() { + expect(countShapePathsInUpperLayer()).toEqual(0); + expect(countShapePathsInLowerLayer()).toEqual(0); + expect(countShapePathsInSubplots()).toEqual(0); + }).then(done); + }); + it('should be able to update a shape layer', function(done) { var index = countShapes(gd), astr = 'shapes[' + index + ']',