From 4d6a6f0fd58f25070a7cf819be8cb46d3ee83719 Mon Sep 17 00:00:00 2001 From: Ross Keenan Date: Sun, 15 Aug 2021 18:41:12 +0200 Subject: [PATCH] fix(Vis View): :bug: Force Directed Graph: Path finding wasn't working correctly, oops --- src/Visualisations/ForceDirectedG.ts | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/Visualisations/ForceDirectedG.ts b/src/Visualisations/ForceDirectedG.ts index 6a19be80..93a3389f 100644 --- a/src/Visualisations/ForceDirectedG.ts +++ b/src/Visualisations/ForceDirectedG.ts @@ -195,22 +195,21 @@ export const forceDirectedG = ( paths: { [node: string]: graphlib.Path }, startNode: string ) { - if ( - startNode === currFile.basename || - paths[startNode].distance === Infinity - ) + const currFileName = currFile.basename; + if (startNode === currFileName || paths[startNode].distance === Infinity) return []; let step = startNode; const path: string[] = [startNode]; let i = 0; - while (paths[step].distance > 1 && i < 200) { + const MAX = 300; + while (paths[step].predecessor !== currFileName && i < MAX) { i++; - step = paths[startNode].predecessor; + step = paths[step].predecessor; path.push(step); } - if (i >= 200) return []; - path.push(currFile.basename); + if (i >= MAX) return []; + path.push(currFileName); return path; }