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 `producer`/`consumer` pair classes to nodes,
will add the `animated` class to an egde ot type 'arroe-point'
having stroke 'dotted'

Eg.

```mermaid
graph LR
A:::producer -.-> B:::consumer -.-> A -.-> C
```
  • Loading branch information
cmnstmntmn committed Jul 23, 2024
1 parent d6ccd93 commit 22d0f40
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
14 changes: 13 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,16 @@ export const addEdges = async function (edges, g, diagObj) {

let style = '';
let labelStyle = '';
let isAnimatedProducerNode = g.node(edge.start).class.split(' ').includes('producer');
let isAnimatedConsumerNode = g.node(edge.end).class.split(' ').includes('consumer');

let linkAnimatedDashClass =
edge.stroke === 'dotted' &&
edge.type === 'arrow_point' &&
isAnimatedProducerNode &&
isAnimatedConsumerNode
? 'animated'
: '';

switch (edge.stroke) {
case 'normal':
Expand Down Expand Up @@ -329,7 +339,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 22d0f40

Please sign in to comment.