Skip to content

Write Legend as D2's native legend - #18

Merged
h0rv merged 1 commit into
mainfrom
fix-native-legend
Oct 23, 2026
Merged

h0rv merged 1 commit into
mainfrom
fix-native-legend

Conversation

@h0rv

@h0rv h0rv commented Oct 23, 2026

Copy link
Copy Markdown
Owner

In 2.0.0, d2.Legend was written as a top-level legend: key. D2 reads that as an ordinary container named "legend", so the "legend" was drawn as one more box in the diagram. d2 validate accepted it, because a box named legend is valid D2.

This change:

  • writes the legend under vars: { d2-legend: <label> { ... } }, so D2 draws its real legend card at the bottom right. The label becomes the card's title.
  • hides the endpoints of legend connections unless they are declared as legend shapes, so a connection entry shows only its colored line and label.
  • writes one vars block with d2-config, the variables and the legend, instead of separate blocks.
  • removes Legend.near. D2 always places the legend itself and has no setting for its position. near was released a few hours ago and only ever positioned the wrong box.

Checked locally: all 244 tests pass. A new render test checks that D2 draws the legend title, and ruff and ty are clean. I also used it in the relationship map spike, where the legend now shows as a key with one sample arrow per color.

🤖 Generated with Claude Code

Legend was written as a top-level 'legend' key, which D2 draws as an
ordinary container. It now goes under vars.d2-legend with its label as
the title, so D2 draws a real legend. Connection endpoints that are not
legend shapes are hidden, so an entry for a connection shows only its
line and label. The diagram writes one vars block for d2-config,
variables and the legend. Legend.near is removed: D2 places the legend
itself and has no position for it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@h0rv
h0rv merged commit 8c61162 into main Oct 23, 2026
9 checks passed
@h0rv
h0rv deleted the fix-native-legend branch October 23, 2026 19:25
@h0rv h0rv mentioned this pull request Oct 23, 2026
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