Skip to content

Commit 2fdfc17

Browse files
committed
Merge pull request #465 from n-riesco/issue-464-revert-drawall
Fixes #464 (shapes not deleted when clearing all shapes)
2 parents 7ba60a4 + fcf3c36 commit 2fdfc17

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

src/components/shapes/index.js

+6
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ function linearToData(ax) { return ax.type === 'category' ? ax.l2c : ax.l2d; }
9494

9595
shapes.drawAll = function(gd) {
9696
var fullLayout = gd._fullLayout;
97+
98+
// Remove previous shapes before drawing new in shapes in fullLayout.shapes
99+
fullLayout._shapeUpperLayer.selectAll('path').remove();
100+
fullLayout._shapeLowerLayer.selectAll('path').remove();
101+
fullLayout._subplotShapeLayer.selectAll('path').remove();
102+
97103
for(var i = 0; i < fullLayout.shapes.length; i++) {
98104
shapes.draw(gd, i);
99105
}

src/plot_api/plot_api.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -2630,6 +2630,10 @@ function makePlotFramework(gd) {
26302630
// single ternary layer for the whole plot
26312631
fullLayout._ternarylayer = fullLayout._paper.append('g').classed('ternarylayer', true);
26322632

2633+
// shape layers in subplots
2634+
fullLayout._subplotShapeLayer = fullLayout._paper
2635+
.selectAll('.shapelayer-subplot');
2636+
26332637
// upper shape layer
26342638
// (only for shapes to be drawn above the whole plot, including subplots)
26352639
fullLayout._shapeUpperLayer = fullLayout._paper.append('g')
@@ -2815,10 +2819,6 @@ function makeCartesianPlotFramwork(gd, subplots) {
28152819
.style('fill', 'none')
28162820
.classed('crisp', true);
28172821
});
2818-
2819-
// shape layers in subplots
2820-
fullLayout._subplotShapeLayer = fullLayout._paper
2821-
.selectAll('.shapelayer-subplot');
28222822
}
28232823

28242824
// layoutStyles: styling for plot layout elements

test/jasmine/tests/shapes_test.js

+8
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,14 @@ describe('Test shapes:', function() {
187187
}).then(done);
188188
});
189189

190+
it('should be able to remove all shapes', function(done) {
191+
Plotly.relayout(gd, { shapes: [] }).then(function() {
192+
expect(countShapePathsInUpperLayer()).toEqual(0);
193+
expect(countShapePathsInLowerLayer()).toEqual(0);
194+
expect(countShapePathsInSubplots()).toEqual(0);
195+
}).then(done);
196+
});
197+
190198
it('should be able to update a shape layer', function(done) {
191199
var index = countShapes(gd),
192200
astr = 'shapes[' + index + ']',

0 commit comments

Comments
 (0)