Skip to content

Commit d7a190e

Browse files
author
xwj02155382
committed
fix: Fix the issue of the homepage legend not being centered
1 parent 9d78a8c commit d7a190e

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

packages/studio-importor/src/app/graph-canvas/useInteractive.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -142,22 +142,21 @@ const useInteractive: any = () => {
142142
// onDoubleClick();
143143
// }
144144
// 布局
145-
const graph = createStaticForceLayout(fakeSnapshot(nodes), fakeSnapshot(edges));
146145
if (!hasLayouted) {
147-
updateStore(draft => {
148-
draft.hasLayouted = true;
149-
draft.nodes = graph.nodes;
150-
draft.edges = graph.edges;
151-
});
152-
}
153-
if(hasLayouted){
146+
const graph = createStaticForceLayout(fakeSnapshot(nodes), fakeSnapshot(edges));
154147
if (timerRef.current) {
155148
clearTimeout(timerRef.current);
156149
}
157-
timerRef.current = setTimeout(() => {
150+
const timerId = setTimeout(() => {
158151
const bbox = getBBox(graph.nodes);
159152
fitBounds(bbox, { duration: 300 });
160153
}, 300);
154+
timerRef.current = timerId;
155+
updateStore(draft => {
156+
draft.hasLayouted = true;
157+
draft.nodes = graph.nodes;
158+
draft.edges = graph.edges;
159+
});
161160
}
162161
}
163162
}, [nodes, edges, hasLayouted]);
@@ -172,9 +171,11 @@ const useInteractive: any = () => {
172171

173172
const onReactFlowInit = reactFlowInstance => {
174173
if (reactFlowInstance) {
174+
setTimeout(()=>{
175175
const allNodes = reactFlowInstance.toObject().nodes;
176176
const bbox = getNodesBounds(allNodes);
177177
fitBounds(bbox, { duration: 600 });
178+
},300)
178179
}
179180
};
180181

0 commit comments

Comments
 (0)