Skip to content

feat: add an opt-in preview for scattergl and scatter3d plots of many points - #10

Draft
katosh wants to merge 13 commits into
pr/scattergl-typedfrom
pr/lod-v3
Draft

katosh wants to merge 13 commits into
pr/scattergl-typedfrom
pr/lod-v3

Conversation

@katosh

@katosh katosh commented Dec 5, 2026 •

Copy link
Copy Markdown

Stacked on #9 (typed scattergl) and #4 (disc markers). The base is pr/scattergl-typed, so the diff also shows the three commits of #4.

Description

layout.lod draws every k-th point of a large scattergl plot first. The full picture follows when the plot is at rest. scene.lod does the same for scatter3d discs while the camera moves. At 20 million points, a pan frame takes 5.4 ms instead of 114 ms. Without the two attributes, no pixel changes.

One drag in two panels. Without the change, the picture lags behind the pointer. With layout.lod, previews of every 32nd point follow the pointer, and then the full picture comes
Screencast frames in time order: the same scripted drag over 20 million points on main and with layout.lod, 900x600. The ring marks the pointer. The times in this text come from separate measurement runs.

One full draw of 20 million points takes the GPU about 0.1 s (114 ms per pan frame on this branch without layout.lod). Each open, edit and pan frame waits for that draw.

Two rows of five states in order after the call. Without layout.lod, the graph stays empty until the full picture in panel 4. With it, a preview of every 64th point comes in panel 2, and the full picture in panel 5
Plotly.react of 50 million points on this branch, without and with layout.lod. Five moments of a screencast in time order. Each panel shows the state of that moment, drawn with visible axes.

The preview and the full picture of the same graph, side by side with the same axes
The same graph and axes. The preview draws 781,250 of the 50 million points. At rest, 64 times more points fill the edge of each cluster.

A draw shows every k-th point, and k keeps the count within budget. After settle ms without a draw request, the full picture follows in parts of slice points. A pan between two parts waits for one part only. A recolor of a full plot keeps the old picture until the new picture is ready. The plotly_lod event reports each state.

Three line charts of the time to the first frame, to the full picture and for a pan frame, against the number of points
main and this branch as strict bundles, one run each, Apple M3 Max. Preset: minpoints 1M, budget 1M, maxstride 64, settle 150 ms. The dashed line is this branch without layout.lod, which holds #9.

20M points, ms without with layout.lod
Open to the first frame 338 134
Open to the full picture 338 449
Pan frame 114 5.4

The full picture comes later with layout.lod, because the full draw starts settle ms after the last draw request. With 50 million points, the first frame comes after 245 ms instead of 740 ms. The full picture comes after 885 ms instead of 741 ms. In 3D, the full picture also waits for the end of the camera glide of the open. With 5 million discs, that is 786 ms instead of 491 ms.

AnnZarro draws millions of single cells with plotly.js and needs this. Overview: #11.

Changes

  • src/traces/scattergl/lod.ts (new): the states around scene.draw
  • layout.lod: minpoints, budget, maxstride, settle, slice and edits
  • scene.lod for gl3d: minpoints, budget, maxstride and settle
  • scene.hidden and scene.setHidden on the scattergl scene: hide traces without a calc or an upload
  • Pin regl-scatter2d, gl-plot3d and gl-scatter3d to fork commits: settylab/regl-scatter2d#2, settylab/gl-plot3d#4, settylab/gl-scatter3d#6

Testing

  • scattergl_lod: 24 specs. gl3d_lod: 6 specs.
  • With lod unset, 13 2D scenes and 8 3D scenes render the same pixels as main
  • With lod set, the picture at rest equals the picture without it in 7 2D scenes and 8 3D scenes

Notes

  • Scope. The 2D preview needs one subplot of markers-only scattergl traces. Other WebGL traces or a selection turn the preview off.
  • Behavior with layout.lod. plotly_afterplot fires after the preview. For the full picture, wait for plotly_lod with state full.
  • Cost of an edit. A recolor of one trace takes longer with layout.lod. It takes 182 ms against 120 ms at 20 million points, and 455 ms against 266 ms at 50 million. The edit keeps the old picture on screen and draws the new picture in parts.
  • Opacity. A preview marker of alpha a at stride k gets the alpha 1 - (1 - a)^k. A translucent preview is thus as dense as the full picture. This is an estimate: it holds where the markers left out lie like the markers kept. A scattergl trace with markers of different alpha takes their mean.
  • scene.hidden and scene.setHidden are members of an internal object. I can change them to a public form.
  • I verified the change in Chromium only
  • The pins are temporary
  • Order with feat: draw the gl3d pick pass on demand #8. If that pull request merges first, one gl3d_lod spec needs a change. The full frame then draws no pick pass before a pointer query. The change is ready.

