Skip to content

Expose ELK edgeEdgeBetweenLayers spacing - #2887

Open
jonapoul wants to merge 2 commits into
d2lang:masterfrom
jonapoul:elk-edge-edge-spacing
Open

Expose ELK edgeEdgeBetweenLayers spacing#2887
jonapoul wants to merge 2 commits into
d2lang:masterfrom
jonapoul:elk-edge-edge-spacing

Conversation

@jonapoul

@jonapoul jonapoul commented Sep 8, 2026

Copy link
Copy Markdown

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).

On a 6x6 graph with 36 edges between two layers:

--elk-edgeEdgeBetweenLayers height
10 724
25 1189
50 (current) 2164
100 3414

elk-go's own default is 10, for reference.

This adds a --elk-edgeEdgeBetweenLayers flag, next to the other four spacing flags. The default stays 50, so nothing changes unless you pass it.

The field had to move onto ConfigurableOpts rather than be copied, because elkOpts embeds ConfigurableOpts and would otherwise shadow it and keep the old hardcoded value.

Related to #1221.

The spacing between edges routed between the same pair of layers was
hardcoded to 50 in elkOpts, so it could not be configured from the CLI.

ELK gives every connector crossing between two layers its own routing
slot, and the orthogonal router sizes the gap as
max(nodeNodeBetweenLayers, (slots-1)*edgeEdgeBetweenLayers +
2*edgeNodeBetweenLayers). On a wide graph with many links between
adjacent layers the first term stops mattering, so layers get pushed far
apart with no way to pull them back. ELK's own default for this option
is 10.

Move the field onto ConfigurableOpts and add --elk-edgeEdgeBetweenLayers
alongside the other four spacing flags. It has to move rather than be
duplicated: elkOpts embeds ConfigurableOpts, so a depth-0 field with the
same tag would shadow the embedded one and keep the hardcoded value. The
default stays 50, so behaviour is unchanged unless the flag is passed.
@jonapoul
jonapoul marked this pull request as ready for review September 8, 2026 09:53
@jonapoul

jonapoul commented Sep 8, 2026

Copy link
Copy Markdown
Author

For comparison on my local project using D2/ELK (zoomed out to minimise attachment size). The default edgeEdgeBetweenLayers value gets very difficult to read when the node count starts to grow:

edgeEdgeBetweenLayers = 10 - 2.76MB

image

edgeEdgeBetweenLayers = 20 - 3.71MB

image

edgeEdgeBetweenLayers = 50 (default) - 7.04MB

image

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