summaryrefslogtreecommitdiff
path: root/src/graph.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/graph.js')
-rw-r--r--src/graph.js28
1 files changed, 27 insertions, 1 deletions
diff --git a/src/graph.js b/src/graph.js
index 7381f49..880caab 100644
--- a/src/graph.js
+++ b/src/graph.js
@@ -63,6 +63,11 @@ export default function buildGraph({ db, objects, handlers }) {
const a = data.nodes[link.source];
const b = data.nodes[link.target];
+ !a.neighbors && (a.neighbors = []);
+ !b.neighbors && (b.neighbors = []);
+ a.neighbors.push(b);
+ b.neighbors.push(a);
+
!a.links && (a.links = []);
!b.links && (b.links = []);
a.links.push(link);
@@ -122,7 +127,23 @@ export default function buildGraph({ db, objects, handlers }) {
return sprite;
}
})
- .onNodeClick(handlers.click);
+ .onNodeClick((node) => {
+ // no state change
+ if (!node && !highlightNodes.size) return;
+
+ highlightNodes.clear();
+ highlightLinks.clear();
+ if (node) {
+ highlightNodes.add(node);
+ node.neighbors.forEach((neighbor) => highlightNodes.add(neighbor));
+ node.links.forEach((link) => highlightLinks.add(link));
+ }
+
+ updateHighlight();
+
+ handlers.click(node);
+ })
+ .linkWidth((link) => (highlightLinks.has(link) ? 4 : 1));
// TrackballControls
graph.controls().addEventListener("change", () => {
@@ -130,6 +151,11 @@ export default function buildGraph({ db, objects, handlers }) {
// console.log(position);
});
+ const updateHighlight = () => {
+ // trigger update of highlighted objects in scene
+ graph.linkWidth(graph.linkWidth());
+ };
+
const initialZoom = () => {
const distance = 20000;
let angle = 0;