Skip to content

Feature/flowchart edge classdef#7557

Open
christikaes wants to merge 4 commits intomermaid-js:developfrom
christikaes:feature/flowchart-edge-classdef
Open

Feature/flowchart edge classdef#7557
christikaes wants to merge 4 commits intomermaid-js:developfrom
christikaes:feature/flowchart-edge-classdef

Conversation

@christikaes
Copy link
Copy Markdown

Summary

Resolves #6938, #6017

Adds support for applying classDef styles directly to edges in flowchart diagrams using a new inline @:::className syntax, mirroring how :::className works for nodes. This allows applying styles such as colors to multiple edges at once while still remaining backwards compatible with edge ids.

New syntax

flowchart TD
Start:::nodeStyle --> Process
Process okLink@:::edgeStyle-->|OK| Approve
Process @:::edgeStyle-->|Error| Retry
Approve @:::edgeStyle--> End
Retry --> Process

classDef nodeStyle fill:green,stroke:red
classDef edgeStyle stroke:red,stroke-width:3px
  • @:::className — class only, no edge ID
  • myId@:::className — class + user-defined edge ID
  • Works with bare (-->), pipe-labeled (-->|text|), and inline-text (-- text -->) edges
  • Existing class <edgeId> <className> statement syntax unchanged

Changes

  • flow.jison — new LINK_ID_CLASS / LINK_CLASS lexer tokens + grammar rules
  • flowDb.ts — propagate type.classes in addSingleLink(); append class names in getData()
  • edges.js — fix for...in → for...of in insertEdge
  • 9 new parser tests, 2 new getData() integration tests
  • docs: new section in flowchart.md

Tests

982 flowchart tests pass, 0 regressions.

Introduces a new @:::className syntax that allows users to apply classDef
styles to edges in flowchart diagrams, mirroring how :::className works
for nodes.

- Add LINK_ID_CLASS and LINK_CLASS lexer tokens to flow.jison (placed
  before LINK_ID to ensure first-match wins)
- Add grammar rules for both bare-arrow and pipe-label forms in
  linkStatement and link productions
- Update addSingleLink() in flowDb.ts to propagate type.classes onto
  the FlowEdge
- Fix getData() in flowDb.ts to append classDef class names to the
  SVG class attribute string on rendered edges
- Fix for...in on array in edges.js (insertEdge) to use for...of
- Add 9 parser tests in flow-style.spec.js covering all syntax variants
- Add 2 getData() integration tests in flowDb.spec.ts verifying
  cssCompiledStyles is populated for edges
- Add demo diagram to demos/flowchart.html
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 31, 2026

🦋 Changeset detected

Latest commit: 0279465

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
Copy link
Copy Markdown

netlify bot commented Mar 31, 2026

Deploy Preview for mermaid-js ready!

Name Link
🔨 Latest commit 0279465
🔍 Latest deploy log https://app.netlify.com/projects/mermaid-js/deploys/69cc1c25f4ba3a00082081de
😎 Deploy Preview https://deploy-preview-7557--mermaid-js.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

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 Mar 31, 2026
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Mar 31, 2026

Open in StackBlitz

@mermaid-js/examples

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

mermaid

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

@mermaid-js/layout-elk

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

@mermaid-js/layout-tidy-tree

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

@mermaid-js/mermaid-zenuml

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

@mermaid-js/parser

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

@mermaid-js/tiny

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

commit: 0279465

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 31, 2026

Codecov Report

❌ Patch coverage is 0% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 3.34%. Comparing base (e9d4c11) to head (0279465).

Files with missing lines Patch % Lines
packages/mermaid/src/diagrams/flowchart/flowDb.ts 0.00% 5 Missing ⚠️
...aid/src/rendering-util/rendering-elements/edges.js 0.00% 3 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           develop   #7557      +/-   ##
==========================================
- Coverage     3.34%   3.34%   -0.01%     
==========================================
  Files          524     524              
  Lines        55256   55261       +5     
  Branches       795     795              
==========================================
  Hits          1850    1850              
- Misses       53406   53411       +5     
Flag Coverage Δ
unit 3.34% <0.00%> (-0.01%) ⬇️

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

Files with missing lines Coverage Δ
...aid/src/rendering-util/rendering-elements/edges.js 0.00% <0.00%> (ø)
packages/mermaid/src/diagrams/flowchart/flowDb.ts 0.00% <0.00%> (ø)
🚀 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.

@Sudhanshu-Ambastha
Copy link
Copy Markdown

Hi! Checked your PR—in line 2262 of the failed e2e tests, it clearly says the screenshot limit for the plan was exceeded. So technically, it’s not your fault at all! If you want, you could reduce the number of test cases, but honestly, you can probably leave it as is. I've seen many other PRs with the same issue that still got merged because the logic itself is fine. Nice work regardless

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.

Allows classes for edges

2 participants