Skip to content

Commit 4b6cf3d

Browse files
committed
make sure old scenes on polar subplot are destroyed
... when no gl traces are present on graph.
1 parent 5a24245 commit 4b6cf3d

File tree

3 files changed

+78
-0
lines changed

3 files changed

+78
-0
lines changed

src/plots/polar/index.js

+8
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ function plot(gd) {
5353

5454
function clean(newFullData, newFullLayout, oldFullData, oldFullLayout) {
5555
var oldIds = oldFullLayout._subplots[name] || [];
56+
var hadGl = (oldFullLayout._has && oldFullLayout._has('gl'));
57+
var hasGl = (newFullLayout._has && newFullLayout._has('gl'));
58+
var mustCleanScene = hadGl && !hasGl;
5659

5760
for(var i = 0; i < oldIds.length; i++) {
5861
var id = oldIds[i];
@@ -66,6 +69,11 @@ function clean(newFullData, newFullLayout, oldFullData, oldFullLayout) {
6669
oldSubplot.clipPaths[k].remove();
6770
}
6871
}
72+
73+
if(mustCleanScene && oldSubplot._scene) {
74+
oldSubplot._scene.destroy();
75+
oldSubplot._scene = null;
76+
}
6977
}
7078
}
7179

src/traces/scatterpolargl/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ function calc(container, trace) {
4242
}
4343

4444
function plot(container, subplot, cdata) {
45+
if(!cdata.length) return;
46+
4547
var radialAxis = subplot.radialAxis;
4648
var angularAxis = subplot.angularAxis;
4749

test/jasmine/tests/scatterpolargl_test.js

+68
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
var Plotly = require('@lib');
22
var Lib = require('@src/lib');
33

4+
var d3 = require('d3');
45
var createGraphDiv = require('../assets/create_graph_div');
56
var destroyGraphDiv = require('../assets/destroy_graph_div');
67
var failTest = require('../assets/fail_test');
78
var mouseEvent = require('../assets/mouse_event');
9+
var readPixel = require('../assets/read_pixel');
810

911
var customAssertions = require('../assets/custom_assertions');
1012
var assertHoverLabelContent = customAssertions.assertHoverLabelContent;
@@ -102,3 +104,69 @@ describe('Test scatterpolargl hover:', function() {
102104
});
103105
});
104106
});
107+
108+
describe('Test scatterpolargl interactions:', function() {
109+
var gd;
110+
111+
afterEach(function() {
112+
Plotly.purge(gd);
113+
destroyGraphDiv();
114+
});
115+
116+
function countCanvases() {
117+
return d3.selectAll('canvas').size();
118+
}
119+
120+
function totalPixels() {
121+
return readPixel(gd.querySelector('.gl-canvas-context'), 0, 0, 400, 400)
122+
.reduce(function(acc, v) { return acc + v; }, 0);
123+
}
124+
125+
it('@gl should be able to toggle from svg to gl', function(done) {
126+
gd = createGraphDiv();
127+
128+
var scene;
129+
130+
Plotly.plot(gd, [{
131+
type: 'scatterpolar',
132+
r: [1, 2, 1],
133+
}], {
134+
width: 400,
135+
height: 400
136+
})
137+
.then(function() {
138+
expect(countCanvases()).toBe(0);
139+
expect(d3.selectAll('.scatterlayer > .trace').size()).toBe(1);
140+
141+
return Plotly.restyle(gd, 'type', 'scatterpolargl');
142+
})
143+
.then(function() {
144+
expect(countCanvases()).toBe(3);
145+
expect(totalPixels()).not.toBe(0);
146+
expect(d3.selectAll('.scatterlayer > .trace').size()).toBe(0);
147+
148+
scene = gd._fullLayout.polar._subplot._scene;
149+
spyOn(scene, 'destroy').and.callThrough();
150+
151+
return Plotly.restyle(gd, 'type', 'scatterpolar');
152+
})
153+
.then(function() {
154+
expect(countCanvases()).toBe(0);
155+
expect(scene.destroy).toHaveBeenCalledTimes(1);
156+
expect(gd._fullLayout.polar._subplot._scene).toBe(null);
157+
expect(d3.selectAll('.scatterlayer > .trace').size()).toBe(1);
158+
159+
return Plotly.restyle(gd, 'type', 'scatterpolargl');
160+
})
161+
.then(function() {
162+
expect(countCanvases()).toBe(3);
163+
// this here was failing before
164+
// https://github.com/plotly/plotly.js/issues/3094
165+
// got fixed
166+
expect(totalPixels()).not.toBe(0);
167+
expect(d3.selectAll('.scatterlayer > .trace').size()).toBe(0);
168+
})
169+
.catch(failTest)
170+
.then(done);
171+
});
172+
});

0 commit comments

Comments
 (0)