#1143 Adding support in grammar for multiple nodes in dependency declarations

This commit is contained in:
Knut Sveidqvist
2019-12-15 18:10:52 +01:00
parent 26fac9507e
commit 6598b1b10d
4 changed files with 29 additions and 18 deletions

View File

@@ -5,7 +5,7 @@
rel="stylesheet" rel="stylesheet"
/> />
<style> <style>
body {background: white} body {background: black}
h1 { color: white;} h1 { color: white;}
.arrowheadPath {fill: red;} .arrowheadPath {fill: red;}
@@ -17,17 +17,12 @@
<body> <body>
<h1>info below</h1> <h1>info below</h1>
<div style="display: flex;width: 100%; height: 100%"> <div style="display: flex;width: 100%; height: 100%">
<div class="mermaid" style="width: 100%; height: 100%">gantt <div class="mermaid" style="width: 100%; height: 100%">
dateFormat YYYY-MM-DD graph LR
axisFormat %d/%m a[gorillan vaggar]|b[apan hoppar]--> c --> d
title Adding GANTT diagram to mermaid subgraph "One Two"
excludes weekdays 2014-01-10 a1-->a2-->a3
end
apple :a, 2017-07-20, 1w
banana :crit, b, 2017-07-23, 1d
cherry :active, c, after b a, 1d
</div> </div>
</div> </div>
<script src="./mermaid.js"></script> <script src="./mermaid.js"></script>

View File

@@ -102,7 +102,7 @@ export const addVertex = function(_id, text, type, style, classes) {
* @param type * @param type
* @param linktext * @param linktext
*/ */
export const addLink = function(_start, _end, type, linktext) { export const addSingleLink = function(_start, _end, type, linktext) {
let start = _start; let start = _start;
let end = _end; let end = _end;
if (start[0].match(/\d/)) start = MERMAID_DOM_ID_PREFIX + start; if (start[0].match(/\d/)) start = MERMAID_DOM_ID_PREFIX + start;
@@ -127,6 +127,14 @@ export const addLink = function(_start, _end, type, linktext) {
} }
edges.push(edge); edges.push(edge);
}; };
export const addLink = function(_start, _end, type, linktext) {
let i, j;
for (i = 0; i < _start.length; i++) {
for (j = 0; j < _end.length; j++) {
addSingleLink(_start[i], _end[j], type, linktext);
}
}
};
/** /**
* Updates a link's line interpolation algorithm * Updates a link's line interpolation algorithm
@@ -490,6 +498,7 @@ export const indexNodes = function() {
}; };
export const getSubGraphs = function() { export const getSubGraphs = function() {
console.warn(subGraphs);
return subGraphs; return subGraphs;
}; };

View File

@@ -8,6 +8,7 @@
%lex %lex
%x string %x string
%x dir %x dir
%x vertex
%% %%
\%\%[^\n]*\n* /* do nothing */ \%\%[^\n]*\n* /* do nothing */
["] this.begin("string"); ["] this.begin("string");
@@ -19,6 +20,7 @@
"interpolate" return 'INTERPOLATE'; "interpolate" return 'INTERPOLATE';
"classDef" return 'CLASSDEF'; "classDef" return 'CLASSDEF';
"class" return 'CLASS'; "class" return 'CLASS';
"EPA" return 'EPA';
"click" return 'CLICK'; "click" return 'CLICK';
"graph" {if(yy.lex.firstGraph()){this.begin("dir");} return 'GRAPH';} "graph" {if(yy.lex.firstGraph()){this.begin("dir");} return 'GRAPH';}
"subgraph" return 'subgraph'; "subgraph" return 'subgraph';
@@ -94,6 +96,7 @@
"<" return 'TAGSTART'; "<" return 'TAGSTART';
">" return 'TAGEND'; ">" return 'TAGEND';
"^" return 'UP'; "^" return 'UP';
"\|" return 'SEP';
"v" return 'DOWN'; "v" return 'DOWN';
[A-Za-z]+ return 'ALPHA'; [A-Za-z]+ return 'ALPHA';
"\\]" return 'TRAPEND'; "\\]" return 'TRAPEND';
@@ -247,7 +250,7 @@ spaceList
statement statement
: verticeStatement separator : verticeStatement separator
{ $$=$1} { console.warn('finat vs', $1.nodes); $$=$1.nodes}
| styleStatement separator | styleStatement separator
{$$=[];} {$$=[];}
| linkStyleStatement separator | linkStyleStatement separator
@@ -285,12 +288,15 @@ separator: NEWLINE | SEMI | EOF ;
// {$$ = [$1];yy.setClass($1,$3)} // {$$ = [$1];yy.setClass($1,$3)}
// ; // ;
verticeStatement: verticeStatement link node { yy.addLink($1[0],$3[0],$2); $$ = $3.concat($1) }
|node { $$ = $1 } verticeStatement: verticeStatement link node { console.warn('vs',$1.stmt,$3); yy.addLink($1.stmt,$3,$2); $$ = { stmt: $3, nodes: $3.concat($1.nodes) } }
|node {console.warn('noda', $1); $$ = {stmt: $1, nodes:$1 }}
; ;
node: vertex node: vertex
{ $$ = [$1];} { console.warn('nod', $1);$$ = [$1];}
| node PIPE vertex
{ $$ = [$1[0], $3]; console.warn('pip', $1, $3, $$); }
| vertex STYLE_SEPARATOR idString | vertex STYLE_SEPARATOR idString
{$$ = [$1];yy.setClass($1,$3)} {$$ = [$1];yy.setClass($1,$3)}
; ;
@@ -348,7 +354,7 @@ vertex: idString SQS text SQE
| idString SQS text TAGSTART spaceList | idString SQS text TAGSTART spaceList
{$$ = $1;yy.addVertex($1,$3,'odd_right');} */ {$$ = $1;yy.addVertex($1,$3,'odd_right');} */
| idString | idString
{$$ = $1;yy.addVertex($1);} {console.warn('h: ', $1);$$ = $1;yy.addVertex($1);}
| idString spaceList | idString spaceList
{$$ = $1;yy.addVertex($1);} {$$ = $1;yy.addVertex($1);}
; ;

View File

@@ -16,6 +16,7 @@ describe('when parsing subgraphs', function() {
const subgraphs = flow.parser.yy.getSubGraphs(); const subgraphs = flow.parser.yy.getSubGraphs();
expect(subgraphs.length).toBe(1); expect(subgraphs.length).toBe(1);
const subgraph = subgraphs[0]; const subgraph = subgraphs[0];
expect(subgraph.nodes.length).toBe(2); expect(subgraph.nodes.length).toBe(2);
expect(subgraph.nodes[0]).toBe('a2'); expect(subgraph.nodes[0]).toBe('a2');
expect(subgraph.nodes[1]).toBe('a1'); expect(subgraph.nodes[1]).toBe('a1');