Improve graph state cleanup by fully resetting sigma instance on label change

• Modify reset logic to clear sigma instance
• Remove manual node deletion
• Update GraphLabels to use reset()
• Simplify state cleanup process
• Ensure complete graph refresh
This commit is contained in:
yangdx
2025-03-15 22:21:56 +08:00
parent 550b4d110c
commit 59ac94c61d
2 changed files with 3 additions and 17 deletions

View File

@@ -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 !== '*') {

View File

@@ -142,22 +142,13 @@ const useGraphStoreBase = create<GraphState>()((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
});