-
Notifications
You must be signed in to change notification settings - Fork 1
/
visualize.html
109 lines (96 loc) · 3.03 KB
/
visualize.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>BBOT Demo</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://code.jquery.com/jquery-3.6.3.min.js" integrity="sha256-pvPw+upLPUjgMXY0G+8O0xUf+/Im1MZjXxxgOcBQBXU=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vivagraphjs/0.12.0/vivagraph.js"></script>
<style>
body {
background-color: black;
}
#graphVisualization {
width: calc(100vw - 1em);
height: calc(100vh - 1em);
}
</style>
</head>
<body>
<div id="graphVisualization">
</div>
<script>
checkSupport = function() {
if (window.WebGLRenderingContext) {
var elem = document.createElement('canvas');
if (!elem.getContext || !elem.getContext('experimental-webgl')) {
return false;
}
return true;
}
return false;
},
webglSupported = checkSupport();
renderGraph = async function() {
$("#graphVisualization").empty();
var graph = Viva.Graph.graph();
var layout = Viva.Graph.Layout.forceDirected(graph, {
springLength: 30,
springCoeff: 0.0001,
dragCoeff: 0.009,
gravity: -1.2,
theta: 0.8
});
var graphics = webglSupported ? Viva.Graph.View.webglGraphics() : Viva.Graph.View.svgGraphics();
graphics.node(function(node){
return Viva.Graph.View.webglSquare(20, 0xff8400ff);
})
.link(function(link) {
return Viva.Graph.View.webglLine(0x888888ff);
});
var renderer = Viva.Graph.View.renderer(graph, {
layout: layout,
graphics: graphics,
renderLinks: true,
container: document.getElementById('graphVisualization')
});
renderer.run();
// zoom level
// for (var i = 0; i < 4; i++) {
// renderer.zoomOut();
// }
var i = 0;
function myLoop() {
setTimeout(function() {
i++;
if (i < 100) {
console.log(i);
graph.beginUpdate();
graph.addLink(Math.floor(Math.random() * 100), Math.floor(Math.random() * 10));
graph.endUpdate();
myLoop();
}
}, 100)
}
// uncomment to fill graph with random data (for testing)
// myLoop();
// Create WebSocket connection.
const socket = new WebSocket('ws://localhost:1234');
// Listen for messages
socket.addEventListener('message', (event) => {
console.log(event.data);
var i = JSON.parse(event.data)["id"];
var s = JSON.parse(event.data)["parent"];
graph.beginUpdate();
if (i && s) {
graph.addLink(i, s);
} else {
console.error(`${i}:${s}`);
}
graph.endUpdate();
});
}
renderGraph();
</script>
</body>
</html>