From ebd73a54b9d6cafb4ef6711b7af9349b8b27dedf Mon Sep 17 00:00:00 2001 From: yangdx Date: Sat, 22 Mar 2025 12:39:16 +0800 Subject: [PATCH] Fix node size calculation bugs --- lightrag_webui/src/hooks/useLightragGraph.tsx | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/lightrag_webui/src/hooks/useLightragGraph.tsx b/lightrag_webui/src/hooks/useLightragGraph.tsx index e2a379b8..6c54ec2e 100644 --- a/lightrag_webui/src/hooks/useLightragGraph.tsx +++ b/lightrag_webui/src/hooks/useLightragGraph.tsx @@ -464,7 +464,7 @@ const useLightrangeGraph = () => { const nodesToAdd = new Set(); const edgesToAdd = new Set(); - // Get degree range from existing graph for size calculations + // Get degree maxDegree from existing graph for size calculations const minDegree = 1; let maxDegree = 0; sigmaGraph.forEachNode(node => { @@ -472,10 +472,6 @@ const useLightrangeGraph = () => { maxDegree = Math.max(maxDegree, degree); }); - // Calculate size formula parameters - const range = maxDegree - minDegree || 1; // Avoid division by zero - const scale = Constants.maxNodeSize - Constants.minNodeSize; - // First identify connectable nodes (nodes connected to the expanded node) for (const node of processedNodes) { // Skip if node already exists @@ -512,7 +508,7 @@ const useLightrangeGraph = () => { // Track degree increments for existing nodes existingNodeDegreeIncrements.set(edge.source, (existingNodeDegreeIncrements.get(edge.source) || 0) + 1); } - + if (nodesToAdd.has(edge.target)) { nodeDegrees.set(edge.target, (nodeDegrees.get(edge.target) || 0) + 1); } else if (existingNodeIds.has(edge.target)) { @@ -579,7 +575,7 @@ const useLightrangeGraph = () => { for (const [, degree] of nodeDegrees.entries()) { maxDegree = Math.max(maxDegree, degree); } - + // 2. Consider degree increments for existing nodes for (const [nodeId, increment] of existingNodeDegreeIncrements.entries()) { const currentDegree = sigmaGraph.degree(nodeId); @@ -587,6 +583,9 @@ const useLightrangeGraph = () => { maxDegree = Math.max(maxDegree, projectedDegree); } + const range = maxDegree - minDegree || 1; // Avoid division by zero + const scale = Constants.maxNodeSize - Constants.minNodeSize; + // SAdd nodes and edges to the graph // Calculate camera ratio and spread factor once before the loop const cameraRatio = useGraphStore.getState().sigmaInstance?.getCamera().ratio || 1;