@@ -12,6 +12,7 @@ import type {
1212 Node ,
1313 OutNode ,
1414} from './types' ;
15+ import { isLayoutWithIterations } from './types' ;
1516import { getLayoutBBox , graphTreeDfs , isArray } from './util' ;
1617import { handleSingleNodeGraph } from './util/common' ;
1718
@@ -116,7 +117,7 @@ export class ComboCombinedLayout implements Layout<ComboCombinedLayoutOptions> {
116117 } ) ;
117118
118119 // each one in comboNodes is a combo contains the size and child nodes
119- // comboNodes ncludes the node who has no parent combo
120+ // comboNodes includes the node who has no parent combo
120121 const comboNodes : Map < ID , Node > = new Map ( ) ;
121122 // the inner layouts, the result positions are stored in comboNodes and their child nodes
122123 const innerGraphLayoutPromises = this . getInnerGraphs (
@@ -214,7 +215,8 @@ export class ComboCombinedLayout implements Layout<ComboCombinedLayoutOptions> {
214215 : new ConcentricLayout ( ) ;
215216 await outerLayoutPreset . assign ( outerLayoutGraph ) ;
216217 }
217- outerPositions = await outerLayout . execute ( outerLayoutGraph , {
218+
219+ const options = {
218220 center,
219221 kg : 5 ,
220222 preventOverlap : true ,
@@ -232,7 +234,13 @@ export class ComboCombinedLayout implements Layout<ComboCombinedLayoutOptions> {
232234 } ,
233235 }
234236 : { } ) ,
235- } ) ;
237+ } ;
238+
239+ outerPositions = await executeLayout (
240+ outerLayout ,
241+ outerLayoutGraph ,
242+ options ,
243+ ) ;
236244 }
237245
238246 // move the combos and their child nodes
@@ -400,7 +408,7 @@ export class ComboCombinedLayout implements Layout<ComboCombinedLayoutOptions> {
400408 } ,
401409 } ) ;
402410
403- let start = Promise . resolve ( ) ;
411+ let start : Promise < any > = Promise . resolve ( ) ;
404412
405413 // Regard the child nodes in one combo as a graph, and layout them from bottom to top
406414 graphTreeDfs (
@@ -479,14 +487,16 @@ export class ComboCombinedLayout implements Layout<ComboCombinedLayoutOptions> {
479487 // innerGraphLayout.assign(innerGraphCore, innerLayoutOptions);
480488 start = start . then ( async ( ) => {
481489 const innerGraphCore = new GraphCore ( innerGraphData ) ;
482- const innerLayout = await innerGraphLayout . assign (
490+ await executeLayout (
491+ innerGraphLayout ,
483492 innerGraphCore ,
484493 innerLayoutOptions ,
494+ true ,
485495 ) ;
486496 const { minX, minY, maxX, maxY } = getLayoutBBox (
487497 innerLayoutNodes as OutNode [ ] ,
488498 ) ;
489- // move the innerGraph to [0, 0], for later controled by parent layout
499+ // move the innerGraph to [0, 0], for later controlled by parent layout
490500 const center = { x : ( maxX + minX ) / 2 , y : ( maxY + minY ) / 2 } ;
491501 innerGraphData . nodes . forEach ( ( node ) => {
492502 node . data . x -= center . x ;
@@ -499,7 +509,6 @@ export class ComboCombinedLayout implements Layout<ComboCombinedLayoutOptions> {
499509
500510 comboNodes . get ( treeNode . id ) . data . size = size ;
501511 comboNodes . get ( treeNode . id ) . data . nodes = innerLayoutNodes ;
502- return innerLayout ;
503512 } ) ;
504513 }
505514 return true ;
@@ -512,3 +521,18 @@ export class ComboCombinedLayout implements Layout<ComboCombinedLayoutOptions> {
512521 return innerLayoutPromises ;
513522 }
514523}
524+
525+ async function executeLayout (
526+ layout : Layout < any > ,
527+ graph : Graph ,
528+ options : Record < string , any > ,
529+ assign ?: boolean ,
530+ ) {
531+ if ( isLayoutWithIterations ( layout ) ) {
532+ layout . execute ( graph , options ) ;
533+ layout . stop ( ) ;
534+ return layout . tick ( options . iterations ?? 300 ) ;
535+ }
536+ if ( assign ) return await layout . assign ( graph , options ) ;
537+ return await layout . execute ( graph , options ) ;
538+ }
0 commit comments