Skip to content

feat(c4): clickable $link for the unified renderer - #7863

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

filipsajdak wants to merge 10 commits into
mermaid-js:developfrom
filipsajdak:feature/7492_c4-links

Conversation

@filipsajdak

Copy link
Copy Markdown
Collaborator

Summary

Makes $link on C4 elements clickable in the unified renderer. The legacy db stores attribute values ($link, $tags, ...) either as a plain string or wrapped in { text } depending on the positional slot, so a small C4Attribute helper (attributeText) normalises both forms before the link is attached to the node.

Stacked on #7862 (AddElementTag/AddRelTag), which is stacked on #7842 - draft until those merge; the diff carries their commits until then. Tracked in #7849.

Slice commits (review by commit):

  • feat(c4): make $link clickable in the unified renderer
  • chore: add changeset for c4 clickable links

🤖 Generated with Claude Code

@changeset-bot

changeset-bot Bot commented Jun 16, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 51ca02c

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 51ca02c
🔍 Latest deploy log https://app.netlify.com/projects/mermaid-js/deploys/6a34ee9005b19c0009702fc6
😎 Deploy Preview https://deploy-preview-7863--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@7863

mermaid

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

@mermaid-js/layout-elk

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

@mermaid-js/layout-tidy-tree

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

@mermaid-js/mermaid-zenuml

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

@mermaid-js/parser

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

@mermaid-js/tiny

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

commit: 51ca02c

@codecov

codecov Bot commented Jun 16, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.20879% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.91%. Comparing base (625ab8b) to head (51ca02c).
⚠️ 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.28% 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    #7863      +/-   ##
===========================================
+ Coverage    77.79%   77.91%   +0.11%     
===========================================
  Files          409      412       +3     
  Lines        30328    30510     +182     
  Branches      5175     5213      +38     
===========================================
+ Hits         23595    23772     +177     
- Misses        5410     5411       +1     
- Partials      1323     1327       +4     
Flag Coverage Δ
e2e 82.06% <91.20%> (+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.28% <95.28%> (ø)
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:59 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-links branch from b7f641f to a8f0dc2 Compare June 18, 2026 22:42
filipsajdak and others added 10 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>
Normalize $link values on elements and boundaries (which the legacy
db stores either as a plain string or a { text } object depending on
the positional slot) before passing them as node.link, where the
unified pipeline wraps the node in an anchor and honors
securityLevel (sandbox opens links in the top window).

$link on relationships is documented as unsupported: the unified
Edge type has no link field.

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-links branch from a8f0dc2 to 51ca02c 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