Skip to content

Commit a123b63

Browse files
committed
Improve type definitions
1 parent 425e9f1 commit a123b63

4 files changed

Lines changed: 47 additions & 6 deletions

File tree

src/index.js

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

29832983
return {
2984+
/**
2985+
* Get whether the browser supports all necessary WebGL features
2986+
* @return {boolean} If `true` the browser supports all necessary WebGL features
2987+
*/
29842988
get isSupported() {
29852989
return renderer.isSupported;
29862990
},

src/renderer.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ export const createRenderer = (options = {}) => {
8989
);
9090
};
9191

92+
/**
93+
* The render function
94+
* @param {function} draw - The function for drawing
95+
* @param {HTMLCanvasElement} targetCanvas - The canvas element that should received the rendered pixels.
96+
*/
9297
const render = (draw, targetCanvas) => {
9398
// Clear internal canvas
9499
regl.clear(CLEAR_OPTIONS);
@@ -116,6 +121,11 @@ export const createRenderer = (options = {}) => {
116121

117122
const drawFns = new Set();
118123

124+
/**
125+
* Register an draw function that is going to be invoked on every animation
126+
* frame.
127+
* @param {function} draw - The callback function
128+
*/
119129
const onFrame = (draw) => {
120130
drawFns.add(draw);
121131
return () => {
@@ -146,6 +156,9 @@ export const createRenderer = (options = {}) => {
146156
resize();
147157
}
148158

159+
/**
160+
* Destroy the renderer to free resources and cancel animation frames
161+
*/
149162
const destroy = () => {
150163
frame.cancel();
151164
canvas = undefined;
@@ -155,18 +168,38 @@ export const createRenderer = (options = {}) => {
155168
};
156169

157170
return {
171+
/**
172+
* Get the associated canvas element
173+
* @return {HTMLCanvasElement} The associated canvas element
174+
*/
158175
get canvas() {
159176
return canvas;
160177
},
178+
/**
179+
* Get the associated Regl instance
180+
* @return {import('regl').Regl} The associated Regl instance
181+
*/
161182
get regl() {
162183
return regl;
163184
},
185+
/**
186+
* Get the gamma value
187+
* @return {number} The gamma value
188+
*/
164189
get gamma() {
165190
return gamma;
166191
},
192+
/**
193+
* Set gamma to a new value
194+
* @param {number} newGamma - The new gamma value
195+
*/
167196
set gamma(newGamma) {
168197
gamma = +newGamma;
169198
},
199+
/**
200+
* Get whether the browser supports all necessary WebGL features
201+
* @return {boolean} If `true` the browser supports all necessary WebGL features
202+
*/
170203
get isSupported() {
171204
return isSupportingAllGlExtensions;
172205
},

src/types.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ export type Settable = BaseOptions &
116116
WithPrefix<'camera', CameraOptions>;
117117

118118
export type Properties = {
119+
renderer: ReturnType<typeof import('./renderer').createRenderer>;
119120
canvas: HTMLCanvasElement;
120121
regl: import('regl').Regl;
121122
syncEvents: boolean;

src/utils.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,20 @@ import { GL_EXTENSIONS } from './constants';
1111
export const arrayMax = (max, x) => (max > x ? max : x);
1212

1313
/**
14-
* Check if all GL extensions are enabled and warn otherwise
14+
* Check if all GL extensions are supported and enabled and warn otherwise
1515
* @param {import('regl').Regl} regl Regl instance to be tested
16-
* @return {function} Returns the Regl instance itself
16+
* @param {boolean} silent If `true` the function will not print `console.warn` statements
17+
* @return {boolean} If `true` all required GL extensions are supported
1718
*/
18-
export const checkReglExtensions = (regl) => {
19+
export const checkReglExtensions = (regl, silent) => {
1920
if (!regl) return false;
2021
return GL_EXTENSIONS.reduce((every, EXTENSION) => {
2122
if (!regl.hasExtension(EXTENSION)) {
22-
console.warn(
23-
`WebGL: ${EXTENSION} extension not supported. Scatterplot might not render properly`
24-
);
23+
if (!silent) {
24+
console.warn(
25+
`WebGL: ${EXTENSION} extension not supported. Scatterplot might not render properly`
26+
);
27+
}
2528
return false;
2629
}
2730
return every;

0 commit comments

Comments
 (0)