@@ -61,76 +61,60 @@ const _addMods = (
61
61
}
62
62
}
63
63
64
- const _computeCenter1Layout = (
64
+ const _computeCenter2Layout = (
65
65
tree : Tree ,
66
66
depth = 0 ,
67
67
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
68
68
offsets : number [ ] ,
69
- // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
70
- nexts : number [ ] ,
71
69
) : DeepWriteable < TreeWithLayout > => {
72
70
const children = tree . children ?. map ( ( child ) => ( {
73
71
edgeData : child . edgeData ,
74
- node : _computeCenter1Layout ( child . node , depth + 1 , offsets , nexts ) ,
72
+ node : _computeCenter2Layout ( child . node , depth + 1 , offsets ) ,
75
73
} ) )
76
74
77
- let place : number
78
75
let x : number
79
-
76
+ let m = 0
80
77
const numChildren = tree . children ?. length ?? 0
81
78
if ( numChildren === 0 ) {
82
- place = nexts [ depth ] ?? 0
83
- x = place
79
+ x = offsets [ depth ] ?? 0
84
80
} else if ( numChildren === 1 ) {
85
81
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
86
- place = children ! [ 0 ] ! . node . meta . pos . x
82
+ x = children ! [ 0 ] ! . node . meta . pos . x
87
83
} else {
88
- place =
89
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
84
+ const c = // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
90
85
( children ! [ 0 ] ! . node . meta . pos . x +
91
86
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
92
87
children ! [ numChildren - 1 ] ! . node . meta . pos . x ) *
93
88
0.5
89
+ x = Math . max ( offsets [ depth ] ?? 0 , c )
90
+ m = x - c
94
91
}
95
-
96
- offsets [ depth ] = Math . max ( offsets [ depth ] ?? 0 , nexts [ depth ] ?? 0 - place )
97
- if ( numChildren > 0 ) {
98
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
99
- x = place + offsets [ depth ] !
100
- }
101
- nexts [ depth ] = ( nexts [ depth ] ?? 0 ) + 1
92
+ offsets [ depth ] = 1 + x
102
93
103
94
return {
104
95
data : tree . data ,
105
96
children,
106
97
meta : {
107
98
isRoot : depth === 0 ,
108
99
isLeaf : tree . children === undefined || tree . children . length === 0 ,
109
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
110
- pos : { x : x ! , y : depth } ,
111
- m : offsets [ depth ] ,
100
+ pos : { x, y : depth } ,
101
+ m,
112
102
} ,
113
103
} satisfies Readonly < TreeWithLayout > as DeepWriteable < TreeWithLayout >
114
104
}
115
105
116
- export const computeCenter1Layout = (
106
+ export const computeCenter2Layout = (
117
107
tree : Readonly < Tree > ,
118
108
) : Readonly < WrappedTreeWithLayout > => {
119
- const nexts : number [ ] = [ ]
120
- const t = _computeCenter1Layout ( tree , 0 , [ ] , nexts )
121
-
122
- console . log ( 'without mods' )
123
- console . log ( t )
109
+ const offsets : number [ ] = [ ]
110
+ const t = _computeCenter2Layout ( tree , 0 , offsets )
124
111
125
112
const tracer = { maxX : 0 }
126
113
_addMods ( t , 0 , tracer )
127
114
128
- console . log ( 'with mods' )
129
- console . log ( t )
130
-
131
115
return {
132
116
tree : t ,
133
- maxY : nexts . length - 1 ,
117
+ maxY : offsets . length - 1 ,
134
118
maxX : tracer . maxX ,
135
119
}
136
120
}
0 commit comments