100k-point WebGL chart with live DOM tooltips
I wanted to know if a WebGL 2 chart can plot 100,000 points smoothly while keeping its tooltips, series filters and pinned callouts as real accessible HTML inside the same canvas. This experiment draws on the data-visualisation motivation in the WICG HTML-in-canvas explainer and on high-density WebGL charts such as deck.gl and Lightweight Charts. Drag or pinch to pan and zoom, click or tap any point to inspect and copy its values, or pin an editable note to a data coordinate.
Show the code 100k-point VBO, spatial grid, ElementGL quads and 2D fallback
- Three drawable HTML overlays inside one canvas. The legend, pinned callout and tooltip are children of
<canvas content="drawable" layoutsubtree>. - 100,000 points and a 64×64 spatial grid. Both layouts are generated deterministically and indexed in flat typed arrays for sub-millisecond lookup.
- One bitmask uniform filters 25,000 points per series. Toggling a checkbox updates
uMaskon the GPU without touching the vertex buffer. - Sharing one
ElementGLWebGL 2 context. The chart draws its buffers first, restoresElementGL's program and VAO, draws the HTML textures and syncs hit boxes viaupdateElementGeometry(). - 2D canvas fallback. If WebGL 2 is unavailable, a 2D context draws a downsampled point set and composites the same overlays with five-argument
drawElementImage(). - Texture upload.
ElementGL.upload()sizes each texture to the element's picture and callstexElementSubImage2D().
How it works
Most high-density WebGL charts (deck.gl, Lightweight Charts and similar engines) render the data on a canvas and float separate HTML nodes over it with CSS transforms.
That works until a fast pan or zoom lets the HTML layer drift a frame behind the WebGL buffer, or until screen readers and hit testing disagree with clipped elements.
Here the page opens one WebGL 2 context through ElementGL from /lib/element-gl.js, uploads 100,000 points once into static ARRAY_BUFFER storage, and draws three drawable HTML children in the same paint pass.
In scatter mode all 100,000 vertices are drawn in one gl.drawArrays(gl.POINTS, 0, 100000) call.
Each checkbox in the in-canvas legend flips a bit in a 4-bit integer uniform (uMask); hidden series are discarded in the vertex shader with zero VBO re-uploads.
In time-series mode the same 100,000 samples are drawn as four 25,000-vertex GL_LINE_STRIP traces over precomputed 500-bucket high/low OHLC range bands.
Pointer lookup doesn't scan all 100,000 points.
Scatter points are packed into a 64×64 flat grid (cellStart and cellPoints typed arrays) so finding the nearest visible point inspects only a handful of cells around the pointer.
Time-series samples are evenly spaced in time, so lookup jumps straight to the bucket index.
When you pan or zoom, the pinned callout's screen position is calculated from its data-space (x, y) coordinate, drawn with stage.quad(), and registered for clicks and text selection via canvas.updateElementGeometry(el, { canvasTransform }) plus a data-hit-tick attribute toggle to clear Chromium's hit-test cache.
Live checks
These checks wait for a tap so the page opens only one WebGL context on load. Each check builds its own fixture on the off-to-the-side test stage and retires its canvas when finished.
Findings
- This experiment was inspired by the data-visualisation use case in the WICG HTML-in-canvas explainer (keeping accessible labels and tooltips in the same composited surface) and by high-density WebGL scatter and financial charts like deck.gl and Lightweight Charts.
- Sharing
ElementGL's single WebGL 2 context avoids allocating a second GPU context on mobile. BecauseElementGLkeeps its quad program and VAO private, the chart readsgl.CURRENT_PROGRAMandgl.VERTEX_ARRAY_BINDINGonce afterstage.begin(), draws the 100,000-point buffers with its own VAOs, then restoresElementGL's bindings before callingstage.quad(). - Panning and zooming change only view uniforms and quad matrices. Stationary overlays whose DOM content didn't change don't need new
texElementSubImage2D()uploads, which the upload counter under the chart tracks live. - Toggling
el.dataset.hitTickafterupdateElementGeometry()clears Chromium's stale hit-test cache, and gating it on whether the element's rectangle actually changed prevents an infinitepaintloop. - Hidden overlays (a dismissed tooltip, an unpinned callout, or a pinned point panned outside the plot) get
inert = trueand a hit box moved off-canvas so they stop catching clicks or Tab focus. - Live browser verification in Chromium 157 and on Chrome 159 for Android is not verified yet; run the live checks on your device to measure spatial lookup, WebGL 2 rendering, hit-box alignment and upload counts directly.