Skip to content

feat(c4): AddElementTag/AddRelTag styling for the unified renderer - #7862

Closed
filipsajdak wants to merge 8 commits into
mermaid-js:developfrom
filipsajdak:feature/7492_c4-tags
Closed

filipsajdak wants to merge 8 commits into
mermaid-js:developfrom
filipsajdak:feature/7492_c4-tags

Conversation

@filipsajdak

Copy link
Copy Markdown
Collaborator

Summary

Adds AddElementTag(...) / AddRelTag(...) styling to C4 diagrams in the unified renderer: elements and relationships carrying a tag pick up the tag's bgColor/fontColor/borderColor/shape (elements) or textColor/lineColor (rels). Tag styles compose with per-element styles and the config palette. Legacy renderer behaviour is unchanged.

Stacked on #7842 (opt-in unified renderer) - draft until #7842 merges; the diff carries #7842's commits until then. Base slice for clickable $link and SHOW_LEGEND(). Tracked in #7849.

Slice commits (review by commit):

  • feat(c4): style elements and rels via AddElementTag and AddRelTag (+ parser/layout specs)
  • chore(c4): add changeset

🤖 Generated with Claude Code

@changeset-bot

changeset-bot Bot commented Jun 16, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: b83e908

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
mermaid Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@netlify

netlify Bot commented Jun 16, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for mermaid-js ready!

Name Link
🔨 Latest commit b83e908
🔍 Latest deploy log https://app.netlify.com/projects/mermaid-js/deploys/6a34ee8ea707640008b8f161
😎 Deploy Preview https://deploy-preview-7862--mermaid-js.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@github-actions github-actions Bot added the Type: Enhancement New feature or request label Jun 16, 2026
@pkg-pr-new

pkg-pr-new Bot commented Jun 16, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@mermaid-js/examples

npm i https://pkg.pr.new/@mermaid-js/examples@7862

mermaid

npm i https://pkg.pr.new/mermaid@7862

@mermaid-js/layout-elk

npm i https://pkg.pr.new/@mermaid-js/layout-elk@7862

@mermaid-js/layout-tidy-tree

npm i https://pkg.pr.new/@mermaid-js/layout-tidy-tree@7862

@mermaid-js/mermaid-zenuml

npm i https://pkg.pr.new/@mermaid-js/mermaid-zenuml@7862

@mermaid-js/parser

npm i https://pkg.pr.new/@mermaid-js/parser@7862

@mermaid-js/tiny

npm i https://pkg.pr.new/@mermaid-js/tiny@7862

commit: b83e908

@codecov

codecov Bot commented Jun 16, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.16022% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.91%. Comparing base (625ab8b) to head (b83e908).
⚠️ Report is 2 commits behind head on develop.

Files with missing lines Patch % Lines
packages/mermaid/src/diagrams/c4/c4Db.ts 82.85% 3 Missing and 3 partials ⚠️
packages/mermaid/src/diagrams/c4/c4LayoutData.ts 95.23% 2 Missing and 3 partials ⚠️
...ages/mermaid/src/diagrams/c4/c4Renderer-unified.ts 77.77% 0 Missing and 4 partials ⚠️
...ndering-util/rendering-elements/shapes/c4Person.ts 94.73% 0 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #7862      +/-   ##
===========================================
+ Coverage    77.79%   77.91%   +0.11%     
===========================================
  Files          409      412       +3     
  Lines        30328    30509     +181     
  Branches      5175     5213      +38     
===========================================
+ Hits         23595    23771     +176     
- Misses        5410     5411       +1     
- Partials      1323     1327       +4     
Flag Coverage Δ
e2e 82.06% <91.16%> (+0.09%) ⬆️
unit 24.36% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
packages/mermaid/src/diagrams/c4/c4Diagram.ts 100.00% <100.00%> (ø)
packages/mermaid/src/diagrams/c4/styles.js 100.00% <ø> (ø)
...id/src/rendering-util/rendering-elements/shapes.ts 100.00% <ø> (ø)
...ndering-util/rendering-elements/shapes/c4Person.ts 94.73% <94.73%> (ø)
...ages/mermaid/src/diagrams/c4/c4Renderer-unified.ts 77.77% <77.77%> (ø)
packages/mermaid/src/diagrams/c4/c4LayoutData.ts 95.23% <95.23%> (ø)
packages/mermaid/src/diagrams/c4/c4Db.ts 58.35% <82.85%> (+4.39%) ⬆️

