Skip to content

Commit

Permalink
refactor(Vis View): ♻️ Disable path finding in ForceDirectedG for now
Browse files Browse the repository at this point in the history
  • Loading branch information
SkepticMystic committed Nov 17, 2021
1 parent 304c9ba commit 8593325
Showing 1 changed file with 45 additions and 46 deletions.
91 changes: 45 additions & 46 deletions src/Visualisations/ForceDirectedG.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as d3 from "d3";
import type Graph from "graphology";
import * as graphlib from "graphlib";
import { openOrSwitch } from "src/sharedFunctions";
import type { d3Node } from "src/interfaces";
import { graphlibToD3, VisModal } from "src/VisModal";
Expand All @@ -19,7 +18,7 @@ export const forceDirectedG = (
console.log({ nodeToGetTo });

console.time("Find all paths");
let pathsFromNodeToGetTo = graphlib.alg.dijkstra(graph, nodeToGetTo);
// let pathsFromNodeToGetTo = graphlib.alg.dijkstra(graph, nodeToGetTo);
console.timeEnd("Find all paths");

const defaultNodeColour = getComputedStyle(document.body).getPropertyValue(
Expand Down Expand Up @@ -193,7 +192,7 @@ export const forceDirectedG = (
} else return currNodeColour;
});

pathsFromNodeToGetTo = graphlib.alg.dijkstra(graph, nodeToGetTo);
// pathsFromNodeToGetTo = graphlib.alg.dijkstra(graph, nodeToGetTo);
}
});

Expand All @@ -208,26 +207,26 @@ export const forceDirectedG = (
return !!linkedArr;
}

function walkDijkstraPaths(
paths: { [node: string]: graphlib.Path },
startNode: string
) {
if (startNode === nodeToGetTo || paths[startNode].distance === Infinity)
return [];
let step = startNode;

const path: string[] = [startNode];
let i = 0;
const MAX = 300;
while (paths[step].predecessor !== nodeToGetTo && i < MAX) {
i++;
step = paths[step].predecessor;
path.push(step);
}
if (i >= MAX) return [];
path.push(nodeToGetTo);
return path;
}
// function walkDijkstraPaths(
// paths: { [node: string]: graphlib.Path },
// startNode: string
// ) {
// if (startNode === nodeToGetTo || paths[startNode].distance === Infinity)
// return [];
// let step = startNode;

// const path: string[] = [startNode];
// let i = 0;
// const MAX = 300;
// while (paths[step].predecessor !== nodeToGetTo && i < MAX) {
// i++;
// step = paths[step].predecessor;
// path.push(step);
// }
// if (i >= MAX) return [];
// path.push(nodeToGetTo);
// return path;
// }

node
.on("mouseover", (event: MouseEvent, d: { index: number }) => {
Expand All @@ -248,30 +247,30 @@ export const forceDirectedG = (

// Highlight path from hovered node to currNode
const hoveredNode = nameFromIndex(d);
const path = walkDijkstraPaths(pathsFromNodeToGetTo, hoveredNode);
if (path.length) {
link
.transition()
.duration(150)
.style("stroke", function (link) {
if (
path.includes(nameFromIndex(link.source)) &&
path.includes(nameFromIndex(link.target))
)
return currNodeColour;
})
.style("opacity", function (link) {
if (
path.includes(nameFromIndex(link.source)) &&
path.includes(nameFromIndex(link.target))
)
return 1;
});
}
// const path = walkDijkstraPaths(pathsFromNodeToGetTo, hoveredNode);
// if (path.length) {
// link
// .transition()
// .duration(150)
// .style("stroke", function (link) {
// if (
// path.includes(nameFromIndex(link.source)) &&
// path.includes(nameFromIndex(link.target))
// )
// return currNodeColour;
// })
// .style("opacity", function (link) {
// if (
// path.includes(nameFromIndex(link.source)) &&
// path.includes(nameFromIndex(link.target))
// )
// return 1;
// });
// }
})
.on("mouseout", unfocus);

function focusNeighbours(d, event: MouseEvent) { }
function focusNeighbours(d, event: MouseEvent) {}

function unfocus() {
// labelNode.attr("display", "block");
Expand Down Expand Up @@ -305,7 +304,7 @@ export const forceDirectedG = (
);

function saveGraph() {
const clone = svg.clone(true)
localStorage.setItem('FDG', JSON.stringify(clone))
const clone = svg.clone(true);
localStorage.setItem("FDG", JSON.stringify(clone));
}
};

0 comments on commit 8593325

Please sign in to comment.