ADR-0014 — Density presets and dynamic layout metrics
Replace hardcoded node dimensions, port chips, and ELK spacing with density presets and an optional scaling multiplier.
Status: accepted
Node dimensions, port chip sizes, font metrics tables, and ELK layer spacing were previously hardcoded constants in compiler code. Marrow now introduces high-level density presets (compact, standard, spacious) and an optional numeric scale multiplier in the topology header and marrow.config.yaml.
Why
High-density fabrics (such as data center spines with 100+ switches) produced excessive canvas footprints when rendered with standard node boxes and layer spacing. Conversely, presentation slides and kiosk screens required larger node chips and bolder typography.
Manual node sizing in YAML was considered and rejected. Exposing manual width and height coordinates per device violates ADR-0001 (declare structure, not layout), breaks libavoid edge routing channels, and triggers geometry linter collisions.
Applying post-render CSS scale transforms on the container was also rejected. CSS scaling zooms entire viewports without adjusting internal gutter routing clearance, port chip collision boundaries, or text bounding boxes.
A centralized layout metrics engine in @marrow/layout (metrics.ts) resolves presets prior to node placement. The engine calculates icon chip dimensions (48 px, 64 px, 80 px), font sizes (10 px, 12 px, 14 px), ELK layer spacing (60 px, 88 px, 116 px), and zone padding dynamically before running ELK and libavoid. The resolved metrics are propagated to SceneNode.labelSize and scene metadata to synchronize both SVG and Canvas 2D engines.
Consequences
Configurable compactness. Topologies can declare density: compact to reduce overall diagram surface area by up to 45% while preserving readable text hierarchy.
Strict determinism preserved. Geometry linter checks remain fully deterministic and overlap-free across all density presets and scale factors.
Multi-page consistency. Multi-page site generation carries density and scale settings across overview, zone, and device sub-views.
Considered and rejected
Per-device width and height coordinates. Rejected because manual dimensions conflict with automated layout classification and destroy routing determinism.
Pure CSS zoom transforms. Rejected because CSS transforms fail to recalculate cable routing gutters, port chip clearance, and collision boxes.