yangdx
commited on
Commit
·
e36d3ea
1
Parent(s):
7a54fb3
Fix node size calculation bugs
Browse files
lightrag_webui/src/hooks/useLightragGraph.tsx
CHANGED
@@ -464,7 +464,7 @@ const useLightrangeGraph = () => {
|
|
464 |
const nodesToAdd = new Set<string>();
|
465 |
const edgesToAdd = new Set<string>();
|
466 |
|
467 |
-
// Get degree
|
468 |
const minDegree = 1;
|
469 |
let maxDegree = 0;
|
470 |
sigmaGraph.forEachNode(node => {
|
@@ -472,10 +472,6 @@ const useLightrangeGraph = () => {
|
|
472 |
maxDegree = Math.max(maxDegree, degree);
|
473 |
});
|
474 |
|
475 |
-
// Calculate size formula parameters
|
476 |
-
const range = maxDegree - minDegree || 1; // Avoid division by zero
|
477 |
-
const scale = Constants.maxNodeSize - Constants.minNodeSize;
|
478 |
-
|
479 |
// First identify connectable nodes (nodes connected to the expanded node)
|
480 |
for (const node of processedNodes) {
|
481 |
// Skip if node already exists
|
@@ -512,7 +508,7 @@ const useLightrangeGraph = () => {
|
|
512 |
// Track degree increments for existing nodes
|
513 |
existingNodeDegreeIncrements.set(edge.source, (existingNodeDegreeIncrements.get(edge.source) || 0) + 1);
|
514 |
}
|
515 |
-
|
516 |
if (nodesToAdd.has(edge.target)) {
|
517 |
nodeDegrees.set(edge.target, (nodeDegrees.get(edge.target) || 0) + 1);
|
518 |
} else if (existingNodeIds.has(edge.target)) {
|
@@ -579,7 +575,7 @@ const useLightrangeGraph = () => {
|
|
579 |
for (const [, degree] of nodeDegrees.entries()) {
|
580 |
maxDegree = Math.max(maxDegree, degree);
|
581 |
}
|
582 |
-
|
583 |
// 2. Consider degree increments for existing nodes
|
584 |
for (const [nodeId, increment] of existingNodeDegreeIncrements.entries()) {
|
585 |
const currentDegree = sigmaGraph.degree(nodeId);
|
@@ -587,6 +583,9 @@ const useLightrangeGraph = () => {
|
|
587 |
maxDegree = Math.max(maxDegree, projectedDegree);
|
588 |
}
|
589 |
|
|
|
|
|
|
|
590 |
// SAdd nodes and edges to the graph
|
591 |
// Calculate camera ratio and spread factor once before the loop
|
592 |
const cameraRatio = useGraphStore.getState().sigmaInstance?.getCamera().ratio || 1;
|
|
|
464 |
const nodesToAdd = new Set<string>();
|
465 |
const edgesToAdd = new Set<string>();
|
466 |
|
467 |
+
// Get degree maxDegree from existing graph for size calculations
|
468 |
const minDegree = 1;
|
469 |
let maxDegree = 0;
|
470 |
sigmaGraph.forEachNode(node => {
|
|
|
472 |
maxDegree = Math.max(maxDegree, degree);
|
473 |
});
|
474 |
|
|
|
|
|
|
|
|
|
475 |
// First identify connectable nodes (nodes connected to the expanded node)
|
476 |
for (const node of processedNodes) {
|
477 |
// Skip if node already exists
|
|
|
508 |
// Track degree increments for existing nodes
|
509 |
existingNodeDegreeIncrements.set(edge.source, (existingNodeDegreeIncrements.get(edge.source) || 0) + 1);
|
510 |
}
|
511 |
+
|
512 |
if (nodesToAdd.has(edge.target)) {
|
513 |
nodeDegrees.set(edge.target, (nodeDegrees.get(edge.target) || 0) + 1);
|
514 |
} else if (existingNodeIds.has(edge.target)) {
|
|
|
575 |
for (const [, degree] of nodeDegrees.entries()) {
|
576 |
maxDegree = Math.max(maxDegree, degree);
|
577 |
}
|
578 |
+
|
579 |
// 2. Consider degree increments for existing nodes
|
580 |
for (const [nodeId, increment] of existingNodeDegreeIncrements.entries()) {
|
581 |
const currentDegree = sigmaGraph.degree(nodeId);
|
|
|
583 |
maxDegree = Math.max(maxDegree, projectedDegree);
|
584 |
}
|
585 |
|
586 |
+
const range = maxDegree - minDegree || 1; // Avoid division by zero
|
587 |
+
const scale = Constants.maxNodeSize - Constants.minNodeSize;
|
588 |
+
|
589 |
// SAdd nodes and edges to the graph
|
590 |
// Calculate camera ratio and spread factor once before the loop
|
591 |
const cameraRatio = useGraphStore.getState().sigmaInstance?.getCamera().ratio || 1;
|