Skip to content

Commit

Permalink
Add animated class to the dotted links
Browse files Browse the repository at this point in the history
The purpose of this PR is to add more clarity to a
diagram and to how the nodes of a diagram communicate

Eg.

```mermaid
graph LR
A:::animated -.-> B
```
  • Loading branch information
cmnstmntmn committed Jul 17, 2024
1 parent d6ccd93 commit 0a6201f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
5 changes: 4 additions & 1 deletion packages/mermaid/src/diagrams/flowchart/flowRenderer-v2.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ export const addEdges = async function (edges, g, diagObj) {

let style = '';
let labelStyle = '';
let linkAnimatedDashClass = '';

switch (edge.stroke) {
case 'normal':
Expand All @@ -282,6 +283,7 @@ export const addEdges = async function (edges, g, diagObj) {
edgeData.thickness = 'normal';
edgeData.pattern = 'dotted';
edgeData.style = 'fill:none;stroke-width:2px;stroke-dasharray:3;';
linkAnimatedDashClass = g.node(edge.start).class;
break;
case 'thick':
edgeData.thickness = 'thick';
Expand Down Expand Up @@ -329,7 +331,8 @@ export const addEdges = async function (edges, g, diagObj) {
edgeData.labelStyle = edgeData.labelStyle.replace('color:', 'fill:');

edgeData.id = linkId;
edgeData.classes = 'flowchart-link ' + linkNameStart + ' ' + linkNameEnd;
edgeData.classes =
'flowchart-link ' + linkAnimatedDashClass + linkNameStart + ' ' + linkNameEnd;

// Add the edge to the graph
g.setEdge(edge.start, edge.end, edgeData, cnt);
Expand Down
11 changes: 10 additions & 1 deletion packages/mermaid/src/diagrams/flowchart/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ const getStyles = (options: FlowChartStyleOptions) =>
/* For html labels only */
.labelBkg {
background-color: ${fade(options.edgeLabelBackground, 0.5)};
// background-color:
// background-color:
}
.cluster rect {
Expand Down Expand Up @@ -145,6 +145,15 @@ const getStyles = (options: FlowChartStyleOptions) =>
font-size: 18px;
fill: ${options.textColor};
}
.animated {
animation: animate-dash-line 5s linear infinite;
}
@keyframes animate-dash-line {
0% { stroke-dashoffset: 3; }
100% { stroke-dashoffset: -100; }
}
`;

export default getStyles;

0 comments on commit 0a6201f

Please sign in to comment.