• 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

46.88
/projects/igniteui-angular/src/lib/grids/summaries/grid-summary.ts
1
import { IGroupByRecord } from '../../data-operations/groupby-record.interface';
2

3
/* tsPlainInterface */
4
/* marshalByValue */
5
export interface ISummaryExpression {
6
    fieldName: string;
7
    /* blazorCSSuppress */
8
    customSummary?: any;
9
}
10

11
/* tsPlainInterface */
12
/* marshalByValue */
13
export interface IgxSummaryResult {
14
    key: string;
15
    label: string;
16
    /* blazorAlternateName: Result */
17
    summaryResult: any;
18
    /**
19
     * Apply default formatting based on the grid column type.
20
     * ```typescript
21
     * const result: IgxSummaryResult = {
22
     *   key: 'key',
23
     *   label: 'label',
24
     *   defaultFormatting: true
25
     * }
26
     * ```
27
     *
28
     * @memberof IgxSummaryResult
29
     */
30
    defaultFormatting?: boolean;
31
}
32

33
export interface ISummaryRecord {
34
    summaries: Map<string, IgxSummaryResult[]>;
35
    max?: number;
36
    cellIndentation?: number;
37
}
38

39
const clear = (el) => el === 0 || Boolean(el);
3,312✔
40
const first = (arr) => arr[0];
2✔
41
const last = (arr) => arr[arr.length - 1];
2✔
42

43
/* blazorCSSuppress */
44
export class IgxSummaryOperand {
45
    /**
46
     * Counts all the records in the data source.
47
     * If filtering is applied, counts only the filtered records.
48
     * ```typescript
49
     * IgxSummaryOperand.count(dataSource);
50
     * ```
51
     *
52
     * @memberof IgxSummaryOperand
53
     */
54
    public static count(data: any[]): number {
55
        return data.length;
539✔
56
    }
57
    /**
58
     * Executes the static `count` method and returns `IgxSummaryResult[]`.
59
     * ```typescript
60
     * interface IgxSummaryResult {
61
     *   key: string;
62
     *   label: string;
63
     *   summaryResult: any;
64
     * }
65
     * ```
66
     * Can be overridden in the inherited classes to provide customization for the `summary`.
67
     * ```typescript
68
     * class CustomSummary extends IgxSummaryOperand {
69
     *   constructor() {
70
     *     super();
71
     *   }
72
     *   public operate(data: any[], allData: any[], fieldName: string, groupRecord: IGroupByRecord): IgxSummaryResult[] {
73
     *     const result = [];
74
     *     result.push({
75
     *       key: "test",
76
     *       label: "Test",
77
     *       summaryResult: IgxSummaryOperand.count(data)
78
     *     });
79
     *     return result;
80
     *   }
81
     * }
82
     * this.grid.getColumnByName('ColumnName').summaries = CustomSummary;
83
     * ```
84
     *
85
     * @memberof IgxSummaryOperand
86
     */
87
    public operate(data: any[] = [], _allData: any[] = [], _fieldName?: string, _groupRecord?: IGroupByRecord): IgxSummaryResult[] {
×
88
        return [{
480✔
89
            key: 'count',
90
            label: 'Count',
91
            defaultFormatting: false,
92
            summaryResult: IgxSummaryOperand.count(data)
93
        }];
94
    }
95
}
96

