Merge branch 'master' into text-labels

Conflicts:
	dist/mermaid.full.js
	dist/mermaid.full.min.js
	dist/mermaid.slim.js
	dist/mermaid.slim.min.js
	src/diagrams/flowchart/flowRenderer.js
	src/utils.js
	test/web_style.html
This commit is contained in:
Björn Weström
2015-01-13 21:50:05 +01:00
33 changed files with 3516 additions and 659 deletions

View File

@@ -38,6 +38,8 @@ exports.addVertices = function (vert, g) {
*/
var classStr = '';
//console.log(vertice.classes);
if(vertice.classes.length >0){
classStr = vertice.classes.join(" ");
}
@@ -58,6 +60,7 @@ exports.addVertices = function (vert, g) {
verticeText = vertice.text;
}
<<<<<<< HEAD
var labelTypeStr = '';
if(equals('html',mermaid_config.labelType)) {
labelTypeStr = 'html';
@@ -65,6 +68,9 @@ exports.addVertices = function (vert, g) {
verticeText = verticeText.replace(/<br>/g, "\n");
labelTypeStr = 'text';
}
=======
console.log(verticeText);
>>>>>>> master
var radious = 0;
var _shape = '';
@@ -115,16 +121,34 @@ exports.addEdges = function (edges, g) {
}
var style = '';
if(typeof edge.style !== 'undefined'){
edge.style.forEach(function(s){
style = style + s +';';
});
}
else{
switch(edge.stroke){
case 'normal':
style = 'stroke: #333; stroke-width: 1.5px;fill:none';
break;
case 'dotted':
style = 'stroke: #333; fill:none;stroke-width:2px;stroke-dasharray:3;';
break;
case 'thick':
style = 'stroke: #333; stroke-width: 3.5px;fill:none';
break;
}
}
// Add the edge to the graph
if (typeof edge.text === 'undefined') {
if(typeof edge.style === 'undefined'){
g.setEdge(edge.start, edge.end,{ style: "stroke: #333; stroke-width: 1.5px;fill:none", arrowheadStyle: "fill: #333", arrowhead: aHead},cnt);
g.setEdge(edge.start, edge.end,{ style: style, arrowhead: aHead},cnt);
}else{
g.setEdge(edge.start, edge.end, {
style: style, arrowheadStyle: "fill: #333", arrowhead: aHead
@@ -135,7 +159,11 @@ exports.addEdges = function (edges, g) {
else {
var edgeText = edge.text.replace(/<br>/g, "\n");
if(typeof edge.style === 'undefined'){
<<<<<<< HEAD
g.setEdge(edge.start, edge.end,{labelType: "text", style: "stroke: #333; stroke-width: 1.5px;fill:none", labelpos:'c', label: edgeText, arrowheadStyle: "fill: #333", arrowhead: aHead},cnt);
=======
g.setEdge(edge.start, edge.end,{labelType: "html",style: style, labelpos:'c', label: '<span style="background:#e8e8e8">'+edge.text+'</span>', arrowheadStyle: "fill: #333", arrowhead: aHead},cnt);
>>>>>>> master
}else{
g.setEdge(edge.start, edge.end, {
labelType: "text",style: style, arrowheadStyle: "fill: #333", label: edgeText, arrowhead: aHead
@@ -205,7 +233,10 @@ exports.draw = function (text, id,isDot) {
}
// Create the input mermaid.graph
var g = new dagreD3.graphlib.Graph({multigraph:true})
var g = new dagreD3.graphlib.Graph({
multigraph:true,
compound: true
})
.setGraph({
rankdir: dir,
marginx: 20,
@@ -216,9 +247,35 @@ exports.draw = function (text, id,isDot) {
return {};
});
var subGraphs = graph.getSubGraphs();
var i = 0;
subGraphs.forEach(function(subG){
i = i + 1;
var id = 'subG'+i;
graph.addVertex(id,undefined,undefined,undefined);
});
// Fetch the verices/nodes and edges/links from the parsed graph definition
var vert = graph.getVertices();
//console.log(vert);
var edges = graph.getEdges();
//g.setParent("A", "p");
//g.setParent("B", "p");
//console.log(subGraphs);
i = 0;
subGraphs.forEach(function(subG){
i = i + 1;
var id = 'subG'+i;
d3.selectAll('cluster').append('text');
subG.nodes.forEach(function(node){
//console.log('Setting node',node,' to subgraph '+id);
g.setParent(node,id);
});
});
exports.addVertices(vert, g);
exports.addEdges(edges, g);
@@ -294,8 +351,57 @@ exports.draw = function (text, id,isDot) {
// Run the renderer. This is what draws the final graph.
render(d3.select("#" + id + " g"), g);
var svgb = document.querySelector('#mermaidChart0');
/*
var xPos = document.querySelectorAll('.clusters rect')[0].x.baseVal.value;
var width = document.querySelectorAll('.clusters rect')[0].width.baseVal.value;
var cluster = d3.selectAll('.cluster');
var te = cluster.append('text');
te.attr('x', xPos+width/2);
te.attr('y', 12);
//te.stroke('black');
te.attr('id', 'apa12');
te.style('text-anchor', 'middle');
te.text('Title for cluster');
*/
// Center the graph
svg.attr("height", g.graph().height );
svg.attr("width", g.graph().width );
svg.attr("viewBox", svgb.getBBox().x + ' 0 '+ g.graph().width+' '+ g.graph().height);
setTimeout(function(){
console.log('Fixing titles');
var i = 0;
subGraphs.forEach(function(subG){
console.log('Setting id '+id);
var clusterRects = document.querySelectorAll('#' + id + ' .clusters rect');
var clusters = document.querySelectorAll('#' + id + ' .cluster');
if(subG.title !== 'undefined'){
console.log(clusterRects[i]);
var xPos = clusterRects[i].x.baseVal.value;
var yPos = clusterRects[i].y.baseVal.value;
var width = clusterRects[i].width.baseVal.value;
var cluster = d3.select(clusters[i]);
var te = cluster.append('text');
te.attr('x', xPos+width/2);
te.attr('y', yPos +14);
te.attr('fill', 'black');
te.attr('stroke','none');
te.attr('id', id+'Text');
te.style('text-anchor', 'middle');
console.log('Title '+subG.title);
console.log('i',i);
console.log('x'+xPos+width/2);
console.log('y'+xPos);
te.text(subG.title);
}
i = i + 1;
});
},200);
};

View File

@@ -5,6 +5,7 @@
var vertices = {};
var edges = [];
var classes = [];
var subGraphs = [];
var direction;
// Functions to be run after graph rendering
var funs = [];
@@ -63,6 +64,7 @@ exports.addLink = function (start, end, type, linktext) {
if (typeof type !== 'undefined') {
edge.type = type.type;
edge.stroke = type.stroke;
}
edges.push(edge);
};
@@ -197,6 +199,7 @@ exports.clear = function () {
classes = {};
edges = [];
funs = [];
subGraphs = [];
};
/**
*
@@ -205,3 +208,30 @@ exports.clear = function () {
exports.defaultStyle = function () {
return "fill:#ffa;stroke: #f66; stroke-width: 3px; stroke-dasharray: 5, 5;fill:#ffa;stroke: #666;";
};
/**
* Clears the internal graph db so that a new graph can be parsed.
*/
exports.addSubGraph = function (list, title) {
function uniq(a) {
var prims = {"boolean":{}, "number":{}, "string":{}}, objs = [];
return a.filter(function(item) {
var type = typeof item;
if(type in prims)
return prims[type].hasOwnProperty(item) ? false : (prims[type][item] = true);
else
return objs.indexOf(item) >= 0 ? false : objs.push(item);
});
}
var subG = [];
subG = uniq(subG.concat.apply(subG,list));
//console.log(subG);
subGraphs.push({nodes:subG,title:title});
};
exports.getSubGraphs = function (list) {
return subGraphs;
};

View File

@@ -10,31 +10,50 @@
"class" return 'CLASS';
"click" return 'CLICK';
"graph" return 'GRAPH';
"subgraph" return 'subgraph';
"end" return 'end';
"LR" return 'DIR';
"RL" return 'DIR';
"TB" return 'DIR';
"BT" return 'DIR';
"TD" return 'DIR';
"BR" return 'DIR';
[0-9] return 'NUM';
[0-9]+ return 'NUM';
\# return 'BRKT';
":" return 'COLON';
";" return 'SEMI';
"," return 'COMMA';
"=" return 'EQUALS';
"*" return 'MULT';
"." return 'DOT';
"<" return 'TAGSTART';
">" return 'TAGEND';
"^" return 'UP';
"v" return 'DOWN';
\-\-[x] return 'ARROW_CROSS';
\-\-\> return 'ARROW_POINT';
\-\-[o] return 'ARROW_CIRCLE';
\-\-\- return 'ARROW_OPEN';
\-\.\-[x] return 'DOTTED_ARROW_CROSS';
\-\.\-\> return 'DOTTED_ARROW_POINT';
\-\.\-[o] return 'DOTTED_ARROW_CIRCLE';
\-\.\- return 'DOTTED_ARROW_OPEN';
.\-[x] return 'DOTTED_ARROW_CROSS';
\.\-\> return 'DOTTED_ARROW_POINT';
\.\-[o] return 'DOTTED_ARROW_CIRCLE';
\.\- return 'DOTTED_ARROW_OPEN';
\=\=[x] return 'THICK_ARROW_CROSS';
\=\=\> return 'THICK_ARROW_POINT';
\=\=[o] return 'THICK_ARROW_CIRCLE';
\=\=[\=] return 'THICK_ARROW_OPEN';
\-\- return '--';
\-\. return '-.';
\=\= return '==';
\- return 'MINUS';
"." return 'DOT';
\+ return 'PLUS';
\% return 'PCT';
"=" return 'EQUALS';
\= return 'EQUALS';
[\u0021-\u0027\u002A-\u002E\u003F\u0041-\u005A\u0061-\u007A\u00AA\u00B5\u00BA\u00C0-\u00D6\u00D8-\u00F6]|
[\u0021-\u0027\u002A-\u002E\u003F\u0041-\u005A\u005C\u005F-\u007A\u00AA\u00B5\u00BA\u00C0-\u00D6\u00D8-\u00F6]|
[\u00F8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377]|
[\u037A-\u037D\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5]|
[\u03F7-\u0481\u048A-\u0527\u0531-\u0556\u0559\u0561-\u0587\u05D0-\u05EA]|
@@ -114,25 +133,47 @@
%left '^'
%start expressions
%start mermaidDoc
%% /* language grammar */
expressions
: graphConfig statements EOF
| graphConfig spaceListNewline statements EOF
{$$=$1;}
;
mermaidDoc: graphConfig document ;
document
: /* empty */
{ $$ = [];}
| document line
{
if($2 !== []){
$1.push($2);
}
$$=$1;}
;
line
: spaceListNewline statement
{$$=$2;}
| statement
{$$=$1;}
| SEMI
| EOF
;
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;}
;
statements
: statement spaceListNewline statements
| statement
;
FirstStmtSeperator
: SEMI | NEWLINE | spaceList NEWLINE ;
spaceListNewline
@@ -150,20 +191,36 @@ spaceList
statement
: commentStatement NEWLINE
{$$='Comment';}
| verticeStatement SEMI
| styleStatement SEMI
| linkStyleStatement SEMI
| classDefStatement SEMI
| classStatement SEMI
| clickStatement SEMI
{$$=[];}
| verticeStatement separator
{$$=$1}
| styleStatement separator
{$$=[];}
| linkStyleStatement separator
{$$=[];}
| classDefStatement separator
{$$=[];}
| classStatement separator
{$$=[];}
| clickStatement separator
{$$=[];}
| subgraph text separator document endStatement separator
{yy.addSubGraph($4,$2);}
| subgraph separator document endStatement separator
{yy.addSubGraph($3,undefined);}
;
endStatement: end
| SPACE endStatement
;
separator: NEWLINE | SEMI | EOF ;
verticeStatement:
vertex link vertex
{ yy.addLink($1,$3,$2);$$ = 'oy'}
{ yy.addLink($1,$3,$2);$$ = [$1,$3];}
| vertex
{$$ = 'yo';}
{$$ = [$1];}
;
vertex: alphaNum SQS text SQE
@@ -186,8 +243,6 @@ vertex: alphaNum SQS text SQE
{$$ = $1;yy.addVertex($1,$3,'odd');}
| alphaNum TAGEND text SQE SPACE
{$$ = $1;yy.addVertex($1,$3,'odd');}
| alphaNum TAGSTART text TAGEND
{$$ = $1;yy.addVertex($1,$3,'diamond');}
| alphaNum
{$$ = $1;yy.addVertex($1);}
| alphaNum SPACE
@@ -197,7 +252,7 @@ vertex: alphaNum SQS text SQE
alphaNum
: alphaNumStatement
{$$=$1;}
| alphaNumStatement alphaNum
| alphaNum alphaNumStatement
{$$=$1+''+$2;}
;
@@ -217,17 +272,45 @@ link: linkStatement arrowText
{$$ = $1;}
| linkStatement SPACE
{$$ = $1;}
| '--' SPACE text SPACE linkStatement
{$5.text = $3;$$ = $5;}
| '--' SPACE text SPACE linkStatement SPACE
{$5.text = $3;$$ = $5;}
| '-.' SPACE text SPACE linkStatement
{$5.text = $3;$$ = $5;}
| '-.' SPACE text SPACE linkStatement SPACE
{$5.text = $3;$$ = $5;}
| '==' SPACE text SPACE linkStatement
{$5.text = $3;$$ = $5;}
| '==' SPACE text SPACE linkStatement SPACE
{$5.text = $3;$$ = $5;}
;
linkStatement: ARROW_POINT
{$$ = {"type":"arrow"};}
{$$ = {"type":"arrow","stroke":"normal"};}
| ARROW_CIRCLE
{$$ = {"type":"arrow_circle"};}
{$$ = {"type":"arrow_circle","stroke":"normal"};}
| ARROW_CROSS
{$$ = {"type":"arrow_cross"};}
{$$ = {"type":"arrow_cross","stroke":"normal"};}
| ARROW_OPEN
{$$ = {"type":"arrow_open"};}
;
{$$ = {"type":"arrow_open","stroke":"normal"};}
| DOTTED_ARROW_POINT
{$$ = {"type":"arrow","stroke":"dotted"};}
| DOTTED_ARROW_CIRCLE
{$$ = {"type":"arrow_circle","stroke":"dotted"};}
| DOTTED_ARROW_CROSS
{$$ = {"type":"arrow_cross","stroke":"dotted"};}
| DOTTED_ARROW_OPEN
{$$ = {"type":"arrow_open","stroke":"dotted"};}
| THICK_ARROW_POINT
{$$ = {"type":"arrow","stroke":"thick"};}
| THICK_ARROW_CIRCLE
{$$ = {"type":"arrow_circle","stroke":"thick"};}
| THICK_ARROW_CROSS
{$$ = {"type":"arrow_cross","stroke":"thick"};}
| THICK_ARROW_OPEN
{$$ = {"type":"arrow_open","stroke":"thick"};}
;
arrowText:
PIPE text PIPE
@@ -250,7 +333,7 @@ commentText: commentToken
keywords
: STYLE | LINKSTYLE | CLASSDEF | CLASS | CLICK | GRAPH | DIR;
: STYLE | LINKSTYLE | CLASSDEF | CLASS | CLICK | GRAPH | DIR | subgraph | end ;
textNoTags: textNoTagsToken
@@ -296,13 +379,13 @@ style: styleComponent
{$$ = $1 + $2;}
;
styleComponent: ALPHA | COLON | MINUS | NUM | UNIT | SPACE | HEX | BRKT | DOT;
styleComponent: ALPHA | COLON | MINUS | NUM | UNIT | SPACE | HEX | BRKT | DOT | STYLE | PCT ;
/* Token lists */
commentToken : textToken | graphCodeTokens ;
textToken : textNoTagsToken | TAGSTART | TAGEND ;
textToken : textNoTagsToken | TAGSTART | TAGEND | '==' | '--' ;
textNoTagsToken: alphaNumToken | SPACE | MINUS | keywords ;

File diff suppressed because one or more lines are too long

View File

@@ -10,12 +10,12 @@ 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);
}*/
});
it('should handle a nodes and edges',function(){
var res = flow.parser.parse('graph TD;A-->B;');
var res = flow.parser.parse('graph TD;\nA-->B;');
var vert = flow.parser.yy.getVertices();
@@ -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;');
@@ -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;');
@@ -95,7 +204,7 @@ describe('when parsing ',function(){
});
it('it should handle a trailing whitespaces after statememnts',function(){
var res = flow.parser.parse('graph TD;\n\n\n %% CComment\n A-->B; \nB-->C;');
var res = flow.parser.parse('graph TD;\n\n\n %% CComment\n A-->B; \n B-->C;');
var vert = flow.parser.yy.getVertices();
@@ -139,76 +248,341 @@ describe('when parsing ',function(){
expect(edges[0].type).toBe('arrow_circle');
});
it('should handle text on edges without space',function(){
var res = flow.parser.parse('graph TD;A--x|textNoSpace|B;');
it('should handle subgraphs',function(){
var res = flow.parser.parse('graph TD;A-->B;subgraph myTitle;c-->d;end;');
var vert = flow.parser.yy.getVertices();
var edges = flow.parser.yy.getEdges();
expect(edges[0].type).toBe('arrow_cross');
expect(edges[0].type).toBe('arrow');
});
it('should handle text on edges without space and space between vertices and link',function(){
var res = flow.parser.parse('graph TD;A --x|textNoSpace| B;');
it('should handle subgraphs',function(){
var res = flow.parser.parse('graph TD\nA-->B\nsubgraph myTitle\nc-->d\nend\n');
var vert = flow.parser.yy.getVertices();
var edges = flow.parser.yy.getEdges();
expect(edges[0].type).toBe('arrow_cross');
expect(edges[0].type).toBe('arrow');
});
it('should handle text on edges with space',function(){
var res = flow.parser.parse('graph TD;A--x|text including space|B;');
it('should handle subgraphs',function(){
var res = flow.parser.parse('graph TD\nA-->B\nsubgraph myTitle\nc-->d\nend;');
var vert = flow.parser.yy.getVertices();
var edges = flow.parser.yy.getEdges();
expect(edges[0].type).toBe('arrow_cross');
expect(edges[0].type).toBe('arrow');
});
it('should handle text on edges with space',function(){
var res = flow.parser.parse('graph TD;A--x|text with / should work|B;');
it('should handle subgraphs',function(){
var res = flow.parser.parse('graph TD\nA-->B\nsubgraph myTitle\nc-- text -->d\nd-->e\n end;');
var vert = flow.parser.yy.getVertices();
var edges = flow.parser.yy.getEdges();
expect(edges[0].text).toBe('text with / should work');
expect(edges[0].type).toBe('arrow');
});
it('should handle text on edges with space CAPS',function(){
var res = flow.parser.parse('graph TD;A--x|text including CAPS space|B;');
it('should handle classDefs with style in classes',function(){
var res = flow.parser.parse('graph TD\nA-->B\nclassDef exClass font-style:bold;');
var vert = flow.parser.yy.getVertices();
var edges = flow.parser.yy.getEdges();
expect(edges[0].type).toBe('arrow_cross');
expect(edges[0].type).toBe('arrow');
});
it('should handle text on edges with space dir',function(){
var res = flow.parser.parse('graph TD;A--x|text including URL space|B;');
it('should handle classDefs with % in classes',function(){
var res = flow.parser.parse('graph TD\nA-->B\nclassDef exClass fill:#f96,stroke:#333,stroke-width:4px,font-size:50%,font-style:bold;');
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 URL space');
expect(edges[0].type).toBe('arrow');
});
it('should handle text on edges with graph keyword',function(){
var res = flow.parser.parse('graph TD;A--x|text including graph space|B;');
it('should handle style definitons with more then 1 digit in a row',function(){
var res = flow.parser.parse('graph TD\n' +
'A-->B1\n' +
'A-->B2\n' +
'A-->B3\n' +
'A-->B4\n' +
'A-->B5\n' +
'A-->B6\n' +
'A-->B7\n' +
'A-->B8\n' +
'A-->B9\n' +
'A-->B10\n' +
'A-->B11\n' +
'linkStyle 10 stroke-width:1px;');
var vert = flow.parser.yy.getVertices();
var edges = flow.parser.yy.getEdges();
expect(edges[0].text).toBe('text including graph space');
expect(edges[0].type).toBe('arrow');
});
describe("it should handle text on edges",function(){
it('it should handle text without space',function(){
var res = flow.parser.parse('graph TD;A--x|textNoSpace|B;');
var vert = flow.parser.yy.getVertices();
var edges = flow.parser.yy.getEdges();
expect(edges[0].type).toBe('arrow_cross');
});
it('should handle with space',function(){
var res = flow.parser.parse('graph TD;A--x|text including space|B;');
var vert = flow.parser.yy.getVertices();
var edges = flow.parser.yy.getEdges();
expect(edges[0].type).toBe('arrow_cross');
});
it('it should handle text with /',function(){
var res = flow.parser.parse('graph TD;A--x|text with / should work|B;');
var vert = flow.parser.yy.getVertices();
var edges = flow.parser.yy.getEdges();
expect(edges[0].text).toBe('text with / should work');
});
it('it should handle space and space between vertices and link',function(){
var res = flow.parser.parse('graph TD;A --x|textNoSpace| B;');
var vert = flow.parser.yy.getVertices();
var edges = flow.parser.yy.getEdges();
expect(edges[0].type).toBe('arrow_cross');
});
it('should handle space and CAPS',function(){
var res = flow.parser.parse('graph TD;A--x|text including CAPS space|B;');
var vert = flow.parser.yy.getVertices();
var edges = flow.parser.yy.getEdges();
expect(edges[0].type).toBe('arrow_cross');
});
it('should handle space and dir',function(){
var res = flow.parser.parse('graph TD;A--x|text including URL 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 URL space');
});
it('should handle space and dir (TD)',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 `',function(){
var res = flow.parser.parse('graph TD;A--x|text including `|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 `');
});
it('should handle keywords',function(){
var res = flow.parser.parse('graph TD;A--x|text including graph space|B;');
var vert = flow.parser.yy.getVertices();
var edges = flow.parser.yy.getEdges();
expect(edges[0].text).toBe('text including graph space');
});
});
describe("it should handle new line type notation",function() {
it('it should handle regular lines', function () {
var res = flow.parser.parse('graph TD;A-->B;');
var vert = flow.parser.yy.getVertices();
var edges = flow.parser.yy.getEdges();
expect(edges[0].stroke).toBe('normal');
});
it('it should handle dotted lines', function () {
var res = flow.parser.parse('graph TD;A-.->B;');
var vert = flow.parser.yy.getVertices();
var edges = flow.parser.yy.getEdges();
expect(edges[0].stroke).toBe('dotted');
});
it('it should handle dotted lines', function () {
var res = flow.parser.parse('graph TD;A==>B;');
var vert = flow.parser.yy.getVertices();
var edges = flow.parser.yy.getEdges();
expect(edges[0].stroke).toBe('thick');
});
it('it should handle text on lines', function () {
var res = flow.parser.parse('graph TD;A-- test text with == -->B;');
var vert = flow.parser.yy.getVertices();
var edges = flow.parser.yy.getEdges();
expect(edges[0].stroke).toBe('normal');
});
it('it should handle text on lines', function () {
var res = flow.parser.parse('graph TD;A-. test text with == .->B;');
var vert = flow.parser.yy.getVertices();
var edges = flow.parser.yy.getEdges();
expect(edges[0].stroke).toBe('dotted');
});
it('it should handle text on lines', function () {
var res = flow.parser.parse('graph TD;A== test text with -- ==>B;');
var vert = flow.parser.yy.getVertices();
var edges = flow.parser.yy.getEdges();
expect(edges[0].stroke).toBe('thick');
});
});
describe("it should handle text on edges using the new notation",function(){
it('it should handle text without space',function(){
var res = flow.parser.parse('graph TD;A-- textNoSpace --xB;');
var vert = flow.parser.yy.getVertices();
var edges = flow.parser.yy.getEdges();
expect(edges[0].type).toBe('arrow_cross');
});
it('it should handle text with multiple leading space',function(){
var res = flow.parser.parse('graph TD;A-- textNoSpace --xB;');
var vert = flow.parser.yy.getVertices();
var edges = flow.parser.yy.getEdges();
expect(edges[0].type).toBe('arrow_cross');
});
it('should handle with space',function(){
var res = flow.parser.parse('graph TD;A-- text including space --xB;');
var vert = flow.parser.yy.getVertices();
var edges = flow.parser.yy.getEdges();
expect(edges[0].type).toBe('arrow_cross');
});
it('it should handle text with /',function(){
var res = flow.parser.parse('graph TD;A -- text with / should work --x B;');
var vert = flow.parser.yy.getVertices();
var edges = flow.parser.yy.getEdges();
expect(edges[0].text).toBe('text with / should work');
});
it('it should handle space and space between vertices and link',function(){
var res = flow.parser.parse('graph TD;A -- textNoSpace --x B;');
var vert = flow.parser.yy.getVertices();
var edges = flow.parser.yy.getEdges();
expect(edges[0].type).toBe('arrow_cross');
});
it('should handle space and CAPS',function(){
var res = flow.parser.parse('graph TD;A-- text including CAPS space --xB;');
var vert = flow.parser.yy.getVertices();
var edges = flow.parser.yy.getEdges();
expect(edges[0].type).toBe('arrow_cross');
});
it('should handle space and dir',function(){
var res = flow.parser.parse('graph TD;A-- text including URL space --xB;');
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 URL space');
});
it('should handle space and dir (TD)',function(){
var res = flow.parser.parse('graph TD;A-- text including R TD space --xB;');
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 keywords',function(){
var res = flow.parser.parse('graph TD;A-- text including graph space --xB;');
var vert = flow.parser.yy.getVertices();
var edges = flow.parser.yy.getEdges();
expect(edges[0].text).toBe('text including graph space');
});
});
it('should handle multi-line text',function(){
var res = flow.parser.parse('graph TD;A--o|text space|B;\n B-->|more text with space|C;');
@@ -229,6 +603,7 @@ describe('when parsing ',function(){
expect(edges[1].text).toBe('more text with space');
});
it('should handle multiple edges',function(){
var res = flow.parser.parse('graph TD;A---|This is the 123 s text|B;\nA---|This is the second edge|B;');
var vert = flow.parser.yy.getVertices();
@@ -314,60 +689,79 @@ describe('when parsing ',function(){
expect(edges[0].text).toBe(',.?!+-*');
});
describe("it should handle text in vertices, ",function(){
it('should handle text in vertices with space',function(){
var res = flow.parser.parse('graph TD;A-->C(Chimpansen hoppar);');
it('it should handle space',function(){
var res = flow.parser.parse('graph TD;A-->C(Chimpansen hoppar);');
var vert = flow.parser.yy.getVertices();
var edges = flow.parser.yy.getEdges();
var vert = flow.parser.yy.getVertices();
var edges = flow.parser.yy.getEdges();
expect(vert['C'].type).toBe('round');
expect(vert['C'].text).toBe('Chimpansen hoppar');
expect(vert['C'].type).toBe('round');
expect(vert['C'].text).toBe('Chimpansen hoppar');
});
it('it should handle åäö and minus',function(){
var res = flow.parser.parse('graph TD;A-->C{Chimpansen hoppar åäö-ÅÄÖ};');
var vert = flow.parser.yy.getVertices();
var edges = flow.parser.yy.getEdges();
expect(vert['C'].type).toBe('diamond');
expect(vert['C'].text).toBe('Chimpansen hoppar åäö-ÅÄÖ');
});
it('it should handle with åäö, minus and space and br',function(){
var res = flow.parser.parse('graph TD;A-->C(Chimpansen hoppar åäö <br> - ÅÄÖ);');
var vert = flow.parser.yy.getVertices();
var edges = flow.parser.yy.getEdges();
expect(vert['C'].type).toBe('round');
expect(vert['C'].text).toBe('Chimpansen hoppar åäö <br> - ÅÄÖ');
});
xit('it should handle åäö, 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('it should handle unicode chars',function(){
var res = flow.parser.parse('graph TD;A-->C(Начало);');
var vert = flow.parser.yy.getVertices();
expect(vert['C'].text).toBe('Начало');
});
it('it should handle backslask',function(){
var res = flow.parser.parse('graph TD;A-->C(c:\\windows);');
var vert = flow.parser.yy.getVertices();
expect(vert['C'].text).toBe('c:\\windows');
});
it('it should handle CAPS',function(){
var res = flow.parser.parse('graph TD;A-->C(some CAPS);');
var vert = flow.parser.yy.getVertices();
var edges = flow.parser.yy.getEdges();
expect(vert['C'].type).toBe('round');
expect(vert['C'].text).toBe('some CAPS');
});
it('it should handle directions',function(){
var res = flow.parser.parse('graph TD;A-->C(some URL);');
var vert = flow.parser.yy.getVertices();
var edges = flow.parser.yy.getEdges();
expect(vert['C'].type).toBe('round');
expect(vert['C'].text).toBe('some URL');
});
});
it('should handle text in vertices with åäö and minus',function(){
var res = flow.parser.parse('graph TD;A-->C{Chimpansen hoppar åäö-ÅÄÖ};');
var vert = flow.parser.yy.getVertices();
var edges = flow.parser.yy.getEdges();
expect(vert['C'].type).toBe('diamond');
expect(vert['C'].text).toBe('Chimpansen hoppar åäö-ÅÄÖ');
});
it('should handle text in vertices with åäö, minus and space and br',function(){
var res = flow.parser.parse('graph TD;A-->C(Chimpansen hoppar åäö <br> - ÅÄÖ);');
var vert = flow.parser.yy.getVertices();
var edges = flow.parser.yy.getEdges();
expect(vert['C'].type).toBe('round');
expect(vert['C'].text).toBe('Chimpansen hoppar åäö <br> - ÅÄÖ');
});
it('should handle text in vertices with unicode chars',function(){
var res = flow.parser.parse('graph TD;A-->C(Начало);');
var vert = flow.parser.yy.getVertices();
expect(vert['C'].text).toBe('Начало');
});
it('should handle text in vertices with CAPS',function(){
var res = flow.parser.parse('graph TD;A-->C(some CAPS);');
var vert = flow.parser.yy.getVertices();
var edges = flow.parser.yy.getEdges();
expect(vert['C'].type).toBe('round');
expect(vert['C'].text).toBe('some CAPS');
});
it('should handle text in vertices with directions',function(){
var res = flow.parser.parse('graph TD;A-->C(some URL);');
var vert = flow.parser.yy.getVertices();
var edges = flow.parser.yy.getEdges();
expect(vert['C'].type).toBe('round');
expect(vert['C'].text).toBe('some URL');
});
it('should handle a single node',function(){
// Silly but syntactically correct
var res = flow.parser.parse('graph TD;A;');