forked from zelig/p2p-cy
-
Notifications
You must be signed in to change notification settings - Fork 1
/
cy.js
124 lines (109 loc) · 2.48 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
$(document).ready(function(){
var cy = cytoscape({
container: $('#cy'), // container to render in
// container: document.getElementById('cy'), // container to render in
layout: {
name: "spread"
},
style: [ // the stylesheet for the graph
{
selector: 'node',
style: {
'content': 'data(id)',
"font-size":"12px",
"text-valign":"center",
"text-halign":"center",
"background-color":"#000",
"text-outline-color":"#000",
"text-outline-width":"1px",
"color":"#fff",
"overlay-padding":"6px",
"z-index":"10"
}
},
{
selector: 'edge',
style: {
"font-size":"4px",
"label": "data(id)",
'edge-text-rotation': 'autorotate',
'width': 2,
'line-color': '#000',
'target-arrow-color': '#000',
// '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
}
}
]
});
var params = {
'name': 'spread'
};
var layout = cy.makeLayout(params);
// layout.run();
console.log("hey");
var update = function(journal) {
if (journal.add.length > 0) {
console.log(JSON.stringify(journal.add))
cy.add(journal.add);
};
if (journal.remove.length > 0) {
console.log(JSON.stringify(journal.remove))
cy.remove('#'+journal.remove.join(",#"));
};
var params = {
// 'name': 'grid'
'name': 'circle'
// 'name': 'spread'
};
var layout = cy.makeLayout(params);
layout.run();
};
var set_delay = 1000;
var callout = function () {
$.ajax({
dataType: "json",
url: "http://localhost:8888/0/",
method: "GET",
// crossDomain: true,
// json: {
// format: "cy.update"
// }
})
.done(function (response) {
console.log(response);
// update the page
update(response);
})
.always(function () {
setTimeout(callout, set_delay);
});
};
// layout.run()
// //clearInterval(id);
$.ajax({
dataType: "json",
url: "http://localhost:8888",
method: "POST",
// crossDomain: true,
// json: {
// format: "cy.update"
// }
})
.done(function (response) {
console.log(response);
})
// // initial call
callout();
});