97
/* blazorCSSuppress */
98
// @dynamic
99
export class IgxNumberSummaryOperand extends IgxSummaryOperand {
100
    /**
101
     * Returns the minimum numeric value in the provided data records.
102
     * If filtering is applied, returns the minimum value in the filtered data records.
103
     * ```typescript
104
     * IgxNumberSummaryOperand.min(data);
105
     * ```
106
     *
107
     * @memberof IgxNumberSummaryOperand
108
     */
109
    public static min(data: any[]): number {
110
        return data.length && data.filter(clear).length ? data.filter(clear).reduce((a, b) => Math.min(a, b)) : 0;
266✔
111
    }
112
    /**
113
     * Returns the maximum numeric value in the provided data records.
114
     * If filtering is applied, returns the maximum value in the filtered data records.
115
     * ```typescript
116
     * IgxNumberSummaryOperand.max(data);
117
     * ```
118
     *
119
     * @memberof IgxNumberSummaryOperand
120
     */
121
    public static max(data: any[]): number {
122
        return data.length && data.filter(clear).length ? data.filter(clear).reduce((a, b) => Math.max(a, b)) : 0;
266✔
123
    }
124
    /**
125
     * Returns the sum of the numeric values in the provided data records.
126
     * If filtering is applied, returns the sum of the numeric values in the data records.
127
     * ```typescript
128
     * IgxNumberSummaryOperand.sum(data);
129
     * ```
130
     *
131
     * @memberof IgxNumberSummaryOperand
132
     */
133
    public static sum(data: any[]): number {
134
        return data.length && data.filter(clear).length ? data.filter(clear).reduce((a, b) => +a + +b) : 0;
532✔
135
    }
136
    /**
137
     * Returns the average numeric value in the data provided data records.
138
     * If filtering is applied, returns the average numeric value in the filtered data records.
139
     * ```typescript
140
     * IgxSummaryOperand.average(data);
141
     * ```
142
     *
143
     * @memberof IgxNumberSummaryOperand
144
     */
145
    public static average(data: any[]): number {
146
        return data.length && data.filter(clear).length ? this.sum(data) / this.count(data) : 0;
234✔
147
    }
148
    /**
149
     * Executes the static methods and returns `IgxSummaryResult[]`.
150
     * ```typescript
151
     * interface IgxSummaryResult {
152
     *   key: string;
153
     *   label: string;
154
     *   summaryResult: any;
155
     * }
156
     * ```
157
     * Can be overridden in the inherited classes to provide customization for the `summary`.
158
     * ```typescript
159
     * class CustomNumberSummary extends IgxNumberSummaryOperand {
160
     *   constructor() {
161
     *     super();
162
     *   }
163
     *   public operate(data: any[], allData: any[], fieldName: string, groupRecord: IGroupByRecord): IgxSummaryResult[] {
164
     *     const result = super.operate(data, allData, fieldName, groupRecord);
165
     *     result.push({
166
     *       key: "avg",
167
     *       label: "Avg",
168
     *       summaryResult: IgxNumberSummaryOperand.average(data)
169
     *     });
170
     *     result.push({
171
     *       key: 'mdn',
172
     *       label: 'Median',
173
     *       summaryResult: this.findMedian(data)
174
     *     });
175
     *     return result;
176
     *   }
177
     * }
178
     * this.grid.getColumnByName('ColumnName').summaries = CustomNumberSummary;
179
     * ```
180
     *
181
     * @memberof IgxNumberSummaryOperand
182
     */
183
    public override operate(data: any[] = [], allData: any[] = [], fieldName?: string, groupRecord?: IGroupByRecord): IgxSummaryResult[] {
×
184
        const result = super.operate(data, allData, fieldName, groupRecord);
234✔
185
        result.push({
234✔
186
            key: 'min',
187
            label: 'Min',
188
            defaultFormatting: true,
189
            summaryResult: IgxNumberSummaryOperand.min(data)
190
        });
191
        result.push({
234✔
192
            key: 'max',
193
            label: 'Max',
194
            defaultFormatting: true,
195
            summaryResult: IgxNumberSummaryOperand.max(data)
196
        });
197
        result.push({
234✔
198
            key: 'sum',
199
            label: 'Sum',
200
            defaultFormatting: true,
201
            summaryResult: IgxNumberSummaryOperand.sum(data)
202
        });
203
        result.push({
234✔
204
            key: 'average',
205
            label: 'Avg',
206
            defaultFormatting: true,
207
            summaryResult: IgxNumberSummaryOperand.average(data)
208
        });
209
        return result;
234✔
210
    }
211
}
212

