mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-10-21 06:59:36 +02:00
Compare commits
19 Commits
6919-fix-i
...
renovate/p
Author | SHA1 | Date | |
---|---|---|---|
![]() |
322bb94c85 | ||
![]() |
3d768f3adf | ||
![]() |
18f51eb14e | ||
![]() |
2bb57bf7d2 | ||
![]() |
a6276daffd | ||
![]() |
ac411a7d7e | ||
![]() |
6fecb985e8 | ||
![]() |
69b338d8af | ||
![]() |
fa15ce8502 | ||
![]() |
6d0650918f | ||
![]() |
1a9d45abf0 | ||
![]() |
bbb93b263d | ||
![]() |
4240340a18 | ||
![]() |
ca10a259fa | ||
![]() |
0ed9c65572 | ||
![]() |
56cc12690f | ||
![]() |
e6fb4a84da | ||
![]() |
32723b2de1 | ||
![]() |
18703782ee |
5
.changeset/brave-memes-flash.md
Normal file
5
.changeset/brave-memes-flash.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'mermaid': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: Support edge animation in hand drawn look
|
5
.changeset/busy-mirrors-try.md
Normal file
5
.changeset/busy-mirrors-try.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'mermaid': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: Resolved parsing error where direction TD was not recognized within subgraphs
|
@@ -1,5 +0,0 @@
|
|||||||
---
|
|
||||||
'mermaid': patch
|
|
||||||
---
|
|
||||||
|
|
||||||
fix: Correct viewBox casing and make SVGs responsive
|
|
5
.changeset/curly-apes-prove.md
Normal file
5
.changeset/curly-apes-prove.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'mermaid': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: Improve participant parsing and prevent recursive loops on invalid syntax
|
2
.github/workflows/e2e-timings.yml
vendored
2
.github/workflows/e2e-timings.yml
vendored
@@ -58,7 +58,7 @@ jobs:
|
|||||||
echo "EOF" >> $GITHUB_OUTPUT
|
echo "EOF" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
- name: Commit and create pull request
|
- name: Commit and create pull request
|
||||||
uses: peter-evans/create-pull-request@915d841dae6a4f191bb78faf61a257411d7be4d2
|
uses: peter-evans/create-pull-request@46cdba753c74545733b821043d64bd6925fc4da9
|
||||||
with:
|
with:
|
||||||
add-paths: |
|
add-paths: |
|
||||||
cypress/timings.json
|
cypress/timings.json
|
||||||
|
@@ -6,6 +6,7 @@ interface CypressConfig {
|
|||||||
listUrl?: boolean;
|
listUrl?: boolean;
|
||||||
listId?: string;
|
listId?: string;
|
||||||
name?: string;
|
name?: string;
|
||||||
|
screenshot?: boolean;
|
||||||
}
|
}
|
||||||
type CypressMermaidConfig = MermaidConfig & CypressConfig;
|
type CypressMermaidConfig = MermaidConfig & CypressConfig;
|
||||||
|
|
||||||
@@ -90,7 +91,7 @@ export const renderGraph = (
|
|||||||
|
|
||||||
export const openURLAndVerifyRendering = (
|
export const openURLAndVerifyRendering = (
|
||||||
url: string,
|
url: string,
|
||||||
options: CypressMermaidConfig,
|
{ screenshot = true, ...options }: CypressMermaidConfig,
|
||||||
validation?: any
|
validation?: any
|
||||||
): void => {
|
): void => {
|
||||||
const name: string = (options.name ?? cy.state('runnable').fullTitle()).replace(/\s+/g, '-');
|
const name: string = (options.name ?? cy.state('runnable').fullTitle()).replace(/\s+/g, '-');
|
||||||
@@ -98,13 +99,14 @@ export const openURLAndVerifyRendering = (
|
|||||||
cy.visit(url);
|
cy.visit(url);
|
||||||
cy.window().should('have.property', 'rendered', true);
|
cy.window().should('have.property', 'rendered', true);
|
||||||
cy.get('svg').should('be.visible');
|
cy.get('svg').should('be.visible');
|
||||||
cy.get('svg').should('not.have.attr', 'viewbox');
|
|
||||||
|
|
||||||
if (validation) {
|
if (validation) {
|
||||||
cy.get('svg').should(validation);
|
cy.get('svg').should(validation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (screenshot) {
|
||||||
verifyScreenshot(name);
|
verifyScreenshot(name);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const verifyScreenshot = (name: string): void => {
|
export const verifyScreenshot = (name: string): void => {
|
||||||
|
@@ -1029,4 +1029,19 @@ graph TD
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('FDH49: should add edge animation', () => {
|
||||||
|
renderGraph(
|
||||||
|
`
|
||||||
|
flowchart TD
|
||||||
|
A(["Start"]) L_A_B_0@--> B{"Decision"}
|
||||||
|
B --> C["Option A"] & D["Option B"]
|
||||||
|
style C stroke-width:4px,stroke-dasharray: 5
|
||||||
|
L_A_B_0@{ animation: slow }
|
||||||
|
L_B_D_0@{ animation: fast }`,
|
||||||
|
{ look: 'handDrawn', screenshot: false }
|
||||||
|
);
|
||||||
|
cy.get('path#L_A_B_0').should('have.class', 'edge-animation-slow');
|
||||||
|
cy.get('path#L_B_D_0').should('have.class', 'edge-animation-fast');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@@ -774,6 +774,21 @@ describe('Graph', () => {
|
|||||||
expect(svg).to.not.have.attr('style');
|
expect(svg).to.not.have.attr('style');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
it('40: should add edge animation', () => {
|
||||||
|
renderGraph(
|
||||||
|
`
|
||||||
|
flowchart TD
|
||||||
|
A(["Start"]) L_A_B_0@--> B{"Decision"}
|
||||||
|
B --> C["Option A"] & D["Option B"]
|
||||||
|
style C stroke-width:4px,stroke-dasharray: 5
|
||||||
|
L_A_B_0@{ animation: slow }
|
||||||
|
L_B_D_0@{ animation: fast }`,
|
||||||
|
{ screenshot: false }
|
||||||
|
);
|
||||||
|
// Verify animation classes are applied to both edges
|
||||||
|
cy.get('path#L_A_B_0').should('have.class', 'edge-animation-slow');
|
||||||
|
cy.get('path#L_B_D_0').should('have.class', 'edge-animation-fast');
|
||||||
|
});
|
||||||
it('58: handle styling with style expressions', () => {
|
it('58: handle styling with style expressions', () => {
|
||||||
imgSnapshotTest(
|
imgSnapshotTest(
|
||||||
`
|
`
|
||||||
@@ -973,4 +988,19 @@ graph TD
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('70: should render a subgraph with direction TD', () => {
|
||||||
|
imgSnapshotTest(
|
||||||
|
`
|
||||||
|
flowchart LR
|
||||||
|
subgraph A
|
||||||
|
direction TD
|
||||||
|
a --> b
|
||||||
|
end
|
||||||
|
`,
|
||||||
|
{
|
||||||
|
fontFamily: 'courier',
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@@ -21,7 +21,7 @@ title: Animal example
|
|||||||
classDiagram
|
classDiagram
|
||||||
note "From Duck till Zebra"
|
note "From Duck till Zebra"
|
||||||
Animal <|-- Duck
|
Animal <|-- Duck
|
||||||
note for Duck "can fly\ncan swim\ncan dive\ncan help in debugging"
|
note for Duck "can fly<br>can swim<br>can dive<br>can help in debugging"
|
||||||
Animal <|-- Fish
|
Animal <|-- Fish
|
||||||
Animal <|-- Zebra
|
Animal <|-- Zebra
|
||||||
Animal : +int age
|
Animal : +int age
|
||||||
@@ -50,7 +50,7 @@ title: Animal example
|
|||||||
classDiagram
|
classDiagram
|
||||||
note "From Duck till Zebra"
|
note "From Duck till Zebra"
|
||||||
Animal <|-- Duck
|
Animal <|-- Duck
|
||||||
note for Duck "can fly\ncan swim\ncan dive\ncan help in debugging"
|
note for Duck "can fly<br>can swim<br>can dive<br>can help in debugging"
|
||||||
Animal <|-- Fish
|
Animal <|-- Fish
|
||||||
Animal <|-- Zebra
|
Animal <|-- Zebra
|
||||||
Animal : +int age
|
Animal : +int age
|
||||||
|
@@ -140,6 +140,7 @@ that id.
|
|||||||
.*direction\s+BT[^\n]* return 'direction_bt';
|
.*direction\s+BT[^\n]* return 'direction_bt';
|
||||||
.*direction\s+RL[^\n]* return 'direction_rl';
|
.*direction\s+RL[^\n]* return 'direction_rl';
|
||||||
.*direction\s+LR[^\n]* return 'direction_lr';
|
.*direction\s+LR[^\n]* return 'direction_lr';
|
||||||
|
.*direction\s+TD[^\n]* return 'direction_td';
|
||||||
|
|
||||||
[^\s\"]+\@(?=[^\{\"]) { return 'LINK_ID'; }
|
[^\s\"]+\@(?=[^\{\"]) { return 'LINK_ID'; }
|
||||||
[0-9]+ return 'NUM';
|
[0-9]+ return 'NUM';
|
||||||
@@ -626,6 +627,8 @@ direction
|
|||||||
{ $$={stmt:'dir', value:'RL'};}
|
{ $$={stmt:'dir', value:'RL'};}
|
||||||
| direction_lr
|
| direction_lr
|
||||||
{ $$={stmt:'dir', value:'LR'};}
|
{ $$={stmt:'dir', value:'LR'};}
|
||||||
|
| direction_td
|
||||||
|
{ $$={stmt:'dir', value:'TD'};}
|
||||||
;
|
;
|
||||||
|
|
||||||
%%
|
%%
|
||||||
|
@@ -309,4 +309,21 @@ describe('when parsing subgraphs', function () {
|
|||||||
expect(subgraphA.nodes).toContain('a');
|
expect(subgraphA.nodes).toContain('a');
|
||||||
expect(subgraphA.nodes).not.toContain('c');
|
expect(subgraphA.nodes).not.toContain('c');
|
||||||
});
|
});
|
||||||
|
it('should correctly parse direction TD inside a subgraph', function () {
|
||||||
|
const res = flow.parser.parse(`
|
||||||
|
graph LR
|
||||||
|
subgraph WithTD
|
||||||
|
direction TD
|
||||||
|
A1 --> A2
|
||||||
|
end
|
||||||
|
`);
|
||||||
|
|
||||||
|
const subgraphs = flow.parser.yy.getSubGraphs();
|
||||||
|
expect(subgraphs.length).toBe(1);
|
||||||
|
const subgraph = subgraphs[0];
|
||||||
|
|
||||||
|
expect(subgraph.dir).toBe('TD');
|
||||||
|
expect(subgraph.nodes).toContain('A1');
|
||||||
|
expect(subgraph.nodes).toContain('A2');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@@ -16,7 +16,7 @@ const draw: DrawDefinition = (_text, id, _version, diagram: Diagram) => {
|
|||||||
const svgWidth = bitWidth * bitsPerRow + 2;
|
const svgWidth = bitWidth * bitsPerRow + 2;
|
||||||
const svg: SVG = selectSvgElement(id);
|
const svg: SVG = selectSvgElement(id);
|
||||||
|
|
||||||
svg.attr('viewBox', `0 0 ${svgWidth} ${svgHeight}`);
|
svg.attr('viewbox', `0 0 ${svgWidth} ${svgHeight}`);
|
||||||
configureSvgSize(svg, svgHeight, svgWidth, config.useMaxWidth);
|
configureSvgSize(svg, svgHeight, svgWidth, config.useMaxWidth);
|
||||||
|
|
||||||
for (const [word, packet] of words.entries()) {
|
for (const [word, packet] of words.entries()) {
|
||||||
|
@@ -2,7 +2,6 @@ import type { Diagram } from '../../Diagram.js';
|
|||||||
import type { RadarDiagramConfig } from '../../config.type.js';
|
import type { RadarDiagramConfig } from '../../config.type.js';
|
||||||
import type { DiagramRenderer, DrawDefinition, SVG, SVGGroup } from '../../diagram-api/types.js';
|
import type { DiagramRenderer, DrawDefinition, SVG, SVGGroup } from '../../diagram-api/types.js';
|
||||||
import { selectSvgElement } from '../../rendering-util/selectSvgElement.js';
|
import { selectSvgElement } from '../../rendering-util/selectSvgElement.js';
|
||||||
import { configureSvgSize } from '../../setupGraphViewbox.js';
|
|
||||||
import type { RadarDB, RadarAxis, RadarCurve } from './types.js';
|
import type { RadarDB, RadarAxis, RadarCurve } from './types.js';
|
||||||
|
|
||||||
const draw: DrawDefinition = (_text, id, _version, diagram: Diagram) => {
|
const draw: DrawDefinition = (_text, id, _version, diagram: Diagram) => {
|
||||||
@@ -54,9 +53,11 @@ const drawFrame = (svg: SVG, config: Required<RadarDiagramConfig>): SVGGroup =>
|
|||||||
x: config.marginLeft + config.width / 2,
|
x: config.marginLeft + config.width / 2,
|
||||||
y: config.marginTop + config.height / 2,
|
y: config.marginTop + config.height / 2,
|
||||||
};
|
};
|
||||||
configureSvgSize(svg, totalHeight, totalWidth, config.useMaxWidth ?? true);
|
// Initialize the SVG
|
||||||
|
svg
|
||||||
svg.attr('viewBox', `0 0 ${totalWidth} ${totalHeight}`);
|
.attr('viewbox', `0 0 ${totalWidth} ${totalHeight}`)
|
||||||
|
.attr('width', totalWidth)
|
||||||
|
.attr('height', totalHeight);
|
||||||
// g element to center the radar chart
|
// g element to center the radar chart
|
||||||
return svg.append('g').attr('transform', `translate(${center.x}, ${center.y})`);
|
return svg.append('g').attr('transform', `translate(${center.x}, ${center.y})`);
|
||||||
};
|
};
|
||||||
|
@@ -32,13 +32,14 @@
|
|||||||
<CONFIG>[^\}]+ { return 'CONFIG_CONTENT'; }
|
<CONFIG>[^\}]+ { return 'CONFIG_CONTENT'; }
|
||||||
<CONFIG>\} { this.popState(); this.popState(); return 'CONFIG_END'; }
|
<CONFIG>\} { this.popState(); this.popState(); return 'CONFIG_END'; }
|
||||||
<ID>[^\<->\->:\n,;@\s]+(?=\@\{) { yytext = yytext.trim(); return 'ACTOR'; }
|
<ID>[^\<->\->:\n,;@\s]+(?=\@\{) { yytext = yytext.trim(); return 'ACTOR'; }
|
||||||
<ID>[^\<->\->:\n,;@]+?([\-]*[^\<->\->:\n,;@]+?)*?(?=((?!\n)\s)+"as"(?!\n)\s|[#\n;]|$) { yytext = yytext.trim(); this.begin('ALIAS'); return 'ACTOR'; }
|
<ID>[^<>:\n,;@\s]+(?=\s+as\s) { yytext = yytext.trim(); this.begin('ALIAS'); return 'ACTOR'; }
|
||||||
|
<ID>[^<>:\n,;@]+(?=\s*[\n;#]|$) { yytext = yytext.trim(); this.popState(); return 'ACTOR'; }
|
||||||
|
<ID>[^<>:\n,;@]*\<[^\n]* { this.popState(); return 'INVALID'; }
|
||||||
"box" { this.begin('LINE'); return 'box'; }
|
"box" { this.begin('LINE'); return 'box'; }
|
||||||
"participant" { this.begin('ID'); return 'participant'; }
|
"participant" { this.begin('ID'); return 'participant'; }
|
||||||
"actor" { this.begin('ID'); return 'participant_actor'; }
|
"actor" { this.begin('ID'); return 'participant_actor'; }
|
||||||
"create" return 'create';
|
"create" return 'create';
|
||||||
"destroy" { this.begin('ID'); return 'destroy'; }
|
"destroy" { this.begin('ID'); return 'destroy'; }
|
||||||
<ID>[^<\->\->:\n,;]+?([\-]*[^<\->\->:\n,;]+?)*?(?=((?!\n)\s)+"as"(?!\n)\s|[#\n;]|$) { yytext = yytext.trim(); this.begin('ALIAS'); return 'ACTOR'; }
|
|
||||||
<ALIAS>"as" { this.popState(); this.popState(); this.begin('LINE'); return 'AS'; }
|
<ALIAS>"as" { this.popState(); this.popState(); this.begin('LINE'); return 'AS'; }
|
||||||
<ALIAS>(?:) { this.popState(); this.popState(); return 'NEWLINE'; }
|
<ALIAS>(?:) { this.popState(); this.popState(); return 'NEWLINE'; }
|
||||||
"loop" { this.begin('LINE'); return 'loop'; }
|
"loop" { this.begin('LINE'); return 'loop'; }
|
||||||
@@ -145,6 +146,7 @@ line
|
|||||||
: SPACE statement { $$ = $2 }
|
: SPACE statement { $$ = $2 }
|
||||||
| statement { $$ = $1 }
|
| statement { $$ = $1 }
|
||||||
| NEWLINE { $$=[]; }
|
| NEWLINE { $$=[]; }
|
||||||
|
| INVALID { $$=[]; }
|
||||||
;
|
;
|
||||||
|
|
||||||
box_section
|
box_section
|
||||||
|
@@ -2609,5 +2609,17 @@ Bob->>Alice:Got it!
|
|||||||
expect(actors.get('E').type).toBe('entity');
|
expect(actors.get('E').type).toBe('entity');
|
||||||
expect(actors.get('E').description).toBe('E');
|
expect(actors.get('E').description).toBe('E');
|
||||||
});
|
});
|
||||||
|
it('should handle fail parsing when alias token causes conflicts in participant definition', async () => {
|
||||||
|
let error = false;
|
||||||
|
try {
|
||||||
|
await Diagram.fromText(`
|
||||||
|
sequenceDiagram
|
||||||
|
participant SAS MyServiceWithMoreThan20Chars <br> service decription
|
||||||
|
`);
|
||||||
|
} catch (e) {
|
||||||
|
error = true;
|
||||||
|
}
|
||||||
|
expect(error).toBe(true);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -15,7 +15,7 @@ title: Animal example
|
|||||||
classDiagram
|
classDiagram
|
||||||
note "From Duck till Zebra"
|
note "From Duck till Zebra"
|
||||||
Animal <|-- Duck
|
Animal <|-- Duck
|
||||||
note for Duck "can fly\ncan swim\ncan dive\ncan help in debugging"
|
note for Duck "can fly<br>can swim<br>can dive<br>can help in debugging"
|
||||||
Animal <|-- Fish
|
Animal <|-- Fish
|
||||||
Animal <|-- Zebra
|
Animal <|-- Zebra
|
||||||
Animal : +int age
|
Animal : +int age
|
||||||
|
@@ -605,6 +605,14 @@ export const insertEdge = function (
|
|||||||
const edgeStyles = Array.isArray(edge.style) ? edge.style : [edge.style];
|
const edgeStyles = Array.isArray(edge.style) ? edge.style : [edge.style];
|
||||||
let strokeColor = edgeStyles.find((style) => style?.startsWith('stroke:'));
|
let strokeColor = edgeStyles.find((style) => style?.startsWith('stroke:'));
|
||||||
|
|
||||||
|
let animationClass = '';
|
||||||
|
if (edge.animate) {
|
||||||
|
animationClass = 'edge-animation-fast';
|
||||||
|
}
|
||||||
|
if (edge.animation) {
|
||||||
|
animationClass = 'edge-animation-' + edge.animation;
|
||||||
|
}
|
||||||
|
|
||||||
let animatedEdge = false;
|
let animatedEdge = false;
|
||||||
if (edge.look === 'handDrawn') {
|
if (edge.look === 'handDrawn') {
|
||||||
const rc = rough.svg(elem);
|
const rc = rough.svg(elem);
|
||||||
@@ -620,7 +628,13 @@ export const insertEdge = function (
|
|||||||
svgPath = select(svgPathNode)
|
svgPath = select(svgPathNode)
|
||||||
.select('path')
|
.select('path')
|
||||||
.attr('id', edge.id)
|
.attr('id', edge.id)
|
||||||
.attr('class', ' ' + strokeClasses + (edge.classes ? ' ' + edge.classes : ''))
|
.attr(
|
||||||
|
'class',
|
||||||
|
' ' +
|
||||||
|
strokeClasses +
|
||||||
|
(edge.classes ? ' ' + edge.classes : '') +
|
||||||
|
(animationClass ? ' ' + animationClass : '')
|
||||||
|
)
|
||||||
.attr('style', edgeStyles ? edgeStyles.reduce((acc, style) => acc + ';' + style, '') : '');
|
.attr('style', edgeStyles ? edgeStyles.reduce((acc, style) => acc + ';' + style, '') : '');
|
||||||
let d = svgPath.attr('d');
|
let d = svgPath.attr('d');
|
||||||
svgPath.attr('d', d);
|
svgPath.attr('d', d);
|
||||||
@@ -628,13 +642,6 @@ export const insertEdge = function (
|
|||||||
} else {
|
} else {
|
||||||
const stylesFromClasses = edgeClassStyles.join(';');
|
const stylesFromClasses = edgeClassStyles.join(';');
|
||||||
const styles = edgeStyles ? edgeStyles.reduce((acc, style) => acc + style + ';', '') : '';
|
const styles = edgeStyles ? edgeStyles.reduce((acc, style) => acc + style + ';', '') : '';
|
||||||
let animationClass = '';
|
|
||||||
if (edge.animate) {
|
|
||||||
animationClass = ' edge-animation-fast';
|
|
||||||
}
|
|
||||||
if (edge.animation) {
|
|
||||||
animationClass = ' edge-animation-' + edge.animation;
|
|
||||||
}
|
|
||||||
|
|
||||||
const pathStyle =
|
const pathStyle =
|
||||||
(stylesFromClasses ? stylesFromClasses + ';' + styles + ';' : styles) +
|
(stylesFromClasses ? stylesFromClasses + ';' + styles + ';' : styles) +
|
||||||
@@ -646,7 +653,10 @@ export const insertEdge = function (
|
|||||||
.attr('id', edge.id)
|
.attr('id', edge.id)
|
||||||
.attr(
|
.attr(
|
||||||
'class',
|
'class',
|
||||||
' ' + strokeClasses + (edge.classes ? ' ' + edge.classes : '') + (animationClass ?? '')
|
' ' +
|
||||||
|
strokeClasses +
|
||||||
|
(edge.classes ? ' ' + edge.classes : '') +
|
||||||
|
(animationClass ? ' ' + animationClass : '')
|
||||||
)
|
)
|
||||||
.attr('style', pathStyle);
|
.attr('style', pathStyle);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user