Skip to content

Plantuml metrics - #2935

Closed
pavlo-alkhimov wants to merge 5 commits into
d2lang:masterfrom
pavlo-alkhimov:plantuml-metrics
Closed

pavlo-alkhimov wants to merge 5 commits into
d2lang:masterfrom
pavlo-alkhimov:plantuml-metrics

Conversation

@pavlo-alkhimov

Copy link
Copy Markdown

No description provided.

pavlo-alkhimov and others added 5 commits September 22, 2026 15:08
Upstream sizes a shape as text + 45px per axis with a 1.5 markdown line
height; PlantUML uses text + 20px and ~1.36. The result is that most of a
D2 box is padding, which reads as a small font in a large rectangle.

Three constants close the gap, leaving diagram sources untouched:

  lib/shape/shape.go              defaultPadding      40.  -> 15.
  lib/textmeasure/markdown.go     MarkdownLineHeight  1.5  -> 1.36
  d2renderers/d2fonts/...         FONT_SIZE_M         16   -> 14

Every shape derives its padding from defaultPadding as a multiple or a
fraction, so one constant rescales them all consistently. Box heights now
land within 1px of PlantUML at one, two and three lines. Line height drives
both measurement and rendering, so baselines and boxes stay in agreement.

Version is set to v0.9.0-plantuml-metrics.1 so it cannot be mistaken for an
upstream release. Adds a workflow that cross-compiles Windows, Linux and
macOS binaries and re-asserts the three constants after every build, and
PLANTUML-METRICS.md documenting the rationale and how to rebase.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Tag pattern becomes v*-plantuml-metrics* so a tagged build reports the same
string the source defaults to, instead of a bare "v1". Adds a four-line
banner at the top of README pointing at PLANTUML-METRICS.md, and documents
releases plus the upstream remote needed before a rebase.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…rror

Compiling this panics with an invalid memory address:

    **.shape: rectangle
    b
    LINK -> b

Field.LastPrimaryKey() returns a nil *d2ast.Key for a field that was created
by an edge or a glob rather than written as `KEY: value`. compileReserved
passes that result straight to errorf, and d2parser.Errorf calls GetRange()
on the nil pointer, so the crash happens inside the code that was trying to
report an ordinary compile error. Around sixty call sites in d2compiler pass
LastPrimaryKey() the same way, so the crash is reachable by other routes.

errorf now substitutes a zero-range node when handed a nil one, which covers
every call site. It still delegates to d2parser.Errorf rather than
formatting the message itself, so go vet does not begin treating errorf as a
printf wrapper and flagging pre-existing non-constant format strings in this
file. The site in the traceback additionally falls back to LastRef().AST(),
keeping an accurate source position like the sibling error just below it.

The panic becomes:

    reserved field LINK does not accept composite

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
d2compiler: fix nil-pointer panic when reporting a reserved-keyword e…
This fork deliberately changes the geometry of every rendered diagram, so
upstream's end-to-end tests cannot pass: verified, they fail on exactly the
coordinates the metrics change moves. Keeping those workflows means a
permanently red master and a thirty-minute job on every push to prove
something already known.

Removes ci.yml, release-archives.yml, weekly-race.yml, tala-fuzz.yml, the
docker and npm staging jobs, and windows-msi.yml, leaving only
plantuml-metrics-build.yml. Dropping release-archives.yml also stops a
second, differently named set of binaries being built for every v* tag,
which was a source of confusion about which download to install.

The build workflow now triggers on master rather than the patch branch,
since the work is being consolidated there. Docs updated accordingly: the
rebase recipe no longer assumes a pristine mirror branch, and the compiler
crash fix is documented again after the branch split dropped that section.

What still guards correctness: the build asserts the three metric constants
on every run, and go test ./d2compiler/ covers the panic fix.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@pavlo-alkhimov
pavlo-alkhimov deleted the plantuml-metrics branch September 22, 2026 14: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