Skip to content
Snippets Groups Projects
Commit 114efd93 authored by Matthias Konitzny's avatar Matthias Konitzny :fire:
Browse files

Optimized node access via node ids.

parent e209da5c
No related branches found
No related tags found
No related merge requests found
...@@ -7,6 +7,7 @@ class Graph { ...@@ -7,6 +7,7 @@ class Graph {
this.highlightLinks = new Set(); this.highlightLinks = new Set();
this.hoverNode = null; this.hoverNode = null;
this.edgeColors = {}; this.edgeColors = {};
this.idToNode = {};
this.firstTick = true; this.firstTick = true;
this.infooverlay = null; this.infooverlay = null;
...@@ -46,6 +47,7 @@ class Graph { ...@@ -46,6 +47,7 @@ class Graph {
if (this.firstTick) { if (this.firstTick) {
this.mapEdgeColors(); this.mapEdgeColors();
this.updateLinks(); this.updateLinks();
this.updateNodeMap();
this.addBackground(); this.addBackground();
// Catch resize events // Catch resize events
...@@ -107,6 +109,10 @@ class Graph { ...@@ -107,6 +109,10 @@ class Graph {
} }
focusOnNode(node) { focusOnNode(node) {
if (typeof node == "string") {
node = this.idToNode[node];
}
// Aim at node from outside it // Aim at node from outside it
const distance = 250; const distance = 250;
const distRatio = 1 + distance/Math.hypot(node.x, node.y, node.z); const distRatio = 1 + distance/Math.hypot(node.x, node.y, node.z);
...@@ -118,18 +124,8 @@ class Graph { ...@@ -118,18 +124,8 @@ class Graph {
); );
} }
focusOnNodeId(id) {
const gData = this.graph.graphData();
gData.nodes.forEach(node => {
if (node.id === id) {
this.onNodeClick(node);
}
})
}
updateLinks() { updateLinks() {
const gData = this.graph.graphData() const gData = this.graph.graphData();
// cross-link node objects // cross-link node objects
gData.links.forEach(link => { gData.links.forEach(link => {
const a = link.source; const a = link.source;
...@@ -155,6 +151,13 @@ class Graph { ...@@ -155,6 +151,13 @@ class Graph {
.linkDirectionalParticles(this.graph.linkDirectionalParticles()); .linkDirectionalParticles(this.graph.linkDirectionalParticles());
} }
updateNodeMap() {
const gData = this.graph.graphData();
gData.nodes.forEach(node => {
this.idToNode[node.id] = node;
})
}
resize() { resize() {
if(document.fullscreenElement == getCanvasDivNode()) { if(document.fullscreenElement == getCanvasDivNode()) {
this.graph.height(screen.height); this.graph.height(screen.height);
......
...@@ -149,7 +149,7 @@ class InfoOverlay { ...@@ -149,7 +149,7 @@ class InfoOverlay {
//linkButton.appendChild(linkTitle); //linkButton.appendChild(linkTitle);
linkButton.appendChild(linkImage); linkButton.appendChild(linkImage);
linkButton.addEventListener('click', function (){focusOnNodeId(nodeID)}); jQuery(linkButton).on('click', () => this.graph.focusOnNode(nodeID));
tabcontent[i].appendChild(linkButton); tabcontent[i].appendChild(linkButton);
} }
}); });
......
...@@ -11,8 +11,8 @@ function ks_add_graph(): string ...@@ -11,8 +11,8 @@ function ks_add_graph(): string
{ {
$graph = '<script src="//unpkg.com/3d-force-graph"></script>'; $graph = '<script src="//unpkg.com/3d-force-graph"></script>';
$three = '<script src="//unpkg.com/three@0.130.0"></script>'; $three = '<script src="//unpkg.com/three@0.130.0"></script>';
$renderer = '<script src="//unpkg.com/three/examples/js/renderers/CSS2DRenderer.js"></script>'; $renderer = '<script src="//unpkg.com/three@0.130.0/examples/js/renderers/CSS2DRenderer.js"></script>';
$renderer2 = '<script src="//unpkg.com/three/examples/js/renderers/CSS3DRenderer.js"></script>'; $renderer2 = '<script src="//unpkg.com/three@0.130.0/examples/js/renderers/CSS3DRenderer.js"></script>';
$div = '<div id="3d-graph"></div>'; $div = '<div id="3d-graph"></div>';
$plugin_dir = plugin_dir_url(__FILE__); $plugin_dir = plugin_dir_url(__FILE__);
//$dataset = $plugin_dir.'datasets/miserables.json'; //$dataset = $plugin_dir.'datasets/miserables.json';
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment