-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmermaid-render.ts
86 lines (68 loc) · 1.99 KB
/
mermaid-render.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import { Graph, GraphEdge } from "./graph-builder";
import { MermaidNode } from "./mermaid-node";
export class MermaidRender {
constructor(private readonly includeLegend: boolean) {}
public render(graph: Graph): string {
return `
\`\`\`mermaid
flowchart TD
${this.renderLegendSection()}
${this.renderCssSection()}
${this.renderIssuesSection(graph.vertices)}
${this.renderDependencies(graph.edges)}
\`\`\`
`;
}
private renderCssSection(): string {
return `
%% <CSS>
classDef notstarted fill:#FFF,color:#000;
classDef started fill:#fae17d,color:#000;
classDef completed fill:#ccffd8,color:#000;
%% </CSS>
`;
}
private renderLegendSection(): string {
if (!this.includeLegend) {
return "";
}
return `
%% <Legend>
legend --> start
subgraph legend["Legend"]
direction LR;
notstarted("Issue is not started"):::notstarted;
started("Issue is in progress"):::started;
completed("Issue is done"):::completed;
notstarted --> started --> completed;
end
%% </Legend>
`;
}
private renderIssuesSection(issues: MermaidNode[]): string {
const renderedGraphIssues = issues.map(x => this.renderIssue(x)).join("\n\n");
return `
%% <Issues>
${renderedGraphIssues}
%% </Issues>
`;
}
private renderIssue(issue: MermaidNode): string {
const title = issue.getFormattedTitle();
const linkedTitle = issue.url
? `<a href='${issue.url}' style='text-decoration:none;color: inherit;'>${title}</a>`
: title;
return `${issue.nodeId}("${linkedTitle}"):::${issue.status};`;
}
private renderDependencies(dependencies: GraphEdge[]): string {
const renderedDependencies = dependencies.map(x => this.renderDependency(x)).join("\n");
return `
%% <Dependencies>
${renderedDependencies}
%% </Dependencies>
`;
}
private renderDependency(dependency: GraphEdge): string {
return `${dependency.from.nodeId} --> ${dependency.to.nodeId};`;
}
}