yangdx
commited on
Commit
·
1d099f8
1
Parent(s):
950dbcd
Fix merge problem
Browse files
lightrag_webui/src/hooks/useLightragGraph.tsx
CHANGED
@@ -375,29 +375,28 @@ const useLightrangeGraph = () => {
|
|
375 |
}
|
376 |
|
377 |
// 3. Process data
|
378 |
-
dataPromise.then((
|
379 |
-
|
380 |
-
const
|
381 |
|
382 |
// Assign colors based on entity_type *after* fetching
|
383 |
-
if (
|
384 |
-
|
385 |
// Use entity_type instead of type
|
386 |
const nodeEntityType = node.properties?.entity_type as string | undefined;
|
387 |
node.color = getNodeColorByType(nodeEntityType);
|
388 |
});
|
389 |
}
|
390 |
|
391 |
-
if (
|
392 |
toast.info(t('graphPanel.dataIsTruncated', 'Graph data is truncated to Max Nodes'));
|
393 |
}
|
394 |
|
395 |
// Reset state
|
396 |
-
const state = useGraphStore.getState()
|
397 |
state.reset()
|
398 |
|
399 |
// Check if data is empty or invalid
|
400 |
-
if (!
|
401 |
// Create a graph with a single "Graph Is Empty" node
|
402 |
const emptyGraph = new DirectedGraph();
|
403 |
|
@@ -438,12 +437,12 @@ const useLightrangeGraph = () => {
|
|
438 |
console.log(`Graph data is empty, created graph with empty graph node. Auth error: ${isAuthError}`);
|
439 |
} else {
|
440 |
// Create and set new graph
|
441 |
-
const newSigmaGraph = createSigmaGraph(
|
442 |
-
|
443 |
|
444 |
// Set new graph data
|
445 |
state.setSigmaGraph(newSigmaGraph);
|
446 |
-
state.setRawGraph(
|
447 |
state.setGraphIsEmpty(false);
|
448 |
|
449 |
// Update last successful query label
|
@@ -460,7 +459,7 @@ const useLightrangeGraph = () => {
|
|
460 |
state.setIsFetching(false)
|
461 |
|
462 |
// Mark empty data as handled if data is empty and query label is empty
|
463 |
-
if ((!
|
464 |
emptyDataHandledRef.current = true;
|
465 |
}
|
466 |
}).catch((error) => {
|
@@ -508,9 +507,9 @@ const useLightrangeGraph = () => {
|
|
508 |
// Process nodes to add required properties for RawNodeType
|
509 |
const processedNodes: RawNodeType[] = [];
|
510 |
for (const node of extendedGraph.nodes) {
|
511 |
-
//
|
512 |
-
|
513 |
-
const color =
|
514 |
|
515 |
// Create a properly typed RawNodeType
|
516 |
processedNodes.push({
|
|
|
375 |
}
|
376 |
|
377 |
// 3. Process data
|
378 |
+
dataPromise.then((result) => {
|
379 |
+
const state = useGraphStore.getState()
|
380 |
+
const data = result?.rawGraph;
|
381 |
|
382 |
// Assign colors based on entity_type *after* fetching
|
383 |
+
if (data && data.nodes) {
|
384 |
+
data.nodes.forEach(node => {
|
385 |
// Use entity_type instead of type
|
386 |
const nodeEntityType = node.properties?.entity_type as string | undefined;
|
387 |
node.color = getNodeColorByType(nodeEntityType);
|
388 |
});
|
389 |
}
|
390 |
|
391 |
+
if (result?.is_truncated) {
|
392 |
toast.info(t('graphPanel.dataIsTruncated', 'Graph data is truncated to Max Nodes'));
|
393 |
}
|
394 |
|
395 |
// Reset state
|
|
|
396 |
state.reset()
|
397 |
|
398 |
// Check if data is empty or invalid
|
399 |
+
if (!data || !data.nodes || data.nodes.length === 0) {
|
400 |
// Create a graph with a single "Graph Is Empty" node
|
401 |
const emptyGraph = new DirectedGraph();
|
402 |
|
|
|
437 |
console.log(`Graph data is empty, created graph with empty graph node. Auth error: ${isAuthError}`);
|
438 |
} else {
|
439 |
// Create and set new graph
|
440 |
+
const newSigmaGraph = createSigmaGraph(data);
|
441 |
+
data.buildDynamicMap();
|
442 |
|
443 |
// Set new graph data
|
444 |
state.setSigmaGraph(newSigmaGraph);
|
445 |
+
state.setRawGraph(data);
|
446 |
state.setGraphIsEmpty(false);
|
447 |
|
448 |
// Update last successful query label
|
|
|
459 |
state.setIsFetching(false)
|
460 |
|
461 |
// Mark empty data as handled if data is empty and query label is empty
|
462 |
+
if ((!data || !data.nodes || data.nodes.length === 0) && !currentQueryLabel) {
|
463 |
emptyDataHandledRef.current = true;
|
464 |
}
|
465 |
}).catch((error) => {
|
|
|
507 |
// Process nodes to add required properties for RawNodeType
|
508 |
const processedNodes: RawNodeType[] = [];
|
509 |
for (const node of extendedGraph.nodes) {
|
510 |
+
// Generate random color values
|
511 |
+
seedrandom(node.id, { global: true });
|
512 |
+
const color = randomColor();
|
513 |
|
514 |
// Create a properly typed RawNodeType
|
515 |
processedNodes.push({
|