mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-02 15:16:49 +02:00
#945 Support for forks and joins
This commit is contained in:
@@ -161,6 +161,24 @@ describe('State diagram', () => {
|
|||||||
`,
|
`,
|
||||||
{ logLevel: 0 }
|
{ logLevel: 0 }
|
||||||
);
|
);
|
||||||
|
});
|
||||||
|
it('should render forks and joins', () => {
|
||||||
|
imgSnapshotTest(
|
||||||
|
`
|
||||||
|
stateDiagram
|
||||||
|
state fork_state <<fork>>
|
||||||
|
[*] --> fork_state
|
||||||
|
fork_state --> State2
|
||||||
|
fork_state --> State3
|
||||||
|
|
||||||
|
state join_state <<join>>
|
||||||
|
State2 --> join_state
|
||||||
|
State3 --> join_state
|
||||||
|
join_state --> State4
|
||||||
|
State4 --> [*]
|
||||||
|
`,
|
||||||
|
{ logLevel: 0 }
|
||||||
|
);
|
||||||
cy.get('svg');
|
cy.get('svg');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -43,8 +43,10 @@
|
|||||||
<SCALE>\s+"width" {this.popState();}
|
<SCALE>\s+"width" {this.popState();}
|
||||||
|
|
||||||
<INITIAL,struct>"state"\s+ { this.pushState('STATE'); }
|
<INITIAL,struct>"state"\s+ { this.pushState('STATE'); }
|
||||||
<STATE>.*"<<fork>>" {this.popState();console.log('Fork: ',yytext);return 'FORK';}
|
<STATE>.*"<<fork>>" {this.popState();yytext=yytext.slice(0,-8).trim(); console.warn('Fork Fork: ',yytext);return 'FORK';}
|
||||||
<STATE>.*"<<join>>" {this.popState();console.log('Join: ',yytext);return 'JOIN';}
|
<STATE>.*"<<join>>" {this.popState();yytext=yytext.slice(0,-8).trim();console.warn('Fork Join: ',yytext);return 'JOIN';}
|
||||||
|
<STATE>.*"[[fork]]" {this.popState();yytext=yytext.slice(0,-8).trim();console.warn('Fork Fork: ',yytext);return 'FORK';}
|
||||||
|
<STATE>.*"[[join]]" {this.popState();yytext=yytext.slice(0,-8).trim();console.warn('Fork Join: ',yytext);return 'JOIN';}
|
||||||
<STATE>["] this.begin("STATE_STRING");
|
<STATE>["] this.begin("STATE_STRING");
|
||||||
<STATE>"as"\s* {this.popState();this.pushState('STATE_ID');return "AS";}
|
<STATE>"as"\s* {this.popState();this.pushState('STATE_ID');return "AS";}
|
||||||
<STATE_ID>[^\n\{]* {this.popState();console.log('STATE_ID', yytext);return "ID";}
|
<STATE_ID>[^\n\{]* {this.popState();console.log('STATE_ID', yytext);return "ID";}
|
||||||
@@ -135,8 +137,12 @@ statement
|
|||||||
//console.warn('Adding document for state with id ', $3, $4); yy.addDocument($3);
|
//console.warn('Adding document for state with id ', $3, $4); yy.addDocument($3);
|
||||||
$$={ stmt: 'state', id: $3, type: 'default', description: $1, doc: $5 }
|
$$={ stmt: 'state', id: $3, type: 'default', description: $1, doc: $5 }
|
||||||
}
|
}
|
||||||
| FORK
|
| FORK {
|
||||||
| JOIN
|
$$={ stmt: 'state', id: $1, type: 'fork' }
|
||||||
|
}
|
||||||
|
| JOIN {
|
||||||
|
$$={ stmt: 'state', id: $1, type: 'join' }
|
||||||
|
}
|
||||||
| CONCURRENT
|
| CONCURRENT
|
||||||
| note notePosition ID NOTE_TEXT
|
| note notePosition ID NOTE_TEXT
|
||||||
{
|
{
|
||||||
|
@@ -168,6 +168,16 @@ const drawEndState = g => {
|
|||||||
.attr('cx', conf.padding + 7)
|
.attr('cx', conf.padding + 7)
|
||||||
.attr('cy', conf.padding + 7);
|
.attr('cy', conf.padding + 7);
|
||||||
};
|
};
|
||||||
|
const drawForkJoinState = g => {
|
||||||
|
return g
|
||||||
|
.append('rect')
|
||||||
|
.style('stroke', 'black')
|
||||||
|
.style('fill', 'black')
|
||||||
|
.attr('width', 70)
|
||||||
|
.attr('height', 7)
|
||||||
|
.attr('x', conf.padding)
|
||||||
|
.attr('y', conf.padding);
|
||||||
|
};
|
||||||
|
|
||||||
export const drawText = function(elem, textData, width) {
|
export const drawText = function(elem, textData, width) {
|
||||||
// Remove and ignore br:s
|
// Remove and ignore br:s
|
||||||
@@ -264,6 +274,7 @@ export const drawState = function(elem, stateDef, graph, doc) {
|
|||||||
|
|
||||||
if (stateDef.type === 'start') drawStartState(g);
|
if (stateDef.type === 'start') drawStartState(g);
|
||||||
if (stateDef.type === 'end') drawEndState(g);
|
if (stateDef.type === 'end') drawEndState(g);
|
||||||
|
if (stateDef.type === 'fork' || stateDef.type === 'join') drawForkJoinState(g);
|
||||||
if (stateDef.type === 'note') drawNote(stateDef.note.text, g);
|
if (stateDef.type === 'note') drawNote(stateDef.note.text, g);
|
||||||
if (stateDef.type === 'default' && stateDef.descriptions.length === 0)
|
if (stateDef.type === 'default' && stateDef.descriptions.length === 0)
|
||||||
drawSimpleState(g, stateDef);
|
drawSimpleState(g, stateDef);
|
||||||
|
@@ -61,7 +61,7 @@ const insertMarkers = function(elem) {
|
|||||||
export const draw = function(text, id) {
|
export const draw = function(text, id) {
|
||||||
parser.yy.clear();
|
parser.yy.clear();
|
||||||
parser.parse(text);
|
parser.parse(text);
|
||||||
logger.info('Rendering diagram ' + text);
|
logger.warn('Rendering diagram ' + text);
|
||||||
|
|
||||||
// /// / Fetch the default direction, use TD if none was found
|
// /// / Fetch the default direction, use TD if none was found
|
||||||
const diagram = d3.select(`[id='${id}']`);
|
const diagram = d3.select(`[id='${id}']`);
|
||||||
|
Reference in New Issue
Block a user