Skip to content

Commit

Permalink
Update graph.js
Browse files Browse the repository at this point in the history
  • Loading branch information
imaitland authored Feb 7, 2024
1 parent 6be733e commit 28da0a0
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions js/graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ const Graph = ForceGraph()(document.getElementById("graph"))
d.source.tag;
})
.onNodeClick(async (node) => {
// Store last clicked in local storage
localStorage.setItem('lastClickedNode', JSON.stringify(node));

if (node.id == "day") {
document.getElementsByClassName("logo")[0].style.color = "black";

Expand Down Expand Up @@ -107,6 +110,16 @@ const Graph = ForceGraph()(document.getElementById("graph"))
//const rootNode = graph_data.nodes.find((node)=>{return node.id === "about"})
//Graph.centerAt(rootNode.x, rootNode.y, 1000);
//Graph.zoom(8, 2000);
const lastClickedNode = JSON.parse(localStorage.getItem('lastClickedNode'));
if (lastClickedNode) {
console.log('Last clicked node:', lastClickedNode.id);
Graph.centerAt(lastClickedNode.x, lastClickedNode.y, 1000);
Graph.zoom(8, 2000);
} else {
const rootNode = graph_data.nodes.find((node)=>{return node.id === "about"})
Graph.centerAt(rootNode.x, rootNode.y, 1000);
Graph.zoom(8, 2000);
}
})

// Contain nodes to a box.
Expand Down

0 comments on commit 28da0a0

Please sign in to comment.