Skip to content

Commit 6b0f175

Browse files
committed
Add isSupported property
1 parent b9ec903 commit 6b0f175

4 files changed

Lines changed: 49 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
## Next
22

3+
## v1.3.2
4+
5+
- Add `scatterplot.isSupported` and `renderer.isSupported` as read-only properties to expose if all GL extensions are supported and enabled in the user's browser (#90)
6+
- Add `checkSupport()` as a globally exported function for users to check if their browser supports and has enabled all required GL extensions (#90)
7+
38
## v1.3.1
49

510
- Add a missing `select` event name to the type definition (#87)

src/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2981,6 +2981,9 @@ const createScatterplot = (
29812981
init();
29822982

29832983
return {
2984+
get isSupported() {
2985+
return renderer.isSupported;
2986+
},
29842987
clear: withDraw(clear),
29852988
createTextureFromUrl: (/** @type {string} */ url) =>
29862989
createTextureFromUrl(renderer.regl, url),
@@ -3004,3 +3007,5 @@ const createScatterplot = (
30043007
export default createScatterplot;
30053008

30063009
export { createRegl, createRenderer, createTextureFromUrl };
3010+
3011+
export { checkReglExtensions as checkSupport } from './utils';

src/renderer.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ export const createRenderer = (options = {}) => {
88
gamma = DEFAULT_GAMMA,
99
} = options;
1010

11-
checkReglExtensions(regl);
12-
1311
// Same as regl ||= createRegl(canvas) but avoids having to rely on
1412
// https://babeljs.io/docs/en/babel-plugin-proposal-logical-assignment-operators
1513
// eslint-disable-next-line no-unused-expressions
1614
regl || (regl = createRegl(canvas));
1715

16+
const isSupportingAllGlExtensions = checkReglExtensions(regl);
17+
1818
const fboRes = [canvas.width, canvas.height];
1919
const fbo = regl.framebuffer({
2020
width: fboRes[0],
@@ -167,6 +167,9 @@ export const createRenderer = (options = {}) => {
167167
set gamma(newGamma) {
168168
gamma = +newGamma;
169169
},
170+
get isSupported() {
171+
return isSupportingAllGlExtensions;
172+
},
170173
render,
171174
onFrame,
172175
refresh,

tests/index.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ import createScatterplot, {
1212
createRegl,
1313
createRenderer,
1414
createTextureFromUrl,
15+
checkSupport,
1516
} from '../src';
17+
1618
import {
1719
DEFAULT_COLOR_NORMAL,
1820
DEFAULT_COLOR_ACTIVE,
@@ -1864,6 +1866,31 @@ test('hover() with columnar data', async (t) => {
18641866
scatterplot.destroy();
18651867
});
18661868

1869+
test('isSupported', (t) => {
1870+
const scatterplot = createScatterplot({ canvas: createCanvas() });
1871+
const renderer = scatterplot.get('renderer');
1872+
1873+
t.ok(
1874+
Object.prototype.hasOwnProperty.call(scatterplot, 'isSupported'),
1875+
'scatter plot instance should have `isSupported` property'
1876+
);
1877+
1878+
t.ok(
1879+
Object.prototype.hasOwnProperty.call(renderer, 'isSupported'),
1880+
'renderer instance should have `isSupported` property'
1881+
);
1882+
1883+
t.ok(
1884+
scatterplot.isSupported === true || scatterplot.isSupported === false,
1885+
'`isSupported` should return a Boolean value'
1886+
);
1887+
1888+
t.ok(
1889+
renderer.isSupported === true || renderer.isSupported === false,
1890+
'`isSupported` should return a Boolean value'
1891+
);
1892+
});
1893+
18671894
/* --------------------------------- Utils ---------------------------------- */
18681895

18691896
test('isNormFloatArray()', async (t) => {
@@ -1949,3 +1976,10 @@ test('toRgba()', async (t) => {
19491976
'should leave normalized RGBA unchanged'
19501977
);
19511978
});
1979+
1980+
test('checkSupport()', (t) => {
1981+
t.ok(
1982+
checkSupport() === true || checkSupport() === false,
1983+
'should return a Boolean value'
1984+
);
1985+
});

0 commit comments

Comments
 (0)