Skip to content

fix(layout): Harden layout internals, edge overlay keys, and WASM forceIterations#140

Merged
mhiro2 merged 3 commits intomainfrom
fix/layout-review
May 3, 2026
Merged

fix(layout): Harden layout internals, edge overlay keys, and WASM forceIterations#140
mhiro2 merged 3 commits intomainfrom
fix/layout-review

Conversation

@mhiro2
Copy link
Copy Markdown
Owner

@mhiro2 mhiro2 commented May 3, 2026

Summary

  • Smooth out the auto-tuned density-factor curve and remove the saturating ceiling on excess_ratio so the compaction response stays continuous and keeps reacting past 2x the threshold.
  • Speed up component-graph construction with HashSet-based dedup, replace silent unwrap_or_default calls in the SCC pass with descriptive expects, and precompute per-node radii so the spatial-grid repulsion no longer redoes spacing math per pair.
  • Wire the obstacle-aware self-loop detour to the actual node extent so the endpoint anchor distance can be clamped on small nodes.
  • Replace the collision-prone from->to string key in DiagramOverlay::edges with an explicit EdgeKey { from, to } tuple, and reject duplicate entries during deserialization.
  • Plumb forceIterations through WasmRenderRequest / WasmDiffRequest with positive-and-bounded validation so JS callers can finally tune the force-directed layout safely.
  • Add a property-based routing test and document the Mermaid v10 quoted-entity requirement.

Changes

  • 70d7f72 : refactor(layout): tighten layout, rank, and routing internals
    • Make the density factor continuous at the 1.0 / 2.0 thresholds and stop saturating excess_ratio, so compaction stays responsive on large graphs.
    • Replace the O(C^2) component-adjacency contains check with a HashSet, promote SCC unwrap_or_default to descriptive expect so invariant violations surface immediately, and hoist node radii out of the per-pair repulsion hot loop.
    • Thread node sizes into the self-loop detour, add a property-based routing test (covering 96 random configurations), and document the Mermaid v10 quoted-entity requirement.
  • e7c967b : fix(layout): key edge overlays by an explicit (from, to) tuple
    • Replace BTreeMap<String, EdgeOverlay> keyed by format!(\"{from}->{to}\") with BTreeMap<EdgeKey, EdgeOverlay> so identifiers that contain -> no longer collide.
    • Serialize the edge map as a list of {from, to, overlay} entries and reject duplicate entries on the way back in.
  • 2a58355 : feat(wasm): respect forceIterations override from JS
    • Plumb the forceIterations request field through to_render_request / to_diff_request instead of pinning it to 150.
    • Validate the override against a positive lower bound and a 10000 upper bound so a runaway value can't freeze the host thread, and document the option on the public render/diff entry points.

mhiro2 added 3 commits May 3, 2026 10:36
- Smooth the auto-tuned density factor so it stays continuous across
  the density==1.0 and density==2.0 thresholds.
- Drop the saturating ceiling on excess_ratio so the compaction curve
  keeps responding past 2x the threshold.
- Precompute per-node radii once and reuse them inside the spatial
  grid repulsion loop instead of re-deriving spacing per pair.
- Wire the obstacle-aware self-loop detour to the actual node extent
  so the endpoint anchor distance can be clamped on small nodes.
- Replace the O(C^2) component adjacency contains-check in rank
  assignment with a HashSet-based dedup.
- Promote the SCC unwrap_or_default sites to descriptive expects so
  invariant violations surface immediately instead of silently zeroing
  state.
- Add a property-based routing test and document the Mermaid v10
  quoted-entity requirement.
Edge identifiers can themselves contain "->" characters, which made
the previous `format!("{from}->{to}")` map key collision-prone:
("a", "b->c") and ("a->b", "c") flattened to the same string.

Replace the `String` map key with a `EdgeKey { from, to }` struct.
Because JSON map keys must be strings, serialize/deserialize the
edge map through a `Vec<{from, to, overlay}>` and reject duplicate
entries on the way back in.
The `forceIterations` field was previously hardcoded to 150 inside
`to_render_request` / `to_diff_request`, so JS callers had no way to
tune the force-directed layout from the WASM API. Plumb the request
field through, validate it against a positive lower bound and a
10000 upper bound (so a runaway value can't freeze the host
thread), and document the option on the public render/diff entry
points.
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 3, 2026

Code Metrics Report

main (d1858b4) #140 (dad45cd) +/-
Coverage 94.9% 94.9% +0.0%
Test Execution Time 1m26s 1m35s +9s
Details
  |                     | main (d1858b4) | #140 (dad45cd) |  +/-  |
  |---------------------|----------------|----------------|-------|
+ | Coverage            |          94.9% |          94.9% | +0.0% |
  |   Files             |             81 |             81 |     0 |
  |   Lines             |          39248 |          39477 |  +229 |
+ |   Covered           |          37253 |          37479 |  +226 |
- | Test Execution Time |          1m26s |          1m35s |   +9s |

Code coverage of files in pull request scope (94.6% → 94.8%)

Files Coverage +/- Status
crates/relune-layout/src/diagram_export.rs 94.1% 0.0% modified
crates/relune-layout/src/layout.rs 95.7% -0.1% modified
crates/relune-layout/src/overlay.rs 99.4% +0.3% modified
crates/relune-layout/src/rank.rs 98.4% +0.0% modified
crates/relune-layout/src/route/geometry.rs 95.6% +1.6% affected
crates/relune-layout/src/route/mod.rs 99.0% +0.3% modified
crates/relune-layout/src/route/obstacle.rs 93.6% +0.1% modified
crates/relune-render-html/src/metadata.rs 98.1% +0.0% modified
crates/relune-wasm/src/lib.rs 4.7% -0.1% modified
crates/relune-wasm/src/request.rs 98.5% +0.1% modified

Reported by octocov

@mhiro2 mhiro2 self-assigned this May 3, 2026
@mhiro2 mhiro2 added the enhancement New feature or request label May 3, 2026
@mhiro2 mhiro2 merged commit 60ca6a6 into main May 3, 2026
4 checks passed
@mhiro2 mhiro2 deleted the fix/layout-review branch May 3, 2026 01:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant