@tanstack/table-core 9.0.0-beta.2 → 9.0.0-beta.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/cells/coreCellsFeature.cjs +11 -20
- package/dist/core/cells/coreCellsFeature.cjs.map +1 -1
- package/dist/core/cells/coreCellsFeature.d.cts +4 -12
- package/dist/core/cells/coreCellsFeature.d.ts +4 -12
- package/dist/core/cells/coreCellsFeature.js +12 -20
- package/dist/core/cells/coreCellsFeature.js.map +1 -1
- package/dist/core/columns/coreColumnsFeature.cjs +59 -68
- package/dist/core/columns/coreColumnsFeature.cjs.map +1 -1
- package/dist/core/columns/coreColumnsFeature.d.cts +4 -12
- package/dist/core/columns/coreColumnsFeature.d.ts +4 -12
- package/dist/core/columns/coreColumnsFeature.js +60 -68
- package/dist/core/columns/coreColumnsFeature.js.map +1 -1
- package/dist/core/headers/buildHeaderGroups.cjs.map +1 -1
- package/dist/core/headers/buildHeaderGroups.js.map +1 -1
- package/dist/core/headers/coreHeadersFeature.cjs +44 -53
- package/dist/core/headers/coreHeadersFeature.cjs.map +1 -1
- package/dist/core/headers/coreHeadersFeature.d.cts +4 -12
- package/dist/core/headers/coreHeadersFeature.d.ts +4 -12
- package/dist/core/headers/coreHeadersFeature.js +45 -53
- package/dist/core/headers/coreHeadersFeature.js.map +1 -1
- package/dist/core/headers/coreHeadersFeature.utils.cjs.map +1 -1
- package/dist/core/headers/coreHeadersFeature.utils.js.map +1 -1
- package/dist/core/row-models/coreRowModelsFeature.cjs +17 -26
- package/dist/core/row-models/coreRowModelsFeature.cjs.map +1 -1
- package/dist/core/row-models/coreRowModelsFeature.d.cts +4 -12
- package/dist/core/row-models/coreRowModelsFeature.d.ts +4 -12
- package/dist/core/row-models/coreRowModelsFeature.js +18 -26
- package/dist/core/row-models/coreRowModelsFeature.js.map +1 -1
- package/dist/core/row-models/coreRowModelsFeature.types.d.cts +3 -5
- package/dist/core/row-models/coreRowModelsFeature.types.d.ts +3 -5
- package/dist/core/row-models/createCoreRowModel.cjs.map +1 -1
- package/dist/core/row-models/createCoreRowModel.js.map +1 -1
- package/dist/core/rows/coreRowsFeature.cjs +27 -36
- package/dist/core/rows/coreRowsFeature.cjs.map +1 -1
- package/dist/core/rows/coreRowsFeature.d.cts +4 -12
- package/dist/core/rows/coreRowsFeature.d.ts +4 -12
- package/dist/core/rows/coreRowsFeature.js +28 -36
- package/dist/core/rows/coreRowsFeature.js.map +1 -1
- package/dist/core/table/constructTable.cjs +2 -2
- package/dist/core/table/constructTable.cjs.map +1 -1
- package/dist/core/table/constructTable.js +2 -2
- package/dist/core/table/constructTable.js.map +1 -1
- package/dist/core/table/coreTablesFeature.cjs +7 -16
- package/dist/core/table/coreTablesFeature.cjs.map +1 -1
- package/dist/core/table/coreTablesFeature.d.cts +4 -12
- package/dist/core/table/coreTablesFeature.d.ts +4 -12
- package/dist/core/table/coreTablesFeature.js +8 -16
- package/dist/core/table/coreTablesFeature.js.map +1 -1
- package/dist/core/table/coreTablesFeature.utils.cjs.map +1 -1
- package/dist/core/table/coreTablesFeature.utils.js.map +1 -1
- package/dist/features/column-faceting/columnFacetingFeature.cjs +49 -61
- package/dist/features/column-faceting/columnFacetingFeature.cjs.map +1 -1
- package/dist/features/column-faceting/columnFacetingFeature.d.cts +4 -15
- package/dist/features/column-faceting/columnFacetingFeature.d.ts +4 -15
- package/dist/features/column-faceting/columnFacetingFeature.js +50 -61
- package/dist/features/column-faceting/columnFacetingFeature.js.map +1 -1
- package/dist/features/column-faceting/createFacetedMinMaxValues.cjs.map +1 -1
- package/dist/features/column-faceting/createFacetedMinMaxValues.js.map +1 -1
- package/dist/features/column-faceting/createFacetedRowModel.cjs.map +1 -1
- package/dist/features/column-faceting/createFacetedRowModel.js.map +1 -1
- package/dist/features/column-faceting/createFacetedUniqueValues.cjs.map +1 -1
- package/dist/features/column-faceting/createFacetedUniqueValues.js.map +1 -1
- package/dist/features/column-filtering/columnFilteringFeature.cjs +40 -53
- package/dist/features/column-filtering/columnFilteringFeature.cjs.map +1 -1
- package/dist/features/column-filtering/columnFilteringFeature.d.cts +4 -16
- package/dist/features/column-filtering/columnFilteringFeature.d.ts +4 -16
- package/dist/features/column-filtering/columnFilteringFeature.js +41 -53
- package/dist/features/column-filtering/columnFilteringFeature.js.map +1 -1
- package/dist/features/column-filtering/columnFilteringFeature.types.d.cts +3 -3
- package/dist/features/column-filtering/columnFilteringFeature.types.d.ts +3 -3
- package/dist/features/column-filtering/columnFilteringFeature.utils.cjs.map +1 -1
- package/dist/features/column-filtering/columnFilteringFeature.utils.d.cts +1 -1
- package/dist/features/column-filtering/columnFilteringFeature.utils.d.ts +1 -1
- package/dist/features/column-filtering/columnFilteringFeature.utils.js.map +1 -1
- package/dist/features/column-filtering/createFilteredRowModel.cjs.map +1 -1
- package/dist/features/column-filtering/createFilteredRowModel.d.cts +1 -1
- package/dist/features/column-filtering/createFilteredRowModel.d.ts +1 -1
- package/dist/features/column-filtering/createFilteredRowModel.js.map +1 -1
- package/dist/features/column-grouping/columnGroupingFeature.cjs +57 -69
- package/dist/features/column-grouping/columnGroupingFeature.cjs.map +1 -1
- package/dist/features/column-grouping/columnGroupingFeature.d.cts +4 -15
- package/dist/features/column-grouping/columnGroupingFeature.d.ts +4 -15
- package/dist/features/column-grouping/columnGroupingFeature.js +58 -69
- package/dist/features/column-grouping/columnGroupingFeature.js.map +1 -1
- package/dist/features/column-grouping/createGroupedRowModel.cjs.map +1 -1
- package/dist/features/column-grouping/createGroupedRowModel.js.map +1 -1
- package/dist/features/column-ordering/columnOrderingFeature.cjs +47 -59
- package/dist/features/column-ordering/columnOrderingFeature.cjs.map +1 -1
- package/dist/features/column-ordering/columnOrderingFeature.d.cts +4 -15
- package/dist/features/column-ordering/columnOrderingFeature.d.ts +4 -15
- package/dist/features/column-ordering/columnOrderingFeature.js +48 -59
- package/dist/features/column-ordering/columnOrderingFeature.js.map +1 -1
- package/dist/features/column-pinning/columnPinningFeature.cjs +209 -221
- package/dist/features/column-pinning/columnPinningFeature.cjs.map +1 -1
- package/dist/features/column-pinning/columnPinningFeature.d.cts +4 -15
- package/dist/features/column-pinning/columnPinningFeature.d.ts +4 -15
- package/dist/features/column-pinning/columnPinningFeature.js +210 -221
- package/dist/features/column-pinning/columnPinningFeature.js.map +1 -1
- package/dist/features/column-pinning/columnPinningFeature.utils.cjs.map +1 -1
- package/dist/features/column-pinning/columnPinningFeature.utils.d.cts +12 -12
- package/dist/features/column-pinning/columnPinningFeature.utils.d.ts +12 -12
- package/dist/features/column-pinning/columnPinningFeature.utils.js.map +1 -1
- package/dist/features/column-resizing/columnResizingFeature.cjs +31 -43
- package/dist/features/column-resizing/columnResizingFeature.cjs.map +1 -1
- package/dist/features/column-resizing/columnResizingFeature.d.cts +4 -15
- package/dist/features/column-resizing/columnResizingFeature.d.ts +4 -15
- package/dist/features/column-resizing/columnResizingFeature.js +32 -43
- package/dist/features/column-resizing/columnResizingFeature.js.map +1 -1
- package/dist/features/column-sizing/columnSizingFeature.cjs +112 -125
- package/dist/features/column-sizing/columnSizingFeature.cjs.map +1 -1
- package/dist/features/column-sizing/columnSizingFeature.d.cts +4 -16
- package/dist/features/column-sizing/columnSizingFeature.d.ts +4 -16
- package/dist/features/column-sizing/columnSizingFeature.js +113 -125
- package/dist/features/column-sizing/columnSizingFeature.js.map +1 -1
- package/dist/features/column-sizing/columnSizingFeature.utils.d.cts +3 -3
- package/dist/features/column-sizing/columnSizingFeature.utils.d.ts +3 -3
- package/dist/features/column-visibility/columnVisibilityFeature.cjs +83 -95
- package/dist/features/column-visibility/columnVisibilityFeature.cjs.map +1 -1
- package/dist/features/column-visibility/columnVisibilityFeature.d.cts +4 -15
- package/dist/features/column-visibility/columnVisibilityFeature.d.ts +4 -15
- package/dist/features/column-visibility/columnVisibilityFeature.js +84 -95
- package/dist/features/column-visibility/columnVisibilityFeature.js.map +1 -1
- package/dist/features/global-filtering/globalFilteringFeature.cjs +31 -43
- package/dist/features/global-filtering/globalFilteringFeature.cjs.map +1 -1
- package/dist/features/global-filtering/globalFilteringFeature.d.cts +4 -15
- package/dist/features/global-filtering/globalFilteringFeature.d.ts +4 -15
- package/dist/features/global-filtering/globalFilteringFeature.js +32 -43
- package/dist/features/global-filtering/globalFilteringFeature.js.map +1 -1
- package/dist/features/global-filtering/globalFilteringFeature.utils.cjs.map +1 -1
- package/dist/features/global-filtering/globalFilteringFeature.utils.d.cts +4 -2
- package/dist/features/global-filtering/globalFilteringFeature.utils.d.ts +4 -2
- package/dist/features/global-filtering/globalFilteringFeature.utils.js.map +1 -1
- package/dist/features/row-expanding/createExpandedRowModel.cjs.map +1 -1
- package/dist/features/row-expanding/createExpandedRowModel.js.map +1 -1
- package/dist/features/row-expanding/rowExpandingFeature.cjs +37 -49
- package/dist/features/row-expanding/rowExpandingFeature.cjs.map +1 -1
- package/dist/features/row-expanding/rowExpandingFeature.d.cts +4 -15
- package/dist/features/row-expanding/rowExpandingFeature.d.ts +4 -15
- package/dist/features/row-expanding/rowExpandingFeature.js +38 -49
- package/dist/features/row-expanding/rowExpandingFeature.js.map +1 -1
- package/dist/features/row-pagination/createPaginatedRowModel.cjs.map +1 -1
- package/dist/features/row-pagination/createPaginatedRowModel.js.map +1 -1
- package/dist/features/row-pagination/rowPaginationFeature.cjs +35 -47
- package/dist/features/row-pagination/rowPaginationFeature.cjs.map +1 -1
- package/dist/features/row-pagination/rowPaginationFeature.d.cts +4 -15
- package/dist/features/row-pagination/rowPaginationFeature.d.ts +4 -15
- package/dist/features/row-pagination/rowPaginationFeature.js +36 -47
- package/dist/features/row-pagination/rowPaginationFeature.js.map +1 -1
- package/dist/features/row-pinning/rowPinningFeature.cjs +55 -67
- package/dist/features/row-pinning/rowPinningFeature.cjs.map +1 -1
- package/dist/features/row-pinning/rowPinningFeature.d.cts +4 -15
- package/dist/features/row-pinning/rowPinningFeature.d.ts +4 -15
- package/dist/features/row-pinning/rowPinningFeature.js +56 -67
- package/dist/features/row-pinning/rowPinningFeature.js.map +1 -1
- package/dist/features/row-selection/rowSelectionFeature.cjs +65 -77
- package/dist/features/row-selection/rowSelectionFeature.cjs.map +1 -1
- package/dist/features/row-selection/rowSelectionFeature.d.cts +4 -15
- package/dist/features/row-selection/rowSelectionFeature.d.ts +4 -15
- package/dist/features/row-selection/rowSelectionFeature.js +66 -77
- package/dist/features/row-selection/rowSelectionFeature.js.map +1 -1
- package/dist/features/row-sorting/createSortedRowModel.cjs.map +1 -1
- package/dist/features/row-sorting/createSortedRowModel.js.map +1 -1
- package/dist/features/row-sorting/rowSortingFeature.cjs +45 -57
- package/dist/features/row-sorting/rowSortingFeature.cjs.map +1 -1
- package/dist/features/row-sorting/rowSortingFeature.d.cts +4 -15
- package/dist/features/row-sorting/rowSortingFeature.d.ts +4 -15
- package/dist/features/row-sorting/rowSortingFeature.js +46 -57
- package/dist/features/row-sorting/rowSortingFeature.js.map +1 -1
- package/dist/features/row-sorting/rowSortingFeature.utils.cjs +8 -5
- package/dist/features/row-sorting/rowSortingFeature.utils.cjs.map +1 -1
- package/dist/features/row-sorting/rowSortingFeature.utils.js +8 -5
- package/dist/features/row-sorting/rowSortingFeature.utils.js.map +1 -1
- package/dist/fns/aggregationFns.cjs +18 -18
- package/dist/fns/aggregationFns.cjs.map +1 -1
- package/dist/fns/aggregationFns.d.cts +21 -19
- package/dist/fns/aggregationFns.d.ts +21 -19
- package/dist/fns/aggregationFns.js +18 -18
- package/dist/fns/aggregationFns.js.map +1 -1
- package/dist/fns/filterFns.cjs +51 -65
- package/dist/fns/filterFns.cjs.map +1 -1
- package/dist/fns/filterFns.d.cts +82 -28
- package/dist/fns/filterFns.d.ts +82 -28
- package/dist/fns/filterFns.js +51 -65
- package/dist/fns/filterFns.js.map +1 -1
- package/dist/fns/sortFns.cjs +18 -6
- package/dist/fns/sortFns.cjs.map +1 -1
- package/dist/fns/sortFns.d.cts +15 -13
- package/dist/fns/sortFns.d.ts +15 -13
- package/dist/fns/sortFns.js +18 -6
- package/dist/fns/sortFns.js.map +1 -1
- package/dist/index.cjs +0 -20
- package/dist/index.d.cts +34 -34
- package/dist/index.d.ts +34 -34
- package/dist/index.js +21 -21
- package/dist/types/Cell.d.cts +3 -8
- package/dist/types/Cell.d.ts +3 -8
- package/dist/types/Column.d.cts +3 -8
- package/dist/types/Column.d.ts +3 -8
- package/dist/types/ColumnDef.d.cts +3 -8
- package/dist/types/ColumnDef.d.ts +3 -8
- package/dist/types/Header.d.cts +3 -8
- package/dist/types/Header.d.ts +3 -8
- package/dist/types/HeaderGroup.d.cts +3 -8
- package/dist/types/HeaderGroup.d.ts +3 -8
- package/dist/types/Row.d.cts +3 -8
- package/dist/types/Row.d.ts +3 -8
- package/dist/types/RowModel.d.cts +4 -10
- package/dist/types/RowModel.d.ts +4 -10
- package/dist/types/RowModelFns.d.cts +3 -8
- package/dist/types/RowModelFns.d.ts +3 -8
- package/dist/types/Table.d.cts +3 -8
- package/dist/types/Table.d.ts +3 -8
- package/dist/types/TableFeatures.d.cts +13 -39
- package/dist/types/TableFeatures.d.ts +13 -39
- package/dist/types/TableOptions.d.cts +3 -4
- package/dist/types/TableOptions.d.ts +3 -4
- package/dist/types/TableState.d.cts +5 -10
- package/dist/types/TableState.d.ts +5 -10
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +1 -1
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js.map +1 -1
- package/package.json +1 -1
- package/src/core/cells/coreCellsFeature.ts +17 -39
- package/src/core/columns/coreColumnsFeature.ts +56 -83
- package/src/core/headers/buildHeaderGroups.ts +1 -1
- package/src/core/headers/coreHeadersFeature.ts +42 -64
- package/src/core/headers/coreHeadersFeature.utils.ts +1 -1
- package/src/core/row-models/coreRowModelsFeature.ts +43 -64
- package/src/core/row-models/coreRowModelsFeature.types.ts +2 -6
- package/src/core/row-models/createCoreRowModel.ts +1 -1
- package/src/core/rows/coreRowsFeature.ts +45 -72
- package/src/core/table/constructTable.ts +10 -7
- package/src/core/table/coreTablesFeature.ts +13 -35
- package/src/core/table/coreTablesFeature.utils.ts +1 -1
- package/src/features/column-faceting/columnFacetingFeature.ts +71 -102
- package/src/features/column-faceting/createFacetedMinMaxValues.ts +1 -1
- package/src/features/column-faceting/createFacetedRowModel.ts +1 -1
- package/src/features/column-faceting/createFacetedUniqueValues.ts +1 -1
- package/src/features/column-filtering/columnFilteringFeature.ts +60 -103
- package/src/features/column-filtering/columnFilteringFeature.types.ts +3 -3
- package/src/features/column-filtering/columnFilteringFeature.utils.ts +4 -4
- package/src/features/column-filtering/createFilteredRowModel.ts +2 -2
- package/src/features/column-grouping/columnGroupingFeature.ts +82 -126
- package/src/features/column-grouping/createGroupedRowModel.ts +1 -1
- package/src/features/column-ordering/columnOrderingFeature.ts +52 -84
- package/src/features/column-pinning/columnPinningFeature.ts +268 -304
- package/src/features/column-pinning/columnPinningFeature.utils.ts +5 -5
- package/src/features/column-resizing/columnResizingFeature.ts +44 -78
- package/src/features/column-sizing/columnSizingFeature.ts +115 -152
- package/src/features/column-visibility/columnVisibilityFeature.ts +92 -129
- package/src/features/global-filtering/globalFilteringFeature.ts +45 -79
- package/src/features/global-filtering/globalFilteringFeature.utils.ts +4 -2
- package/src/features/row-expanding/createExpandedRowModel.ts +1 -1
- package/src/features/row-expanding/rowExpandingFeature.ts +65 -101
- package/src/features/row-pagination/createPaginatedRowModel.ts +1 -1
- package/src/features/row-pagination/rowPaginationFeature.ts +69 -103
- package/src/features/row-pinning/rowPinningFeature.ts +72 -104
- package/src/features/row-selection/rowSelectionFeature.ts +103 -135
- package/src/features/row-sorting/createSortedRowModel.ts +1 -1
- package/src/features/row-sorting/rowSortingFeature.ts +73 -114
- package/src/features/row-sorting/rowSortingFeature.utils.ts +8 -6
- package/src/fns/aggregationFns.ts +26 -42
- package/src/fns/filterFns.ts +231 -264
- package/src/fns/sortFns.ts +51 -29
- package/src/types/Cell.ts +3 -19
- package/src/types/Column.ts +2 -18
- package/src/types/ColumnDef.ts +2 -18
- package/src/types/Header.ts +2 -18
- package/src/types/HeaderGroup.ts +2 -13
- package/src/types/Row.ts +2 -17
- package/src/types/RowModel.ts +3 -25
- package/src/types/RowModelFns.ts +2 -17
- package/src/types/Table.ts +2 -17
- package/src/types/TableFeatures.ts +51 -112
- package/src/types/TableOptions.ts +1 -12
- package/src/types/TableState.ts +4 -30
- package/src/utils.ts +5 -4
|
@@ -6,47 +6,47 @@
|
|
|
6
6
|
* Non-number values contribute `0`. Child rows are used so nested group totals
|
|
7
7
|
* can reuse already aggregated values.
|
|
8
8
|
*/
|
|
9
|
-
|
|
9
|
+
function aggregationFn_sum(columnId, _leafRows, childRows) {
|
|
10
10
|
return childRows.reduce((sumValue, next) => {
|
|
11
11
|
const nextValue = next.getValue(columnId);
|
|
12
12
|
return sumValue + (typeof nextValue === "number" ? nextValue : 0);
|
|
13
13
|
}, 0);
|
|
14
|
-
}
|
|
14
|
+
}
|
|
15
15
|
/**
|
|
16
16
|
* Finds the minimum numeric child-row value for a grouped column.
|
|
17
17
|
*
|
|
18
18
|
* Nullish and non-number values are ignored. Returns `undefined` when no
|
|
19
19
|
* numeric value is found.
|
|
20
20
|
*/
|
|
21
|
-
|
|
21
|
+
function aggregationFn_min(columnId, _leafRows, childRows) {
|
|
22
22
|
let minValue;
|
|
23
23
|
childRows.forEach((row) => {
|
|
24
24
|
const value = row.getValue(columnId);
|
|
25
25
|
if (value != null && typeof value === "number" && (minValue === void 0 || value < minValue)) minValue = value;
|
|
26
26
|
});
|
|
27
27
|
return minValue;
|
|
28
|
-
}
|
|
28
|
+
}
|
|
29
29
|
/**
|
|
30
30
|
* Finds the maximum numeric child-row value for a grouped column.
|
|
31
31
|
*
|
|
32
32
|
* Nullish and non-number values are ignored. Returns `undefined` when no
|
|
33
33
|
* numeric value is found.
|
|
34
34
|
*/
|
|
35
|
-
|
|
35
|
+
function aggregationFn_max(columnId, _leafRows, childRows) {
|
|
36
36
|
let maxValue;
|
|
37
37
|
childRows.forEach((row) => {
|
|
38
38
|
const value = row.getValue(columnId);
|
|
39
39
|
if (value != null && typeof value === "number" && (maxValue === void 0 || value > maxValue)) maxValue = value;
|
|
40
40
|
});
|
|
41
41
|
return maxValue;
|
|
42
|
-
}
|
|
42
|
+
}
|
|
43
43
|
/**
|
|
44
44
|
* Finds the numeric extent for a grouped column.
|
|
45
45
|
*
|
|
46
46
|
* Returns `[min, max]`, where each entry is `undefined` when no numeric value is
|
|
47
47
|
* present.
|
|
48
48
|
*/
|
|
49
|
-
|
|
49
|
+
function aggregationFn_extent(columnId, _leafRows, childRows) {
|
|
50
50
|
let minValue;
|
|
51
51
|
let maxValue;
|
|
52
52
|
childRows.forEach((row) => {
|
|
@@ -58,14 +58,14 @@ const aggregationFn_extent = (columnId, _leafRows, childRows) => {
|
|
|
58
58
|
}
|
|
59
59
|
});
|
|
60
60
|
return [minValue, maxValue];
|
|
61
|
-
}
|
|
61
|
+
}
|
|
62
62
|
/**
|
|
63
63
|
* Averages numeric leaf-row values for a grouped column.
|
|
64
64
|
*
|
|
65
65
|
* Number-like values are coerced with unary `+`; nullish and non-numeric values
|
|
66
66
|
* are ignored.
|
|
67
67
|
*/
|
|
68
|
-
|
|
68
|
+
function aggregationFn_mean(columnId, leafRows) {
|
|
69
69
|
let count = 0;
|
|
70
70
|
let sumValue = 0;
|
|
71
71
|
leafRows.forEach((row) => {
|
|
@@ -82,14 +82,14 @@ const aggregationFn_mean = (columnId, leafRows) => {
|
|
|
82
82
|
}
|
|
83
83
|
});
|
|
84
84
|
if (count) return sumValue / count;
|
|
85
|
-
}
|
|
85
|
+
}
|
|
86
86
|
/**
|
|
87
87
|
* Computes the median of numeric leaf-row values for a grouped column.
|
|
88
88
|
*
|
|
89
89
|
* All values must be numbers. If any value is non-numeric, or no leaf rows are
|
|
90
90
|
* present, the result is `undefined`.
|
|
91
91
|
*/
|
|
92
|
-
|
|
92
|
+
function aggregationFn_median(columnId, leafRows) {
|
|
93
93
|
if (!leafRows.length) return;
|
|
94
94
|
const values = new Array(leafRows.length);
|
|
95
95
|
for (let i = 0; i < leafRows.length; i++) {
|
|
@@ -101,35 +101,35 @@ const aggregationFn_median = (columnId, leafRows) => {
|
|
|
101
101
|
const mid = Math.floor(values.length / 2);
|
|
102
102
|
values.sort((a, b) => a - b);
|
|
103
103
|
return values.length % 2 !== 0 ? values[mid] : (values[mid - 1] + values[mid]) / 2;
|
|
104
|
-
}
|
|
104
|
+
}
|
|
105
105
|
/**
|
|
106
106
|
* Collects unique leaf-row values for a grouped column.
|
|
107
107
|
*
|
|
108
108
|
* Values are compared with JavaScript `Set` semantics.
|
|
109
109
|
*/
|
|
110
|
-
|
|
110
|
+
function aggregationFn_unique(columnId, leafRows) {
|
|
111
111
|
const set = /* @__PURE__ */ new Set();
|
|
112
112
|
for (let i = 0; i < leafRows.length; i++) set.add(leafRows[i].getValue(columnId));
|
|
113
113
|
return Array.from(set.values());
|
|
114
|
-
}
|
|
114
|
+
}
|
|
115
115
|
/**
|
|
116
116
|
* Counts unique leaf-row values for a grouped column.
|
|
117
117
|
*
|
|
118
118
|
* Values are compared with JavaScript `Set` semantics.
|
|
119
119
|
*/
|
|
120
|
-
|
|
120
|
+
function aggregationFn_uniqueCount(columnId, leafRows) {
|
|
121
121
|
const set = /* @__PURE__ */ new Set();
|
|
122
122
|
for (let i = 0; i < leafRows.length; i++) set.add(leafRows[i].getValue(columnId));
|
|
123
123
|
return set.size;
|
|
124
|
-
}
|
|
124
|
+
}
|
|
125
125
|
/**
|
|
126
126
|
* Counts the number of leaf rows in the group.
|
|
127
127
|
*
|
|
128
128
|
* The column id is ignored because the result is based only on group size.
|
|
129
129
|
*/
|
|
130
|
-
|
|
130
|
+
function aggregationFn_count(_columnId, leafRows) {
|
|
131
131
|
return leafRows.length;
|
|
132
|
-
}
|
|
132
|
+
}
|
|
133
133
|
/**
|
|
134
134
|
* The built-in aggregation function registry.
|
|
135
135
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aggregationFns.cjs","names":[],"sources":["../../src/fns/aggregationFns.ts"],"sourcesContent":["import type { RowData } from '../types/type-utils'\nimport type { TableFeatures } from '../types/TableFeatures'\nimport type { Row } from '../types/Row'\
|
|
1
|
+
{"version":3,"file":"aggregationFns.cjs","names":[],"sources":["../../src/fns/aggregationFns.ts"],"sourcesContent":["import type { RowData } from '../types/type-utils'\nimport type { TableFeatures } from '../types/TableFeatures'\nimport type { Row } from '../types/Row'\n\n/**\n * Sums numeric child-row values for a grouped column.\n *\n * Non-number values contribute `0`. Child rows are used so nested group totals\n * can reuse already aggregated values.\n */\nexport function aggregationFn_sum<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n columnId: string,\n _leafRows: Array<Row<TFeatures, TData>>,\n childRows: Array<Row<TFeatures, TData>>,\n) {\n // It's faster to just add the aggregations together instead of\n // process leaf nodes individually\n return childRows.reduce((sumValue, next) => {\n const nextValue = next.getValue(columnId)\n return sumValue + (typeof nextValue === 'number' ? nextValue : 0)\n }, 0)\n}\n\n/**\n * Finds the minimum numeric child-row value for a grouped column.\n *\n * Nullish and non-number values are ignored. Returns `undefined` when no\n * numeric value is found.\n */\nexport function aggregationFn_min<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n columnId: string,\n _leafRows: Array<Row<TFeatures, TData>>,\n childRows: Array<Row<TFeatures, TData>>,\n) {\n let minValue: number | undefined\n\n childRows.forEach((row) => {\n const value = row.getValue(columnId)\n\n if (\n value != null &&\n typeof value === 'number' &&\n (minValue === undefined || value < minValue)\n ) {\n minValue = value\n }\n })\n\n return minValue\n}\n\n/**\n * Finds the maximum numeric child-row value for a grouped column.\n *\n * Nullish and non-number values are ignored. Returns `undefined` when no\n * numeric value is found.\n */\nexport function aggregationFn_max<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n columnId: string,\n _leafRows: Array<Row<TFeatures, TData>>,\n childRows: Array<Row<TFeatures, TData>>,\n) {\n let maxValue: number | undefined\n\n childRows.forEach((row) => {\n const value = row.getValue(columnId)\n if (\n value != null &&\n typeof value === 'number' &&\n (maxValue === undefined || value > maxValue)\n ) {\n maxValue = value\n }\n })\n\n return maxValue\n}\n\n/**\n * Finds the numeric extent for a grouped column.\n *\n * Returns `[min, max]`, where each entry is `undefined` when no numeric value is\n * present.\n */\nexport function aggregationFn_extent<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n columnId: string,\n _leafRows: Array<Row<TFeatures, TData>>,\n childRows: Array<Row<TFeatures, TData>>,\n) {\n let minValue: number | undefined\n let maxValue: number | undefined\n\n childRows.forEach((row) => {\n const value = row.getValue(columnId)\n if (value != null && typeof value === 'number') {\n if (minValue === undefined) {\n minValue = maxValue = value\n } else {\n if (minValue > value) minValue = value\n if (maxValue! < value) maxValue = value\n }\n }\n })\n\n return [minValue, maxValue]\n}\n\n/**\n * Averages numeric leaf-row values for a grouped column.\n *\n * Number-like values are coerced with unary `+`; nullish and non-numeric values\n * are ignored.\n */\nexport function aggregationFn_mean<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(columnId: string, leafRows: Array<Row<TFeatures, TData>>) {\n let count = 0\n let sumValue = 0\n\n leafRows.forEach((row) => {\n const value = row.getValue(columnId)\n if (value != null && typeof value === 'number') {\n ++count\n sumValue += value\n } else if (value != null) {\n const numValue = +value\n if (!Number.isNaN(numValue)) {\n ++count\n sumValue += numValue\n }\n }\n })\n\n if (count) return sumValue / count\n\n return\n}\n\n/**\n * Computes the median of numeric leaf-row values for a grouped column.\n *\n * All values must be numbers. If any value is non-numeric, or no leaf rows are\n * present, the result is `undefined`.\n */\nexport function aggregationFn_median<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(columnId: string, leafRows: Array<Row<TFeatures, TData>>) {\n if (!leafRows.length) {\n return\n }\n\n const values: Array<number> = new Array(leafRows.length)\n for (let i = 0; i < leafRows.length; i++) {\n const v = leafRows[i]!.getValue(columnId)\n if (typeof v !== 'number') return\n values[i] = v\n }\n\n if (values.length === 1) {\n return values[0]\n }\n\n const mid = Math.floor(values.length / 2)\n values.sort((a, b) => a - b)\n return values.length % 2 !== 0\n ? values[mid]\n : (values[mid - 1]! + values[mid]!) / 2\n}\n\n/**\n * Collects unique leaf-row values for a grouped column.\n *\n * Values are compared with JavaScript `Set` semantics.\n */\nexport function aggregationFn_unique<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(columnId: string, leafRows: Array<Row<TFeatures, TData>>) {\n const set = new Set<unknown>()\n for (let i = 0; i < leafRows.length; i++) {\n set.add(leafRows[i]!.getValue(columnId))\n }\n return Array.from(set.values())\n}\n\n/**\n * Counts unique leaf-row values for a grouped column.\n *\n * Values are compared with JavaScript `Set` semantics.\n */\nexport function aggregationFn_uniqueCount<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(columnId: string, leafRows: Array<Row<TFeatures, TData>>) {\n const set = new Set<unknown>()\n for (let i = 0; i < leafRows.length; i++) {\n set.add(leafRows[i]!.getValue(columnId))\n }\n return set.size\n}\n\n/**\n * Counts the number of leaf rows in the group.\n *\n * The column id is ignored because the result is based only on group size.\n */\nexport function aggregationFn_count<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(_columnId: string, leafRows: Array<Row<TFeatures, TData>>) {\n return leafRows.length\n}\n\n/**\n * The built-in aggregation function registry.\n *\n * Pass this object to grouped row model creation or extend it with custom aggregation functions for grouped columns.\n */\nexport const aggregationFns = {\n sum: aggregationFn_sum,\n min: aggregationFn_min,\n max: aggregationFn_max,\n extent: aggregationFn_extent,\n mean: aggregationFn_mean,\n median: aggregationFn_median,\n unique: aggregationFn_unique,\n uniqueCount: aggregationFn_uniqueCount,\n count: aggregationFn_count,\n}\n\nexport type BuiltInAggregationFn = keyof typeof aggregationFns\n"],"mappings":"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"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RowData } from "../types/type-utils.cjs";
|
|
2
|
+
import { Row } from "../types/Row.cjs";
|
|
3
|
+
import { TableFeatures } from "../types/TableFeatures.cjs";
|
|
2
4
|
|
|
3
5
|
//#region src/fns/aggregationFns.d.ts
|
|
4
6
|
/**
|
|
@@ -7,75 +9,75 @@ import { AggregationFn } from "../features/column-grouping/columnGroupingFeature
|
|
|
7
9
|
* Non-number values contribute `0`. Child rows are used so nested group totals
|
|
8
10
|
* can reuse already aggregated values.
|
|
9
11
|
*/
|
|
10
|
-
declare
|
|
12
|
+
declare function aggregationFn_sum<TFeatures extends TableFeatures, TData extends RowData>(columnId: string, _leafRows: Array<Row<TFeatures, TData>>, childRows: Array<Row<TFeatures, TData>>): number;
|
|
11
13
|
/**
|
|
12
14
|
* Finds the minimum numeric child-row value for a grouped column.
|
|
13
15
|
*
|
|
14
16
|
* Nullish and non-number values are ignored. Returns `undefined` when no
|
|
15
17
|
* numeric value is found.
|
|
16
18
|
*/
|
|
17
|
-
declare
|
|
19
|
+
declare function aggregationFn_min<TFeatures extends TableFeatures, TData extends RowData>(columnId: string, _leafRows: Array<Row<TFeatures, TData>>, childRows: Array<Row<TFeatures, TData>>): number | undefined;
|
|
18
20
|
/**
|
|
19
21
|
* Finds the maximum numeric child-row value for a grouped column.
|
|
20
22
|
*
|
|
21
23
|
* Nullish and non-number values are ignored. Returns `undefined` when no
|
|
22
24
|
* numeric value is found.
|
|
23
25
|
*/
|
|
24
|
-
declare
|
|
26
|
+
declare function aggregationFn_max<TFeatures extends TableFeatures, TData extends RowData>(columnId: string, _leafRows: Array<Row<TFeatures, TData>>, childRows: Array<Row<TFeatures, TData>>): number | undefined;
|
|
25
27
|
/**
|
|
26
28
|
* Finds the numeric extent for a grouped column.
|
|
27
29
|
*
|
|
28
30
|
* Returns `[min, max]`, where each entry is `undefined` when no numeric value is
|
|
29
31
|
* present.
|
|
30
32
|
*/
|
|
31
|
-
declare
|
|
33
|
+
declare function aggregationFn_extent<TFeatures extends TableFeatures, TData extends RowData>(columnId: string, _leafRows: Array<Row<TFeatures, TData>>, childRows: Array<Row<TFeatures, TData>>): (number | undefined)[];
|
|
32
34
|
/**
|
|
33
35
|
* Averages numeric leaf-row values for a grouped column.
|
|
34
36
|
*
|
|
35
37
|
* Number-like values are coerced with unary `+`; nullish and non-numeric values
|
|
36
38
|
* are ignored.
|
|
37
39
|
*/
|
|
38
|
-
declare
|
|
40
|
+
declare function aggregationFn_mean<TFeatures extends TableFeatures, TData extends RowData>(columnId: string, leafRows: Array<Row<TFeatures, TData>>): number | undefined;
|
|
39
41
|
/**
|
|
40
42
|
* Computes the median of numeric leaf-row values for a grouped column.
|
|
41
43
|
*
|
|
42
44
|
* All values must be numbers. If any value is non-numeric, or no leaf rows are
|
|
43
45
|
* present, the result is `undefined`.
|
|
44
46
|
*/
|
|
45
|
-
declare
|
|
47
|
+
declare function aggregationFn_median<TFeatures extends TableFeatures, TData extends RowData>(columnId: string, leafRows: Array<Row<TFeatures, TData>>): number | undefined;
|
|
46
48
|
/**
|
|
47
49
|
* Collects unique leaf-row values for a grouped column.
|
|
48
50
|
*
|
|
49
51
|
* Values are compared with JavaScript `Set` semantics.
|
|
50
52
|
*/
|
|
51
|
-
declare
|
|
53
|
+
declare function aggregationFn_unique<TFeatures extends TableFeatures, TData extends RowData>(columnId: string, leafRows: Array<Row<TFeatures, TData>>): unknown[];
|
|
52
54
|
/**
|
|
53
55
|
* Counts unique leaf-row values for a grouped column.
|
|
54
56
|
*
|
|
55
57
|
* Values are compared with JavaScript `Set` semantics.
|
|
56
58
|
*/
|
|
57
|
-
declare
|
|
59
|
+
declare function aggregationFn_uniqueCount<TFeatures extends TableFeatures, TData extends RowData>(columnId: string, leafRows: Array<Row<TFeatures, TData>>): number;
|
|
58
60
|
/**
|
|
59
61
|
* Counts the number of leaf rows in the group.
|
|
60
62
|
*
|
|
61
63
|
* The column id is ignored because the result is based only on group size.
|
|
62
64
|
*/
|
|
63
|
-
declare
|
|
65
|
+
declare function aggregationFn_count<TFeatures extends TableFeatures, TData extends RowData>(_columnId: string, leafRows: Array<Row<TFeatures, TData>>): number;
|
|
64
66
|
/**
|
|
65
67
|
* The built-in aggregation function registry.
|
|
66
68
|
*
|
|
67
69
|
* Pass this object to grouped row model creation or extend it with custom aggregation functions for grouped columns.
|
|
68
70
|
*/
|
|
69
71
|
declare const aggregationFns: {
|
|
70
|
-
sum:
|
|
71
|
-
min:
|
|
72
|
-
max:
|
|
73
|
-
extent:
|
|
74
|
-
mean:
|
|
75
|
-
median:
|
|
76
|
-
unique:
|
|
77
|
-
uniqueCount:
|
|
78
|
-
count:
|
|
72
|
+
sum: typeof aggregationFn_sum;
|
|
73
|
+
min: typeof aggregationFn_min;
|
|
74
|
+
max: typeof aggregationFn_max;
|
|
75
|
+
extent: typeof aggregationFn_extent;
|
|
76
|
+
mean: typeof aggregationFn_mean;
|
|
77
|
+
median: typeof aggregationFn_median;
|
|
78
|
+
unique: typeof aggregationFn_unique;
|
|
79
|
+
uniqueCount: typeof aggregationFn_uniqueCount;
|
|
80
|
+
count: typeof aggregationFn_count;
|
|
79
81
|
};
|
|
80
82
|
type BuiltInAggregationFn = keyof typeof aggregationFns;
|
|
81
83
|
//#endregion
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RowData } from "../types/type-utils.js";
|
|
2
|
+
import { Row } from "../types/Row.js";
|
|
3
|
+
import { TableFeatures } from "../types/TableFeatures.js";
|
|
2
4
|
|
|
3
5
|
//#region src/fns/aggregationFns.d.ts
|
|
4
6
|
/**
|
|
@@ -7,75 +9,75 @@ import { AggregationFn } from "../features/column-grouping/columnGroupingFeature
|
|
|
7
9
|
* Non-number values contribute `0`. Child rows are used so nested group totals
|
|
8
10
|
* can reuse already aggregated values.
|
|
9
11
|
*/
|
|
10
|
-
declare
|
|
12
|
+
declare function aggregationFn_sum<TFeatures extends TableFeatures, TData extends RowData>(columnId: string, _leafRows: Array<Row<TFeatures, TData>>, childRows: Array<Row<TFeatures, TData>>): number;
|
|
11
13
|
/**
|
|
12
14
|
* Finds the minimum numeric child-row value for a grouped column.
|
|
13
15
|
*
|
|
14
16
|
* Nullish and non-number values are ignored. Returns `undefined` when no
|
|
15
17
|
* numeric value is found.
|
|
16
18
|
*/
|
|
17
|
-
declare
|
|
19
|
+
declare function aggregationFn_min<TFeatures extends TableFeatures, TData extends RowData>(columnId: string, _leafRows: Array<Row<TFeatures, TData>>, childRows: Array<Row<TFeatures, TData>>): number | undefined;
|
|
18
20
|
/**
|
|
19
21
|
* Finds the maximum numeric child-row value for a grouped column.
|
|
20
22
|
*
|
|
21
23
|
* Nullish and non-number values are ignored. Returns `undefined` when no
|
|
22
24
|
* numeric value is found.
|
|
23
25
|
*/
|
|
24
|
-
declare
|
|
26
|
+
declare function aggregationFn_max<TFeatures extends TableFeatures, TData extends RowData>(columnId: string, _leafRows: Array<Row<TFeatures, TData>>, childRows: Array<Row<TFeatures, TData>>): number | undefined;
|
|
25
27
|
/**
|
|
26
28
|
* Finds the numeric extent for a grouped column.
|
|
27
29
|
*
|
|
28
30
|
* Returns `[min, max]`, where each entry is `undefined` when no numeric value is
|
|
29
31
|
* present.
|
|
30
32
|
*/
|
|
31
|
-
declare
|
|
33
|
+
declare function aggregationFn_extent<TFeatures extends TableFeatures, TData extends RowData>(columnId: string, _leafRows: Array<Row<TFeatures, TData>>, childRows: Array<Row<TFeatures, TData>>): (number | undefined)[];
|
|
32
34
|
/**
|
|
33
35
|
* Averages numeric leaf-row values for a grouped column.
|
|
34
36
|
*
|
|
35
37
|
* Number-like values are coerced with unary `+`; nullish and non-numeric values
|
|
36
38
|
* are ignored.
|
|
37
39
|
*/
|
|
38
|
-
declare
|
|
40
|
+
declare function aggregationFn_mean<TFeatures extends TableFeatures, TData extends RowData>(columnId: string, leafRows: Array<Row<TFeatures, TData>>): number | undefined;
|
|
39
41
|
/**
|
|
40
42
|
* Computes the median of numeric leaf-row values for a grouped column.
|
|
41
43
|
*
|
|
42
44
|
* All values must be numbers. If any value is non-numeric, or no leaf rows are
|
|
43
45
|
* present, the result is `undefined`.
|
|
44
46
|
*/
|
|
45
|
-
declare
|
|
47
|
+
declare function aggregationFn_median<TFeatures extends TableFeatures, TData extends RowData>(columnId: string, leafRows: Array<Row<TFeatures, TData>>): number | undefined;
|
|
46
48
|
/**
|
|
47
49
|
* Collects unique leaf-row values for a grouped column.
|
|
48
50
|
*
|
|
49
51
|
* Values are compared with JavaScript `Set` semantics.
|
|
50
52
|
*/
|
|
51
|
-
declare
|
|
53
|
+
declare function aggregationFn_unique<TFeatures extends TableFeatures, TData extends RowData>(columnId: string, leafRows: Array<Row<TFeatures, TData>>): unknown[];
|
|
52
54
|
/**
|
|
53
55
|
* Counts unique leaf-row values for a grouped column.
|
|
54
56
|
*
|
|
55
57
|
* Values are compared with JavaScript `Set` semantics.
|
|
56
58
|
*/
|
|
57
|
-
declare
|
|
59
|
+
declare function aggregationFn_uniqueCount<TFeatures extends TableFeatures, TData extends RowData>(columnId: string, leafRows: Array<Row<TFeatures, TData>>): number;
|
|
58
60
|
/**
|
|
59
61
|
* Counts the number of leaf rows in the group.
|
|
60
62
|
*
|
|
61
63
|
* The column id is ignored because the result is based only on group size.
|
|
62
64
|
*/
|
|
63
|
-
declare
|
|
65
|
+
declare function aggregationFn_count<TFeatures extends TableFeatures, TData extends RowData>(_columnId: string, leafRows: Array<Row<TFeatures, TData>>): number;
|
|
64
66
|
/**
|
|
65
67
|
* The built-in aggregation function registry.
|
|
66
68
|
*
|
|
67
69
|
* Pass this object to grouped row model creation or extend it with custom aggregation functions for grouped columns.
|
|
68
70
|
*/
|
|
69
71
|
declare const aggregationFns: {
|
|
70
|
-
sum:
|
|
71
|
-
min:
|
|
72
|
-
max:
|
|
73
|
-
extent:
|
|
74
|
-
mean:
|
|
75
|
-
median:
|
|
76
|
-
unique:
|
|
77
|
-
uniqueCount:
|
|
78
|
-
count:
|
|
72
|
+
sum: typeof aggregationFn_sum;
|
|
73
|
+
min: typeof aggregationFn_min;
|
|
74
|
+
max: typeof aggregationFn_max;
|
|
75
|
+
extent: typeof aggregationFn_extent;
|
|
76
|
+
mean: typeof aggregationFn_mean;
|
|
77
|
+
median: typeof aggregationFn_median;
|
|
78
|
+
unique: typeof aggregationFn_unique;
|
|
79
|
+
uniqueCount: typeof aggregationFn_uniqueCount;
|
|
80
|
+
count: typeof aggregationFn_count;
|
|
79
81
|
};
|
|
80
82
|
type BuiltInAggregationFn = keyof typeof aggregationFns;
|
|
81
83
|
//#endregion
|
|
@@ -5,47 +5,47 @@
|
|
|
5
5
|
* Non-number values contribute `0`. Child rows are used so nested group totals
|
|
6
6
|
* can reuse already aggregated values.
|
|
7
7
|
*/
|
|
8
|
-
|
|
8
|
+
function aggregationFn_sum(columnId, _leafRows, childRows) {
|
|
9
9
|
return childRows.reduce((sumValue, next) => {
|
|
10
10
|
const nextValue = next.getValue(columnId);
|
|
11
11
|
return sumValue + (typeof nextValue === "number" ? nextValue : 0);
|
|
12
12
|
}, 0);
|
|
13
|
-
}
|
|
13
|
+
}
|
|
14
14
|
/**
|
|
15
15
|
* Finds the minimum numeric child-row value for a grouped column.
|
|
16
16
|
*
|
|
17
17
|
* Nullish and non-number values are ignored. Returns `undefined` when no
|
|
18
18
|
* numeric value is found.
|
|
19
19
|
*/
|
|
20
|
-
|
|
20
|
+
function aggregationFn_min(columnId, _leafRows, childRows) {
|
|
21
21
|
let minValue;
|
|
22
22
|
childRows.forEach((row) => {
|
|
23
23
|
const value = row.getValue(columnId);
|
|
24
24
|
if (value != null && typeof value === "number" && (minValue === void 0 || value < minValue)) minValue = value;
|
|
25
25
|
});
|
|
26
26
|
return minValue;
|
|
27
|
-
}
|
|
27
|
+
}
|
|
28
28
|
/**
|
|
29
29
|
* Finds the maximum numeric child-row value for a grouped column.
|
|
30
30
|
*
|
|
31
31
|
* Nullish and non-number values are ignored. Returns `undefined` when no
|
|
32
32
|
* numeric value is found.
|
|
33
33
|
*/
|
|
34
|
-
|
|
34
|
+
function aggregationFn_max(columnId, _leafRows, childRows) {
|
|
35
35
|
let maxValue;
|
|
36
36
|
childRows.forEach((row) => {
|
|
37
37
|
const value = row.getValue(columnId);
|
|
38
38
|
if (value != null && typeof value === "number" && (maxValue === void 0 || value > maxValue)) maxValue = value;
|
|
39
39
|
});
|
|
40
40
|
return maxValue;
|
|
41
|
-
}
|
|
41
|
+
}
|
|
42
42
|
/**
|
|
43
43
|
* Finds the numeric extent for a grouped column.
|
|
44
44
|
*
|
|
45
45
|
* Returns `[min, max]`, where each entry is `undefined` when no numeric value is
|
|
46
46
|
* present.
|
|
47
47
|
*/
|
|
48
|
-
|
|
48
|
+
function aggregationFn_extent(columnId, _leafRows, childRows) {
|
|
49
49
|
let minValue;
|
|
50
50
|
let maxValue;
|
|
51
51
|
childRows.forEach((row) => {
|
|
@@ -57,14 +57,14 @@ const aggregationFn_extent = (columnId, _leafRows, childRows) => {
|
|
|
57
57
|
}
|
|
58
58
|
});
|
|
59
59
|
return [minValue, maxValue];
|
|
60
|
-
}
|
|
60
|
+
}
|
|
61
61
|
/**
|
|
62
62
|
* Averages numeric leaf-row values for a grouped column.
|
|
63
63
|
*
|
|
64
64
|
* Number-like values are coerced with unary `+`; nullish and non-numeric values
|
|
65
65
|
* are ignored.
|
|
66
66
|
*/
|
|
67
|
-
|
|
67
|
+
function aggregationFn_mean(columnId, leafRows) {
|
|
68
68
|
let count = 0;
|
|
69
69
|
let sumValue = 0;
|
|
70
70
|
leafRows.forEach((row) => {
|
|
@@ -81,14 +81,14 @@ const aggregationFn_mean = (columnId, leafRows) => {
|
|
|
81
81
|
}
|
|
82
82
|
});
|
|
83
83
|
if (count) return sumValue / count;
|
|
84
|
-
}
|
|
84
|
+
}
|
|
85
85
|
/**
|
|
86
86
|
* Computes the median of numeric leaf-row values for a grouped column.
|
|
87
87
|
*
|
|
88
88
|
* All values must be numbers. If any value is non-numeric, or no leaf rows are
|
|
89
89
|
* present, the result is `undefined`.
|
|
90
90
|
*/
|
|
91
|
-
|
|
91
|
+
function aggregationFn_median(columnId, leafRows) {
|
|
92
92
|
if (!leafRows.length) return;
|
|
93
93
|
const values = new Array(leafRows.length);
|
|
94
94
|
for (let i = 0; i < leafRows.length; i++) {
|
|
@@ -100,35 +100,35 @@ const aggregationFn_median = (columnId, leafRows) => {
|
|
|
100
100
|
const mid = Math.floor(values.length / 2);
|
|
101
101
|
values.sort((a, b) => a - b);
|
|
102
102
|
return values.length % 2 !== 0 ? values[mid] : (values[mid - 1] + values[mid]) / 2;
|
|
103
|
-
}
|
|
103
|
+
}
|
|
104
104
|
/**
|
|
105
105
|
* Collects unique leaf-row values for a grouped column.
|
|
106
106
|
*
|
|
107
107
|
* Values are compared with JavaScript `Set` semantics.
|
|
108
108
|
*/
|
|
109
|
-
|
|
109
|
+
function aggregationFn_unique(columnId, leafRows) {
|
|
110
110
|
const set = /* @__PURE__ */ new Set();
|
|
111
111
|
for (let i = 0; i < leafRows.length; i++) set.add(leafRows[i].getValue(columnId));
|
|
112
112
|
return Array.from(set.values());
|
|
113
|
-
}
|
|
113
|
+
}
|
|
114
114
|
/**
|
|
115
115
|
* Counts unique leaf-row values for a grouped column.
|
|
116
116
|
*
|
|
117
117
|
* Values are compared with JavaScript `Set` semantics.
|
|
118
118
|
*/
|
|
119
|
-
|
|
119
|
+
function aggregationFn_uniqueCount(columnId, leafRows) {
|
|
120
120
|
const set = /* @__PURE__ */ new Set();
|
|
121
121
|
for (let i = 0; i < leafRows.length; i++) set.add(leafRows[i].getValue(columnId));
|
|
122
122
|
return set.size;
|
|
123
|
-
}
|
|
123
|
+
}
|
|
124
124
|
/**
|
|
125
125
|
* Counts the number of leaf rows in the group.
|
|
126
126
|
*
|
|
127
127
|
* The column id is ignored because the result is based only on group size.
|
|
128
128
|
*/
|
|
129
|
-
|
|
129
|
+
function aggregationFn_count(_columnId, leafRows) {
|
|
130
130
|
return leafRows.length;
|
|
131
|
-
}
|
|
131
|
+
}
|
|
132
132
|
/**
|
|
133
133
|
* The built-in aggregation function registry.
|
|
134
134
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aggregationFns.js","names":[],"sources":["../../src/fns/aggregationFns.ts"],"sourcesContent":["import type { RowData } from '../types/type-utils'\nimport type { TableFeatures } from '../types/TableFeatures'\nimport type { Row } from '../types/Row'\
|
|
1
|
+
{"version":3,"file":"aggregationFns.js","names":[],"sources":["../../src/fns/aggregationFns.ts"],"sourcesContent":["import type { RowData } from '../types/type-utils'\nimport type { TableFeatures } from '../types/TableFeatures'\nimport type { Row } from '../types/Row'\n\n/**\n * Sums numeric child-row values for a grouped column.\n *\n * Non-number values contribute `0`. Child rows are used so nested group totals\n * can reuse already aggregated values.\n */\nexport function aggregationFn_sum<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n columnId: string,\n _leafRows: Array<Row<TFeatures, TData>>,\n childRows: Array<Row<TFeatures, TData>>,\n) {\n // It's faster to just add the aggregations together instead of\n // process leaf nodes individually\n return childRows.reduce((sumValue, next) => {\n const nextValue = next.getValue(columnId)\n return sumValue + (typeof nextValue === 'number' ? nextValue : 0)\n }, 0)\n}\n\n/**\n * Finds the minimum numeric child-row value for a grouped column.\n *\n * Nullish and non-number values are ignored. Returns `undefined` when no\n * numeric value is found.\n */\nexport function aggregationFn_min<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n columnId: string,\n _leafRows: Array<Row<TFeatures, TData>>,\n childRows: Array<Row<TFeatures, TData>>,\n) {\n let minValue: number | undefined\n\n childRows.forEach((row) => {\n const value = row.getValue(columnId)\n\n if (\n value != null &&\n typeof value === 'number' &&\n (minValue === undefined || value < minValue)\n ) {\n minValue = value\n }\n })\n\n return minValue\n}\n\n/**\n * Finds the maximum numeric child-row value for a grouped column.\n *\n * Nullish and non-number values are ignored. Returns `undefined` when no\n * numeric value is found.\n */\nexport function aggregationFn_max<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n columnId: string,\n _leafRows: Array<Row<TFeatures, TData>>,\n childRows: Array<Row<TFeatures, TData>>,\n) {\n let maxValue: number | undefined\n\n childRows.forEach((row) => {\n const value = row.getValue(columnId)\n if (\n value != null &&\n typeof value === 'number' &&\n (maxValue === undefined || value > maxValue)\n ) {\n maxValue = value\n }\n })\n\n return maxValue\n}\n\n/**\n * Finds the numeric extent for a grouped column.\n *\n * Returns `[min, max]`, where each entry is `undefined` when no numeric value is\n * present.\n */\nexport function aggregationFn_extent<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n columnId: string,\n _leafRows: Array<Row<TFeatures, TData>>,\n childRows: Array<Row<TFeatures, TData>>,\n) {\n let minValue: number | undefined\n let maxValue: number | undefined\n\n childRows.forEach((row) => {\n const value = row.getValue(columnId)\n if (value != null && typeof value === 'number') {\n if (minValue === undefined) {\n minValue = maxValue = value\n } else {\n if (minValue > value) minValue = value\n if (maxValue! < value) maxValue = value\n }\n }\n })\n\n return [minValue, maxValue]\n}\n\n/**\n * Averages numeric leaf-row values for a grouped column.\n *\n * Number-like values are coerced with unary `+`; nullish and non-numeric values\n * are ignored.\n */\nexport function aggregationFn_mean<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(columnId: string, leafRows: Array<Row<TFeatures, TData>>) {\n let count = 0\n let sumValue = 0\n\n leafRows.forEach((row) => {\n const value = row.getValue(columnId)\n if (value != null && typeof value === 'number') {\n ++count\n sumValue += value\n } else if (value != null) {\n const numValue = +value\n if (!Number.isNaN(numValue)) {\n ++count\n sumValue += numValue\n }\n }\n })\n\n if (count) return sumValue / count\n\n return\n}\n\n/**\n * Computes the median of numeric leaf-row values for a grouped column.\n *\n * All values must be numbers. If any value is non-numeric, or no leaf rows are\n * present, the result is `undefined`.\n */\nexport function aggregationFn_median<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(columnId: string, leafRows: Array<Row<TFeatures, TData>>) {\n if (!leafRows.length) {\n return\n }\n\n const values: Array<number> = new Array(leafRows.length)\n for (let i = 0; i < leafRows.length; i++) {\n const v = leafRows[i]!.getValue(columnId)\n if (typeof v !== 'number') return\n values[i] = v\n }\n\n if (values.length === 1) {\n return values[0]\n }\n\n const mid = Math.floor(values.length / 2)\n values.sort((a, b) => a - b)\n return values.length % 2 !== 0\n ? values[mid]\n : (values[mid - 1]! + values[mid]!) / 2\n}\n\n/**\n * Collects unique leaf-row values for a grouped column.\n *\n * Values are compared with JavaScript `Set` semantics.\n */\nexport function aggregationFn_unique<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(columnId: string, leafRows: Array<Row<TFeatures, TData>>) {\n const set = new Set<unknown>()\n for (let i = 0; i < leafRows.length; i++) {\n set.add(leafRows[i]!.getValue(columnId))\n }\n return Array.from(set.values())\n}\n\n/**\n * Counts unique leaf-row values for a grouped column.\n *\n * Values are compared with JavaScript `Set` semantics.\n */\nexport function aggregationFn_uniqueCount<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(columnId: string, leafRows: Array<Row<TFeatures, TData>>) {\n const set = new Set<unknown>()\n for (let i = 0; i < leafRows.length; i++) {\n set.add(leafRows[i]!.getValue(columnId))\n }\n return set.size\n}\n\n/**\n * Counts the number of leaf rows in the group.\n *\n * The column id is ignored because the result is based only on group size.\n */\nexport function aggregationFn_count<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(_columnId: string, leafRows: Array<Row<TFeatures, TData>>) {\n return leafRows.length\n}\n\n/**\n * The built-in aggregation function registry.\n *\n * Pass this object to grouped row model creation or extend it with custom aggregation functions for grouped columns.\n */\nexport const aggregationFns = {\n sum: aggregationFn_sum,\n min: aggregationFn_min,\n max: aggregationFn_max,\n extent: aggregationFn_extent,\n mean: aggregationFn_mean,\n median: aggregationFn_median,\n unique: aggregationFn_unique,\n uniqueCount: aggregationFn_uniqueCount,\n count: aggregationFn_count,\n}\n\nexport type BuiltInAggregationFn = keyof typeof aggregationFns\n"],"mappings":"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"}
|