mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-05 16:46:43 +02:00
Merge pull request #66 from vijay40/master
Allow special symbols for direction along with acronyms
This commit is contained in:
@@ -26,6 +26,8 @@
|
|||||||
"." return 'DOT';
|
"." return 'DOT';
|
||||||
"<" return 'TAGSTART';
|
"<" return 'TAGSTART';
|
||||||
">" return 'TAGEND';
|
">" return 'TAGEND';
|
||||||
|
"^" return 'UP'
|
||||||
|
"v" return 'DOWN'
|
||||||
\-\-[x] return 'ARROW_CROSS';
|
\-\-[x] return 'ARROW_CROSS';
|
||||||
\-\-\> return 'ARROW_POINT';
|
\-\-\> return 'ARROW_POINT';
|
||||||
\-\-[o] return 'ARROW_CIRCLE';
|
\-\-[o] return 'ARROW_CIRCLE';
|
||||||
@@ -128,14 +130,21 @@ expressions
|
|||||||
;
|
;
|
||||||
|
|
||||||
graphConfig
|
graphConfig
|
||||||
: GRAPH SPACE DIR SEMI
|
: GRAPH SPACE DIR FirstStmtSeperator
|
||||||
{ yy.setDirection($3);$$ = $3;}
|
|
||||||
| GRAPH SPACE DIR NEWLINE
|
|
||||||
{ yy.setDirection($3);$$ = $3;}
|
|
||||||
| GRAPH SPACE DIR spaceList NEWLINE
|
|
||||||
{ yy.setDirection($3);$$ = $3;}
|
{ yy.setDirection($3);$$ = $3;}
|
||||||
|
| GRAPH SPACE TAGEND FirstStmtSeperator
|
||||||
|
{ yy.setDirection("LR");$$ = $3;}
|
||||||
|
| GRAPH SPACE TAGSTART FirstStmtSeperator
|
||||||
|
{ yy.setDirection("RL");$$ = $3;}
|
||||||
|
| GRAPH SPACE UP FirstStmtSeperator
|
||||||
|
{ yy.setDirection("BT");$$ = $3;}
|
||||||
|
| GRAPH SPACE DOWN FirstStmtSeperator
|
||||||
|
{ yy.setDirection("TB");$$ = $3;}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
FirstStmtSeperator
|
||||||
|
: SEMI | NEWLINE | spaceList NEWLINE ;
|
||||||
|
|
||||||
statements
|
statements
|
||||||
: statement spaceListNewline statements
|
: statement spaceListNewline statements
|
||||||
| statement statements
|
| statement statements
|
||||||
|
File diff suppressed because one or more lines are too long
@@ -30,6 +30,84 @@ describe('when parsing ',function(){
|
|||||||
expect(edges[0].text).toBe('');
|
expect(edges[0].text).toBe('');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should handle angle bracket '>' as direction LR',function(){
|
||||||
|
var res = flow.parser.parse('graph >;A-->B;');
|
||||||
|
|
||||||
|
|
||||||
|
var vert = flow.parser.yy.getVertices();
|
||||||
|
var edges = flow.parser.yy.getEdges();
|
||||||
|
var direction = flow.parser.yy.getDirection();
|
||||||
|
|
||||||
|
expect(direction).toBe('LR');
|
||||||
|
|
||||||
|
expect(vert['A'].id).toBe('A');
|
||||||
|
expect(vert['B'].id).toBe('B');
|
||||||
|
expect(edges.length).toBe(1);
|
||||||
|
expect(edges[0].start).toBe('A');
|
||||||
|
expect(edges[0].end).toBe('B');
|
||||||
|
expect(edges[0].type).toBe('arrow');
|
||||||
|
expect(edges[0].text).toBe('');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle angle bracket '<' as direction RL',function(){
|
||||||
|
var res = flow.parser.parse('graph <;A-->B;');
|
||||||
|
|
||||||
|
|
||||||
|
var vert = flow.parser.yy.getVertices();
|
||||||
|
var edges = flow.parser.yy.getEdges();
|
||||||
|
var direction = flow.parser.yy.getDirection();
|
||||||
|
|
||||||
|
expect(direction).toBe('RL');
|
||||||
|
|
||||||
|
expect(vert['A'].id).toBe('A');
|
||||||
|
expect(vert['B'].id).toBe('B');
|
||||||
|
expect(edges.length).toBe(1);
|
||||||
|
expect(edges[0].start).toBe('A');
|
||||||
|
expect(edges[0].end).toBe('B');
|
||||||
|
expect(edges[0].type).toBe('arrow');
|
||||||
|
expect(edges[0].text).toBe('');
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
it('should handle caret '^' as direction BT',function(){
|
||||||
|
var res = flow.parser.parse('graph ^;A-->B;');
|
||||||
|
|
||||||
|
|
||||||
|
var vert = flow.parser.yy.getVertices();
|
||||||
|
var edges = flow.parser.yy.getEdges();
|
||||||
|
var direction = flow.parser.yy.getDirection();
|
||||||
|
|
||||||
|
expect(direction).toBe('BT');
|
||||||
|
|
||||||
|
expect(vert['A'].id).toBe('A');
|
||||||
|
expect(vert['B'].id).toBe('B');
|
||||||
|
expect(edges.length).toBe(1);
|
||||||
|
expect(edges[0].start).toBe('A');
|
||||||
|
expect(edges[0].end).toBe('B');
|
||||||
|
expect(edges[0].type).toBe('arrow');
|
||||||
|
expect(edges[0].text).toBe('');
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
it('should handle lower-case \'v\' as direction TB',function(){
|
||||||
|
var res = flow.parser.parse('graph v;A-->B;');
|
||||||
|
|
||||||
|
|
||||||
|
var vert = flow.parser.yy.getVertices();
|
||||||
|
var edges = flow.parser.yy.getEdges();
|
||||||
|
var direction = flow.parser.yy.getDirection();
|
||||||
|
|
||||||
|
expect(direction).toBe('TB');
|
||||||
|
|
||||||
|
expect(vert['A'].id).toBe('A');
|
||||||
|
expect(vert['B'].id).toBe('B');
|
||||||
|
expect(edges.length).toBe(1);
|
||||||
|
expect(edges[0].start).toBe('A');
|
||||||
|
expect(edges[0].end).toBe('B');
|
||||||
|
expect(edges[0].type).toBe('arrow');
|
||||||
|
expect(edges[0].text).toBe('');
|
||||||
|
});
|
||||||
|
|
||||||
it('should handle a nodes and edges and a space between link and node',function(){
|
it('should handle a nodes and edges and a space between link and node',function(){
|
||||||
var res = flow.parser.parse('graph TD;A --> B;');
|
var res = flow.parser.parse('graph TD;A --> B;');
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user