@@ -30,7 +30,8 @@ let svg = null,
30
30
d3 . forceManyBody ( )
31
31
. strength ( d => { return - 10 * d . radius ; } )
32
32
)
33
- . force ( "center" , d3 . forceCenter ( width / 2 , height / 2 ) ) ,
33
+ . force ( "center" , d3 . forceCenter ( width / 2 , height / 2 ) )
34
+ . on ( "tick" , ticked ) ,
34
35
brusher = d3 . brush ( )
35
36
. extent ( [ [ - 9999999 , - 9999999 ] , [ 9999999 , 9999999 ] ] )
36
37
. on ( "start.brush" , ( ) => {
@@ -61,6 +62,8 @@ let svg = null,
61
62
view = null ;
62
63
63
64
function ticked ( ) {
65
+ if ( ! link )
66
+ return ;
64
67
link
65
68
. attr ( "x1" , d => d . source . x )
66
69
. attr ( "y1" , d => d . source . y )
@@ -165,6 +168,17 @@ function flattenEdges (root) {
165
168
166
169
}
167
170
171
+ function resetChildrenPosition ( parent , children = [ ] ) {
172
+ if ( ! children || ! children . length )
173
+ return ;
174
+ for ( let c of children ) {
175
+ c . x = parent . x ;
176
+ c . y = parent . y ;
177
+ if ( c . children )
178
+ resetChildrenPosition ( c , c . children ) ;
179
+ }
180
+ }
181
+
168
182
export function update ( reset = false ) {
169
183
170
184
let g = getGraphData ( ) . foldedTree ,
@@ -195,6 +209,7 @@ export function update (reset = false) {
195
209
if ( d . type === "folder" && d . _children && d . _children . length ) {
196
210
let next = d . _children . splice ( 0 , 20 ) ,
197
211
left = parseInt ( d . label ) - 20 ;
212
+ resetChildrenPosition ( d , next ) ;
198
213
d . children = d . children . concat ( next ) ;
199
214
d . label = left > 0 ? `${ left } more` : `Others` ;
200
215
d3 . select ( this ) . select ( "text" ) . text ( d . label ) ;
@@ -222,9 +237,6 @@ export function update (reset = false) {
222
237
223
238
simulation
224
239
. nodes ( graph . nodes )
225
- . on ( "tick" , ticked ) ;
226
-
227
- simulation
228
240
. force ( "link" )
229
241
. links ( graph . edges ) ;
230
242
0 commit comments