From 3cd15cdcf2a2d6e81a296831323c57981fececfc Mon Sep 17 00:00:00 2001 From: Knut Sveidqvist Date: Thu, 19 Jan 2023 20:50:36 +0100 Subject: [PATCH 1/5] #4012 Handling rows with only spaces in them --- packages/mermaid-mindmap/src/mindmap.spec.js | 12 ++++++++++++ packages/mermaid-mindmap/src/parser/mindmap.jison | 5 ++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/mermaid-mindmap/src/mindmap.spec.js b/packages/mermaid-mindmap/src/mindmap.spec.js index e3f018350..2a2dd13bb 100644 --- a/packages/mermaid-mindmap/src/mindmap.spec.js +++ b/packages/mermaid-mindmap/src/mindmap.spec.js @@ -347,4 +347,16 @@ root expect(child.children.length).toEqual(2); expect(child.children[1].nodeId).toEqual('b'); }); + it('MMP-23 Rows with only spaces should not interfere', function () { + let str = 'mindmap\nroot\n A\n \n\n B'; + mindmap.parse(str); + const mm = mindmap.yy.getMindmap(); + expect(mm.nodeId).toEqual('root'); + expect(mm.children.length).toEqual(2); + + const child = mm.children[0]; + expect(child.nodeId).toEqual('A'); + const child2 = mm.children[1]; + expect(child2.nodeId).toEqual('B'); + }); }); diff --git a/packages/mermaid-mindmap/src/parser/mindmap.jison b/packages/mermaid-mindmap/src/parser/mindmap.jison index a96ee6261..651d9dc09 100644 --- a/packages/mermaid-mindmap/src/parser/mindmap.jison +++ b/packages/mermaid-mindmap/src/parser/mindmap.jison @@ -25,6 +25,7 @@ \n { this.popState();} // [\s]*"::icon(" { this.begin('ICON'); } "::icon(" { yy.getLogger().trace('Begin icon');this.begin('ICON'); } +[\s]+[\n] {yy.getLogger().trace('SPACELINE');return 'SPACELINE' /* skip all whitespace */ ;} [\n]+ return 'NL'; [^\)]+ { return 'ICON'; } \) {yy.getLogger().trace('end icon');this.popState();} @@ -72,6 +73,7 @@ start stop : NL {yy.getLogger().trace('Stop NL ');} | EOF {yy.getLogger().trace('Stop EOF ');} + | SPACELINE | stop NL {yy.getLogger().trace('Stop NL2 ');} | stop EOF {yy.getLogger().trace('Stop EOF2 ');} ; @@ -81,9 +83,10 @@ document ; statement - : SPACELIST node { yy.getLogger().trace('Node: ',$2.id);yy.addNode($1.length, $2.id, $2.descr, $2.type); } + : SPACELIST node { yy.getLogger().info('Node: ',$2.id);yy.addNode($1.length, $2.id, $2.descr, $2.type); } | SPACELIST ICON { yy.getLogger().trace('Icon: ',$2);yy.decorateNode({icon: $2}); } | SPACELIST CLASS { yy.decorateNode({class: $2}); } + | SPACELINE { yy.getLogger().trace('SPACELIST');} | node { yy.getLogger().trace('Node: ',$1.id);yy.addNode(0, $1.id, $1.descr, $1.type); } | ICON { yy.decorateNode({icon: $1}); } | CLASS { yy.decorateNode({class: $1}); } From 023f2354cdd659fc9827a567342ded4ed6df7579 Mon Sep 17 00:00:00 2001 From: Knut Sveidqvist Date: Fri, 20 Jan 2023 08:31:01 +0100 Subject: [PATCH 2/5] --- cypress/platform/knsv2.html | 36 ++++++++++++++++--------- packages/mermaid-mindmap/src/svgDraw.js | 6 ++--- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/cypress/platform/knsv2.html b/cypress/platform/knsv2.html index afc12dbe9..e28184627 100644 --- a/cypress/platform/knsv2.html +++ b/cypress/platform/knsv2.html @@ -54,7 +54,7 @@ -
+    
 %%{init: {"flowchart": {"defaultRenderer": "elk"}} }%%
 graph TB
       a --> b
@@ -62,14 +62,14 @@ graph TB
       b --> d
       c --> d
     
-
+    
 flowchart-elk TB
       a --> b
       a --> c
       b --> d
       c --> d
     
