Skip to content

Commit cab319d

Browse files
committed
add another svg <-> gl test
1 parent 25fb7dc commit cab319d

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed

Diff for: test/jasmine/tests/scatterpolargl_test.js

+81
Original file line numberDiff line numberDiff line change
@@ -169,4 +169,85 @@ describe('Test scatterpolargl interactions:', function() {
169169
.catch(failTest)
170170
.then(done);
171171
});
172+
173+
it('@gl should be able to toggle from svg to gl (on graph with scattergl subplot)', function(done) {
174+
gd = createGraphDiv();
175+
176+
var sceneXY, scenePolar;
177+
178+
Plotly.plot(gd, [{
179+
type: 'scattergl',
180+
y: [1, 2, 1]
181+
}, {
182+
type: 'scatterpolargl',
183+
r: [1, 2, 1]
184+
}], {
185+
grid: {rows: 1, columns: 2},
186+
yaxis: {domain: {column: 0}},
187+
polar: {domain: {column: 1}},
188+
width: 400,
189+
height: 400
190+
})
191+
.then(function() {
192+
expect(countCanvases()).toBe(3);
193+
expect(totalPixels()).not.toBe(0);
194+
expect(d3.selectAll('.scatterlayer > .trace').size()).toBe(0);
195+
196+
sceneXY = gd._fullLayout._plots.xy._scene;
197+
spyOn(sceneXY, 'destroy').and.callThrough();
198+
199+
scenePolar = gd._fullLayout.polar._subplot._scene;
200+
spyOn(scenePolar, 'destroy').and.callThrough();
201+
202+
return Plotly.restyle(gd, 'type', 'scatterpolar', [1]);
203+
})
204+
.then(function() {
205+
expect(countCanvases()).toBe(3);
206+
expect(totalPixels()).not.toBe(0);
207+
expect(d3.selectAll('.scatterlayer > .trace').size()).toBe(1);
208+
209+
expect(sceneXY.destroy).toHaveBeenCalledTimes(0);
210+
expect(gd._fullLayout._plots.xy._scene).not.toBe(null);
211+
212+
// N.B. does not destroy scene in this case,
213+
// we don't need as the same gl canvases are still there
214+
expect(scenePolar.destroy).toHaveBeenCalledTimes(0);
215+
expect(gd._fullLayout.polar._subplot._scene).not.toBe(null);
216+
217+
return Plotly.restyle(gd, 'type', 'scatterpolargl', [1]);
218+
})
219+
.then(function() {
220+
expect(countCanvases()).toBe(3);
221+
expect(totalPixels()).not.toBe(0);
222+
expect(d3.selectAll('.scatterlayer > .trace').size()).toBe(0);
223+
224+
return Plotly.restyle(gd, 'type', 'scatter', [0]);
225+
})
226+
.then(function() {
227+
expect(countCanvases()).toBe(3);
228+
expect(totalPixels()).not.toBe(0);
229+
expect(d3.selectAll('.scatterlayer > .trace').size()).toBe(1);
230+
231+
// Similarly, does not destroy scene in this case,
232+
// we don't need as the same gl canvases are still there
233+
expect(sceneXY.destroy).toHaveBeenCalledTimes(0);
234+
expect(gd._fullLayout._plots.xy._scene).not.toBe(null);
235+
236+
expect(scenePolar.destroy).toHaveBeenCalledTimes(0);
237+
expect(gd._fullLayout.polar._subplot._scene).not.toBe(null);
238+
239+
return Plotly.restyle(gd, 'type', 'scatterpolar', [1]);
240+
})
241+
.then(function() {
242+
expect(countCanvases()).toBe(0);
243+
expect(d3.selectAll('.scatterlayer > .trace').size()).toBe(2);
244+
245+
expect(sceneXY.destroy).toHaveBeenCalledTimes(1);
246+
expect(gd._fullLayout._plots.xy._scene).toBe(null);
247+
expect(scenePolar.destroy).toHaveBeenCalledTimes(1);
248+
expect(gd._fullLayout.polar._subplot._scene).toBe(null);
249+
})
250+
.catch(failTest)
251+
.then(done);
252+
});
172253
});

0 commit comments

Comments
 (0)