-
Notifications
You must be signed in to change notification settings - Fork 17
/
cy.js
138 lines (125 loc) · 3.16 KB
/
cy.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
135
136
137
138
var host = "http://localhost:8888/";
// var host = "http://192.168.1.3:8888/";
var pollInterval = 1000;
var timeoutInterval = 1000;
var cy;
var layout_opts = {
name: 'cola',
fit: true,
idealEdgeLength: 100,
nodeOverlap: 20,
animate: true,
animationDuration: 12200,
// animationEasing: 'ease-out-quint',
randomize: false,
maxSimulationTime: 10500,
nodeSpacing: 30
}
var initNetwork = function(){
return $.ajax({
dataType: "json",
url: host,
method: "POST",
});
}
var initMocker = function(){
return $.ajax({
dataType: "json",
url: host+"0/mockevents/",
method: "POST",
});
}
var getNodes = function(){
return $.ajax({
dataType: "json",
// url: "init.json",
url: host+"0/",
method: "GET",
});
};
var ajax_error_handler = function(e){
console.error("ajax error: "+e)
};
var initialiseCy = function(initialNodes){
cy = cytoscape({
container: $('#cy'), // container to render in
motionBlur: true,
// container: document.getElementById('cy'), // container to render in
layout: layout_opts,
style: [ // the stylesheet for the graph
{
selector: 'node',
style: {
'shape': 'hexagon',
'content': 'data(id)',
"font-size":"20px",
"text-valign":"center",
"text-halign":"center",
"background-color":"#000",
"text-outline-color":"#000",
"text-outline-width":"1px",
"color":"orange",
"overlay-padding":"8px",
"z-index":"10",
"width": "110px",
"height": "100px",
"border-width": "2px",
"border-color": "orange"
}
},
{
selector: 'edge',
style: {
"font-size":"4px",
"label": "data(id)",
'edge-text-rotation': 'autorotate',
'width': 2,
'line-color': 'white',
'target-arrow-color': 'white',
'target-arrow-shape': 'triangle',
"curve-style":"haystack",
"haystack-radius":"0.5",
"opacity":"0.4",
"overlay-padding":"3px",
"z-index":"10"
}
},
{
selector: '.faded',
style: {
'opacity': 0.25,
'text-opacity': 0
}
},
],
elements: initialNodes
});
};
var updateCy = function(journal){
if (journal.add.length > 0) {
console.log("add", JSON.stringify(journal.add.length))
cy.add(journal.add);
};
if (journal.remove.length > 0) {
console.log("rm", JSON.stringify(journal.remove.length))
cy.remove('#'+journal.remove.join(",#"));
};
var layout = cy.makeLayout(layout_opts);
layout.run();
}
$(function(){
initNetwork()
.then(function(response){
initMocker()
.then(function(response){
console.log('new network simulation started');
var initialNodes = false;
setTimeout(function(){
getNodes().then(function(response){
initialiseCy(response.add);
setInterval(function(){getNodes().then(function(response){updateCy(response);})}, pollInterval);
},ajax_error_handler)
},timeoutInterval)
},ajax_error_handler)
},ajax_error_handler)
});