Skip to content

Commit

Permalink
Merge pull request #5604 from mermaid-js/5237-unified-layout-common-r…
Browse files Browse the repository at this point in the history
…enderer

Streamlining and enhancing diagram rendering across various diagram types
  • Loading branch information
ashishjain0512 authored Aug 12, 2024
2 parents 47601ac + 9b42ffd commit 87b2084
Show file tree
Hide file tree
Showing 138 changed files with 13,726 additions and 6,881 deletions.
8 changes: 4 additions & 4 deletions .build/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ export const packageOptions = {
packageName: 'mermaid-zenuml',
file: 'detector.ts',
},
'mermaid-flowchart-elk': {
name: 'mermaid-flowchart-elk',
packageName: 'mermaid-flowchart-elk',
file: 'detector.ts',
'mermaid-layout-elk': {
name: 'mermaid-layout-elk',
packageName: 'mermaid-layout-elk',
file: 'layouts.ts',
},
} as const;
1 change: 1 addition & 0 deletions .build/jisonTransformer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import jison from 'jison';

export const transformJison = (src: string): string => {
// @ts-ignore - Jison is not typed properly
const parser = new jison.Generator(src, {
moduleType: 'js',
'token-stack': true,
Expand Down
3 changes: 3 additions & 0 deletions .cspell/code-terms.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ controly
CSSCLASS
CYLINDEREND
CYLINDERSTART
DAGA
datakey
DEND
descr
Expand Down Expand Up @@ -90,6 +91,7 @@ reqs
rewritelinks
rgba
RIGHTOF
roughjs
sankey
sequencenumber
shrc
Expand All @@ -109,6 +111,7 @@ strikethrough
stringifying
struct
STYLECLASS
STYLEDEF
STYLEOPTS
subcomponent
subcomponents
Expand Down
1 change: 1 addition & 0 deletions .cspell/libraries.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ presetAttributify
pyplot
redmine
rehype
roughjs
rscratch
shiki
sparkline
Expand Down
2 changes: 2 additions & 0 deletions .cspell/mermaid-terms.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ elems
gantt
gitgraph
gzipped
handDrawn
knsv
Knut
marginx
Expand All @@ -17,6 +18,7 @@ Markdownish
mermaidjs
mindmap
mindmaps
mrtree
multigraph
nodesep
NOTEGROUP
Expand Down
4 changes: 3 additions & 1 deletion .cspell/misc-terms.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
BRANDES
handdrawn
circo
handDrawn
KOEPF
neato
newbranch
4 changes: 2 additions & 2 deletions .esbuild/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { defaultOptions, getBuildConfig } from './util.js';
const shouldVisualize = process.argv.includes('--visualize');

const buildPackage = async (entryName: keyof typeof packageOptions) => {
const commonOptions = { ...defaultOptions, entryName } as const;
const buildConfigs = [
const commonOptions: MermaidBuildOptions = { ...defaultOptions, entryName } as const;
const buildConfigs: MermaidBuildOptions[] = [
// package.mjs
{ ...commonOptions },
// package.min.mjs
Expand Down
2 changes: 1 addition & 1 deletion .esbuild/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { jisonPlugin } from './jisonPlugin.js';

const __dirname = fileURLToPath(new URL('.', import.meta.url));

export interface MermaidBuildOptions {
export interface MermaidBuildOptions extends BuildOptions {
minify: boolean;
core: boolean;
metafile: boolean;
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ cypress/snapshots/
.tsbuildinfo
tsconfig.tsbuildinfo

knsv*.html
#knsv*.html
local*.html
stats/

Expand Down
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ generated/
# Ignore the files creates in /demos/dev except for example.html
demos/dev/**
!/demos/dev/example.html
# TODO: Lots of errors to fix
cypress/platform/state-refactor.html
14 changes: 0 additions & 14 deletions cypress/integration/other/flowchart-elk.spec.js

This file was deleted.

21 changes: 21 additions & 0 deletions cypress/integration/rendering/appli.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,27 @@ describe('Git Graph diagram', () => {
{}
);
});
it('Should render subgraphs with title margins and edge labels', () => {
imgSnapshotTest(
`flowchart LR
subgraph TOP
direction TB
subgraph B1
direction RL
i1 --lb1-->f1
end
subgraph B2
direction BT
i2 --lb2-->f2
end
end
A --lb3--> TOP --lb4--> B
B1 --lb5--> B2
`,
{ flowchart: { subGraphTitleMargin: { top: 10, bottom: 5 } } }
);
});
// it(`ultraFastTest`, function () {
// // Navigate to the url we want to test
// // ⭐️ Note to see visual bugs, run the test using the above URL for the 1st run.
Expand Down
31 changes: 16 additions & 15 deletions cypress/integration/rendering/block.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ describe('Block diagram', () => {
);
});

it('BL16: width alignment - blocks shold be equal in width', () => {
it('BL17: width alignment - blocks shold be equal in width', () => {
imgSnapshotTest(
`block-beta
A("This is the text")
Expand All @@ -247,7 +247,7 @@ describe('Block diagram', () => {
);
});

it('BL17: block types 1 - square, rounded and circle', () => {
it('BL18: block types 1 - square, rounded and circle', () => {
imgSnapshotTest(
`block-beta
A["square"]
Expand All @@ -258,7 +258,7 @@ describe('Block diagram', () => {
);
});

it('BL18: block types 2 - odd, diamond and hexagon', () => {
it('BL19: block types 2 - odd, diamond and hexagon', () => {
imgSnapshotTest(
`block-beta
A>"rect_left_inv_arrow"]
Expand All @@ -269,7 +269,7 @@ describe('Block diagram', () => {
);
});

it('BL19: block types 3 - stadium', () => {
it('BL20: block types 3 - stadium', () => {
imgSnapshotTest(
`block-beta
A(["stadium"])
Expand All @@ -278,7 +278,7 @@ describe('Block diagram', () => {
);
});

it('BL20: block types 4 - lean right, lean left, trapezoid and inv trapezoid', () => {
it('BL21: block types 4 - lean right, lean left, trapezoid and inv trapezoid', () => {
imgSnapshotTest(
`block-beta
A[/"lean right"/]
Expand All @@ -290,7 +290,7 @@ describe('Block diagram', () => {
);
});

it('BL21: block types 1 - square, rounded and circle', () => {
it('BL22: block types 1 - square, rounded and circle', () => {
imgSnapshotTest(
`block-beta
A["square"]
Expand All @@ -301,7 +301,7 @@ describe('Block diagram', () => {
);
});

it('BL22: sizing - it should be possible to make a block wider', () => {
it('BL23: sizing - it should be possible to make a block wider', () => {
imgSnapshotTest(
`block-beta
A("rounded"):2
Expand All @@ -312,7 +312,7 @@ describe('Block diagram', () => {
);
});

it('BL23: sizing - it should be possible to make a composite block wider', () => {
it('BL24: sizing - it should be possible to make a composite block wider', () => {
imgSnapshotTest(
`block-beta
block:2
Expand All @@ -324,7 +324,7 @@ describe('Block diagram', () => {
);
});

it('BL24: block in the middle with space on each side', () => {
it('BL25: block in the middle with space on each side', () => {
imgSnapshotTest(
`block-beta
columns 3
Expand All @@ -335,7 +335,7 @@ describe('Block diagram', () => {
{}
);
});
it('BL25: space and an edge', () => {
it('BL26: space and an edge', () => {
imgSnapshotTest(
`block-beta
columns 5
Expand All @@ -345,7 +345,7 @@ describe('Block diagram', () => {
{}
);
});
it('BL26: block sizes for regular blocks', () => {
it('BL27: block sizes for regular blocks', () => {
imgSnapshotTest(
`block-beta
columns 3
Expand All @@ -354,7 +354,7 @@ describe('Block diagram', () => {
{}
);
});
it('BL27: composite block with a set width - f should use the available space', () => {
it('BL28: composite block with a set width - f should use the available space', () => {
imgSnapshotTest(
`block-beta
columns 3
Expand All @@ -363,11 +363,12 @@ describe('Block diagram', () => {
f
end
g
`,
`,
{}
);
});
it('BL23: composite block with a set width - f and g should split the available space', () => {

it('BL29: composite block with a set width - f and g should split the available space', () => {
imgSnapshotTest(
`block-beta
columns 3
Expand All @@ -379,7 +380,7 @@ describe('Block diagram', () => {
h
i
j
`,
`,
{}
);
});
Expand Down
10 changes: 5 additions & 5 deletions cypress/integration/rendering/c4.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { imgSnapshotTest, renderGraph } from '../../helpers/util.ts';

describe('C4 diagram', () => {
it('should render a simple C4Context diagram', () => {
it('C4.1 should render a simple C4Context diagram', () => {
imgSnapshotTest(
`
C4Context
Expand Down Expand Up @@ -31,7 +31,7 @@ describe('C4 diagram', () => {
{}
);
});
it('should render a simple C4Container diagram', () => {
it('C4.2 should render a simple C4Container diagram', () => {
imgSnapshotTest(
`
C4Container
Expand All @@ -50,7 +50,7 @@ describe('C4 diagram', () => {
{}
);
});
it('should render a simple C4Component diagram', () => {
it('C4.3 should render a simple C4Component diagram', () => {
imgSnapshotTest(
`
C4Component
Expand All @@ -68,7 +68,7 @@ describe('C4 diagram', () => {
{}
);
});
it('should render a simple C4Dynamic diagram', () => {
it('C4.4 should render a simple C4Dynamic diagram', () => {
imgSnapshotTest(
`
C4Dynamic
Expand All @@ -91,7 +91,7 @@ describe('C4 diagram', () => {
{}
);
});
it('should render a simple C4Deployment diagram', () => {
it('C4.5 should render a simple C4Deployment diagram', () => {
imgSnapshotTest(
`
C4Deployment
Expand Down
4 changes: 2 additions & 2 deletions cypress/integration/rendering/classDiagram-v2.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ describe('Class diagram V2', () => {
);
});

it('should render a simple class diagram with different visibilities', () => {
it('2.1 should render a simple class diagram with different visibilities', () => {
imgSnapshotTest(
`
classDiagram-v2
Expand All @@ -93,7 +93,7 @@ describe('Class diagram V2', () => {
);
});

it('should render multiple class diagrams', () => {
it('3: should render multiple class diagrams', () => {
imgSnapshotTest(
[
`
Expand Down
2 changes: 1 addition & 1 deletion cypress/integration/rendering/errorDiagram.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { imgSnapshotTest } from '../../helpers/util';
describe('Error Diagrams', () => {
beforeEach(() => {
cy.on('uncaught:exception', (err) => {
expect(err.message).to.include('Parse error');
expect(err.message).to.include('error');
// return false to prevent the error from
// failing this test
return false;
Expand Down
Loading

0 comments on commit 87b2084

Please sign in to comment.