File tree Expand file tree Collapse file tree 2 files changed +78
-3
lines changed Expand file tree Collapse file tree 2 files changed +78
-3
lines changed Original file line number Diff line number Diff line change @@ -119,11 +119,9 @@ const _inPlaceEvenSpacingUpdate = (
119
119
) : void => {
120
120
if ( numChildren === 0 ) {
121
121
tree . meta . pos . x += shift
122
- tree . meta . m = 0
123
122
} else if ( numChildren === 1 ) {
124
123
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
125
124
tree . meta . pos . x = tree . children ! [ 0 ] ! . node . meta . pos . x
126
- tree . meta . m = 0
127
125
} else {
128
126
const c = // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
129
127
( tree . children ! [ 0 ] ! . node . meta . pos . x +
@@ -132,6 +130,7 @@ const _inPlaceEvenSpacingUpdate = (
132
130
0.5
133
131
tree . meta . pos . x = Math . max ( offsets [ depth ] ?? 0 , c )
134
132
}
133
+ delete tree . meta . m
135
134
tracer . maxX = Math . max ( tracer . maxX , tree . meta . pos . x )
136
135
offsets [ depth ] = 1 + tree . meta . pos . x
137
136
}
Original file line number Diff line number Diff line change
1
+ import { computeCenter3Layout , computeLeftShiftLayout } from '../layouts'
1
2
import { describe , expect , it } from 'vitest'
2
- import { computeLeftShiftLayout } from '../layouts'
3
3
4
4
describe ( 'computeLeftShiftLayout' , ( ) => {
5
5
it ( 'sets x=0,y=0 for a single-node tree, and data is preserved' , ( ) => {
@@ -349,3 +349,79 @@ describe('computeLeftShiftLayout', () => {
349
349
} )
350
350
} )
351
351
} )
352
+
353
+ describe ( 'computeCenter3Layout' , ( ) => {
354
+ it ( 'sets x=0,y=0 for a single-node tree, and data is preserved' , ( ) => {
355
+ const resultWithoutChildren = computeCenter3Layout ( {
356
+ data : { v : 42 } ,
357
+ } )
358
+ expect ( resultWithoutChildren ) . toEqual ( {
359
+ maxX : 0 ,
360
+ maxY : 0 ,
361
+ tree : {
362
+ data : { v : 42 } ,
363
+ meta : {
364
+ isRoot : true ,
365
+ isLeaf : true ,
366
+ pos : { x : 0 , y : 0 } ,
367
+ } ,
368
+ } ,
369
+ } )
370
+
371
+ const resultWithEmptyChildren = computeCenter3Layout ( {
372
+ data : { v : 42 } ,
373
+ children : [ ] ,
374
+ } )
375
+ expect ( resultWithEmptyChildren ) . toEqual ( {
376
+ maxX : 0 ,
377
+ maxY : 0 ,
378
+ tree : {
379
+ data : { v : 42 } ,
380
+ children : [ ] ,
381
+ meta : {
382
+ isRoot : true ,
383
+ isLeaf : true ,
384
+ pos : { x : 0 , y : 0 } ,
385
+ } ,
386
+ } ,
387
+ } )
388
+ } )
389
+
390
+ it ( 'sets x=0,y=0 & x=0,y=1 for tree with single child' , ( ) => {
391
+ const result = computeCenter3Layout ( {
392
+ data : { v : 42 } ,
393
+ children : [
394
+ {
395
+ edgeData : { } ,
396
+ node : { data : { v : 43 } } ,
397
+ } ,
398
+ ] ,
399
+ } )
400
+
401
+ expect ( result ) . toEqual ( {
402
+ maxX : 0 ,
403
+ maxY : 1 ,
404
+ tree : {
405
+ data : { v : 42 } ,
406
+ children : [
407
+ {
408
+ edgeData : { } ,
409
+ node : {
410
+ data : { v : 43 } ,
411
+ meta : {
412
+ isRoot : false ,
413
+ isLeaf : true ,
414
+ pos : { x : 0 , y : 1 } ,
415
+ } ,
416
+ } ,
417
+ } ,
418
+ ] ,
419
+ meta : {
420
+ isRoot : true ,
421
+ isLeaf : false ,
422
+ pos : { x : 0 , y : 0 } ,
423
+ } ,
424
+ } ,
425
+ } )
426
+ } )
427
+ } )
You can’t perform that action at this time.
0 commit comments