@@ -209,43 +209,41 @@ export class PivotUtil {
209
209
}
210
210
211
211
public static processSubGroups ( row , prevRowDims , siblingData , pivotKeys ) {
212
+ const prevRowDimsIter = prevRowDims . slice ( 0 ) ;
212
213
// process combined groups
213
- while ( prevRowDims . length > 0 ) {
214
- const prevRowDim = prevRowDims . shift ( ) ;
214
+ while ( prevRowDimsIter . length > 0 ) {
215
+ const prevRowDim = prevRowDimsIter . pop ( ) ;
215
216
const prevRowField = prevRowDim . memberName ;
216
- const sameDimLvl = PivotUtil . getDimensionDepth ( prevRowDim ) === PivotUtil . getDimensionDepth ( row ) ;
217
217
for ( const sibling of siblingData ) {
218
218
const childCollection = sibling [ prevRowField + '_' + pivotKeys . records ] || [ ] ;
219
219
for ( const child of childCollection ) {
220
- if ( sameDimLvl ) {
221
- child [ row . memberName ] = sibling [ row . memberName ] ;
222
- }
223
220
if ( ! child [ pivotKeys . records ] ) {
224
221
continue ;
225
222
}
223
+ child [ row . memberName ] = sibling [ row . memberName ] ;
226
224
child [ row . memberName + '_' + pivotKeys . records ] = [ ] ;
227
225
const keys = Object . assign ( { } , pivotKeys ) as any ;
228
226
keys [ row . memberName ] = row . memberName ;
229
227
const hierarchyFields2 = PivotUtil
230
228
. getFieldsHierarchy ( child [ pivotKeys . records ] , [ row ] , PivotDimensionType . Row , pivotKeys ) ;
231
229
const siblingData2 = PivotUtil
232
230
. processHierarchy ( hierarchyFields2 , child ?? [ ] , keys , 0 ) ;
233
- if ( sameDimLvl ) {
234
- // add children to current level if dimensions have same depth
235
- for ( const sib of siblingData2 ) {
236
- if ( sib [ row . memberName + '_' + pivotKeys . records ] ) {
237
- child [ row . memberName + '_' + pivotKeys . records ] =
238
- child [ row . memberName + '_' + pivotKeys . records ] . concat ( sib [ row . memberName + '_' + pivotKeys . records ] ) ;
239
- child [ row . memberName ] = sib [ row . memberName ] ;
240
- }
231
+
232
+ // add children to current level
233
+ for ( const sib of siblingData2 ) {
234
+ if ( sib [ row . memberName + '_' + pivotKeys . records ] ) {
235
+ child [ row . memberName + '_' + pivotKeys . records ] =
236
+ child [ row . memberName + '_' + pivotKeys . records ] . concat ( sib [ row . memberName + '_' + pivotKeys . records ] ) ;
237
+ child [ row . memberName ] = sib [ row . memberName ] ;
241
238
}
242
- } else {
243
- // otherwise overwrite direct child collection
244
- child [ row . memberName + '_' + pivotKeys . records ] = siblingData2 ;
245
239
}
240
+
246
241
PivotUtil . processSiblingProperties ( child , siblingData2 , keys ) ;
247
- if ( prevRowDims . length > 0 ) {
248
- this . processSubGroups ( row , prevRowDims . slice ( 0 ) , siblingData2 , pivotKeys ) ;
242
+ if ( prevRowDim . childLevel ) {
243
+ // Get child dimensions now as well since we go a level deeper into the hierarchy.
244
+ // Keep above level dims as well since lower level dims correspond to upper sibling dims as well.
245
+ const childDimensions = prevRowDims . filter ( dim => ! ! dim . childLevel ) . map ( dim => dim . childLevel ) ;
246
+ this . processSubGroups ( row , [ ...prevRowDims , ...childDimensions ] , childCollection , pivotKeys ) ;
249
247
}
250
248
}
251
249
}
0 commit comments