@tanstack/table-core 9.0.0-alpha.47 → 9.0.0-alpha.48
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/README.md +10 -0
- package/dist/core/cells/coreCellsFeature.utils.cjs +11 -8
- package/dist/core/cells/coreCellsFeature.utils.cjs.map +1 -1
- package/dist/core/cells/coreCellsFeature.utils.d.cts +11 -8
- package/dist/core/cells/coreCellsFeature.utils.d.ts +11 -8
- package/dist/core/cells/coreCellsFeature.utils.js +11 -8
- package/dist/core/cells/coreCellsFeature.utils.js.map +1 -1
- package/dist/core/columns/coreColumnsFeature.types.d.cts +7 -6
- package/dist/core/columns/coreColumnsFeature.types.d.ts +7 -6
- package/dist/core/columns/coreColumnsFeature.utils.cjs +37 -27
- package/dist/core/columns/coreColumnsFeature.utils.cjs.map +1 -1
- package/dist/core/columns/coreColumnsFeature.utils.d.cts +37 -27
- package/dist/core/columns/coreColumnsFeature.utils.d.ts +37 -27
- package/dist/core/columns/coreColumnsFeature.utils.js +37 -27
- package/dist/core/columns/coreColumnsFeature.utils.js.map +1 -1
- package/dist/core/headers/coreHeadersFeature.types.d.cts +6 -4
- package/dist/core/headers/coreHeadersFeature.types.d.ts +6 -4
- package/dist/core/headers/coreHeadersFeature.utils.cjs +23 -18
- package/dist/core/headers/coreHeadersFeature.utils.cjs.map +1 -1
- package/dist/core/headers/coreHeadersFeature.utils.d.cts +23 -18
- package/dist/core/headers/coreHeadersFeature.utils.d.ts +23 -18
- package/dist/core/headers/coreHeadersFeature.utils.js +23 -18
- package/dist/core/headers/coreHeadersFeature.utils.js.map +1 -1
- package/dist/core/row-models/coreRowModelsFeature.utils.cjs +48 -36
- package/dist/core/row-models/coreRowModelsFeature.utils.cjs.map +1 -1
- package/dist/core/row-models/coreRowModelsFeature.utils.d.cts +48 -36
- package/dist/core/row-models/coreRowModelsFeature.utils.d.ts +48 -36
- package/dist/core/row-models/coreRowModelsFeature.utils.js +48 -36
- package/dist/core/row-models/coreRowModelsFeature.utils.js.map +1 -1
- package/dist/core/rows/coreRowsFeature.types.d.cts +4 -4
- package/dist/core/rows/coreRowsFeature.types.d.ts +4 -4
- package/dist/core/rows/coreRowsFeature.utils.cjs +34 -28
- package/dist/core/rows/coreRowsFeature.utils.cjs.map +1 -1
- package/dist/core/rows/coreRowsFeature.utils.d.cts +34 -28
- package/dist/core/rows/coreRowsFeature.utils.d.ts +34 -28
- package/dist/core/rows/coreRowsFeature.utils.js +34 -28
- package/dist/core/rows/coreRowsFeature.utils.js.map +1 -1
- package/dist/core/table/coreTablesFeature.types.d.cts +6 -2
- package/dist/core/table/coreTablesFeature.types.d.ts +6 -2
- package/dist/core/table/coreTablesFeature.utils.cjs +2 -2
- package/dist/core/table/coreTablesFeature.utils.cjs.map +1 -1
- package/dist/core/table/coreTablesFeature.utils.d.cts +2 -2
- package/dist/core/table/coreTablesFeature.utils.d.ts +2 -2
- package/dist/core/table/coreTablesFeature.utils.js +2 -2
- package/dist/core/table/coreTablesFeature.utils.js.map +1 -1
- package/dist/features/column-faceting/columnFacetingFeature.types.d.cts +16 -10
- package/dist/features/column-faceting/columnFacetingFeature.types.d.ts +16 -10
- package/dist/features/column-faceting/columnFacetingFeature.utils.cjs +26 -18
- package/dist/features/column-faceting/columnFacetingFeature.utils.cjs.map +1 -1
- package/dist/features/column-faceting/columnFacetingFeature.utils.d.cts +26 -18
- package/dist/features/column-faceting/columnFacetingFeature.utils.d.ts +26 -18
- package/dist/features/column-faceting/columnFacetingFeature.utils.js +26 -18
- package/dist/features/column-faceting/columnFacetingFeature.utils.js.map +1 -1
- package/dist/features/column-filtering/columnFilteringFeature.types.d.cts +21 -11
- package/dist/features/column-filtering/columnFilteringFeature.types.d.ts +21 -11
- package/dist/features/column-filtering/columnFilteringFeature.utils.cjs +39 -28
- package/dist/features/column-filtering/columnFilteringFeature.utils.cjs.map +1 -1
- package/dist/features/column-filtering/columnFilteringFeature.utils.d.cts +39 -28
- package/dist/features/column-filtering/columnFilteringFeature.utils.d.ts +39 -28
- package/dist/features/column-filtering/columnFilteringFeature.utils.js +39 -28
- package/dist/features/column-filtering/columnFilteringFeature.utils.js.map +1 -1
- package/dist/features/column-grouping/columnGroupingFeature.types.d.cts +18 -14
- package/dist/features/column-grouping/columnGroupingFeature.types.d.ts +18 -14
- package/dist/features/column-grouping/columnGroupingFeature.utils.cjs +55 -43
- package/dist/features/column-grouping/columnGroupingFeature.utils.cjs.map +1 -1
- package/dist/features/column-grouping/columnGroupingFeature.utils.d.cts +55 -43
- package/dist/features/column-grouping/columnGroupingFeature.utils.d.ts +55 -43
- package/dist/features/column-grouping/columnGroupingFeature.utils.js +55 -43
- package/dist/features/column-grouping/columnGroupingFeature.utils.js.map +1 -1
- package/dist/features/column-ordering/columnOrderingFeature.types.d.cts +14 -5
- package/dist/features/column-ordering/columnOrderingFeature.types.d.ts +14 -5
- package/dist/features/column-ordering/columnOrderingFeature.utils.cjs +30 -23
- package/dist/features/column-ordering/columnOrderingFeature.utils.cjs.map +1 -1
- package/dist/features/column-ordering/columnOrderingFeature.utils.d.cts +30 -23
- package/dist/features/column-ordering/columnOrderingFeature.utils.d.ts +30 -23
- package/dist/features/column-ordering/columnOrderingFeature.utils.js +30 -23
- package/dist/features/column-ordering/columnOrderingFeature.utils.js.map +1 -1
- package/dist/features/column-pinning/columnPinningFeature.types.d.cts +43 -31
- package/dist/features/column-pinning/columnPinningFeature.types.d.ts +43 -31
- package/dist/features/column-pinning/columnPinningFeature.utils.cjs +111 -91
- package/dist/features/column-pinning/columnPinningFeature.utils.cjs.map +1 -1
- package/dist/features/column-pinning/columnPinningFeature.utils.d.cts +111 -91
- package/dist/features/column-pinning/columnPinningFeature.utils.d.ts +111 -91
- package/dist/features/column-pinning/columnPinningFeature.utils.js +111 -91
- package/dist/features/column-pinning/columnPinningFeature.utils.js.map +1 -1
- package/dist/features/column-resizing/columnResizingFeature.types.d.cts +9 -9
- package/dist/features/column-resizing/columnResizingFeature.types.d.ts +9 -9
- package/dist/features/column-resizing/columnResizingFeature.utils.cjs +28 -19
- package/dist/features/column-resizing/columnResizingFeature.utils.cjs.map +1 -1
- package/dist/features/column-resizing/columnResizingFeature.utils.d.cts +28 -19
- package/dist/features/column-resizing/columnResizingFeature.utils.d.ts +28 -19
- package/dist/features/column-resizing/columnResizingFeature.utils.js +28 -19
- package/dist/features/column-resizing/columnResizingFeature.utils.js.map +1 -1
- package/dist/features/column-sizing/columnSizingFeature.types.d.cts +19 -12
- package/dist/features/column-sizing/columnSizingFeature.types.d.ts +19 -12
- package/dist/features/column-sizing/columnSizingFeature.utils.cjs +52 -41
- package/dist/features/column-sizing/columnSizingFeature.utils.cjs.map +1 -1
- package/dist/features/column-sizing/columnSizingFeature.utils.d.cts +52 -41
- package/dist/features/column-sizing/columnSizingFeature.utils.d.ts +52 -41
- package/dist/features/column-sizing/columnSizingFeature.utils.js +52 -41
- package/dist/features/column-sizing/columnSizingFeature.utils.js.map +1 -1
- package/dist/features/column-visibility/columnVisibilityFeature.types.d.cts +16 -13
- package/dist/features/column-visibility/columnVisibilityFeature.types.d.ts +16 -13
- package/dist/features/column-visibility/columnVisibilityFeature.utils.cjs +54 -42
- package/dist/features/column-visibility/columnVisibilityFeature.utils.cjs.map +1 -1
- package/dist/features/column-visibility/columnVisibilityFeature.utils.d.cts +54 -42
- package/dist/features/column-visibility/columnVisibilityFeature.utils.d.ts +54 -42
- package/dist/features/column-visibility/columnVisibilityFeature.utils.js +54 -42
- package/dist/features/column-visibility/columnVisibilityFeature.utils.js.map +1 -1
- package/dist/features/global-filtering/globalFilteringFeature.types.d.cts +10 -5
- package/dist/features/global-filtering/globalFilteringFeature.types.d.ts +10 -5
- package/dist/features/global-filtering/globalFilteringFeature.utils.cjs +20 -14
- package/dist/features/global-filtering/globalFilteringFeature.utils.cjs.map +1 -1
- package/dist/features/global-filtering/globalFilteringFeature.utils.d.cts +20 -14
- package/dist/features/global-filtering/globalFilteringFeature.utils.d.ts +20 -14
- package/dist/features/global-filtering/globalFilteringFeature.utils.js +20 -14
- package/dist/features/global-filtering/globalFilteringFeature.utils.js.map +1 -1
- package/dist/features/row-expanding/rowExpandingFeature.types.d.cts +16 -15
- package/dist/features/row-expanding/rowExpandingFeature.types.d.ts +16 -15
- package/dist/features/row-expanding/rowExpandingFeature.utils.cjs +56 -41
- package/dist/features/row-expanding/rowExpandingFeature.utils.cjs.map +1 -1
- package/dist/features/row-expanding/rowExpandingFeature.utils.d.cts +56 -41
- package/dist/features/row-expanding/rowExpandingFeature.utils.d.ts +56 -41
- package/dist/features/row-expanding/rowExpandingFeature.utils.js +56 -41
- package/dist/features/row-expanding/rowExpandingFeature.utils.js.map +1 -1
- package/dist/features/row-pagination/rowPaginationFeature.types.d.cts +19 -12
- package/dist/features/row-pagination/rowPaginationFeature.types.d.ts +19 -12
- package/dist/features/row-pagination/rowPaginationFeature.utils.cjs +49 -32
- package/dist/features/row-pagination/rowPaginationFeature.utils.cjs.map +1 -1
- package/dist/features/row-pagination/rowPaginationFeature.utils.d.cts +49 -32
- package/dist/features/row-pagination/rowPaginationFeature.utils.d.ts +49 -32
- package/dist/features/row-pagination/rowPaginationFeature.utils.js +49 -32
- package/dist/features/row-pagination/rowPaginationFeature.utils.js.map +1 -1
- package/dist/features/row-pinning/rowPinningFeature.types.d.cts +12 -8
- package/dist/features/row-pinning/rowPinningFeature.types.d.ts +12 -8
- package/dist/features/row-pinning/rowPinningFeature.utils.cjs +39 -29
- package/dist/features/row-pinning/rowPinningFeature.utils.cjs.map +1 -1
- package/dist/features/row-pinning/rowPinningFeature.utils.d.cts +39 -29
- package/dist/features/row-pinning/rowPinningFeature.utils.d.ts +39 -29
- package/dist/features/row-pinning/rowPinningFeature.utils.js +39 -29
- package/dist/features/row-pinning/rowPinningFeature.utils.js.map +1 -1
- package/dist/features/row-selection/rowSelectionFeature.types.d.cts +30 -24
- package/dist/features/row-selection/rowSelectionFeature.types.d.ts +30 -24
- package/dist/features/row-selection/rowSelectionFeature.utils.cjs +89 -69
- package/dist/features/row-selection/rowSelectionFeature.utils.cjs.map +1 -1
- package/dist/features/row-selection/rowSelectionFeature.utils.d.cts +89 -69
- package/dist/features/row-selection/rowSelectionFeature.utils.d.ts +89 -69
- package/dist/features/row-selection/rowSelectionFeature.utils.js +89 -69
- package/dist/features/row-selection/rowSelectionFeature.utils.js.map +1 -1
- package/dist/features/row-sorting/rowSortingFeature.types.d.cts +10 -8
- package/dist/features/row-sorting/rowSortingFeature.types.d.ts +10 -8
- package/dist/features/row-sorting/rowSortingFeature.utils.cjs +61 -44
- package/dist/features/row-sorting/rowSortingFeature.utils.cjs.map +1 -1
- package/dist/features/row-sorting/rowSortingFeature.utils.d.cts +61 -44
- package/dist/features/row-sorting/rowSortingFeature.utils.d.ts +61 -44
- package/dist/features/row-sorting/rowSortingFeature.utils.js +61 -44
- package/dist/features/row-sorting/rowSortingFeature.utils.js.map +1 -1
- package/dist/fns/aggregationFns.cjs +33 -9
- package/dist/fns/aggregationFns.cjs.map +1 -1
- package/dist/fns/aggregationFns.d.cts +33 -9
- package/dist/fns/aggregationFns.d.ts +33 -9
- package/dist/fns/aggregationFns.js +33 -9
- package/dist/fns/aggregationFns.js.map +1 -1
- package/dist/fns/filterFns.cjs +48 -17
- package/dist/fns/filterFns.cjs.map +1 -1
- package/dist/fns/filterFns.d.cts +42 -15
- package/dist/fns/filterFns.d.ts +42 -15
- package/dist/fns/filterFns.js +48 -17
- package/dist/fns/filterFns.js.map +1 -1
- package/dist/helpers/columnHelper.cjs +9 -4
- package/dist/helpers/columnHelper.cjs.map +1 -1
- package/dist/helpers/columnHelper.d.cts +9 -4
- package/dist/helpers/columnHelper.d.ts +9 -4
- package/dist/helpers/columnHelper.js +9 -4
- package/dist/helpers/columnHelper.js.map +1 -1
- package/dist/helpers/tableOptions.cjs.map +1 -1
- package/dist/helpers/tableOptions.d.cts +12 -9
- package/dist/helpers/tableOptions.d.ts +12 -9
- package/dist/helpers/tableOptions.js.map +1 -1
- package/dist/types/ColumnDef.d.cts +38 -0
- package/dist/types/ColumnDef.d.ts +38 -0
- package/dist/types/TableOptions.d.cts +15 -0
- package/dist/types/TableOptions.d.ts +15 -0
- package/dist/types/TableState.d.cts +12 -0
- package/dist/types/TableState.d.ts +12 -0
- package/package.json +5 -3
- package/skills/column-definitions/SKILL.md +333 -0
- package/skills/column-layout/SKILL.md +328 -0
- package/skills/column-layout/references/subsystems.md +220 -0
- package/skills/customizing-feature-behavior/SKILL.md +416 -0
- package/skills/filtering/SKILL.md +357 -0
- package/skills/filtering/references/faceting-and-fuzzy.md +191 -0
- package/skills/grouping/SKILL.md +448 -0
- package/skills/migrate-v8-to-v9/SKILL.md +495 -0
- package/skills/pagination/SKILL.md +385 -0
- package/skills/row-expanding/SKILL.md +348 -0
- package/skills/row-pinning/SKILL.md +269 -0
- package/skills/row-selection/SKILL.md +391 -0
- package/skills/setup/SKILL.md +400 -0
- package/skills/sorting/SKILL.md +344 -0
- package/skills/state-management/SKILL.md +388 -0
- package/src/core/cells/coreCellsFeature.utils.ts +11 -8
- package/src/core/columns/coreColumnsFeature.types.ts +7 -6
- package/src/core/columns/coreColumnsFeature.utils.ts +37 -27
- package/src/core/headers/coreHeadersFeature.types.ts +6 -4
- package/src/core/headers/coreHeadersFeature.utils.ts +23 -18
- package/src/core/row-models/coreRowModelsFeature.utils.ts +48 -36
- package/src/core/rows/coreRowsFeature.types.ts +4 -4
- package/src/core/rows/coreRowsFeature.utils.ts +34 -28
- package/src/core/table/coreTablesFeature.types.ts +6 -2
- package/src/core/table/coreTablesFeature.utils.ts +2 -2
- package/src/features/column-faceting/columnFacetingFeature.types.ts +16 -10
- package/src/features/column-faceting/columnFacetingFeature.utils.ts +26 -18
- package/src/features/column-filtering/columnFilteringFeature.types.ts +21 -11
- package/src/features/column-filtering/columnFilteringFeature.utils.ts +39 -28
- package/src/features/column-grouping/columnGroupingFeature.types.ts +18 -14
- package/src/features/column-grouping/columnGroupingFeature.utils.ts +55 -43
- package/src/features/column-ordering/columnOrderingFeature.types.ts +14 -5
- package/src/features/column-ordering/columnOrderingFeature.utils.ts +30 -23
- package/src/features/column-pinning/columnPinningFeature.types.ts +43 -31
- package/src/features/column-pinning/columnPinningFeature.utils.ts +111 -91
- package/src/features/column-resizing/columnResizingFeature.types.ts +9 -9
- package/src/features/column-resizing/columnResizingFeature.utils.ts +28 -19
- package/src/features/column-sizing/columnSizingFeature.types.ts +19 -12
- package/src/features/column-sizing/columnSizingFeature.utils.ts +52 -41
- package/src/features/column-visibility/columnVisibilityFeature.types.ts +16 -13
- package/src/features/column-visibility/columnVisibilityFeature.utils.ts +54 -42
- package/src/features/global-filtering/globalFilteringFeature.types.ts +10 -5
- package/src/features/global-filtering/globalFilteringFeature.utils.ts +20 -14
- package/src/features/row-expanding/rowExpandingFeature.types.ts +16 -15
- package/src/features/row-expanding/rowExpandingFeature.utils.ts +56 -41
- package/src/features/row-pagination/rowPaginationFeature.types.ts +19 -12
- package/src/features/row-pagination/rowPaginationFeature.utils.ts +49 -32
- package/src/features/row-pinning/rowPinningFeature.types.ts +12 -8
- package/src/features/row-pinning/rowPinningFeature.utils.ts +39 -29
- package/src/features/row-selection/rowSelectionFeature.types.ts +30 -24
- package/src/features/row-selection/rowSelectionFeature.utils.ts +89 -69
- package/src/features/row-sorting/rowSortingFeature.types.ts +10 -8
- package/src/features/row-sorting/rowSortingFeature.utils.ts +61 -44
- package/src/fns/aggregationFns.ts +33 -9
- package/src/fns/filterFns.ts +48 -17
- package/src/helpers/columnHelper.ts +9 -4
- package/src/helpers/tableOptions.ts +12 -9
- package/src/types/ColumnDef.ts +38 -0
- package/src/types/TableOptions.ts +15 -0
- package/src/types/TableState.ts +12 -0
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
|
|
2
2
|
//#region src/fns/aggregationFns.ts
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Sums numeric child-row values for a grouped column.
|
|
5
|
+
*
|
|
6
|
+
* Non-number values contribute `0`. Child rows are used so nested group totals
|
|
7
|
+
* can reuse already aggregated values.
|
|
5
8
|
*/
|
|
6
9
|
const aggregationFn_sum = (columnId, _leafRows, childRows) => {
|
|
7
10
|
return childRows.reduce((sumValue, next) => {
|
|
@@ -10,7 +13,10 @@ const aggregationFn_sum = (columnId, _leafRows, childRows) => {
|
|
|
10
13
|
}, 0);
|
|
11
14
|
};
|
|
12
15
|
/**
|
|
13
|
-
*
|
|
16
|
+
* Finds the minimum numeric child-row value for a grouped column.
|
|
17
|
+
*
|
|
18
|
+
* Nullish and non-number values are ignored. Returns `undefined` when no
|
|
19
|
+
* numeric value is found.
|
|
14
20
|
*/
|
|
15
21
|
const aggregationFn_min = (columnId, _leafRows, childRows) => {
|
|
16
22
|
let minValue;
|
|
@@ -21,7 +27,10 @@ const aggregationFn_min = (columnId, _leafRows, childRows) => {
|
|
|
21
27
|
return minValue;
|
|
22
28
|
};
|
|
23
29
|
/**
|
|
24
|
-
*
|
|
30
|
+
* Finds the maximum numeric child-row value for a grouped column.
|
|
31
|
+
*
|
|
32
|
+
* Nullish and non-number values are ignored. Returns `undefined` when no
|
|
33
|
+
* numeric value is found.
|
|
25
34
|
*/
|
|
26
35
|
const aggregationFn_max = (columnId, _leafRows, childRows) => {
|
|
27
36
|
let maxValue;
|
|
@@ -32,7 +41,10 @@ const aggregationFn_max = (columnId, _leafRows, childRows) => {
|
|
|
32
41
|
return maxValue;
|
|
33
42
|
};
|
|
34
43
|
/**
|
|
35
|
-
*
|
|
44
|
+
* Finds the numeric extent for a grouped column.
|
|
45
|
+
*
|
|
46
|
+
* Returns `[min, max]`, where each entry is `undefined` when no numeric value is
|
|
47
|
+
* present.
|
|
36
48
|
*/
|
|
37
49
|
const aggregationFn_extent = (columnId, _leafRows, childRows) => {
|
|
38
50
|
let minValue;
|
|
@@ -48,7 +60,10 @@ const aggregationFn_extent = (columnId, _leafRows, childRows) => {
|
|
|
48
60
|
return [minValue, maxValue];
|
|
49
61
|
};
|
|
50
62
|
/**
|
|
51
|
-
*
|
|
63
|
+
* Averages numeric leaf-row values for a grouped column.
|
|
64
|
+
*
|
|
65
|
+
* Number-like values are coerced with unary `+`; nullish and non-numeric values
|
|
66
|
+
* are ignored.
|
|
52
67
|
*/
|
|
53
68
|
const aggregationFn_mean = (columnId, leafRows) => {
|
|
54
69
|
let count = 0;
|
|
@@ -69,7 +84,10 @@ const aggregationFn_mean = (columnId, leafRows) => {
|
|
|
69
84
|
if (count) return sumValue / count;
|
|
70
85
|
};
|
|
71
86
|
/**
|
|
72
|
-
*
|
|
87
|
+
* Computes the median of numeric leaf-row values for a grouped column.
|
|
88
|
+
*
|
|
89
|
+
* All values must be numbers. If any value is non-numeric, or no leaf rows are
|
|
90
|
+
* present, the result is `undefined`.
|
|
73
91
|
*/
|
|
74
92
|
const aggregationFn_median = (columnId, leafRows) => {
|
|
75
93
|
if (!leafRows.length) return;
|
|
@@ -85,7 +103,9 @@ const aggregationFn_median = (columnId, leafRows) => {
|
|
|
85
103
|
return values.length % 2 !== 0 ? values[mid] : (values[mid - 1] + values[mid]) / 2;
|
|
86
104
|
};
|
|
87
105
|
/**
|
|
88
|
-
*
|
|
106
|
+
* Collects unique leaf-row values for a grouped column.
|
|
107
|
+
*
|
|
108
|
+
* Values are compared with JavaScript `Set` semantics.
|
|
89
109
|
*/
|
|
90
110
|
const aggregationFn_unique = (columnId, leafRows) => {
|
|
91
111
|
const set = /* @__PURE__ */ new Set();
|
|
@@ -93,7 +113,9 @@ const aggregationFn_unique = (columnId, leafRows) => {
|
|
|
93
113
|
return Array.from(set.values());
|
|
94
114
|
};
|
|
95
115
|
/**
|
|
96
|
-
*
|
|
116
|
+
* Counts unique leaf-row values for a grouped column.
|
|
117
|
+
*
|
|
118
|
+
* Values are compared with JavaScript `Set` semantics.
|
|
97
119
|
*/
|
|
98
120
|
const aggregationFn_uniqueCount = (columnId, leafRows) => {
|
|
99
121
|
const set = /* @__PURE__ */ new Set();
|
|
@@ -101,7 +123,9 @@ const aggregationFn_uniqueCount = (columnId, leafRows) => {
|
|
|
101
123
|
return set.size;
|
|
102
124
|
};
|
|
103
125
|
/**
|
|
104
|
-
*
|
|
126
|
+
* Counts the number of leaf rows in the group.
|
|
127
|
+
*
|
|
128
|
+
* The column id is ignored because the result is based only on group size.
|
|
105
129
|
*/
|
|
106
130
|
const aggregationFn_count = (_columnId, leafRows) => {
|
|
107
131
|
return leafRows.length;
|
|
@@ -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'\nimport type { AggregationFn } from '../features/column-grouping/columnGroupingFeature.types'\n\n/**\n *
|
|
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'\nimport type { AggregationFn } from '../features/column-grouping/columnGroupingFeature.types'\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 const aggregationFn_sum: AggregationFn<any, any> = <\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n columnId: string,\n _leafRows: Array<Row<any, any>>,\n childRows: Array<Row<any, any>>,\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 const aggregationFn_min: AggregationFn<any, any> = <\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n columnId: string,\n _leafRows: Array<Row<any, any>>,\n childRows: Array<Row<any, any>>,\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 const aggregationFn_max: AggregationFn<any, any> = <\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n columnId: string,\n _leafRows: Array<Row<any, any>>,\n childRows: Array<Row<any, any>>,\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 const aggregationFn_extent: AggregationFn<any, any> = <\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n columnId: string,\n _leafRows: Array<Row<any, any>>,\n childRows: Array<Row<any, any>>,\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 const aggregationFn_mean: AggregationFn<any, any> = <\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n columnId: string,\n leafRows: Array<Row<any, any>>,\n) => {\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 const aggregationFn_median: AggregationFn<any, any> = <\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n columnId: string,\n leafRows: Array<Row<any, any>>,\n) => {\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 const aggregationFn_unique: AggregationFn<any, any> = <\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n columnId: string,\n leafRows: Array<Row<any, any>>,\n) => {\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 const aggregationFn_uniqueCount: AggregationFn<any, any> = <\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n columnId: string,\n leafRows: Array<Row<any, any>>,\n) => {\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 const aggregationFn_count: AggregationFn<any, any> = <\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n _columnId: string,\n leafRows: Array<Row<any, any>>,\n) => {\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":";;;;;;;;AAWA,MAAa,qBAIX,UACA,WACA,cACG;CAGH,OAAO,UAAU,QAAQ,UAAU,SAAS;EAC1C,MAAM,YAAY,KAAK,SAAS,SAAS;EACzC,OAAO,YAAY,OAAO,cAAc,WAAW,YAAY;IAC9D,EAAE;;;;;;;;AASP,MAAa,qBAIX,UACA,WACA,cACG;CACH,IAAI;CAEJ,UAAU,SAAS,QAAQ;EACzB,MAAM,QAAQ,IAAI,SAAS,SAAS;EAEpC,IACE,SAAS,QACT,OAAO,UAAU,aAChB,aAAa,UAAa,QAAQ,WAEnC,WAAW;GAEb;CAEF,OAAO;;;;;;;;AAST,MAAa,qBAIX,UACA,WACA,cACG;CACH,IAAI;CAEJ,UAAU,SAAS,QAAQ;EACzB,MAAM,QAAQ,IAAI,SAAS,SAAS;EACpC,IACE,SAAS,QACT,OAAO,UAAU,aAChB,aAAa,UAAa,QAAQ,WAEnC,WAAW;GAEb;CAEF,OAAO;;;;;;;;AAST,MAAa,wBAIX,UACA,WACA,cACG;CACH,IAAI;CACJ,IAAI;CAEJ,UAAU,SAAS,QAAQ;EACzB,MAAM,QAAQ,IAAI,SAAS,SAAS;EACpC,IAAI,SAAS,QAAQ,OAAO,UAAU,UACpC,IAAI,aAAa,QACf,WAAW,WAAW;OACjB;GACL,IAAI,WAAW,OAAO,WAAW;GACjC,IAAI,WAAY,OAAO,WAAW;;GAGtC;CAEF,OAAO,CAAC,UAAU,SAAS;;;;;;;;AAS7B,MAAa,sBAIX,UACA,aACG;CACH,IAAI,QAAQ;CACZ,IAAI,WAAW;CAEf,SAAS,SAAS,QAAQ;EACxB,MAAM,QAAQ,IAAI,SAAS,SAAS;EACpC,IAAI,SAAS,QAAQ,OAAO,UAAU,UAAU;GAC9C,EAAE;GACF,YAAY;SACP,IAAI,SAAS,MAAM;GACxB,MAAM,WAAW,CAAC;GAClB,IAAI,CAAC,OAAO,MAAM,SAAS,EAAE;IAC3B,EAAE;IACF,YAAY;;;GAGhB;CAEF,IAAI,OAAO,OAAO,WAAW;;;;;;;;AAW/B,MAAa,wBAIX,UACA,aACG;CACH,IAAI,CAAC,SAAS,QACZ;CAGF,MAAM,SAAwB,IAAI,MAAM,SAAS,OAAO;CACxD,KAAK,IAAI,IAAI,GAAG,IAAI,SAAS,QAAQ,KAAK;EACxC,MAAM,IAAI,SAAS,GAAI,SAAS,SAAS;EACzC,IAAI,OAAO,MAAM,UAAU;EAC3B,OAAO,KAAK;;CAGd,IAAI,OAAO,WAAW,GACpB,OAAO,OAAO;CAGhB,MAAM,MAAM,KAAK,MAAM,OAAO,SAAS,EAAE;CACzC,OAAO,MAAM,GAAG,MAAM,IAAI,EAAE;CAC5B,OAAO,OAAO,SAAS,MAAM,IACzB,OAAO,QACN,OAAO,MAAM,KAAM,OAAO,QAAS;;;;;;;AAQ1C,MAAa,wBAIX,UACA,aACG;CACH,MAAM,sBAAM,IAAI,KAAc;CAC9B,KAAK,IAAI,IAAI,GAAG,IAAI,SAAS,QAAQ,KACnC,IAAI,IAAI,SAAS,GAAI,SAAS,SAAS,CAAC;CAE1C,OAAO,MAAM,KAAK,IAAI,QAAQ,CAAC;;;;;;;AAQjC,MAAa,6BAIX,UACA,aACG;CACH,MAAM,sBAAM,IAAI,KAAc;CAC9B,KAAK,IAAI,IAAI,GAAG,IAAI,SAAS,QAAQ,KACnC,IAAI,IAAI,SAAS,GAAI,SAAS,SAAS,CAAC;CAE1C,OAAO,IAAI;;;;;;;AAQb,MAAa,uBAIX,WACA,aACG;CACH,OAAO,SAAS;;;;;;;AAQlB,MAAa,iBAAiB;CAC5B,KAAK;CACL,KAAK;CACL,KAAK;CACL,QAAQ;CACR,MAAM;CACN,QAAQ;CACR,QAAQ;CACR,aAAa;CACb,OAAO;CACR"}
|
|
@@ -2,39 +2,63 @@ import { AggregationFn } from "../features/column-grouping/columnGroupingFeature
|
|
|
2
2
|
|
|
3
3
|
//#region src/fns/aggregationFns.d.ts
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* Sums numeric child-row values for a grouped column.
|
|
6
|
+
*
|
|
7
|
+
* Non-number values contribute `0`. Child rows are used so nested group totals
|
|
8
|
+
* can reuse already aggregated values.
|
|
6
9
|
*/
|
|
7
10
|
declare const aggregationFn_sum: AggregationFn<any, any>;
|
|
8
11
|
/**
|
|
9
|
-
*
|
|
12
|
+
* Finds the minimum numeric child-row value for a grouped column.
|
|
13
|
+
*
|
|
14
|
+
* Nullish and non-number values are ignored. Returns `undefined` when no
|
|
15
|
+
* numeric value is found.
|
|
10
16
|
*/
|
|
11
17
|
declare const aggregationFn_min: AggregationFn<any, any>;
|
|
12
18
|
/**
|
|
13
|
-
*
|
|
19
|
+
* Finds the maximum numeric child-row value for a grouped column.
|
|
20
|
+
*
|
|
21
|
+
* Nullish and non-number values are ignored. Returns `undefined` when no
|
|
22
|
+
* numeric value is found.
|
|
14
23
|
*/
|
|
15
24
|
declare const aggregationFn_max: AggregationFn<any, any>;
|
|
16
25
|
/**
|
|
17
|
-
*
|
|
26
|
+
* Finds the numeric extent for a grouped column.
|
|
27
|
+
*
|
|
28
|
+
* Returns `[min, max]`, where each entry is `undefined` when no numeric value is
|
|
29
|
+
* present.
|
|
18
30
|
*/
|
|
19
31
|
declare const aggregationFn_extent: AggregationFn<any, any>;
|
|
20
32
|
/**
|
|
21
|
-
*
|
|
33
|
+
* Averages numeric leaf-row values for a grouped column.
|
|
34
|
+
*
|
|
35
|
+
* Number-like values are coerced with unary `+`; nullish and non-numeric values
|
|
36
|
+
* are ignored.
|
|
22
37
|
*/
|
|
23
38
|
declare const aggregationFn_mean: AggregationFn<any, any>;
|
|
24
39
|
/**
|
|
25
|
-
*
|
|
40
|
+
* Computes the median of numeric leaf-row values for a grouped column.
|
|
41
|
+
*
|
|
42
|
+
* All values must be numbers. If any value is non-numeric, or no leaf rows are
|
|
43
|
+
* present, the result is `undefined`.
|
|
26
44
|
*/
|
|
27
45
|
declare const aggregationFn_median: AggregationFn<any, any>;
|
|
28
46
|
/**
|
|
29
|
-
*
|
|
47
|
+
* Collects unique leaf-row values for a grouped column.
|
|
48
|
+
*
|
|
49
|
+
* Values are compared with JavaScript `Set` semantics.
|
|
30
50
|
*/
|
|
31
51
|
declare const aggregationFn_unique: AggregationFn<any, any>;
|
|
32
52
|
/**
|
|
33
|
-
*
|
|
53
|
+
* Counts unique leaf-row values for a grouped column.
|
|
54
|
+
*
|
|
55
|
+
* Values are compared with JavaScript `Set` semantics.
|
|
34
56
|
*/
|
|
35
57
|
declare const aggregationFn_uniqueCount: AggregationFn<any, any>;
|
|
36
58
|
/**
|
|
37
|
-
*
|
|
59
|
+
* Counts the number of leaf rows in the group.
|
|
60
|
+
*
|
|
61
|
+
* The column id is ignored because the result is based only on group size.
|
|
38
62
|
*/
|
|
39
63
|
declare const aggregationFn_count: AggregationFn<any, any>;
|
|
40
64
|
/**
|
|
@@ -2,39 +2,63 @@ import { AggregationFn } from "../features/column-grouping/columnGroupingFeature
|
|
|
2
2
|
|
|
3
3
|
//#region src/fns/aggregationFns.d.ts
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* Sums numeric child-row values for a grouped column.
|
|
6
|
+
*
|
|
7
|
+
* Non-number values contribute `0`. Child rows are used so nested group totals
|
|
8
|
+
* can reuse already aggregated values.
|
|
6
9
|
*/
|
|
7
10
|
declare const aggregationFn_sum: AggregationFn<any, any>;
|
|
8
11
|
/**
|
|
9
|
-
*
|
|
12
|
+
* Finds the minimum numeric child-row value for a grouped column.
|
|
13
|
+
*
|
|
14
|
+
* Nullish and non-number values are ignored. Returns `undefined` when no
|
|
15
|
+
* numeric value is found.
|
|
10
16
|
*/
|
|
11
17
|
declare const aggregationFn_min: AggregationFn<any, any>;
|
|
12
18
|
/**
|
|
13
|
-
*
|
|
19
|
+
* Finds the maximum numeric child-row value for a grouped column.
|
|
20
|
+
*
|
|
21
|
+
* Nullish and non-number values are ignored. Returns `undefined` when no
|
|
22
|
+
* numeric value is found.
|
|
14
23
|
*/
|
|
15
24
|
declare const aggregationFn_max: AggregationFn<any, any>;
|
|
16
25
|
/**
|
|
17
|
-
*
|
|
26
|
+
* Finds the numeric extent for a grouped column.
|
|
27
|
+
*
|
|
28
|
+
* Returns `[min, max]`, where each entry is `undefined` when no numeric value is
|
|
29
|
+
* present.
|
|
18
30
|
*/
|
|
19
31
|
declare const aggregationFn_extent: AggregationFn<any, any>;
|
|
20
32
|
/**
|
|
21
|
-
*
|
|
33
|
+
* Averages numeric leaf-row values for a grouped column.
|
|
34
|
+
*
|
|
35
|
+
* Number-like values are coerced with unary `+`; nullish and non-numeric values
|
|
36
|
+
* are ignored.
|
|
22
37
|
*/
|
|
23
38
|
declare const aggregationFn_mean: AggregationFn<any, any>;
|
|
24
39
|
/**
|
|
25
|
-
*
|
|
40
|
+
* Computes the median of numeric leaf-row values for a grouped column.
|
|
41
|
+
*
|
|
42
|
+
* All values must be numbers. If any value is non-numeric, or no leaf rows are
|
|
43
|
+
* present, the result is `undefined`.
|
|
26
44
|
*/
|
|
27
45
|
declare const aggregationFn_median: AggregationFn<any, any>;
|
|
28
46
|
/**
|
|
29
|
-
*
|
|
47
|
+
* Collects unique leaf-row values for a grouped column.
|
|
48
|
+
*
|
|
49
|
+
* Values are compared with JavaScript `Set` semantics.
|
|
30
50
|
*/
|
|
31
51
|
declare const aggregationFn_unique: AggregationFn<any, any>;
|
|
32
52
|
/**
|
|
33
|
-
*
|
|
53
|
+
* Counts unique leaf-row values for a grouped column.
|
|
54
|
+
*
|
|
55
|
+
* Values are compared with JavaScript `Set` semantics.
|
|
34
56
|
*/
|
|
35
57
|
declare const aggregationFn_uniqueCount: AggregationFn<any, any>;
|
|
36
58
|
/**
|
|
37
|
-
*
|
|
59
|
+
* Counts the number of leaf rows in the group.
|
|
60
|
+
*
|
|
61
|
+
* The column id is ignored because the result is based only on group size.
|
|
38
62
|
*/
|
|
39
63
|
declare const aggregationFn_count: AggregationFn<any, any>;
|
|
40
64
|
/**
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
//#region src/fns/aggregationFns.ts
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Sums numeric child-row values for a grouped column.
|
|
4
|
+
*
|
|
5
|
+
* Non-number values contribute `0`. Child rows are used so nested group totals
|
|
6
|
+
* can reuse already aggregated values.
|
|
4
7
|
*/
|
|
5
8
|
const aggregationFn_sum = (columnId, _leafRows, childRows) => {
|
|
6
9
|
return childRows.reduce((sumValue, next) => {
|
|
@@ -9,7 +12,10 @@ const aggregationFn_sum = (columnId, _leafRows, childRows) => {
|
|
|
9
12
|
}, 0);
|
|
10
13
|
};
|
|
11
14
|
/**
|
|
12
|
-
*
|
|
15
|
+
* Finds the minimum numeric child-row value for a grouped column.
|
|
16
|
+
*
|
|
17
|
+
* Nullish and non-number values are ignored. Returns `undefined` when no
|
|
18
|
+
* numeric value is found.
|
|
13
19
|
*/
|
|
14
20
|
const aggregationFn_min = (columnId, _leafRows, childRows) => {
|
|
15
21
|
let minValue;
|
|
@@ -20,7 +26,10 @@ const aggregationFn_min = (columnId, _leafRows, childRows) => {
|
|
|
20
26
|
return minValue;
|
|
21
27
|
};
|
|
22
28
|
/**
|
|
23
|
-
*
|
|
29
|
+
* Finds the maximum numeric child-row value for a grouped column.
|
|
30
|
+
*
|
|
31
|
+
* Nullish and non-number values are ignored. Returns `undefined` when no
|
|
32
|
+
* numeric value is found.
|
|
24
33
|
*/
|
|
25
34
|
const aggregationFn_max = (columnId, _leafRows, childRows) => {
|
|
26
35
|
let maxValue;
|
|
@@ -31,7 +40,10 @@ const aggregationFn_max = (columnId, _leafRows, childRows) => {
|
|
|
31
40
|
return maxValue;
|
|
32
41
|
};
|
|
33
42
|
/**
|
|
34
|
-
*
|
|
43
|
+
* Finds the numeric extent for a grouped column.
|
|
44
|
+
*
|
|
45
|
+
* Returns `[min, max]`, where each entry is `undefined` when no numeric value is
|
|
46
|
+
* present.
|
|
35
47
|
*/
|
|
36
48
|
const aggregationFn_extent = (columnId, _leafRows, childRows) => {
|
|
37
49
|
let minValue;
|
|
@@ -47,7 +59,10 @@ const aggregationFn_extent = (columnId, _leafRows, childRows) => {
|
|
|
47
59
|
return [minValue, maxValue];
|
|
48
60
|
};
|
|
49
61
|
/**
|
|
50
|
-
*
|
|
62
|
+
* Averages numeric leaf-row values for a grouped column.
|
|
63
|
+
*
|
|
64
|
+
* Number-like values are coerced with unary `+`; nullish and non-numeric values
|
|
65
|
+
* are ignored.
|
|
51
66
|
*/
|
|
52
67
|
const aggregationFn_mean = (columnId, leafRows) => {
|
|
53
68
|
let count = 0;
|
|
@@ -68,7 +83,10 @@ const aggregationFn_mean = (columnId, leafRows) => {
|
|
|
68
83
|
if (count) return sumValue / count;
|
|
69
84
|
};
|
|
70
85
|
/**
|
|
71
|
-
*
|
|
86
|
+
* Computes the median of numeric leaf-row values for a grouped column.
|
|
87
|
+
*
|
|
88
|
+
* All values must be numbers. If any value is non-numeric, or no leaf rows are
|
|
89
|
+
* present, the result is `undefined`.
|
|
72
90
|
*/
|
|
73
91
|
const aggregationFn_median = (columnId, leafRows) => {
|
|
74
92
|
if (!leafRows.length) return;
|
|
@@ -84,7 +102,9 @@ const aggregationFn_median = (columnId, leafRows) => {
|
|
|
84
102
|
return values.length % 2 !== 0 ? values[mid] : (values[mid - 1] + values[mid]) / 2;
|
|
85
103
|
};
|
|
86
104
|
/**
|
|
87
|
-
*
|
|
105
|
+
* Collects unique leaf-row values for a grouped column.
|
|
106
|
+
*
|
|
107
|
+
* Values are compared with JavaScript `Set` semantics.
|
|
88
108
|
*/
|
|
89
109
|
const aggregationFn_unique = (columnId, leafRows) => {
|
|
90
110
|
const set = /* @__PURE__ */ new Set();
|
|
@@ -92,7 +112,9 @@ const aggregationFn_unique = (columnId, leafRows) => {
|
|
|
92
112
|
return Array.from(set.values());
|
|
93
113
|
};
|
|
94
114
|
/**
|
|
95
|
-
*
|
|
115
|
+
* Counts unique leaf-row values for a grouped column.
|
|
116
|
+
*
|
|
117
|
+
* Values are compared with JavaScript `Set` semantics.
|
|
96
118
|
*/
|
|
97
119
|
const aggregationFn_uniqueCount = (columnId, leafRows) => {
|
|
98
120
|
const set = /* @__PURE__ */ new Set();
|
|
@@ -100,7 +122,9 @@ const aggregationFn_uniqueCount = (columnId, leafRows) => {
|
|
|
100
122
|
return set.size;
|
|
101
123
|
};
|
|
102
124
|
/**
|
|
103
|
-
*
|
|
125
|
+
* Counts the number of leaf rows in the group.
|
|
126
|
+
*
|
|
127
|
+
* The column id is ignored because the result is based only on group size.
|
|
104
128
|
*/
|
|
105
129
|
const aggregationFn_count = (_columnId, leafRows) => {
|
|
106
130
|
return leafRows.length;
|
|
@@ -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'\nimport type { AggregationFn } from '../features/column-grouping/columnGroupingFeature.types'\n\n/**\n *
|
|
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'\nimport type { AggregationFn } from '../features/column-grouping/columnGroupingFeature.types'\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 const aggregationFn_sum: AggregationFn<any, any> = <\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n columnId: string,\n _leafRows: Array<Row<any, any>>,\n childRows: Array<Row<any, any>>,\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 const aggregationFn_min: AggregationFn<any, any> = <\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n columnId: string,\n _leafRows: Array<Row<any, any>>,\n childRows: Array<Row<any, any>>,\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 const aggregationFn_max: AggregationFn<any, any> = <\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n columnId: string,\n _leafRows: Array<Row<any, any>>,\n childRows: Array<Row<any, any>>,\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 const aggregationFn_extent: AggregationFn<any, any> = <\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n columnId: string,\n _leafRows: Array<Row<any, any>>,\n childRows: Array<Row<any, any>>,\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 const aggregationFn_mean: AggregationFn<any, any> = <\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n columnId: string,\n leafRows: Array<Row<any, any>>,\n) => {\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 const aggregationFn_median: AggregationFn<any, any> = <\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n columnId: string,\n leafRows: Array<Row<any, any>>,\n) => {\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 const aggregationFn_unique: AggregationFn<any, any> = <\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n columnId: string,\n leafRows: Array<Row<any, any>>,\n) => {\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 const aggregationFn_uniqueCount: AggregationFn<any, any> = <\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n columnId: string,\n leafRows: Array<Row<any, any>>,\n) => {\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 const aggregationFn_count: AggregationFn<any, any> = <\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n _columnId: string,\n leafRows: Array<Row<any, any>>,\n) => {\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":";;;;;;;AAWA,MAAa,qBAIX,UACA,WACA,cACG;CAGH,OAAO,UAAU,QAAQ,UAAU,SAAS;EAC1C,MAAM,YAAY,KAAK,SAAS,SAAS;EACzC,OAAO,YAAY,OAAO,cAAc,WAAW,YAAY;IAC9D,EAAE;;;;;;;;AASP,MAAa,qBAIX,UACA,WACA,cACG;CACH,IAAI;CAEJ,UAAU,SAAS,QAAQ;EACzB,MAAM,QAAQ,IAAI,SAAS,SAAS;EAEpC,IACE,SAAS,QACT,OAAO,UAAU,aAChB,aAAa,UAAa,QAAQ,WAEnC,WAAW;GAEb;CAEF,OAAO;;;;;;;;AAST,MAAa,qBAIX,UACA,WACA,cACG;CACH,IAAI;CAEJ,UAAU,SAAS,QAAQ;EACzB,MAAM,QAAQ,IAAI,SAAS,SAAS;EACpC,IACE,SAAS,QACT,OAAO,UAAU,aAChB,aAAa,UAAa,QAAQ,WAEnC,WAAW;GAEb;CAEF,OAAO;;;;;;;;AAST,MAAa,wBAIX,UACA,WACA,cACG;CACH,IAAI;CACJ,IAAI;CAEJ,UAAU,SAAS,QAAQ;EACzB,MAAM,QAAQ,IAAI,SAAS,SAAS;EACpC,IAAI,SAAS,QAAQ,OAAO,UAAU,UACpC,IAAI,aAAa,QACf,WAAW,WAAW;OACjB;GACL,IAAI,WAAW,OAAO,WAAW;GACjC,IAAI,WAAY,OAAO,WAAW;;GAGtC;CAEF,OAAO,CAAC,UAAU,SAAS;;;;;;;;AAS7B,MAAa,sBAIX,UACA,aACG;CACH,IAAI,QAAQ;CACZ,IAAI,WAAW;CAEf,SAAS,SAAS,QAAQ;EACxB,MAAM,QAAQ,IAAI,SAAS,SAAS;EACpC,IAAI,SAAS,QAAQ,OAAO,UAAU,UAAU;GAC9C,EAAE;GACF,YAAY;SACP,IAAI,SAAS,MAAM;GACxB,MAAM,WAAW,CAAC;GAClB,IAAI,CAAC,OAAO,MAAM,SAAS,EAAE;IAC3B,EAAE;IACF,YAAY;;;GAGhB;CAEF,IAAI,OAAO,OAAO,WAAW;;;;;;;;AAW/B,MAAa,wBAIX,UACA,aACG;CACH,IAAI,CAAC,SAAS,QACZ;CAGF,MAAM,SAAwB,IAAI,MAAM,SAAS,OAAO;CACxD,KAAK,IAAI,IAAI,GAAG,IAAI,SAAS,QAAQ,KAAK;EACxC,MAAM,IAAI,SAAS,GAAI,SAAS,SAAS;EACzC,IAAI,OAAO,MAAM,UAAU;EAC3B,OAAO,KAAK;;CAGd,IAAI,OAAO,WAAW,GACpB,OAAO,OAAO;CAGhB,MAAM,MAAM,KAAK,MAAM,OAAO,SAAS,EAAE;CACzC,OAAO,MAAM,GAAG,MAAM,IAAI,EAAE;CAC5B,OAAO,OAAO,SAAS,MAAM,IACzB,OAAO,QACN,OAAO,MAAM,KAAM,OAAO,QAAS;;;;;;;AAQ1C,MAAa,wBAIX,UACA,aACG;CACH,MAAM,sBAAM,IAAI,KAAc;CAC9B,KAAK,IAAI,IAAI,GAAG,IAAI,SAAS,QAAQ,KACnC,IAAI,IAAI,SAAS,GAAI,SAAS,SAAS,CAAC;CAE1C,OAAO,MAAM,KAAK,IAAI,QAAQ,CAAC;;;;;;;AAQjC,MAAa,6BAIX,UACA,aACG;CACH,MAAM,sBAAM,IAAI,KAAc;CAC9B,KAAK,IAAI,IAAI,GAAG,IAAI,SAAS,QAAQ,KACnC,IAAI,IAAI,SAAS,GAAI,SAAS,SAAS,CAAC;CAE1C,OAAO,IAAI;;;;;;;AAQb,MAAa,uBAIX,WACA,aACG;CACH,OAAO,SAAS;;;;;;;AAQlB,MAAa,iBAAiB;CAC5B,KAAK;CACL,KAAK;CACL,KAAK;CACL,QAAQ;CACR,MAAM;CACN,QAAQ;CACR,QAAQ;CACR,aAAa;CACb,OAAO;CACR"}
|
package/dist/fns/filterFns.cjs
CHANGED
|
@@ -1,21 +1,28 @@
|
|
|
1
1
|
|
|
2
2
|
//#region src/fns/filterFns.ts
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Keeps rows whose column value is strictly equal to the filter value.
|
|
5
|
+
*
|
|
6
|
+
* Uses JavaScript `===` comparison and auto-removes empty filter values.
|
|
5
7
|
*/
|
|
6
8
|
const filterFn_equals = (row, columnId, filterValue) => {
|
|
7
9
|
return row.getValue(columnId) === filterValue;
|
|
8
10
|
};
|
|
9
11
|
filterFn_equals.autoRemove = (val) => testFalsy(val);
|
|
10
12
|
/**
|
|
11
|
-
*
|
|
13
|
+
* Keeps rows whose column value is loosely equal to the filter value.
|
|
14
|
+
*
|
|
15
|
+
* Uses JavaScript `==` comparison and auto-removes empty filter values. This is
|
|
16
|
+
* useful for matching string input against numeric row values.
|
|
12
17
|
*/
|
|
13
18
|
const filterFn_weakEquals = (row, columnId, filterValue) => {
|
|
14
19
|
return row.getValue(columnId) == filterValue;
|
|
15
20
|
};
|
|
16
21
|
filterFn_weakEquals.autoRemove = (val) => testFalsy(val);
|
|
17
22
|
/**
|
|
18
|
-
*
|
|
23
|
+
* Keeps rows whose stringified column value includes the filter text.
|
|
24
|
+
*
|
|
25
|
+
* Matching is case-sensitive and empty filter values are auto-removed.
|
|
19
26
|
*/
|
|
20
27
|
const filterFn_includesStringSensitive = (row, columnId, filterValue) => {
|
|
21
28
|
var _row$getValue;
|
|
@@ -23,7 +30,10 @@ const filterFn_includesStringSensitive = (row, columnId, filterValue) => {
|
|
|
23
30
|
};
|
|
24
31
|
filterFn_includesStringSensitive.autoRemove = (val) => testFalsy(val);
|
|
25
32
|
/**
|
|
26
|
-
*
|
|
33
|
+
* Keeps rows whose stringified column value includes the filter text.
|
|
34
|
+
*
|
|
35
|
+
* Both values are lowercased before comparison, and empty filter values are
|
|
36
|
+
* auto-removed.
|
|
27
37
|
*/
|
|
28
38
|
const filterFn_includesString = (row, columnId, filterValue) => {
|
|
29
39
|
var _row$getValue2;
|
|
@@ -31,7 +41,10 @@ const filterFn_includesString = (row, columnId, filterValue) => {
|
|
|
31
41
|
};
|
|
32
42
|
filterFn_includesString.autoRemove = (val) => testFalsy(val);
|
|
33
43
|
/**
|
|
34
|
-
*
|
|
44
|
+
* Keeps rows whose stringified column value equals the filter text.
|
|
45
|
+
*
|
|
46
|
+
* Both values are lowercased before comparison, and empty filter values are
|
|
47
|
+
* auto-removed.
|
|
35
48
|
*/
|
|
36
49
|
const filterFn_equalsString = (row, columnId, filterValue) => {
|
|
37
50
|
var _row$getValue3;
|
|
@@ -39,7 +52,9 @@ const filterFn_equalsString = (row, columnId, filterValue) => {
|
|
|
39
52
|
};
|
|
40
53
|
filterFn_equalsString.autoRemove = (val) => testFalsy(val);
|
|
41
54
|
/**
|
|
42
|
-
*
|
|
55
|
+
* Keeps rows whose stringified column value exactly equals the filter text.
|
|
56
|
+
*
|
|
57
|
+
* Matching is case-sensitive and empty filter values are auto-removed.
|
|
43
58
|
*/
|
|
44
59
|
const filterFn_equalsStringSensitive = (row, columnId, filterValue) => {
|
|
45
60
|
var _row$getValue4;
|
|
@@ -47,7 +62,10 @@ const filterFn_equalsStringSensitive = (row, columnId, filterValue) => {
|
|
|
47
62
|
};
|
|
48
63
|
filterFn_equalsStringSensitive.autoRemove = (val) => testFalsy(val);
|
|
49
64
|
/**
|
|
50
|
-
*
|
|
65
|
+
* Keeps rows whose value is greater than the filter value.
|
|
66
|
+
*
|
|
67
|
+
* Numeric values are compared numerically when both sides can be coerced to
|
|
68
|
+
* numbers; otherwise normalized strings are compared.
|
|
51
69
|
*/
|
|
52
70
|
const filterFn_greaterThan = (row, columnId, filterValue) => {
|
|
53
71
|
const rowValue = row.getValue(columnId);
|
|
@@ -58,38 +76,51 @@ const filterFn_greaterThan = (row, columnId, filterValue) => {
|
|
|
58
76
|
};
|
|
59
77
|
filterFn_greaterThan.resolveFilterValue = (val) => testFalsy(val);
|
|
60
78
|
/**
|
|
61
|
-
*
|
|
79
|
+
* Keeps rows whose value is greater than or equal to the filter value.
|
|
80
|
+
*
|
|
81
|
+
* Delegates to the built-in greater-than and equality comparisons.
|
|
62
82
|
*/
|
|
63
83
|
const filterFn_greaterThanOrEqualTo = (row, columnId, filterValue) => {
|
|
64
84
|
return filterFn_greaterThan(row, columnId, filterValue) || filterFn_equals(row, columnId, filterValue);
|
|
65
85
|
};
|
|
66
86
|
filterFn_greaterThanOrEqualTo.resolveFilterValue = (val) => testFalsy(val);
|
|
67
87
|
/**
|
|
68
|
-
*
|
|
88
|
+
* Keeps rows whose value is less than the filter value.
|
|
89
|
+
*
|
|
90
|
+
* This is implemented as the inverse of greater-than-or-equal comparison.
|
|
69
91
|
*/
|
|
70
92
|
const filterFn_lessThan = (row, columnId, filterValue) => {
|
|
71
93
|
return !filterFn_greaterThanOrEqualTo(row, columnId, filterValue);
|
|
72
94
|
};
|
|
73
95
|
filterFn_lessThan.resolveFilterValue = (val) => testFalsy(val);
|
|
74
96
|
/**
|
|
75
|
-
*
|
|
97
|
+
* Keeps rows whose value is less than or equal to the filter value.
|
|
98
|
+
*
|
|
99
|
+
* This is implemented as the inverse of greater-than comparison.
|
|
76
100
|
*/
|
|
77
101
|
const filterFn_lessThanOrEqualTo = (row, columnId, filterValue) => {
|
|
78
102
|
return !filterFn_greaterThan(row, columnId, filterValue);
|
|
79
103
|
};
|
|
80
104
|
filterFn_lessThanOrEqualTo.resolveFilterValue = (val) => testFalsy(val);
|
|
81
105
|
/**
|
|
82
|
-
*
|
|
106
|
+
* Keeps rows whose value falls between an exclusive min/max pair.
|
|
107
|
+
*
|
|
108
|
+
* Blank range endpoints are treated as open-ended.
|
|
83
109
|
*/
|
|
84
110
|
const filterFn_between = (row, columnId, filterValues) => (["", void 0].includes(filterValues[0]) || filterFn_greaterThan(row, columnId, filterValues[0])) && (!isNaN(+filterValues[0]) && !isNaN(+filterValues[1]) && +filterValues[0] > +filterValues[1] || ["", void 0].includes(filterValues[1]) || filterFn_lessThan(row, columnId, filterValues[1]));
|
|
85
111
|
filterFn_between.autoRemove = (val) => !val;
|
|
86
112
|
/**
|
|
87
|
-
*
|
|
113
|
+
* Keeps rows whose value falls between an inclusive min/max pair.
|
|
114
|
+
*
|
|
115
|
+
* Blank range endpoints are treated as open-ended.
|
|
88
116
|
*/
|
|
89
117
|
const filterFn_betweenInclusive = (row, columnId, filterValues) => (["", void 0].includes(filterValues[0]) || filterFn_greaterThanOrEqualTo(row, columnId, filterValues[0])) && (!isNaN(+filterValues[0]) && !isNaN(+filterValues[1]) && +filterValues[0] > +filterValues[1] || ["", void 0].includes(filterValues[1]) || filterFn_lessThanOrEqualTo(row, columnId, filterValues[1]));
|
|
90
118
|
filterFn_betweenInclusive.autoRemove = (val) => !val;
|
|
91
119
|
/**
|
|
92
|
-
*
|
|
120
|
+
* Keeps rows whose numeric value is inside an inclusive `[min, max]` range.
|
|
121
|
+
*
|
|
122
|
+
* Filter values are normalized so blank endpoints become open-ended and
|
|
123
|
+
* reversed endpoints are swapped.
|
|
93
124
|
*/
|
|
94
125
|
const filterFn_inNumberRange = (row, columnId, filterValue) => {
|
|
95
126
|
const [min, max] = filterValue;
|
|
@@ -111,20 +142,20 @@ filterFn_inNumberRange.resolveFilterValue = (val) => {
|
|
|
111
142
|
};
|
|
112
143
|
filterFn_inNumberRange.autoRemove = (val) => testFalsy(val) || testFalsy(val[0]) && testFalsy(val[1]);
|
|
113
144
|
/**
|
|
114
|
-
*
|
|
145
|
+
* Keeps rows whose scalar column value equals at least one filter value.
|
|
115
146
|
*/
|
|
116
147
|
const filterFn_arrHas = (row, columnId, filterValue) => {
|
|
117
148
|
return filterValue.some((val) => row.getValue(columnId) === val);
|
|
118
149
|
};
|
|
119
150
|
/**
|
|
120
|
-
*
|
|
151
|
+
* Keeps rows whose array or string column value includes at least one filter value.
|
|
121
152
|
*/
|
|
122
153
|
const filterFn_arrIncludes = (row, columnId, filterValue) => {
|
|
123
154
|
return filterValue.some((val) => row.getValue(columnId).includes(val));
|
|
124
155
|
};
|
|
125
156
|
filterFn_arrIncludes.autoRemove = (val) => testFalsy(val) || !(val === null || val === void 0 ? void 0 : val.length);
|
|
126
157
|
/**
|
|
127
|
-
*
|
|
158
|
+
* Keeps rows whose array column value includes every filter value.
|
|
128
159
|
*/
|
|
129
160
|
const filterFn_arrIncludesAll = (row, columnId, filterValue) => {
|
|
130
161
|
const value = row.getValue(columnId);
|
|
@@ -133,7 +164,7 @@ const filterFn_arrIncludesAll = (row, columnId, filterValue) => {
|
|
|
133
164
|
};
|
|
134
165
|
filterFn_arrIncludesAll.autoRemove = (val) => testFalsy(val) || !(val === null || val === void 0 ? void 0 : val.length);
|
|
135
166
|
/**
|
|
136
|
-
*
|
|
167
|
+
* Keeps rows whose array column value includes at least one filter value.
|
|
137
168
|
*/
|
|
138
169
|
const filterFn_arrIncludesSome = (row, columnId, filterValue) => {
|
|
139
170
|
const value = row.getValue(columnId);
|