-
Notifications
You must be signed in to change notification settings - Fork 13
/
config1.html
284 lines (268 loc) · 13.3 KB
/
config1.html
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="description" content="Terraform configuration graph">
<meta name="author" content="https://github.com/pcasteran/terraform-graph-beautifier">
<title>config1</title>
</head>
<style>
#cy {
width: 100%;
height: 95%;
position: absolute;
top: 40px;
left: 0px;
}
</style>
<body>
<script src="https://unpkg.com/cytoscape/dist/cytoscape.min.js"></script>
<script src="https://unpkg.com/layout-base/layout-base.js"></script>
<script src="https://unpkg.com/cose-base/cose-base.js"></script>
<script src="https://unpkg.com/cytoscape-fcose/cytoscape-fcose.js"></script>
<script src="https://unpkg.com/cytoscape-expand-collapse/cytoscape-expand-collapse.js"></script>
<p>
<b id="collapse-all" style="cursor: pointer;color: darkred">Collapse all</b>
/
<b id="expand-all" style="cursor: pointer; color: darkslateblue">Expand all</b>
-
<b id="run-layout" style="cursor: pointer; color: #598b3d">Run layout</b>
</p>
<div id="cy"></div>
<script>
// Helper function used to retrieve the scratchpad data of an element.
const getScratchPad = function (element) {
let scratchPad = element.scratch('_tf-graph-beautifier');
if (!scratchPad) {
scratchPad = element.scratch('_tf-graph-beautifier', {});
}
return scratchPad;
}
// Color palette used for the modules background.
//
// This is the "8-class Pastel2" palette from ColorBrewer v2.0 (https://colorbrewer2.org/?type=qualitative&scheme=Pastel2&n=8).
//
// This palette is covered by a licence, hence here is the related acknowledgments:
// This product includes color specifications and designs developed by Cynthia Brewer (http://colorbrewer.org/).
// Please see license at http://colorbrewer.org/export/LICENSE.txt
const moduleBgColorPalette = ['#b3e2cd', '#fdcdac', '#cbd5e8', '#f4cae4', '#e6f5c9', '#fff2ae', '#f1e2cc', '#cccccc'];
// Returns the color index in the `moduleBgColorPalette` for an element.
const getColorIndex = function (element) {
let scratchPad = getScratchPad(element);
let colorIndex = scratchPad["module-bg-color-index"];
if (colorIndex === undefined) {
// Get the color index of the parent (if any).
let parentId = element.data("parentModuleID");
if (parentId) {
let parent = element.cy().getElementById(parentId);
let parentColorIndex = getColorIndex(parent);
colorIndex = (parentColorIndex + 1) % moduleBgColorPalette.length;
} else {
colorIndex = 0;
}
scratchPad["module-bg-color-index"] = colorIndex;
}
return colorIndex
}
// Layout options.
const layoutOptions = {
name: 'fcose',
// 'draft', 'default' or 'proof'
// - "draft" only applies spectral layout
// - "default" improves the quality with incremental layout (fast cooling rate)
// - "proof" improves the quality with incremental layout (slow cooling rate)
quality: "proof",
// Use random node positions at beginning of layout
// if this is set to false, then quality option must be "proof"
randomize: false,
// Whether or not to animate the layout
animate: "end",
// Duration of animation in ms, if enabled
animationDuration: 500,
// Easing of animation, if enabled
animationEasing: undefined,
// Fit the viewport to the repositioned nodes
fit: true,
// Padding around layout
padding: 45,
// Whether to include labels in node dimensions. Valid in "proof" quality
nodeDimensionsIncludeLabels: true,
// Whether or not simple nodes (non-compound nodes) are of uniform dimensions
uniformNodeDimensions: false,
// Whether to pack disconnected components - valid only if randomize: true
packComponents: true,
/* spectral layout options */
// False for random, true for greedy sampling
samplingType: true,
// Sample size to construct distance matrix
sampleSize: 25,
// Separation amount between nodes
nodeSeparation: 75,
// Power iteration tolerance
piTol: 0.0000001,
/* incremental layout options */
// Node repulsion (non overlapping) multiplier
nodeRepulsion: 4500,
// Ideal edge (non nested) length
idealEdgeLength: 50,
// Divisor to compute edge forces
edgeElasticity: 0.45,
// Nesting factor (multiplier) to compute ideal edge length for nested edges
nestingFactor: 0.1,
// Maximum number of iterations to perform
numIter: 2500,
// For enabling tiling
tile: true,
// Represents the amount of the vertical space to put between the zero degree members during the tiling operation(can also be a function)
tilingPaddingVertical: 10,
// Represents the amount of the horizontal space to put between the zero degree members during the tiling operation(can also be a function)
tilingPaddingHorizontal: 10,
// Gravity force (constant)
gravity: 0.25,
// Gravity range (constant) for compounds
gravityRangeCompound: 1.5,
// Gravity force (constant) for compounds
gravityCompound: 1.0,
// Gravity range (constant)
gravityRange: 3.8,
// Initial cooling factor for incremental layout
initialEnergyOnIncremental: 0.3,
};
// Create the DOM element used to draw the graph.
let initialLayoutOptions = Object.assign({}, layoutOptions);
initialLayoutOptions["randomize"] = true;
const cy = cytoscape({
container: document.getElementById('cy'),
layout: initialLayoutOptions,
style: [
{
selector: 'node',
style: {
'label': 'data(label)',
'shape': 'rectangle',
'width': 'label',
'height': 'label',
'padding': '10px',
'text-valign': 'center',
'text-halign': 'center',
'background-color': '#EEEEEE',
'border-style': 'solid',
'border-width': 1,
'border-color': '#000000',
}
},
{
selector: 'node.resource',
style: {
'shape': 'round-rectangle',
},
},
{
selector: 'node.var',
style: {
'shape': 'ellipse',
},
},
{
selector: 'node.local',
style: {
'shape': 'ellipse',
},
},
{
selector: 'node.output',
style: {
'shape': 'cut-rectangle',
},
},
{
selector: 'node.module',
style: {
'font-weight': 'bold',
'text-valign': 'top',
'text-halign': 'center',
'background-color': function (ele) {
let colorIndex = getColorIndex(ele);
return moduleBgColorPalette[colorIndex];
}
}
},
{
selector: 'node.provider',
style: {
'shape': 'diamond',
'padding': '25px',
},
},
{
selector: "node.cy-expand-collapse-collapsed-node",
style: {
'border-style': 'dashed'
}
},
{
selector: ':selected',
style: {
"border-width": 2
}
},
{
selector: 'edge',
style: {
'line-style': 'solid',
'width': 1,
'line-color': '#000000',
'source-arrow-color': '#000000',
'target-arrow-color': '#000000',
'target-arrow-shape': 'triangle',
'curve-style': 'bezier',
}
},
{
selector: 'edge[targetType = "var"], edge[targetType = "local"]',
style: {
'line-style': 'dotted',
}
},
{
selector: 'edge[targetType = "output"]',
style: {
'line-style': 'dashed',
}
},
{
selector: 'edge[sourceType = "module"][targetType = "module"]',
style: {
'width': 2,
'source-arrow-shape': 'diamond',
'curve-style': 'straight',
}
},
{
selector: 'edge.cy-expand-collapse-meta-edge',
style: {
'visibility': 'hidden'
}
},
],
elements: {"nodes":[{"data":{"id":"module.root","label":"module.root","type":"module"},"classes":["module"]},{"data":{"id":"module.root.module.random_file","parent":"module.root","label":"module.random_file","type":"module","parentModuleID":"module.root"},"classes":["module"]},{"data":{"id":"module.root.module.random_file.random_string.content","parent":"module.root.module.random_file","label":"random_string.content","type":"resource"},"classes":["resource"]},{"data":{"id":"module.root.module.random_file.time_static.creation_time","parent":"module.root.module.random_file","label":"time_static.creation_time","type":"resource"},"classes":["resource"]},{"data":{"id":"module.root.module.random_file.output.file_name","parent":"module.root.module.random_file","label":"output.file_name","type":"output"},"classes":["output"]},{"data":{"id":"module.root.module.random_file.var.file_prefix","parent":"module.root.module.random_file","label":"var.file_prefix","type":"var"},"classes":["var"]},{"data":{"id":"module.root.module.random_file.local_file.file","parent":"module.root.module.random_file","label":"local_file.file","type":"resource"},"classes":["resource"]},{"data":{"id":"module.root.module.random_file.module.noop","parent":"module.root.module.random_file","label":"module.noop","type":"module","parentModuleID":"module.root.module.random_file"},"classes":["module"]},{"data":{"id":"module.root.module.random_file.module.noop.null_resource.noop","parent":"module.root.module.random_file.module.noop","label":"null_resource.noop","type":"resource"},"classes":["resource"]},{"data":{"id":"module.root.output.file_name","parent":"module.root","label":"output.file_name","type":"output"},"classes":["output"]}],"edges":[{"data":{"id":"module.root.module.random_file.local_file.file-module.root.module.random_file.random_string.content","source":"module.root.module.random_file.local_file.file","target":"module.root.module.random_file.random_string.content","sourceType":"resource","targetType":"resource"},"classes":["resource-resource"]},{"data":{"id":"module.root.module.random_file.local_file.file-module.root.module.random_file.time_static.creation_time","source":"module.root.module.random_file.local_file.file","target":"module.root.module.random_file.time_static.creation_time","sourceType":"resource","targetType":"resource"},"classes":["resource-resource"]},{"data":{"id":"module.root.module.random_file.output.file_name-module.root.module.random_file.local_file.file","source":"module.root.module.random_file.output.file_name","target":"module.root.module.random_file.local_file.file","sourceType":"output","targetType":"resource"},"classes":["output-resource"]},{"data":{"id":"module.root.module.random_file.random_string.content-module.root.module.random_file.var.file_prefix","source":"module.root.module.random_file.random_string.content","target":"module.root.module.random_file.var.file_prefix","sourceType":"resource","targetType":"var"},"classes":["resource-var"]},{"data":{"id":"module.root.module.random_file.time_static.creation_time-module.root.module.random_file.var.file_prefix","source":"module.root.module.random_file.time_static.creation_time","target":"module.root.module.random_file.var.file_prefix","sourceType":"resource","targetType":"var"},"classes":["resource-var"]},{"data":{"id":"module.root.output.file_name-module.root.module.random_file.output.file_name","source":"module.root.output.file_name","target":"module.root.module.random_file.output.file_name","sourceType":"output","targetType":"output"},"classes":["output-output"]}]}
});
const expandCollapseApi = cy.expandCollapse({
layoutBy: layoutOptions,
fisheye: true,
animate: false,
undoable: false
});
document.getElementById("collapse-all").addEventListener("click", function () {
expandCollapseApi.collapseAll();
});
document.getElementById("expand-all").addEventListener("click", function () {
expandCollapseApi.expandAll();
});
document.getElementById("run-layout").addEventListener("click", function () {
const layout = cy.layout(layoutOptions);
layout.run();
});
</script>
</body>
</html>