Skip to content

Commit

Permalink
Merge pull request #5825 from mermaid-js/knsv/new-shapes
Browse files Browse the repository at this point in the history
New Flowchart Shapes (with new syntax)
  • Loading branch information
sidharthv96 authored Oct 3, 2024
2 parents ef8c002 + 43e8f83 commit 02cf111
Show file tree
Hide file tree
Showing 98 changed files with 6,949 additions and 391 deletions.
5 changes: 5 additions & 0 deletions .changeset/popular-hounds-smash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@mermaid-js/layout-elk': patch
---

chore: Update render options
5 changes: 5 additions & 0 deletions .changeset/rude-meals-invite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'mermaid': minor
---

New Flowchart Shapes (with new syntax)
1 change: 1 addition & 0 deletions .cspell/code-terms.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ concat
controlx
controly
CSSCLASS
curv
CYLINDEREND
CYLINDERSTART
DAGA
Expand Down
3 changes: 3 additions & 0 deletions .cspell/cspell.config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ dictionaryDefinitions:
- name: suggestions
words:
- none
- disp
- subproc
- tria
suggestWords:
- seperator:separator
- vertice:vertex
Expand Down
2 changes: 2 additions & 0 deletions .cspell/mermaid-terms.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ bmatrix
braintree
catmull
compositTitleSize
curv
doublecircle
elems
gantt
Expand All @@ -24,6 +25,7 @@ multigraph
nodesep
NOTEGROUP
Pinterest
procs
rankdir
ranksep
rect
Expand Down
142 changes: 142 additions & 0 deletions cypress/integration/rendering/flowchart-shape-alias.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
import { imgSnapshotTest } from '../../helpers/util.ts';

const aliasSet1 = ['process', 'rect', 'proc', 'rectangle'] as const;

const aliasSet2 = ['event', 'rounded'] as const;

const aliasSet3 = ['stadium', 'pill', 'terminal'] as const;

const aliasSet4 = ['fr-rect', 'subproc', 'subprocess', 'framed-rectangle', 'subroutine'] as const;

const aliasSet5 = ['db', 'database', 'cylinder', 'cyl'] as const;

const aliasSet6 = ['diam', 'decision', 'diamond'] as const;

const aliasSet7 = ['hex', 'hexagon', 'prepare'] as const;

const aliasSet8 = ['lean-r', 'lean-right', 'in-out'] as const;

const aliasSet9 = ['lean-l', 'lean-left', 'out-in'] as const;

const aliasSet10 = ['trap-b', 'trapezoid-bottom', 'priority'] as const;

const aliasSet11 = ['trap-t', 'trapezoid-top', 'manual'] as const;

const aliasSet12 = ['dbl-circ', 'double-circle'] as const;

const aliasSet13 = ['notched-rectangle', 'card', 'notch-rect'] as const;

const aliasSet14 = [
'lin-rect',
'lined-rectangle',
'lin-proc',
'lined-process',
'shaded-process',
] as const;

const aliasSet15 = ['sm-circ', 'small-circle', 'start'] as const;

const aliasSet16 = ['fr-circ', 'framed-circle', 'stop'] as const;

const aliasSet17 = ['fork', 'join'] as const;
// brace-r', 'braces'
const aliasSet18 = ['comment', 'brace-l'] as const;

const aliasSet19 = ['bolt', 'com-link', 'lightning-bolt'] as const;

const aliasSet20 = ['doc', 'document'] as const;

const aliasSet21 = ['delay', 'half-rounded-rectangle'] as const;

const aliasSet22 = ['h-cyl', 'das', 'horizontal-cylinder'] as const;

const aliasSet23 = ['lin-cyl', 'disk', 'lined-cylinder'] as const;

const aliasSet24 = ['curv-trap', 'display', 'curved-trapezoid'] as const;

const aliasSet25 = ['div-rect', 'div-proc', 'divided-rectangle', 'divided-process'] as const;

const aliasSet26 = ['extract', 'tri', 'triangle'] as const;

const aliasSet27 = ['win-pane', 'internal-storage', 'window-pane'] as const;

const aliasSet28 = ['f-circ', 'junction', 'filled-circle'] as const;

const aliasSet29 = ['lin-doc', 'lined-document'] as const;

const aliasSet30 = ['notch-pent', 'loop-limit', 'notched-pentagon'] as const;

const aliasSet31 = ['flip-tri', 'manual-file', 'flipped-triangle'] as const;

const aliasSet32 = ['sl-rect', 'manual-input', 'sloped-rectangle'] as const;

const aliasSet33 = ['docs', 'documents', 'st-doc', 'stacked-document'] as const;

const aliasSet34 = ['procs', 'processes', 'st-rect', 'stacked-rectangle'] as const;

const aliasSet35 = ['flag', 'paper-tape'] as const;

const aliasSet36 = ['bow-rect', 'stored-data', 'bow-tie-rectangle'] as const;

const aliasSet37 = ['cross-circ', 'summary', 'crossed-circle'] as const;

const aliasSet38 = ['tag-doc', 'tagged-document'] as const;

const aliasSet39 = ['tag-rect', 'tag-proc', 'tagged-rectangle', 'tagged-process'] as const;

const aliasSet40 = ['collate', 'hourglass'] as const;

