• 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

4.05
/projects/igniteui-angular/src/lib/data-operations/pivot-strategy.ts
1

2
import { ColumnType, PivotGridType } from '../grids/common/grid.interface';
3
import { DEFAULT_PIVOT_KEYS, IPivotDimension, IPivotDimensionStrategy, IPivotGridRecord, IPivotKeys, IPivotValue, PivotDimensionType } from '../grids/pivot-grid/pivot-grid.interface';
4
import { PivotUtil } from '../grids/pivot-grid/pivot-util';
5
import { FilteringStrategy, IgxFilterItem } from './filtering-strategy';
6
import { cloneArray } from '../core/utils';
7
import { IFilteringExpressionsTree } from './filtering-expressions-tree';
8
import { IDataCloneStrategy } from './data-clone-strategy';
9

10
/* csSuppress */
11
export class NoopPivotDimensionsStrategy implements IPivotDimensionStrategy {
12
    private static _instance: NoopPivotDimensionsStrategy = null;
2✔
13

14
    public static instance(): NoopPivotDimensionsStrategy {
UNCOV
15
        return this._instance || (this._instance = new NoopPivotDimensionsStrategy());
×
16
    }
17

18
    public process(collection: any[], _: IPivotDimension[], __: IPivotValue[]): any[] {
UNCOV
19
        return collection;
×
20
    }
21
}
22

23

24
export class PivotRowDimensionsStrategy implements IPivotDimensionStrategy {
25
    private static _instance: PivotRowDimensionsStrategy = null;
2✔
26

27
    public static instance() {
UNCOV
28
        return this._instance || (this._instance = new PivotRowDimensionsStrategy());
×
29
    }
30

31
    public process(
32
        collection: any,
33
        rows: IPivotDimension[],
34
        values: IPivotValue[],
35
        cloneStrategy: IDataCloneStrategy,
36
        pivotKeys: IPivotKeys = DEFAULT_PIVOT_KEYS
×
37
    ): IPivotGridRecord[] {
38
        let hierarchies;
39
        let data: IPivotGridRecord[];
UNCOV
40
        const prevRowDims = [];
×
UNCOV
41
        const currRows = cloneArray(rows, true);
×
UNCOV
42
        PivotUtil.assignLevels(currRows);
×
43

UNCOV
44
        if (currRows.length === 0) {
×
UNCOV
45
            hierarchies = PivotUtil.getFieldsHierarchy(collection, [{ memberName: '', enabled: true }], PivotDimensionType.Row, pivotKeys, cloneStrategy);
×
46
            // generate flat data from the hierarchies
UNCOV
47
            data = PivotUtil.processHierarchy(hierarchies, pivotKeys, 0, true);
×
UNCOV
48
            return data;
×
49
        }
50

UNCOV
51
        for (const row of currRows) {
×
UNCOV
52
            if (!data) {
×
53
                // build hierarchies - groups and subgroups
UNCOV
54
                hierarchies = PivotUtil.getFieldsHierarchy(collection, [row], PivotDimensionType.Row, pivotKeys, cloneStrategy);
×
55
                // generate flat data from the hierarchies
UNCOV
56
                data = PivotUtil.processHierarchy(hierarchies, pivotKeys, 0, true);
×
UNCOV
57
                prevRowDims.push(row);
×
58
            } else {
UNCOV
59
                PivotUtil.processGroups(data, row, pivotKeys, cloneStrategy);
×
60
            }
61
        }
UNCOV
62
        return data;
×
63
    }
64
}
65

66
export class PivotColumnDimensionsStrategy implements IPivotDimensionStrategy {
67
    private static _instance: PivotRowDimensionsStrategy = null;
2✔
68

69
    public static instance() {
UNCOV
70
        return this._instance || (this._instance = new PivotColumnDimensionsStrategy());
×
71
    }
72

73
    public process(
74
        collection: IPivotGridRecord[],
75
        columns: IPivotDimension[],
76
        values: IPivotValue[],
77
        cloneStrategy: IDataCloneStrategy,
78
        pivotKeys: IPivotKeys = DEFAULT_PIVOT_KEYS
×
79
    ): any[] {
UNCOV
80
        const res = this.processHierarchy(collection, columns, values, pivotKeys, cloneStrategy);
×
UNCOV
81
        return res;
×
82
    }
83

84
    private processHierarchy(collection: IPivotGridRecord[], columns: IPivotDimension[], values, pivotKeys, cloneStrategy) {
UNCOV
85
        const result: IPivotGridRecord[] = [];
×
UNCOV
86
        collection.forEach(rec => {
×
87
            // apply aggregations based on the created groups and generate column fields based on the hierarchies
UNCOV
88
            this.groupColumns(rec, columns, values, pivotKeys, cloneStrategy);
×
UNCOV
89
            result.push(rec);
×
90
        });
UNCOV
91
        return result;
×
92
    }
93

94
    private groupColumns(rec: IPivotGridRecord, columns, values, pivotKeys, cloneStrategy) {
UNCOV
95
        const children = rec.children;
×
UNCOV
96
        if (children && children.size > 0) {
×
UNCOV
97
            children.forEach((childRecs) => {
×
UNCOV
98
                if (childRecs) {
×
UNCOV
99
                    childRecs.forEach(child => {
×
UNCOV
100
                        this.groupColumns(child, columns, values, pivotKeys, cloneStrategy);
×
101
                    })
102
                }
103
            });
104
        }
UNCOV
105
        this.applyAggregates(rec, columns, values, pivotKeys, cloneStrategy);
×
106
    }
107

108
    private applyAggregates(rec, columns, values, pivotKeys, cloneStrategy) {
UNCOV
109
        const leafRecords = this.getLeafs(rec.records, pivotKeys);
×
UNCOV
110
        const hierarchy = PivotUtil.getFieldsHierarchy(leafRecords, columns, PivotDimensionType.Column, pivotKeys, cloneStrategy);
×
UNCOV
111
        PivotUtil.applyAggregations(rec, hierarchy, values, pivotKeys)
×
112
    }
113

114
    private getLeafs(records, pivotKeys) {
UNCOV
115
        let leafs = [];
×
UNCOV
116
        for (const rec of records) {
×
UNCOV
117
            if (rec[pivotKeys.records]) {
×
118
                leafs = leafs.concat(this.getLeafs(rec[pivotKeys.records], pivotKeys));
×
119
            } else {
UNCOV
120
                leafs.push(rec);
×
121
            }
122
        }
UNCOV
123
        return leafs;
×
124
    }
125
}
126

