Skip to content

Commit a2a215e

Browse files
committed
fixes #2666 - show no-WebGL msg for all gl trace types
- gl2d was broken (fixed here) - all regl-based trace types (scattergl, scatterpolargl, splom and parcoords) were missing.
1 parent 17fc17c commit a2a215e

File tree

8 files changed

+118
-17
lines changed

8 files changed

+118
-17
lines changed

src/lib/prepare_regl.js

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
'use strict';
1010

11+
var showNoWebGlMsg = require('./show_no_webgl_msg');
12+
1113
// Note that this module should be ONLY required into
1214
// files corresponding to regl trace modules
1315
// so that bundles with non-regl only don't include
@@ -21,23 +23,35 @@ var createRegl = require('regl');
2123
*
2224
* @param {DOM node or object} gd : graph div object
2325
* @param {array} extensions : list of extension to pass to createRegl
26+
*
27+
* @return {boolean} true if all createRegl calls succeeded, false otherwise
2428
*/
2529
module.exports = function prepareRegl(gd, extensions) {
2630
var fullLayout = gd._fullLayout;
31+
var success = true;
2732

2833
fullLayout._glcanvas.each(function(d) {
2934
if(d.regl) return;
3035
// only parcoords needs pick layer
3136
if(d.pick && !fullLayout._has('parcoords')) return;
3237

33-
d.regl = createRegl({
34-
canvas: this,
35-
attributes: {
36-
antialias: !d.pick,
37-
preserveDrawingBuffer: true
38-
},
39-
pixelRatio: gd._context.plotGlPixelRatio || global.devicePixelRatio,
40-
extensions: extensions || []
41-
});
38+
try {
39+
d.regl = createRegl({
40+
canvas: this,
41+
attributes: {
42+
antialias: !d.pick,
43+
preserveDrawingBuffer: true
44+
},
45+
pixelRatio: gd._context.plotGlPixelRatio || global.devicePixelRatio,
46+
extensions: extensions || []
47+
});
48+
} catch(e) {
49+
success = false;
50+
}
4251
});
52+
53+
if(!success) {
54+
showNoWebGlMsg({container: fullLayout._glcontainer.node()});
55+
}
56+
return success;
4357
};

