-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
63 lines (56 loc) · 1.62 KB
/
script.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/**
* Created by aarnavjindal on 19/03/20.
*/
onload = function () {
// create a network
const container = document.getElementById('container');
const genNew = document.getElementById('generate-graph');
// initialise graph options
const options = {
edges: {
labelHighlightBold: true,
font: {
size: 20
}
},
nodes: {
font: '12px arial red',
scaling: {
label: true
},
shape: 'icon',
icon: {
face: 'FontAwesome',
code: '\uf015',
size: 40,
color: '#991133',
}
}
};
// initialize your network!
const network = new vis.Network(container);
network.setOptions(options);
function createData(){
const cities = ['Delhi', 'Mumbai', 'Gujarat', 'Goa', 'Kanpur', 'Jammu', 'Hyderabad', 'Bangalore', 'Gangtok', 'Meghalaya'];
const V = Math.floor(Math.random() * cities.length) + 3;
let vertices = [];
for(let i=0;i<V;i++){
vertices.push({id:i, label: cities[i-1]});
}
let edges = [];
for(let i=1;i<V;i++){
let neigh = Math.floor(Math.random()*i);
edges.push({from: i, to: neigh, color: 'orange',label: String(Math.floor(Math.random()*70)+30)});
}
const data = {
nodes: vertices,
edges: edges
};
return data;
}
genNew.onclick = function () {
let data = createData();
network.setData(data);
};
genNew.click();
};