From b47f849cb7393ce26029439bb82b29d9b6a58627 Mon Sep 17 00:00:00 2001 From: Ross Keenan Date: Sun, 8 Aug 2021 16:53:18 +0200 Subject: [PATCH] feat(Vis View): :sparkles: Proof of Concept of hierarchy!!! --- src/VisModal.ts | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/src/VisModal.ts b/src/VisModal.ts index d7dd9d73..d8e5aefa 100644 --- a/src/VisModal.ts +++ b/src/VisModal.ts @@ -127,18 +127,58 @@ export function bfsAdjList(g: Graph, startNode: string): AdjListItem[] { }; queue.push(succ); adjList.push(next); +export function dfsFlatAdjList(g: Graph, startNode: string) { + const nodes = g.nodes(); + const nodeCount = nodes.length; + const visits = {}; + nodes.forEach((node, i) => { + visits[node] = nodeCount * i; + }); + + const queue: string[] = [startNode]; + const adjList: AdjListItem[] = []; + + let i = 0; + while (queue.length && i < 1000) { + i++; + + const currNode = queue.shift(); + const neighbours = { + succs: g.successors(currNode) as string[], + // pres: g.predecessors(currNode) as string[], + }; + if (neighbours.succs.length) { + queue.unshift(...neighbours.succs); + neighbours.succs.forEach((succ, j) => { + visits[currNode] += j + 1; + adjList.push({ + id: visits[currNode] as number, + name: currNode, + parentId: (visits[succ] + 1) as number, + depth: i, + }); }); } else { + visits[currNode]++; adjList.push({ + id: visits[currNode] as number, name: currNode, - parentId: undefined, + parentId: 999999999, depth: i, }); } } + adjList.push({ + id: 999999999, + name: "CONTAINER", + parentId: undefined, + depth: i + 1, + }); + const maxDepth = adjList.sort((a, b) => a.depth - b.depth).last().depth; adjList.forEach((item) => (item.height = maxDepth - item.depth)); + console.log({ visits }); return adjList; }