Spec 031 asks for one Rust frontend graph engine over the existing WebGL renderer: layered, hierarchical, port- and route-aware, LOD-disciplined, and shared by graph exploration and flow editing (the flow editor’s move onto it is ADR-0018). This note maps every requirement onto what packages/graph-render (wasm, wgpu 30) and packages/editors/graph (Dioxus host) have today, proposes the smallest set of interfaces, and stages the work in testable steps. Nothing here rewrites the backend or touches storage, semantics or simulation.
1. What exists today
| Piece | File(s) | State |
|---|---|---|
| Wire format | graph.rs InGraph { nodes: Vec<InNode{id,label,kind,key,color}>, edges: Vec<InEdge{a,b,kind,color}> } | flat nodes + straight edges by index; JSON from the panel, incremental set_graph keeps ≥50 % shared positions (spec 017) |
| Internal graph | graph.rs Node { id, x, y, z, radius, color, degree, pinned }, Edge { a, b, color } | one instance per node; a == b filtered out (no self-loops); no ports, shapes, selection, hierarchy, layers |
| Layout | layout.rs FR + Barnes–Hut (quadtree.rs) | force-directed only; pinning exists (drag); 100 k nodes measured |
| Camera/picking | camera.rs | 2D/3D, hit = nearest node, CPU only; no edge/port picking, no GPU id buffer |
| Rendering | render.rs + shaders.wgsl | 2 instanced pipelines: SDF-circle node billboards, edge quads (straight, uniform width); depth buffer; alpha blend; instance buffers rebuilt and re-uploaded every frame |
| Labels | web.rs on a 2D-canvas overlay | importance-ordered, collision-tested, ≤ 400, LOD off above 20 k nodes |
| Rust API | scene.rs (Milestone 18) | Scene graph-in/events-out (hover/click/dblclick/settled), same protocol as wasm — the natural seam for extension |
| Interaction | web.rs | pan/zoom, node drag (id-stable since P-155), hover, click/dblclick, touch pinch, 3D orbit; no selection, multiselection, edge clicks, collapse |
| Host protocol | panel.rs eval script | commands setGraph/stash/unstash/fit/relayout/setMode/destroy; events ready/hover/click/dblclick/settled |
| Flow editor | editors/flow on dioxus-flow (DOM/SVG, ~1 k nodes, typed handles, layered auto-layout) | a second rendering stack — exactly what the spec asks to eventually unify, and what dioxus-flow recommended against unifying at Milestone 6 scale |
Key numbers to respect: 100 k nodes / 170 ms layout step native (Milestone 6 bench, bench.mjs); the engine must stay fluid at that scale after each stage.
2. Requirement → architecture mapping
§1 Architecture (input / scene / layout / render separation; instance ≠ semantic id).
The split already exists in embryo: InGraph (input) → Graph + Layout + Camera (scene, exposed as Scene) → Renderer (draw). Two changes, both additive:
- Instance vs entity: today
Node.idis both. AddInNode.entity: Option<String>— instances keep unique ids (trace[3],frame@main#2), the entity names what they reify (the same function appearing twice in a stack trace).set_graph’s incremental matching stays keyed on instance ids. - Styles/viewport vs topology: node/edge presentation fields (below) are data, never topology — the renderer already keeps camera state out of
Graph, and layers (§3) will follow the same rule: a layer hides or styles, it never removes.
§2 Visual primitives. All gaps; the renderer has circles and straight quads only.
- Shapes/stroke: extend the billboard SDF (circle → also rect, diamond, arbitrary convex polygon by per-instance shape id + half-extents); stroke = second SDF ring. Icons: draw on the existing 2D label overlay for hovered/selected/expanded nodes only (§6 forbids rich UI per node anyway).
- Ports: new
InPort { node, name, color, side, offset }; edges gaina_port/b_port. Ports are instances on the node pipeline plus independent hit targets (port_hit, next tocamera.hit). - Edges:
InEdgegrows optional fields —directed,width,dash,opacity,arrow,label,route: Straight | Bezier { tension } | Orthogonal { bends }. Internally one edge becomes N segment instances (route tessellation; straight stays N = 1) plus optional arrowhead instances on the glyph pipeline. Parallel edges: at build time, edges sharing a pair get a curvature fan-out by index. Self-loops: stop filteringa == b, render as a small circle route at the node’s rim. - Animated edges:
InPulse { edge, speed, color }→ shader-animated particles along the segment range (time uniform; no CPU per-frame cost). LOD-gated (§6). - Compound nodes: see §4.
§3 Layers. Nothing exists. InLayer { id, name, color, visible, overlay }; nodes/edges carry layers: Vec<String>. A shared edge drawn in two visible layers becomes two segment instances with a per-layer offset (parallel strokes) — built at frame-build time, so layers are pure presentation. Persistent vs temporary is host bookkeeping (an overlay layer can be dropped by id).
- Stack traces: an ordered occurrence walk, not an edge-id set:
InTrace { id, layer, steps: Vec<instance-id> }. The renderer draws it as one polyline + hop markers over the base graph — order and revisits survive by construction because each step is an occurrence instance (entity ids repeat, instance ids don’t).
§4 Hierarchy, grouping, zoom.
- Structural expansion is host-driven: the host sends the group’s internals or doesn’t (collapse = re-query with the group folded to one node). The renderer’s job is only to draw group hulls (
InGroup { id, members, label, collapsed }→ a rounded-rect fill instance) and to keepset_graph’s incremental positioning so a collapse/expand doesn’t scatter the map. Selection survives because selection is by instance id and the host keeps the group node’s id stable across the fold. - Visual aggregation is renderer-side LOD (§6 + the designed Case Selector coarse tier): below a pixel threshold, dense groups swap for aggregate nodes and bundled proxy edges. Substituting instances at frame-build time keeps this out of topology.
- Focal layouts:
fit-to-subset already exists in embryo (fit_bounds); addfocus { ids }that frames and centres on member bounds.
§5 Layout and interaction.
- Pluggable layouts:
Layoutbecomes an enum (Force, laterHierarchical);InNode.fixed: [f32; 2]opts a node out of any layout (spatial hardware layouts, §7, keep their coordinates — the layout must never move fixed nodes; today only pinned drags are respected). - Interaction: add selection (click = single, Ctrl = toggle, later marquee) as
HashSet<instance-id>in state +selectevents; edge and port picking via CPU distance tests over viewport-culled segments first (GPU id picking stays an option, see staged plan). - Modes over one renderer:
set_mode("explore" | "edit")onGraphView. Edit mode: ports snap the hover, a drag from port to port emitsconnect { from_port, to_port }, new wires route orthogonally, optional grid snap. The flow editor’s migration onto this is the final stage, not a prerequisite — dioxus-flow stays until parity (see staged plan).
§6 LOD and performance.
Today: label LOD, 2 px min node radius, iteration caps. Missing: the general rule. Add a Lod table computed from projected pixel size + per-tile density (quadtree exists) each frame: thresholds for ports, icons, edge labels, dashes, pulses, hull fills; below them, instances are not built (not merely hidden — never uploaded). Frustum-cull instances. Replace draw’s per-frame create_buffer_init with persistent buffers + partial write_buffer updates (positions change every layout step; styles rarely). Keep bench.mjs as the regression gate per stage.
§7 Domain compatibility. The wire format is the config surface: typed edges = kind + per-layer styles (RDF: one layer per predicate); call graphs = layers for call vs trace; flows = ports + orthogonal routes + edit mode; MTK/factor graphs = port sides + directed edges; hypergraphs/simplicial = InHyperedge { members, style: Junction | Region } and InSimplex { members } (junction = a small node + spokes, region = tinted hull — deliberately distinct instance classes so they can’t be conflated); spatial layouts = fixed positions. Validation/simulation stay in the domains, outside the renderer, as the spec demands.
3D. The renderer has a 3D mode (set_mode, orbit camera, kind planes). Everything this note adds is 2D-first: routes, ports, hulls, orthogonal edges and edit mode are 2D-only — in 3D every edge stays a straight quad between endpoints, groups show as their members, and edit mode is refused (the mode stays 2D while it is active). Straight segments and pulses work in both (a pulse travels the projected path).
Accessibility. A canvas graph is invisible to keyboards and screen readers today. Two minimums, tracked as requirements rather than a stage: keyboard focus moves between nodes (arrows/Tab over the instance order, Enter = click), and the selection is described in text (an aria-live line naming the selected nodes/edges, mirroring what the events already carry).
3. Minimal interfaces (proposal)
All wire additions are #[serde(default)], so the current panel — and every existing e2e suite — keeps working unchanged.
// graph.rs — the wire format grows, nothing breaks
pub struct InNode { .., entity: Option<String>, shape: Option<InShape>,
size: Option<[f32; 2]>, stroke: Option<InStroke>,
icon: Option<String>, fixed: Option<[f32; 2]>,
layers: Vec<String> }
pub struct InEdge { .., a_port: Option<String>, b_port: Option<String>,
directed: bool, width: Option<f32>, dash: Option<f32>,
opacity: Option<f32>, arrow: Option<InArrow>,
label: Option<String>, route: Option<InRoute>,
layers: Vec<String> }
pub struct InGraph { .., ports: Vec<InPort>, groups: Vec<InGroup>,
layers: Vec<InLayer>, traces: Vec<InTrace>,
hyperedges: Vec<InHyperedge>, simplices: Vec<InSimplex>,
pulses: Vec<InPulse> }
// frame.rs — new: pure, unit-testable scene → instance lists (LOD, culling,
// parallel fan-out, route tessellation, layer duplication all live here)
pub struct Frame { nodes: Vec<NodeInst>, segs: Vec<SegInst>,
glyphs: Vec<GlyphInst>, // arrowheads, ports, junction dots
fills: Vec<FillInst>, // hulls, simplex faces, regions
pulses: Vec<PulseInst> }
pub fn build_frame(graph: &Graph, pres: &Presentation, lod: &Lod) -> Frame
// scene.rs / web.rs — protocol additions
// in: set_layer_visibility, toggle_group, set_mode("explore"|"edit"), focus(ids)
// out: select { ids }, port_hover { node, port }, connect { from, to }render.rs then draws one pipeline per instance class and uploads ranges into persistent buffers. Native unit tests target build_frame (counts, fan-out geometry, LOD cutoffs) — the same style as the existing scene.rs/camera.rs tests — and graph3d.mjs/graph.mjs gain per-stage e2e steps.
Updates at scale: every update re-sends the whole graph as JSON today, which will not stay fluid at 100 k nodes under edit-mode-frequency changes. A delta form — add/remove/change by instance id, next to the incremental set_graph that matches whole graphs — belongs in the same command set; it is the wire-level twin of ADR-0015’s changes_since model and can be introduced per stage without changing the shapes above.
4. Staged plan
| Stage | Delivers | Acceptance | Tests |
|---|---|---|---|
| 0 — Persistent buffers | replace draw’s per-frame create_buffer_init with persistent buffers + partial write_buffer updates (positions change every layout step, styles rarely) | none by itself, but it removes today’s per-frame cost at 100 k and depends on nothing else — do it first and measure | Done 2026-10-08: geometry/appearance split per pipeline, revision-gated uploads; bench-draw.mjs (new) on SwiftShader: settling 1.91 → 1.14 ms/frame, hover 1.88 → 0.89 ms; graph, graph-local, graph3d suites pass |
| 1 — Edges & selection | segment instances, width/dash/opacity/arrow, parallel fan-out, self-loops, edge labels on hover, CPU edge/port-free picking, selection + select events | §8.1 (partly: edges selectable), §8.2 (routes minus orthogonal) | Done 2026-10-08: frame.rs (build_frame + edge_at, 8 native tests), three pipelines (segments with width/dash, arrowheads, nodes), id-based selection with select events and a drag guard; graph-edges.mjs picks parallels apart, toggles with Ctrl, drags nothing, picks a self-loop; a naga shader-validation test gates WGSL typos natively. Edge hover labels wait for the panel’s popup work |
| 2 — Ports & edit mode | InPort, port hit targets, set_interaction("edit") (set_mode stays 2D/3D), connect gesture + connect event | §8.1 (ports), §8.7 (mode switch on the same renderer) | Done 2026-10-09: ports draw on the node pipeline (edit mode), edges anchor at ports (stale names fall back to the node), Drag::Wire emits connect — the host adds the edge, never the renderer; 4 native tests, graph-edit.mjs (ports only in edit, camera preserved, connect + cancel); all five graph suites pass |
| 3 — Layers & traces | InLayer visibility/commands, offset parallel strokes, InTrace ordered walks, overlays | §8.3 | Done 2026-10-09: shared edges draw one offset stroke per visible layer, traces walk node ids in order with a head per hop (never picked), hidden layers drop their strokes/nodes and answer no hits; 4 native tests + graph-layers.mjs (both layers on: 21 segments, 4 heads; toggles remove exactly each layer’s share); all six graph suites pass |
| 4a — Delta updates | add/remove by instance id next to the whole-graph set_graph — the wire-level twin of ADR-0015’s changes_since, split out of stage 4 so collapse/expand (4b) never re-sends 100 k nodes | keeps the incremental-set contract: ids/selection/camera survive, a removed node’s edges go, an edge naming a missing node waits for it | Done 2026-10-09: InDelta {add_nodes, remove_nodes, add_edges, remove_edges} (endpoints by node id, not index), Graph::apply_delta (survivor remap, re-addable idempotence, recompute_degrees + with_bows re-run), GraphView::apply_delta(json) warms the layout at temperature 3 without touching the camera; 4 native tests + graph-delta.mjs (a collapse keeps counts/camera/selection, a missing endpoint waits, the expand restores); all seven graph suites pass |
| 4 — Groups & LOD | group hulls, collapse/expand via host + incremental set_graph, LOD table (ports/icons/labels/dashes/pulses), frustum culling, focus | §8.5, §8.6 | Done 2026-10-09 (4b, on top of 4a’s deltas): InGroup (members by node id, tint, visible) on the wire format and in InDelta (add_groups/remove_groups — a collapse re-sends its group with the aggregate among the members); a 4th pipeline draws one rounded-rect SDF hull per group behind everything (tint HULL_FILL + a rim stroke); focus(ids) fits to a subset and ends auto-fit. LOD is shader-side so zooming never rebuilds: ports discard below a 2.5 px projected radius, dashes go solid under a 6 px sub-segment, hulls fade out between 6–14 px of half-extent. graph-groups.mjs pixel-checks the nested/overlapping tints by hue, the collapse/expand through apply_delta (counts, camera, selection, hulls), focus, and all three LOD gates; bench at 100k: settle 4.66 ms/frame, hover 0.92 (was 4.37/0.82 — the wider node-attr slot; both far under the 16 ms budget). Still open from the stage’s letter: frustum culling and the general Lod table for icons/labels (labels already LOD); pulses come with stage 6 |
| 5 — Higher-order | hyperedge junctions/regions, simplices, clique hulls | §8.4 | Done 2026-10-09: InHyperedge (a junction: marker at the centroid + spokes, never picked as edges), InSimplex (a filled triangle, fanned for more, on a 5th TriangleList pipeline behind the edges), and InGroup.highlight (a clique = a visual membership over the hull mechanism, twice the tint + a 0.9 rim) — three wire-distinct classes; deltas carry all of them by id with member remap. graph-higher.mjs shows all four §8.4 items as hue-exclusive pixel checks and removes/re-adds each class independently; bench idle 100k: settle 4.20 ms, hover 0.92. Region-style hyperedges (the enclosing form) stay open — the junction reads for low-degree cases |
| 6 — Pulses | shader-animated edge particles, LOD-gated | §8.2 (variable speed) | Done 2026-10-09: InEdge.pulse_speed (also in deltas) moves a Gaussian glow along the stroke in the segment shader — no new instances, no CPU uploads; the vertex positions it over the stroke’s length, the fragment brightens by interpolated world distance, sub-8-px segments stop (§6). camera.time (the uniform’s former pad slot) drives it; a view with pulsed edges redraws every frame (animates). graph-pulse.mjs measures the brightness peak’s displacement at two speeds and the LOD stop; the fragment-visibility trap is P-162 |
| 7 — Flow migration | hierarchical layout, orthogonal routing, port-typed wiring parity — including parameter editing: an HTML editor shown only for the selected node, positioned from Scene::screen_position (the spec forbids rich per-node UI). The flow editor drives the wgpu engine in edit mode; dioxus-flow retired | §8.7 complete | flow.mjs rewritten against the engine; only then does the second stack die. 7a done 2026-10-09: the engine’s flow primitives — rect block nodes (shape/width/height, a circle ignores the height field), ports on the rect’s sides, Route::Ortho step wires (3 square-cornered segments, parallels step apart), hier_layout (ranks → columns/rows, all pinned — the document owns positions) + node_positions() harvest; graph-flow.mjs (3 segments/wire, the block’s lit box wider than tall, side ports in edit, left-to-right arrangement, harvest, click-selects); 3 native tests. 7b done 2026-10-09: the flow panel hosts the engine (dioxus-flow removed from its Cargo.toml) — to_scene turns blocks into pinned rect nodes with typed ports and ortho wires, connect is validated in the panel (unify, one wire per input, a refusal re-pushes without the wire), moved harvests coordinates, one HTML parameter editor for the selected block (§7), the panel refits when the scene grows beyond the fitted box, and the fit carries node rims (bounds_with_rims — a block’s half-width put the outer ports off the canvas, where a drag caught the workspace splitter, P-168); flow.mjs rewritten against the engine (palette single-fire, port drags, Layout, Save, Generate, Lux disable, broken-file guard). Remaining parity for 7c: undo, the parameter editor positioned from the canvas, then the dioxus-flow remnants go. 7c done 2026-10-09: undo/redo as document-JSON snapshots (Ctrl+Z/Y, a field’s Ctrl+Z stays its native text undo, spec 001), the parameter editor floating beside its block (the engine’s select/moved now carry screen positions — a host cannot call back into the view from inside an event, the state borrow is held; that also fixed drag-end moved, which 7b never exercised and which panicked), a pinned node with pos is the host’s to move on an incremental set_graph (undo restores coordinates on the canvas), the last dioxus-flow CSS remnants deleted, and the flow panel’s keys work after a canvas click (the engine’s overlay pointerdown prevents the focus — the host focuses it in the capture phase). Stage 7 is complete: dioxus-flow is fully retired |
| 8 — §2 presentation gaps | the diamond shape, a host stroke, node icons (the acceptance list’s “shapes/sizes/colors/icons”), partial buffer updates | §8.1 complete (icons) | Done 2026-10-09: shape: "diamond" (the third silhouette, half-extents and side ports like a rect, the rhombus leaves the extent box’s corners dark), stroke (a ~2 px band inside the rim — a band on the rim blends with the fading alpha; selection’s light ring wins over styling) and icon (a glyph on the label overlay, hovered/selected only, §6; the ink contrasts the node’s own fill — a hovered node is white); all carried by deltas, absent keeps the old one. Perf (P-170): the icon scan is gated on has_icons, a packed-u32 attribute was slower than 52 B f32 on GL, and a hover now patches two instance slots instead of re-uploading the appearance buffer — hover at 100 k: 0.97 → 0.29 ms/frame, better than before the stage. graph-shapes.mjs pixel-checks the rhombus, both strokes and the icon’s hover lifecycle |
| 9 — Edge labels | InEdge.label renders on hover (§2’s “labels and clickability”; stage 1 deferred it to “the panel’s popup work”) | §2 complete for edges | Done 2026-10-09: a pointer over a stroke (a node hover wins) scans the cached frame with edge_at and draws the edge’s label beside the pointer on the overlay, inked in the edge’s colour; the scan is gated on has_edge_labels (one pass over every segment per move — a 100 k graph without labels pays nothing). The session’s real find (P-171): dx served the engine one build behind — the asset URL hash never recompiled with the wasm — fixed by keying the asset crate on the engine bytes via build.rs; until then several probes measured a binary without the feature. graph-edges.mjs checks the label’s appearance and that it leaves with the hover |
| 10 — Accessibility | the two minimums from this note’s own requirement list: keyboard node navigation, and the selection described in text | a keyboard user can walk and select the map; a screen reader hears the selection | Done 2026-10-09: the overlay takes a tabindex (the engine’s own, with a capture-phase pointerdown focus — the pointerdown prevents the default), the arrows walk spatially (nearest_in_direction, a 45° cone with distance-vs-angle weighting; nothing focused → the walk starts from node 0 so the first arrow moves), Enter selects and emits click, Escape clears, Tab is not consumed (a canvas must not trap it). The focus is id-keyed, ring-drawn on the overlay, emits focus { id }; Graph::visible now carries the layer check. The panel narrates selection + focus through an aria-live span in all three locales. graph-a11y.mjs (the 16th suite) checks the walk, the ring, Enter/Escape and the narration |
Order notes: stages 1–3 are additive and independently shippable; 4 is where performance work lands (it gates 5–6 visually); 7 is the only stage that removes code and is explicitly gated on a parity checklist (ports, typed validation hooks, layered layout, undo are the flow editor’s today — Flow Editor phase list). GPU id-picking is deliberately not scheduled: CPU picking over culled segments is O(visible), and the pick-buffer only wins if measurements say otherwise (Graph Rendering Options lists it; decide with data).
Review pass (2026-10-09, P-159). Claude’s review of stages 0–3 found ten defects — every arrowhead pointed screen-right (shape-space and NDC-angle bugs), two-way links overdraw each other, a wire drag panicked across graph swaps, the pending wire drew from an unwritten style slot, a shared curve doubled its own bow, 3D switches left heads at old positions, dashes restarted per sub-segment, touch taps stopped opening notes, negative-bow loops floated off their nodes, port-anchored heads hid under their nodes — all fixed with geometry or pixel tests (pnglit.mjs decodes screenshots), plus the hover/selection revision split and buffer reuse in build_frame_into.
Review pass (2026-10-09, P-166). Claude’s review of stages 4a–6 confirmed two bugs — count-preserving deltas never redrew (the collapse kept five equal counts; apply_delta now reports whether anything changed, and the delta e2e pixel-checks the picture) and the stale-index drag crash was back across deltas (re-homed via dragged_id/keep_drag) — and eight candidates that all proved real: a lone edge kept its dead partner’s bow, the pulse measured 3D length over a 2D phase, the dash/pulse LOD gates read a curve’s sub-segments instead of the stroke, hyperedge spokes and simplex faces reached layer-hidden nodes, a replace without pos teleported the node, id lookups were linear (one owned HashMap per call now), focus did nothing in 3D (shared Camera::fit_rect), and the stroke-length pass ran for every edge on every layout step (gated to pulsed/dashed strokes).
Decided with the spec’s registration: stage 7 is in — the flow editor moves onto this engine and dioxus-flow is gradually replaced, because we do not own that repository and cannot make the substantial changes the spec needs (ADR-0018). Still to confirm along the way: whether hulls/regions are worth their own pipeline early, or wait for stage 5. The specification is registered as 031; the mapping above was written against it section by section.