src/lib/show_no_webgl_msg.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ var noop = function() {};
2121
* Expects 'scene' to have property 'container'
2222
*
2323
*/
24-
module.exports = function showWebGlMsg(scene) {
24+
module.exports = function showNoWebGlMsg(scene) {
2525
for(var prop in scene) {
2626
if(typeof scene[prop] === 'function') scene[prop] = noop;
2727
}
@@ -36,6 +36,10 @@ module.exports = function showWebGlMsg(scene) {
3636
div.style.cursor = 'pointer';
3737
div.style.fontSize = '24px';
3838
div.style.color = Color.defaults[0];
39+
div.style.position = 'absolute';
40+
div.style.left = '20px';
41+
div.style.top = '50%';
42+
div.style.width = div.style.height = '100%';
3943

4044
scene.container.appendChild(div);
4145
scene.container.style.background = '#FFFFFF';

src/plots/gl2d/scene2d.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ function Scene2D(options, fullLayout) {
4545
this.updateRefs(fullLayout);
4646

4747
this.makeFramework();
48+
if(this.stopped) return;
4849

4950
// update options
5051
this.glplotOptions = createOptions(this);
@@ -121,7 +122,11 @@ proto.makeFramework = function() {
121122
premultipliedAlpha: true
122123
});
123124

124-
if(!gl) showNoWebGlMsg(this);
125+
if(!gl) {
126+
showNoWebGlMsg(this);
127+
this.stopped = true;
128+
return;
129+
}
125130

126131
this.canvas = liveCanvas;
127132
this.gl = gl;

src/plots/plots.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,7 @@ plots.cleanPlot = function(newFullData, newFullLayout, oldFullData, oldFullLayou
682682
if(hadGl && !hasGl) {
683683
if(oldFullLayout._glcontainer !== undefined) {
684684
oldFullLayout._glcontainer.selectAll('.gl-canvas').remove();
685+
oldFullLayout._glcontainer.selectAll('.no-webgl').remove();
685686
oldFullLayout._glcanvas = null;
686687
}
687688
}

src/traces/parcoords/plot.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ module.exports = function plot(gd, cdparcoords) {
1717
var root = fullLayout._paperdiv;
1818
var container = fullLayout._glcontainer;
1919

20-
prepareRegl(gd);
20+
var success = prepareRegl(gd);
21+
if(!success) return;
2122

2223
var gdDimensions = {};
2324
var gdDimensionsOriginalOrder = {};

src/traces/scattergl/index.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,15 @@ function plot(gd, subplot, cdata) {
326326
var width = fullLayout.width;
327327
var height = fullLayout.height;
328328

329-
prepareRegl(gd, ['ANGLE_instanced_arrays', 'OES_element_index_uint']);
329+
var success = prepareRegl(gd, ['ANGLE_instanced_arrays', 'OES_element_index_uint']);
330+
if(!success) {
331+
scene.error2d = false;
332+
scene.line2d = false;
333+
scene.scatter2d = false;
334+
scene.fill2d = false;
335+
return;
336+
}
337+
330338
var regl = fullLayout._glcanvas.data()[0].regl;
331339

332340
// that is needed for fills

src/traces/splom/base_plot.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ function plot(gd) {
2424
var _module = Registry.getModule(SPLOM);
2525
var splomCalcData = getModuleCalcData(gd.calcdata, _module)[0];
2626

27-
prepareRegl(gd, ['ANGLE_instanced_arrays', 'OES_element_index_uint']);
27+
var success = prepareRegl(gd, ['ANGLE_instanced_arrays', 'OES_element_index_uint']);
28+
if(!success) return;
2829

2930
if(fullLayout._hasOnlyLargeSploms) {
3031
drawGrid(gd);
@@ -209,7 +210,10 @@ function clean(newFullData, newFullLayout, oldFullData, oldFullLayout, oldCalcda
209210
var trace = cd0.trace;
210211
var scene = cd0.t._scene;
211212

212-
if(trace.type === 'splom' && scene && scene.matrix) {
213+
if(
214+
trace.type === 'splom' &&
215+
scene && scene.matrix && scene.matrix.destroy
216+
) {
213217
scene.matrix.destroy();
214218
cd0.t._scene = null;
215219
}

test/jasmine/bundle_tests/no_webgl_test.js

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ describe('Plotly w/o WebGL support:', function() {
1717
});
1818

1919
function checkNoWebGLMsg(visible) {
20-
var glDiv = gd.querySelector('div.gl-container');
21-
var msg = glDiv.querySelector('div.no-webgl');
20+
var msg = gd.querySelector('div.no-webgl');
2221
if(visible) {
2322
expect(msg.innerHTML.substr(0, 22)).toBe('WebGL is not supported');
2423
} else {
@@ -38,4 +37,69 @@ describe('Plotly w/o WebGL support:', function() {
3837
.catch(failTest)
3938
.then(done);
4039
});
40+
41+
it('gl2d subplots', function(done) {
42+
Plotly.react(gd, require('@mocks/gl2d_pointcloud-basic.json'))
43+
.then(function() {
44+
checkNoWebGLMsg(true);
45+
return Plotly.react(gd, require('@mocks/10.json'));
46+
})
47+
.then(function() {
48+
checkNoWebGLMsg(false);
49+
})
50+
.catch(failTest)
51+
.then(done);
52+
});
53+
54+
it('scattergl subplots', function(done) {
55+
Plotly.react(gd, require('@mocks/gl2d_12.json'))
56+
.then(function() {
57+
checkNoWebGLMsg(true);
58+
return Plotly.react(gd, require('@mocks/10.json'));
59+
})
60+
.then(function() {
61+
checkNoWebGLMsg(false);
62+
})
63+
.catch(failTest)
64+
.then(done);
65+
});
66+
67+
it('scatterpolargl subplots', function(done) {
68+
Plotly.react(gd, require('@mocks/glpolar_scatter.json'))
69+
.then(function() {
70+
checkNoWebGLMsg(true);
71+
return Plotly.react(gd, require('@mocks/10.json'));
72+
})
73+
.then(function() {
74+
checkNoWebGLMsg(false);
75+
})
76+
.catch(failTest)
77+
.then(done);
78+
});
79+
80+
it('splom subplots', function(done) {
81+
Plotly.react(gd, require('@mocks/splom_0.json'))
82+
.then(function() {
83+
checkNoWebGLMsg(true);
84+
return Plotly.react(gd, require('@mocks/10.json'));
85+
})
86+
.then(function() {
87+
checkNoWebGLMsg(false);
88+
})
89+
.catch(failTest)
90+
.then(done);
91+
});
92+
93+
it('parcoords subplots', function(done) {
94+
Plotly.react(gd, require('@mocks/gl2d_parcoords_2.json'))
95+
.then(function() {
96+
checkNoWebGLMsg(true);
97+
return Plotly.react(gd, require('@mocks/10.json'));
98+
})
99+
.then(function() {
100+
checkNoWebGLMsg(false);
101+
})
102+
.catch(failTest)
103+
.then(done);
104+
});
41105
});

0 commit comments

Comments
 (0)