Skip to content

Commit

Permalink
Added support for nested subgraphs in grammar, part 1 of issue #161
Browse files Browse the repository at this point in the history
  • Loading branch information
knsv committed May 9, 2015
1 parent 594e69d commit ae6bb57
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/diagrams/flowchart/graphDb.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ exports.addVertex = function (id, text, type, style) {
vertices[id] = {id: id, styles: [], classes:[]};
}
if (typeof text !== 'undefined') {
vertices[id].text = text;
vertices[id].text = text.trim();
}
if (typeof type !== 'undefined') {
vertices[id].type = type;
Expand Down Expand Up @@ -59,7 +59,7 @@ exports.addLink = function (start, end, type, linktext) {
linktext = type.text;

if (typeof linktext !== 'undefined') {
edge.text = linktext;
edge.text = linktext.trim();
}

if (typeof type !== 'undefined') {
Expand Down
6 changes: 3 additions & 3 deletions src/diagrams/flowchart/parser/flow.jison
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"click" return 'CLICK';
"graph" return 'GRAPH';
"subgraph" return 'subgraph';
"end" return 'end';
"end"\s* return 'end';
"LR" return 'DIR';
"RL" return 'DIR';
"TB" return 'DIR';
Expand Down Expand Up @@ -216,9 +216,9 @@ statement
{$$=[];}
| clickStatement separator
{$$=[];}
| subgraph text separator document end separator
| subgraph text separator document end
{yy.addSubGraph($4,$2);}
| subgraph separator document end separator
| subgraph separator document end
{yy.addSubGraph($3,undefined);}
;

Expand Down
12 changes: 6 additions & 6 deletions src/diagrams/flowchart/parser/flow.js

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions src/diagrams/flowchart/parser/flow.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,17 @@ describe('when parsing ',function(){
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(){
var res = flow.parser.parse('graph TD\nA-->B\nsubgraph myTitle\nc-->d\nend;');

Expand Down
1 change: 1 addition & 0 deletions src/diagrams/gantt/ganttRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ module.exports.draw = function (text, id) {
var h = taskArray.length * (conf.barHeight + conf.barGap) + 2 * conf.topPadding;

elem.style.height = h + 'px';
elem.height = h;
var svg = d3.select('#' + id);

// http://codepen.io/anon/pen/azLvWR
Expand Down

0 comments on commit ae6bb57

Please sign in to comment.