summaryrefslogtreecommitdiff
path: root/src/graph.js
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2021-08-24 19:07:19 +0200
committerJules Laplace <julescarbon@gmail.com>2021-08-24 19:07:19 +0200
commitf31ed7d781fb36d9b4debe7287b11badd8d7f75a (patch)
tree86eea18af825e0a3aced428a1679e9c4bf04350c /src/graph.js
parent1cc630da4247e75a18629d960768d06239b0175b (diff)
add legend, filter visible nodes
Diffstat (limited to 'src/graph.js')
-rw-r--r--src/graph.js31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/graph.js b/src/graph.js
index 4ed953a..640b42e 100644
--- a/src/graph.js
+++ b/src/graph.js
@@ -102,6 +102,34 @@ export default function buildGraph(db, handlers) {
})
.onNodeClick(handlers.click);
+ const handleSelect = (category) => {
+ if (!category) {
+ graph.graphData(data);
+ return;
+ }
+ const { nodes, links } = data;
+ const visible = new Set();
+
+ const selectedData = {};
+ selectedData.nodes = nodes.filter((node) => {
+ for (let tagIndex = 0; tagIndex < 8; tagIndex += 1) {
+ const group = node.data["tag_" + tagIndex];
+ if (!group) continue;
+ if (group === category) {
+ visible.add(node.id);
+ return true;
+ }
+ }
+ return false;
+ });
+ selectedData.links = links.filter((link) => {
+ const { source, target } = link;
+ return visible.has(source.id) && visible.has(target.id);
+ });
+ console.log(selectedData);
+ graph.graphData(selectedData);
+ };
+
// graph.d3Force("charge").strength(-150);
// camera orbit
@@ -112,6 +140,9 @@ export default function buildGraph(db, handlers) {
z: distance * Math.cos(angle),
});
+ return {
+ onSelect: handleSelect,
+ };
// stars();
}