-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
198 lines (170 loc) · 7.52 KB
/
index.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
<!DOCTYPE html>
<html>
<meta charset="UTF-8">
<head>
<title>
Arch package viz
</title>
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BmbxuPwQa2lc/FVzBcNJ7UAyJxM6wuqIj61tLrc4wSX0szH/Ev+nYRRuWlolflfl" crossorigin="anonymous">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="./style.css">
<style id="NodeStyle">
.toggleNodeVisibility {
display: none;
}
</style>
<script type="text/javascript" src="./dist/vivagraph.js"></script>
<script type="text/javascript" src="./searcher.js"></script>
<script type="text/javascript">
function addSearchFunction() {
document.getElementById('searchbutton').setAttribute('onclick', 'drawgraph()')
document.getElementById('packageInput').addEventListener('keyup', (ev => {
if (ev.key === 'Enter') {
drawgraph();
}
}));
}
document.addEventListener("DOMContentLoaded", addSearchFunction);
</script>
<script type="text/javascript">
function toggleLabels() {
if (!document.getElementById('ShowLabels').checked) {
document.getElementById('NodeStyle').innerText = ".toggleNodeVisibility{display: none;}";
} else {
document.getElementById('NodeStyle').innerText = ".toggleNodeVisibility{display: block;}";
}
}
</script>
<script>
async function drawgraph() {
document.getElementById('graphContainer').innerHTML = '';
const graph = Viva.Graph.graph();
const packageName = document.getElementById('packageInput').value;
graph.addNode(packageName);
await addSubtree(packageName, graph, new Set());
let domLabels = new Set();
// Set custom nodes appearance
const graphics = Viva.Graph.View.webglGraphics();
const layout = Viva.Graph.Layout.forceDirected(graph, {
springLength: 1,
springCoeff: 0.0001,
dragCoeff: 0.01,
gravity: -7
});
graphics.placeNode((ui, pos) => {
if (typeof domLabels[ui.node.id] === "undefined") {
const label = document.createElement('span');
label.classList.add('node-label');
label.classList.add('toggleNodeVisibility');
label.innerText = ui.node.id;
document.getElementById('graphContainer').appendChild(label);
domLabels[ui.node.id] = label;
}
// create a copy of layout position
const domPos = {
x: pos.x,
y: pos.y
};
// And ask graphics to transform it to DOM coordinates:
graphics.transformGraphToClientCoordinates(domPos);
const nodeId = ui.node.id;
const labelStyle = domLabels[nodeId].style;
const labelWidth = domLabels[nodeId].offsetWidth;
const labelHeight = domLabels[nodeId].offsetHeight;
labelStyle.left = (domPos.x - labelWidth / 2) + 'px';
labelStyle.top = (domPos.y - labelHeight / 2) + 'px';
//check there is nothing undefined being accessed
if (typeof ui.node.data !== "undefined" &&
ui.node.data['repository'] !== "undefined" &&
!labelStyle.hasOwnProperty('color')) {
labelStyle.color = repoToColor(ui.node.data['repository']);
}
})
.node(node => {
return Viva.Graph.View.webglSquare(5, '#666666')
});
const renderer = Viva.Graph.View.renderer(graph, {
graphics: graphics,
layout: layout,
container: document.getElementById('graphContainer')
});
renderer.run();
}
function repoToColor(repository) {
switch (repository) {
case 'extra':
return '#5baa00'
case 'core':
return "#008bc6"
case 'community':
return '#b90000'
case 'multilib':
return '#d07603'
default:
return '#ffffff'
}
}
</script>
</head>
<body onload="toggleLabels()">
<div class="container top-row mt-3 mb-3">
<div class="row">
<div class="col mt-3 mb-3">
<div class="form-floating">
<input type="text" id="packageInput" class="form-control" placeholder="">
<label for="packageInput">Package</label>
<button type="button" id="searchbutton" class="btn btn-primary mt-2">Draw</button>
<p id="ErrorMessageBox" class="mt-2"></p>
</div>
</div>
<div class="col mt-3 mb-3">
<div class="row">
<label for="includeOptionalDepsCheckbox">
<input type="checkbox" id="includeOptionalDepsCheckbox">
Include optional dependencies
</label>
</div>
<div class="row">
<label for="includeMakeDepsCheckbox">
<input type="checkbox" id="includeMakeDepsCheckbox">
Include make dependencies
</label>
</div>
<div class="row">
<label for="allowCircularDependencies">
<input type="checkbox" id="allowCircularDependencies">
Allow circular dependencies
</label>
</div>
</div>
<div class="col mt-3 mb-3">
<div class="row">
<label for="ShowLabels">
<input type="checkbox" id="ShowLabels" onclick="toggleLabels()">
Display node labels
</label>
</div>
</div>
<div class="col mt-3 mb-3 toggleNodeVisibility">
<div class="col mt-3 mb-3">
<div class="row">
<div class="col">
<span style="color: #008bc6">Core packages</span><br>
<span style="color: #5baa00">Extra packages</span><br>
<span style="color: #b90000">Community packages</span>
</div>
<div class="col">
<span style="color: #d07603">Multilib packages</span><br>
<span style="color: #ffffff">Unresolvable packages (most likely .so files)</span>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="container-fluid" id="graphContainer">
</div>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-b5kHyXgcpbZJO/tY9Ul7kGkf1S0CWuKcCD38l8YkeH8z8QjE0GmW1gYU5S9FOnJ0" crossorigin="anonymous"></script>
</body>
</html>