From 59ac94c61d6ed0d5b78bf49cffc5a80d88bda3a4 Mon Sep 17 00:00:00 2001 From: yangdx Date: Sat, 15 Mar 2025 22:21:56 +0800 Subject: [PATCH] Improve graph state cleanup by fully resetting sigma instance on label change MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit • Modify reset logic to clear sigma instance • Remove manual node deletion • Update GraphLabels to use reset() • Simplify state cleanup process • Ensure complete graph refresh --- lightrag_webui/src/components/graph/GraphLabels.tsx | 9 ++------- lightrag_webui/src/stores/graph.ts | 11 +---------- 2 files changed, 3 insertions(+), 17 deletions(-) diff --git a/lightrag_webui/src/components/graph/GraphLabels.tsx b/lightrag_webui/src/components/graph/GraphLabels.tsx index bd2c8ea0..1ee46bb8 100644 --- a/lightrag_webui/src/components/graph/GraphLabels.tsx +++ b/lightrag_webui/src/components/graph/GraphLabels.tsx @@ -111,13 +111,8 @@ const GraphLabels = () => { // Clear current graph data to ensure complete reload when label changes if (newLabel !== currentLabel) { const graphStore = useGraphStore.getState(); - graphStore.clearSelection(); - - // Reset the graph state but preserve the instance - if (graphStore.sigmaGraph) { - const nodes = Array.from(graphStore.sigmaGraph.nodes()); - nodes.forEach(node => graphStore.sigmaGraph?.dropNode(node)); - } + // 完全重置图形状态 + graphStore.reset(); } if (newLabel === currentLabel && newLabel !== '*') { diff --git a/lightrag_webui/src/stores/graph.ts b/lightrag_webui/src/stores/graph.ts index 3de7f502..996b720b 100644 --- a/lightrag_webui/src/stores/graph.ts +++ b/lightrag_webui/src/stores/graph.ts @@ -142,22 +142,13 @@ const useGraphStoreBase = create()((set, get) => ({ focusedEdge: null }), reset: () => { - // Get the existing graph - const existingGraph = get().sigmaGraph; - - // If we have an existing graph, clear it by removing all nodes - if (existingGraph) { - const nodes = Array.from(existingGraph.nodes()); - nodes.forEach(node => existingGraph.dropNode(node)); - } - set({ selectedNode: null, focusedNode: null, selectedEdge: null, focusedEdge: null, rawGraph: null, - // Keep the existing graph instance but with cleared data + sigmaGraph: null, // 完全清除图形实例 moveToSelectedNode: false, shouldRender: false });