r/webdev • u/ice1905 • 12h ago
[Showoff Saturday] A rotatable map of 8,207 chess positions, drawn on a plain 2D canvas
I built Theoria, a map of every named chess opening: https://theoria.up.railway.app
Each dot is a position and each line a move, so a frame has about 8,200 nodes and 8,400 edges, plus labels. Some details that might interest people here:
- Stack: Next.js App Router, Neo4j for the position graph, deployed on Railway.
- One payload: a single API route returns the whole graph as parallel arrays (key, depth, x, y, parent, move, family, name). The layout is computed on the server and cached per data revision.
- Batching: edges and dots are grouped into Path2D objects by colour and highlight level, so the whole graph is drawn with a small number of stroke and fill calls instead of one per node.
- 3D without WebGL: an orthographic projection with yaw and pitch, where depth becomes a shallow bowl. Plain drag pans; right-drag, Alt-drag or Shift+arrow keys rotate.
- Picking: brute-force hit-testing over the projected points. At 8k points it's cheap enough on every mouse move.
- A bug worth sharing: React Strict Mode's double mount in development cancelled my requestAnimationFrame but didn't reset the stored frame id, so the canvas stayed blank in dev only. Resetting the id in the effect cleanup fixed it.
Feedback on performance is welcome, especially from low-end laptops and phones.