From 8fce07c19cda9dda8a10264e63baa5173376db37 Mon Sep 17 00:00:00 2001 From: Nicolas Riesco Date: Fri, 22 Apr 2016 13:13:53 +0100 Subject: [PATCH 1/3] Revert "Remove unnecessary step from shapes.drawAll()" This reverts commit f67ff4d1dcbd4a0a9e5d460ed10020861a8abcae. --- src/components/shapes/index.js | 6 ++++++ 1 file changed, 6 insertions(+) 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); } From 1495a5df3466e953102e2ff68b429a84ce1e13bc Mon Sep 17 00:00:00 2001 From: Nicolas Riesco Date: Fri, 22 Apr 2016 13:30:08 +0100 Subject: [PATCH 2/3] Update shapes_test.js * Check whether `Plotly.relayout()` can remove all the shapes. --- test/jasmine/tests/shapes_test.js | 8 ++++++++ 1 file changed, 8 insertions(+) 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 + ']', From fcf3c36d9a4d3c54708cabc238a5a7557b7b6108 Mon Sep 17 00:00:00 2001 From: Nicolas Riesco Date: Fri, 22 Apr 2016 15:17:06 +0100 Subject: [PATCH 3/3] Ensure _subplotShapeLayer is always defined. --- src/plot_api/plot_api.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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