-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdebug.html
More file actions
455 lines (369 loc) · 16.7 KB
/
debug.html
File metadata and controls
455 lines (369 loc) · 16.7 KB
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
<head>
<title>Santa Barbara Surgery</title>
<style>
body {
margin: 0;
}
</style>
<!--
<script src="//unpkg.com/3d-force-graph"></script>
-->
<script src="./libs/3d-force-graph.min.js"></script>
<script src="http://unpkg.com/three"></script>
<script src="libs/MyBoxBufferGeometry.js"></script>
<script>
var zdistance = 200;
var active_link_colors = {};
var active_node_colors = {};
/*
A global variable to hold the loaded JSON
*/
var loaded_json = null;
/*
The JSON is processed into an array of cells
-> I am reconstructing the data structure used in the Python code
*/
var coordinates_matrix = {};
function filterEdgeOnColor(color) {
// make active or inactive
active_link_colors[color] = !active_link_colors[color];
// console.log("filter " + color + " " + active_link_colors[color]);
// for all colors generate an object
// only with the ones which are active (True)
processed_json = {};
processed_json.nodes = loaded_json.nodes;
processed_json.links = [];
for (var i = 0; i < loaded_json["links"].length; i++) {
if (loaded_json.links[i].c == color || color == "all") {
processed_json.links.push(loaded_json.links[i]);
}
}
//reload JSON
Graph.graphData(processed_json);
}
function filterNodeOnColor(color) {
// make active or inactive
active_link_colors[color] = !active_link_colors[color];
processed_json = {};
//an empty set of nodes
//add only nodes of specific color
active_nodes = {};
processed_json.nodes = [];
for (var i = 0; i < loaded_json["nodes"].length; i++) {
if (loaded_json.nodes[i].c == color || color == "all") {
processed_json.nodes.push(loaded_json.nodes[i]);
active_nodes[loaded_json.nodes[i].id] = true;
}
}
// add links only between nodes which exist in the collection
processed_json.links = [];
for (var i = 0; i < loaded_json["links"].length; i++) {
var key_is_in = loaded_json.links[i].source.id in active_nodes;
key_is_in = key_is_in && loaded_json.links[i].target.id in active_nodes;
if (key_is_in) {
processed_json.links.push(loaded_json.links[i]);
}
}
//reload JSON
Graph.graphData(processed_json);
}
function filterNodeOnTime(time) {
processed_json = {};
//an empty set of nodes
//add only nodes of specific time coordinate
active_nodes = {};
processed_json.nodes = [];
for (var i = 0; i < loaded_json["nodes"].length; i++) {
if (loaded_json.nodes[i].fz <= time) {
processed_json.nodes.push(loaded_json.nodes[i]);
active_nodes[loaded_json.nodes[i].id] = true;
}
}
// add links only between nodes which exist in the collection
processed_json.links = [];
for (var i = 0; i < loaded_json["links"].length; i++) {
var key_is_in = loaded_json.links[i].source.id in active_nodes;
key_is_in = key_is_in && loaded_json.links[i].target.id in active_nodes;
if (key_is_in) {
processed_json.links.push(loaded_json.links[i]);
}
}
//reload JSON
Graph.graphData(processed_json);
}
function filterNodeOnOp(op_number) {
processed_json = {};
//an empty set of nodes
//add only nodes of specific time coordinate
active_nodes = {};
processed_json.nodes = [];
for (var i = 0; i < loaded_json["nodes"].length; i++) {
if (loaded_json.nodes[i].op == op_number || op_number == "-1") {
processed_json.nodes.push(loaded_json.nodes[i]);
active_nodes[loaded_json.nodes[i].id] = true;
}
}
// add links only between nodes which exist in the collection
processed_json.links = [];
for (var i = 0; i < loaded_json["links"].length; i++) {
var key_is_in = loaded_json.links[i].source.id in active_nodes;
key_is_in = key_is_in && loaded_json.links[i].target.id in active_nodes;
if (key_is_in) {
processed_json.links.push(loaded_json.links[i]);
}
}
//reload JSON
Graph.graphData(processed_json);
}
function addControlColor(color, where_id) {
var btn = document.createElement("button");
var t = document.createTextNode(".....");
if (color == "all")
t.textContent = "All"
btn.appendChild(t);
if (color != "all")
btn.style["background-color"] = color;
if (where_id === "edge_buttons")
btn.onclick = function () { filterEdgeOnColor(color) };
else if (where_id === "node_buttons")
btn.onclick = function () { filterNodeOnColor(color) };
document.getElementById(where_id).appendChild(btn);
}
function check_coordinate_exists(collection, c1, c2, c3)
{
if (! (c1 in collection))
return false;
if(! (c2 in collection[c1]) )
return false;
if(! (c3 in collection[c1][c2]))
return false;
return true;
}
function add_coordinates_as_keys(collection, fx, fy, fz)
{
if(! (fx in collection))
{
collection[fx] = {}
}
if(! (fy in collection[fx]))
{
collection[fx][fy] = {}
}
if(! (fz in collection[fx][fy]))
{
collection[fx][fy][fz] = -1;
}
}
function counterOnChange() {
// reset active colors
active_link_colors = {};
active_node_colors = {};
var myNode = document.getElementById('edge_buttons');
while (myNode.firstChild) {
myNode.removeChild(myNode.firstChild);
}
var myNode = document.getElementById('node_buttons');
while (myNode.firstChild) {
myNode.removeChild(myNode.firstChild);
}
var filename = 'layout.json';
console.log("fetch " + filename);
fetch(filename)
.then(function (response) {
return response.json();
},
function (reason) {
console.log(reason);
})
.then(function (myJson) {
//save to global var?
loaded_json = myJson;
for (var i = 0; i < myJson["nodes"].length; i++)
{
var node = myJson["nodes"][i];
add_coordinates_as_keys(coordinates_matrix, node.fx, node.fy, node.fz);
coordinates_matrix[node.fx][node.fy][node.fz] = node.op;
}
Graph.graphData(loaded_json);
//console.log("XXX" + myJson.links.length);
for (var i = 0; i < myJson["links"].length; i++) {
var curr_link = myJson.links[i];
if (!(curr_link.c in active_link_colors)) {
active_link_colors[curr_link.c] = true;
addControlColor(curr_link.c, "edge_buttons");
}
}
operation_ids = {}
var min_time = 10000;
var max_time = -1000;
for (var i = 0; i < myJson["nodes"].length; i++) {
//collect operation ids
if (!(myJson.nodes[i].op in operation_ids))
{
operation_ids[myJson.nodes[i].op] = myJson.nodes[i].op;
}
var curr_node = myJson.nodes[i];
if (!(curr_node.c in active_node_colors)) {
active_node_colors[curr_node.c] = true;
addControlColor(curr_node.c, "node_buttons");
}
if (min_time > curr_node.fz) {
min_time = curr_node.fz;
}
if (max_time < curr_node.fz) {
max_time = curr_node.fz;
}
}
/*merge geometries for cubes with the same operation ID*/
//add a button to view all again
addControlColor("all", "edge_buttons");
addControlColor("all", "node_buttons");
document.getElementById("number_time").min = min_time;
document.getElementById("number_time").max = max_time;
document.getElementById("number_time").value = max_time;
var select_html = document.getElementById("operation_id")
for (var key in operation_ids)
{
var opt = document.createElement("option");
opt.value = key;
var txt = document.createTextNode(key + "");
opt.appendChild(txt);
select_html.appendChild(opt);
}
// console.log("maxtime" + max_time);
});
}
</script>
</head>
<body>
<div id="graphcounter">
Graph number
<input type="number" min="0" max="1000" step="1" value="0" onchange="counterOnChange(this.value)">
Time Coordinate
<input type="number" id="number_time" min="0" max="1000" step="1" value="0" onchange="filterNodeOnTime(this.value)">
Operation Id:
<select id="operation_id" onchange="filterNodeOnOp(this.value)">
<option value="-1">All</option>
</select>
</div>
<div id="controlpanel">
View Edge <div id="edge_buttons"></div>
View Node <div id="node_buttons"></div>
</div>
<div id="3d-graph"></div>
<script>
function is_zero_vector(vector)
{
var ret = true;
for(var i=0; i<vector.length; i++)
{
ret = ret && (vector[i] == 0);
}
return ret;
}
function generate_geometry(mesh, dim1, dim2, dim3, offset, sides, color)
{
var material_cube = new THREE.MeshBasicMaterial( { color: color, opacity: 0.8, transparent: true, side:THREE.DoubleSide});
var material_sides = new THREE.MeshBasicMaterial( { color: 0x000000, opacity: 1, transparent: false, side:THREE.DoubleSide});
//the geometry element
var geometry = new MyBoxBufferGeometry(sides, dim1, dim2, dim3);
//will be offset by the vector specified in the parameters
//make it a vector
if(!is_zero_vector(offset))
{
geometry.applyMatrix( new THREE.Matrix4().makeTranslation(offset[0], offset[1], offset[2]) );
}
//the mesh is added to the mesh received as parameter
var geom_mesh = new THREE.Mesh( geometry, material_cube);
mesh.add(geom_mesh);
// the X operator is specified by the sides argument
// if it is different from 63, then add the operator
// same procedure as before: geometry + mesh
if(sides != 63)
{
// add the black sides - X logical stabiliser indication for the cell
var geometry2 = new MyBoxBufferGeometry(63 - sides, dim1, dim2, dim3);
if (!is_zero_vector(offset))
{
geometry2.applyMatrix( new THREE.Matrix4().makeTranslation(offset[0], offset[1], offset[2]) );
}
var mesh2 = new THREE.Mesh( geometry2, material_sides);
mesh.add(mesh2);
}
// the edges of the drawn cubes are added
// this is increasing the complexity of the visualisation just for eye candy
// add wires for nicer visualisation
var edges = new THREE.EdgesGeometry( geometry );
var wire_edges = new THREE.LineSegments( edges, edges_mat );
mesh.add(wire_edges);
}
</script>
<script>
var scale_factor = 0.5;//0.25;
var dim = 0.8;
dim = dim * scale_factor;
var decorator_factor = 1.2;
var edges_mat = new THREE.LineBasicMaterial( { color: 0x000000, linewidth: 2 } );
var Graph = ForceGraph3D()
(document.getElementById('3d-graph'))
.nodeRelSize(0.1)
.nodeVal(d => { if (d.hasOwnProperty("s")){return d.s;} else {return 0.5}})
.linkWidth(0.7)
.linkOpacity(1)
.backgroundColor("#ffffff")
.nodeColor("c")
.linkColor("c")
.cameraPosition({ x: 0, y: 0, z: zdistance })
.height(window.innerHeight * 0.9)
.nodeLabel(d => `<span style="color: black">${d.op}</span>`)
.nodeThreeObject( cube =>
{
if(cube.c == "white")
{
return;
}
// this is the mesh where objects will be stored
var mesh = new THREE.Mesh();
var sides = cube.s;
var color = cube.c;
var dim1 = dim;
var dim2 = dim;
var dim3 = dim;
var offset = [0, 0, 0];
if (cube.d == 'orange')
{
//flat operation
dim1 = dim * decorator_factor;
dim2 = dim * decorator_factor;
dim3 = 0.02;
offset = [0, 0, dim/2];
}
generate_geometry(mesh, dim1, dim2, dim3, offset, sides, color);
/*
if scaling should be applied
this means that bars between the nodes are introduced into the visualisation
*/
if(cube.d != "orange" && scale_factor != 1.0)
{
if(check_coordinate_exists(coordinates_matrix, cube.fx + 1, cube.fy, cube.fz) && coordinates_matrix[cube.fx + 1][cube.fy][cube.fz] != -1)
{
offset = [(dim + dim1*(1/scale_factor))/2, 0, 0];
generate_geometry(mesh, dim1*(1/scale_factor), dim2, dim3, offset, sides, color);
}
if(check_coordinate_exists(coordinates_matrix, cube.fx, cube.fy + 1, cube.fz) && coordinates_matrix[cube.fx][cube.fy + 1][cube.fz] != -1)
{
offset = [0, (dim + dim2*(1/scale_factor))/2, 0];
generate_geometry(mesh, dim1, dim2*(1/scale_factor), dim3, offset, sides, color);
}
if(check_coordinate_exists(coordinates_matrix, cube.fx, cube.fy, cube.fz + 1) && coordinates_matrix[cube.fx][cube.fy][cube.fz + 1] != -1)
{
offset = [0, 0, (dim + dim3*(1/scale_factor))/2];
generate_geometry(mesh, dim1, dim2, dim3*(1/scale_factor), offset, sides, color);
}
}
return mesh;
}
);
counterOnChange();
</script>
</body>