1
1
import Store from '../store' ;
2
2
import Family from '../models/family' ;
3
+ import Unit from '../models/unit' ;
3
4
import arrangeMiddle from '../middle/arrange' ;
4
5
5
6
export default ( store : Store , family : Family ) : void => {
6
- const shift = family . pUnits [ 0 ] . shift ;
7
- if ( shift === 0 || family . pID === null ) return ;
8
-
7
+ if ( family . pID === null ) return ;
9
8
let right = 0 ;
10
9
11
10
while ( family ) {
11
+ const fUnit = family . pUnits [ 0 ] ;
12
+
13
+ const shift = fUnit . shift ;
12
14
const fRight = family . left + family . width ;
13
15
right = Math . max ( right , fRight ) ;
14
16
15
17
const pFamily = store . getFamily ( family . pID as number ) ; // TODO
16
18
17
- const fUnit = family . pUnits [ 0 ] ;
18
- const fShift = fUnit . shift ;
19
-
19
+ const cUnit = pFamily . cUnits . find ( unit => unit . isSame ( fUnit ) ) as Unit ; // TODO
20
20
const uIndex = pFamily . cUnits . findIndex ( unit => (
21
21
unit . nodes [ 0 ] . id === fUnit . nodes [ 0 ] . id
22
22
) ) ;
23
23
24
24
if ( uIndex === 0 ) {
25
- pFamily . left = family . left + fShift ;
25
+ const left = family . left + shift - cUnit . shift ;
26
+ pFamily . left = Math . max ( pFamily . left , left ) ;
26
27
} else {
27
- const pUnit = pFamily . cUnits . find ( unit => unit . isSame ( fUnit ) ) ;
28
- if ( pUnit ) pUnit . shift += fShift ;
28
+ cUnit . shift = family . left + fUnit . shift - pFamily . left ;
29
29
}
30
30
31
31
const next = pFamily . cUnits [ uIndex + 1 ] ;
@@ -46,9 +46,9 @@ export default (store: Store, family: Family): void => {
46
46
}
47
47
48
48
if ( pFamily . pID === null ) {
49
- const rNodes = [ ...store . families . values ( ) ] . filter ( f => f . type === 'root' ) ;
50
- const start = rNodes . findIndex ( f => f . id === pFamily . id ) ;
51
- arrangeMiddle ( rNodes , start + 1 , fRight ) ;
49
+ const rootFamily = [ ...store . families . values ( ) ] . filter ( f => f . type === 'root' ) ;
50
+ const start = rootFamily . findIndex ( f => f . id === pFamily . id ) ;
51
+ arrangeMiddle ( rootFamily , start + 1 , fRight ) ;
52
52
break ;
53
53
}
54
54
0 commit comments