• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

IgniteUI / igniteui-angular / 13331632524

14 Feb 2025 02:51PM CUT coverage: 22.015% (-69.6%) from 91.622%
13331632524

Pull #15372

github

web-flow
Merge d52d57714 into bcb78ae0a
Pull Request #15372: chore(*): test ci passing

1990 of 15592 branches covered (12.76%)

431 of 964 new or added lines in 18 files covered. (44.71%)

19956 existing lines in 307 files now uncovered.

6452 of 29307 relevant lines covered (22.02%)

249.17 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-util.ts
1
import { IDataCloneStrategy } from '../../data-operations/data-clone-strategy';
2
import { DataUtil, GridColumnDataType } from '../../data-operations/data-util';
3
import { FilteringLogic } from '../../data-operations/filtering-expression.interface';
4
import { FilteringExpressionsTree } from '../../data-operations/filtering-expressions-tree';
5
import { ISortingExpression } from '../../data-operations/sorting-strategy';
6
import { PivotGridType } from '../common/grid.interface';
7
import { IGridSortingStrategy, IgxSorting } from '../common/strategy';
8
import { IgxPivotAggregate, IgxPivotDateAggregate, IgxPivotNumericAggregate, IgxPivotTimeAggregate } from './pivot-grid-aggregate';
9
import { IPivotAggregator, IPivotConfiguration, IPivotDimension, IPivotGridRecord, IPivotKeys, IPivotValue, PivotDimensionType, PivotSummaryPosition } from './pivot-grid.interface';
10

