Skip to content

Commit

Permalink
feat(Vis View): ✨ Better dfsFlatAdjList
Browse files Browse the repository at this point in the history
This version dpoesn't add duplicates, and it does depth more accurately
  • Loading branch information
SkepticMystic committed Aug 10, 2021
1 parent 935d8fc commit cbe3182
Showing 1 changed file with 27 additions and 26 deletions.
53 changes: 27 additions & 26 deletions src/VisModal.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
import * as d3 from "d3";
import type { Graph } from "graphlib";
import { App, Modal, Notice } from "obsidian";
import type { AdjListItem, d3Graph, d3Tree, visTypes } from "src/interfaces";
import type { AdjListItem, d3Graph, d3Tree } from "src/interfaces";
import type BreadcrumbsPlugin from "src/main";
import { arcDiagram } from "src/Visualisations/ArcDiagram";
import { circlePacking } from "src/Visualisations/CirclePacking";
import { edgeBundling } from "src/Visualisations/EdgeBundling";
import { forceDirectedG } from "src/Visualisations/ForceDirectedG";
import { icicle } from "src/Visualisations/Icicle";
import { sunburst } from "src/Visualisations/Sunburst";
import { tidyTree } from "src/Visualisations/TidyTree";
import { treeMap } from "src/Visualisations/TreeMap";
import VisComp from "./Components/VisComp.svelte";

export function graphlibToD3(g: Graph): d3Graph {
Expand Down Expand Up @@ -148,41 +140,50 @@ export function dfsFlatAdjList(g: Graph, startNode: string) {
const queue: string[] = [startNode];
const adjList: AdjListItem[] = [];

let depth = 1;
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) => {
visits[currNode]++;
adjList.push({
id: visits[currNode] as number,
name: currNode,
parentId: (visits[succ] + 1) as number,
depth: i,
});
const next = g.successors(currNode) as string[];

if (next.length) {
queue.unshift(...next);
next.forEach((succ) => {
const parentId = nodeCount * nodes.indexOf(succ);
if (
!adjList.some(
(adjItem) =>
adjItem.name === currNode && adjItem.parentId === parentId
)
) {
adjList.push({
id: visits[currNode] as number,
name: currNode,
parentId,
depth,
});
visits[currNode]++;
}
});
depth++;
} else {
visits[currNode]++;
adjList.push({
id: visits[currNode] as number,
name: currNode,
parentId: 999999999,
depth: i,
depth,
});
depth = 1;
visits[currNode]++;
}
}
adjList.push({
id: 999999999,
name: "CONTAINER",
parentId: undefined,
depth: i + 1,
depth: 0,
});

const maxDepth = adjList.sort((a, b) => a.depth - b.depth).last().depth;
Expand Down

0 comments on commit cbe3182

Please sign in to comment.