mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-21 08:19:43 +02:00
Merge pull request #1149 from mermaid-js/other/1143_utilze_browser_console_object_better
#1143 Adding support in grammar for multiple nodes in dependency decl…
This commit is contained in:
@@ -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
|
||||||
|
@@ -22,6 +22,16 @@ describe('[Singlenodes] when parsing', () => {
|
|||||||
expect(edges.length).toBe(0);
|
expect(edges.length).toBe(0);
|
||||||
expect(vert['A'].styles.length).toBe(0);
|
expect(vert['A'].styles.length).toBe(0);
|
||||||
});
|
});
|
||||||
|
it('should handle a single node with white space after it (SN1)', function() {
|
||||||
|
// Silly but syntactically correct
|
||||||
|
const res = flow.parser.parse('graph TD;A ;');
|
||||||
|
|
||||||
|
const vert = flow.parser.yy.getVertices();
|
||||||
|
const edges = flow.parser.yy.getEdges();
|
||||||
|
|
||||||
|
expect(edges.length).toBe(0);
|
||||||
|
expect(vert['A'].styles.length).toBe(0);
|
||||||
|
});
|
||||||
|
|
||||||
it('should handle a single square node', function() {
|
it('should handle a single square node', function() {
|
||||||
// Silly but syntactically correct
|
// Silly but syntactically correct
|
||||||
|
@@ -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");
|
||||||
@@ -94,6 +95,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 +249,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,72 +287,49 @@ 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) } }
|
||||||
|
| verticeStatement link node spaceList
|
||||||
|
{ /* console.warn('vs',$1.stmt,$3); */ yy.addLink($1.stmt,$3,$2); $$ = { stmt: $3, nodes: $3.concat($1.nodes) } }
|
||||||
|
|node spaceList {/*console.warn('noda', $1);*/ $$ = {stmt: $1, nodes:$1 }}
|
||||||
|
|node { /*console.warn('noda', $1);*/ $$ = {stmt: $1, nodes:$1 }}
|
||||||
;
|
;
|
||||||
|
|
||||||
node: vertex
|
node: vertex
|
||||||
{ $$ = [$1];}
|
{ /* console.warn('nod', $1); */ $$ = [$1];}
|
||||||
|
| node spaceList 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)}
|
||||||
;
|
;
|
||||||
|
|
||||||
vertex: idString SQS text SQE
|
vertex: idString SQS text SQE
|
||||||
{$$ = $1;yy.addVertex($1,$3,'square');}
|
{$$ = $1;yy.addVertex($1,$3,'square');}
|
||||||
| idString SQS text SQE spaceList
|
|
||||||
{$$ = $1;yy.addVertex($1,$3,'square');}
|
|
||||||
| idString PS PS text PE PE
|
| idString PS PS text PE PE
|
||||||
{$$ = $1;yy.addVertex($1,$4,'circle');}
|
{$$ = $1;yy.addVertex($1,$4,'circle');}
|
||||||
| idString PS PS text PE PE spaceList
|
|
||||||
{$$ = $1;yy.addVertex($1,$4,'circle');}
|
|
||||||
| idString '(-' text '-)'
|
| idString '(-' text '-)'
|
||||||
{$$ = $1;yy.addVertex($1,$3,'ellipse');}
|
{$$ = $1;yy.addVertex($1,$3,'ellipse');}
|
||||||
| idString '(-' text '-)' spaceList
|
|
||||||
{$$ = $1;yy.addVertex($1,$3,'ellipse');}
|
|
||||||
| idString STADIUMSTART text STADIUMEND
|
| idString STADIUMSTART text STADIUMEND
|
||||||
{$$ = $1;yy.addVertex($1,$3,'stadium');}
|
{$$ = $1;yy.addVertex($1,$3,'stadium');}
|
||||||
| idString STADIUMSTART text STADIUMEND spaceList
|
|
||||||
{$$ = $1;yy.addVertex($1,$3,'stadium');}
|
|
||||||
| idString PS text PE
|
| idString PS text PE
|
||||||
{$$ = $1;yy.addVertex($1,$3,'round');}
|
{$$ = $1;yy.addVertex($1,$3,'round');}
|
||||||
| idString PS text PE spaceList
|
|
||||||
{$$ = $1;yy.addVertex($1,$3,'round');}
|
|
||||||
| idString DIAMOND_START text DIAMOND_STOP
|
| idString DIAMOND_START text DIAMOND_STOP
|
||||||
{$$ = $1;yy.addVertex($1,$3,'diamond');}
|
{$$ = $1;yy.addVertex($1,$3,'diamond');}
|
||||||
| idString DIAMOND_START text DIAMOND_STOP spaceList
|
|
||||||
{$$ = $1;yy.addVertex($1,$3,'diamond');}
|
|
||||||
| idString DIAMOND_START DIAMOND_START text DIAMOND_STOP DIAMOND_STOP
|
| idString DIAMOND_START DIAMOND_START text DIAMOND_STOP DIAMOND_STOP
|
||||||
{$$ = $1;yy.addVertex($1,$4,'hexagon');}
|
{$$ = $1;yy.addVertex($1,$4,'hexagon');}
|
||||||
| idString DIAMOND_START DIAMOND_START text DIAMOND_STOP DIAMOND_STOP spaceList
|
|
||||||
{$$ = $1;yy.addVertex($1,$4,'hexagon');}
|
|
||||||
| idString TAGEND text SQE
|
| idString TAGEND text SQE
|
||||||
{$$ = $1;yy.addVertex($1,$3,'odd');}
|
{$$ = $1;yy.addVertex($1,$3,'odd');}
|
||||||
| idString TAGEND text SQE spaceList
|
|
||||||
{$$ = $1;yy.addVertex($1,$3,'odd');}
|
|
||||||
| idString TRAPSTART text TRAPEND
|
| idString TRAPSTART text TRAPEND
|
||||||
{$$ = $1;yy.addVertex($1,$3,'trapezoid');}
|
{$$ = $1;yy.addVertex($1,$3,'trapezoid');}
|
||||||
| idString TRAPSTART text TRAPEND spaceList
|
|
||||||
{$$ = $1;yy.addVertex($1,$3,'trapezoid');}
|
|
||||||
| idString INVTRAPSTART text INVTRAPEND
|
| idString INVTRAPSTART text INVTRAPEND
|
||||||
{$$ = $1;yy.addVertex($1,$3,'inv_trapezoid');}
|
{$$ = $1;yy.addVertex($1,$3,'inv_trapezoid');}
|
||||||
| idString INVTRAPSTART text INVTRAPEND spaceList
|
|
||||||
{$$ = $1;yy.addVertex($1,$3,'inv_trapezoid');}
|
|
||||||
| idString TRAPSTART text INVTRAPEND
|
| idString TRAPSTART text INVTRAPEND
|
||||||
{$$ = $1;yy.addVertex($1,$3,'lean_right');}
|
{$$ = $1;yy.addVertex($1,$3,'lean_right');}
|
||||||
| idString TRAPSTART text INVTRAPEND spaceList
|
|
||||||
{$$ = $1;yy.addVertex($1,$3,'lean_right');}
|
|
||||||
| idString INVTRAPSTART text TRAPEND
|
| idString INVTRAPSTART text TRAPEND
|
||||||
{$$ = $1;yy.addVertex($1,$3,'lean_left');}
|
{$$ = $1;yy.addVertex($1,$3,'lean_left');}
|
||||||
| idString INVTRAPSTART text TRAPEND spaceList
|
|
||||||
{$$ = $1;yy.addVertex($1,$3,'lean_left');}
|
|
||||||
/* | idString SQS text TAGSTART
|
|
||||||
{$$ = $1;yy.addVertex($1,$3,'odd_right');}
|
|
||||||
| idString SQS text TAGSTART spaceList
|
|
||||||
{$$ = $1;yy.addVertex($1,$3,'odd_right');} */
|
|
||||||
| idString
|
| idString
|
||||||
{$$ = $1;yy.addVertex($1);}
|
{ /*console.warn('h: ', $1);*/$$ = $1;yy.addVertex($1);}
|
||||||
| idString spaceList
|
|
||||||
{$$ = $1;yy.addVertex($1);}
|
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
||||||
|
@@ -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');
|
||||||
@@ -191,6 +192,15 @@ describe('when parsing subgraphs', function() {
|
|||||||
expect(edges[0].type).toBe('arrow');
|
expect(edges[0].type).toBe('arrow');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should handle subgraphs3', function() {
|
||||||
|
const res = flow.parser.parse('graph TD\nA-->B\nsubgraph myTitle \n\n c-->d \nend\n');
|
||||||
|
|
||||||
|
const vert = flow.parser.yy.getVertices();
|
||||||
|
const edges = flow.parser.yy.getEdges();
|
||||||
|
|
||||||
|
expect(edges[0].type).toBe('arrow');
|
||||||
|
});
|
||||||
|
|
||||||
it('should handle nested subgraphs', function() {
|
it('should handle nested subgraphs', function() {
|
||||||
const str =
|
const str =
|
||||||
'graph TD\n' +
|
'graph TD\n' +
|
||||||
|
@@ -49,7 +49,7 @@ line
|
|||||||
|
|
||||||
statement
|
statement
|
||||||
: STR VALUE {
|
: STR VALUE {
|
||||||
console.log('str:'+$1+' value: '+$2)
|
/*console.log('str:'+$1+' value: '+$2)*/
|
||||||
yy.addSection($1,yy.cleanupValue($2)); }
|
yy.addSection($1,yy.cleanupValue($2)); }
|
||||||
| title {yy.setTitle($1.substr(6));$$=$1.substr(6);}
|
| title {yy.setTitle($1.substr(6));$$=$1.substr(6);}
|
||||||
;
|
;
|
||||||
|
Reference in New Issue
Block a user