Skip to content

feat(mermaid): color diagram nodes with theme palette - #64

Merged
denolfe merged 1 commit into
mainfrom
feat/mermaid-colors
Nov 2, 2026
Merged

denolfe merged 1 commit into
mainfrom
feat/mermaid-colors

Conversation

@denolfe

@denolfe denolfe commented Nov 2, 2026 •

Copy link
Copy Markdown
Owner

Mermaid and DOT diagrams now render in color. Each node box takes its own hue from the theme palette. Edges, arrowheads, and edge labels take a color by role.

 src/app/
 ├── components/blocks/
 │   └── CodeBlock.tsx      # renders diagram text as colored runs
 ├── lib/
+│   └── diagram-paint.ts   # assigns a color to each diagram glyph
 └── styles/
     └── theme.ts           # adds diagram palette tokens
image

Changes

  • Diagram painter
    • paintDiagram scans the rendered glyph grid for box rectangles. Each innermost box (border and label) takes the next node hue.
    • Hues are keyed by label. A sequence participant has the same hue at the top and bottom of the diagram.
    • Remaining glyphs take a role color: line, arrowhead, or text. Subgraph frames take the line color.
  • Theme tokens
    • diagramNodes, diagramLine, diagramArrow, and diagramText reuse existing theme values.
  • Diagram rendering
    • CodeBlock renders one span per run. Each span wraps a HighlightedText piece.
    • Search match backgrounds paint over the run color.
  • Mermaid fixture
    • Adds sequence note variants (left of, over X, over X,Y).
    • Notes that beautiful-mermaid drops state-diagram notes.

Design Decisions

  • viewmd paints the plain diagram text after rendering. Newer beautiful-mermaid releases can emit ANSI color. The Projection (the printed text that search and highlighting index) cannot hold escape codes, so library color is not usable here. The painted runs concatenate back to the diagram text.
  • The node palette has no yellow or red. Yellow is the search-match background. Red reads as an error.
  • Join glyphs (┬ ┴ ├ ┤) on a box border take the node hue. A terminal cell holds one color. A line-colored join would put a notch in the border. The cost is a half-cell colored stub where an edge leaves a node.
  • The box scan is a heuristic. A shape it does not match, such as a box with wide CJK characters in its label, falls back to role colors.

Overall Flow

 CodeBlock (diagram branch)
   codeText(node, breakoutWidth)
-  <HighlightedText value={ascii} />
+  paintDiagram(ascii)                 # memoized per diagram text
+  for each run
+    <span fg={run.fg}>
+      <HighlightedText value={run.text} />

References / Links

  • merman: prior art for the box scan and per-label node hues.

🤖 Written with AI

Each innermost box (border and label) takes the next node hue, keyed by
label so a repeated node keeps its hue. Lines, arrowheads, and loose text
color by role; subgraph frames paint as lines. Runs concatenate back to
the diagram text, so search and match highlighting are unchanged.
@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

Startup benchmark (--render test/exhaustive.md, linux-x64)

build mean ratio verdict
baseline (main@8b38c47) 287.1ms ± 5.4ms —
PR 295.6ms ± 5.6ms 1.03× ✅ ok

Thresholds: warn ≥ 1.1×, fail ≥ 1.25×. Baseline built from main.

First-frame (large.md, runs=10)

metric baseline (main@8b38c47) PR ratio verdict
first-frame 205.3ms 206.7ms 1.01× ✅ ok

Thresholds: warn ≥ 1.1×, fail ≥ 1.25×. Baseline built from main.

Scroll (large.md)

metric baseline (main@8b38c47) PR ratio verdict
full_mount 7718.0ms 7124.0ms 0.92× ✅ ok
step_p50 23.9ms 25.8ms 1.08× ✅ ok
step_search_p50 28.5ms 26.8ms 0.94× ✅ ok
stepMatch_p50 21.6ms 22.3ms 1.03× ✅ ok
commit 126.4ms 132.9ms 1.05× ✅ ok

Thresholds: warn ≥ 1.1×, fail ≥ 1.25×. Baseline built from main.

@denolfe
denolfe merged commit 8b9a056 into main Nov 2, 2026
8 checks passed
@denolfe
denolfe deleted the feat/mermaid-colors branch November 2, 2026 23:27
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