Skip to content

feat: improve sketch order with checked joint placement - #134

Merged
ViktorMikhalkin merged 24 commits into
mainfrom
loop/issue-125
Nov 30, 2026
Merged

ViktorMikhalkin merged 24 commits into
mainfrom
loop/issue-125

Conversation

@ViktorMikhalkin

Copy link
Copy Markdown
Contributor

What changes for users

Preferred sketch pins retain more of the author's order and move boxes closer to their intended positions. ELK and dagre compare the existing final drawing with one certified placement over both axes. They select the joint proposal only when raw and refined hard defects and crossings, within-rank order and rank order do not worsen, with at least one improvement. When those counts tie, lower pin distance or fewer bends can decide. Natural drawings also keep their existing bend ceiling.

The selected drawing keeps its reserved label geometry. Exact pins, hand geometry, the map format and the public API retain their contracts. Joint selection loads only for preferred sketches.

Why

Separate axis optima can disagree after routing. The joint problem combines required lanes, pins and forward-arrow gaps with sketch rank groups and order within and between ranks. Coordinates fixed by both bounds are removed before optimisation and counted. The optimiser balances pin distance and weighted arrow straightness, then checks one primal/dual and complementary-slackness certificate against the routed placement. It routes the proposal once.

A certificate does not prove drawing quality. Independent measurements compare the actual existing and joint drawings after the width pass, with the existing drawing as fallback. Each evidence report records the selected variant, reason, decisive measurements and fixed/free counts. Contradiction diagnostics include both proposals and suppress equivalent cycle rotations while preserving the first witness's order.

Evidence

  • npm run verify: 165 files and 1,410 tests pass, including the new public selection and score-guard tests. All dependency, schema, API, complexity, packaging and build checks pass.
  • npm run format:check and npm run size pass after adding the separate joint-selection budget. All 11 budgets pass. Existing limits are unchanged. Reported first downloads: component 32.79 → 32.98 kB gzip; layout 24.22 → 24.43 kB; player unchanged. The new standalone on-demand entry is 32,233 B with a 33,199 B limit, including shared code.
  • npx playwright test --project=chromium: all 176 tests pass. The related sketch and element-loading run also passes all 12 tests. Firefox and WebKit remain CI checks, as required for this browser-independent change.
  • All four sketch scorers pass. The 96 refreshed reports contain one report per map and one summary per engine/width, at most 79 lines each. Joint proposals are selected on 2 natural ELK maps, 13 narrow ELK maps, 1 natural dagre map and 15 narrow dagre maps. Every rejected map retains its previous drawing exactly.
  • The contradiction trace passes its exact public-callback comparison on all 46 map/engine combinations. Its updated per-map reports stay below 500 lines.
  • Before/after pictures are retained outside the repository for the author. Browser probes checked the saved drawings at their intended width and the normal source resize flow at 1280 and 390 px. Source-flow probes found no added checker contacts, crossings or horizontal overflow. Existing node-text crowding on large narrow dagre maps remains visible.

Scores below are before → after. Within-rank agreement is out of 114 pairs; rank agreement is out of 1,559. Distance is the mean translated distance per pinned box. Other figures are collection totals.

Engine / width Within rank Rank Distance Hard defects Crossings Bends
ELK / natural 103 → 103 1421 → 1440 168.45 → 164.63 0 → 0 0 → 0 526 → 506
ELK / 39 em 89 → 99 1401 → 1432 250.84 → 217.55 0 → 0 0 → 0 800 → 550
dagre / natural 64 → 64 1289 → 1289 220.35 → 220.23 8 → 8 6 → 6 154 → 154
dagre / 39 em 53 → 79 1266 → 1293 431.08 → 226.40 15 → 7 9 → 8 164 → 251

The narrow dagre bend increase is allowed by its guarded order and defect improvements. CI now runs all four scorers and protects these measured levels; the original natural ELK guards remain unchanged. No quality-checker threshold, band or complexity exception changes.

Reproduce the score reports with:

npm run build
for engine in elk dagre; do
  node scripts/sketches/score.mjs "docs/evidence/sketches/solver/$engine/raw" "$engine"
  node scripts/sketches/score.mjs "docs/evidence/sketches/solver/$engine/narrow" "$engine" 39
done
node scripts/sketches/trace-contradictions.mjs

Not done

  • The 90% within-rank target remains unmet for narrow ELK (86.84%) and dagre at both widths (56.14% and 69.30%). Dagre retains the defects and crossings shown above.
  • Shared-channel spacing can add crossings to otherwise certified placements: diagnosed dagre map 0-1 increases from 2 to 8, and 1-3 from 0 to 2. Consistent shared-track ordering is the next step for a separate issue.
  • Existing narrow node-text crowding on large dagre maps remains. Saved geometry also needs a new width-aware layout when its available width changes; a frozen 39 em map is not the source resize flow.
  • ELK's interactive starting options and the existing fallback remain. A fallback drawing is not claimed to be a joint optimum. Pin and arrow multipliers remain 1/1; no new weight-grid search was performed.

Changelog

BEGIN_COMMIT_OVERRIDE
feat: improve sketch order with checked joint placement
END_COMMIT_OVERRIDE

@ViktorMikhalkin
ViktorMikhalkin marked this pull request as ready for review November 30, 2026 22:10
@ViktorMikhalkin
ViktorMikhalkin merged commit f8a7510 into main Nov 30, 2026
8 checks passed
@ViktorMikhalkin
ViktorMikhalkin deleted the loop/issue-125 branch November 30, 2026 22:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant