Skip to content

Commit

Permalink
Merge pull request #3 from knsv/master
Browse files Browse the repository at this point in the history
Merge from master
  • Loading branch information
bjowes committed Dec 20, 2014
2 parents e550ef9 + 9458bfb commit 6a1550f
Show file tree
Hide file tree
Showing 19 changed files with 2,259 additions and 1,070 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ graph LR;
C-->|Two|E[Result two];
```

Below is the new declaration of the graph which since 0.2.16 also is valid along with the old declaration of the graph as described in the graph example on the home wiki page.

```
graph LR
A[Hard edge] -->|Link text| B(Round edge)
B --> C{Decision}
C -->|One| D[Result one]
C -->|Two| E[Result two]
```


![Example 2](http://www.sveido.com/mermaid/img/ex2.png)


Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mermaid",
"version": "0.2.15",
"version": "0.2.16",
"authors": [
"knsv <[email protected]>"
],
Expand Down
818 changes: 525 additions & 293 deletions dist/mermaid.full.js

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions dist/mermaid.full.min.js

Large diffs are not rendered by default.

818 changes: 525 additions & 293 deletions dist/mermaid.slim.js

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions dist/mermaid.slim.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mermaid",
"version": "0.2.15",
"version": "0.2.16",
"description": "Markdownish syntax for generating flowcharts",
"main": "src/main.js",
"scripts": {
Expand Down
34 changes: 26 additions & 8 deletions src/diagrams/flowchart/parser/flow.jison
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
"." return 'DOT';
"<" return 'TAGSTART';
">" return 'TAGEND';
"^" return 'UP'
"v" return 'DOWN'
\-\-[x] return 'ARROW_CROSS';
\-\-\> return 'ARROW_POINT';
\-\-[o] return 'ARROW_CIRCLE';
Expand Down Expand Up @@ -120,17 +122,32 @@

expressions
: graphConfig statements EOF
| graphConfig statements
| graphConfig spaceListNewline statements EOF
{$$=$1;}
| graphConfig spaceListNewline statements
{$$=$1;}
;

graphConfig
: GRAPH SPACE DIR SEMI
: GRAPH SPACE DIR FirstStmtSeperator
{ 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
: statement spaceListNewline statements
| statement statements
| statement
;

Expand All @@ -150,15 +167,16 @@ spaceList

statement
: commentStatement NEWLINE
{$$='Comment';}
| verticeStatement SEMI
| styleStatement SEMI
| linkStyleStatement SEMI
| classDefStatement SEMI
| classStatement SEMI
| clickStatement SEMI
| verticeStatement separator
| styleStatement separator
| linkStyleStatement separator
| classDefStatement separator
| classStatement separator
| clickStatement separator
;

separator: NEWLINE | SEMI | EOF ;

verticeStatement:
vertex link vertex
{ yy.addLink($1,$3,$2);$$ = 'oy'}
Expand Down
174 changes: 95 additions & 79 deletions src/diagrams/flowchart/parser/flow.js

Large diffs are not rendered by default.

132 changes: 131 additions & 1 deletion src/diagrams/flowchart/parser/flow.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('when parsing ',function(){
flow.parser.yy = require('../graphDb');
flow.parser.yy.clear();
/*flow.parser.parse.parseError= function parseError(str, hash) {
console.log(str);
console.logconsole.log(str);
}*/
});

Expand All @@ -30,6 +30,84 @@ describe('when parsing ',function(){
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(){
var res = flow.parser.parse('graph TD;A --> B;');

Expand All @@ -46,6 +124,37 @@ describe('when parsing ',function(){
expect(edges[0].text).toBe('');
});

it('should handle a nodes and edges, a space between link and node and each line ending without semicolon',function(){
var res = flow.parser.parse('graph TD\nA --> B\n style e red');


var vert = flow.parser.yy.getVertices();
var edges = flow.parser.yy.getEdges();

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 statements ending without semicolon',function(){
var res = flow.parser.parse('graph TD\nA-->B\nB-->C');


var vert = flow.parser.yy.getVertices();
var edges = flow.parser.yy.getEdges();

expect(vert['A'].id).toBe('A');
expect(vert['B'].id).toBe('B');
expect(edges.length).toBe(2);
expect(edges[1].start).toBe('B');
expect(edges[1].end).toBe('C');
expect(edges[0].type).toBe('arrow');
expect(edges[0].text).toBe('');
});

it('should handle a comments',function(){
var res = flow.parser.parse('graph TD;\n%% CComment\n A-->B;');

Expand Down Expand Up @@ -199,6 +308,18 @@ describe('when parsing ',function(){
expect(edges[0].type).toBe('arrow_cross');
expect(edges[0].text).toBe('text including URL space');

});

it('should handle text on edges with space dir',function(){
var res = flow.parser.parse('graph TD;A--x|text including R TD space|B;');

var vert = flow.parser.yy.getVertices();
var edges = flow.parser.yy.getEdges();


expect(edges[0].type).toBe('arrow_cross');
expect(edges[0].text).toBe('text including R TD space');

});
it('should handle text on edges with graph keyword',function(){
var res = flow.parser.parse('graph TD;A--x|text including graph space|B;');
Expand Down Expand Up @@ -343,6 +464,15 @@ describe('when parsing ',function(){
expect(vert['C'].type).toBe('round');
expect(vert['C'].text).toBe('Chimpansen hoppar åäö <br> - ÅÄÖ');
});
xit('should handle text in vertices with åäö, minus and space and br',function(){
var res = flow.parser.parse('graph TD; A[Object&#40;foo,bar&#41;]-->B(Thing);');

var vert = flow.parser.yy.getVertices();
var edges = flow.parser.yy.getEdges();

expect(vert['C'].type).toBe('round');
expect(vert['C'].text).toBe(' A[Object&#40;foo,bar&#41;]-->B(Thing);');
});
it('should handle text in vertices with unicode chars',function(){
var res = flow.parser.parse('graph TD;A-->C(Начало);');

Expand Down
8 changes: 8 additions & 0 deletions src/diagrams/sequenceDiagram/parser/sequenceDiagram.jison
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
[\n]+ return 'NL';
\s+ /* skip whitespace */
\#[^\n]* /* skip comments */
\%%[^\n]* /* skip comments */
"participant" return 'participant';
"loop" return 'loop';
"end" return 'end';
"left of" return 'left_of';
"right of" return 'right_of';
"over" return 'over';
Expand All @@ -30,6 +33,7 @@
">>" return 'OPENARROW';
">" return 'ARROW';
:[^#\n]+ return 'MESSAGE';
"%%" return 'CMT';
<<EOF>> return 'EOF';
. return 'INVALID';

Expand Down Expand Up @@ -58,6 +62,10 @@ statement
| signal { $$='signal'; }
| note_statement { $$='note'; }
| 'title' message { yy.setTitle($2); }
| 'loop' ACTOR
{ yy.addSignal(undefined, undefined, $2, yy.LINETYPE.LOOP_START);$$='loop'; }
| 'end'
{ yy.addSignal(undefined, undefined, undefined, yy.LINETYPE.LOOP_END);$$='loop'; }
;

note_statement
Expand Down
Loading

0 comments on commit 6a1550f

Please sign in to comment.