1 | import { __values } from "tslib";
|
2 | import { groupToMap } from '@antv/util';
|
3 |
|
4 | export function group(data, fields, appendConditions) {
|
5 | var e_1, _a;
|
6 | if (appendConditions === void 0) { appendConditions = {}; }
|
7 | if (!fields) {
|
8 | return [data];
|
9 | }
|
10 | var groups = groupToMap(data, fields);
|
11 | var array = [];
|
12 | if (fields.length === 1 && appendConditions[fields[0]]) {
|
13 | var values = appendConditions[fields[0]];
|
14 | try {
|
15 | for (var values_1 = __values(values), values_1_1 = values_1.next(); !values_1_1.done; values_1_1 = values_1.next()) {
|
16 | var value = values_1_1.value;
|
17 | var arr = groups["_".concat(value)];
|
18 | if (arr) {
|
19 |
|
20 | array.push(arr);
|
21 | }
|
22 | }
|
23 | }
|
24 | catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
25 | finally {
|
26 | try {
|
27 | if (values_1_1 && !values_1_1.done && (_a = values_1.return)) _a.call(values_1);
|
28 | }
|
29 | finally { if (e_1) throw e_1.error; }
|
30 | }
|
31 | }
|
32 | else {
|
33 | for (var k in groups) {
|
34 | if (groups.hasOwnProperty(k)) {
|
35 | var eachGroup = groups[k];
|
36 | array.push(eachGroup);
|
37 | }
|
38 | }
|
39 | }
|
40 | return array;
|
41 | }
|
42 |
|
\ | No newline at end of file |