Fix subgraph issue

This commit is contained in:
Tyler Long
2018-03-17 18:12:24 +08:00
parent 015b976c28
commit 52d0605066
6 changed files with 25 additions and 8 deletions

View File

@@ -318,7 +318,7 @@ export const addSubGraph = function (list, title) {
return a.filter(function (item) {
const type = typeof item
if (item === ' ') {
if (item.trim() === '') {
return false
}
if (type in prims) { return prims[type].hasOwnProperty(item) ? false : (prims[type][item] = true) } else { return objs.indexOf(item) >= 0 ? false : objs.push(item) }
@@ -329,7 +329,7 @@ export const addSubGraph = function (list, title) {
nodeList = uniq(nodeList.concat.apply(nodeList, list))
const subGraph = { id: 'subGraph' + subCount, nodes: nodeList, title: title }
const subGraph = { id: 'subGraph' + subCount, nodes: nodeList, title: title.trim() }
subGraphs.push(subGraph)
subCount = subCount + 1
return subGraph.id

View File

@@ -225,7 +225,7 @@ statement
{$$=[];}
| clickStatement separator
{$$=[];}
| subgraph text separator document end
| subgraph text separator document end
{$$=yy.addSubGraph($4,$2);}
| subgraph separator document end
{$$=yy.addSubGraph($3,undefined);}

View File

@@ -22,6 +22,17 @@ describe('when parsing ', function () {
expect(edges[0].text).toBe('')
})
it('should handle subgraph with tab indentation', function () {
const res = flow.parser.parse('graph TB\nsubgraph One\n\ta1-->a2\nend')
const subgraphs = flow.parser.yy.getSubGraphs()
expect(subgraphs.length).toBe(1)
const subgraph = subgraphs[0]
expect(subgraph.nodes.length).toBe(2)
expect(subgraph.nodes[0]).toBe('a1')
expect(subgraph.nodes[1]).toBe('a2')
expect(subgraph.title).toBe('One')
})
it('should handle angle bracket ' > ' as direction LR', function () {
const res = flow.parser.parse('graph >;A-->B;')