From 9dc987b28b34d81580be59b7499e7eab6f3e636c Mon Sep 17 00:00:00 2001 From: darshanr0107 Date: Tue, 17 Jun 2025 12:12:40 +0530 Subject: [PATCH] remove beta support for sankey diagram --- cypress/integration/rendering/sankey.spec.ts | 4 ++-- demos/sankey.html | 16 ++++++++------ docs/syntax/sankey.md | 22 +++++++++---------- .../src/diagrams/sankey/parser/sankey.jison | 1 + .../src/diagrams/sankey/parser/sankey.spec.ts | 21 ++++++++++++++++-- .../src/diagrams/sankey/sankeyDetector.ts | 2 +- packages/mermaid/src/docs/syntax/sankey.md | 12 +++++----- 7 files changed, 49 insertions(+), 29 deletions(-) diff --git a/cypress/integration/rendering/sankey.spec.ts b/cypress/integration/rendering/sankey.spec.ts index ad0d75f18..b9940d998 100644 --- a/cypress/integration/rendering/sankey.spec.ts +++ b/cypress/integration/rendering/sankey.spec.ts @@ -15,7 +15,7 @@ describe('Sankey Diagram', () => { describe('when given a linkColor', function () { this.beforeAll(() => { cy.wrap( - `sankey-beta + `sankey a,b,10 ` ).as('graph'); @@ -62,7 +62,7 @@ describe('Sankey Diagram', () => { this.beforeAll(() => { cy.wrap( ` - sankey-beta + sankey a,b,8 b,c,8 diff --git a/demos/sankey.html b/demos/sankey.html index 2439cb589..11bb541c2 100644 --- a/demos/sankey.html +++ b/demos/sankey.html @@ -20,12 +20,14 @@ width: 800 nodeAlignment: left --- - sankey-beta - Revenue,Expenses,10 - Revenue,Profit,10 - Expenses,Manufacturing,5 - Expenses,Tax,3 - Expenses,Research,2 + sankey + a,b,8 + b,c,8 + c,d,8 + d,e,8 + + x,c,4 + c,y,4

Energy flow

@@ -40,7 +42,7 @@ linkColor: gradient nodeAlignment: justify --- - sankey-beta + sankey Agricultural 'waste',Bio-conversion,124.729 Bio-conversion,Liquid,0.597 diff --git a/docs/syntax/sankey.md b/docs/syntax/sankey.md index ccabc11c9..e981358b5 100644 --- a/docs/syntax/sankey.md +++ b/docs/syntax/sankey.md @@ -23,7 +23,7 @@ config: sankey: showValues: false --- -sankey-beta +sankey Agricultural 'waste',Bio-conversion,124.729 Bio-conversion,Liquid,0.597 @@ -101,7 +101,7 @@ config: sankey: showValues: false --- -sankey-beta +sankey Agricultural 'waste',Bio-conversion,124.729 Bio-conversion,Liquid,0.597 @@ -175,7 +175,7 @@ Wind,Electricity grid,289.366 ## Syntax -The idea behind syntax is that a user types `sankey-beta` keyword first, then pastes raw CSV below and get the result. +The idea behind syntax is that a user types `sankey` keyword first, then pastes raw CSV below and get the result. It implements CSV standard as [described here](https://www.ietf.org/rfc/rfc4180.txt) with subtle **differences**: @@ -187,7 +187,7 @@ It implements CSV standard as [described here](https://www.ietf.org/rfc/rfc4180. It is implied that 3 columns inside CSV should represent `source`, `target` and `value` accordingly: ```mermaid-example -sankey-beta +sankey %% source,target,value Electricity grid,Over generation / exports,104.453 @@ -196,7 +196,7 @@ Electricity grid,H2 conversion,27.14 ``` ```mermaid -sankey-beta +sankey %% source,target,value Electricity grid,Over generation / exports,104.453 @@ -209,7 +209,7 @@ Electricity grid,H2 conversion,27.14 CSV does not support empty lines without comma delimiters by default. But you can add them if needed: ```mermaid-example -sankey-beta +sankey Bio-conversion,Losses,26.862 @@ -219,7 +219,7 @@ Bio-conversion,Gas,81.144 ``` ```mermaid -sankey-beta +sankey Bio-conversion,Losses,26.862 @@ -233,14 +233,14 @@ Bio-conversion,Gas,81.144 If you need to have a comma, wrap it in double quotes: ```mermaid-example -sankey-beta +sankey Pumped heat,"Heating and cooling, homes",193.026 Pumped heat,"Heating and cooling, commercial",70.672 ``` ```mermaid -sankey-beta +sankey Pumped heat,"Heating and cooling, homes",193.026 Pumped heat,"Heating and cooling, commercial",70.672 @@ -251,14 +251,14 @@ Pumped heat,"Heating and cooling, commercial",70.672 If you need to have double quote, put a pair of them inside quoted string: ```mermaid-example -sankey-beta +sankey Pumped heat,"Heating and cooling, ""homes""",193.026 Pumped heat,"Heating and cooling, ""commercial""",70.672 ``` ```mermaid -sankey-beta +sankey Pumped heat,"Heating and cooling, ""homes""",193.026 Pumped heat,"Heating and cooling, ""commercial""",70.672 diff --git a/packages/mermaid/src/diagrams/sankey/parser/sankey.jison b/packages/mermaid/src/diagrams/sankey/parser/sankey.jison index 9d66b69a4..d531c438a 100644 --- a/packages/mermaid/src/diagrams/sankey/parser/sankey.jison +++ b/packages/mermaid/src/diagrams/sankey/parser/sankey.jison @@ -27,6 +27,7 @@ TEXTDATA [\u0020-\u0021\u0023-\u002B\u002D-\u007E] %% "sankey-beta" { this.pushState('csv'); return 'SANKEY'; } +"sankey" { this.pushState('csv'); return 'SANKEY'; } <> { return 'EOF' } // match end of file ({CRLF}|{LF}) { return 'NEWLINE' } {COMMA} { return 'COMMA' } diff --git a/packages/mermaid/src/diagrams/sankey/parser/sankey.spec.ts b/packages/mermaid/src/diagrams/sankey/parser/sankey.spec.ts index 007cda6f9..10fc86963 100644 --- a/packages/mermaid/src/diagrams/sankey/parser/sankey.spec.ts +++ b/packages/mermaid/src/diagrams/sankey/parser/sankey.spec.ts @@ -13,7 +13,7 @@ describe('Sankey diagram', function () { sankey.parser.yy.clear(); }); - it('parses csv', () => { + it('parses csv with sankey-beta syntax', () => { const csv = path.resolve(__dirname, './energy.csv'); const data = fs.readFileSync(csv, 'utf8'); const graphDefinition = prepareTextForParsing(cleanupComments('sankey-beta\n\n ' + data)); @@ -21,7 +21,15 @@ describe('Sankey diagram', function () { sankey.parser.parse(graphDefinition); }); - it('allows __proto__ as id', function () { + it('parses csv with sankey syntax', () => { + const csv = path.resolve(__dirname, './energy.csv'); + const data = fs.readFileSync(csv, 'utf8'); + const graphDefinition = prepareTextForParsing(cleanupComments('sankey\n\n ' + data)); + + sankey.parser.parse(graphDefinition); + }); + + it('allows __proto__ as id with sankey-beta syntax', function () { sankey.parser.parse( prepareTextForParsing(`sankey-beta __proto__,A,0.597 @@ -29,5 +37,14 @@ describe('Sankey diagram', function () { `) ); }); + + it('allows __proto__ as id with sankey syntax', function () { + sankey.parser.parse( + prepareTextForParsing(`sankey + __proto__,A,0.597 + A,__proto__,0.403 + `) + ); + }); }); }); diff --git a/packages/mermaid/src/diagrams/sankey/sankeyDetector.ts b/packages/mermaid/src/diagrams/sankey/sankeyDetector.ts index 73c4d1428..589bc9ade 100644 --- a/packages/mermaid/src/diagrams/sankey/sankeyDetector.ts +++ b/packages/mermaid/src/diagrams/sankey/sankeyDetector.ts @@ -3,7 +3,7 @@ import type { DiagramDetector, ExternalDiagramDefinition } from '../../diagram-a const id = 'sankey'; const detector: DiagramDetector = (txt) => { - return /^\s*sankey-beta/.test(txt); + return /^\s*sankey(-beta)?/.test(txt); }; const loader = async () => { diff --git a/packages/mermaid/src/docs/syntax/sankey.md b/packages/mermaid/src/docs/syntax/sankey.md index 6b7c359e3..bf04d5553 100644 --- a/packages/mermaid/src/docs/syntax/sankey.md +++ b/packages/mermaid/src/docs/syntax/sankey.md @@ -18,7 +18,7 @@ config: sankey: showValues: false --- -sankey-beta +sankey Agricultural 'waste',Bio-conversion,124.729 Bio-conversion,Liquid,0.597 @@ -92,7 +92,7 @@ Wind,Electricity grid,289.366 ## Syntax -The idea behind syntax is that a user types `sankey-beta` keyword first, then pastes raw CSV below and get the result. +The idea behind syntax is that a user types `sankey` keyword first, then pastes raw CSV below and get the result. It implements CSV standard as [described here](https://www.ietf.org/rfc/rfc4180.txt) with subtle **differences**: @@ -104,7 +104,7 @@ It implements CSV standard as [described here](https://www.ietf.org/rfc/rfc4180. It is implied that 3 columns inside CSV should represent `source`, `target` and `value` accordingly: ```mermaid-example -sankey-beta +sankey %% source,target,value Electricity grid,Over generation / exports,104.453 @@ -117,7 +117,7 @@ Electricity grid,H2 conversion,27.14 CSV does not support empty lines without comma delimiters by default. But you can add them if needed: ```mermaid-example -sankey-beta +sankey Bio-conversion,Losses,26.862 @@ -131,7 +131,7 @@ Bio-conversion,Gas,81.144 If you need to have a comma, wrap it in double quotes: ```mermaid-example -sankey-beta +sankey Pumped heat,"Heating and cooling, homes",193.026 Pumped heat,"Heating and cooling, commercial",70.672 @@ -142,7 +142,7 @@ Pumped heat,"Heating and cooling, commercial",70.672 If you need to have double quote, put a pair of them inside quoted string: ```mermaid-example -sankey-beta +sankey Pumped heat,"Heating and cooling, ""homes""",193.026 Pumped heat,"Heating and cooling, ""commercial""",70.672