... and 3 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@argos-ci

argos-ci Bot commented Jun 16, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Argos notifications ↗︎

Build Status Details Updated (UTC)
default (Inspect) ⚠️ Changes detected (Review) 91 changed, 75 added Jun 19, 2026, 8:50 AM

@filipsajdak

Copy link
Copy Markdown
Collaborator Author

Heads-up: following @aloisklink's review on #7842, Track 1 has switched from the opt-in-flag approach to an in-place migration sliced by rendering layer (shapes -> edges -> layout) - see the updated plan in #7849.

This slice is paused for now. Its branch is preserved as an archive tag (archive/2026-06-17/... on the fork) and its work is reused: it will be re-sequenced as a feature slice on top of the migrated (now-default) unified renderer rather than stacked on an opt-in flag. Keeping it open as a draft for reference; not abandoned.

@filipsajdak
filipsajdak force-pushed the feature/7492_c4-tags branch from 0294276 to 86c3a2c Compare June 18, 2026 22:42
filipsajdak and others added 8 commits June 19, 2026 09:22
Converts the legacy C4 db state (c4ShapeArray / boundaries / rels) into
the unified renderer LayoutData format: elements become nodes (db
variants use cylinder, queue variants use h-cyl), boundaries become
isGroup clusters with parentId nesting, and rels become edges.
UpdateElementStyle and UpdateRelStyle map onto cssStyles/style/labelStyle
preserving legacy semantics. Default fills come from the existing c4
config color keys so the palette matches the legacy renderer.

Kept in a separate file so the legacy c4Db keeps its exact shape.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Adds an opt-in renderer for C4 diagrams that goes through the unified
rendering pipeline (dagre by default, other algorithms such as ELK via
registerLayoutLoaders), replacing the legacy statement-order grid with a
real layout algorithm. The legacy row-based renderer stays the default,
so existing diagrams render byte-identical unless the flag is set.

- c4Renderer-unified.ts: renders getData() output via render()
- c4Diagram.ts: dispatches between legacy and unified renderer
- styles.js: CSS for the unified path (nodes, dashed boundary
  clusters, edges, edge labels, title), theme-variable driven
- config.schema.yaml: new c4.useUnifiedRenderer flag (default false)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Renders C4 Person and Person_Ext elements with the classic C4 notation
(circular head over a rounded box body) instead of a plain rectangle.
The shape is registered in the shared shape registry as c4-person so
other diagrams can reuse it.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Covers nested boundaries, UpdateElementStyle/UpdateRelStyle, db and
queue shape variants, nested deployment nodes, and guards the rendered
viewBox dimensions against layout blowups.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Add the C4-PlantUML macros AddElementTag(tagName, ?bgColor,
?fontColor, ?borderColor, ?shape) and AddRelTag(tagName, ?textColor,
?lineColor) to the grammar and store the definitions in the db
(getElementTags/getRelTags, reset in clear).

The unified renderer resolves the $tags of every element, boundary
and rel against the defined tags ('+' separated per C4-PlantUML,
commas accepted) and applies the tag colors between the per-type
config palette and the per-element UpdateElementStyle/UpdateRelStyle
overrides. Tag names are also exposed as c4-tag-<name> css classes on
the nodes for user styling. The legacy renderer ignores tags, as
documented.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@filipsajdak
filipsajdak force-pushed the feature/7492_c4-tags branch from 86c3a2c to b83e908 Compare June 19, 2026 07:23
@filipsajdak

Copy link
Copy Markdown
Collaborator Author

Closing this PR. It was part of the original opt-in feature-slice approach for the C4 unified renderer. Following @aloisklink's review on #7842, that approach was superseded by an in-place migration sliced by rendering layer (shapes -> edges -> layout), tracked in #7849 (#7842 shapes, #7883 edges, layout PR to follow). This feature will be re-introduced on top of the migrated renderer once the layout slice lands.

The branch is preserved as an archive tag (archive/2026-06-17/*) for reference, so nothing is lost. Closing to keep the open-PR set small and avoid unnecessary CI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type: Enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant