Skip to main content

Module graphlayout

Module graphlayout 

Source
Expand description

Deterministic force-directed layout for the /graph/ view.

Consumes the already-built crate::graph::LinkGraph (wikilink edges) plus per-doc (slug, title) metadata and runs a fixed-iteration spring layout in pure Rust to produce stable 2D node positions. No RNG, no clock, no HashMap iteration in the hot loop: index-ordered Vecs + a BTreeMap for slug lookups built once.

§Cross-platform determinism

The only transcendental operations in the whole pipeline are the sin/cos in [seed_point]; everything after seeding is + - * / sqrt, all of which are IEEE-754 correctly-rounded and therefore identical on every platform. sin/cos, however, are NOT guaranteed correctly-rounded across libm implementations (glibc/musl/macOS/Windows can differ by ~1 ULP). To keep the whole layout byte-identical across machines, [seed_point] quantizes its output to a fixed 2-decimal grid: a sub-ULP libm difference cannot survive that rounding, so the seeds — and hence the entire deterministic force loop fed only by correctly-rounded ops — are platform-independent. Given the same inputs, layout_graph produces byte-identical output across runs and machines (locked by the golden_* snapshot tests below).

Structs§

GraphData
The serializable layout result embedded in /graph/ and consumed by the island.
GraphDataEdge
One graph edge (undirected for display; carries the directed slugs).
GraphNode
One laid-out graph node: a doc plus its 2D position and link degree.
LayoutParams
Fixed layout parameters. LayoutParams::default is the canonical, tested seed.

Functions§

graph_data_json
Serialize GraphData to compact JSON (stable key order via serde derive).
layout_graph
Deterministic force-directed layout. nodes_meta: (slug, title) in a STABLE order (doc input order). graph: the already-built LinkGraph. Returns a GraphData with positions clamped inside [padding, width-padding] x [padding, height-padding].