mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-01-14 06:43:25 +08:00
Merge pull request #1345 from GDFaber/feature/1343_add_flowchart_subroutine_shape
Add flowchart subroutine node shape
This commit is contained in:
commit
6ec731e263
@ -652,4 +652,23 @@ describe('Flowchart', () => {
|
|||||||
{ flowchart: { htmlLabels: false } }
|
{ flowchart: { htmlLabels: false } }
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('32: Render Subroutine shape', () => {
|
||||||
|
imgSnapshotTest(
|
||||||
|
`graph LR
|
||||||
|
A[[subroutine shape test]]
|
||||||
|
A -->|Get money| B[[Go shopping]]
|
||||||
|
B --> C[[Let me think...<br />Do I want something for work,<br />something to spend every free second with,<br />or something to get around?]]
|
||||||
|
C -->|One| D[[Laptop]]
|
||||||
|
C -->|Two| E[[iPhone]]
|
||||||
|
C -->|Three| F[[Car<br/>wroom wroom]]
|
||||||
|
click A "index.html#link-clicked" "link test"
|
||||||
|
click B testClick "click test"
|
||||||
|
classDef someclass fill:#f96;
|
||||||
|
class A someclass;
|
||||||
|
class C someclass;
|
||||||
|
`,
|
||||||
|
{ flowchart: { htmlLabels: false } }
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
14
dist/index.html
vendored
14
dist/index.html
vendored
@ -338,6 +338,20 @@ graph TB
|
|||||||
class A someclass;
|
class A someclass;
|
||||||
class C someclass;
|
class C someclass;
|
||||||
</div>
|
</div>
|
||||||
|
<div class="mermaid">
|
||||||
|
graph LR
|
||||||
|
A[[subroutine shape test]]
|
||||||
|
A -->|Get money| B[[Go shopping]]
|
||||||
|
B --> C[[Let me think...<br />Do I want something for work,<br />something to spend every free second with,<br />or something to get around?]]
|
||||||
|
C -->|One| D[[Laptop]]
|
||||||
|
C -->|Two| E[[iPhone]]
|
||||||
|
C -->|Three| F[[Car<br/>wroom wroom]]
|
||||||
|
click A "index.html#link-clicked" "link test"
|
||||||
|
click B testClick "click test"
|
||||||
|
classDef someclass fill:#f96;
|
||||||
|
class A someclass;
|
||||||
|
class C someclass;
|
||||||
|
</div>
|
||||||
<div class="mermaid">
|
<div class="mermaid">
|
||||||
graph LR
|
graph LR
|
||||||
A[(cylindrical<br />shape<br />test)]
|
A[(cylindrical<br />shape<br />test)]
|
||||||
|
@ -89,6 +89,17 @@ graph LR
|
|||||||
id1([This is the text in the box])
|
id1([This is the text in the box])
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### A node in a subroutine shape
|
||||||
|
|
||||||
|
```
|
||||||
|
graph LR
|
||||||
|
id1[[This is the text in the box]]
|
||||||
|
```
|
||||||
|
```mermaid
|
||||||
|
graph LR
|
||||||
|
id1[[This is the text in the box]]
|
||||||
|
```
|
||||||
|
|
||||||
### A node in a cylindrical shape
|
### A node in a cylindrical shape
|
||||||
|
|
||||||
```
|
```
|
||||||
|
@ -154,6 +154,28 @@ function stadium(parent, bbox, node) {
|
|||||||
return shapeSvg;
|
return shapeSvg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function subroutine(parent, bbox, node) {
|
||||||
|
const w = bbox.width;
|
||||||
|
const h = bbox.height;
|
||||||
|
const points = [
|
||||||
|
{ x: 0, y: 0 },
|
||||||
|
{ x: w, y: 0 },
|
||||||
|
{ x: w, y: -h },
|
||||||
|
{ x: 0, y: -h },
|
||||||
|
{ x: 0, y: 0 },
|
||||||
|
{ x: -8, y: 0 },
|
||||||
|
{ x: w + 8, y: 0 },
|
||||||
|
{ x: w + 8, y: -h },
|
||||||
|
{ x: -8, y: -h },
|
||||||
|
{ x: -8, y: 0 }
|
||||||
|
];
|
||||||
|
const shapeSvg = insertPolygonShape(parent, w, h, points);
|
||||||
|
node.intersect = function(point) {
|
||||||
|
return dagreD3.intersect.polygon(node, points, point);
|
||||||
|
};
|
||||||
|
return shapeSvg;
|
||||||
|
}
|
||||||
|
|
||||||
function cylinder(parent, bbox, node) {
|
function cylinder(parent, bbox, node) {
|
||||||
const w = bbox.width;
|
const w = bbox.width;
|
||||||
const rx = w / 2;
|
const rx = w / 2;
|
||||||
@ -221,6 +243,7 @@ export function addToRender(render) {
|
|||||||
render.shapes().question = question;
|
render.shapes().question = question;
|
||||||
render.shapes().hexagon = hexagon;
|
render.shapes().hexagon = hexagon;
|
||||||
render.shapes().stadium = stadium;
|
render.shapes().stadium = stadium;
|
||||||
|
render.shapes().subroutine = subroutine;
|
||||||
render.shapes().cylinder = cylinder;
|
render.shapes().cylinder = cylinder;
|
||||||
|
|
||||||
// Add custom shape for box with inverted arrow on left side
|
// Add custom shape for box with inverted arrow on left side
|
||||||
@ -246,6 +269,7 @@ export function addToRenderV2(addShape) {
|
|||||||
addShape({ question });
|
addShape({ question });
|
||||||
addShape({ hexagon });
|
addShape({ hexagon });
|
||||||
addShape({ stadium });
|
addShape({ stadium });
|
||||||
|
addShape({ subroutine });
|
||||||
addShape({ cylinder });
|
addShape({ cylinder });
|
||||||
|
|
||||||
// Add custom shape for box with inverted arrow on left side
|
// Add custom shape for box with inverted arrow on left side
|
||||||
|
@ -65,7 +65,8 @@ describe('flowchart shapes', function() {
|
|||||||
['lean_right', 4, useWidth, useHeight],
|
['lean_right', 4, useWidth, useHeight],
|
||||||
['lean_left', 4, useWidth, useHeight],
|
['lean_left', 4, useWidth, useHeight],
|
||||||
['trapezoid', 4, useWidth, useHeight],
|
['trapezoid', 4, useWidth, useHeight],
|
||||||
['inv_trapezoid', 4, useWidth, useHeight]
|
['inv_trapezoid', 4, useWidth, useHeight],
|
||||||
|
['subroutine', 10, useWidth, useHeight],
|
||||||
].forEach(function([shapeType, expectedPointCount, getW, getH]) {
|
].forEach(function([shapeType, expectedPointCount, getW, getH]) {
|
||||||
it(`should add a ${shapeType} shape that renders a properly translated polygon element`, function() {
|
it(`should add a ${shapeType} shape that renders a properly translated polygon element`, function() {
|
||||||
const mockRender = MockRender();
|
const mockRender = MockRender();
|
||||||
|
@ -119,6 +119,9 @@ export const addVertices = function(vert, g, svgId) {
|
|||||||
case 'stadium':
|
case 'stadium':
|
||||||
_shape = 'stadium';
|
_shape = 'stadium';
|
||||||
break;
|
break;
|
||||||
|
case 'subroutine':
|
||||||
|
_shape = 'subroutine';
|
||||||
|
break;
|
||||||
case 'cylinder':
|
case 'cylinder':
|
||||||
_shape = 'cylinder';
|
_shape = 'cylinder';
|
||||||
break;
|
break;
|
||||||
|
@ -119,6 +119,9 @@ export const addVertices = function(vert, g, svgId) {
|
|||||||
case 'stadium':
|
case 'stadium':
|
||||||
_shape = 'stadium';
|
_shape = 'stadium';
|
||||||
break;
|
break;
|
||||||
|
case 'subroutine':
|
||||||
|
_shape = 'subroutine';
|
||||||
|
break;
|
||||||
case 'cylinder':
|
case 'cylinder':
|
||||||
_shape = 'cylinder';
|
_shape = 'cylinder';
|
||||||
break;
|
break;
|
||||||
|
@ -23,6 +23,7 @@ describe('the flowchart renderer', function() {
|
|||||||
['circle', 'circle'],
|
['circle', 'circle'],
|
||||||
['ellipse', 'ellipse'],
|
['ellipse', 'ellipse'],
|
||||||
['stadium', 'stadium'],
|
['stadium', 'stadium'],
|
||||||
|
['subroutine', 'subroutine'],
|
||||||
['cylinder', 'cylinder'],
|
['cylinder', 'cylinder'],
|
||||||
['group', 'rect']
|
['group', 'rect']
|
||||||
].forEach(function([type, expectedShape, expectedRadios = 0]) {
|
].forEach(function([type, expectedShape, expectedRadios = 0]) {
|
||||||
|
@ -87,6 +87,8 @@
|
|||||||
"-)" return '-)';
|
"-)" return '-)';
|
||||||
"([" return 'STADIUMSTART';
|
"([" return 'STADIUMSTART';
|
||||||
"])" return 'STADIUMEND';
|
"])" return 'STADIUMEND';
|
||||||
|
"[[" return 'SUBROUTINESTART';
|
||||||
|
"]]" return 'SUBROUTINEEND';
|
||||||
"[(" return 'CYLINDERSTART';
|
"[(" return 'CYLINDERSTART';
|
||||||
")]" return 'CYLINDEREND';
|
")]" return 'CYLINDEREND';
|
||||||
\- return 'MINUS';
|
\- return 'MINUS';
|
||||||
@ -316,6 +318,8 @@ vertex: idString SQS text SQE
|
|||||||
{$$ = $1;yy.addVertex($1,$3,'ellipse');}
|
{$$ = $1;yy.addVertex($1,$3,'ellipse');}
|
||||||
| idString STADIUMSTART text STADIUMEND
|
| idString STADIUMSTART text STADIUMEND
|
||||||
{$$ = $1;yy.addVertex($1,$3,'stadium');}
|
{$$ = $1;yy.addVertex($1,$3,'stadium');}
|
||||||
|
| idString SUBROUTINESTART text SUBROUTINEEND
|
||||||
|
{$$ = $1;yy.addVertex($1,$3,'subroutine');}
|
||||||
| idString CYLINDERSTART text CYLINDEREND
|
| idString CYLINDERSTART text CYLINDEREND
|
||||||
{$$ = $1;yy.addVertex($1,$3,'cylinder');}
|
{$$ = $1;yy.addVertex($1,$3,'cylinder');}
|
||||||
| idString PS text PE
|
| idString PS text PE
|
||||||
@ -474,5 +478,5 @@ alphaNumToken : PUNCTUATION | AMP | UNICODE_TEXT | NUM| ALPHA | COLON | COMMA |
|
|||||||
|
|
||||||
idStringToken : ALPHA|UNDERSCORE |UNICODE_TEXT | NUM| COLON | COMMA | PLUS | MINUS | DOWN |EQUALS | MULT | BRKT | DOT | PUNCTUATION | AMP;
|
idStringToken : ALPHA|UNDERSCORE |UNICODE_TEXT | NUM| COLON | COMMA | PLUS | MINUS | DOWN |EQUALS | MULT | BRKT | DOT | PUNCTUATION | AMP;
|
||||||
|
|
||||||
graphCodeTokens: STADIUMSTART | STADIUMEND | CYLINDERSTART | CYLINDEREND | TRAPSTART | TRAPEND | INVTRAPSTART | INVTRAPEND | PIPE | PS | PE | SQS | SQE | DIAMOND_START | DIAMOND_STOP | TAGSTART | TAGEND | ARROW_CROSS | ARROW_POINT | ARROW_CIRCLE | ARROW_OPEN | QUOTE | SEMI;
|
graphCodeTokens: STADIUMSTART | STADIUMEND | SUBROUTINESTART | SUBROUTINEEND | CYLINDERSTART | CYLINDEREND | TRAPSTART | TRAPEND | INVTRAPSTART | INVTRAPEND | PIPE | PS | PE | SQS | SQE | DIAMOND_START | DIAMOND_STOP | TAGSTART | TAGEND | ARROW_CROSS | ARROW_POINT | ARROW_CIRCLE | ARROW_OPEN | QUOTE | SEMI;
|
||||||
%%
|
%%
|
||||||
|
Loading…
x
Reference in New Issue
Block a user