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 21, 2024
1 parent d6ccd93 commit 2d9682e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
7 changes: 6 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,9 @@ 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 ? 'animated' : '';

switch (edge.stroke) {
case 'normal':
Expand Down Expand Up @@ -329,7 +332,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
10 changes: 9 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,6 @@ const getStyles = (options: FlowChartStyleOptions) =>
/* For html labels only */
.labelBkg {
background-color: ${fade(options.edgeLabelBackground, 0.5)};
// background-color:
}
.cluster rect {
Expand Down Expand Up @@ -145,6 +144,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 2d9682e

Please sign in to comment.