-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
131 lines (118 loc) · 3.92 KB
/
index.html
File metadata and controls
131 lines (118 loc) · 3.92 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Dependency Graph</title>
<script type="text/javascript" src="https://unpkg.com/vis-network/standalone/umd/vis-network.min.js"></script>
<style>
#network { width: 100%; height: 100vh; border: 1px solid lightgray; }
</style>
</head>
<body>
<div id="network"></div>
<h2>Most Important Packages</h2>
<table id="importance">
<thead><tr><th>Package</th><th>Importance</th></tr></thead>
<tbody></tbody>
</table>
<script>
async function draw() {
const [graphRes, importanceRes] = await Promise.all([
fetch('/graph'),
fetch('/importance')
]);
const graph = await graphRes.json();
const importance = Object.fromEntries(await importanceRes.json());
const nodes = [];
const edges = [];
for (const [project, deps] of Object.entries(graph)) {
const count = importance[project] ?? 0;
let color = '#97C2FC'; // default color
let border = undefined;
let dashes = false;
if (deps.length === 0) {
color = '#FFFFFF';
border = '#000000';
dashes = true;
} else if (count > 20) {
color = '#FF6B6B';
} else if (count > 10) {
color = '#FFD93D';
} else if (count > 5) {
color = '#6BCB77';
}
nodes.push({ id: project, label: project, color, borderWidth: border ? 2 : 1, borderWidthSelected: 2, borderColor: border, shape: 'ellipse', dashes });
for (const dep of deps) {
edges.push({ id: `${project}->${dep}`, from: project, to: dep, arrows: 'to' });
}
}
const container = document.getElementById('network');
const data = { nodes: new vis.DataSet(nodes), edges: new vis.DataSet(edges) };
const options = { layout: { hierarchical: false } };
const network = new vis.Network(container, data, options);
// Add click handler to dim unrelated nodes/edges
network.on('click', function (params) {
// Reset all nodes and edges to full opacity first
nodes.forEach(n => {
network.body.data.nodes.update({
id: n.id,
opacity: 1,
font: { color: '#000000' }
});
});
edges.forEach(e => {
network.body.data.edges.update({
id: e.id,
opacity: 1
});
});
if (params.nodes.length === 0) {
return;
}
const selected = params.nodes[0];
const connectedNodes = new Set([selected]);
function expand(node) {
network.getConnectedNodes(node, 'to').forEach(n => {
if (!connectedNodes.has(n)) {
connectedNodes.add(n);
expand(n);
}
});
}
expand(selected);
nodes.forEach(n => {
const isConnected = connectedNodes.has(n.id);
network.body.data.nodes.update({
id: n.id,
opacity: isConnected ? 1 : 0.2,
font: { color: isConnected ? '#000000' : 'rgba(0,0,0,0.2)' }
});
});
edges.forEach(e => {
const isEdgeConnected = (connectedNodes.has(e.from) && connectedNodes.has(e.to));
network.body.data.edges.update({
id: e.id,
color: {
color: isEdgeConnected ? '#848484' : 'rgba(132,132,132,0.2)',
highlight: '#848484',
hover: '#848484'
}
});
});
});
}
draw();
async function loadImportance() {
const res = await fetch('/importance');
const importance = await res.json();
const tbody = document.querySelector('#importance tbody');
for (const [pkg, count] of importance) {
const tr = document.createElement('tr');
tr.innerHTML = `<td>${pkg}</td><td>${count}</td>`;
tbody.appendChild(tr);
}
}
loadImportance();
</script>
</body>
</html>