File tree Expand file tree Collapse file tree 1 file changed +10
-9
lines changed
packages/studio-importor/src/app/graph-canvas Expand file tree Collapse file tree 1 file changed +10
-9
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments