@@ -261,7 +261,7 @@ export function CodeGraph({
261261 const type = "category" in element . data
262262
263263 if ( element . data . expand ) {
264- deleteNeighbors ( element . data , chart )
264+ deleteNeighbors ( [ element . data ] , chart )
265265 }
266266
267267 graph . Elements . splice ( index , 1 ) ;
@@ -296,7 +296,9 @@ export function CodeGraph({
296296
297297 if ( ! graphNode ) return
298298
299- if ( ! graphNode . data . expand ) {
299+ const expand = ! graphNode . data . expand
300+
301+ if ( expand ) {
300302 const elements = await onFetchNode ( [ node . id ] )
301303
302304 if ( elements . length === 0 ) {
@@ -312,7 +314,9 @@ export function CodeGraph({
312314 deleteNeighbors ( [ node ] , chart ) ;
313315 }
314316
315- graphNode . data . expand = ! graphNode . data . expand
317+ const element = chart . elements ( `#${ node . id } ` )
318+ element . data ( 'expand' , expand )
319+ graphNode . data . expand = expand
316320
317321 setSelectedObj ( undefined )
318322 chart . elements ( ) . layout ( LAYOUT ) . run ( ) ;
@@ -336,20 +340,26 @@ export function CodeGraph({
336340 }
337341
338342 chart . add ( elements ) ;
343+ chart . elements ( ) . layout ( LAYOUT ) . run ( ) ;
339344 } else {
340- deleteNeighbors ( nodes , chart ) ;
345+ const deleteNodes = nodes . filter ( n => n . expand === true )
346+ if ( deleteNodes . length > 0 ) {
347+ deleteNeighbors ( deleteNodes , chart ) ;
348+ chart . elements ( ) . layout ( LAYOUT ) . run ( ) ;
349+ }
341350 }
342351
343352 nodes . forEach ( ( node ) => {
344353 const graphNode = graph . Elements . find ( e => e . data . id === node . id )
354+ const element = chart . elements ( `#${ node . id } ` )
345355
346356 if ( ! graphNode ) return
347357
358+ element . data ( "expand" , expand )
348359 graphNode . data . expand = expand
349360 } )
350361
351362 setSelectedObj ( undefined )
352- chart . elements ( ) . layout ( LAYOUT ) . run ( ) ;
353363 }
354364
355365 const handelSearchSubmit = ( node : any ) => {
0 commit comments