213
/* blazorCSSuppress */
214
// @dynamic
215
export class IgxDateSummaryOperand extends IgxSummaryOperand {
216
    /**
217
     * Returns the latest date value in the data records.
218
     * If filtering is applied, returns the latest date value in the filtered data records.
219
     * ```typescript
220
     * IgxDateSummaryOperand.latest(data);
221
     * ```
222
     *
223
     * @memberof IgxDateSummaryOperand
224
     */
225
    public static latest(data: any[]) {
UNCOV
226
        return data.length && data.filter(clear).length ?
×
UNCOV
227
            first(data.filter(clear).sort((a, b) => new Date(b).valueOf() - new Date(a).valueOf())) : undefined;
×
228
    }
229
    /**
230
     * Returns the earliest date value in the data records.
231
     * If filtering is applied, returns the latest date value in the filtered data records.
232
     * ```typescript
233
     * IgxDateSummaryOperand.earliest(data);
234
     * ```
235
     *
236
     * @memberof IgxDateSummaryOperand
237
     */
238
    public static earliest(data: any[]) {
UNCOV
239
        return data.length && data.filter(clear).length ?
×
UNCOV
240
            last(data.filter(clear).sort((a, b) => new Date(b).valueOf() - new Date(a).valueOf())) : undefined;
×
241
    }
242
    /**
243
     * Executes the static methods and returns `IgxSummaryResult[]`.
244
     * ```typescript
245
     * interface IgxSummaryResult {
246
     *   key: string;
247
     *   label: string;
248
     *   summaryResult: any;
249
     * }
250
     * ```
251
     * Can be overridden in the inherited classes to provide customization for the `summary`.
252
     * ```typescript
253
     * class CustomDateSummary extends IgxDateSummaryOperand {
254
     *   constructor() {
255
     *     super();
256
     *   }
257
     *   public operate(data: any[], allData: any[], fieldName: string, groupRecord: IGroupByRecord): IgxSummaryResult[] {
258
     *     const result = super.operate(data, allData, fieldName, groupRecord);
259
     *     result.push({
260
     *       key: "deadline",
261
     *       label: "Deadline Date",
262
     *       summaryResult: this.calculateDeadline(data);
263
     *     });
264
     *     return result;
265
     *   }
266
     * }
267
     * this.grid.getColumnByName('ColumnName').summaries = CustomDateSummary;
268
     * ```
269
     *
270
     * @memberof IgxDateSummaryOperand
271
     */
272
    public override operate(data: any[] = [], allData: any[] = [],  fieldName?: string, groupRecord?: IGroupByRecord): IgxSummaryResult[] {
×
UNCOV
273
        const result = super.operate(data, allData, fieldName, groupRecord);
×
UNCOV
274
        result.push({
×
275
            key: 'earliest',
276
            label: 'Earliest',
277
            defaultFormatting: true,
278
            summaryResult: IgxDateSummaryOperand.earliest(data)
279
        });
UNCOV
280
        result.push({
×
281
            key: 'latest',
282
            label: 'Latest',
283
            defaultFormatting: true,
284
            summaryResult: IgxDateSummaryOperand.latest(data)
285
        });
UNCOV
286
        return result;
×
287
    }
288
}
289

290
/* blazorCSSuppress */
291
// @dynamic
292
export class IgxTimeSummaryOperand extends IgxSummaryOperand {
293
    /**
294
     * Returns the latest time value in the data records. Compare only the time part of the date.
295
     * If filtering is applied, returns the latest time value in the filtered data records.
296
     * ```typescript
297
     * IgxTimeSummaryOperand.latestTime(data);
298
     * ```
299
     *
300
     * @memberof IgxTimeSummaryOperand
301
     */
302
    public static latestTime(data: any[]) {
UNCOV
303
        return data.length && data.filter(clear).length ?
×
UNCOV
304
            first(data.filter(clear).map(v => new Date(v)).sort((a, b) =>
×
UNCOV
305
                new Date().setHours(b.getHours(), b.getMinutes(), b.getSeconds()) -
×
306
                new Date().setHours(a.getHours(), a.getMinutes(), a.getSeconds()))) : undefined;
307
    }
308

309
    /**
310
     * Returns the earliest time value in the data records. Compare only the time part of the date.
311
     * If filtering is applied, returns the earliest time value in the filtered data records.
312
     * ```typescript
313
     * IgxTimeSummaryOperand.earliestTime(data);
314
     * ```
315
     *
316
     * @memberof IgxTimeSummaryOperand
317
     */
318
    public static earliestTime(data: any[]) {
UNCOV
319
        return data.length && data.filter(clear).length ?
×
UNCOV
320
            last(data.filter(clear).map(v => new Date(v)).sort((a, b) => new Date().setHours(b.getHours(), b.getMinutes(), b.getSeconds()) -
×
321
            new Date().setHours(a.getHours(), a.getMinutes(), a.getSeconds()))) : undefined;
322
    }
323
    /**
324
     * @memberof IgxTimeSummaryOperand
325
     */
326
    public override operate(data: any[] = [], allData: any[] = [],  fieldName?: string, groupRecord?: IGroupByRecord): IgxSummaryResult[] {
×
UNCOV
327
        const result = super.operate(data, allData, fieldName, groupRecord);
×
UNCOV
328
        result.push({
×
329
            key: 'earliest',
330
            label: 'Earliest',
331
            defaultFormatting: true,
332
            summaryResult: IgxTimeSummaryOperand.earliestTime(data)
333
        });
UNCOV
334
        result.push({
×
335
            key: 'latest',
336
            label: 'Latest',
337
            defaultFormatting: true,
338
            summaryResult: IgxTimeSummaryOperand.latestTime(data)
339
        });
UNCOV
340
        return result;
×
341
    }
342
}
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