summaryrefslogtreecommitdiff
path: root/src/index.js
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2021-08-16 16:26:01 +0200
committerJules Laplace <julescarbon@gmail.com>2021-08-16 16:26:01 +0200
commitbf563861320cf207bb2d788f50b327e4eb37016a (patch)
tree7e775216592e1f935fd9a10a6cf59f84c789f7c9 /src/index.js
parent9ae202820b698796f93b929b3e30cd499de796a1 (diff)
showing a graph
Diffstat (limited to 'src/index.js')
-rw-r--r--src/index.js56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/index.js b/src/index.js
new file mode 100644
index 0000000..6cc83e4
--- /dev/null
+++ b/src/index.js
@@ -0,0 +1,56 @@
+/**
+ * No.6092 site for Charles Stankievech
+ * - load db.json
+ * - map the nodes to a graph
+ * - click the nodes to open them
+ * - some of the nodes are images, others are 3D
+ */
+
+import ForceGraph3D from "3d-force-graph";
+
+async function main() {
+ const db = await loadDB();
+
+ const trees = {};
+ const data = { nodes: [], links: [] };
+
+ console.log(db);
+
+ db.page.forEach((item, index) => {
+ data.nodes.push({
+ id: index,
+ });
+ for (let tagIndex = 0; tagIndex < 8; tagIndex += 1) {
+ const value = item["tag_" + tagIndex];
+ if (value) {
+ if (value in trees) {
+ data.links.push({
+ source: choice(trees[value]),
+ target: index,
+ });
+ // don't link to the root node more than once!
+ if (trees[value][0]) {
+ trees[value].push(index);
+ } else {
+ trees[value] = [index];
+ }
+ } else {
+ trees[value] = [index];
+ }
+ }
+ }
+ });
+
+ let graph = ForceGraph3D();
+ graph(document.querySelector("#graph")).graphData(data);
+}
+
+const randint = (limit) => Math.floor(Math.random() * limit);
+const choice = (list) => list[randint(list.length)];
+
+async function loadDB() {
+ const request = await fetch("/db.json");
+ return await request.json();
+}
+
+main();