summaryrefslogtreecommitdiff
path: root/src/graph.js
diff options
context:
space:
mode:
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();
}