-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathvisual.js
134 lines (122 loc) · 3.14 KB
/
visual.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
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
// const vis = require('./vis/dist/vis.js')
// var nodes = new vis.DataSet([
// {id: 1, label: 'Node 1'},
// {id: 2, label: 'Node 2'},
// {id: 3, label: 'Node 3'},
// {id: 4, label: 'Node 4'},
// {id: 5, label: 'Node 5'}
// ]);
// // create an array with edges
// let arr = [
// {from: 1, to: 3},
// {from: 1, to: 2},
// {from: 2, to: 4},
// {from: 2, to: 5},
// // {from: 3, to: 3}
// ]
// let edgeAr = []
// var edges = new vis.DataSet(edgeAr);
// // create a network
// var container = document.getElementById('mynetwork');
// var data = {
// nodes: nodes,
// edges: edges
// };
// var options = {
// nodes: {
// shape: "dot",
// size: 15,
// borderWidth: 2
// },
// edges: {
// width: 2
// }
// };
// var network = new vis.Network(container, data, options);
// counter = 0
// const submit = document.querySelector('#but')
// submit.addEventListener('click', (e)=>{
// // let val = {id:counter, label:`Node ${counter}`}
// let edge = {from: 1, to:counter}
// // nodes.update(val)
// edges.update(arr[counter])
// counter+=1
// })
// Since we are only updating a color of a graph, we dont need to add
// all the edges one by one
// Function to initialise a graph network
const initGraph = function () {
// Async request for getting a list of node of a graph
n = [
{ id: 1, label: 'Node 1' },
{ id: 2, label: 'Node 2' },
{ id: 3, label: 'Node 3' },
{ id: 4, label: 'Node 4' },
{ id: 5, label: 'Node 5' },
];
e = [
{ from: 1, to: 3 },
{ from: 1, to: 2 },
{ from: 2, to: 4 },
{ from: 2, to: 5 },
// {from: 3, to: 3}
];
var nodes = new vis.DataSet(n);
var edges1 = new vis.DataSet(e);
var edges2 = new vis.DataSet([{ from: 1, to: 3 }]);
// create a network
var container1 = document.getElementById('mynetwork1');
var container2 = document.getElementById('mynetwork2');
var data1 = {
nodes: nodes,
edges: edges1,
};
var data2 = {
nodes: nodes,
edges: edges2,
};
var options = {
nodes: {
shape: 'dot',
size: 15,
borderWidth: 2,
},
edges: {
width: 2,
color: {
inherit: false,
},
},
};
var network1 = new vis.Network(container1, data1, options);
var network2 = new vis.Network(container2, data2, options);
console.log('YYY' + edges2);
return { nodes, edges2 };
};
const graph = initGraph();
console.log(graph);
var nodes = graph.nodes;
var edges = graph.edges2;
// Async request for getting the edge list in a particular order
arr = [
// {from: 1, to: 3},
{ from: 1, to: 2 },
{ from: 2, to: 4 },
{ from: 2, to: 5 },
{ from: 3, to: 3 },
];
counter = 0;
const submit = document.querySelector('#but');
// var x = new TimedQueue(2000);
submit.addEventListener('click', (e) => {
console.log(edges);
for (var counter = 0; counter < arr.length; counter++) {
(function (counter) {
setTimeout(function () {
edges.update(arr[counter]);
}, 2000 * counter);
})(counter);
}
console.log(edges);
submit.textContent = 'Stopped Animation';
});