// Aggregate all alias sets into a single array
const aliasSets = [
aliasSet1,
aliasSet2,
aliasSet3,
aliasSet4,
aliasSet5,
aliasSet6,
aliasSet7,
aliasSet8,
aliasSet9,
aliasSet10,
aliasSet11,
aliasSet12,
aliasSet13,
aliasSet14,
aliasSet15,
aliasSet16,
aliasSet17,
aliasSet18,
aliasSet19,
aliasSet20,
aliasSet21,
aliasSet22,
aliasSet23,
aliasSet24,
aliasSet25,
aliasSet26,
aliasSet27,
aliasSet28,
aliasSet29,
aliasSet30,
aliasSet31,
aliasSet32,
aliasSet33,
aliasSet34,
aliasSet35,
aliasSet36,
aliasSet37,
aliasSet38,
aliasSet39,
] as const;

aliasSets.forEach((aliasSet) => {
describe(`Test ${aliasSet.join(',')} `, () => {
it(`All ${aliasSet.join(',')} should render same shape`, () => {
let flowchartCode = `flowchart \n`;
aliasSet.forEach((alias, index) => {
flowchartCode += ` n${index}@{ shape: ${alias}, label: "${alias}" }\n`;
});
imgSnapshotTest(flowchartCode);
});
});
});
126 changes: 126 additions & 0 deletions cypress/integration/rendering/iconShape.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
import { imgSnapshotTest } from '../../helpers/util';

const looks = ['classic', 'handDrawn'] as const;
const directions = [
'TB',
//'BT',
'LR',
// 'RL'
] as const;
const forms = [undefined, 'square', 'circle', 'rounded'] as const;
const labelPos = [undefined, 't', 'b'] as const;

looks.forEach((look) => {
directions.forEach((direction) => {
forms.forEach((form) => {
labelPos.forEach((pos) => {
describe(`Test iconShape in ${form ? `${form} form,` : ''} ${look} look and dir ${direction} with label position ${pos ? pos : 'not defined'}`, () => {
it(`without label`, () => {
let flowchartCode = `flowchart ${direction}\n`;
flowchartCode += ` nA --> nAA@{ icon: 'fa:bell'`;
if (form) {
flowchartCode += `, form: '${form}'`;
}
flowchartCode += ` }\n`;
imgSnapshotTest(flowchartCode, { look });
});

it(`with label`, () => {
let flowchartCode = `flowchart ${direction}\n`;
flowchartCode += ` nA --> nAA@{ icon: 'fa:bell', label: 'This is a label for icon shape'`;
if (form) {
flowchartCode += `, form: '${form}'`;
}
if (pos) {
flowchartCode += `, pos: '${pos}'`;
}
flowchartCode += ` }\n`;
imgSnapshotTest(flowchartCode, { look });
});

it(`with very long label`, () => {
let flowchartCode = `flowchart ${direction}\n`;
flowchartCode += ` nA --> nAA@{ icon: 'fa:bell', label: 'This is a very very very very very long long long label for icon shape'`;
if (form) {
flowchartCode += `, form: '${form}'`;
}
if (pos) {
flowchartCode += `, pos: '${pos}'`;
}
flowchartCode += ` }\n`;
imgSnapshotTest(flowchartCode, { look });
});

it(`with markdown htmlLabels:true`, () => {
let flowchartCode = `flowchart ${direction}\n`;
flowchartCode += ` nA --> nAA@{ icon: 'fa:bell', label: 'This is **bold** </br>and <strong>strong</strong> for icon shape'`;
if (form) {
flowchartCode += `, form: '${form}'`;
}
if (pos) {
flowchartCode += `, pos: '${pos}'`;
}
flowchartCode += ` }\n`;
imgSnapshotTest(flowchartCode, { look });
});

it(`with markdown htmlLabels:false`, () => {
let flowchartCode = `flowchart ${direction}\n`;
flowchartCode += ` nA --> nAA@{ icon: 'fa:bell', label: 'This is **bold** </br>and <strong>strong</strong> for icon shape'`;
if (form) {
flowchartCode += `, form: '${form}'`;
}
if (pos) {
flowchartCode += `, pos: '${pos}'`;
}
flowchartCode += ` }\n`;
imgSnapshotTest(flowchartCode, {
look,
htmlLabels: false,
flowchart: { htmlLabels: false },
});
});

it(`with styles`, () => {
let flowchartCode = `flowchart ${direction}\n`;
flowchartCode += ` nA --> nAA@{ icon: 'fa:bell', label: 'new icon shape'`;
if (form) {
flowchartCode += `, form: '${form}'`;
}
if (pos) {
flowchartCode += `, pos: '${pos}'`;
}
flowchartCode += ` }\n`;
flowchartCode += ` style nAA fill:#f9f,stroke:#333,stroke-width:4px \n`;
imgSnapshotTest(flowchartCode, { look });
});

it(`with classDef`, () => {
let flowchartCode = `flowchart ${direction}\n`;
flowchartCode += ` classDef customClazz fill:#bbf,stroke:#f66,stroke-width:2px,color:#fff,stroke-dasharray: 5 5\n`;
flowchartCode += ` nA --> nAA@{ icon: 'fa:bell', label: 'new icon shape'`;
if (form) {
flowchartCode += `, form: '${form}'`;
}
if (pos) {
flowchartCode += `, pos: '${pos}'`;
}
flowchartCode += ` }\n`;
flowchartCode += ` nAA:::customClazz\n`;
imgSnapshotTest(flowchartCode, { look });
});
});
});
});
});
});

describe('Test iconShape with different h', () => {
it('with different h', () => {
let flowchartCode = `flowchart TB\n`;
const icon = 'fa:bell';
const iconHeight = 64;
flowchartCode += ` nA --> nAA@{ icon: '${icon}', label: 'icon with different h', h: ${iconHeight} }\n`;
imgSnapshotTest(flowchartCode);
});
});
Loading

0 comments on commit 02cf111

Please sign in to comment.