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

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
```
  • Loading branch information
cmnstmntmn committed Jul 19, 2024
1 parent d6ccd93 commit 84b10ac
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
12 changes: 11 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,14 @@ export const addEdges = async function (edges, g, diagObj) {

let style = '';
let labelStyle = '';
let isAnimatedNode = g.node(edge.start).class.split(' ').includes('animate');
let linkAnimatedDashClass =
edge.stroke === 'dotted' &&
edge.type === 'arrow_point' &&
isAnimatedNode &&
linkNameEnd.includes('LE')
? 'animated'
: '';

switch (edge.stroke) {
case 'normal':
Expand Down Expand Up @@ -329,7 +337,9 @@ 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].join(
' '
);

// 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 {
from { stroke-dashoffset: 102; }
to { stroke-dashoffset: 0; }
}
`;

export default getStyles;

0 comments on commit 84b10ac

Please sign in to comment.