Skip to content

elk: expose edgeEdgeBetweenLayers spacing - #2887

Merged
alixander merged 3 commits into
d2lang:masterfrom
jonapoul:elk-edge-edge-spacing
Oct 11, 2026
Merged

alixander merged 3 commits into
d2lang:masterfrom
jonapoul:elk-edge-edge-spacing

Conversation

@jonapoul

@jonapoul jonapoul commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

ELK's edgeEdgeBetweenLayers spacing is hardcoded to 50, so there's no way to change it.

Every edge between two layers gets its own routing slot, and each slot adds this much space. So the more links you have between two layers, the further apart ELK pushes them. Lowering --elk-nodeNodeBetweenLayers doesn't help, because it only sets a minimum. Especially noticeable in tall charts like #1221 (comment).

This adds a --elk-edgeEdgeBetweenLayers flag, next to the other four spacing flags. The default stays 50, so nothing changes unless you pass it. ELK's own default is 10, for reference.

Related to #1221.

edgeEdgeBetweenLayers=10 edgeEdgeBetweenLayers=50 (default) edgeEdgeBetweenLayers=100
spacing-10 spacing-50 spacing-100

@jonapoul
jonapoul force-pushed the elk-edge-edge-spacing branch from 06c4493 to 55977f5 Compare September 15, 2026 13:27
@jonapoul jonapoul changed the title Expose ELK edgeEdgeBetweenLayers spacing elk: expose edgeEdgeBetweenLayers spacing Sep 15, 2026

@alixander alixander left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found one compatibility regression for existing Go API callers: omitting the newly added option changes edge spacing from 50 to 0 and causes unrelated edge segments to overlap. Please preserve the previous default for callers that do not explicitly configure the new option.

Validation at 55977f5: native ELK and CLI test suites passed, selected rendering tests passed (sanity, stable, root, unicode, and themes), and targeted WASM option/profile tests passed. The regression was confirmed by running the same Go program against the PR head and the merge-base layout implementation.

  • sent from alixander's Codex

Comment thread d2layouts/d2elklayout/layout.go Outdated
EdgeEdgeSpacing is a *int, so nil means unset and resolves to the 50 D2
sent before the option existed, while an explicit 0 still reaches ELK.
@jonapoul
jonapoul requested a review from alixander September 20, 2026 15:09
Returning the caller's pointer shared storage with DefaultOpts, and Layout
unmarshals ELK output back through it, racing across concurrent layouts.

@alixander alixander left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both review findings are resolved: omitted spacing preserves the previous value of 50, explicit zero is honored, and each layout receives its own copy of the spacing value. No further issues found in the final diff.

The final layout implementation matches the local fix that passed the earlier parallel race test. A fresh test run was blocked during compilation by insufficient local disk space.

  • sent from alixander's Codex

@alixander
alixander merged commit 03735a7 into d2lang:master Oct 11, 2026
13 checks passed
@jonapoul
jonapoul deleted the elk-edge-edge-spacing branch October 11, 2026 19:56
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.

2 participants