-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
491 lines (458 loc) · 16.6 KB
/
index.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
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
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1 user-scalable=no" />
<title>GRAPH</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Roboto+Mono:wght@500&display=swap" rel="stylesheet">
<style type="text/css">
body, html {
touch-action: none;
user-select: none;
margin: 0;
padding: 0;
height: 100%;
overflow: hidden;
font-family: "Roboto Mono", monospace;
}
a {
color: #002FA7;
}
a:visited {
color: #000B67;
}
#graph-canvas {
position:absolute;
width: 100%;
height: 100%;
}
#table-outer-container {
position: absolute;
display: flex;
flex-direction: column;
left: 0;
right: 0;
top: 0;
margin: auto;
width: 320px;
height: 75%;
background-color: rgba(210, 210, 210, 0.7);
z-index: 2;
}
#table-min-max-button {
height: 16px;
flex: initial;
background-color: rgba(190, 190, 190, 0.7);
border: 1px solid #999;
text-align: center;
}
#table-min-max-button>svg {
padding: 1.2%;
height: 45%;
fill: #555;
margin: 0 auto;
}
table-min-max-button:hover {
background-color: rgba(190, 190, 190, 1);
}
#table-search-container {
height: 20px;
flex: initial;
padding: 16px 45px 6px 40px;
}
#table-search-container>input {
width: 100%;
font-size: 1em;
}
#table-inner-container {
flex-grow: 1;
overflow-x: clip;
overflow-y: scroll;
}
table {
width: 100%;
margin: 0.5em;
font-size: 1em;
}
.focus-button {
margin: 0 0.4em 0 0;
padding: 0.2em 0.3em 0 0.3em;
font-size: 1.6em;
color: #522;
}
.focus-button:hover {
background-color: rgba(190, 190, 190, 1);
}
#zoom-container {
position: absolute;
right: 0;
bottom: 0;
margin: 0 0 1em 0;
z-index: 4;
}
.zoom-button {
margin-right: 0.2em;
font-size: 1.8em;
float: right;
fill: #999;
stroke-width: 3;
stroke: #222;
}
.zoom-button:hover {
fill: #ccc;
stroke: #444;
}
.node-link {
background-color: rgba(210, 210, 210, 0.7);
z-index: 1;
overflow-wrap: normal;
font-size: 0.9em;
}
#about-link {
background-color: rgba(210, 210, 210, 0.7);
padding: 0 0.2em;
float: right;
position: relative;
font-family: serif;
text-decoration: none;
margin: 0.2em 0.4em 0 0;
z-index: 2;
font-size: 1.8em;
}
</style>
<script src="webgl-utils.js"></script>
</head>
<body>
<code id="my-log"></code>
<a id="about-link" href="/about.html"><em>i</em></a>
<canvas id="graph-canvas"></canvas>
<div id="table-outer-container" style="height: auto">
<div id="table-min-max-button">
<svg viewBox="0 0 20 10" height="1em" id="table-max-graphic" >
<g><path d="M 0,0 10,10 20,0 Z"/></g>
</svg>
<svg viewBox="0 0 20 10" height="1em" style="display: none;" id="table-min-graphic">
<g><path d="M 0,10 10,0 20,10 Z"/></g>
</svg>
</div>
<div id="table-search-container" style="display: none;">
<input type="search" name="search" placeholder="search"/>
</div>
<div id="table-inner-container" style="display: none;">
<table>
<tbody id="table-body"></tbody>
</table>
</div>
</div>
<div id="zoom-container">
<svg class="zoom-button" id="zoom-in-button" height="1em" viewBox="0 0 50 50">
<g>
<path d="M 25 5 A 20 20 0 0 0 5 25 A 20 20 0 0 0 25 45 A 20 20 0 0 0 45 25 A 20 20 0 0 0 25 5 z M 22 11 L 28 11 L 28 22 L 39 22 L 39 28 L 28 28 L 28 39 L 22 39 L 22 28 L 11 28 L 11 22 L 22 22 L 22 11 z" />
</g>
</svg>
<svg class="zoom-button" id="zoom-out-button" height="1em" viewBox="0 0 50 50">
<g>
<path
d="M 25 5 A 20 20 0 0 0 5 25 A 20 20 0 0 0 25 45 A 20 20 0 0 0 45 25 A 20 20 0 0 0 25 5 z M 11 22 L 39 22 L 39 28 L 11 28 L 11 22 z" />
</g>
</svg>
</div>
<script type="module" defer>
const accountsData = [];
const nodeLocations = [];
const tableBody = document.getElementById("table-body");
const createLink = (text, url) => {
const anchor = document.createElement("a");
const textNode = document.createTextNode(text);
anchor.appendChild(textNode);
anchor.href = url;
anchor.target = '_blank';
return anchor
};
const addRow = (rank, text, url) => {
const row = document.createElement("tr");
const rankData = document.createElement("td");
rankData.textContent = rank;
row.appendChild(rankData);
const linkData = document.createElement("td");
const link = createLink(text, url);
linkData.appendChild(link);
row.appendChild(linkData);
const focusBtnData = document.createElement("td");
const focusBtn = document.createElement("div");
focusBtn.textContent = "*";
focusBtn.className = "focus-button";
focusBtn.title = `Center on ${text}`;
focusBtnData.appendChild(focusBtn);
row.appendChild(focusBtnData);
tableBody.appendChild(row);
};
const resp = await fetch("./nodes.json");
const data = await resp.json();
data.forEach(node => {
const url = `https://instagram.com/${node.username}`
let name;
if (node.name !== '') {
name = node.name;
} else {
name = node.username;
}
addRow(node.rank, name, url);
const nodeID = node.rank - 1;
accountsData.push({name: name, url: url});
nodeLocations.push(node.x, node.y)
});
const tableMinMaxRate = 7.5;
const canvas = document.getElementById("graph-canvas");
const tableOuter = document.getElementById("table-outer-container");
const tableInner = document.getElementById("table-inner-container");
const tableSearch = document.getElementById("table-search-container");
const tableMinMaxButton = document.getElementById("table-min-max-button");
const tableMinGraphic = document.getElementById("table-min-graphic");
const tableMaxGraphic = document.getElementById("table-max-graphic");
let tableMaximised = 0.0;
let tableMaximising = false;
let tableMinimising = false;
const minimiseTable = () => {
if (tableMaximised === 1.0) {
tableMinimising = true;
tableInner.style["display"] = "none";
tableSearch.style["display"] = "none";
tableOuter.style["height"] = "auto";
//tableMinMaxButton.style["height"] = "100%";
}
};
const maximiseTable = () => {
if (tableMaximised === 0.0) {
tableMaximising = true;
}
};
const updateTablePosition = deltaTime => {
if (tableMaximising && tableMaximised !== 1.0) {
tableMaximised += tableMinMaxRate * deltaTime;
if (tableMaximised >= 1.0) {
tableMaximised = 1.0;
tableMaximising = false;
tableSearch.style["display"] = "block";
tableInner.style["display"] = "block";
tableOuter.style["height"] = "75%";
//tableMinMaxButton.style["height"] = "20px";
tableMinGraphic.style["display"] = "block";
tableMaxGraphic.style["display"] = "none";
}
tableOuter.style["top"] = `${12.5*tableMaximised}%`;
} else if (tableMinimising && tableMaximised !== 0.0) {
tableMaximised -= tableMinMaxRate * deltaTime;
if (tableMaximised <= 0.0) {
tableMaximised = 0.0;
tableMinimising = false;
tableMinGraphic.style["display"] = "none";
tableMaxGraphic.style["display"] = "block";
}
tableOuter.style["top"] = `${12.5*tableMaximised}%`;
}
}
tableMinMaxButton.addEventListener("click", e => {
if (tableMaximised === 1.0) {
minimiseTable();
} else if (tableMaximised == 0.0) {
maximiseTable();
}
});
canvas.addEventListener("mousedown", e => {minimiseTable()});
import init, { init_logging, get_memory, GraphFacade, TouchSet } from "./pkg/rust_wasm_centrality.js";
init().then(async () => {
init_logging();
let edgeCount = 0;
const wasmMemory = get_memory();
const nodeCount = accountsData.length;
const locsArray = new Float32Array(nodeLocations);
const displayScale = 0.0011;
const autopanRate = 2048.0;
const focusNodeIdx = 0;
const graph = GraphFacade.new(nodeCount, locsArray,
window.innerWidth, window.innerHeight,
displayScale, autopanRate, focusNodeIdx);
document.querySelectorAll("tr").forEach(row => {
const nodeID = parseInt(row.children[0].textContent) - 1
const focusBtn = row.children[2].children[0];
focusBtn.onclick = () => {
graph.autopan(nodeID);
};
});
const searchInput = document.querySelector("input");
searchInput.addEventListener("input", e => {
document.querySelectorAll("tr").forEach(row => {
const searchTerm = e.target.value.toUpperCase();
const nodeText = row.children[1].textContent.toUpperCase();
if (nodeText.indexOf(searchTerm) !== -1) {
row.style["display"] = "table-row"
} else {
row.style["display"] = "none"
}
});
});
const touchMoveMulti = 3;
let dragging = false;
canvas.addEventListener("mousedown", e => {dragging = true;});
const stopDragging = e => {dragging = false};
canvas.addEventListener("mouseup", stopDragging);
canvas.addEventListener("mouseleave", stopDragging);
canvas.addEventListener("mousemove", e => {
if (dragging) {
graph.pan(-e.movementX, e.movementY);
}
});
canvas.addEventListener('wheel', (e) => {
if (e.deltaY < 0) {
graph.zoom_in();
}
else {
graph.zoom_out();
}
minimiseTable();
});
document.getElementById("zoom-in-button").addEventListener("click",
e => graph.zoom_in()
);
document.getElementById("zoom-out-button").addEventListener("click",
e => graph.zoom_out()
);
const makeTouchSet = touches => {
const locs = [];
const ids = [];
for (const touch of touches) {
locs.push(touch.pageX, touch.pageY);
ids.push(touch.identifier);
}
const locsArr = new Float32Array(locs);
const idsArr = new Int32Array(ids);
return TouchSet.new(locsArr, idsArr);
}
canvas.addEventListener("touchstart", e => {
graph.touch_start(makeTouchSet(event.touches));
minimiseTable();
});
canvas.addEventListener("touchmove", e => {
graph.touch_move(makeTouchSet(event.touches));
});
const gl = canvas.getContext("webgl");
if (!gl) {
window.setInterval(() => {
updateTablePosition(0.05)
}, 50);
document.getElementById("zoom-container").remove();
document.querySelectorAll('.focus-button').forEach(e => e.remove());
canvas.remove()
alert("Unable to render graph; your browser does not support WebGL. Feel free to browse the table.");
maximiseTable();
return
}
webglUtils.resizeCanvasToDisplaySize(gl.canvas);
const vertexSrc = `
attribute vec2 a_position;
void main() {
gl_Position = vec4(a_position, 0.0, 1.0);
}
`
const fragmentSrc = `
precision mediump float;
void main() {
gl_FragColor = vec4(0, 0, 0, 1);
}
`
const program = webglUtils.createProgramFromSources(gl,[vertexSrc, fragmentSrc]);
const positionAttrLoc = gl.getAttribLocation(program, "a_position");
const positionBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);
const indexBuffer = gl.createBuffer();
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, indexBuffer);
let prevFrameTime = 0;
const renderFrame = (now) => {
webglUtils.resizeCanvasToDisplaySize(gl.canvas);
const deltaTime = (now - prevFrameTime) / 1000;
updateTablePosition(deltaTime);
gl.viewport(0, 0, canvas.width, canvas.height);
gl.clearColor(0, 0, 0, 0);
gl.clear(gl.COLOR_BUFFER_BIT);
gl.useProgram(program);
gl.enableVertexAttribArray(positionAttrLoc);
graph.update_display_size(window.innerWidth, window.innerHeight);
graph.update_clipspace_vertices(deltaTime);
graph.update_edges();
const nodePageLocations = graph.get_visible_node_page_locations();
document.querySelectorAll('.node-link').forEach(link => {
const accountId = parseInt(link.id.substring(1));
if (!nodePageLocations.has(accountId)) {
link.remove();
};
});
nodePageLocations.forEach((loc, accountId) => {
const data = accountsData[accountId];
let link = document.querySelector(`#a${accountId}.node-link`);
if (link == undefined) {
link = createLink(data.name, data.url);
link.className = 'node-link';
link.id = `a${accountId}`;
link.style.position = 'absolute';
document.body.appendChild(link);
}
link.style.left = `${loc.x}px`;
link.style.top = `${loc.y}px`;
});
// Load vertex positions
const verticesPtr = graph.get_vertices_ptr();
const vertices = new Float32Array(wasmMemory.buffer,
verticesPtr,
nodeCount * 2);
gl.bufferData(gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW);
gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);
// Tell GL how to unpack positionBuffer
const size = 2;
const type = gl.FLOAT;
const normalize = false;
const stride = 0;
const unpackOffset = 0;
gl.vertexAttribPointer(positionAttrLoc, size, type,
normalize, stride, unpackOffset);
// Tell GL to draw edge lines from indices
const offset = 0;
const count = edgeCount * 2;
const indexType = gl.UNSIGNED_SHORT;
gl.drawElements(gl.LINES, count, indexType, offset);
prevFrameTime = now;
};
const updateEdgeBuffer = () => {
const vertexIndicesLen = graph.get_vertex_indices_len();
edgeCount = vertexIndicesLen / 2;
const vertexIndicesPtr = graph.get_vertex_indices_ptr();
const vertexIndices = new Int16Array(wasmMemory.buffer,
vertexIndicesPtr,
vertexIndicesLen);
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, vertexIndices, gl.STATIC_DRAW);
};
const renderFrameWithEdgeBuffer = (now) => {
renderFrame();
updateEdgeBuffer();
};
const renderLoop = (now) => {
renderFrame(now);
requestAnimationFrame(renderLoop);
};
fetch("./targets.bin")
.then(async response => {
const respReader = response.body.getReader();
while(true) {
const {done, value} = await respReader.read();
if (done && value === undefined) {break;}
graph.load_edges(value);
renderFrameWithEdgeBuffer();
}
renderLoop();
});
});
</script>
</body>
</html>