Skip to content

Commit 1870378

Browse files
Fixed edge animation for hand drawn shapes
1 parent e53c17a commit 1870378

File tree

3 files changed

+39
-8
lines changed

3 files changed

+39
-8
lines changed

cypress/integration/rendering/flowchart-handDrawn.spec.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,4 +1029,19 @@ graph TD
10291029
}
10301030
);
10311031
});
1032+
1033+
it('FDH49: should add edge animation', () => {
1034+
renderGraph(
1035+
`
1036+
flowchart TD
1037+
A(["Start"]) L_A_B_0@--> B{"Decision"}
1038+
B --> C["Option A"] & D["Option B"]
1039+
style C stroke-width:4px,stroke-dasharray: 5
1040+
L_A_B_0@{ animation: slow }
1041+
L_B_D_0@{ animation: fast }`,
1042+
{ look: 'handDrawn' }
1043+
);
1044+
cy.get('path#L_A_B_0').should('have.class', 'edge-animation-slow');
1045+
cy.get('path#L_B_D_0').should('have.class', 'edge-animation-fast');
1046+
});
10321047
});

cypress/integration/rendering/flowchart.spec.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,18 @@ describe('Graph', () => {
774774
expect(svg).to.not.have.attr('style');
775775
});
776776
});
777+
it('40: should add edge animation', () => {
778+
renderGraph(`
779+
flowchart TD
780+
A(["Start"]) L_A_B_0@--> B{"Decision"}
781+
B --> C["Option A"] & D["Option B"]
782+
style C stroke-width:4px,stroke-dasharray: 5
783+
L_A_B_0@{ animation: slow }
784+
L_B_D_0@{ animation: fast }`);
785+
// Verify animation classes are applied to both edges
786+
cy.get('path#L_A_B_0').should('have.class', 'edge-animation-slow');
787+
cy.get('path#L_B_D_0').should('have.class', 'edge-animation-fast');
788+
});
777789
it('58: handle styling with style expressions', () => {
778790
imgSnapshotTest(
779791
`

packages/mermaid/src/rendering-util/rendering-elements/edges.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,14 @@ export const insertEdge = function (elem, edge, clusterDb, diagramType, startNod
565565
const edgeStyles = Array.isArray(edge.style) ? edge.style : edge.style ? [edge.style] : [];
566566
let strokeColor = edgeStyles.find((style) => style?.startsWith('stroke:'));
567567

568+
let animationClass = '';
569+
if (edge.animate) {
570+
animationClass = ' edge-animation-fast';
571+
}
572+
if (edge.animation) {
573+
animationClass = ' edge-animation-' + edge.animation;
574+
}
575+
568576
if (edge.look === 'handDrawn') {
569577
const rc = rough.svg(elem);
570578
Object.assign([], lineData);
@@ -579,21 +587,17 @@ export const insertEdge = function (elem, edge, clusterDb, diagramType, startNod
579587
svgPath = select(svgPathNode)
580588
.select('path')
581589
.attr('id', edge.id)
582-
.attr('class', ' ' + strokeClasses + (edge.classes ? ' ' + edge.classes : ''))
590+
.attr(
591+
'class',
592+
' ' + strokeClasses + (edge.classes ? ' ' + edge.classes : '') + (animationClass ?? '')
593+
)
583594
.attr('style', edgeStyles ? edgeStyles.reduce((acc, style) => acc + ';' + style, '') : '');
584595
let d = svgPath.attr('d');
585596
svgPath.attr('d', d);
586597
elem.node().appendChild(svgPath.node());
587598
} else {
588599
const stylesFromClasses = edgeClassStyles.join(';');
589600
const styles = edgeStyles ? edgeStyles.reduce((acc, style) => acc + style + ';', '') : '';
590-
let animationClass = '';
591-
if (edge.animate) {
592-
animationClass = ' edge-animation-fast';
593-
}
594-
if (edge.animation) {
595-
animationClass = ' edge-animation-' + edge.animation;
596-
}
597601

598602
const pathStyle = stylesFromClasses ? stylesFromClasses + ';' + styles + ';' : styles;
599603
svgPath = elem

0 commit comments

Comments
 (0)