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§
- Graph
Data - The serializable layout result embedded in
/graph/and consumed by the island. - Graph
Data Edge - One graph edge (undirected for display; carries the directed slugs).
- Graph
Node - One laid-out graph node: a doc plus its 2D position and link degree.
- Layout
Params - Fixed layout parameters.
LayoutParams::defaultis the canonical, tested seed.
Functions§
- graph_
data_ json - Serialize
GraphDatato 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-builtLinkGraph. Returns aGraphDatawith positions clamped inside[padding, width-padding] x [padding, height-padding].