127
export class DimensionValuesFilteringStrategy extends FilteringStrategy {
128

129
    /**
130
     * Creates a new instance of FormattedValuesFilteringStrategy.
131
     *
132
     * @param fields An array of column field names that should be formatted.
133
     * If omitted the values of all columns which has formatter will be formatted.
134
     */
UNCOV
135
    constructor(private fields?: string[]) {
×
UNCOV
136
        super();
×
137
    }
138

139
    protected override getFieldValue(rec: any, fieldName: string, _isDate = false, _isTime = false,
×
140
        grid?: PivotGridType): any {
UNCOV
141
        const allDimensions = grid.allDimensions;
×
UNCOV
142
        const enabledDimensions = allDimensions.filter(x => x && x.enabled);
×
UNCOV
143
        const dim :IPivotDimension = PivotUtil.flatten(enabledDimensions).find(x => x.memberName === fieldName);
×
UNCOV
144
        const value = dim.childLevel ? this._getDimensionValueHierarchy(dim, rec).map(x => `[` + x +`]`).join('.') : PivotUtil.extractValueFromDimension(dim, rec);
×
UNCOV
145
        return value;
×
146
    }
147

148
    public override getFilterItems(column: ColumnType, tree: IFilteringExpressionsTree): Promise<IgxFilterItem[]> {
UNCOV
149
        const grid = (column.grid as any);
×
UNCOV
150
        const enabledDimensions = grid.allDimensions.filter(x => x && x.enabled);
×
UNCOV
151
        const data = column.grid.gridAPI.filterDataByExpressions(tree);
×
UNCOV
152
        const dim = enabledDimensions.find(x => x.memberName === column.field);
×
UNCOV
153
        const allValuesHierarchy = PivotUtil.getFieldsHierarchy(
×
154
            data,
155
            [dim],
156
            PivotDimensionType.Column,
157
            grid.pivotKeys,
158
            grid.pivotValueCloneStrategy
159
        );
UNCOV
160
        const isNoop = grid.pivotConfiguration.columnStrategy instanceof NoopPivotDimensionsStrategy || grid.pivotConfiguration.rowStrategy instanceof NoopPivotDimensionsStrategy;
×
UNCOV
161
        const items: IgxFilterItem[] = !isNoop ? this._getFilterItems(allValuesHierarchy, grid.pivotKeys) : [{value : ''}];
×
UNCOV
162
        return Promise.resolve(items);
×
163
    }
164

165
    private _getFilterItems(hierarchy: Map<string, any>, pivotKeys: IPivotKeys) : IgxFilterItem[] {
UNCOV
166
        const items:  IgxFilterItem[] = [];
×
UNCOV
167
        hierarchy.forEach((value) => {
×
UNCOV
168
            const val = value.value;
×
UNCOV
169
            const path = val.split(pivotKeys.columnDimensionSeparator);
×
UNCOV
170
            const hierarchicalValue = path.length > 1 ? path.map(x => `[` + x +`]`).join('.') : val;
×
UNCOV
171
            const text = path[path.length -1];
×
UNCOV
172
            items.push({
×
173
                value: hierarchicalValue,
174
                label: text,
175
                children: this._getFilterItems(value.children, pivotKeys)
176
            });
177
        });
UNCOV
178
        return items;
×
179
    }
180

181
    private _getDimensionValueHierarchy(dim: IPivotDimension, rec: any) : string[] {
UNCOV
182
        let path = [];
×
UNCOV
183
        const value = PivotUtil.extractValueFromDimension(dim, rec);
×
UNCOV
184
        path.push(value);
×
UNCOV
185
        if (dim.childLevel) {
×
UNCOV
186
            const childVals = this._getDimensionValueHierarchy(dim.childLevel, rec);
×
UNCOV
187
            path = path.concat(childVals);
×
188
        }
UNCOV
189
        return path;
×
190
    }
191
}
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