I can split, reshape or drop any part. Thank you for your time.

Checklist

  • The linked issue has the ready-for-pr label, and it has no assignee or lists me as an assignee
  • I opened the pull request from a branch other than main in my fork
  • I selected "Allow edits from maintainers"
  • I did not edit files in dist/
  • I committed package-lock.json only for a dependency change
  • I added a file to draftlogs/ as draftlogs/README.md describes, or I will add one after the pull request opens

katosh added 11 commits December 3, 2026 23:13
A circle marker is a vectorized glyph mesh of 60 to 104 vertices, about
4,160 bytes in the vertex buffers. With scene.markerrender set to disc or
auto, circle and circle-open markers draw as one gl.POINTS vertex with a
round cutout in the fragment shader, with an outline ring for
marker.line.width. Other symbols, projections on the axes and sprites larger
than the point size limit keep the glyph path. The default is glyph, so
rendering does not change unless the attribute is set.

gl-scatter3d is pinned to a fork commit, and stackgl_modules/index.js is
rebuilt from it.
The value disc draws a glyph where a disc cannot draw the marker, and auto
is the same as disc for now. The first description left both out.
The next commits call drawStride, drawRange and lodCount of regl-scatter2d. No release has these calls. The pinned commit holds them on top of the typed positions of the base branch, with a built bundle.js and no build script, so npm installs it without a build. A regl-scatter2d release replaces this pin.
A restyle of visible does a calc of every trace and an upload of every point. An application that
hides one group of a large plot needs a faster path. scene.hidden[i] removes the markers of trace i
from each draw. scene.setHidden(map) sets entries and draws again, without a calc or an upload.
scene.visibleCount[i] replaces the point count of a trace for a caller that counts visible points.
Each calc empties the two arrays.
One full draw of tens of millions of points takes the GPU 0.3 s to 0.7 s. Each open, edit and pan
frame waits for that draw. With layout.lod.minpoints set, a draw shows every k-th point first. The
full picture follows layout.lod.settle ms after the last draw request, in parts of layout.lod.slice
points. A timer query paces the parts, so a new draw request waits for one part only. A copy of the
preview covers the canvas until the last part.

An edit of a fully drawn plot keeps the old full picture on screen until the new one is ready, in
state stale. layout.lod.edits: 'preview' gives edits the preview. The graph emits plotly_lod on each
change of state. Without layout.lod the draw calls and _fullLayout do not change.
Each frame of a rotation draws every scatter3d marker, and draws every marker again for the pick buffer. With scene.lod.minpoints set, a frame with a changed view draws every k-th disc marker and no pick pass. The scene draws every marker scene.lod.settle ms after the last change of the view, and the pick pass follows. scene.getLOD() returns the state, and the graph emits plotly_lod.

stackgl_modules/package.json pins gl-plot3d and gl-scatter3d to the fork commits of the two package pull requests. stackgl_modules/index.js is the webpack output of that install. A static scene gets no level of detail.
npm run schema wrote test/plot-schema.json and src/types/generated/schema.d.ts.
The level of detail commit carried an older wording of the scene.markerrender description. That text belongs to the disc marker change. This commit puts the description of the base branch back, with the schema output of npm run schema.
The other draftlog files start with the dash.
A preview of every k-th marker had one k-th of the cover of the full picture, so faint markers all but vanished in it. A marker of alpha a that stands for k markers now gets the alpha 1 - (1 - a)^k. This is exact where the k markers cover the same pixels, and an estimate elsewhere. A marker of alpha 1 does not change.

The change is in the two packages: this commit moves the pins of regl-scatter2d and gl-scatter3d, holds the webpack output for stackgl_modules, and adds one spec for scattergl and one for scatter3d.
virtual-webgl returns an object with constants and no functions for an extension that it does not wrap, also when the context has no such extension. The level of detail tested only that the object exists, and then threw in the timer that draws the full picture in parts. The full picture never came. The extension now counts as missing unless createQueryEXT and getQueryObjectEXT are functions, and the plot waits with readPixels after each part.

One spec passes such an object to the scene. The spec was not run on this machine before the commit.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant