@@ -14,10 +14,10 @@ export class PivotUtil {
14
14
this . extractValuesForRow ( dimensions , rec , pivotKeys ) ;
15
15
for ( const [ key , val ] of vals ) { // this should go in depth also vals.children
16
16
if ( hierarchy . get ( val . value ) != null ) {
17
- this . applyHierarchyChildren ( hierarchy , val , rec , pivotKeys . records ) ;
17
+ this . applyHierarchyChildren ( hierarchy , val , rec , pivotKeys ) ;
18
18
} else {
19
19
hierarchy . set ( val . value , cloneValue ( val ) ) ;
20
- this . applyHierarchyChildren ( hierarchy , val , rec , pivotKeys . records ) ;
20
+ this . applyHierarchyChildren ( hierarchy , val , rec , pivotKeys ) ;
21
21
}
22
22
}
23
23
}
@@ -79,7 +79,7 @@ export class PivotUtil {
79
79
continue ;
80
80
}
81
81
rec [ field + '_' + pivotKeys . level ] = currDimLvl ;
82
- const expansionRowKey = PivotUtil . getRecordKey ( rec , dim , prevDims ) ;
82
+ const expansionRowKey = PivotUtil . getRecordKey ( rec , dim , prevDims , pivotKeys ) ;
83
83
const isExpanded = expansionStates . get ( expansionRowKey ) === undefined ?
84
84
defaultExpandState :
85
85
expansionStates . get ( expansionRowKey ) ;
@@ -219,7 +219,7 @@ export class PivotUtil {
219
219
}
220
220
for ( const property in parentRec ) {
221
221
if ( parentRec . hasOwnProperty ( property ) &&
222
- Object . keys ( pivotKeys ) . indexOf ( property ) === - 1 ) {
222
+ Object . values ( pivotKeys ) . indexOf ( property ) === - 1 ) {
223
223
siblingData . forEach ( s => {
224
224
s [ property ] = parentRec [ property ] ;
225
225
} ) ;
@@ -313,23 +313,22 @@ export class PivotUtil {
313
313
return leafs ;
314
314
}
315
315
316
- public static getRecordKey ( rec , currentDim : IPivotDimension , prevDims : IPivotDimension [ ] ) {
316
+ public static getRecordKey ( rec , currentDim : IPivotDimension , prevDims : IPivotDimension [ ] , pivotKeys : IPivotKeys ) {
317
317
const parentFields = [ ] ;
318
318
const field = currentDim . memberName ;
319
319
const value = rec [ field ] ;
320
320
for ( const prev of prevDims ) {
321
- const dimData = PivotUtil . getDimensionLevel ( prev , rec ,
322
- { aggregations : 'aggregations' , records : 'records' , children : 'children' , level : 'level' } ) ;
321
+ const dimData = PivotUtil . getDimensionLevel ( prev , rec , pivotKeys ) ;
323
322
parentFields . push ( rec [ dimData . dimension . memberName ] ) ;
324
323
}
325
324
parentFields . push ( value ) ;
326
325
return parentFields . join ( '_' ) ;
327
326
}
328
327
329
- public static getTotalLvl ( rec ) {
328
+ public static getTotalLvl ( rec , pivotKeys : IPivotKeys ) {
330
329
let total = 0 ;
331
330
Object . keys ( rec ) . forEach ( key => {
332
- if ( key . indexOf ( '_level' ) !== - 1 && key . indexOf ( 'level_ ') === - 1 && key . indexOf ( ' records' ) === - 1 ) {
331
+ if ( key . indexOf ( '_' + pivotKeys . level ) !== - 1 && key . indexOf ( pivotKeys . level + '_ ') === - 1 && key . indexOf ( pivotKeys . records ) === - 1 ) {
333
332
total += rec [ key ] || 0 ;
334
333
}
335
334
} ) ;
@@ -374,10 +373,12 @@ export class PivotUtil {
374
373
return result ;
375
374
}
376
375
377
- private static applyHierarchyChildren ( hierarchy , val , rec , recordsKey ) {
378
- const childCollection = val . children ;
379
- if ( Array . isArray ( hierarchy . get ( val . value ) . children ) ) {
380
- hierarchy . get ( val . value ) . children = new Map < string , any > ( ) ;
376
+ private static applyHierarchyChildren ( hierarchy , val , rec , pivotKeys : IPivotKeys ) {
377
+ const recordsKey = pivotKeys . records ;
378
+ const childKey = pivotKeys . children ;
379
+ const childCollection = val [ childKey ] ;
380
+ if ( Array . isArray ( hierarchy . get ( val . value ) [ childKey ] ) ) {
381
+ hierarchy . get ( val . value ) [ childKey ] = new Map < string , any > ( ) ;
381
382
}
382
383
if ( ! childCollection || childCollection . size === 0 ) {
383
384
const dim = hierarchy . get ( val . value ) . dimension ;
@@ -391,26 +392,26 @@ export class PivotUtil {
391
392
}
392
393
} else {
393
394
for ( const [ key , child ] of childCollection ) {
394
- if ( ! hierarchy . get ( val . value ) . children . get ( child . value ) ) {
395
- hierarchy . get ( val . value ) . children . set ( child . value , child ) ;
395
+ if ( ! hierarchy . get ( val . value ) [ childKey ] . get ( child . value ) ) {
396
+ hierarchy . get ( val . value ) [ childKey ] . set ( child . value , child ) ;
396
397
}
397
398
398
- if ( hierarchy . get ( val . value ) . children . get ( child . value ) [ recordsKey ] ) {
399
+ if ( hierarchy . get ( val . value ) [ childKey ] . get ( child . value ) [ recordsKey ] ) {
399
400
const copy = Object . assign ( { } , rec ) ;
400
401
if ( rec [ recordsKey ] ) {
401
402
// not all nested children are valid
402
- const nestedValue = hierarchy . get ( val . value ) . children . get ( child . value ) . value ;
403
- const dimension = hierarchy . get ( val . value ) . children . get ( child . value ) . dimension ;
403
+ const nestedValue = hierarchy . get ( val . value ) [ childKey ] . get ( child . value ) . value ;
404
+ const dimension = hierarchy . get ( val . value ) [ childKey ] . get ( child . value ) . dimension ;
404
405
const validRecs = rec [ recordsKey ] . filter ( x => this . extractValueFromDimension ( dimension , x ) === nestedValue ) ;
405
406
copy [ recordsKey ] = validRecs ;
406
407
}
407
- hierarchy . get ( val . value ) . children . get ( child . value ) [ recordsKey ] . push ( copy ) ;
408
+ hierarchy . get ( val . value ) [ childKey ] . get ( child . value ) [ recordsKey ] . push ( copy ) ;
408
409
} else {
409
- hierarchy . get ( val . value ) . children . get ( child . value ) [ recordsKey ] = [ rec ] ;
410
+ hierarchy . get ( val . value ) [ childKey ] . get ( child . value ) [ recordsKey ] = [ rec ] ;
410
411
}
411
412
412
- if ( child . children && child . children . size > 0 ) {
413
- this . applyHierarchyChildren ( hierarchy . get ( val . value ) . children , child , rec , recordsKey ) ;
413
+ if ( child [ childKey ] && child [ childKey ] . size > 0 ) {
414
+ this . applyHierarchyChildren ( hierarchy . get ( val . value ) [ childKey ] , child , rec , pivotKeys ) ;
414
415
}
415
416
}
416
417
}
0 commit comments