Support for class definitions for nodes

Support multiple edges from one node to another
This commit is contained in:
knsv 2014-11-22 15:34:21 +01:00
parent 983c48c26b
commit 472310fbef
10 changed files with 575 additions and 255 deletions

246
dist/mermaid.full.js vendored
View File

@ -338,20 +338,36 @@ var flow = require('./parser/flow');
var addVertices = function (vert, g) {
var keys = Object.keys(vert);
var styleFromStyleArr = function(styleStr,arr){
var i;
// Create a compound style definition from the style definitions found for the node in the graph definition
for (i = 0; i < arr.length; i++) {
if (typeof arr[i] !== 'undefined') {
styleStr = styleStr + arr[i] + ';';
}
}
return styleStr;
}
// Iterate through each item in the vertice object (containing all the vertices found) in the graph definition
keys.forEach(function (id) {
var vertice = vert[id];
var verticeText;
var i;
var style = '';
// Create a compound style definition from the style definitions found for the node in the graph definition
for (i = 0; i < vertice.styles.length; i++) {
if (typeof vertice.styles[i] !== 'undefined') {
style = style + vertice.styles[i] + ';';
}
var classes = graph.getClasses();
// Check if class is defined for the node
for (i = 0; i < vertice.classes.length; i++) {
style = styleFromStyleArr(style,classes[vertice.classes[i]].styles);
}
// Create a compound style definition from the style definitions found for the node in the graph definition
style = styleFromStyleArr(style, vertice.styles);
// Use vertice id as text in the box if no text is provided by the graph definition
if (vertice.text === undefined) {
verticeText = vertice.id;
@ -360,7 +376,7 @@ var addVertices = function (vert, g) {
verticeText = vertice.text;
}
// Create the node in the graph nased on defined form
// Create the node in the graph based on defined form
if (vertice.type === 'round') {
g.setNode(vertice.id, {label: verticeText, rx: 5, ry: 5, style: style});
} else {
@ -379,7 +395,9 @@ var addVertices = function (vert, g) {
* @param g
*/
var addEdges = function (edges, g) {
var cnt=0;
edges.forEach(function (edge) {
cnt++;
// Set link type for rendering
if(edge.type === 'arrow_open'){
@ -390,22 +408,26 @@ var addEdges = function (edges, g) {
}
// Add the edge to the graph
if (edge.text === 'undefined') {
if (typeof edge.text === 'undefined') {
if(typeof edge.style === 'undefined'){
g.setEdge(edge.start, edge.end,{ arrowheadStyle: "fill: #333", arrowhead: aHead});
g.setEdge(edge.start, edge.end,{ arrowheadStyle: "fill: #333", arrowhead: aHead},cnt);
}else{
g.setEdge(edge.start, edge.end, {
style: edge.style, arrowheadStyle: "fill: #333", arrowhead: aHead
});
},cnt);
}
}
// Edge with text
else {
if(typeof edge.style === 'undefined'){
g.setEdge(edge.start, edge.end,{label: edge.text, arrowheadStyle: "fill: #33f", arrowhead: aHead});
console.log('Edge with Text no style: '+edge.text);
g.setEdge(edge.start, edge.end,{label: edge.text, arrowheadStyle: "fill: #33f", arrowhead: aHead},cnt);
}else{
g.setEdge(edge.start, edge.end, {
style: edge.style, arrowheadStyle: "fill: #333", label: edge.text, arrowhead: aHead
});
},cnt);
}
}
});
@ -431,11 +453,12 @@ var drawChart = function (text, id) {
}
// Create the input mermaid.graph
var g = new dagreD3.graphlib.Graph()
var g = new dagreD3.graphlib.Graph({multigraph:true})
.setGraph({
rankdir: dir,
marginx: 20,
marginy: 20
})
.setDefaultEdgeLabel(function () {
return {};
@ -582,6 +605,7 @@ global.mermaid = {
var vertices = {};
var edges = [];
var classes = [];
var direction;
/**
* Function called by parser when a node definition has been found
@ -591,9 +615,9 @@ var direction;
* @param style
*/
exports.addVertex = function (id, text, type, style) {
console.log('Got node ' + id + ' ' + type + ' ' + text + ' styles: ' + JSON.stringify(style));
//console.log('Got node ' + id + ' ' + type + ' ' + text + ' styles: ' + JSON.stringify(style));
if (typeof vertices[id] === 'undefined') {
vertices[id] = {id: id, styles: []};
vertices[id] = {id: id, styles: [], classes:[]};
}
if (typeof text !== 'undefined') {
vertices[id].text = text;
@ -601,6 +625,9 @@ exports.addVertex = function (id, text, type, style) {
if (typeof type !== 'undefined') {
vertices[id].type = type;
}
if (typeof type !== 'undefined') {
vertices[id].type = type;
}
if (typeof style !== 'undefined') {
if (style !== null) {
style.forEach(function (s) {
@ -637,6 +664,22 @@ exports.updateLink = function (pos, style) {
var position = pos.substr(1);
edges[position].style = style;
};
exports.addClass = function (id, style) {
if (typeof classes[id] === 'undefined') {
classes[id] = {id: id, styles: []};
}
if (typeof style !== 'undefined') {
if (style !== null) {
style.forEach(function (s) {
console.log('Adding style'+s)
classes[id].styles.push(s);
});
}
}
};
/**
* Called by parser when a graph definition is found, stores the direction of the chart.
* @param dir
@ -644,6 +687,26 @@ exports.updateLink = function (pos, style) {
exports.setDirection = function (dir) {
direction = dir;
};
/**
* Called by parser when a graph definition is found, stores the direction of the chart.
* @param dir
*/
exports.setClass = function (id,className) {
console.log('Got id:'+id);
if(id.indexOf(',')>0){
id.split(',').forEach(function(id2){
if(typeof vertices[id2] !== 'undefined'){
vertices[id2].classes.push(className);
}
});
}else{
if(typeof vertices[id] !== 'undefined'){
vertices[id].classes.push(className);
}
}
};
exports.getDirection = function () {
return direction;
};
@ -663,11 +726,20 @@ exports.getEdges = function () {
return edges;
};
/**
* Retrieval function for fetching the found class definitions after parsing has completed.
* @returns {{}|*|classes}
*/
exports.getClasses = function () {
return classes;
};
/**
* Clears the internal graph db so that a new graph can be parsed.
*/
exports.clear = function () {
vertices = {};
classes = {};
edges = [];
};
/**
@ -755,12 +827,12 @@ exports.defaultStyle = function () {
}
*/
var parser = (function(){
var o=function(k,v,o,l){for(o=o||{},l=k.length;l--;o[k[l]]=v);return o},$V0=[1,7],$V1=[2,10],$V2=[1,15],$V3=[1,16],$V4=[1,17],$V5=[1,18],$V6=[1,19],$V7=[1,20],$V8=[1,21],$V9=[1,22],$Va=[1,23],$Vb=[1,24],$Vc=[1,11],$Vd=[6,9],$Ve=[11,27,28,29,30,31,32,33,34,35,36,37,45],$Vf=[2,7],$Vg=[11,40,41,42,43],$Vh=[9,11,18,20,21,22,23,24,40,41,42,43,44],$Vi=[9,11,18,20,21,22,23,24,28,29,30,31,32,33,34,35,36,37,40,41,42,43,44],$Vj=[9,11,18,20,21,22,23,24,27,28,29,30,31,32,33,34,35,36,37,40,41,42,43,44],$Vk=[28,29,30,31,32,33,34,35,36,37],$Vl=[28,29,30,31,32,33,34,35,36,37,44],$Vm=[20,22,24,44],$Vn=[1,75],$Vo=[1,72],$Vp=[1,70],$Vq=[1,73],$Vr=[1,71],$Vs=[1,76],$Vt=[1,74],$Vu=[1,80],$Vv=[11,31],$Vw=[9,11,27,28,29,30,31,47,50];
var o=function(k,v,o,l){for(o=o||{},l=k.length;l--;o[k[l]]=v);return o},$V0=[1,7],$V1=[2,12],$V2=[1,19],$V3=[1,20],$V4=[1,21],$V5=[1,22],$V6=[1,23],$V7=[1,24],$V8=[1,25],$V9=[1,26],$Va=[1,27],$Vb=[1,28],$Vc=[1,14],$Vd=[1,15],$Ve=[1,13],$Vf=[6,9],$Vg=[11,29,30,31,32,33,34,35,36,37,38,39,47,49,50],$Vh=[2,7],$Vi=[11,42,43,44,45],$Vj=[9,11,20,22,23,24,25,26,42,43,44,45,46],$Vk=[9,11,20,22,23,24,25,26,30,31,32,33,34,35,36,37,38,39,42,43,44,45,46],$Vl=[9,11,20,22,23,24,25,26,29,30,31,32,33,34,35,36,37,38,39,42,43,44,45,46],$Vm=[30,31,32,33,34,35,36,37,38,39],$Vn=[30,31,32,33,34,35,36,37,38,39,46],$Vo=[22,24,26,46],$Vp=[1,87],$Vq=[1,84],$Vr=[1,82],$Vs=[1,85],$Vt=[1,83],$Vu=[1,88],$Vv=[1,86],$Vw=[1,94],$Vx=[11,33],$Vy=[9,11,29,30,31,32,33,51,54];
var parser = {trace: function trace() { },
yy: {},
symbols_: {"error":2,"expressions":3,"graphConfig":4,"statements":5,"EOF":6,"spaceList":7,"GRAPH":8,"SPACE":9,"DIR":10,"SEMI":11,"statement":12,"verticeStatement":13,"styleStatement":14,"vertex":15,"link":16,"alphaNum":17,"SQS":18,"text":19,"SQE":20,"PS":21,"PE":22,"DIAMOND_START":23,"DIAMOND_STOP":24,"alphaNumStatement":25,"alphaNumToken":26,"MINUS":27,"ALPHA":28,"NUM":29,"COLON":30,"COMMA":31,"PLUS":32,"EQUALS":33,"MULT":34,"DOT":35,"TAGSTART":36,"TAGEND":37,"linkStatement":38,"arrowText":39,"ARROW_POINT":40,"ARROW_CIRCLE":41,"ARROW_CROSS":42,"ARROW_OPEN":43,"PIPE":44,"STYLE":45,"stylesOpt":46,"HEX":47,"style":48,"styleComponent":49,"UNIT":50,"$accept":0,"$end":1},
terminals_: {2:"error",6:"EOF",8:"GRAPH",9:"SPACE",10:"DIR",11:"SEMI",18:"SQS",20:"SQE",21:"PS",22:"PE",23:"DIAMOND_START",24:"DIAMOND_STOP",27:"MINUS",28:"ALPHA",29:"NUM",30:"COLON",31:"COMMA",32:"PLUS",33:"EQUALS",34:"MULT",35:"DOT",36:"TAGSTART",37:"TAGEND",40:"ARROW_POINT",41:"ARROW_CIRCLE",42:"ARROW_CROSS",43:"ARROW_OPEN",44:"PIPE",45:"STYLE",47:"HEX",50:"UNIT"},
productions_: [0,[3,3],[3,4],[4,4],[5,3],[5,1],[7,2],[7,1],[12,2],[12,2],[13,0],[13,3],[13,1],[15,4],[15,4],[15,4],[15,1],[17,1],[17,2],[25,1],[25,3],[26,1],[26,1],[26,1],[26,1],[26,1],[26,1],[26,1],[26,1],[26,1],[26,1],[16,2],[16,1],[38,1],[38,1],[38,1],[38,1],[39,3],[19,3],[19,5],[19,1],[14,5],[14,5],[46,1],[46,3],[48,1],[48,2],[49,1],[49,1],[49,1],[49,1],[49,1],[49,1],[49,1]],
symbols_: {"error":2,"expressions":3,"graphConfig":4,"statements":5,"EOF":6,"spaceList":7,"GRAPH":8,"SPACE":9,"DIR":10,"SEMI":11,"statement":12,"verticeStatement":13,"styleStatement":14,"classDefStatement":15,"classStatement":16,"vertex":17,"link":18,"alphaNum":19,"SQS":20,"text":21,"SQE":22,"PS":23,"PE":24,"DIAMOND_START":25,"DIAMOND_STOP":26,"alphaNumStatement":27,"alphaNumToken":28,"MINUS":29,"ALPHA":30,"NUM":31,"COLON":32,"COMMA":33,"PLUS":34,"EQUALS":35,"MULT":36,"DOT":37,"TAGSTART":38,"TAGEND":39,"linkStatement":40,"arrowText":41,"ARROW_POINT":42,"ARROW_CIRCLE":43,"ARROW_CROSS":44,"ARROW_OPEN":45,"PIPE":46,"CLASSDEF":47,"stylesOpt":48,"CLASS":49,"STYLE":50,"HEX":51,"style":52,"styleComponent":53,"UNIT":54,"$accept":0,"$end":1},
terminals_: {2:"error",6:"EOF",8:"GRAPH",9:"SPACE",10:"DIR",11:"SEMI",20:"SQS",22:"SQE",23:"PS",24:"PE",25:"DIAMOND_START",26:"DIAMOND_STOP",29:"MINUS",30:"ALPHA",31:"NUM",32:"COLON",33:"COMMA",34:"PLUS",35:"EQUALS",36:"MULT",37:"DOT",38:"TAGSTART",39:"TAGEND",42:"ARROW_POINT",43:"ARROW_CIRCLE",44:"ARROW_CROSS",45:"ARROW_OPEN",46:"PIPE",47:"CLASSDEF",49:"CLASS",50:"STYLE",51:"HEX",54:"UNIT"},
productions_: [0,[3,3],[3,4],[4,4],[5,3],[5,1],[7,2],[7,1],[12,2],[12,2],[12,2],[12,2],[13,0],[13,3],[13,1],[17,4],[17,4],[17,4],[17,1],[19,1],[19,2],[27,1],[27,3],[28,1],[28,1],[28,1],[28,1],[28,1],[28,1],[28,1],[28,1],[28,1],[28,1],[18,2],[18,1],[40,1],[40,1],[40,1],[40,1],[41,3],[21,3],[21,5],[21,1],[15,5],[16,5],[14,5],[14,5],[48,1],[48,3],[52,1],[52,2],[53,1],[53,1],[53,1],[53,1],[53,1],[53,1],[53,1]],
performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate /* action[1] */, $$ /* vstack */, _$ /* lstack */) {
/* this == yyval */
@ -772,82 +844,88 @@ break;
case 3:
yy.setDirection($$[$0-1]);this.$ = $$[$0-1];
break;
case 11:
case 13:
yy.addLink($$[$0-2],$$[$0],$$[$0-1]);this.$ = 'oy'
break;
case 12:
case 14:
this.$ = 'yo';
break;
case 13:
case 15:
this.$ = $$[$0-3];yy.addVertex($$[$0-3],$$[$0-1],'square');
break;
case 14:
case 16:
this.$ = $$[$0-3];yy.addVertex($$[$0-3],$$[$0-1],'round');
break;
case 15:
case 17:
this.$ = $$[$0-3];yy.addVertex($$[$0-3],$$[$0-1],'diamond');
break;
case 16:
case 18:
this.$ = $$[$0];yy.addVertex($$[$0]);
break;
case 17: case 19: case 21: case 22: case 45:
case 19: case 21: case 23: case 24: case 49:
this.$=$$[$0];
break;
case 18:
case 20:
this.$=$$[$0-1]+''+$$[$0];
break;
case 20:
case 22:
this.$=$$[$0-2]+'-'+$$[$0];
break;
case 23: case 24: case 25: case 26: case 27: case 28: case 29: case 30: case 32: case 40:
case 25: case 26: case 27: case 28: case 29: case 30: case 31: case 32: case 34: case 42:
this.$ = $$[$0];
break;
case 31:
case 33:
$$[$0-1].text = $$[$0];this.$ = $$[$0-1];
break;
case 33:
case 35:
this.$ = {"type":"arrow"};
break;
case 34:
case 36:
this.$ = {"type":"arrow_circle"};
break;
case 35:
case 37:
this.$ = {"type":"arrow_cross"};
break;
case 36:
case 38:
this.$ = {"type":"arrow_open"};
break;
case 37:
case 39:
this.$ = $$[$0-1];
break;
case 38:
case 40:
this.$ = $$[$0-2] + ' ' +$$[$0];
break;
case 39:
case 41:
this.$ = $$[$0-4] + ' - ' +$$[$0];
break;
case 41:
this.$ = $$[$0-4];yy.addVertex($$[$0-2],undefined,undefined,$$[$0]);
break;
case 42:
this.$ = $$[$0-4];yy.updateLink($$[$0-2],$$[$0]);
break;
case 43:
this.$ = [$$[$0]]
this.$ = $$[$0-4];yy.addClass($$[$0-2],$$[$0]);
break;
case 44:
$$[$0-2].push($$[$0]);this.$ = $$[$0-2];
this.$ = $$[$0-4];yy.setClass($$[$0-2], $$[$0]);
break;
case 45:
this.$ = $$[$0-4];yy.addVertex($$[$0-2],undefined,undefined,$$[$0]);
break;
case 46:
this.$ = $$[$0-4];yy.updateLink($$[$0-2],$$[$0]);
break;
case 47:
this.$ = [$$[$0]]
break;
case 48:
$$[$0-2].push($$[$0]);this.$ = $$[$0-2];
break;
case 50:
this.$ = $$[$0-1] + $$[$0];
break;
case 47: case 48: case 49: case 50: case 51: case 52: case 53:
case 51: case 52: case 53: case 54: case 55: case 56: case 57:
this.$=$$[$0]
break;
}
},
table: [{3:1,4:2,8:[1,3]},{1:[3]},{5:4,7:5,9:$V0,11:$V1,12:6,13:8,14:9,15:10,17:12,25:13,26:14,28:$V2,29:$V3,30:$V4,31:$V5,32:$V6,33:$V7,34:$V8,35:$V9,36:$Va,37:$Vb,45:$Vc},{9:[1,25]},{6:[1,26],7:27,9:$V0},{5:28,11:$V1,12:6,13:8,14:9,15:10,17:12,25:13,26:14,28:$V2,29:$V3,30:$V4,31:$V5,32:$V6,33:$V7,34:$V8,35:$V9,36:$Va,37:$Vb,45:$Vc},o($Vd,[2,5]),o($Ve,$Vf,{7:29,9:$V0}),{11:[1,30]},{11:[1,31]},{11:[2,12],16:32,38:33,40:[1,34],41:[1,35],42:[1,36],43:[1,37]},{9:[1,38]},o($Vg,[2,16],{18:[1,39],21:[1,40],23:[1,41]}),o($Vh,[2,17],{25:13,26:14,17:42,28:$V2,29:$V3,30:$V4,31:$V5,32:$V6,33:$V7,34:$V8,35:$V9,36:$Va,37:$Vb}),o($Vi,[2,19],{27:[1,43]}),o($Vj,[2,21]),o($Vj,[2,22]),o($Vj,[2,23]),o($Vj,[2,24]),o($Vj,[2,25]),o($Vj,[2,26]),o($Vj,[2,27]),o($Vj,[2,28]),o($Vj,[2,29]),o($Vj,[2,30]),{10:[1,44]},{1:[2,1]},{11:$V1,12:45,13:8,14:9,15:10,17:12,25:13,26:14,28:$V2,29:$V3,30:$V4,31:$V5,32:$V6,33:$V7,34:$V8,35:$V9,36:$Va,37:$Vb,45:$Vc},{6:[1,46],7:27,9:$V0},o($Ve,[2,6]),o($Vd,[2,8]),o($Vd,[2,9]),{15:47,17:12,25:13,26:14,28:$V2,29:$V3,30:$V4,31:$V5,32:$V6,33:$V7,34:$V8,35:$V9,36:$Va,37:$Vb},o($Vk,[2,32],{39:48,44:[1,49]}),o($Vl,[2,33]),o($Vl,[2,34]),o($Vl,[2,35]),o($Vl,[2,36]),{17:50,25:13,26:14,28:$V2,29:$V3,30:$V4,31:$V5,32:$V6,33:$V7,34:$V8,35:$V9,36:$Va,37:$Vb,47:[1,51]},{17:53,19:52,25:13,26:14,28:$V2,29:$V3,30:$V4,31:$V5,32:$V6,33:$V7,34:$V8,35:$V9,36:$Va,37:$Vb},{17:53,19:54,25:13,26:14,28:$V2,29:$V3,30:$V4,31:$V5,32:$V6,33:$V7,34:$V8,35:$V9,36:$Va,37:$Vb},{17:53,19:55,25:13,26:14,28:$V2,29:$V3,30:$V4,31:$V5,32:$V6,33:$V7,34:$V8,35:$V9,36:$Va,37:$Vb},o($Vh,[2,18]),{26:56,28:$V2,29:$V3,30:$V4,31:$V5,32:$V6,33:$V7,34:$V8,35:$V9,36:$Va,37:$Vb},{11:[1,57]},o($Vd,[2,4]),{1:[2,2]},{11:[2,11]},o($Vk,[2,31]),{17:53,19:58,25:13,26:14,28:$V2,29:$V3,30:$V4,31:$V5,32:$V6,33:$V7,34:$V8,35:$V9,36:$Va,37:$Vb},{9:[1,59]},{9:[1,60]},{20:[1,61]},o($Vm,[2,40],{7:63,9:[1,62]}),{22:[1,64]},{24:[1,65]},o($Vi,[2,20]),o([9,11,28,29,30,31,32,33,34,35,36,37,45],[2,3]),{44:[1,66]},{9:$Vn,27:$Vo,28:$Vp,29:$Vq,30:$Vr,46:67,47:$Vs,48:68,49:69,50:$Vt},{9:$Vn,27:$Vo,28:$Vp,29:$Vq,30:$Vr,46:77,47:$Vs,48:68,49:69,50:$Vt},o($Vg,[2,13]),{7:29,9:$V0,17:53,19:78,25:13,26:14,27:$Vf,28:$V2,29:$V3,30:$V4,31:$V5,32:$V6,33:$V7,34:$V8,35:$V9,36:$Va,37:$Vb},{27:[1,79]},o($Vg,[2,14]),o($Vg,[2,15]),o($Vk,[2,37]),{11:[2,41],31:$Vu},o($Vv,[2,43],{49:81,9:$Vn,27:$Vo,28:$Vp,29:$Vq,30:$Vr,47:$Vs,50:$Vt}),o($Vw,[2,45]),o($Vw,[2,47]),o($Vw,[2,48]),o($Vw,[2,49]),o($Vw,[2,50]),o($Vw,[2,51]),o($Vw,[2,52]),o($Vw,[2,53]),{11:[2,42],31:$Vu},o($Vm,[2,38]),{7:82,9:$V0},{9:$Vn,27:$Vo,28:$Vp,29:$Vq,30:$Vr,47:$Vs,48:83,49:69,50:$Vt},o($Vw,[2,46]),{17:53,19:84,25:13,26:14,28:$V2,29:$V3,30:$V4,31:$V5,32:$V6,33:$V7,34:$V8,35:$V9,36:$Va,37:$Vb},o($Vv,[2,44],{49:81,9:$Vn,27:$Vo,28:$Vp,29:$Vq,30:$Vr,47:$Vs,50:$Vt}),o($Vm,[2,39])],
defaultActions: {26:[2,1],46:[2,2],47:[2,11]},
table: [{3:1,4:2,8:[1,3]},{1:[3]},{5:4,7:5,9:$V0,11:$V1,12:6,13:8,14:9,15:10,16:11,17:12,19:16,27:17,28:18,30:$V2,31:$V3,32:$V4,33:$V5,34:$V6,35:$V7,36:$V8,37:$V9,38:$Va,39:$Vb,47:$Vc,49:$Vd,50:$Ve},{9:[1,29]},{6:[1,30],7:31,9:$V0},{5:32,11:$V1,12:6,13:8,14:9,15:10,16:11,17:12,19:16,27:17,28:18,30:$V2,31:$V3,32:$V4,33:$V5,34:$V6,35:$V7,36:$V8,37:$V9,38:$Va,39:$Vb,47:$Vc,49:$Vd,50:$Ve},o($Vf,[2,5]),o($Vg,$Vh,{7:33,9:$V0}),{11:[1,34]},{11:[1,35]},{11:[1,36]},{11:[1,37]},{11:[2,14],18:38,40:39,42:[1,40],43:[1,41],44:[1,42],45:[1,43]},{9:[1,44]},{9:[1,45]},{9:[1,46]},o($Vi,[2,18],{20:[1,47],23:[1,48],25:[1,49]}),o($Vj,[2,19],{27:17,28:18,19:50,30:$V2,31:$V3,32:$V4,33:$V5,34:$V6,35:$V7,36:$V8,37:$V9,38:$Va,39:$Vb}),o($Vk,[2,21],{29:[1,51]}),o($Vl,[2,23]),o($Vl,[2,24]),o($Vl,[2,25]),o($Vl,[2,26]),o($Vl,[2,27]),o($Vl,[2,28]),o($Vl,[2,29]),o($Vl,[2,30]),o($Vl,[2,31]),o($Vl,[2,32]),{10:[1,52]},{1:[2,1]},{11:$V1,12:53,13:8,14:9,15:10,16:11,17:12,19:16,27:17,28:18,30:$V2,31:$V3,32:$V4,33:$V5,34:$V6,35:$V7,36:$V8,37:$V9,38:$Va,39:$Vb,47:$Vc,49:$Vd,50:$Ve},{6:[1,54],7:31,9:$V0},o($Vg,[2,6]),o($Vf,[2,8]),o($Vf,[2,9]),o($Vf,[2,10]),o($Vf,[2,11]),{17:55,19:16,27:17,28:18,30:$V2,31:$V3,32:$V4,33:$V5,34:$V6,35:$V7,36:$V8,37:$V9,38:$Va,39:$Vb},o($Vm,[2,34],{41:56,46:[1,57]}),o($Vn,[2,35]),o($Vn,[2,36]),o($Vn,[2,37]),o($Vn,[2,38]),{19:58,27:17,28:18,30:$V2,31:$V3,32:$V4,33:$V5,34:$V6,35:$V7,36:$V8,37:$V9,38:$Va,39:$Vb,51:[1,59]},{19:60,27:17,28:18,30:$V2,31:$V3,32:$V4,33:$V5,34:$V6,35:$V7,36:$V8,37:$V9,38:$Va,39:$Vb},{19:61,27:17,28:18,30:$V2,31:$V3,32:$V4,33:$V5,34:$V6,35:$V7,36:$V8,37:$V9,38:$Va,39:$Vb},{19:63,21:62,27:17,28:18,30:$V2,31:$V3,32:$V4,33:$V5,34:$V6,35:$V7,36:$V8,37:$V9,38:$Va,39:$Vb},{19:63,21:64,27:17,28:18,30:$V2,31:$V3,32:$V4,33:$V5,34:$V6,35:$V7,36:$V8,37:$V9,38:$Va,39:$Vb},{19:63,21:65,27:17,28:18,30:$V2,31:$V3,32:$V4,33:$V5,34:$V6,35:$V7,36:$V8,37:$V9,38:$Va,39:$Vb},o($Vj,[2,20]),{28:66,30:$V2,31:$V3,32:$V4,33:$V5,34:$V6,35:$V7,36:$V8,37:$V9,38:$Va,39:$Vb},{11:[1,67]},o($Vf,[2,4]),{1:[2,2]},{11:[2,13]},o($Vm,[2,33]),{19:63,21:68,27:17,28:18,30:$V2,31:$V3,32:$V4,33:$V5,34:$V6,35:$V7,36:$V8,37:$V9,38:$Va,39:$Vb},{9:[1,69]},{9:[1,70]},{9:[1,71]},{9:[1,72]},{22:[1,73]},o($Vo,[2,42],{7:75,9:[1,74]}),{24:[1,76]},{26:[1,77]},o($Vk,[2,22]),o([9,11,30,31,32,33,34,35,36,37,38,39,47,49,50],[2,3]),{46:[1,78]},{9:$Vp,29:$Vq,30:$Vr,31:$Vs,32:$Vt,48:79,51:$Vu,52:80,53:81,54:$Vv},{9:$Vp,29:$Vq,30:$Vr,31:$Vs,32:$Vt,48:89,51:$Vu,52:80,53:81,54:$Vv},{9:$Vp,29:$Vq,30:$Vr,31:$Vs,32:$Vt,48:90,51:$Vu,52:80,53:81,54:$Vv},{19:91,27:17,28:18,30:$V2,31:$V3,32:$V4,33:$V5,34:$V6,35:$V7,36:$V8,37:$V9,38:$Va,39:$Vb},o($Vi,[2,15]),{7:33,9:$V0,19:63,21:92,27:17,28:18,29:$Vh,30:$V2,31:$V3,32:$V4,33:$V5,34:$V6,35:$V7,36:$V8,37:$V9,38:$Va,39:$Vb},{29:[1,93]},o($Vi,[2,16]),o($Vi,[2,17]),o($Vm,[2,39]),{11:[2,45],33:$Vw},o($Vx,[2,47],{53:95,9:$Vp,29:$Vq,30:$Vr,31:$Vs,32:$Vt,51:$Vu,54:$Vv}),o($Vy,[2,49]),o($Vy,[2,51]),o($Vy,[2,52]),o($Vy,[2,53]),o($Vy,[2,54]),o($Vy,[2,55]),o($Vy,[2,56]),o($Vy,[2,57]),{11:[2,46],33:$Vw},{11:[2,43],33:$Vw},{11:[2,44]},o($Vo,[2,40]),{7:96,9:$V0},{9:$Vp,29:$Vq,30:$Vr,31:$Vs,32:$Vt,51:$Vu,52:97,53:81,54:$Vv},o($Vy,[2,50]),{19:63,21:98,27:17,28:18,30:$V2,31:$V3,32:$V4,33:$V5,34:$V6,35:$V7,36:$V8,37:$V9,38:$Va,39:$Vb},o($Vx,[2,48],{53:95,9:$Vp,29:$Vq,30:$Vr,31:$Vs,32:$Vt,51:$Vu,54:$Vv}),o($Vo,[2,41])],
defaultActions: {30:[2,1],54:[2,2],55:[2,13],91:[2,44]},
parseError: function parseError(str, hash) {
if (hash.recoverable) {
this.trace(str);
@ -1320,35 +1398,35 @@ options: {},
performAction: function anonymous(yy,yy_,$avoiding_name_collisions,YY_START) {
var YYSTATE=YY_START;
switch($avoiding_name_collisions) {
case 0:return 45;
case 0:return 50;
break;
case 1:return 8;
case 1:return 47;
break;
case 2:return 10;
case 2:return 49;
break;
case 3:return 10;
case 3:return 8;
break;
case 4:return 47;
case 4:return 10;
break;
case 5:return 29;
case 5:return 10;
break;
case 6:return 'BRKT';
case 6:return 51;
break;
case 7:return 50;
case 7:return 31;
break;
case 8:return 50;
case 8:return 'BRKT';
break;
case 9:return 50;
case 9:return 54;
break;
case 10:return 30;
case 10:return 54;
break;
case 11:return 11;
case 11:return 54;
break;
case 12:return 31;
case 12:return 32;
break;
case 13:return 33;
case 13:return 11;
break;
case 14:return 34;
case 14:return 33;
break;
case 15:return 35;
break;
@ -1356,46 +1434,50 @@ case 16:return 36;
break;
case 17:return 37;
break;
case 18:return 42;
case 18:return 38;
break;
case 19:return 40;
case 19:return 39;
break;
case 20:return 41;
case 20:return 44;
break;
case 21:return 43;
case 21:return 42;
break;
case 22:return 27;
case 22:return 43;
break;
case 23:return 32;
case 23:return 45;
break;
case 24:return 33;
case 24:return 29;
break;
case 25:return 28;
case 25:return 34;
break;
case 26:return 44;
case 26:return 35;
break;
case 27:return 21;
case 27:return 30;
break;
case 28:return 22;
case 28:return 46;
break;
case 29:return 18;
case 29:return 23;
break;
case 30:return 20;
case 30:return 24;
break;
case 31:return 23
case 31:return 20;
break;
case 32:return 24
case 32:return 22;
break;
case 33:return 9;
case 33:return 25
break;
case 34:return 'NEWLINE';
case 34:return 26
break;
case 35:return 6;
case 35:return 9;
break;
case 36:return 'NEWLINE';
break;
case 37:return 6;
break;
}
},
rules: [/^(?:style\b)/,/^(?:graph\b)/,/^(?:LR\b)/,/^(?:TD\b)/,/^(?:#[a-f0-9]+)/,/^(?:[0-9]+)/,/^(?:#)/,/^(?:px\b)/,/^(?:pt\b)/,/^(?:dot\b)/,/^(?::)/,/^(?:;)/,/^(?:,)/,/^(?:=)/,/^(?:\*)/,/^(?:\.)/,/^(?:<)/,/^(?:>)/,/^(?:--[x])/,/^(?:-->)/,/^(?:--[o])/,/^(?:---)/,/^(?:-)/,/^(?:\+)/,/^(?:=)/,/^(?:[a-zåäöæøA-ZÅÄÖÆØ_]+)/,/^(?:\|)/,/^(?:\()/,/^(?:\))/,/^(?:\[)/,/^(?:\])/,/^(?:\{)/,/^(?:\})/,/^(?:\s)/,/^(?:\n)/,/^(?:$)/],
conditions: {"INITIAL":{"rules":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35],"inclusive":true}}
rules: [/^(?:style\b)/,/^(?:classDef\b)/,/^(?:class\b)/,/^(?:graph\b)/,/^(?:LR\b)/,/^(?:TD\b)/,/^(?:#[a-f0-9]+)/,/^(?:[0-9]+)/,/^(?:#)/,/^(?:px\b)/,/^(?:pt\b)/,/^(?:dot\b)/,/^(?::)/,/^(?:;)/,/^(?:,)/,/^(?:=)/,/^(?:\*)/,/^(?:\.)/,/^(?:<)/,/^(?:>)/,/^(?:--[x])/,/^(?:-->)/,/^(?:--[o])/,/^(?:---)/,/^(?:-)/,/^(?:\+)/,/^(?:=)/,/^(?:[a-zåäöæøA-ZÅÄÖÆØ_]+)/,/^(?:\|)/,/^(?:\()/,/^(?:\))/,/^(?:\[)/,/^(?:\])/,/^(?:\{)/,/^(?:\})/,/^(?:\s)/,/^(?:\n)/,/^(?:$)/],
conditions: {"INITIAL":{"rules":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37],"inclusive":true}}
});
return lexer;
})();

File diff suppressed because one or more lines are too long

246
dist/mermaid.slim.js vendored
View File

@ -306,20 +306,36 @@ var flow = require('./parser/flow');
var addVertices = function (vert, g) {
var keys = Object.keys(vert);
var styleFromStyleArr = function(styleStr,arr){
var i;
// Create a compound style definition from the style definitions found for the node in the graph definition
for (i = 0; i < arr.length; i++) {
if (typeof arr[i] !== 'undefined') {
styleStr = styleStr + arr[i] + ';';
}
}
return styleStr;
}
// Iterate through each item in the vertice object (containing all the vertices found) in the graph definition
keys.forEach(function (id) {
var vertice = vert[id];
var verticeText;
var i;
var style = '';
// Create a compound style definition from the style definitions found for the node in the graph definition
for (i = 0; i < vertice.styles.length; i++) {
if (typeof vertice.styles[i] !== 'undefined') {
style = style + vertice.styles[i] + ';';
}
var classes = graph.getClasses();
// Check if class is defined for the node
for (i = 0; i < vertice.classes.length; i++) {
style = styleFromStyleArr(style,classes[vertice.classes[i]].styles);
}
// Create a compound style definition from the style definitions found for the node in the graph definition
style = styleFromStyleArr(style, vertice.styles);
// Use vertice id as text in the box if no text is provided by the graph definition
if (vertice.text === undefined) {
verticeText = vertice.id;
@ -328,7 +344,7 @@ var addVertices = function (vert, g) {
verticeText = vertice.text;
}
// Create the node in the graph nased on defined form
// Create the node in the graph based on defined form
if (vertice.type === 'round') {
g.setNode(vertice.id, {label: verticeText, rx: 5, ry: 5, style: style});
} else {
@ -347,7 +363,9 @@ var addVertices = function (vert, g) {
* @param g
*/
var addEdges = function (edges, g) {
var cnt=0;
edges.forEach(function (edge) {
cnt++;
// Set link type for rendering
if(edge.type === 'arrow_open'){
@ -358,22 +376,26 @@ var addEdges = function (edges, g) {
}
// Add the edge to the graph
if (edge.text === 'undefined') {
if (typeof edge.text === 'undefined') {
if(typeof edge.style === 'undefined'){
g.setEdge(edge.start, edge.end,{ arrowheadStyle: "fill: #333", arrowhead: aHead});
g.setEdge(edge.start, edge.end,{ arrowheadStyle: "fill: #333", arrowhead: aHead},cnt);
}else{
g.setEdge(edge.start, edge.end, {
style: edge.style, arrowheadStyle: "fill: #333", arrowhead: aHead
});
},cnt);
}
}
// Edge with text
else {
if(typeof edge.style === 'undefined'){
g.setEdge(edge.start, edge.end,{label: edge.text, arrowheadStyle: "fill: #33f", arrowhead: aHead});
console.log('Edge with Text no style: '+edge.text);
g.setEdge(edge.start, edge.end,{label: edge.text, arrowheadStyle: "fill: #33f", arrowhead: aHead},cnt);
}else{
g.setEdge(edge.start, edge.end, {
style: edge.style, arrowheadStyle: "fill: #333", label: edge.text, arrowhead: aHead
});
},cnt);
}
}
});
@ -399,11 +421,12 @@ var drawChart = function (text, id) {
}
// Create the input mermaid.graph
var g = new dagreD3.graphlib.Graph()
var g = new dagreD3.graphlib.Graph({multigraph:true})
.setGraph({
rankdir: dir,
marginx: 20,
marginy: 20
})
.setDefaultEdgeLabel(function () {
return {};
@ -550,6 +573,7 @@ global.mermaid = {
var vertices = {};
var edges = [];
var classes = [];
var direction;
/**
* Function called by parser when a node definition has been found
@ -559,9 +583,9 @@ var direction;
* @param style
*/
exports.addVertex = function (id, text, type, style) {
console.log('Got node ' + id + ' ' + type + ' ' + text + ' styles: ' + JSON.stringify(style));
//console.log('Got node ' + id + ' ' + type + ' ' + text + ' styles: ' + JSON.stringify(style));
if (typeof vertices[id] === 'undefined') {
vertices[id] = {id: id, styles: []};
vertices[id] = {id: id, styles: [], classes:[]};
}
if (typeof text !== 'undefined') {
vertices[id].text = text;
@ -569,6 +593,9 @@ exports.addVertex = function (id, text, type, style) {
if (typeof type !== 'undefined') {
vertices[id].type = type;
}
if (typeof type !== 'undefined') {
vertices[id].type = type;
}
if (typeof style !== 'undefined') {
if (style !== null) {
style.forEach(function (s) {
@ -605,6 +632,22 @@ exports.updateLink = function (pos, style) {
var position = pos.substr(1);
edges[position].style = style;
};
exports.addClass = function (id, style) {
if (typeof classes[id] === 'undefined') {
classes[id] = {id: id, styles: []};
}
if (typeof style !== 'undefined') {
if (style !== null) {
style.forEach(function (s) {
console.log('Adding style'+s)
classes[id].styles.push(s);
});
}
}
};
/**
* Called by parser when a graph definition is found, stores the direction of the chart.
* @param dir
@ -612,6 +655,26 @@ exports.updateLink = function (pos, style) {
exports.setDirection = function (dir) {
direction = dir;
};
/**
* Called by parser when a graph definition is found, stores the direction of the chart.
* @param dir
*/
exports.setClass = function (id,className) {
console.log('Got id:'+id);
if(id.indexOf(',')>0){
id.split(',').forEach(function(id2){
if(typeof vertices[id2] !== 'undefined'){
vertices[id2].classes.push(className);
}
});
}else{
if(typeof vertices[id] !== 'undefined'){
vertices[id].classes.push(className);
}
}
};
exports.getDirection = function () {
return direction;
};
@ -631,11 +694,20 @@ exports.getEdges = function () {
return edges;
};
/**
* Retrieval function for fetching the found class definitions after parsing has completed.
* @returns {{}|*|classes}
*/
exports.getClasses = function () {
return classes;
};
/**
* Clears the internal graph db so that a new graph can be parsed.
*/
exports.clear = function () {
vertices = {};
classes = {};
edges = [];
};
/**
@ -723,12 +795,12 @@ exports.defaultStyle = function () {
}
*/
var parser = (function(){
var o=function(k,v,o,l){for(o=o||{},l=k.length;l--;o[k[l]]=v);return o},$V0=[1,7],$V1=[2,10],$V2=[1,15],$V3=[1,16],$V4=[1,17],$V5=[1,18],$V6=[1,19],$V7=[1,20],$V8=[1,21],$V9=[1,22],$Va=[1,23],$Vb=[1,24],$Vc=[1,11],$Vd=[6,9],$Ve=[11,27,28,29,30,31,32,33,34,35,36,37,45],$Vf=[2,7],$Vg=[11,40,41,42,43],$Vh=[9,11,18,20,21,22,23,24,40,41,42,43,44],$Vi=[9,11,18,20,21,22,23,24,28,29,30,31,32,33,34,35,36,37,40,41,42,43,44],$Vj=[9,11,18,20,21,22,23,24,27,28,29,30,31,32,33,34,35,36,37,40,41,42,43,44],$Vk=[28,29,30,31,32,33,34,35,36,37],$Vl=[28,29,30,31,32,33,34,35,36,37,44],$Vm=[20,22,24,44],$Vn=[1,75],$Vo=[1,72],$Vp=[1,70],$Vq=[1,73],$Vr=[1,71],$Vs=[1,76],$Vt=[1,74],$Vu=[1,80],$Vv=[11,31],$Vw=[9,11,27,28,29,30,31,47,50];
var o=function(k,v,o,l){for(o=o||{},l=k.length;l--;o[k[l]]=v);return o},$V0=[1,7],$V1=[2,12],$V2=[1,19],$V3=[1,20],$V4=[1,21],$V5=[1,22],$V6=[1,23],$V7=[1,24],$V8=[1,25],$V9=[1,26],$Va=[1,27],$Vb=[1,28],$Vc=[1,14],$Vd=[1,15],$Ve=[1,13],$Vf=[6,9],$Vg=[11,29,30,31,32,33,34,35,36,37,38,39,47,49,50],$Vh=[2,7],$Vi=[11,42,43,44,45],$Vj=[9,11,20,22,23,24,25,26,42,43,44,45,46],$Vk=[9,11,20,22,23,24,25,26,30,31,32,33,34,35,36,37,38,39,42,43,44,45,46],$Vl=[9,11,20,22,23,24,25,26,29,30,31,32,33,34,35,36,37,38,39,42,43,44,45,46],$Vm=[30,31,32,33,34,35,36,37,38,39],$Vn=[30,31,32,33,34,35,36,37,38,39,46],$Vo=[22,24,26,46],$Vp=[1,87],$Vq=[1,84],$Vr=[1,82],$Vs=[1,85],$Vt=[1,83],$Vu=[1,88],$Vv=[1,86],$Vw=[1,94],$Vx=[11,33],$Vy=[9,11,29,30,31,32,33,51,54];
var parser = {trace: function trace() { },
yy: {},
symbols_: {"error":2,"expressions":3,"graphConfig":4,"statements":5,"EOF":6,"spaceList":7,"GRAPH":8,"SPACE":9,"DIR":10,"SEMI":11,"statement":12,"verticeStatement":13,"styleStatement":14,"vertex":15,"link":16,"alphaNum":17,"SQS":18,"text":19,"SQE":20,"PS":21,"PE":22,"DIAMOND_START":23,"DIAMOND_STOP":24,"alphaNumStatement":25,"alphaNumToken":26,"MINUS":27,"ALPHA":28,"NUM":29,"COLON":30,"COMMA":31,"PLUS":32,"EQUALS":33,"MULT":34,"DOT":35,"TAGSTART":36,"TAGEND":37,"linkStatement":38,"arrowText":39,"ARROW_POINT":40,"ARROW_CIRCLE":41,"ARROW_CROSS":42,"ARROW_OPEN":43,"PIPE":44,"STYLE":45,"stylesOpt":46,"HEX":47,"style":48,"styleComponent":49,"UNIT":50,"$accept":0,"$end":1},
terminals_: {2:"error",6:"EOF",8:"GRAPH",9:"SPACE",10:"DIR",11:"SEMI",18:"SQS",20:"SQE",21:"PS",22:"PE",23:"DIAMOND_START",24:"DIAMOND_STOP",27:"MINUS",28:"ALPHA",29:"NUM",30:"COLON",31:"COMMA",32:"PLUS",33:"EQUALS",34:"MULT",35:"DOT",36:"TAGSTART",37:"TAGEND",40:"ARROW_POINT",41:"ARROW_CIRCLE",42:"ARROW_CROSS",43:"ARROW_OPEN",44:"PIPE",45:"STYLE",47:"HEX",50:"UNIT"},
productions_: [0,[3,3],[3,4],[4,4],[5,3],[5,1],[7,2],[7,1],[12,2],[12,2],[13,0],[13,3],[13,1],[15,4],[15,4],[15,4],[15,1],[17,1],[17,2],[25,1],[25,3],[26,1],[26,1],[26,1],[26,1],[26,1],[26,1],[26,1],[26,1],[26,1],[26,1],[16,2],[16,1],[38,1],[38,1],[38,1],[38,1],[39,3],[19,3],[19,5],[19,1],[14,5],[14,5],[46,1],[46,3],[48,1],[48,2],[49,1],[49,1],[49,1],[49,1],[49,1],[49,1],[49,1]],
symbols_: {"error":2,"expressions":3,"graphConfig":4,"statements":5,"EOF":6,"spaceList":7,"GRAPH":8,"SPACE":9,"DIR":10,"SEMI":11,"statement":12,"verticeStatement":13,"styleStatement":14,"classDefStatement":15,"classStatement":16,"vertex":17,"link":18,"alphaNum":19,"SQS":20,"text":21,"SQE":22,"PS":23,"PE":24,"DIAMOND_START":25,"DIAMOND_STOP":26,"alphaNumStatement":27,"alphaNumToken":28,"MINUS":29,"ALPHA":30,"NUM":31,"COLON":32,"COMMA":33,"PLUS":34,"EQUALS":35,"MULT":36,"DOT":37,"TAGSTART":38,"TAGEND":39,"linkStatement":40,"arrowText":41,"ARROW_POINT":42,"ARROW_CIRCLE":43,"ARROW_CROSS":44,"ARROW_OPEN":45,"PIPE":46,"CLASSDEF":47,"stylesOpt":48,"CLASS":49,"STYLE":50,"HEX":51,"style":52,"styleComponent":53,"UNIT":54,"$accept":0,"$end":1},
terminals_: {2:"error",6:"EOF",8:"GRAPH",9:"SPACE",10:"DIR",11:"SEMI",20:"SQS",22:"SQE",23:"PS",24:"PE",25:"DIAMOND_START",26:"DIAMOND_STOP",29:"MINUS",30:"ALPHA",31:"NUM",32:"COLON",33:"COMMA",34:"PLUS",35:"EQUALS",36:"MULT",37:"DOT",38:"TAGSTART",39:"TAGEND",42:"ARROW_POINT",43:"ARROW_CIRCLE",44:"ARROW_CROSS",45:"ARROW_OPEN",46:"PIPE",47:"CLASSDEF",49:"CLASS",50:"STYLE",51:"HEX",54:"UNIT"},
productions_: [0,[3,3],[3,4],[4,4],[5,3],[5,1],[7,2],[7,1],[12,2],[12,2],[12,2],[12,2],[13,0],[13,3],[13,1],[17,4],[17,4],[17,4],[17,1],[19,1],[19,2],[27,1],[27,3],[28,1],[28,1],[28,1],[28,1],[28,1],[28,1],[28,1],[28,1],[28,1],[28,1],[18,2],[18,1],[40,1],[40,1],[40,1],[40,1],[41,3],[21,3],[21,5],[21,1],[15,5],[16,5],[14,5],[14,5],[48,1],[48,3],[52,1],[52,2],[53,1],[53,1],[53,1],[53,1],[53,1],[53,1],[53,1]],
performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate /* action[1] */, $$ /* vstack */, _$ /* lstack */) {
/* this == yyval */
@ -740,82 +812,88 @@ break;
case 3:
yy.setDirection($$[$0-1]);this.$ = $$[$0-1];
break;
case 11:
case 13:
yy.addLink($$[$0-2],$$[$0],$$[$0-1]);this.$ = 'oy'
break;
case 12:
case 14:
this.$ = 'yo';
break;
case 13:
case 15:
this.$ = $$[$0-3];yy.addVertex($$[$0-3],$$[$0-1],'square');
break;
case 14:
case 16:
this.$ = $$[$0-3];yy.addVertex($$[$0-3],$$[$0-1],'round');
break;
case 15:
case 17:
this.$ = $$[$0-3];yy.addVertex($$[$0-3],$$[$0-1],'diamond');
break;
case 16:
case 18:
this.$ = $$[$0];yy.addVertex($$[$0]);
break;
case 17: case 19: case 21: case 22: case 45:
case 19: case 21: case 23: case 24: case 49:
this.$=$$[$0];
break;
case 18:
case 20:
this.$=$$[$0-1]+''+$$[$0];
break;
case 20:
case 22:
this.$=$$[$0-2]+'-'+$$[$0];
break;
case 23: case 24: case 25: case 26: case 27: case 28: case 29: case 30: case 32: case 40:
case 25: case 26: case 27: case 28: case 29: case 30: case 31: case 32: case 34: case 42:
this.$ = $$[$0];
break;
case 31:
case 33:
$$[$0-1].text = $$[$0];this.$ = $$[$0-1];
break;
case 33:
case 35:
this.$ = {"type":"arrow"};
break;
case 34:
case 36:
this.$ = {"type":"arrow_circle"};
break;
case 35:
case 37:
this.$ = {"type":"arrow_cross"};
break;
case 36:
case 38:
this.$ = {"type":"arrow_open"};
break;
case 37:
case 39:
this.$ = $$[$0-1];
break;
case 38:
case 40:
this.$ = $$[$0-2] + ' ' +$$[$0];
break;
case 39:
case 41:
this.$ = $$[$0-4] + ' - ' +$$[$0];
break;
case 41:
this.$ = $$[$0-4];yy.addVertex($$[$0-2],undefined,undefined,$$[$0]);
break;
case 42:
this.$ = $$[$0-4];yy.updateLink($$[$0-2],$$[$0]);
break;
case 43:
this.$ = [$$[$0]]
this.$ = $$[$0-4];yy.addClass($$[$0-2],$$[$0]);
break;
case 44:
$$[$0-2].push($$[$0]);this.$ = $$[$0-2];
this.$ = $$[$0-4];yy.setClass($$[$0-2], $$[$0]);
break;
case 45:
this.$ = $$[$0-4];yy.addVertex($$[$0-2],undefined,undefined,$$[$0]);
break;
case 46:
this.$ = $$[$0-4];yy.updateLink($$[$0-2],$$[$0]);
break;
case 47:
this.$ = [$$[$0]]
break;
case 48:
$$[$0-2].push($$[$0]);this.$ = $$[$0-2];
break;
case 50:
this.$ = $$[$0-1] + $$[$0];
break;
case 47: case 48: case 49: case 50: case 51: case 52: case 53:
case 51: case 52: case 53: case 54: case 55: case 56: case 57:
this.$=$$[$0]
break;
}
},
table: [{3:1,4:2,8:[1,3]},{1:[3]},{5:4,7:5,9:$V0,11:$V1,12:6,13:8,14:9,15:10,17:12,25:13,26:14,28:$V2,29:$V3,30:$V4,31:$V5,32:$V6,33:$V7,34:$V8,35:$V9,36:$Va,37:$Vb,45:$Vc},{9:[1,25]},{6:[1,26],7:27,9:$V0},{5:28,11:$V1,12:6,13:8,14:9,15:10,17:12,25:13,26:14,28:$V2,29:$V3,30:$V4,31:$V5,32:$V6,33:$V7,34:$V8,35:$V9,36:$Va,37:$Vb,45:$Vc},o($Vd,[2,5]),o($Ve,$Vf,{7:29,9:$V0}),{11:[1,30]},{11:[1,31]},{11:[2,12],16:32,38:33,40:[1,34],41:[1,35],42:[1,36],43:[1,37]},{9:[1,38]},o($Vg,[2,16],{18:[1,39],21:[1,40],23:[1,41]}),o($Vh,[2,17],{25:13,26:14,17:42,28:$V2,29:$V3,30:$V4,31:$V5,32:$V6,33:$V7,34:$V8,35:$V9,36:$Va,37:$Vb}),o($Vi,[2,19],{27:[1,43]}),o($Vj,[2,21]),o($Vj,[2,22]),o($Vj,[2,23]),o($Vj,[2,24]),o($Vj,[2,25]),o($Vj,[2,26]),o($Vj,[2,27]),o($Vj,[2,28]),o($Vj,[2,29]),o($Vj,[2,30]),{10:[1,44]},{1:[2,1]},{11:$V1,12:45,13:8,14:9,15:10,17:12,25:13,26:14,28:$V2,29:$V3,30:$V4,31:$V5,32:$V6,33:$V7,34:$V8,35:$V9,36:$Va,37:$Vb,45:$Vc},{6:[1,46],7:27,9:$V0},o($Ve,[2,6]),o($Vd,[2,8]),o($Vd,[2,9]),{15:47,17:12,25:13,26:14,28:$V2,29:$V3,30:$V4,31:$V5,32:$V6,33:$V7,34:$V8,35:$V9,36:$Va,37:$Vb},o($Vk,[2,32],{39:48,44:[1,49]}),o($Vl,[2,33]),o($Vl,[2,34]),o($Vl,[2,35]),o($Vl,[2,36]),{17:50,25:13,26:14,28:$V2,29:$V3,30:$V4,31:$V5,32:$V6,33:$V7,34:$V8,35:$V9,36:$Va,37:$Vb,47:[1,51]},{17:53,19:52,25:13,26:14,28:$V2,29:$V3,30:$V4,31:$V5,32:$V6,33:$V7,34:$V8,35:$V9,36:$Va,37:$Vb},{17:53,19:54,25:13,26:14,28:$V2,29:$V3,30:$V4,31:$V5,32:$V6,33:$V7,34:$V8,35:$V9,36:$Va,37:$Vb},{17:53,19:55,25:13,26:14,28:$V2,29:$V3,30:$V4,31:$V5,32:$V6,33:$V7,34:$V8,35:$V9,36:$Va,37:$Vb},o($Vh,[2,18]),{26:56,28:$V2,29:$V3,30:$V4,31:$V5,32:$V6,33:$V7,34:$V8,35:$V9,36:$Va,37:$Vb},{11:[1,57]},o($Vd,[2,4]),{1:[2,2]},{11:[2,11]},o($Vk,[2,31]),{17:53,19:58,25:13,26:14,28:$V2,29:$V3,30:$V4,31:$V5,32:$V6,33:$V7,34:$V8,35:$V9,36:$Va,37:$Vb},{9:[1,59]},{9:[1,60]},{20:[1,61]},o($Vm,[2,40],{7:63,9:[1,62]}),{22:[1,64]},{24:[1,65]},o($Vi,[2,20]),o([9,11,28,29,30,31,32,33,34,35,36,37,45],[2,3]),{44:[1,66]},{9:$Vn,27:$Vo,28:$Vp,29:$Vq,30:$Vr,46:67,47:$Vs,48:68,49:69,50:$Vt},{9:$Vn,27:$Vo,28:$Vp,29:$Vq,30:$Vr,46:77,47:$Vs,48:68,49:69,50:$Vt},o($Vg,[2,13]),{7:29,9:$V0,17:53,19:78,25:13,26:14,27:$Vf,28:$V2,29:$V3,30:$V4,31:$V5,32:$V6,33:$V7,34:$V8,35:$V9,36:$Va,37:$Vb},{27:[1,79]},o($Vg,[2,14]),o($Vg,[2,15]),o($Vk,[2,37]),{11:[2,41],31:$Vu},o($Vv,[2,43],{49:81,9:$Vn,27:$Vo,28:$Vp,29:$Vq,30:$Vr,47:$Vs,50:$Vt}),o($Vw,[2,45]),o($Vw,[2,47]),o($Vw,[2,48]),o($Vw,[2,49]),o($Vw,[2,50]),o($Vw,[2,51]),o($Vw,[2,52]),o($Vw,[2,53]),{11:[2,42],31:$Vu},o($Vm,[2,38]),{7:82,9:$V0},{9:$Vn,27:$Vo,28:$Vp,29:$Vq,30:$Vr,47:$Vs,48:83,49:69,50:$Vt},o($Vw,[2,46]),{17:53,19:84,25:13,26:14,28:$V2,29:$V3,30:$V4,31:$V5,32:$V6,33:$V7,34:$V8,35:$V9,36:$Va,37:$Vb},o($Vv,[2,44],{49:81,9:$Vn,27:$Vo,28:$Vp,29:$Vq,30:$Vr,47:$Vs,50:$Vt}),o($Vm,[2,39])],
defaultActions: {26:[2,1],46:[2,2],47:[2,11]},
table: [{3:1,4:2,8:[1,3]},{1:[3]},{5:4,7:5,9:$V0,11:$V1,12:6,13:8,14:9,15:10,16:11,17:12,19:16,27:17,28:18,30:$V2,31:$V3,32:$V4,33:$V5,34:$V6,35:$V7,36:$V8,37:$V9,38:$Va,39:$Vb,47:$Vc,49:$Vd,50:$Ve},{9:[1,29]},{6:[1,30],7:31,9:$V0},{5:32,11:$V1,12:6,13:8,14:9,15:10,16:11,17:12,19:16,27:17,28:18,30:$V2,31:$V3,32:$V4,33:$V5,34:$V6,35:$V7,36:$V8,37:$V9,38:$Va,39:$Vb,47:$Vc,49:$Vd,50:$Ve},o($Vf,[2,5]),o($Vg,$Vh,{7:33,9:$V0}),{11:[1,34]},{11:[1,35]},{11:[1,36]},{11:[1,37]},{11:[2,14],18:38,40:39,42:[1,40],43:[1,41],44:[1,42],45:[1,43]},{9:[1,44]},{9:[1,45]},{9:[1,46]},o($Vi,[2,18],{20:[1,47],23:[1,48],25:[1,49]}),o($Vj,[2,19],{27:17,28:18,19:50,30:$V2,31:$V3,32:$V4,33:$V5,34:$V6,35:$V7,36:$V8,37:$V9,38:$Va,39:$Vb}),o($Vk,[2,21],{29:[1,51]}),o($Vl,[2,23]),o($Vl,[2,24]),o($Vl,[2,25]),o($Vl,[2,26]),o($Vl,[2,27]),o($Vl,[2,28]),o($Vl,[2,29]),o($Vl,[2,30]),o($Vl,[2,31]),o($Vl,[2,32]),{10:[1,52]},{1:[2,1]},{11:$V1,12:53,13:8,14:9,15:10,16:11,17:12,19:16,27:17,28:18,30:$V2,31:$V3,32:$V4,33:$V5,34:$V6,35:$V7,36:$V8,37:$V9,38:$Va,39:$Vb,47:$Vc,49:$Vd,50:$Ve},{6:[1,54],7:31,9:$V0},o($Vg,[2,6]),o($Vf,[2,8]),o($Vf,[2,9]),o($Vf,[2,10]),o($Vf,[2,11]),{17:55,19:16,27:17,28:18,30:$V2,31:$V3,32:$V4,33:$V5,34:$V6,35:$V7,36:$V8,37:$V9,38:$Va,39:$Vb},o($Vm,[2,34],{41:56,46:[1,57]}),o($Vn,[2,35]),o($Vn,[2,36]),o($Vn,[2,37]),o($Vn,[2,38]),{19:58,27:17,28:18,30:$V2,31:$V3,32:$V4,33:$V5,34:$V6,35:$V7,36:$V8,37:$V9,38:$Va,39:$Vb,51:[1,59]},{19:60,27:17,28:18,30:$V2,31:$V3,32:$V4,33:$V5,34:$V6,35:$V7,36:$V8,37:$V9,38:$Va,39:$Vb},{19:61,27:17,28:18,30:$V2,31:$V3,32:$V4,33:$V5,34:$V6,35:$V7,36:$V8,37:$V9,38:$Va,39:$Vb},{19:63,21:62,27:17,28:18,30:$V2,31:$V3,32:$V4,33:$V5,34:$V6,35:$V7,36:$V8,37:$V9,38:$Va,39:$Vb},{19:63,21:64,27:17,28:18,30:$V2,31:$V3,32:$V4,33:$V5,34:$V6,35:$V7,36:$V8,37:$V9,38:$Va,39:$Vb},{19:63,21:65,27:17,28:18,30:$V2,31:$V3,32:$V4,33:$V5,34:$V6,35:$V7,36:$V8,37:$V9,38:$Va,39:$Vb},o($Vj,[2,20]),{28:66,30:$V2,31:$V3,32:$V4,33:$V5,34:$V6,35:$V7,36:$V8,37:$V9,38:$Va,39:$Vb},{11:[1,67]},o($Vf,[2,4]),{1:[2,2]},{11:[2,13]},o($Vm,[2,33]),{19:63,21:68,27:17,28:18,30:$V2,31:$V3,32:$V4,33:$V5,34:$V6,35:$V7,36:$V8,37:$V9,38:$Va,39:$Vb},{9:[1,69]},{9:[1,70]},{9:[1,71]},{9:[1,72]},{22:[1,73]},o($Vo,[2,42],{7:75,9:[1,74]}),{24:[1,76]},{26:[1,77]},o($Vk,[2,22]),o([9,11,30,31,32,33,34,35,36,37,38,39,47,49,50],[2,3]),{46:[1,78]},{9:$Vp,29:$Vq,30:$Vr,31:$Vs,32:$Vt,48:79,51:$Vu,52:80,53:81,54:$Vv},{9:$Vp,29:$Vq,30:$Vr,31:$Vs,32:$Vt,48:89,51:$Vu,52:80,53:81,54:$Vv},{9:$Vp,29:$Vq,30:$Vr,31:$Vs,32:$Vt,48:90,51:$Vu,52:80,53:81,54:$Vv},{19:91,27:17,28:18,30:$V2,31:$V3,32:$V4,33:$V5,34:$V6,35:$V7,36:$V8,37:$V9,38:$Va,39:$Vb},o($Vi,[2,15]),{7:33,9:$V0,19:63,21:92,27:17,28:18,29:$Vh,30:$V2,31:$V3,32:$V4,33:$V5,34:$V6,35:$V7,36:$V8,37:$V9,38:$Va,39:$Vb},{29:[1,93]},o($Vi,[2,16]),o($Vi,[2,17]),o($Vm,[2,39]),{11:[2,45],33:$Vw},o($Vx,[2,47],{53:95,9:$Vp,29:$Vq,30:$Vr,31:$Vs,32:$Vt,51:$Vu,54:$Vv}),o($Vy,[2,49]),o($Vy,[2,51]),o($Vy,[2,52]),o($Vy,[2,53]),o($Vy,[2,54]),o($Vy,[2,55]),o($Vy,[2,56]),o($Vy,[2,57]),{11:[2,46],33:$Vw},{11:[2,43],33:$Vw},{11:[2,44]},o($Vo,[2,40]),{7:96,9:$V0},{9:$Vp,29:$Vq,30:$Vr,31:$Vs,32:$Vt,51:$Vu,52:97,53:81,54:$Vv},o($Vy,[2,50]),{19:63,21:98,27:17,28:18,30:$V2,31:$V3,32:$V4,33:$V5,34:$V6,35:$V7,36:$V8,37:$V9,38:$Va,39:$Vb},o($Vx,[2,48],{53:95,9:$Vp,29:$Vq,30:$Vr,31:$Vs,32:$Vt,51:$Vu,54:$Vv}),o($Vo,[2,41])],
defaultActions: {30:[2,1],54:[2,2],55:[2,13],91:[2,44]},
parseError: function parseError(str, hash) {
if (hash.recoverable) {
this.trace(str);
@ -1288,35 +1366,35 @@ options: {},
performAction: function anonymous(yy,yy_,$avoiding_name_collisions,YY_START) {
var YYSTATE=YY_START;
switch($avoiding_name_collisions) {
case 0:return 45;
case 0:return 50;
break;
case 1:return 8;
case 1:return 47;
break;
case 2:return 10;
case 2:return 49;
break;
case 3:return 10;
case 3:return 8;
break;
case 4:return 47;
case 4:return 10;
break;
case 5:return 29;
case 5:return 10;
break;
case 6:return 'BRKT';
case 6:return 51;
break;
case 7:return 50;
case 7:return 31;
break;
case 8:return 50;
case 8:return 'BRKT';
break;
case 9:return 50;
case 9:return 54;
break;
case 10:return 30;
case 10:return 54;
break;
case 11:return 11;
case 11:return 54;
break;
case 12:return 31;
case 12:return 32;
break;
case 13:return 33;
case 13:return 11;
break;
case 14:return 34;
case 14:return 33;
break;
case 15:return 35;
break;
@ -1324,46 +1402,50 @@ case 16:return 36;
break;
case 17:return 37;
break;
case 18:return 42;
case 18:return 38;
break;
case 19:return 40;
case 19:return 39;
break;
case 20:return 41;
case 20:return 44;
break;
case 21:return 43;
case 21:return 42;
break;
case 22:return 27;
case 22:return 43;
break;
case 23:return 32;
case 23:return 45;
break;
case 24:return 33;
case 24:return 29;
break;
case 25:return 28;
case 25:return 34;
break;
case 26:return 44;
case 26:return 35;
break;
case 27:return 21;
case 27:return 30;
break;
case 28:return 22;
case 28:return 46;
break;
case 29:return 18;
case 29:return 23;
break;
case 30:return 20;
case 30:return 24;
break;
case 31:return 23
case 31:return 20;
break;
case 32:return 24
case 32:return 22;
break;
case 33:return 9;
case 33:return 25
break;
case 34:return 'NEWLINE';
case 34:return 26
break;
case 35:return 6;
case 35:return 9;
break;
case 36:return 'NEWLINE';
break;
case 37:return 6;
break;
}
},
rules: [/^(?:style\b)/,/^(?:graph\b)/,/^(?:LR\b)/,/^(?:TD\b)/,/^(?:#[a-f0-9]+)/,/^(?:[0-9]+)/,/^(?:#)/,/^(?:px\b)/,/^(?:pt\b)/,/^(?:dot\b)/,/^(?::)/,/^(?:;)/,/^(?:,)/,/^(?:=)/,/^(?:\*)/,/^(?:\.)/,/^(?:<)/,/^(?:>)/,/^(?:--[x])/,/^(?:-->)/,/^(?:--[o])/,/^(?:---)/,/^(?:-)/,/^(?:\+)/,/^(?:=)/,/^(?:[a-zåäöæøA-ZÅÄÖÆØ_]+)/,/^(?:\|)/,/^(?:\()/,/^(?:\))/,/^(?:\[)/,/^(?:\])/,/^(?:\{)/,/^(?:\})/,/^(?:\s)/,/^(?:\n)/,/^(?:$)/],
conditions: {"INITIAL":{"rules":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35],"inclusive":true}}
rules: [/^(?:style\b)/,/^(?:classDef\b)/,/^(?:class\b)/,/^(?:graph\b)/,/^(?:LR\b)/,/^(?:TD\b)/,/^(?:#[a-f0-9]+)/,/^(?:[0-9]+)/,/^(?:#)/,/^(?:px\b)/,/^(?:pt\b)/,/^(?:dot\b)/,/^(?::)/,/^(?:;)/,/^(?:,)/,/^(?:=)/,/^(?:\*)/,/^(?:\.)/,/^(?:<)/,/^(?:>)/,/^(?:--[x])/,/^(?:-->)/,/^(?:--[o])/,/^(?:---)/,/^(?:-)/,/^(?:\+)/,/^(?:=)/,/^(?:[a-zåäöæøA-ZÅÄÖÆØ_]+)/,/^(?:\|)/,/^(?:\()/,/^(?:\))/,/^(?:\[)/,/^(?:\])/,/^(?:\{)/,/^(?:\})/,/^(?:\s)/,/^(?:\n)/,/^(?:$)/],
conditions: {"INITIAL":{"rules":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37],"inclusive":true}}
});
return lexer;
})();

File diff suppressed because one or more lines are too long

View File

@ -4,6 +4,7 @@
var vertices = {};
var edges = [];
var classes = [];
var direction;
/**
* Function called by parser when a node definition has been found
@ -13,9 +14,9 @@ var direction;
* @param style
*/
exports.addVertex = function (id, text, type, style) {
console.log('Got node ' + id + ' ' + type + ' ' + text + ' styles: ' + JSON.stringify(style));
//console.log('Got node ' + id + ' ' + type + ' ' + text + ' styles: ' + JSON.stringify(style));
if (typeof vertices[id] === 'undefined') {
vertices[id] = {id: id, styles: []};
vertices[id] = {id: id, styles: [], classes:[]};
}
if (typeof text !== 'undefined') {
vertices[id].text = text;
@ -23,6 +24,9 @@ exports.addVertex = function (id, text, type, style) {
if (typeof type !== 'undefined') {
vertices[id].type = type;
}
if (typeof type !== 'undefined') {
vertices[id].type = type;
}
if (typeof style !== 'undefined') {
if (style !== null) {
style.forEach(function (s) {
@ -59,6 +63,22 @@ exports.updateLink = function (pos, style) {
var position = pos.substr(1);
edges[position].style = style;
};
exports.addClass = function (id, style) {
if (typeof classes[id] === 'undefined') {
classes[id] = {id: id, styles: []};
}
if (typeof style !== 'undefined') {
if (style !== null) {
style.forEach(function (s) {
console.log('Adding style'+s)
classes[id].styles.push(s);
});
}
}
};
/**
* Called by parser when a graph definition is found, stores the direction of the chart.
* @param dir
@ -66,6 +86,26 @@ exports.updateLink = function (pos, style) {
exports.setDirection = function (dir) {
direction = dir;
};
/**
* Called by parser when a graph definition is found, stores the direction of the chart.
* @param dir
*/
exports.setClass = function (id,className) {
console.log('Got id:'+id);
if(id.indexOf(',')>0){
id.split(',').forEach(function(id2){
if(typeof vertices[id2] !== 'undefined'){
vertices[id2].classes.push(className);
}
});
}else{
if(typeof vertices[id] !== 'undefined'){
vertices[id].classes.push(className);
}
}
};
exports.getDirection = function () {
return direction;
};
@ -85,11 +125,20 @@ exports.getEdges = function () {
return edges;
};
/**
* Retrieval function for fetching the found class definitions after parsing has completed.
* @returns {{}|*|classes}
*/
exports.getClasses = function () {
return classes;
};
/**
* Clears the internal graph db so that a new graph can be parsed.
*/
exports.clear = function () {
vertices = {};
classes = {};
edges = [];
};
/**

View File

@ -9,20 +9,36 @@ var flow = require('./parser/flow');
var addVertices = function (vert, g) {
var keys = Object.keys(vert);
var styleFromStyleArr = function(styleStr,arr){
var i;
// Create a compound style definition from the style definitions found for the node in the graph definition
for (i = 0; i < arr.length; i++) {
if (typeof arr[i] !== 'undefined') {
styleStr = styleStr + arr[i] + ';';
}
}
return styleStr;
}
// Iterate through each item in the vertice object (containing all the vertices found) in the graph definition
keys.forEach(function (id) {
var vertice = vert[id];
var verticeText;
var i;
var style = '';
// Create a compound style definition from the style definitions found for the node in the graph definition
for (i = 0; i < vertice.styles.length; i++) {
if (typeof vertice.styles[i] !== 'undefined') {
style = style + vertice.styles[i] + ';';
}
var classes = graph.getClasses();
// Check if class is defined for the node
for (i = 0; i < vertice.classes.length; i++) {
style = styleFromStyleArr(style,classes[vertice.classes[i]].styles);
}
// Create a compound style definition from the style definitions found for the node in the graph definition
style = styleFromStyleArr(style, vertice.styles);
// Use vertice id as text in the box if no text is provided by the graph definition
if (vertice.text === undefined) {
verticeText = vertice.id;
@ -31,7 +47,7 @@ var addVertices = function (vert, g) {
verticeText = vertice.text;
}
// Create the node in the graph nased on defined form
// Create the node in the graph based on defined form
if (vertice.type === 'round') {
g.setNode(vertice.id, {label: verticeText, rx: 5, ry: 5, style: style});
} else {
@ -50,7 +66,9 @@ var addVertices = function (vert, g) {
* @param g
*/
var addEdges = function (edges, g) {
var cnt=0;
edges.forEach(function (edge) {
cnt++;
// Set link type for rendering
if(edge.type === 'arrow_open'){
@ -61,22 +79,26 @@ var addEdges = function (edges, g) {
}
// Add the edge to the graph
if (edge.text === 'undefined') {
if (typeof edge.text === 'undefined') {
if(typeof edge.style === 'undefined'){
g.setEdge(edge.start, edge.end,{ arrowheadStyle: "fill: #333", arrowhead: aHead});
g.setEdge(edge.start, edge.end,{ arrowheadStyle: "fill: #333", arrowhead: aHead},cnt);
}else{
g.setEdge(edge.start, edge.end, {
style: edge.style, arrowheadStyle: "fill: #333", arrowhead: aHead
});
},cnt);
}
}
// Edge with text
else {
if(typeof edge.style === 'undefined'){
g.setEdge(edge.start, edge.end,{label: edge.text, arrowheadStyle: "fill: #33f", arrowhead: aHead});
console.log('Edge with Text no style: '+edge.text);
g.setEdge(edge.start, edge.end,{label: edge.text, arrowheadStyle: "fill: #33f", arrowhead: aHead},cnt);
}else{
g.setEdge(edge.start, edge.end, {
style: edge.style, arrowheadStyle: "fill: #333", label: edge.text, arrowhead: aHead
});
},cnt);
}
}
});
@ -102,11 +124,12 @@ var drawChart = function (text, id) {
}
// Create the input mermaid.graph
var g = new dagreD3.graphlib.Graph()
var g = new dagreD3.graphlib.Graph({multigraph:true})
.setGraph({
rankdir: dir,
marginx: 20,
marginy: 20
})
.setDefaultEdgeLabel(function () {
return {};

View File

@ -5,6 +5,8 @@
%%
"style" return 'STYLE';
"classDef" return 'CLASSDEF';
"class" return 'CLASS';
"graph" return 'GRAPH';
"LR" return 'DIR';
"TD" return 'DIR';
@ -75,6 +77,8 @@ spaceList
statement
: verticeStatement SEMI
| styleStatement SEMI
| classDefStatement SEMI
| classStatement SEMI
;
verticeStatement:
@ -161,6 +165,14 @@ text: alphaNum SPACE text
{$$ = $1;}
;
classDefStatement:CLASSDEF SPACE alphaNum SPACE stylesOpt
{$$ = $1;yy.addClass($3,$5);}
;
classStatement:CLASS SPACE alphaNum SPACE alphaNum
{$$ = $1;yy.setClass($3, $5);}
;
styleStatement:STYLE SPACE alphaNum SPACE stylesOpt
{$$ = $1;yy.addVertex($3,undefined,undefined,$5);}
| STYLE SPACE HEX SPACE stylesOpt

View File

@ -72,12 +72,12 @@
}
*/
var parser = (function(){
var o=function(k,v,o,l){for(o=o||{},l=k.length;l--;o[k[l]]=v);return o},$V0=[1,7],$V1=[2,10],$V2=[1,15],$V3=[1,16],$V4=[1,17],$V5=[1,18],$V6=[1,19],$V7=[1,20],$V8=[1,21],$V9=[1,22],$Va=[1,23],$Vb=[1,24],$Vc=[1,11],$Vd=[6,9],$Ve=[11,27,28,29,30,31,32,33,34,35,36,37,45],$Vf=[2,7],$Vg=[11,40,41,42,43],$Vh=[9,11,18,20,21,22,23,24,40,41,42,43,44],$Vi=[9,11,18,20,21,22,23,24,28,29,30,31,32,33,34,35,36,37,40,41,42,43,44],$Vj=[9,11,18,20,21,22,23,24,27,28,29,30,31,32,33,34,35,36,37,40,41,42,43,44],$Vk=[28,29,30,31,32,33,34,35,36,37],$Vl=[28,29,30,31,32,33,34,35,36,37,44],$Vm=[20,22,24,44],$Vn=[1,75],$Vo=[1,72],$Vp=[1,70],$Vq=[1,73],$Vr=[1,71],$Vs=[1,76],$Vt=[1,74],$Vu=[1,80],$Vv=[11,31],$Vw=[9,11,27,28,29,30,31,47,50];
var o=function(k,v,o,l){for(o=o||{},l=k.length;l--;o[k[l]]=v);return o},$V0=[1,7],$V1=[2,12],$V2=[1,19],$V3=[1,20],$V4=[1,21],$V5=[1,22],$V6=[1,23],$V7=[1,24],$V8=[1,25],$V9=[1,26],$Va=[1,27],$Vb=[1,28],$Vc=[1,14],$Vd=[1,15],$Ve=[1,13],$Vf=[6,9],$Vg=[11,29,30,31,32,33,34,35,36,37,38,39,47,49,50],$Vh=[2,7],$Vi=[11,42,43,44,45],$Vj=[9,11,20,22,23,24,25,26,42,43,44,45,46],$Vk=[9,11,20,22,23,24,25,26,30,31,32,33,34,35,36,37,38,39,42,43,44,45,46],$Vl=[9,11,20,22,23,24,25,26,29,30,31,32,33,34,35,36,37,38,39,42,43,44,45,46],$Vm=[30,31,32,33,34,35,36,37,38,39],$Vn=[30,31,32,33,34,35,36,37,38,39,46],$Vo=[22,24,26,46],$Vp=[1,87],$Vq=[1,84],$Vr=[1,82],$Vs=[1,85],$Vt=[1,83],$Vu=[1,88],$Vv=[1,86],$Vw=[1,94],$Vx=[11,33],$Vy=[9,11,29,30,31,32,33,51,54];
var parser = {trace: function trace() { },
yy: {},
symbols_: {"error":2,"expressions":3,"graphConfig":4,"statements":5,"EOF":6,"spaceList":7,"GRAPH":8,"SPACE":9,"DIR":10,"SEMI":11,"statement":12,"verticeStatement":13,"styleStatement":14,"vertex":15,"link":16,"alphaNum":17,"SQS":18,"text":19,"SQE":20,"PS":21,"PE":22,"DIAMOND_START":23,"DIAMOND_STOP":24,"alphaNumStatement":25,"alphaNumToken":26,"MINUS":27,"ALPHA":28,"NUM":29,"COLON":30,"COMMA":31,"PLUS":32,"EQUALS":33,"MULT":34,"DOT":35,"TAGSTART":36,"TAGEND":37,"linkStatement":38,"arrowText":39,"ARROW_POINT":40,"ARROW_CIRCLE":41,"ARROW_CROSS":42,"ARROW_OPEN":43,"PIPE":44,"STYLE":45,"stylesOpt":46,"HEX":47,"style":48,"styleComponent":49,"UNIT":50,"$accept":0,"$end":1},
terminals_: {2:"error",6:"EOF",8:"GRAPH",9:"SPACE",10:"DIR",11:"SEMI",18:"SQS",20:"SQE",21:"PS",22:"PE",23:"DIAMOND_START",24:"DIAMOND_STOP",27:"MINUS",28:"ALPHA",29:"NUM",30:"COLON",31:"COMMA",32:"PLUS",33:"EQUALS",34:"MULT",35:"DOT",36:"TAGSTART",37:"TAGEND",40:"ARROW_POINT",41:"ARROW_CIRCLE",42:"ARROW_CROSS",43:"ARROW_OPEN",44:"PIPE",45:"STYLE",47:"HEX",50:"UNIT"},
productions_: [0,[3,3],[3,4],[4,4],[5,3],[5,1],[7,2],[7,1],[12,2],[12,2],[13,0],[13,3],[13,1],[15,4],[15,4],[15,4],[15,1],[17,1],[17,2],[25,1],[25,3],[26,1],[26,1],[26,1],[26,1],[26,1],[26,1],[26,1],[26,1],[26,1],[26,1],[16,2],[16,1],[38,1],[38,1],[38,1],[38,1],[39,3],[19,3],[19,5],[19,1],[14,5],[14,5],[46,1],[46,3],[48,1],[48,2],[49,1],[49,1],[49,1],[49,1],[49,1],[49,1],[49,1]],
symbols_: {"error":2,"expressions":3,"graphConfig":4,"statements":5,"EOF":6,"spaceList":7,"GRAPH":8,"SPACE":9,"DIR":10,"SEMI":11,"statement":12,"verticeStatement":13,"styleStatement":14,"classDefStatement":15,"classStatement":16,"vertex":17,"link":18,"alphaNum":19,"SQS":20,"text":21,"SQE":22,"PS":23,"PE":24,"DIAMOND_START":25,"DIAMOND_STOP":26,"alphaNumStatement":27,"alphaNumToken":28,"MINUS":29,"ALPHA":30,"NUM":31,"COLON":32,"COMMA":33,"PLUS":34,"EQUALS":35,"MULT":36,"DOT":37,"TAGSTART":38,"TAGEND":39,"linkStatement":40,"arrowText":41,"ARROW_POINT":42,"ARROW_CIRCLE":43,"ARROW_CROSS":44,"ARROW_OPEN":45,"PIPE":46,"CLASSDEF":47,"stylesOpt":48,"CLASS":49,"STYLE":50,"HEX":51,"style":52,"styleComponent":53,"UNIT":54,"$accept":0,"$end":1},
terminals_: {2:"error",6:"EOF",8:"GRAPH",9:"SPACE",10:"DIR",11:"SEMI",20:"SQS",22:"SQE",23:"PS",24:"PE",25:"DIAMOND_START",26:"DIAMOND_STOP",29:"MINUS",30:"ALPHA",31:"NUM",32:"COLON",33:"COMMA",34:"PLUS",35:"EQUALS",36:"MULT",37:"DOT",38:"TAGSTART",39:"TAGEND",42:"ARROW_POINT",43:"ARROW_CIRCLE",44:"ARROW_CROSS",45:"ARROW_OPEN",46:"PIPE",47:"CLASSDEF",49:"CLASS",50:"STYLE",51:"HEX",54:"UNIT"},
productions_: [0,[3,3],[3,4],[4,4],[5,3],[5,1],[7,2],[7,1],[12,2],[12,2],[12,2],[12,2],[13,0],[13,3],[13,1],[17,4],[17,4],[17,4],[17,1],[19,1],[19,2],[27,1],[27,3],[28,1],[28,1],[28,1],[28,1],[28,1],[28,1],[28,1],[28,1],[28,1],[28,1],[18,2],[18,1],[40,1],[40,1],[40,1],[40,1],[41,3],[21,3],[21,5],[21,1],[15,5],[16,5],[14,5],[14,5],[48,1],[48,3],[52,1],[52,2],[53,1],[53,1],[53,1],[53,1],[53,1],[53,1],[53,1]],
performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate /* action[1] */, $$ /* vstack */, _$ /* lstack */) {
/* this == yyval */
@ -89,82 +89,88 @@ break;
case 3:
yy.setDirection($$[$0-1]);this.$ = $$[$0-1];
break;
case 11:
case 13:
yy.addLink($$[$0-2],$$[$0],$$[$0-1]);this.$ = 'oy'
break;
case 12:
case 14:
this.$ = 'yo';
break;
case 13:
case 15:
this.$ = $$[$0-3];yy.addVertex($$[$0-3],$$[$0-1],'square');
break;
case 14:
case 16:
this.$ = $$[$0-3];yy.addVertex($$[$0-3],$$[$0-1],'round');
break;
case 15:
case 17:
this.$ = $$[$0-3];yy.addVertex($$[$0-3],$$[$0-1],'diamond');
break;
case 16:
case 18:
this.$ = $$[$0];yy.addVertex($$[$0]);
break;
case 17: case 19: case 21: case 22: case 45:
case 19: case 21: case 23: case 24: case 49:
this.$=$$[$0];
break;
case 18:
case 20:
this.$=$$[$0-1]+''+$$[$0];
break;
case 20:
case 22:
this.$=$$[$0-2]+'-'+$$[$0];
break;
case 23: case 24: case 25: case 26: case 27: case 28: case 29: case 30: case 32: case 40:
case 25: case 26: case 27: case 28: case 29: case 30: case 31: case 32: case 34: case 42:
this.$ = $$[$0];
break;
case 31:
case 33:
$$[$0-1].text = $$[$0];this.$ = $$[$0-1];
break;
case 33:
case 35:
this.$ = {"type":"arrow"};
break;
case 34:
case 36:
this.$ = {"type":"arrow_circle"};
break;
case 35:
case 37:
this.$ = {"type":"arrow_cross"};
break;
case 36:
case 38:
this.$ = {"type":"arrow_open"};
break;
case 37:
case 39:
this.$ = $$[$0-1];
break;
case 38:
case 40:
this.$ = $$[$0-2] + ' ' +$$[$0];
break;
case 39:
case 41:
this.$ = $$[$0-4] + ' - ' +$$[$0];
break;
case 41:
this.$ = $$[$0-4];yy.addVertex($$[$0-2],undefined,undefined,$$[$0]);
break;
case 42:
this.$ = $$[$0-4];yy.updateLink($$[$0-2],$$[$0]);
break;
case 43:
this.$ = [$$[$0]]
this.$ = $$[$0-4];yy.addClass($$[$0-2],$$[$0]);
break;
case 44:
$$[$0-2].push($$[$0]);this.$ = $$[$0-2];
this.$ = $$[$0-4];yy.setClass($$[$0-2], $$[$0]);
break;
case 45:
this.$ = $$[$0-4];yy.addVertex($$[$0-2],undefined,undefined,$$[$0]);
break;
case 46:
this.$ = $$[$0-4];yy.updateLink($$[$0-2],$$[$0]);
break;
case 47:
this.$ = [$$[$0]]
break;
case 48:
$$[$0-2].push($$[$0]);this.$ = $$[$0-2];
break;
case 50:
this.$ = $$[$0-1] + $$[$0];
break;
case 47: case 48: case 49: case 50: case 51: case 52: case 53:
case 51: case 52: case 53: case 54: case 55: case 56: case 57:
this.$=$$[$0]
break;
}
},
table: [{3:1,4:2,8:[1,3]},{1:[3]},{5:4,7:5,9:$V0,11:$V1,12:6,13:8,14:9,15:10,17:12,25:13,26:14,28:$V2,29:$V3,30:$V4,31:$V5,32:$V6,33:$V7,34:$V8,35:$V9,36:$Va,37:$Vb,45:$Vc},{9:[1,25]},{6:[1,26],7:27,9:$V0},{5:28,11:$V1,12:6,13:8,14:9,15:10,17:12,25:13,26:14,28:$V2,29:$V3,30:$V4,31:$V5,32:$V6,33:$V7,34:$V8,35:$V9,36:$Va,37:$Vb,45:$Vc},o($Vd,[2,5]),o($Ve,$Vf,{7:29,9:$V0}),{11:[1,30]},{11:[1,31]},{11:[2,12],16:32,38:33,40:[1,34],41:[1,35],42:[1,36],43:[1,37]},{9:[1,38]},o($Vg,[2,16],{18:[1,39],21:[1,40],23:[1,41]}),o($Vh,[2,17],{25:13,26:14,17:42,28:$V2,29:$V3,30:$V4,31:$V5,32:$V6,33:$V7,34:$V8,35:$V9,36:$Va,37:$Vb}),o($Vi,[2,19],{27:[1,43]}),o($Vj,[2,21]),o($Vj,[2,22]),o($Vj,[2,23]),o($Vj,[2,24]),o($Vj,[2,25]),o($Vj,[2,26]),o($Vj,[2,27]),o($Vj,[2,28]),o($Vj,[2,29]),o($Vj,[2,30]),{10:[1,44]},{1:[2,1]},{11:$V1,12:45,13:8,14:9,15:10,17:12,25:13,26:14,28:$V2,29:$V3,30:$V4,31:$V5,32:$V6,33:$V7,34:$V8,35:$V9,36:$Va,37:$Vb,45:$Vc},{6:[1,46],7:27,9:$V0},o($Ve,[2,6]),o($Vd,[2,8]),o($Vd,[2,9]),{15:47,17:12,25:13,26:14,28:$V2,29:$V3,30:$V4,31:$V5,32:$V6,33:$V7,34:$V8,35:$V9,36:$Va,37:$Vb},o($Vk,[2,32],{39:48,44:[1,49]}),o($Vl,[2,33]),o($Vl,[2,34]),o($Vl,[2,35]),o($Vl,[2,36]),{17:50,25:13,26:14,28:$V2,29:$V3,30:$V4,31:$V5,32:$V6,33:$V7,34:$V8,35:$V9,36:$Va,37:$Vb,47:[1,51]},{17:53,19:52,25:13,26:14,28:$V2,29:$V3,30:$V4,31:$V5,32:$V6,33:$V7,34:$V8,35:$V9,36:$Va,37:$Vb},{17:53,19:54,25:13,26:14,28:$V2,29:$V3,30:$V4,31:$V5,32:$V6,33:$V7,34:$V8,35:$V9,36:$Va,37:$Vb},{17:53,19:55,25:13,26:14,28:$V2,29:$V3,30:$V4,31:$V5,32:$V6,33:$V7,34:$V8,35:$V9,36:$Va,37:$Vb},o($Vh,[2,18]),{26:56,28:$V2,29:$V3,30:$V4,31:$V5,32:$V6,33:$V7,34:$V8,35:$V9,36:$Va,37:$Vb},{11:[1,57]},o($Vd,[2,4]),{1:[2,2]},{11:[2,11]},o($Vk,[2,31]),{17:53,19:58,25:13,26:14,28:$V2,29:$V3,30:$V4,31:$V5,32:$V6,33:$V7,34:$V8,35:$V9,36:$Va,37:$Vb},{9:[1,59]},{9:[1,60]},{20:[1,61]},o($Vm,[2,40],{7:63,9:[1,62]}),{22:[1,64]},{24:[1,65]},o($Vi,[2,20]),o([9,11,28,29,30,31,32,33,34,35,36,37,45],[2,3]),{44:[1,66]},{9:$Vn,27:$Vo,28:$Vp,29:$Vq,30:$Vr,46:67,47:$Vs,48:68,49:69,50:$Vt},{9:$Vn,27:$Vo,28:$Vp,29:$Vq,30:$Vr,46:77,47:$Vs,48:68,49:69,50:$Vt},o($Vg,[2,13]),{7:29,9:$V0,17:53,19:78,25:13,26:14,27:$Vf,28:$V2,29:$V3,30:$V4,31:$V5,32:$V6,33:$V7,34:$V8,35:$V9,36:$Va,37:$Vb},{27:[1,79]},o($Vg,[2,14]),o($Vg,[2,15]),o($Vk,[2,37]),{11:[2,41],31:$Vu},o($Vv,[2,43],{49:81,9:$Vn,27:$Vo,28:$Vp,29:$Vq,30:$Vr,47:$Vs,50:$Vt}),o($Vw,[2,45]),o($Vw,[2,47]),o($Vw,[2,48]),o($Vw,[2,49]),o($Vw,[2,50]),o($Vw,[2,51]),o($Vw,[2,52]),o($Vw,[2,53]),{11:[2,42],31:$Vu},o($Vm,[2,38]),{7:82,9:$V0},{9:$Vn,27:$Vo,28:$Vp,29:$Vq,30:$Vr,47:$Vs,48:83,49:69,50:$Vt},o($Vw,[2,46]),{17:53,19:84,25:13,26:14,28:$V2,29:$V3,30:$V4,31:$V5,32:$V6,33:$V7,34:$V8,35:$V9,36:$Va,37:$Vb},o($Vv,[2,44],{49:81,9:$Vn,27:$Vo,28:$Vp,29:$Vq,30:$Vr,47:$Vs,50:$Vt}),o($Vm,[2,39])],
defaultActions: {26:[2,1],46:[2,2],47:[2,11]},
table: [{3:1,4:2,8:[1,3]},{1:[3]},{5:4,7:5,9:$V0,11:$V1,12:6,13:8,14:9,15:10,16:11,17:12,19:16,27:17,28:18,30:$V2,31:$V3,32:$V4,33:$V5,34:$V6,35:$V7,36:$V8,37:$V9,38:$Va,39:$Vb,47:$Vc,49:$Vd,50:$Ve},{9:[1,29]},{6:[1,30],7:31,9:$V0},{5:32,11:$V1,12:6,13:8,14:9,15:10,16:11,17:12,19:16,27:17,28:18,30:$V2,31:$V3,32:$V4,33:$V5,34:$V6,35:$V7,36:$V8,37:$V9,38:$Va,39:$Vb,47:$Vc,49:$Vd,50:$Ve},o($Vf,[2,5]),o($Vg,$Vh,{7:33,9:$V0}),{11:[1,34]},{11:[1,35]},{11:[1,36]},{11:[1,37]},{11:[2,14],18:38,40:39,42:[1,40],43:[1,41],44:[1,42],45:[1,43]},{9:[1,44]},{9:[1,45]},{9:[1,46]},o($Vi,[2,18],{20:[1,47],23:[1,48],25:[1,49]}),o($Vj,[2,19],{27:17,28:18,19:50,30:$V2,31:$V3,32:$V4,33:$V5,34:$V6,35:$V7,36:$V8,37:$V9,38:$Va,39:$Vb}),o($Vk,[2,21],{29:[1,51]}),o($Vl,[2,23]),o($Vl,[2,24]),o($Vl,[2,25]),o($Vl,[2,26]),o($Vl,[2,27]),o($Vl,[2,28]),o($Vl,[2,29]),o($Vl,[2,30]),o($Vl,[2,31]),o($Vl,[2,32]),{10:[1,52]},{1:[2,1]},{11:$V1,12:53,13:8,14:9,15:10,16:11,17:12,19:16,27:17,28:18,30:$V2,31:$V3,32:$V4,33:$V5,34:$V6,35:$V7,36:$V8,37:$V9,38:$Va,39:$Vb,47:$Vc,49:$Vd,50:$Ve},{6:[1,54],7:31,9:$V0},o($Vg,[2,6]),o($Vf,[2,8]),o($Vf,[2,9]),o($Vf,[2,10]),o($Vf,[2,11]),{17:55,19:16,27:17,28:18,30:$V2,31:$V3,32:$V4,33:$V5,34:$V6,35:$V7,36:$V8,37:$V9,38:$Va,39:$Vb},o($Vm,[2,34],{41:56,46:[1,57]}),o($Vn,[2,35]),o($Vn,[2,36]),o($Vn,[2,37]),o($Vn,[2,38]),{19:58,27:17,28:18,30:$V2,31:$V3,32:$V4,33:$V5,34:$V6,35:$V7,36:$V8,37:$V9,38:$Va,39:$Vb,51:[1,59]},{19:60,27:17,28:18,30:$V2,31:$V3,32:$V4,33:$V5,34:$V6,35:$V7,36:$V8,37:$V9,38:$Va,39:$Vb},{19:61,27:17,28:18,30:$V2,31:$V3,32:$V4,33:$V5,34:$V6,35:$V7,36:$V8,37:$V9,38:$Va,39:$Vb},{19:63,21:62,27:17,28:18,30:$V2,31:$V3,32:$V4,33:$V5,34:$V6,35:$V7,36:$V8,37:$V9,38:$Va,39:$Vb},{19:63,21:64,27:17,28:18,30:$V2,31:$V3,32:$V4,33:$V5,34:$V6,35:$V7,36:$V8,37:$V9,38:$Va,39:$Vb},{19:63,21:65,27:17,28:18,30:$V2,31:$V3,32:$V4,33:$V5,34:$V6,35:$V7,36:$V8,37:$V9,38:$Va,39:$Vb},o($Vj,[2,20]),{28:66,30:$V2,31:$V3,32:$V4,33:$V5,34:$V6,35:$V7,36:$V8,37:$V9,38:$Va,39:$Vb},{11:[1,67]},o($Vf,[2,4]),{1:[2,2]},{11:[2,13]},o($Vm,[2,33]),{19:63,21:68,27:17,28:18,30:$V2,31:$V3,32:$V4,33:$V5,34:$V6,35:$V7,36:$V8,37:$V9,38:$Va,39:$Vb},{9:[1,69]},{9:[1,70]},{9:[1,71]},{9:[1,72]},{22:[1,73]},o($Vo,[2,42],{7:75,9:[1,74]}),{24:[1,76]},{26:[1,77]},o($Vk,[2,22]),o([9,11,30,31,32,33,34,35,36,37,38,39,47,49,50],[2,3]),{46:[1,78]},{9:$Vp,29:$Vq,30:$Vr,31:$Vs,32:$Vt,48:79,51:$Vu,52:80,53:81,54:$Vv},{9:$Vp,29:$Vq,30:$Vr,31:$Vs,32:$Vt,48:89,51:$Vu,52:80,53:81,54:$Vv},{9:$Vp,29:$Vq,30:$Vr,31:$Vs,32:$Vt,48:90,51:$Vu,52:80,53:81,54:$Vv},{19:91,27:17,28:18,30:$V2,31:$V3,32:$V4,33:$V5,34:$V6,35:$V7,36:$V8,37:$V9,38:$Va,39:$Vb},o($Vi,[2,15]),{7:33,9:$V0,19:63,21:92,27:17,28:18,29:$Vh,30:$V2,31:$V3,32:$V4,33:$V5,34:$V6,35:$V7,36:$V8,37:$V9,38:$Va,39:$Vb},{29:[1,93]},o($Vi,[2,16]),o($Vi,[2,17]),o($Vm,[2,39]),{11:[2,45],33:$Vw},o($Vx,[2,47],{53:95,9:$Vp,29:$Vq,30:$Vr,31:$Vs,32:$Vt,51:$Vu,54:$Vv}),o($Vy,[2,49]),o($Vy,[2,51]),o($Vy,[2,52]),o($Vy,[2,53]),o($Vy,[2,54]),o($Vy,[2,55]),o($Vy,[2,56]),o($Vy,[2,57]),{11:[2,46],33:$Vw},{11:[2,43],33:$Vw},{11:[2,44]},o($Vo,[2,40]),{7:96,9:$V0},{9:$Vp,29:$Vq,30:$Vr,31:$Vs,32:$Vt,51:$Vu,52:97,53:81,54:$Vv},o($Vy,[2,50]),{19:63,21:98,27:17,28:18,30:$V2,31:$V3,32:$V4,33:$V5,34:$V6,35:$V7,36:$V8,37:$V9,38:$Va,39:$Vb},o($Vx,[2,48],{53:95,9:$Vp,29:$Vq,30:$Vr,31:$Vs,32:$Vt,51:$Vu,54:$Vv}),o($Vo,[2,41])],
defaultActions: {30:[2,1],54:[2,2],55:[2,13],91:[2,44]},
parseError: function parseError(str, hash) {
if (hash.recoverable) {
this.trace(str);
@ -637,35 +643,35 @@ options: {},
performAction: function anonymous(yy,yy_,$avoiding_name_collisions,YY_START) {
var YYSTATE=YY_START;
switch($avoiding_name_collisions) {
case 0:return 45;
case 0:return 50;
break;
case 1:return 8;
case 1:return 47;
break;
case 2:return 10;
case 2:return 49;
break;
case 3:return 10;
case 3:return 8;
break;
case 4:return 47;
case 4:return 10;
break;
case 5:return 29;
case 5:return 10;
break;
case 6:return 'BRKT';
case 6:return 51;
break;
case 7:return 50;
case 7:return 31;
break;
case 8:return 50;
case 8:return 'BRKT';
break;
case 9:return 50;
case 9:return 54;
break;
case 10:return 30;
case 10:return 54;
break;
case 11:return 11;
case 11:return 54;
break;
case 12:return 31;
case 12:return 32;
break;
case 13:return 33;
case 13:return 11;
break;
case 14:return 34;
case 14:return 33;
break;
case 15:return 35;
break;
@ -673,46 +679,50 @@ case 16:return 36;
break;
case 17:return 37;
break;
case 18:return 42;
case 18:return 38;
break;
case 19:return 40;
case 19:return 39;
break;
case 20:return 41;
case 20:return 44;
break;
case 21:return 43;
case 21:return 42;
break;
case 22:return 27;
case 22:return 43;
break;
case 23:return 32;
case 23:return 45;
break;
case 24:return 33;
case 24:return 29;
break;
case 25:return 28;
case 25:return 34;
break;
case 26:return 44;
case 26:return 35;
break;
case 27:return 21;
case 27:return 30;
break;
case 28:return 22;
case 28:return 46;
break;
case 29:return 18;
case 29:return 23;
break;
case 30:return 20;
case 30:return 24;
break;
case 31:return 23
case 31:return 20;
break;
case 32:return 24
case 32:return 22;
break;
case 33:return 9;
case 33:return 25
break;
case 34:return 'NEWLINE';
case 34:return 26
break;
case 35:return 6;
case 35:return 9;
break;
case 36:return 'NEWLINE';
break;
case 37:return 6;
break;
}
},
rules: [/^(?:style\b)/,/^(?:graph\b)/,/^(?:LR\b)/,/^(?:TD\b)/,/^(?:#[a-f0-9]+)/,/^(?:[0-9]+)/,/^(?:#)/,/^(?:px\b)/,/^(?:pt\b)/,/^(?:dot\b)/,/^(?::)/,/^(?:;)/,/^(?:,)/,/^(?:=)/,/^(?:\*)/,/^(?:\.)/,/^(?:<)/,/^(?:>)/,/^(?:--[x])/,/^(?:-->)/,/^(?:--[o])/,/^(?:---)/,/^(?:-)/,/^(?:\+)/,/^(?:=)/,/^(?:[a-zåäöæøA-ZÅÄÖÆØ_]+)/,/^(?:\|)/,/^(?:\()/,/^(?:\))/,/^(?:\[)/,/^(?:\])/,/^(?:\{)/,/^(?:\})/,/^(?:\s)/,/^(?:\n)/,/^(?:$)/],
conditions: {"INITIAL":{"rules":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35],"inclusive":true}}
rules: [/^(?:style\b)/,/^(?:classDef\b)/,/^(?:class\b)/,/^(?:graph\b)/,/^(?:LR\b)/,/^(?:TD\b)/,/^(?:#[a-f0-9]+)/,/^(?:[0-9]+)/,/^(?:#)/,/^(?:px\b)/,/^(?:pt\b)/,/^(?:dot\b)/,/^(?::)/,/^(?:;)/,/^(?:,)/,/^(?:=)/,/^(?:\*)/,/^(?:\.)/,/^(?:<)/,/^(?:>)/,/^(?:--[x])/,/^(?:-->)/,/^(?:--[o])/,/^(?:---)/,/^(?:-)/,/^(?:\+)/,/^(?:=)/,/^(?:[a-zåäöæøA-ZÅÄÖÆØ_]+)/,/^(?:\|)/,/^(?:\()/,/^(?:\))/,/^(?:\[)/,/^(?:\])/,/^(?:\{)/,/^(?:\})/,/^(?:\s)/,/^(?:\n)/,/^(?:$)/],
conditions: {"INITIAL":{"rules":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37],"inclusive":true}}
});
return lexer;
})();

View File

@ -12,7 +12,6 @@ describe('when parsing ',function(){
/*flow.parser.parse.parseError= function parseError(str, hash) {
console.log(str);
}*/
console.log('in mm spec');
});
it('should handle a nodes and edges',function(){
@ -101,6 +100,22 @@ 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();
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[0].start).toBe('A');
expect(edges[0].end).toBe('B');
expect(edges[0].text).toBe('This is the 123 s text');
expect(edges[1].start).toBe('A');
expect(edges[1].end).toBe('B');
expect(edges[1].text).toBe('This is the second edge');
});
it('should handle text in vertices with space',function(){
var res = flow.parser.parse('graph TD;A[chimpansen hoppar]-->C;');
@ -268,7 +283,7 @@ describe('when parsing ',function(){
expect(vert['T'].styles[1]).toBe('border:1px solid red');
});
ddescribe('special characters should be be handled.',function(){
describe('special characters should be be handled.',function(){
var charTest = function(char){
var res = flow.parser.parse('graph TD;A('+char+')-->B;');
@ -322,4 +337,50 @@ describe('when parsing ',function(){
});
});
it('should be possible to declare a class',function(){
var res = flow.parser.parse('graph TD;classDef exClass background:#bbb,border:1px solid red;');
//var res = flow.parser.parse('graph TD;style T background: #bbb;');
var classes = flow.parser.yy.getClasses();
expect(classes['exClass'].styles.length).toBe(2);
expect(classes['exClass'].styles[0]).toBe('background:#bbb');
expect(classes['exClass'].styles[1]).toBe('border:1px solid red');
});
it('should be possible to apply a class to a vertex',function(){
var statement = '';
statement = statement + 'graph TD;' + '\n';
statement = statement + 'classDef exClass background:#bbb,border:1px solid red;' + '\n';
statement = statement + 'a-->b;' + '\n';
statement = statement + 'class a exClass;';
var res = flow.parser.parse(statement);
var classes = flow.parser.yy.getClasses();
expect(classes['exClass'].styles.length).toBe(2);
expect(classes['exClass'].styles[0]).toBe('background:#bbb');
expect(classes['exClass'].styles[1]).toBe('border:1px solid red');
});
it('should be possible to apply a class to a comma separated list of vertices',function(){
var statement = '';
statement = statement + 'graph TD;' + '\n';
statement = statement + 'classDef exClass background:#bbb,border:1px solid red;' + '\n';
statement = statement + 'a-->b;' + '\n';
statement = statement + 'class a,b exClass;';
var res = flow.parser.parse(statement);
var classes = flow.parser.yy.getClasses();
var vertices = flow.parser.yy.getVertices();
expect(classes['exClass'].styles.length).toBe(2);
expect(classes['exClass'].styles[0]).toBe('background:#bbb');
expect(classes['exClass'].styles[1]).toBe('border:1px solid red');
expect(vertices['a'].classes[0]).toBe('exClass');
expect(vertices['b'].classes[0]).toBe('exClass');
});
});

View File

@ -38,8 +38,11 @@
<body>
<div class="mermaid">
graph LR;
classDef red fill:#ddd,stroke:#00f,stroke-width:2px,stroke-dasharray: 5, 5;
A---|This is the 123 s text|B;
A---|This is the second edge|B;
B---|This is the second edge|C;
class A red;
class B,C red;
</div>
<div class="mermaid">
graph TD;A(Astrid)-->B[Irene];
@ -52,15 +55,13 @@
E-->H[Bjarke];
E-->I[Ingvild];
</div>
<div class="mermaid">
<div class="mermaid2">
graph TD;
eag[Läsa bok 2]-->b;
b{Fundera}---|Klocka|c(Vidar);
b-->|Lego text|d(Bjarke går);
e(orphan);
style eag fill:#6ff,stroke:#f66,stroke-width:2px,stroke-dasharray: 5, 5;
style #2 stroke:#0f0;
style eag red;
</div>
</body>