@@ -50,11 +50,17 @@ export default abstract class LayoutController {
50
50
51
51
protected isLayoutTypeSame ( cfg ) : boolean {
52
52
const current = this . getLayoutCfgType ( cfg ) ;
53
- // already has pipes
54
- if ( Array . isArray ( this . layoutType ) ) {
55
- return this . layoutType . every ( ( type , index ) => type === current [ index ] ) ;
53
+ const preHasPipies = Array . isArray ( this . layoutType ) ;
54
+ const currentHasPipes = Array . isArray ( current ) ;
55
+ // already has pipes, and the new one is pipes
56
+ if ( preHasPipies && currentHasPipes ) {
57
+ return ( this . layoutType as string [ ] ) . every ( ( type , index ) => type === current [ index ] ) ;
56
58
}
57
-
59
+ // only one of the pre and current is pipes
60
+ if ( Array . isArray ( current ) || Array . isArray ( this . layoutType ) ) {
61
+ return false ;
62
+ }
63
+ // both of the pre and current are not pipes
58
64
return cfg ?. type === this . layoutType ;
59
65
}
60
66
@@ -171,28 +177,7 @@ export default abstract class LayoutController {
171
177
} as GraphData ;
172
178
}
173
179
174
- protected reLayoutMethod ( layoutMethod , layoutCfg ) : Promise < void > {
175
- return new Promise ( ( reslove , reject ) => {
176
- const { graph } = this ;
177
- const layoutType = layoutCfg ?. type ;
178
-
179
- // 每个布局方法都需要注册
180
- layoutCfg . onLayoutEnd = ( ) => {
181
- graph . emit ( 'aftersublayout' , { type : layoutType } ) ;
182
- reslove ( ) ;
183
- } ;
184
-
185
- layoutMethod . init ( this . data ) ;
186
- if ( layoutType === 'force' ) {
187
- layoutMethod . ticking = false ;
188
- layoutMethod . forceSimulation . stop ( ) ;
189
- }
190
-
191
- graph . emit ( 'beforesublayout' , { type : layoutType } ) ;
192
- layoutMethod . execute ( ) ;
193
- if ( layoutMethod . isCustomLayout && layoutCfg . onLayoutEnd ) layoutCfg . onLayoutEnd ( ) ;
194
- } ) ;
195
- }
180
+ protected abstract execLayoutMethod ( layoutCfg , order ) : Promise < void > ;
196
181
197
182
// 重新布局
198
183
public relayout ( reloadData ?: boolean ) {
@@ -213,7 +198,7 @@ export default abstract class LayoutController {
213
198
layoutMethods ?. forEach ( ( layoutMethod : any , index : number ) => {
214
199
const currentCfg = layoutCfg [ index ] || layoutCfg ;
215
200
start = start . then ( ( ) => {
216
- const relayoutPromise = this . reLayoutMethod ( layoutMethod , currentCfg ) ;
201
+ const relayoutPromise = this . execLayoutMethod ( layoutMethod , currentCfg ) ;
217
202
if ( index === layoutMethods . length - 1 ) {
218
203
layoutCfg . onAllLayoutEnd ?.( ) ;
219
204
}
0 commit comments