@@ -433,41 +433,45 @@ export class PivotUtil {
433
433
const recordsKey = pivotKeys . records ;
434
434
const childKey = pivotKeys . children ;
435
435
const childCollection = val [ childKey ] ;
436
- if ( Array . isArray ( hierarchy . get ( val . value ) [ childKey ] ) ) {
437
- hierarchy . get ( val . value ) [ childKey ] = new Map < string , any > ( ) ;
436
+ const hierarchyValue = hierarchy . get ( val . value ) ;
437
+ if ( Array . isArray ( hierarchyValue [ childKey ] ) ) {
438
+ hierarchyValue [ childKey ] = new Map < string , any > ( ) ;
438
439
}
439
440
if ( ! childCollection || childCollection . size === 0 ) {
440
- const dim = hierarchy . get ( val . value ) . dimension ;
441
+ const dim = hierarchyValue . dimension ;
441
442
const isValid = this . extractValueFromDimension ( dim , rec ) === val . value ;
442
443
if ( isValid ) {
443
- if ( hierarchy . get ( val . value ) [ recordsKey ] ) {
444
- hierarchy . get ( val . value ) [ recordsKey ] . push ( rec ) ;
444
+ if ( hierarchyValue [ recordsKey ] ) {
445
+ hierarchyValue [ recordsKey ] . push ( rec ) ;
445
446
} else {
446
- hierarchy . get ( val . value ) [ recordsKey ] = [ rec ] ;
447
+ hierarchyValue [ recordsKey ] = [ rec ] ;
447
448
}
448
449
}
449
450
} else {
451
+ const hierarchyChild = hierarchyValue [ childKey ] ;
450
452
for ( const [ key , child ] of childCollection ) {
451
- if ( ! hierarchy . get ( val . value ) [ childKey ] . get ( child . value ) ) {
452
- hierarchy . get ( val . value ) [ childKey ] . set ( child . value , child ) ;
453
+ let hierarchyChildValue = hierarchyChild . get ( child . value ) ;
454
+ if ( ! hierarchyChildValue ) {
455
+ hierarchyChild . set ( child . value , child ) ;
456
+ hierarchyChildValue = child ;
453
457
}
454
458
455
- if ( hierarchy . get ( val . value ) [ childKey ] . get ( child . value ) [ recordsKey ] ) {
459
+ if ( hierarchyChildValue [ recordsKey ] ) {
456
460
const copy = Object . assign ( { } , rec ) ;
457
461
if ( rec [ recordsKey ] ) {
458
462
// not all nested children are valid
459
- const nestedValue = hierarchy . get ( val . value ) [ childKey ] . get ( child . value ) . value ;
460
- const dimension = hierarchy . get ( val . value ) [ childKey ] . get ( child . value ) . dimension ;
463
+ const nestedValue = hierarchyChildValue . value ;
464
+ const dimension = hierarchyChildValue . dimension ;
461
465
const validRecs = rec [ recordsKey ] . filter ( x => this . extractValueFromDimension ( dimension , x ) === nestedValue ) ;
462
466
copy [ recordsKey ] = validRecs ;
463
467
}
464
- hierarchy . get ( val . value ) [ childKey ] . get ( child . value ) [ recordsKey ] . push ( copy ) ;
468
+ hierarchyChildValue [ recordsKey ] . push ( copy ) ;
465
469
} else {
466
- hierarchy . get ( val . value ) [ childKey ] . get ( child . value ) [ recordsKey ] = [ rec ] ;
470
+ hierarchyChildValue [ recordsKey ] = [ rec ] ;
467
471
}
468
472
469
473
if ( child [ childKey ] && child [ childKey ] . size > 0 ) {
470
- this . applyHierarchyChildren ( hierarchy . get ( val . value ) [ childKey ] , child , rec , pivotKeys ) ;
474
+ this . applyHierarchyChildren ( hierarchyChild , child , rec , pivotKeys ) ;
471
475
}
472
476
}
473
477
}
0 commit comments