11
export class PivotUtil {
12

13
    // go through all children and apply new dimension groups as child
14
    public static processGroups(recs: IPivotGridRecord[], dimension: IPivotDimension, pivotKeys: IPivotKeys, cloneStrategy: IDataCloneStrategy) {
UNCOV
15
        for (const rec of recs) {
×
16
            // process existing children
UNCOV
17
            if (rec.children && rec.children.size > 0) {
×
18
                // process hierarchy in dept
UNCOV
19
                rec.children.forEach((values) => {
×
UNCOV
20
                    this.processGroups(values, dimension, pivotKeys, cloneStrategy);
×
21
                });
22
            }
23
            // add children for current dimension
UNCOV
24
            const hierarchyFields = PivotUtil
×
25
                .getFieldsHierarchy(rec.records, [dimension], PivotDimensionType.Row, pivotKeys, cloneStrategy);
UNCOV
26
            const siblingData = PivotUtil
×
27
                .processHierarchy(hierarchyFields, pivotKeys, 0);
UNCOV
28
            rec.children.set(dimension.memberName, siblingData);
×
29
        }
30
    }
31

32
    public static flattenGroups(data: IPivotGridRecord[], dimension: IPivotDimension, expansionStates, defaultExpand: boolean, parent?: IPivotDimension, parentRec?: IPivotGridRecord) {
UNCOV
33
        for (let i = 0; i < data.length; i++) {
×
UNCOV
34
            const rec = data[i];
×
UNCOV
35
            const field = dimension.memberName;
×
UNCOV
36
            if (!field) {
×
37
                continue;
×
38
            }
39

UNCOV
40
            let recordsData = rec.children.get(field);
×
UNCOV
41
            if (!recordsData && parent) {
×
42
                // check parent
UNCOV
43
                recordsData = rec.children.get(parent.memberName);
×
UNCOV
44
                if (recordsData) {
×
UNCOV
45
                    dimension = parent;
×
46
                }
47
            }
48

UNCOV
49
            if (parentRec) {
×
UNCOV
50
                parentRec.dimensionValues.forEach((value, key) => {
×
UNCOV
51
                    if (parent.memberName !== key) {
×
UNCOV
52
                        rec.dimensionValues.set(key, value);
×
UNCOV
53
                        const dim = parentRec.dimensions.find(x => x.memberName === key);
×
UNCOV
54
                        rec.dimensions.unshift(dim);
×
55
                    }
56

57
                });
58
            }
59

60

UNCOV
61
            const expansionRowKey = PivotUtil.getRecordKey(rec, dimension);
×
UNCOV
62
            const isExpanded = expansionStates.get(expansionRowKey) === undefined ?
×
63
                defaultExpand :
64
                expansionStates.get(expansionRowKey);
UNCOV
65
            const shouldExpand = isExpanded || !dimension.childLevel || !rec.dimensionValues.get(dimension.memberName);
×
UNCOV
66
            if (shouldExpand && recordsData) {
×
UNCOV
67
                if (dimension.childLevel) {
×
UNCOV
68
                    this.flattenGroups(recordsData, dimension.childLevel, expansionStates, defaultExpand, dimension, rec);
×
69
                } else {
70
                    // copy parent values and dims in child
UNCOV
71
                    recordsData.forEach(x => {
×
UNCOV
72
                        rec.dimensionValues.forEach((value, key) => {
×
UNCOV
73
                            if (dimension.memberName !== key) {
×
UNCOV
74
                                x.dimensionValues.set(key, value);
×
UNCOV
75
                                const dim = rec.dimensions.find(y => y.memberName === key);
×
UNCOV
76
                                x.dimensions.unshift(dim);
×
77
                            }
78

79
                        });
80
                    });
81
                }
82

UNCOV
83
                data.splice(i + 1, 0, ...recordsData);
×
UNCOV
84
                i += recordsData.length;
×
85

86
            }
87
        }
88
    }
89

90
    public static flattenGroupsHorizontally(data: IPivotGridRecord[],
91
                                            dimension: IPivotDimension,
92
                                            expansionStates,
93
                                            defaultExpand: boolean,
94
                                            visibleDimensions: IPivotDimension[],
95
                                            summariesPosition: PivotSummaryPosition,
96
                                            parent?: IPivotDimension,
97
                                            parentRec?: IPivotGridRecord) {
UNCOV
98
        for (let i = 0; i < data.length; i++) {
×
UNCOV
99
            const rec = data[i];
×
UNCOV
100
            const field = dimension.memberName;
×
UNCOV
101
            if (!field) {
×
102
                continue;
×
103
            }
104

UNCOV
105
            if (!visibleDimensions.find(recDim => recDim.memberName === rec.dimensions[0].memberName)) {
×
UNCOV
106
                visibleDimensions.push(rec.dimensions[0]);
×
107
            }
108

UNCOV
109
            let recordsData = rec.children.get(field);
×
UNCOV
110
            if (!recordsData && parent) {
×
111
                // check parent
UNCOV
112
                recordsData = rec.children.get(parent.memberName);
×
UNCOV
113
                if (recordsData) {
×
UNCOV
114
                    dimension = parent;
×
115
                }
116
            }
117

UNCOV
118
            if (parentRec) {
×
UNCOV
119
                parentRec.dimensionValues.forEach((value, key) => {
×
UNCOV
120
                    rec.dimensionValues.set(key, value);
×
UNCOV
121
                    const dim = parentRec.dimensions.find(x => x.memberName === key);
×
UNCOV
122
                    rec.dimensions.unshift(dim);
×
123
                });
124
            }
125

UNCOV
126
            const expansionRowKey = PivotUtil.getRecordKey(rec, dimension);
×
UNCOV
127
            const isExpanded = expansionStates.get(expansionRowKey) === undefined ?
×
128
                defaultExpand :
129
                expansionStates.get(expansionRowKey);
UNCOV
130
            const shouldExpand = isExpanded || !dimension.childLevel || !rec.dimensionValues.get(dimension.memberName);
×
UNCOV
131
            if (shouldExpand && recordsData && !rec.totalRecordDimensionName) {
×
UNCOV
132
                if (dimension.childLevel) {
×
UNCOV
133
                    this.flattenGroupsHorizontally(recordsData, dimension.childLevel, expansionStates, defaultExpand, visibleDimensions, summariesPosition, dimension, rec);
×
134
                } else {
135
                    // copy parent values and dims in child
136
                    recordsData.forEach(x => {
×
137
                        rec.dimensionValues.forEach((value, key) => {
×
138
                            if (dimension.memberName !== key) {
×
139
                                x.dimensionValues.set(key, value);
×
140
                                const dim = rec.dimensions.find(y => y.memberName === key);
×
141
                                x.dimensions.unshift(dim);
×
142
                            }
143

144
                        });
145
                    });
146
                }
147

UNCOV
148
                recordsData.forEach((childRec) => {
×
UNCOV
149
                    if (childRec.dimensions.length === 1) {
×
150
                        rec.dimensionValues.forEach((value: string, key) => {
×
151
                            childRec.dimensionValues.set(key, value);
×
152
                        });
153
                    }
154

UNCOV
155
                    childRec.dimensions.forEach((dim) => {
×
UNCOV
156
                        if (!visibleDimensions.find(recDim => recDim.memberName === dim.memberName)) {
×
157
                            visibleDimensions.push(dim);
×
158
                        }
159
                    });
160
                });
161

UNCOV
162
                const curDimValue = rec.dimensionValues.get(dimension.memberName);
×
UNCOV
163
                if (dimension.horizontalSummary && curDimValue) {
×
UNCOV
164
                    rec.totalRecordDimensionName = dimension.memberName;
×
UNCOV
165
                    rec.dimensionValues.set(dimension.memberName, `${curDimValue} Total`);
×
UNCOV
166
                    if (summariesPosition === PivotSummaryPosition.Top) {
×
UNCOV
167
                        recordsData.unshift(rec);
×
168
                    } else {
UNCOV
169
                        recordsData.push(rec);
×
170
                    }
171
                }
172

UNCOV
173
                data.splice(i, 1, ...recordsData);
×
UNCOV
174
                i += recordsData.length - 1;
×
175

176
            }
177
        }
178
    }
179

180
    public static assignLevels(dims) {
UNCOV
181
        for (const dim of dims) {
×
UNCOV
182
            let currDim = dim;
×
UNCOV
183
            let lvl = 0;
×
UNCOV
184
            while (currDim.childLevel) {
×
UNCOV
185
                currDim.level = lvl;
×
UNCOV
186
                currDim = currDim.childLevel;
×
UNCOV
187
                lvl++;
×
188
            }
UNCOV
189
            currDim.level = lvl;
×
190
        }
191
    }
192
    public static getFieldsHierarchy(data: any[], dimensions: IPivotDimension[],
193
        dimensionType: PivotDimensionType, pivotKeys: IPivotKeys, cloneStrategy: IDataCloneStrategy): Map<string, any> {
UNCOV
194
        const hierarchy = new Map<string, any>();
×
UNCOV
195
        for (const rec of data) {
×
UNCOV
196
            const vals = dimensionType === PivotDimensionType.Column ?
×
197
                this.extractValuesForColumn(dimensions, rec, pivotKeys) :
198
                this.extractValuesForRow(dimensions, rec, pivotKeys, cloneStrategy);
UNCOV
199
            for (const [_key, val] of vals) { // this should go in depth also vals.children
×
UNCOV
200
                if (hierarchy.get(val.value) != null) {
×
UNCOV
201
                    this.applyHierarchyChildren(hierarchy, val, rec, pivotKeys);
×
202
                } else {
UNCOV
203
                    hierarchy.set(val.value, cloneStrategy.clone(val));
×
UNCOV
204
                    this.applyHierarchyChildren(hierarchy, val, rec, pivotKeys);
×
205
                }
206
            }
207
        }
UNCOV
208
        return hierarchy;
×
209
    }
210

211
    public static sort(data: IPivotGridRecord[], expressions: ISortingExpression[], sorting: IGridSortingStrategy = new IgxSorting()): any[] {
×
UNCOV
212
        data.forEach(rec => {
×
UNCOV
213
            const children = rec.children;
×
UNCOV
214
            if (children) {
×
UNCOV
215
                children.forEach(x => {
×
UNCOV
216
                    this.sort(x, expressions, sorting);
×
217
                });
218
            }
219
        });
UNCOV
220
        return DataUtil.sort(data, expressions, sorting);
×
221
    }
222

223
    public static extractValueFromDimension(dim: IPivotDimension, recData: any) {
UNCOV
224
        return dim.memberFunction ? dim.memberFunction.call(null, recData) : recData[dim.memberName];
×
225
    }
226

227
    public static getDimensionDepth(dim: IPivotDimension): number {
UNCOV
228
        let lvl = 0;
×
UNCOV
229
        while (dim.childLevel) {
×
UNCOV
230
            lvl++;
×
UNCOV
231
            dim = dim.childLevel;
×
232
        }
UNCOV
233
        return lvl;
×
234
    }
235

236
    public static extractValuesForRow(dims: IPivotDimension[], recData: any, pivotKeys: IPivotKeys, cloneStrategy: IDataCloneStrategy) {
UNCOV
237
        const values = new Map<string, any>();
×
UNCOV
238
        for (const col of dims) {
×
UNCOV
239
            if (recData[pivotKeys.level] && recData[pivotKeys.level] > 0) {
×
240
                const childData = recData[pivotKeys.records];
×
241
                return this.getFieldsHierarchy(childData, [col], PivotDimensionType.Row, pivotKeys, cloneStrategy);
×
242
            }
243

UNCOV
244
            const value = this.extractValueFromDimension(col, recData);
×
UNCOV
245
            const objValue = {};
×
UNCOV
246
            objValue['value'] = value;
×
UNCOV
247
            objValue['dimension'] = col;
×
UNCOV
248
            if (col.childLevel) {
×
UNCOV
249
                const childValues = this.extractValuesForRow([col.childLevel], recData, pivotKeys, cloneStrategy);
×
UNCOV
250
                objValue[pivotKeys.children] = childValues;
×
251
            }
UNCOV
252
            values.set(value, objValue);
×
253
        }
254

UNCOV
255
        return values;
×
256
    }
257

258
    public static extractValuesForColumn(dims: IPivotDimension[], recData: any, pivotKeys: IPivotKeys, path = []) {
×
UNCOV
259
        const vals = new Map<string, any>();
×
UNCOV
260
        let lvlCollection = vals;
×
UNCOV
261
        const flattenedDims = this.flatten(dims);
×
UNCOV
262
        for (const col of flattenedDims) {
×
UNCOV
263
            const value = this.extractValueFromDimension(col, recData);
×
UNCOV
264
            path.push(value);
×
UNCOV
265
            const newValue = path.join(pivotKeys.columnDimensionSeparator);
×
UNCOV
266
            const newObj = { value: newValue, expandable: col.expandable, children: null, dimension: col };
×
UNCOV
267
            if (!newObj.children) {
×
UNCOV
268
                newObj.children = new Map<string, any>();
×
269
            }
UNCOV
270
            lvlCollection.set(newValue, newObj);
×
UNCOV
271
            lvlCollection = newObj.children;
×
272
        }
UNCOV
273
        return vals;
×
274
    }
275

276
    public static flatten(arr, lvl = 0) {
×
UNCOV
277
        const newArr = arr.reduce((acc, item) => {
×
UNCOV
278
            if (item) {
×
UNCOV
279
                item.level = lvl;
×
UNCOV
280
                acc.push(item);
×
UNCOV
281
                if (item.childLevel) {
×
UNCOV
282
                    item.expandable = true;
×
UNCOV
283
                    acc = acc.concat(this.flatten([item.childLevel], lvl + 1));
×
284
                }
285
            }
UNCOV
286
            return acc;
×
287
        }, []);
UNCOV
288
        return newArr;
×
289
    }
290

291
    public static applyAggregations(rec: IPivotGridRecord, hierarchies, values, pivotKeys: IPivotKeys) {
UNCOV
292
        if (hierarchies.size === 0) {
×
293
            // no column groups
UNCOV
294
            const aggregationResult = this.aggregate(rec.records, values);
×
UNCOV
295
            this.applyAggregationRecordData(aggregationResult, undefined, rec, pivotKeys);
×
UNCOV
296
            return;
×
297
        }
UNCOV
298
        hierarchies.forEach((hierarchy) => {
×
UNCOV
299
            const children = hierarchy[pivotKeys.children];
×
UNCOV
300
            if (children && children.size > 0) {
×
UNCOV
301
                this.applyAggregations(rec, children, values, pivotKeys);
×
UNCOV
302
                const childRecords = this.collectRecords(children, pivotKeys);
×
UNCOV
303
                hierarchy[pivotKeys.aggregations] = this.aggregate(childRecords, values);
×
UNCOV
304
                this.applyAggregationRecordData(hierarchy[pivotKeys.aggregations], hierarchy.value, rec, pivotKeys);
×
UNCOV
305
            } else if (hierarchy[pivotKeys.records]) {
×
UNCOV
306
                hierarchy[pivotKeys.aggregations] = this.aggregate(hierarchy[pivotKeys.records], values);
×
UNCOV
307
                this.applyAggregationRecordData(hierarchy[pivotKeys.aggregations], hierarchy.value, rec, pivotKeys);
×
308
            }
309
        });
310
    }
311

312
    protected static applyAggregationRecordData(aggregationData: any, groupName: string, rec: IPivotGridRecord, pivotKeys: IPivotKeys) {
UNCOV
313
        const aggregationKeys = Object.keys(aggregationData);
×
UNCOV
314
        if (aggregationKeys.length > 1) {
×
UNCOV
315
            aggregationKeys.forEach((key) => {
×
UNCOV
316
                const aggregationKey = groupName ? groupName + pivotKeys.columnDimensionSeparator + key : key;
×
UNCOV
317
                rec.aggregationValues.set(aggregationKey, aggregationData[key]);
×
318
            });
UNCOV
319
        } else  if (aggregationKeys.length === 1) {
×
UNCOV
320
            const aggregationKey = aggregationKeys[0];
×
UNCOV
321
            rec.aggregationValues.set(groupName || aggregationKey, aggregationData[aggregationKey]);
×
322
        }
323
    }
324

325
    public static aggregate(records, values: IPivotValue[]) {
UNCOV
326
        const result = {};
×
UNCOV
327
        for (const pivotValue of values) {
×
UNCOV
328
            const aggregator = PivotUtil.getAggregatorForType(pivotValue.aggregate, pivotValue.dataType);
×
UNCOV
329
            if (!aggregator) {
×
330
                throw `No valid aggregator found for ${pivotValue.member}. Please set either a valid aggregatorName or aggregator`;
×
331
            }
UNCOV
332
            result[pivotValue.member] = aggregator(records.map(r => r[pivotValue.member]), records);
×
333
        }
334

UNCOV
335
        return result;
×
336
    }
337

338
    public static getAggregatorForType(aggregate: IPivotAggregator, dataType: GridColumnDataType) {
UNCOV
339
        let aggregator = aggregate.aggregator;
×
UNCOV
340
        if (aggregate.aggregatorName) {
×
UNCOV
341
            let aggregators = IgxPivotNumericAggregate.aggregators();
×
UNCOV
342
            if (!dataType || dataType === 'date' || dataType === 'dateTime') {
×
UNCOV
343
                aggregators = aggregators.concat(IgxPivotDateAggregate.aggregators())
×
UNCOV
344
            } else if (dataType === 'time') {
×
345
                aggregators = aggregators.concat(IgxPivotTimeAggregate.aggregators());
×
346
            }
UNCOV
347
            aggregator = aggregators.find(x => x.key.toLocaleLowerCase() === aggregate.aggregatorName.toLocaleLowerCase())?.aggregator;
×
348
        }
UNCOV
349
        return aggregator;
×
350
    }
351

352
    public static processHierarchy(hierarchies, pivotKeys, level = 0, rootData = false): IPivotGridRecord[] {
×
UNCOV
353
        const flatData: IPivotGridRecord[] = [];
×
UNCOV
354
        hierarchies.forEach((h, key) => {
×
UNCOV
355
            const field = h.dimension.memberName;
×
UNCOV
356
            const rec: IPivotGridRecord = {
×
357
                dimensionValues: new Map<string, string>(),
358
                aggregationValues: new Map<string, string>(),
359
                children: new Map<string, IPivotGridRecord[]>(),
360
                dimensions: [h.dimension]
361
            };
UNCOV
362
            rec.dimensionValues.set(field, key);
×
UNCOV
363
            if (h[pivotKeys.records]) {
×
UNCOV
364
                rec.records = this.getDirectLeafs(h[pivotKeys.records]);
×
365
            }
UNCOV
366
            rec.level = level;
×
UNCOV
367
            flatData.push(rec);
×
UNCOV
368
            if (h[pivotKeys.children] && h[pivotKeys.children].size > 0) {
×
UNCOV
369
                const nestedData = this.processHierarchy(h[pivotKeys.children],
×
370
                    pivotKeys, level + 1, rootData);
UNCOV
371
                rec.records = this.getDirectLeafs(nestedData);
×
UNCOV
372
                rec.children.set(field, nestedData);
×
373
            }
374
        });
375

UNCOV
376
        return flatData;
×
377
    }
378

379
    public static getDirectLeafs(records: IPivotGridRecord[]) {
UNCOV
380
        let leafs = [];
×
UNCOV
381
        for (const rec of records) {
×
UNCOV
382
            if (rec.records) {
×
UNCOV
383
                const data = rec.records.filter(x => !x.records && leafs.indexOf(x) === -1);
×
UNCOV
384
                leafs = leafs.concat(data);
×
385
            } else {
UNCOV
386
                leafs.push(rec);
×
387
            }
388
        }
UNCOV
389
        return leafs;
×
390
    }
391

392
    public static getRecordKey(rec: IPivotGridRecord, currentDim: IPivotDimension) {
UNCOV
393
        const parentFields = [];
×
394

UNCOV
395
        const currentDimIndex = rec.dimensions.findIndex(x => x.memberName === currentDim.memberName) + 1;
×
UNCOV
396
        const prevDims = rec.dimensions.slice(0, currentDimIndex);
×
UNCOV
397
        for (const prev of prevDims) {
×
UNCOV
398
            const prevValue = rec.dimensionValues.get(prev.memberName);
×
UNCOV
399
            parentFields.push(prevValue);
×
400
        }
401

UNCOV
402
        return parentFields.join('-');
×
403
    }
404

405
    public static buildExpressionTree(config: IPivotConfiguration) {
UNCOV
406
        const allDimensions = (config?.rows || []).concat((config?.columns || [])).concat(config?.filters || []).filter(x => x !== null && x !== undefined);
×
UNCOV
407
        const enabledDimensions = allDimensions.filter(x => x && x.enabled);
×
408

UNCOV
409
        const expressionsTree = new FilteringExpressionsTree(FilteringLogic.And);
×
410
        // add expression trees from all filters
UNCOV
411
        PivotUtil.flatten(enabledDimensions).forEach((x: IPivotDimension) => {
×
UNCOV
412
            if (x.filter && x.filter.filteringOperands) {
×
UNCOV
413
                expressionsTree.filteringOperands.push(...x.filter.filteringOperands);
×
414
            }
415
        });
416

UNCOV
417
        return expressionsTree;
×
418
    }
419

420
    private static collectRecords(children, pivotKeys: IPivotKeys) {
UNCOV
421
        let result = [];
×
UNCOV
422
        children.forEach(value => result = result.concat(value[pivotKeys.records]));
×
UNCOV
423
        return result;
×
424
    }
425

426
    private static applyHierarchyChildren(hierarchy, val, rec, pivotKeys: IPivotKeys) {
UNCOV
427
        const recordsKey = pivotKeys.records;
×
UNCOV
428
        const childKey = pivotKeys.children;
×
UNCOV
429
        const childCollection = val[childKey];
×
UNCOV
430
        const hierarchyValue = hierarchy.get(val.value);
×
UNCOV
431
        if (Array.isArray(hierarchyValue[childKey])) {
×
432
            hierarchyValue[childKey] = new Map<string, any>();
×
433
        }
UNCOV
434
        if (!childCollection || childCollection.size === 0) {
×
UNCOV
435
            const dim = hierarchyValue.dimension;
×
UNCOV
436
            const isValid = this.extractValueFromDimension(dim, rec) === val.value;
×
UNCOV
437
            if (isValid) {
×
UNCOV
438
                if (hierarchyValue[recordsKey]) {
×
UNCOV
439
                    hierarchyValue[recordsKey].push(rec);
×
440
                } else {
UNCOV
441
                    hierarchyValue[recordsKey] = [rec];
×
442
                }
443
            }
444
        } else {
UNCOV
445
            const hierarchyChild = hierarchyValue[childKey];
×
UNCOV
446
            for (const [_key, child] of childCollection) {
×
UNCOV
447
                let hierarchyChildValue = hierarchyChild.get(child.value);
×
UNCOV
448
                if (!hierarchyChildValue) {
×
UNCOV
449
                    hierarchyChild.set(child.value, child);
×
UNCOV
450
                    hierarchyChildValue = child;
×
451
                }
452

UNCOV
453
                if (hierarchyChildValue[recordsKey]) {
×
UNCOV
454
                    const copy = Object.assign({}, rec);
×
UNCOV
455
                    if (rec[recordsKey]) {
×
456
                        // not all nested children are valid
457
                        const nestedValue = hierarchyChildValue.value;
×
458
                        const dimension = hierarchyChildValue.dimension;
×
459
                        const validRecs = rec[recordsKey].filter(x => this.extractValueFromDimension(dimension, x) === nestedValue);
×
460
                        copy[recordsKey] = validRecs;
×
461
                    }
UNCOV
462
                    hierarchyChildValue[recordsKey].push(copy);
×
463
                } else {
UNCOV
464
                    hierarchyChildValue[recordsKey] = [rec];
×
465
                }
466

UNCOV
467
                if (child[childKey] && child[childKey].size > 0) {
×
UNCOV
468
                    this.applyHierarchyChildren(hierarchyChild, child, rec, pivotKeys);
×
469
                }
470
            }
471
        }
472
    }
473

474
    public static getAggregateList(val: IPivotValue, grid: PivotGridType): IPivotAggregator[] {
UNCOV
475
        if (!val.aggregateList) {
×
UNCOV
476
            let defaultAggr = this.getAggregatorsForValue(val, grid);
×
UNCOV
477
            const isDefault = defaultAggr.find(
×
UNCOV
478
                (x) => x.key === val.aggregate.key
×
479
            );
480
            // resolve custom aggregations
UNCOV
481
            if (!isDefault && grid.data[0][val.member] !== undefined) {
×
482
                // if field exists, then we can apply default aggregations and add the custom one.
483
                defaultAggr.unshift(val.aggregate);
×
UNCOV
484
            } else if (!isDefault) {
×
485
                // otherwise this is a custom aggregation that is not compatible
486
                // with the defaults, since it operates on field that is not in the data
487
                // leave only the custom one.
488
                defaultAggr = [val.aggregate];
×
489
            }
UNCOV
490
            val.aggregateList = defaultAggr;
×
491
        }
UNCOV
492
        return val.aggregateList;
×
493
    }
494

495
    public static getAggregatorsForValue(value: IPivotValue, grid: PivotGridType): IPivotAggregator[] {
UNCOV
496
        const dataType = value.dataType || grid.resolveDataTypes(grid.data[0][value.member]);
×
UNCOV
497
        switch (dataType) {
×
498
            case GridColumnDataType.Number:
499
            case GridColumnDataType.Currency:
UNCOV
500
                return IgxPivotNumericAggregate.aggregators();
×
501
            case GridColumnDataType.Date:
502
            case GridColumnDataType.DateTime:
503
                return IgxPivotDateAggregate.aggregators();
×
504
            case GridColumnDataType.Time:
505
                return IgxPivotTimeAggregate.aggregators();
×
506
            default:
507
                return IgxPivotAggregate.aggregators();
×
508
        }
509
    }
510

511

512
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc