-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdrawing.js
39 lines (31 loc) · 882 Bytes
/
drawing.js
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
function drawGraph(g, nodes, edges, targetId) {
var arrE = [];
for (let i = 0; i < edges.length; i++) {
var percentage = (g.edge(edges[i]).a/g.edge(edges[i]).c*packetSize*100).toFixed(0);
arrE.push({
from: edges[i].v,
to: edges[i].w,
font: {align: 'middle'},
label: percentage !== "NaN" ? `${percentage}%` : '',
});
}
var arrN = [];
for (let i = 0; i < nodes.length; i++) {
arrN.push({
id: nodes[i],
label: `${nodes[i]}`
});
}
var edges = new vis.DataSet(arrE);
var nodes = new vis.DataSet(arrN);
// create a network
var container = document.getElementById(targetId);
var data = {
nodes: nodes,
edges: edges
};
var options = {
physics: true
};
var network = new vis.Network(container, data, options);
}