-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DotStyleGenerator.ts
108 lines (92 loc) · 2.81 KB
/
DotStyleGenerator.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import { DocConfig } from "../../../Config";
import { ClusterType } from "../../../graph/GraphCluster";
import { NodeType } from "../../../graph/GraphNode";
import { IDocOutputter } from "../../../interfaces/IDocOutputter";
export class DotStyleGenerator {
constructor(
protected config: DocConfig,
protected outputter: IDocOutputter
) {}
outputStyling() {
this.outputGraphStyle();
this.outputDefaultNodeStyling();
}
outputGraphNodeStyle(nodeType: NodeType) {
switch (nodeType) {
case NodeType.Normal:
break;
case NodeType.External:
this.outputStylingForExternalNode();
break;
case NodeType.Any:
this.outputStylingForAnyNode();
break;
default:
throw new Error(`unhandled NodeType ${nodeType}`);
}
}
private outputStylingForExternalNode() {
this.outputter.outputLine("node [style=dashed]");
}
outputStylingForAnyNode() {
this.outputStylingForExternalNode();
}
outputContainerStyle(clusterType: ClusterType) {
this.outputPlaceLabelsAtTop();
switch (clusterType) {
case ClusterType.AreaWithSubFolders:
this.outputter.outputLine(
`node [shape="${this.config.dot.subFolderShape}"]`
);
break;
case ClusterType.FromOptimization:
this.outputOptimizedStyle();
break;
case ClusterType.DiagramCluster:
this.outputOptimizedStyle();
break;
case ClusterType.Root:
case ClusterType.TopLevel:
this.outputter.outputLine(
`node [shape="${this.config.dot.packageShape}"]`
);
break;
default:
throw new Error(`unhandled ClusterType ${clusterType}`);
}
}
private outputOptimizedStyle() {
this.outputter.outputLines([`color = gray`, `style=dashed`]);
}
outputPlaceLabelsAtTop() {
this.outputter.outputLine("labelloc = t");
this.outputter.outputLine("");
}
private outputGraphStyle() {
this.outputter.outputLine(`graph [`);
this.outputter.increaseIndent();
this.outputter.outputLines([`bgcolor="#FFFFFF"`, `fillcolor="#FFFFFF"`]);
this.outputter.decreaseIndent();
this.outputter.outputLine(`]`);
}
private outputDefaultNodeStyling() {
// ref: working_copy.dot
this.outputter.outputLine("node [");
this.outputter.increaseIndent();
// ref: colorscheme = https://graphviz.gitlab.io/_pages/doc/info/colors.html
this.outputter.outputLines([
`labeljust="l"`,
`colorscheme="${this.config.dot.colorScheme}"`,
`style=filled`,
`fillcolor=3`,
`shape=record`
]);
this.outputter.decreaseIndent();
this.outputter.outputLines([
`]`,
``,
// setting both head, tail as normally only one will apply
`edge [arrowhead="vee", arrowtail="vee", style=dashed, color="black"]`
]);
}
}