Off-Main-Thread Solving + 60 FPS Canvas 2D Rendering
When a dataset grows beyond a few hundred interactive SVG nodes into thousands of records, two bottlenecks emerge in browser apps: running iterative QAP annealing and PBD collision relaxation synchronously on the UI thread, and mutating thousands of DOM/SVG elements during pan and zoom.
This example pairs @simplex-viz/core/worker with @simplex-viz/canvas to keep the main thread completely fluid across 1,000, 2,000, and 3,500 stars modeled on the Morgan–Keenan / Hertzsprung–Russell (H–R) spectral sequence and evolutionary branches (O–M Main Sequence, Red Giants, Yellow & Red Supergiants, Hot White Dwarfs, and Halo Subdwarfs).
Architecture Highlights
- Zero-Copy Worker Handoff (
createSimplexWorkerClient+attachSimplexWorkerHandler): Each star carries an 8D astrophysicalFloat32Arrayembedding (log Teff,log L,log R,log M,B−V,[Fe/H],log Age,log g). WithtransferEmbeddings: true,SimplexWorkerClienttransfers standaloneArrayBuffers across the Worker boundary without JSON cloning, solves the full 12-cluster Soft-Simplex triangulation off-thread, and rehydrates your original main-threadStellarRecordobjects on return. - Automatic Stale-Generation Cancellation: Toggle rapidly between
1,000,2,000, and3,500stars in the bottom bar—cancelPreviousByDefault: truesupersedes earlier in-flight generations automatically while keeping the previous Canvas snapshot interactive at 60 FPS until the newest snapshot settles. - Frustum Culling & Automatic Level-of-Detail (
CanvasRendererAdapter): At overview magnification,lodThresholdPx: 3.5collapses sub-threshold stars into single-pass flat fills; as you zoom smoothly (wheel, pinch, double-click, or−/+stepper) or click a cluster badge or simplex triangle to frame it, visible stars upgrade to full geometric shapes (circles for core stars, diamonds for 2-population bridges, and stars for 3-cluster hybrids) while off-screen stars are culled before touching the Canvas 2D context. - Zero-Relayout Cluster & Star Inspection: Clicking a cluster badge frames that stellar population and opens its Cluster Inspector (core vs. hybrid breakdown and representative stars); clicking any star inspects its astrophysical parameters and barycentric simplex weights inside the container-query side drawer without altering the Canvas stage dimensions or triggering a worker re-solve.