mirror of
				https://github.com/mermaid-js/mermaid.git
				synced 2025-11-04 04:44:08 +01:00 
			
		
		
		
	Merge pull request #1345 from GDFaber/feature/1343_add_flowchart_subroutine_shape
Add flowchart subroutine node shape
This commit is contained in:
		@@ -652,4 +652,23 @@ describe('Flowchart', () => {
 | 
			
		||||
      { 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 C someclass;
 | 
			
		||||
  </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">
 | 
			
		||||
    graph LR
 | 
			
		||||
    A[(cylindrical<br />shape<br />test)]
 | 
			
		||||
 
 | 
			
		||||
@@ -89,6 +89,17 @@ graph LR
 | 
			
		||||
    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
 | 
			
		||||
 | 
			
		||||
```
 | 
			
		||||
 
 | 
			
		||||
@@ -154,6 +154,28 @@ function stadium(parent, bbox, node) {
 | 
			
		||||
  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) {
 | 
			
		||||
  const w = bbox.width;
 | 
			
		||||
  const rx = w / 2;
 | 
			
		||||
@@ -221,6 +243,7 @@ export function addToRender(render) {
 | 
			
		||||
  render.shapes().question = question;
 | 
			
		||||
  render.shapes().hexagon = hexagon;
 | 
			
		||||
  render.shapes().stadium = stadium;
 | 
			
		||||
  render.shapes().subroutine = subroutine;
 | 
			
		||||
  render.shapes().cylinder = cylinder;
 | 
			
		||||
 | 
			
		||||
  // Add custom shape for box with inverted arrow on left side
 | 
			
		||||
@@ -246,6 +269,7 @@ export function addToRenderV2(addShape) {
 | 
			
		||||
  addShape({ question });
 | 
			
		||||
  addShape({ hexagon });
 | 
			
		||||
  addShape({ stadium });
 | 
			
		||||
  addShape({ subroutine });
 | 
			
		||||
  addShape({ cylinder });
 | 
			
		||||
 | 
			
		||||
  // 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_left', 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]) {
 | 
			
		||||
    it(`should add a ${shapeType} shape that renders a properly translated polygon element`, function() {
 | 
			
		||||
      const mockRender = MockRender();
 | 
			
		||||
 
 | 
			
		||||
@@ -119,6 +119,9 @@ export const addVertices = function(vert, g, svgId) {
 | 
			
		||||
      case 'stadium':
 | 
			
		||||
        _shape = 'stadium';
 | 
			
		||||
        break;
 | 
			
		||||
      case 'subroutine':
 | 
			
		||||
        _shape = 'subroutine';
 | 
			
		||||
        break;
 | 
			
		||||
      case 'cylinder':
 | 
			
		||||
        _shape = 'cylinder';
 | 
			
		||||
        break;
 | 
			
		||||
 
 | 
			
		||||
@@ -119,6 +119,9 @@ export const addVertices = function(vert, g, svgId) {
 | 
			
		||||
      case 'stadium':
 | 
			
		||||
        _shape = 'stadium';
 | 
			
		||||
        break;
 | 
			
		||||
      case 'subroutine':
 | 
			
		||||
        _shape = 'subroutine';
 | 
			
		||||
        break;
 | 
			
		||||
      case 'cylinder':
 | 
			
		||||
        _shape = 'cylinder';
 | 
			
		||||
        break;
 | 
			
		||||
 
 | 
			
		||||
@@ -23,6 +23,7 @@ describe('the flowchart renderer', function() {
 | 
			
		||||
      ['circle', 'circle'],
 | 
			
		||||
      ['ellipse', 'ellipse'],
 | 
			
		||||
      ['stadium', 'stadium'],
 | 
			
		||||
      ['subroutine', 'subroutine'],
 | 
			
		||||
      ['cylinder', 'cylinder'],
 | 
			
		||||
      ['group', 'rect']
 | 
			
		||||
    ].forEach(function([type, expectedShape, expectedRadios = 0]) {
 | 
			
		||||
 
 | 
			
		||||
@@ -87,6 +87,8 @@
 | 
			
		||||
"-)"                  return '-)';
 | 
			
		||||
"(["                  return 'STADIUMSTART';
 | 
			
		||||
"])"                  return 'STADIUMEND';
 | 
			
		||||
"[["                  return 'SUBROUTINESTART';
 | 
			
		||||
"]]"                  return 'SUBROUTINEEND';
 | 
			
		||||
"[("                  return 'CYLINDERSTART';
 | 
			
		||||
")]"                  return 'CYLINDEREND';
 | 
			
		||||
\-                    return 'MINUS';
 | 
			
		||||
@@ -316,6 +318,8 @@ vertex:  idString SQS text SQE
 | 
			
		||||
        {$$ = $1;yy.addVertex($1,$3,'ellipse');}
 | 
			
		||||
    | idString STADIUMSTART text STADIUMEND
 | 
			
		||||
        {$$ = $1;yy.addVertex($1,$3,'stadium');}
 | 
			
		||||
    | idString SUBROUTINESTART text SUBROUTINEEND
 | 
			
		||||
        {$$ = $1;yy.addVertex($1,$3,'subroutine');}
 | 
			
		||||
    | idString CYLINDERSTART text CYLINDEREND
 | 
			
		||||
        {$$ = $1;yy.addVertex($1,$3,'cylinder');}
 | 
			
		||||
    | 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;
 | 
			
		||||
 | 
			
		||||
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;
 | 
			
		||||
%%
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user