Added support for nested subgraphs in grammar, part 1 of issue #161

This commit is contained in:
knsv
2015-05-09 19:05:47 +02:00
parent 594e69dd93
commit ae6bb57cf5
5 changed files with 23 additions and 11 deletions

View File

@@ -29,7 +29,7 @@ exports.addVertex = function (id, text, type, style) {
vertices[id] = {id: id, styles: [], classes:[]}; vertices[id] = {id: id, styles: [], classes:[]};
} }
if (typeof text !== 'undefined') { if (typeof text !== 'undefined') {
vertices[id].text = text; vertices[id].text = text.trim();
} }
if (typeof type !== 'undefined') { if (typeof type !== 'undefined') {
vertices[id].type = type; vertices[id].type = type;
@@ -59,7 +59,7 @@ exports.addLink = function (start, end, type, linktext) {
linktext = type.text; linktext = type.text;
if (typeof linktext !== 'undefined') { if (typeof linktext !== 'undefined') {
edge.text = linktext; edge.text = linktext.trim();
} }
if (typeof type !== 'undefined') { if (typeof type !== 'undefined') {

View File

@@ -17,7 +17,7 @@
"click" return 'CLICK'; "click" return 'CLICK';
"graph" return 'GRAPH'; "graph" return 'GRAPH';
"subgraph" return 'subgraph'; "subgraph" return 'subgraph';
"end" return 'end'; "end"\s* return 'end';
"LR" return 'DIR'; "LR" return 'DIR';
"RL" return 'DIR'; "RL" return 'DIR';
"TB" return 'DIR'; "TB" return 'DIR';
@@ -216,9 +216,9 @@ statement
{$$=[];} {$$=[];}
| clickStatement separator | clickStatement separator
{$$=[];} {$$=[];}
| subgraph text separator document end separator | subgraph text separator document end
{yy.addSubGraph($4,$2);} {yy.addSubGraph($4,$2);}
| subgraph separator document end separator | subgraph separator document end
{yy.addSubGraph($3,undefined);} {yy.addSubGraph($3,undefined);}
; ;

File diff suppressed because one or more lines are too long

View File

@@ -357,6 +357,17 @@ describe('when parsing ',function(){
expect(edges[0].type).toBe('arrow'); expect(edges[0].type).toBe('arrow');
}); });
it('should handle nested subgraphs',function(){
var str = 'graph TD\n' +
'A-->B\n' +
'subgraph myTitle\n\n' +
' c-->d \n\n' +
' subgraph inner\n\n e-->f \n end \n\n' +
'end\n';
var res = flow.parser.parse(str);
});
it('should handle subgraphs',function(){ it('should handle subgraphs',function(){
var res = flow.parser.parse('graph TD\nA-->B\nsubgraph myTitle\nc-->d\nend;'); var res = flow.parser.parse('graph TD\nA-->B\nsubgraph myTitle\nc-->d\nend;');

View File

@@ -38,6 +38,7 @@ module.exports.draw = function (text, id) {
var h = taskArray.length * (conf.barHeight + conf.barGap) + 2 * conf.topPadding; var h = taskArray.length * (conf.barHeight + conf.barGap) + 2 * conf.topPadding;
elem.style.height = h + 'px'; elem.style.height = h + 'px';
elem.height = h;
var svg = d3.select('#' + id); var svg = d3.select('#' + id);
// http://codepen.io/anon/pen/azLvWR // http://codepen.io/anon/pen/azLvWR