-
+    
 %%{init: {"flowchart": {"defaultRenderer": "elk"}} }%%
 flowchart TB
   %% I could not figure out how to use double quotes in labels in Mermaid
@@ -125,7 +125,7 @@ flowchart TB
 

-
+    
 flowchart TB
   %% I could not figure out how to use double quotes in labels in Mermaid
   subgraph ibm[IBM Espresso CPU]
@@ -227,14 +227,24 @@ sequenceDiagram
     Customer->>+Merchant: Receives goods or services
         
-
-      gantt
-        title Style today marker (vertical line should be 5px wide and half-transparent blue)
-        dateFormat YYYY-MM-DD
-        axisFormat %d
-        todayMarker stroke-width:5px,stroke:#00f,opacity:0.5
-        section Section1
-        Today: 1, -1h
+    
+mindmap
+  root((mindmap))
+    Origins
+      Long history
+      ::icon(fa fa-book)
+      Popularisation
+        British popular psychology author Tony Buzan
+    Research
+      On effectiveness
and features + On Automatic creation + Uses + Creative techniques + Strategic planning + Argument mapping + Tools + Pen and paper + Mermaid
@@ -252,7 +262,7 @@ sequenceDiagram // console.error('Mermaid error: ', err); }; mermaid.initialize({ - // theme: 'forest', + theme: 'dark', startOnLoad: true, logLevel: 0, flowchart: { diff --git a/packages/mermaid-mindmap/src/svgDraw.js b/packages/mermaid-mindmap/src/svgDraw.js index d4f57f1f1..e4a52ad98 100644 --- a/packages/mermaid-mindmap/src/svgDraw.js +++ b/packages/mermaid-mindmap/src/svgDraw.js @@ -203,14 +203,12 @@ const roundedRectBkg = function (elem, node) { * @returns {number} The height nodes dom element */ export const drawNode = function (elem, node, fullSection, conf) { - const section = (fullSection % MAX_SECTIONS) - 1; + const section = fullSection % MAX_SECTIONS; const nodeElem = elem.append('g'); node.section = section; nodeElem.attr( 'class', - (node.class ? node.class + ' ' : '') + - 'mindmap-node ' + - (section < 0 ? 'section-root' : 'section-' + section) + (node.class ? node.class + ' ' : '') + 'mindmap-node ' + ('section-' + section) ); const bkgElem = nodeElem.append('g'); From 80903e427ce2031002e2ac15f28bdf8d34cdc381 Mon Sep 17 00:00:00 2001 From: Knut Sveidqvist Date: Fri, 20 Jan 2023 10:18:26 +0100 Subject: [PATCH 3/5] #4012 Allowing multiple lines before the mindmap statement --- packages/mermaid-mindmap/src/mindmap.spec.js | 12 ++++++++++++ packages/mermaid-mindmap/src/parser/mindmap.jison | 9 ++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/packages/mermaid-mindmap/src/mindmap.spec.js b/packages/mermaid-mindmap/src/mindmap.spec.js index 2a2dd13bb..292d7ebf8 100644 --- a/packages/mermaid-mindmap/src/mindmap.spec.js +++ b/packages/mermaid-mindmap/src/mindmap.spec.js @@ -354,6 +354,18 @@ root expect(mm.nodeId).toEqual('root'); expect(mm.children.length).toEqual(2); + const child = mm.children[0]; + expect(child.nodeId).toEqual('A'); + const child2 = mm.children[1]; + expect(child2.nodeId).toEqual('B'); + }); + it('MMP-24 Handle rows above the mindmap declarations', function () { + let str = '\n \nmindmap\nroot\n A\n \n\n B'; + mindmap.parse(str); + const mm = mindmap.yy.getMindmap(); + expect(mm.nodeId).toEqual('root'); + expect(mm.children.length).toEqual(2); + const child = mm.children[0]; expect(child.nodeId).toEqual('A'); const child2 = mm.children[1]; diff --git a/packages/mermaid-mindmap/src/parser/mindmap.jison b/packages/mermaid-mindmap/src/parser/mindmap.jison index 651d9dc09..b604d3b1e 100644 --- a/packages/mermaid-mindmap/src/parser/mindmap.jison +++ b/packages/mermaid-mindmap/src/parser/mindmap.jison @@ -67,9 +67,16 @@ start // %{ : info document 'EOF' { return yy; } } : MINDMAP document { return yy; } | MINDMAP NL document { return yy; } - | SPACELIST MINDMAP document { return yy; } + | spaceLines MINDMAP document { return yy; } + | spaceLines MINDMAP NL document { return yy; } ; +spaceLines + : SPACELINE + | spaceLines SPACELINE + | spaceLines NL + ; + stop : NL {yy.getLogger().trace('Stop NL ');} | EOF {yy.getLogger().trace('Stop EOF ');} From bc56a7d4f1a9a171d5b70e6f3cf8fccfbf70c9f4 Mon Sep 17 00:00:00 2001 From: Knut Sveidqvist Date: Fri, 20 Jan 2023 10:21:13 +0100 Subject: [PATCH 4/5] #4012 Neater grammar for the rows before mindmap --- packages/mermaid-mindmap/src/mindmap.spec.js | 12 ++++++++++++ packages/mermaid-mindmap/src/parser/mindmap.jison | 13 ++++++++----- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/packages/mermaid-mindmap/src/mindmap.spec.js b/packages/mermaid-mindmap/src/mindmap.spec.js index 292d7ebf8..753804a5d 100644 --- a/packages/mermaid-mindmap/src/mindmap.spec.js +++ b/packages/mermaid-mindmap/src/mindmap.spec.js @@ -366,6 +366,18 @@ root expect(mm.nodeId).toEqual('root'); expect(mm.children.length).toEqual(2); + const child = mm.children[0]; + expect(child.nodeId).toEqual('A'); + const child2 = mm.children[1]; + expect(child2.nodeId).toEqual('B'); + }); + it('MMP-25 Handle rows above the mindmap declarations, no space', function () { + let str = '\n\n\nmindmap\nroot\n A\n \n\n B'; + mindmap.parse(str); + const mm = mindmap.yy.getMindmap(); + expect(mm.nodeId).toEqual('root'); + expect(mm.children.length).toEqual(2); + const child = mm.children[0]; expect(child.nodeId).toEqual('A'); const child2 = mm.children[1]; diff --git a/packages/mermaid-mindmap/src/parser/mindmap.jison b/packages/mermaid-mindmap/src/parser/mindmap.jison index b604d3b1e..d2f6bbf1a 100644 --- a/packages/mermaid-mindmap/src/parser/mindmap.jison +++ b/packages/mermaid-mindmap/src/parser/mindmap.jison @@ -65,11 +65,9 @@ start // %{ : info document 'EOF' { return yy; } } - : MINDMAP document { return yy; } - | MINDMAP NL document { return yy; } - | spaceLines MINDMAP document { return yy; } - | spaceLines MINDMAP NL document { return yy; } - ; + : mindMap + | spaceLines mindMap + ; spaceLines : SPACELINE @@ -77,6 +75,11 @@ spaceLines | spaceLines NL ; +mindMap + : MINDMAP document { return yy; } + | MINDMAP NL document { return yy; } + ; + stop : NL {yy.getLogger().trace('Stop NL ');} | EOF {yy.getLogger().trace('Stop EOF ');} From de8928b2d92e1684691682d339e2e17700939275 Mon Sep 17 00:00:00 2001 From: Knut Sveidqvist Date: Fri, 20 Jan 2023 12:48:06 +0100 Subject: [PATCH 5/5] #4016 Fix for max_sections in mindmap renderer --- packages/mermaid-mindmap/src/svgDraw.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/mermaid-mindmap/src/svgDraw.js b/packages/mermaid-mindmap/src/svgDraw.js index e4a52ad98..79eab6e1d 100644 --- a/packages/mermaid-mindmap/src/svgDraw.js +++ b/packages/mermaid-mindmap/src/svgDraw.js @@ -203,7 +203,7 @@ const roundedRectBkg = function (elem, node) { * @returns {number} The height nodes dom element */ export const drawNode = function (elem, node, fullSection, conf) { - const section = fullSection % MAX_SECTIONS; + const section = fullSection % (MAX_SECTIONS - 1); const nodeElem = elem.append('g'); node.section = section; nodeElem.attr( @@ -303,7 +303,7 @@ export const drawNode = function (elem, node, fullSection, conf) { }; export const drawEdge = function drawEdge(edgesElem, mindmap, parent, depth, fullSection) { - const section = (fullSection % MAX_SECTIONS) - 1; + const section = fullSection % (MAX_SECTIONS - 1); const sx = parent.x + parent.width / 2; const sy = parent.y + parent.height / 2; const ex = mindmap.x + mindmap.width / 2;