Skip to content

fix: prevent mermaid LR diagrams from being squished#8230

Open
AhmadYasser1 wants to merge 1 commit intomarimo-team:mainfrom
AhmadYasser1:fix/mermaid-lr-scaling
Open

fix: prevent mermaid LR diagrams from being squished#8230
AhmadYasser1 wants to merge 1 commit intomarimo-team:mainfrom
AhmadYasser1:fix/mermaid-lr-scaling

Conversation

@AhmadYasser1
Copy link
Contributor

Summary

LR (left-to-right) mermaid diagrams were compressed to fit the container width because flowchart.useMaxWidth defaults to true. Sets it to false so diagrams render at natural size, and wraps the output in a scrollable container.

Closes #6697

Test Plan

  • Visual: LR flowcharts render at natural width with horizontal scrolling

@mscolnick
Copy link
Contributor

@AhmadYasser1 this is great, thank you. any chance you can share a screenshot of the change (before and after)?

@AhmadYasser1
Copy link
Contributor Author

Before

image

After

image

@mscolnick
Copy link
Contributor

thanks for the screenshot! and all the effort on these PRs.

do you know if its possible to have something in between the two options? its full width without the overflow? no worries if its hard to figure out (i think myself and others have tried as well)

@AhmadYasser1
Copy link
Contributor Author

tried a few approaches for a middle ground (height: auto, uniform scaling via viewBox) but they all end up with the same tiny squished nodes. the core issue is that mermaid calculates node sizes based on container width when useMaxWidth: true, so there's no way to get readable nodes without useMaxWidth: false.

the overflow-x: auto wrapper keeps it from breaking the layout and matches how other tools like github handle wide diagrams.

@mscolnick
Copy link
Contributor

thanks for exhaustively checking @AhmadYasser1

matches how other tools like github handle wide diagrams.

This is good to know. I think consistency would make sense. I will defer to @Light2Dark or @manzt for some final thoughts or other ideas. Maybe we want to explore navigation buttons (zoom-in/out) or a toggle.

@Light2Dark
Copy link
Contributor

Light2Dark commented Feb 11, 2026

responded on original issue, it feels like the issue is with .center rather than mermaid

Set flowchart `useMaxWidth: false` so SVGs render at natural pixel width
instead of scaling to container width. This matches how GitHub and other
tools render mermaid diagrams, and prevents LR flowcharts from being
compressed when inside flex layouts (e.g. `.center()` wraps content in
an `hstack` flex container).

Wrap the SVG output in a scrollable container with `max-width: 100%` so:
- Wide diagrams scroll horizontally instead of overflowing
- Narrow diagrams keep their natural size (preserving `.center()`)

Closes marimo-team#6697
@AhmadYasser1
Copy link
Contributor Author

thanks @Light2Dark

.center() wraps content in hstack which creates a flex container, and the svg's width: 100% (from useMaxWidth: true) sizes relative to that constrained flex item.

updated the fix:

  • useMaxWidth: false for flowcharts so svgs render at natural size (matches how github renders mermaid)

  • overflow-x: auto + max-width: 100% wrapper so narrow diagrams still center normally, wide ones scroll only affects flowcharts, sequence/gantt unchanged.

@AhmadYasser1 AhmadYasser1 force-pushed the fix/mermaid-lr-scaling branch from f8cdd05 to 97bee3a Compare February 14, 2026 00:01
@vercel
Copy link

vercel bot commented Feb 14, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
marimo-docs Ready Ready Preview, Comment Feb 14, 2026 0:02am

Request Review

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.

Mermaid scaling issue in LR diagrams

3 participants