Skip to content

Graphs that teach > graphs that impress. Turn any code into an interactive knowledge graph you can explore, search, and ask questions about. Works with Claude Code, Codex, Cursor, Copilot, Gemini CLI, and more.

feat(dashboard): overview view uses ELK

Lum11040b18a84014d9
diff --git a/understand-anything-plugin/packages/dashboard/src/components/GraphView.tsx b/understand-anything-plugin/packages/dashboard/src/components/GraphView.tsx
index aa75f09c..55c56351 100644
--- a/understand-anything-plugin/packages/dashboard/src/components/GraphView.tsx
+++ b/understand-anything-plugin/packages/dashboard/src/components/GraphView.tsx
@@ -1,4 +1,4 @@
-import { useCallback, useEffect, useMemo, useRef } from "react";
+import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import {
ReactFlow,
ReactFlowProvider,
@@ -31,7 +31,10 @@ import {
LAYER_CLUSTER_HEIGHT,
PORTAL_NODE_WIDTH,
PORTAL_NODE_HEIGHT,
+ nodesToElkInput,
+ mergeElkPositions,
} from "../utils/layout";
+import { applyElkLayout } from "../utils/elk-layout";
import {
aggregateLayerEdges,
computePortals,
@@ -127,11 +130,17 @@ function useOverviewGraph() {
const searchResults = useDashboardStore((s) => s.searchResults);
const drillIntoLayer = useDashboardStore((s) => s.drillIntoLayer);
- return useMemo(() => {
- if (!graph) return { nodes: [] as Node[], edges: [] as Edge[] };
-
+ // Build cluster nodes / flow edges / dims synchronously; only the layout
+ // call itself is async, so we memo the structural pieces and run ELK in an
+ // effect.
+ const built = useMemo(() => {
+ if (!graph) {
+ return null;
+ }
const layers = graph.layers ?? [];
- if (layers.length === 0) return { nodes: [] as Node[], edges: [] as Edge[] };
+ if (layers.length === 0) {
+ return null;
+ }
// Build search match counts per layer
const searchMatchByLayer = new Map<string, number>();
@@ -199,9 +208,43 @@ function useOverviewGraph() {
for (const n of clusterNodes) {
dims.set(n.id, { width: LAYER_CLUSTER_WIDTH, height: LAYER_CLUSTER_HEIGHT });
}
- const laid = applyDagreLayout(clusterNodes as unknown as Node[], flowEdges, "TB", dims);
- return { nodes: laid.nodes, edges: laid.edges };
+
+ return { clusterNodes, flowEdges, dims };
}, [graph, searchResults, drillIntoLayer]);
+
+ const [overview, setOverview] = useState<{ nodes: Node[]; edges: Edge[] }>({
+ nodes: [],
+ edges: [],
+ });
+
+ useEffect(() => {
+ if (!built) {
+ setOverview({ nodes: [], edges: [] });
+ return;
+ }
+ let cancelled = false;
+ const { clusterNodes, flowEdges, dims } = built;
+ const elkInput = nodesToElkInput(
+ clusterNodes as unknown as Node[],
+ flowEdges,
+ dims,
+ );
+ applyElkLayout(elkInput, { strict: import.meta.env.DEV }).then(
+ ({ positioned }) => {
+ if (cancelled) return;
+ const positionedNodes = mergeElkPositions(
+ clusterNodes as unknown as Node[],
+ positioned,
+ );
+ setOverview({ nodes: positionedNodes, edges: flowEdges });
+ },
+ );
+ return () => {
+ cancelled = true;
+ };
+ }, [built]);
+
+ return overview;
}
// ── Layer detail level: topology (dagre) + visual overlay ───────────────
diff --git a/understand-anything-plugin/packages/dashboard/src/utils/layout.ts b/understand-anything-plugin/packages/dashboard/src/utils/layout.ts
index f418b06e..0b13ac07 100644
--- a/understand-anything-plugin/packages/dashboard/src/utils/layout.ts
+++ b/understand-anything-plugin/packages/dashboard/src/utils/layout.ts
@@ -10,6 +10,7 @@ import {
} from "d3-force";
import type { SimulationNodeDatum, SimulationLinkDatum } from "d3-force";
import type { Node, Edge } from "@xyflow/react";
+import type { ElkInput } from "./elk-layout";
export const NODE_WIDTH = 280;
export const NODE_HEIGHT = 120;
@@ -182,4 +183,55 @@ export function applyForceLayout(
return { nodes: layoutedNodes, edges };
}
+// ---------------------------------------------------------------------------
+// ELK helpers
+// ---------------------------------------------------------------------------
+const ELK_DEFAULT_LAYOUT_OPTIONS: Record<string, string> = {
+ algorithm: "layered",
+ "elk.direction": "DOWN",
+ "elk.layered.spacing.nodeNodeBetweenLayers": "80",
+ "elk.spacing.nodeNode": "60",
+ "elk.layered.crossingMinimization.strategy": "LAYER_SWEEP",
+ "elk.edgeRouting": "ORTHOGONAL",
+ "elk.layered.compaction.postCompaction.strategy": "LEFT",
+ "elk.padding": "[top=40,left=20,right=20,bottom=20]",
+};
+
+export function nodesToElkInput(
+ nodes: Node[],
+ edges: Edge[],
+ dims: Map<string, { width: number; height: number }>,
+): ElkInput {
+ return {
+ id: "root",
+ layoutOptions: ELK_DEFAULT_LAYOUT_OPTIONS,
+ children: nodes.map((n) => {
+ const d = dims.get(n.id);
+ return {
+ id: n.id,
+ width: d?.width ?? NODE_WIDTH,
+ height: d?.height ?? NODE_HEIGHT,
+ };
+ }),
+ edges: edges.map((e, i) => ({
+ id: e.id ?? `e${i}`,
+ sources: [String(e.source)],
+ targets: [String(e.target)],
+ })),
+ };
+}
+
+export function mergeElkPositions<T extends Node>(
+ nodes: T[],
+ positioned: ElkInput,
+): T[] {
+ const posMap = new Map<string, { x: number; y: number }>();
+ for (const c of positioned.children ?? []) {
+ posMap.set(c.id, { x: c.x ?? 0, y: c.y ?? 0 });
+ }
+ return nodes.map((n) => ({
+ ...n,
+ position: posMap.get(n.id) ?? n.position ?? { x: 0, y: 0 },
+ }));
+}