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.

Series (25k each) 100k

 

Show the code 100k-point VBO, spatial grid, ElementGL quads and 2D fallback
  1. Three drawable HTML overlays inside one canvas. The legend, pinned callout and tooltip are children of <canvas content="drawable" layoutsubtree>.
  2. 100,000 points and a 64×64 spatial grid. Both layouts are generated deterministically and indexed in flat typed arrays for sub-millisecond lookup.
  3. One bitmask uniform filters 25,000 points per series. Toggling a checkbox updates uMask on the GPU without touching the vertex buffer.
  4. Sharing one ElementGL WebGL 2 context. The chart draws its buffers first, restores ElementGL's program and VAO, draws the HTML textures and syncs hit boxes via updateElementGeometry().
  5. 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().
  6. Texture upload. ElementGL.upload() sizes each texture to the element's picture and calls texElementSubImage2D().

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