Skip to content

fix: size the timeline diagram to its container, not the window - #45

Merged
XtremeOwnageDotCom merged 2 commits into
mainfrom
fix/timeline-diagram-width
Aug 19, 2026
Merged

fix: size the timeline diagram to its container, not the window#45
XtremeOwnageDotCom merged 2 commits into
mainfrom
fix/timeline-diagram-width

Conversation

@XtremeOwnageDotCom

@XtremeOwnageDotCom XtremeOwnageDotCom commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

What & why

Timeline diagrams render at a fraction of their intended size on the published docs. Straight from Mermaid's gantt renderer:

N = D.getElementById(e);
st = N.parentElement.offsetWidth,           // width comes from the PARENT element
st === void 0 && (st = 1200),
s.useWidth !== void 0 && (st = s.useWidth); // …unless useWidth is set

mermaid.render(id, src) with no container renders into a throwaway element on <body>, so the gantt sizes itself to the whole window. Our .nd-timeline__diagram svg { max-width: 100% } then scales that down into the content column. The wider the window, the smaller the diagram.

Material caps its content column at ~750px, so on a typical desktop this is about a 2.5× shrink — which is why it looks fine on a phone and unreadable on a monitor. Measured on the live site: the same page is legible at an 800px window and microscopic at 1900px.

The fix — part 1: size to the container

Pass the container's measured width as gantt useWidth, which the renderer prefers over the parent's. The SVG is then drawn at the size it is displayed, so max-width has nothing to scale and text lands at its intended size at any window width.

Because the diagram is now sized rather than stretched, a resize has to redraw — added a debounced resize handler, bound once per page rather than once per block.

The fix — part 2: never below a legible width

Fitting the container is not the same as being readable. At a 420px window the diagram fit its column perfectly and was still unusable: task names overlapped their bars and the axis ticks ran together.

So the width is now max(container, 720px), and that width is pinned onto the rendered SVG — Mermaid emits width="100%" plus a max-width, which would otherwise shrink it straight back into the column. .nd-timeline__diagram already had overflow-x: auto, so below the floor the diagram keeps its readable size and scrolls rather than scaling its labels into nothing. The exact-date table underneath is unaffected and stays fully readable at any width.

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Refactor / chore

Checklist

  • dotnet format Netdocs.slnx --verify-no-changes passes
  • dotnet build Netdocs.slnx -c Release succeeds
  • dotnet test Netdocs.slnx -c Release passes (510, +3 new)
  • Added/updated tests for the change
  • Updated docs under docs-site/docs/** — new "Diagram size" section on the timeline page

Verification

Browser, on the real page, at both ends of the range:

Before After
1900px window bars a few pixels tall, labels illegible — matching the published site full-size bars, readable labels
420px window (and after part 1) labels overlapping their bars, axis ticks colliding readable at 720px, container scrolls

I also confirmed this is not environment-specific before fixing it: prod and dev pages are byte-identical apart from asset URLs, and the self-hosted Mermaid module produces exactly the same viewBox 0 0 984 244 as the CDN one. The variable was window width all along.

Notes for reviewers

The two new tests assert on the emitted JavaScript source, not its behaviour — the sizing happens in the client evaluator, which nothing in dotnet test executes. They pin the contract; the browser check above is the real evidence. This is the same coverage gap I flagged on #43, and it just cost us a round trip: one existing EvaluatorJs_* test broke purely because I changed the text of a call it string-matched, with no behaviour change at all. I retargeted it at the intent (the diagram still receives the unsorted events) rather than the literal call.

Once merged, the docs site needs a rebuild for the published diagrams to pick this up.

🤖 Generated with Claude Code

XtremeOwnageDotCom and others added 2 commits August 18, 2026 23:15
Mermaid's gantt renderer takes its width from the parent of the element it
renders into, and mermaid.render() with no container renders into a throwaway
element on <body>. The diagram therefore sized itself to the whole window, and
`.nd-timeline__diagram svg { max-width: 100% }` scaled that down into the content
column -- so the wider the window, the smaller the result.

Material caps its content column at roughly 750px, so on the published docs this
shrank by about 2.5x at a typical desktop width: readable on a phone, unreadably
tiny on a monitor. Verified against the published site, where the same page is
legible at an 800px window and microscopic at 1900px.

Pass the container's measured width as gantt `useWidth`, which the renderer
prefers over the parent's, so the SVG is drawn at the size it is displayed and
nothing is scaled. Redraw on resize (debounced, bound once per page) since the
diagram is now sized rather than stretched.

Verified in a browser in the real Material layout at 1900px, before and after.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sizing the gantt to its container fixed the wide-window case but not the narrow
one: squeezed into a phone-width column it overlaps its own task names and axis
ticks, which is readable in neither direction.

Draw at the greater of the container's width and a 720px floor, and pin that
width onto the rendered SVG -- mermaid emits width="100%" with a max-width, which
would otherwise shrink it straight back into the column. The container already
had overflow-x, so below the floor it now scrolls at a readable size instead of
scaling the labels away.

Verified in a browser on the real page: at a 420px window the diagram stays
legible and scrolls; at 1900px it fills the content column as before.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@XtremeOwnageDotCom
XtremeOwnageDotCom merged commit 41c5b1c into main Aug 19, 2026
1 check passed
@XtremeOwnageDotCom
XtremeOwnageDotCom deleted the fix/timeline-diagram-width branch August 19, 2026 04:26
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