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:
@@ -111,13 +111,8 @@ const GraphLabels = () => {
|
|||||||
// Clear current graph data to ensure complete reload when label changes
|
// Clear current graph data to ensure complete reload when label changes
|
||||||
if (newLabel !== currentLabel) {
|
if (newLabel !== currentLabel) {
|
||||||
const graphStore = useGraphStore.getState();
|
const graphStore = useGraphStore.getState();
|
||||||
graphStore.clearSelection();
|
// 完全重置图形状态
|
||||||
|
graphStore.reset();
|
||||||
// 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));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newLabel === currentLabel && newLabel !== '*') {
|
if (newLabel === currentLabel && newLabel !== '*') {
|
||||||
|
@@ -142,22 +142,13 @@ const useGraphStoreBase = create<GraphState>()((set, get) => ({
|
|||||||
focusedEdge: null
|
focusedEdge: null
|
||||||
}),
|
}),
|
||||||
reset: () => {
|
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({
|
set({
|
||||||
selectedNode: null,
|
selectedNode: null,
|
||||||
focusedNode: null,
|
focusedNode: null,
|
||||||
selectedEdge: null,
|
selectedEdge: null,
|
||||||
focusedEdge: null,
|
focusedEdge: null,
|
||||||
rawGraph: null,
|
rawGraph: null,
|
||||||
// Keep the existing graph instance but with cleared data
|
sigmaGraph: null, // 完全清除图形实例
|
||||||
moveToSelectedNode: false,
|
moveToSelectedNode: false,
|
||||||
shouldRender: false
|
shouldRender: false
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user