Skip to content

Commit 84b10ac

Browse files
committed
Add animated class to the dotted links
The purpose of this PR is to add more clarity to a diagram and to how the nodes of a diagram communicate Adding `animate` class to a node, will add the `animated` class to an egde ot type 'arroe-point' having stroke 'dotted' Eg. ```mermaid graph LR A:::animate -.-> B ```
1 parent d6ccd93 commit 84b10ac

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

packages/mermaid/src/diagrams/flowchart/flowRenderer-v2.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,14 @@ export const addEdges = async function (edges, g, diagObj) {
265265

266266
let style = '';
267267
let labelStyle = '';
268+
let isAnimatedNode = g.node(edge.start).class.split(' ').includes('animate');
269+
let linkAnimatedDashClass =
270+
edge.stroke === 'dotted' &&
271+
edge.type === 'arrow_point' &&
272+
isAnimatedNode &&
273+
linkNameEnd.includes('LE')
274+
? 'animated'
275+
: '';
268276

269277
switch (edge.stroke) {
270278
case 'normal':
@@ -329,7 +337,9 @@ export const addEdges = async function (edges, g, diagObj) {
329337
edgeData.labelStyle = edgeData.labelStyle.replace('color:', 'fill:');
330338

331339
edgeData.id = linkId;
332-
edgeData.classes = 'flowchart-link ' + linkNameStart + ' ' + linkNameEnd;
340+
edgeData.classes = ['flowchart-link', linkAnimatedDashClass, linkNameStart, linkNameEnd].join(
341+
' '
342+
);
333343

334344
// Add the edge to the graph
335345
g.setEdge(edge.start, edge.end, edgeData, cnt);

packages/mermaid/src/diagrams/flowchart/styles.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ const getStyles = (options: FlowChartStyleOptions) =>
106106
/* For html labels only */
107107
.labelBkg {
108108
background-color: ${fade(options.edgeLabelBackground, 0.5)};
109-
// background-color:
109+
// background-color:
110110
}
111111
112112
.cluster rect {
@@ -145,6 +145,15 @@ const getStyles = (options: FlowChartStyleOptions) =>
145145
font-size: 18px;
146146
fill: ${options.textColor};
147147
}
148+
149+
.animated {
150+
animation: animate-dash-line 5s linear infinite;
151+
}
152+
153+
@keyframes animate-dash-line {
154+
from { stroke-dashoffset: 102; }
155+
to { stroke-dashoffset: 0; }
156+
}
148157
`;
149158

150159
export default getStyles;

0 commit comments

Comments
 (0)