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.
TypeScript antigravity-skillsbusiness-knowledgeclaude-codeclaude-skillscodebase-analysiscodexcodex-skillsdeveloper-tools-ai-agentgemini-cli-skillskarpathy-llm-wikiknowledge-baseknowledge-graphmemoryopencode-skillspi-agentunderstandcodevibe-coding
fix(dashboard): normalize sparse community indices
KumamuKumaae51db660ea5
diff --git a/understand-anything-plugin/packages/dashboard/src/utils/__tests__/force-layout.test.ts b/understand-anything-plugin/packages/dashboard/src/utils/__tests__/force-layout.test.tsindex 5ed52fdd..8df2d190 100644--- a/understand-anything-plugin/packages/dashboard/src/utils/__tests__/force-layout.test.ts+++ b/understand-anything-plugin/packages/dashboard/src/utils/__tests__/force-layout.test.ts@@ -38,6 +38,28 @@ describe("computeForceLayout", () => {computeForceLayout(nodes, edges),);});++ it("normalizes sparse community IDs before assigning cluster angles", () => {+ const denseNodes: ForceLayoutNode[] = Array.from({ length: 80 }, (_, index) => ({+ id: `node-${index}`,+ width: 80,+ height: 40,+ community: index % 2,+ }));+ const denseLayout = computeForceLayout(denseNodes, []);++ for (const [firstCommunity, secondCommunity] of [+ [0, 2],+ [10, 20],+ ] as const) {+ const sparseNodes = denseNodes.map((node, index) => ({+ ...node,+ community: index % 2 === 0 ? firstCommunity : secondCommunity,+ }));++ expect(computeForceLayout(sparseNodes, [])).toEqual(denseLayout);+ }+ });});describe("createFallbackGrid", () => {diff --git a/understand-anything-plugin/packages/dashboard/src/utils/force-layout.ts b/understand-anything-plugin/packages/dashboard/src/utils/force-layout.tsindex 2721b4c6..c3b602c8 100644--- a/understand-anything-plugin/packages/dashboard/src/utils/force-layout.ts+++ b/understand-anything-plugin/packages/dashboard/src/utils/force-layout.ts@@ -71,14 +71,19 @@ export function computeForceLayout(.filter((edge) => nodeIds.has(edge.source) && nodeIds.has(edge.target)).map((edge) => ({ source: edge.source, target: edge.target }));- const communities = new Set(- simulationNodes- .map((node) => node.community)- .filter((community): community is number => community !== undefined),+ const communityIds = [+ ...new Set(+ simulationNodes+ .map((node) => node.community)+ .filter((community): community is number => community !== undefined),+ ),+ ].sort((left, right) => left - right);+ const communityIndexById = new Map(+ communityIds.map((community, index) => [community, index]),);- const communityCount = Math.max(1, communities.size);+ const communityCount = Math.max(1, communityIds.length);const communityAngle = (community: number) =>- (2 * Math.PI * community) / communityCount;+ (2 * Math.PI * (communityIndexById.get(community) ?? 0)) / communityCount;const clusterRadius = Math.max(600, nodes.length * 5);const isLarge = nodes.length > 100;const chargeStrength = isLarge ? -600 : -350;