@@ -14,10 +14,10 @@ export class PivotUtil {
1414 this . extractValuesForRow ( dimensions , rec , pivotKeys ) ;
1515 for ( const [ key , val ] of vals ) { // this should go in depth also vals.children
1616 if ( hierarchy . get ( val . value ) != null ) {
17- this . applyHierarchyChildren ( hierarchy , val , rec , pivotKeys . records ) ;
17+ this . applyHierarchyChildren ( hierarchy , val , rec , pivotKeys ) ;
1818 } else {
1919 hierarchy . set ( val . value , cloneValue ( val ) ) ;
20- this . applyHierarchyChildren ( hierarchy , val , rec , pivotKeys . records ) ;
20+ this . applyHierarchyChildren ( hierarchy , val , rec , pivotKeys ) ;
2121 }
2222 }
2323 }
@@ -79,7 +79,7 @@ export class PivotUtil {
7979 continue ;
8080 }
8181 rec [ field + '_' + pivotKeys . level ] = currDimLvl ;
82- const expansionRowKey = PivotUtil . getRecordKey ( rec , dim , prevDims ) ;
82+ const expansionRowKey = PivotUtil . getRecordKey ( rec , dim , prevDims , pivotKeys ) ;
8383 const isExpanded = expansionStates . get ( expansionRowKey ) === undefined ?
8484 defaultExpandState :
8585 expansionStates . get ( expansionRowKey ) ;
@@ -219,7 +219,7 @@ export class PivotUtil {
219219 }
220220 for ( const property in parentRec ) {
221221 if ( parentRec . hasOwnProperty ( property ) &&
222- Object . keys ( pivotKeys ) . indexOf ( property ) === - 1 ) {
222+ Object . values ( pivotKeys ) . indexOf ( property ) === - 1 ) {
223223 siblingData . forEach ( s => {
224224 s [ property ] = parentRec [ property ] ;
225225 } ) ;
@@ -313,23 +313,22 @@ export class PivotUtil {
313313 return leafs ;
314314 }
315315
316- public static getRecordKey ( rec , currentDim : IPivotDimension , prevDims : IPivotDimension [ ] ) {
316+ public static getRecordKey ( rec , currentDim : IPivotDimension , prevDims : IPivotDimension [ ] , pivotKeys : IPivotKeys ) {
317317 const parentFields = [ ] ;
318318 const field = currentDim . memberName ;
319319 const value = rec [ field ] ;
320320 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 ) ;
323322 parentFields . push ( rec [ dimData . dimension . memberName ] ) ;
324323 }
325324 parentFields . push ( value ) ;
326325 return parentFields . join ( '_' ) ;
327326 }
328327
329- public static getTotalLvl ( rec ) {
328+ public static getTotalLvl ( rec , pivotKeys : IPivotKeys ) {
330329 let total = 0 ;
331330 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 ) {
333332 total += rec [ key ] || 0 ;
334333 }
335334 } ) ;
@@ -374,10 +373,12 @@ export class PivotUtil {
374373 return result ;
375374 }
376375
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 > ( ) ;
381382 }
382383 if ( ! childCollection || childCollection . size === 0 ) {
383384 const dim = hierarchy . get ( val . value ) . dimension ;
@@ -391,26 +392,26 @@ export class PivotUtil {
391392 }
392393 } else {
393394 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 ) ;
396397 }
397398
398- if ( hierarchy . get ( val . value ) . children . get ( child . value ) [ recordsKey ] ) {
399+ if ( hierarchy . get ( val . value ) [ childKey ] . get ( child . value ) [ recordsKey ] ) {
399400 const copy = Object . assign ( { } , rec ) ;
400401 if ( rec [ recordsKey ] ) {
401402 // 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 ;
404405 const validRecs = rec [ recordsKey ] . filter ( x => this . extractValueFromDimension ( dimension , x ) === nestedValue ) ;
405406 copy [ recordsKey ] = validRecs ;
406407 }
407- hierarchy . get ( val . value ) . children . get ( child . value ) [ recordsKey ] . push ( copy ) ;
408+ hierarchy . get ( val . value ) [ childKey ] . get ( child . value ) [ recordsKey ] . push ( copy ) ;
408409 } else {
409- hierarchy . get ( val . value ) . children . get ( child . value ) [ recordsKey ] = [ rec ] ;
410+ hierarchy . get ( val . value ) [ childKey ] . get ( child . value ) [ recordsKey ] = [ rec ] ;
410411 }
411412
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 ) ;
414415 }
415416 }
416417 }
0 commit comments