Skip to content

Commit

Permalink
Merge pull request #4553 from tomperr/fix/4550-chaining-style
Browse files Browse the repository at this point in the history
fix(flowchart): allow multiple vertices with style
  • Loading branch information
sidharthv96 committed Jun 28, 2023
2 parents 0a3dcfa + 9e024fd commit c042c4a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
16 changes: 16 additions & 0 deletions packages/mermaid/src/diagrams/flowchart/parser/flow-style.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,4 +338,20 @@ describe('[Style] when parsing', () => {

expect(edges[0].type).toBe('arrow_point');
});

it('should handle multiple vertices with style', function () {
const res = flow.parser.parse(`
graph TD
classDef C1 stroke-dasharray:4
classDef C2 stroke-dasharray:6
A & B:::C1 & D:::C1 --> E:::C2
`);

const vert = flow.parser.yy.getVertices();

expect(vert['A'].classes.length).toBe(0);
expect(vert['B'].classes[0]).toBe('C1');
expect(vert['D'].classes[0]).toBe('C1');
expect(vert['E'].classes[0]).toBe('C2');
});
});
12 changes: 8 additions & 4 deletions packages/mermaid/src/diagrams/flowchart/parser/flow.jison
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ statement

separator: NEWLINE | SEMI | EOF ;


verticeStatement: verticeStatement link node
{ /* console.warn('vs',$1.stmt,$3); */ yy.addLink($1.stmt,$3,$2); $$ = { stmt: $3, nodes: $3.concat($1.nodes) } }
| verticeStatement link node spaceList
Expand All @@ -368,12 +368,16 @@ verticeStatement: verticeStatement link node
|node { /*console.warn('noda', $1);*/ $$ = {stmt: $1, nodes:$1 }}
;

node: vertex
node: styledVertex
{ /* console.warn('nod', $1); */ $$ = [$1];}
| node spaceList AMP spaceList vertex
| node spaceList AMP spaceList styledVertex
{ $$ = $1.concat($5); /* console.warn('pip', $1[0], $5, $$); */ }
;

styledVertex: vertex
{ /* console.warn('nod', $1); */ $$ = $1;}
| vertex STYLE_SEPARATOR idString
{$$ = [$1];yy.setClass($1,$3)}
{$$ = $1;yy.setClass($1,$3)}
;

vertex: idString SQS text SQE
Expand Down

0 comments on commit c042c4a

Please sign in to comment.