mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-12-08 21:45:12 +01:00
Fix subgraph issue
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);}
|
||||
|
||||
@@ -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;')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user