@tanstack/table-core 9.0.0-beta.46 → 9.0.0-beta.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/dist/core/row-models/coreRowModelsFeature.types.d.cts +1 -1
- package/dist/core/row-models/coreRowModelsFeature.types.d.ts +1 -1
- package/dist/core/row-models/coreRowModelsFeature.utils.cjs +1 -1
- package/dist/core/row-models/coreRowModelsFeature.utils.cjs.map +1 -1
- package/dist/core/row-models/coreRowModelsFeature.utils.d.cts +1 -1
- package/dist/core/row-models/coreRowModelsFeature.utils.d.ts +1 -1
- package/dist/core/row-models/coreRowModelsFeature.utils.js +1 -1
- package/dist/core/row-models/coreRowModelsFeature.utils.js.map +1 -1
- package/dist/features/aggregation/aggregationFeature.cjs +38 -0
- package/dist/features/aggregation/aggregationFeature.cjs.map +1 -0
- package/dist/features/aggregation/aggregationFeature.d.cts +10 -0
- package/dist/features/aggregation/aggregationFeature.d.ts +10 -0
- package/dist/features/aggregation/aggregationFeature.js +38 -0
- package/dist/features/aggregation/aggregationFeature.js.map +1 -0
- package/dist/features/aggregation/aggregationFeature.types.cjs +13 -0
- package/dist/features/aggregation/aggregationFeature.types.cjs.map +1 -0
- package/dist/features/aggregation/aggregationFeature.types.d.cts +172 -0
- package/dist/features/aggregation/aggregationFeature.types.d.ts +172 -0
- package/dist/features/aggregation/aggregationFeature.types.js +12 -0
- package/dist/features/aggregation/aggregationFeature.types.js.map +1 -0
- package/dist/features/aggregation/aggregationFeature.utils.cjs +198 -0
- package/dist/features/aggregation/aggregationFeature.utils.cjs.map +1 -0
- package/dist/features/aggregation/aggregationFeature.utils.d.cts +33 -0
- package/dist/features/aggregation/aggregationFeature.utils.d.ts +33 -0
- package/dist/features/aggregation/aggregationFeature.utils.js +192 -0
- package/dist/features/aggregation/aggregationFeature.utils.js.map +1 -0
- package/dist/features/aggregation/aggregationFns.cjs +240 -0
- package/dist/features/aggregation/aggregationFns.cjs.map +1 -0
- package/dist/features/aggregation/aggregationFns.d.cts +67 -0
- package/dist/features/aggregation/aggregationFns.d.ts +67 -0
- package/dist/features/aggregation/aggregationFns.js +229 -0
- package/dist/features/aggregation/aggregationFns.js.map +1 -0
- package/dist/features/column-filtering/columnFilteringFeature.types.d.cts +43 -3
- package/dist/features/column-filtering/columnFilteringFeature.types.d.ts +43 -3
- package/dist/features/column-filtering/columnFilteringFeature.utils.cjs +18 -9
- package/dist/features/column-filtering/columnFilteringFeature.utils.cjs.map +1 -1
- package/dist/features/column-filtering/columnFilteringFeature.utils.d.cts +6 -2
- package/dist/features/column-filtering/columnFilteringFeature.utils.d.ts +6 -2
- package/dist/features/column-filtering/columnFilteringFeature.utils.js +18 -9
- package/dist/features/column-filtering/columnFilteringFeature.utils.js.map +1 -1
- package/dist/features/column-filtering/createFilteredRowModel.cjs +7 -2
- package/dist/features/column-filtering/createFilteredRowModel.cjs.map +1 -1
- package/dist/features/column-filtering/createFilteredRowModel.d.cts +6 -2
- package/dist/features/column-filtering/createFilteredRowModel.d.ts +6 -2
- package/dist/features/column-filtering/createFilteredRowModel.js +7 -2
- package/dist/features/column-filtering/createFilteredRowModel.js.map +1 -1
- package/dist/features/column-filtering/filterFns.cjs +399 -0
- package/dist/features/column-filtering/filterFns.cjs.map +1 -0
- package/dist/features/column-filtering/filterFns.d.cts +210 -0
- package/dist/features/column-filtering/filterFns.d.ts +210 -0
- package/dist/features/column-filtering/filterFns.js +375 -0
- package/dist/features/column-filtering/filterFns.js.map +1 -0
- package/dist/features/column-grouping/columnGroupingFeature.cjs +3 -12
- package/dist/features/column-grouping/columnGroupingFeature.cjs.map +1 -1
- package/dist/features/column-grouping/columnGroupingFeature.d.cts +1 -1
- package/dist/features/column-grouping/columnGroupingFeature.d.ts +1 -1
- package/dist/features/column-grouping/columnGroupingFeature.js +4 -13
- package/dist/features/column-grouping/columnGroupingFeature.js.map +1 -1
- package/dist/features/column-grouping/columnGroupingFeature.types.d.cts +6 -49
- package/dist/features/column-grouping/columnGroupingFeature.types.d.ts +6 -49
- package/dist/features/column-grouping/columnGroupingFeature.utils.cjs +0 -50
- package/dist/features/column-grouping/columnGroupingFeature.utils.cjs.map +1 -1
- package/dist/features/column-grouping/columnGroupingFeature.utils.d.cts +2 -39
- package/dist/features/column-grouping/columnGroupingFeature.utils.d.ts +2 -39
- package/dist/features/column-grouping/columnGroupingFeature.utils.js +2 -49
- package/dist/features/column-grouping/columnGroupingFeature.utils.js.map +1 -1
- package/dist/features/column-grouping/createGroupedRowModel.cjs +23 -13
- package/dist/features/column-grouping/createGroupedRowModel.cjs.map +1 -1
- package/dist/features/column-grouping/createGroupedRowModel.d.cts +2 -3
- package/dist/features/column-grouping/createGroupedRowModel.d.ts +2 -3
- package/dist/features/column-grouping/createGroupedRowModel.js +25 -15
- package/dist/features/column-grouping/createGroupedRowModel.js.map +1 -1
- package/dist/features/global-filtering/globalFilteringFeature.utils.cjs +4 -2
- package/dist/features/global-filtering/globalFilteringFeature.utils.cjs.map +1 -1
- package/dist/features/global-filtering/globalFilteringFeature.utils.d.cts +2 -6
- package/dist/features/global-filtering/globalFilteringFeature.utils.d.ts +2 -6
- package/dist/features/global-filtering/globalFilteringFeature.utils.js +4 -2
- package/dist/features/global-filtering/globalFilteringFeature.utils.js.map +1 -1
- package/dist/features/row-sorting/createSortedRowModel.cjs +6 -2
- package/dist/features/row-sorting/createSortedRowModel.cjs.map +1 -1
- package/dist/features/row-sorting/createSortedRowModel.d.cts +6 -2
- package/dist/features/row-sorting/createSortedRowModel.d.ts +6 -2
- package/dist/features/row-sorting/createSortedRowModel.js +6 -2
- package/dist/features/row-sorting/createSortedRowModel.js.map +1 -1
- package/dist/features/row-sorting/rowSortingFeature.types.d.cts +32 -3
- package/dist/features/row-sorting/rowSortingFeature.types.d.ts +32 -3
- package/dist/features/row-sorting/rowSortingFeature.utils.cjs +20 -5
- package/dist/features/row-sorting/rowSortingFeature.utils.cjs.map +1 -1
- package/dist/features/row-sorting/rowSortingFeature.utils.js +20 -5
- package/dist/features/row-sorting/rowSortingFeature.utils.js.map +1 -1
- package/dist/{fns → features/row-sorting}/sortFns.cjs +69 -22
- package/dist/features/row-sorting/sortFns.cjs.map +1 -0
- package/dist/features/row-sorting/sortFns.d.cts +98 -0
- package/dist/features/row-sorting/sortFns.d.ts +98 -0
- package/dist/{fns → features/row-sorting}/sortFns.js +69 -23
- package/dist/features/row-sorting/sortFns.js.map +1 -0
- package/dist/features/stockFeatures.cjs +2 -0
- package/dist/features/stockFeatures.cjs.map +1 -1
- package/dist/features/stockFeatures.d.cts +2 -0
- package/dist/features/stockFeatures.d.ts +2 -0
- package/dist/features/stockFeatures.js +2 -0
- package/dist/features/stockFeatures.js.map +1 -1
- package/dist/helpers/tableFeatures.cjs +5 -4
- package/dist/helpers/tableFeatures.cjs.map +1 -1
- package/dist/helpers/tableFeatures.d.cts +5 -4
- package/dist/helpers/tableFeatures.d.ts +5 -4
- package/dist/helpers/tableFeatures.js +5 -4
- package/dist/helpers/tableFeatures.js.map +1 -1
- package/dist/index.cjs +18 -3
- package/dist/index.d.cts +10 -8
- package/dist/index.d.ts +10 -8
- package/dist/index.js +6 -4
- package/dist/static-functions.cjs +8 -3
- package/dist/static-functions.d.cts +3 -2
- package/dist/static-functions.d.ts +3 -2
- package/dist/static-functions.js +3 -2
- package/dist/types/Cell.d.cts +3 -1
- package/dist/types/Cell.d.ts +3 -1
- package/dist/types/Column.d.cts +4 -2
- package/dist/types/Column.d.ts +4 -2
- package/dist/types/ColumnDef.d.cts +5 -3
- package/dist/types/ColumnDef.d.ts +5 -3
- package/dist/types/Row.d.cts +3 -1
- package/dist/types/Row.d.ts +3 -1
- package/dist/types/RowModel.d.cts +1 -1
- package/dist/types/RowModel.d.ts +1 -1
- package/dist/types/RowModelFns.d.cts +3 -3
- package/dist/types/RowModelFns.d.ts +3 -3
- package/dist/types/Table.d.cts +1 -1
- package/dist/types/Table.d.ts +1 -1
- package/dist/types/TableFeatures.d.cts +19 -11
- package/dist/types/TableFeatures.d.ts +19 -11
- package/dist/types/TableOptions.d.cts +5 -3
- package/dist/types/TableOptions.d.ts +5 -3
- package/dist/types/TableState.d.cts +1 -1
- package/dist/types/TableState.d.ts +1 -1
- package/dist/types/type-utils.d.cts +8 -1
- package/dist/types/type-utils.d.ts +8 -1
- package/dist/worker/initTableWorker.cjs.map +1 -1
- package/dist/worker/initTableWorker.js.map +1 -1
- package/package.json +1 -1
- package/skills/aggregation/SKILL.md +131 -0
- package/skills/api-not-found/SKILL.md +1 -1
- package/skills/client-vs-server/SKILL.md +1 -1
- package/skills/column-faceting/SKILL.md +11 -5
- package/skills/column-filtering/SKILL.md +8 -3
- package/skills/column-ordering/SKILL.md +1 -1
- package/skills/column-pinning/SKILL.md +1 -1
- package/skills/column-resizing/SKILL.md +1 -1
- package/skills/column-sizing/SKILL.md +1 -1
- package/skills/column-visibility/SKILL.md +1 -1
- package/skills/core/SKILL.md +1 -1
- package/skills/custom-features/SKILL.md +1 -1
- package/skills/expanding/SKILL.md +1 -1
- package/skills/global-filtering/SKILL.md +3 -3
- package/skills/grouping/SKILL.md +12 -13
- package/skills/migrate-v8-to-v9/SKILL.md +21 -8
- package/skills/pagination/SKILL.md +1 -1
- package/skills/row-pinning/SKILL.md +1 -1
- package/skills/row-selection/SKILL.md +1 -1
- package/skills/sorting/SKILL.md +9 -3
- package/skills/table-features/SKILL.md +19 -13
- package/skills/typescript/SKILL.md +1 -1
- package/src/core/row-models/coreRowModelsFeature.utils.ts +1 -1
- package/src/features/aggregation/aggregationFeature.ts +59 -0
- package/src/features/aggregation/aggregationFeature.types.ts +312 -0
- package/src/features/aggregation/aggregationFeature.utils.ts +401 -0
- package/src/features/aggregation/aggregationFns.ts +336 -0
- package/src/features/column-filtering/columnFilteringFeature.types.ts +61 -1
- package/src/features/column-filtering/columnFilteringFeature.utils.ts +33 -19
- package/src/features/column-filtering/createFilteredRowModel.ts +13 -3
- package/src/features/column-filtering/filterFns.ts +533 -0
- package/src/features/column-grouping/columnGroupingFeature.ts +1 -20
- package/src/features/column-grouping/columnGroupingFeature.types.ts +4 -86
- package/src/features/column-grouping/columnGroupingFeature.utils.ts +1 -88
- package/src/features/column-grouping/createGroupedRowModel.ts +32 -38
- package/src/features/global-filtering/globalFilteringFeature.utils.ts +9 -1
- package/src/features/row-sorting/createSortedRowModel.ts +6 -2
- package/src/features/row-sorting/rowSortingFeature.types.ts +54 -2
- package/src/features/row-sorting/rowSortingFeature.utils.ts +46 -14
- package/src/{fns → features/row-sorting}/sortFns.ts +95 -81
- package/src/features/stockFeatures.ts +3 -0
- package/src/helpers/tableFeatures.ts +5 -4
- package/src/index.ts +7 -8
- package/src/static-functions.ts +1 -0
- package/src/types/Cell.ts +2 -0
- package/src/types/Column.ts +3 -1
- package/src/types/ColumnDef.ts +6 -3
- package/src/types/Row.ts +2 -0
- package/src/types/RowModelFns.ts +3 -3
- package/src/types/TableFeatures.ts +19 -11
- package/src/types/TableOptions.ts +5 -1
- package/src/types/type-utils.ts +8 -0
- package/src/worker/initTableWorker.ts +1 -1
- package/dist/fns/aggregationFns.cjs +0 -163
- package/dist/fns/aggregationFns.cjs.map +0 -1
- package/dist/fns/aggregationFns.d.cts +0 -85
- package/dist/fns/aggregationFns.d.ts +0 -85
- package/dist/fns/aggregationFns.js +0 -153
- package/dist/fns/aggregationFns.js.map +0 -1
- package/dist/fns/filterFns.cjs +0 -242
- package/dist/fns/filterFns.cjs.map +0 -1
- package/dist/fns/filterFns.d.cts +0 -178
- package/dist/fns/filterFns.d.ts +0 -178
- package/dist/fns/filterFns.js +0 -226
- package/dist/fns/filterFns.js.map +0 -1
- package/dist/fns/sortFns.cjs.map +0 -1
- package/dist/fns/sortFns.d.cts +0 -65
- package/dist/fns/sortFns.d.ts +0 -65
- package/dist/fns/sortFns.js.map +0 -1
- package/src/fns/aggregationFns.ts +0 -245
- package/src/fns/filterFns.ts +0 -455
|
@@ -24,9 +24,10 @@ import type {
|
|
|
24
24
|
* columnFilteringFeature,
|
|
25
25
|
* createFilteredRowModel,
|
|
26
26
|
* createSortedRowModel,
|
|
27
|
-
*
|
|
27
|
+
* filterFn_includesString,
|
|
28
28
|
* rowSortingFeature,
|
|
29
|
-
*
|
|
29
|
+
* sortFn_alphanumeric,
|
|
30
|
+
* sortFn_text,
|
|
30
31
|
* tableFeatures,
|
|
31
32
|
* } from '@tanstack/react-table'
|
|
32
33
|
* const features = tableFeatures({
|
|
@@ -34,8 +35,8 @@ import type {
|
|
|
34
35
|
* rowSortingFeature,
|
|
35
36
|
* filteredRowModel: createFilteredRowModel(),
|
|
36
37
|
* sortedRowModel: createSortedRowModel(),
|
|
37
|
-
* filterFns: {
|
|
38
|
-
* sortFns,
|
|
38
|
+
* filterFns: { includesString: filterFn_includesString, myCustomFilterFn },
|
|
39
|
+
* sortFns: { alphanumeric: sortFn_alphanumeric, text: sortFn_text },
|
|
39
40
|
* tableMeta: {} as { updateData: (rowIndex: number, columnId: string, value: unknown) => void },
|
|
40
41
|
* columnMeta: {} as { align?: 'left' | 'right' },
|
|
41
42
|
* });
|
package/src/index.ts
CHANGED
|
@@ -58,20 +58,17 @@ export * from './core/table/constructTable'
|
|
|
58
58
|
export * from './core/table/coreTablesFeature'
|
|
59
59
|
export * from './core/table/coreTablesFeature.types'
|
|
60
60
|
|
|
61
|
-
/**
|
|
62
|
-
* RowModelFns
|
|
63
|
-
*/
|
|
64
|
-
|
|
65
|
-
export * from './fns/aggregationFns'
|
|
66
|
-
export * from './fns/filterFns'
|
|
67
|
-
export * from './fns/sortFns'
|
|
68
|
-
|
|
69
61
|
/**
|
|
70
62
|
* Features
|
|
71
63
|
*/
|
|
72
64
|
|
|
73
65
|
export * from './features/stockFeatures'
|
|
74
66
|
|
|
67
|
+
// aggregationFeature
|
|
68
|
+
export * from './features/aggregation/aggregationFeature'
|
|
69
|
+
export * from './features/aggregation/aggregationFeature.types'
|
|
70
|
+
export * from './features/aggregation/aggregationFns'
|
|
71
|
+
|
|
75
72
|
// columnFacetingFeature
|
|
76
73
|
export * from './features/column-faceting/columnFacetingFeature'
|
|
77
74
|
export * from './features/column-faceting/columnFacetingFeature.types'
|
|
@@ -83,6 +80,7 @@ export * from './features/column-faceting/createFacetedUniqueValues'
|
|
|
83
80
|
export * from './features/column-filtering/columnFilteringFeature'
|
|
84
81
|
export * from './features/column-filtering/columnFilteringFeature.types'
|
|
85
82
|
export * from './features/column-filtering/createFilteredRowModel'
|
|
83
|
+
export * from './features/column-filtering/filterFns'
|
|
86
84
|
|
|
87
85
|
// columnGroupingFeature
|
|
88
86
|
export * from './features/column-grouping/columnGroupingFeature'
|
|
@@ -135,5 +133,6 @@ export * from './features/row-selection/rowSelectionFeature.types'
|
|
|
135
133
|
export * from './features/row-sorting/rowSortingFeature'
|
|
136
134
|
export * from './features/row-sorting/rowSortingFeature.types'
|
|
137
135
|
export * from './features/row-sorting/createSortedRowModel'
|
|
136
|
+
export * from './features/row-sorting/sortFns'
|
|
138
137
|
|
|
139
138
|
// force
|
package/src/static-functions.ts
CHANGED
|
@@ -15,6 +15,7 @@ export * from './core/row-models/coreRowModelsFeature.utils'
|
|
|
15
15
|
export * from './core/table/coreTablesFeature.utils'
|
|
16
16
|
|
|
17
17
|
// Features
|
|
18
|
+
export * from './features/aggregation/aggregationFeature.utils'
|
|
18
19
|
export * from './features/column-faceting/columnFacetingFeature.utils'
|
|
19
20
|
export * from './features/column-filtering/columnFilteringFeature.utils'
|
|
20
21
|
export * from './features/column-grouping/columnGroupingFeature.utils'
|
package/src/types/Cell.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Cell_ColumnGrouping } from '../features/column-grouping/columnGroupingFeature.types'
|
|
2
|
+
import type { Cell_Aggregation } from '../features/aggregation/aggregationFeature.types'
|
|
2
3
|
import type { CellData, RowData } from './type-utils'
|
|
3
4
|
import type { ExtractFeatureMapTypes, TableFeatures } from './TableFeatures'
|
|
4
5
|
import type { Cell_Cell } from '../core/cells/coreCellsFeature.types'
|
|
@@ -10,6 +11,7 @@ export interface Cell_Core<
|
|
|
10
11
|
> extends Cell_Cell<TFeatures, TData, TValue> {}
|
|
11
12
|
|
|
12
13
|
export interface Cell_FeatureMap {
|
|
14
|
+
aggregationFeature: Cell_Aggregation
|
|
13
15
|
columnGroupingFeature: Cell_ColumnGrouping
|
|
14
16
|
}
|
|
15
17
|
|
package/src/types/Column.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Table_Internal } from './Table'
|
|
2
2
|
import type { Column_RowSorting } from '../features/row-sorting/rowSortingFeature.types'
|
|
3
|
+
import type { Column_Aggregation } from '../features/aggregation/aggregationFeature.types'
|
|
3
4
|
import type { Column_ColumnFaceting } from '../features/column-faceting/columnFacetingFeature.types'
|
|
4
5
|
import type { Column_ColumnFiltering } from '../features/column-filtering/columnFilteringFeature.types'
|
|
5
6
|
import type { Column_ColumnGrouping } from '../features/column-grouping/columnGroupingFeature.types'
|
|
@@ -24,9 +25,10 @@ export interface Column_FeatureMap<
|
|
|
24
25
|
in out TFeatures extends TableFeatures,
|
|
25
26
|
in out TData extends RowData,
|
|
26
27
|
> {
|
|
28
|
+
aggregationFeature: Column_Aggregation<TFeatures, TData>
|
|
27
29
|
columnFacetingFeature: Column_ColumnFaceting<TFeatures, TData>
|
|
28
30
|
columnFilteringFeature: Column_ColumnFiltering<TFeatures, TData>
|
|
29
|
-
columnGroupingFeature: Column_ColumnGrouping
|
|
31
|
+
columnGroupingFeature: Column_ColumnGrouping
|
|
30
32
|
columnOrderingFeature: Column_ColumnOrdering
|
|
31
33
|
columnPinningFeature: Column_ColumnPinning
|
|
32
34
|
columnResizingFeature: Column_ColumnResizing
|
package/src/types/ColumnDef.ts
CHANGED
|
@@ -7,6 +7,7 @@ import type {
|
|
|
7
7
|
import type { CellContext } from '../core/cells/coreCellsFeature.types'
|
|
8
8
|
import type { HeaderContext } from '../core/headers/coreHeadersFeature.types'
|
|
9
9
|
import type { ColumnDef_ColumnFiltering } from '../features/column-filtering/columnFilteringFeature.types'
|
|
10
|
+
import type { ColumnDef_Aggregation } from '../features/aggregation/aggregationFeature.types'
|
|
10
11
|
import type { ColumnDef_ColumnGrouping } from '../features/column-grouping/columnGroupingFeature.types'
|
|
11
12
|
import type { ColumnDef_ColumnPinning } from '../features/column-pinning/columnPinningFeature.types'
|
|
12
13
|
import type { ColumnDef_ColumnResizing } from '../features/column-resizing/columnResizingFeature.types'
|
|
@@ -132,12 +133,13 @@ export interface ColumnDef_FeatureMap<
|
|
|
132
133
|
in out TData extends RowData,
|
|
133
134
|
TValue extends CellData,
|
|
134
135
|
> {
|
|
136
|
+
aggregationFeature: ColumnDef_Aggregation<TFeatures, TData, TValue>
|
|
135
137
|
columnVisibilityFeature: ColumnDef_ColumnVisibility
|
|
136
138
|
columnPinningFeature: ColumnDef_ColumnPinning
|
|
137
139
|
columnFilteringFeature: ColumnDef_ColumnFiltering<TFeatures, TData>
|
|
138
140
|
globalFilteringFeature: ColumnDef_GlobalFiltering
|
|
139
141
|
rowSortingFeature: ColumnDef_RowSorting<TFeatures, TData>
|
|
140
|
-
columnGroupingFeature: ColumnDef_ColumnGrouping<TFeatures, TData
|
|
142
|
+
columnGroupingFeature: ColumnDef_ColumnGrouping<TFeatures, TData>
|
|
141
143
|
columnSizingFeature: ColumnDef_ColumnSizing
|
|
142
144
|
columnResizingFeature: ColumnDef_ColumnResizing
|
|
143
145
|
}
|
|
@@ -158,12 +160,13 @@ export type ColumnDefBase_All<
|
|
|
158
160
|
TValue extends CellData = CellData,
|
|
159
161
|
> = ColumnDefBase_Core<TFeatures, TData, TValue> &
|
|
160
162
|
Partial<
|
|
161
|
-
|
|
163
|
+
ColumnDef_Aggregation<TFeatures, TData, TValue> &
|
|
164
|
+
ColumnDef_ColumnVisibility &
|
|
162
165
|
ColumnDef_ColumnPinning &
|
|
163
166
|
ColumnDef_ColumnFiltering<TFeatures, TData> &
|
|
164
167
|
ColumnDef_GlobalFiltering &
|
|
165
168
|
ColumnDef_RowSorting<TFeatures, TData> &
|
|
166
|
-
ColumnDef_ColumnGrouping<TFeatures, TData
|
|
169
|
+
ColumnDef_ColumnGrouping<TFeatures, TData> &
|
|
167
170
|
ColumnDef_ColumnSizing &
|
|
168
171
|
ColumnDef_ColumnResizing
|
|
169
172
|
>
|
package/src/types/Row.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Row_ColumnVisibility } from '../features/column-visibility/columnVisibilityFeature.types'
|
|
2
|
+
import type { Row_Aggregation } from '../features/aggregation/aggregationFeature.types'
|
|
2
3
|
import type { Row_ColumnPinning } from '../features/column-pinning/columnPinningFeature.types'
|
|
3
4
|
import type { Row_ColumnGrouping } from '../features/column-grouping/columnGroupingFeature.types'
|
|
4
5
|
import type { Row_ColumnFiltering } from '../features/column-filtering/columnFilteringFeature.types'
|
|
@@ -18,6 +19,7 @@ export interface Row_FeatureMap<
|
|
|
18
19
|
in out TFeatures extends TableFeatures,
|
|
19
20
|
in out TData extends RowData,
|
|
20
21
|
> {
|
|
22
|
+
aggregationFeature: Row_Aggregation
|
|
21
23
|
columnFilteringFeature: Row_ColumnFiltering<TFeatures, TData>
|
|
22
24
|
columnGroupingFeature: Row_ColumnGrouping
|
|
23
25
|
columnPinningFeature: Row_ColumnPinning<TFeatures, TData>
|
package/src/types/RowModelFns.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { RowModelFns_RowSorting } from '../features/row-sorting/rowSortingFeature.types'
|
|
2
|
-
import type {
|
|
2
|
+
import type { RowModelFns_Aggregation } from '../features/aggregation/aggregationFeature.types'
|
|
3
3
|
import type { RowData } from './type-utils'
|
|
4
4
|
import type { RowModelFns_ColumnFiltering } from '../features/column-filtering/columnFilteringFeature.types'
|
|
5
5
|
import type { ExtractFeatureMapTypes, TableFeatures } from './TableFeatures'
|
|
@@ -10,8 +10,8 @@ export interface RowModelFns_FeatureMap<
|
|
|
10
10
|
in out TFeatures extends TableFeatures,
|
|
11
11
|
in out TData extends RowData,
|
|
12
12
|
> {
|
|
13
|
+
aggregationFeature: RowModelFns_Aggregation<TFeatures, TData>
|
|
13
14
|
columnFilteringFeature: RowModelFns_ColumnFiltering<TFeatures, TData>
|
|
14
|
-
columnGroupingFeature: RowModelFns_ColumnGrouping<TFeatures, TData>
|
|
15
15
|
rowSortingFeature: RowModelFns_RowSorting<TFeatures, TData>
|
|
16
16
|
}
|
|
17
17
|
|
|
@@ -27,6 +27,6 @@ export interface RowModelFns_All<
|
|
|
27
27
|
in out TData extends RowData,
|
|
28
28
|
> extends Partial<
|
|
29
29
|
RowModelFns_ColumnFiltering<TFeatures, TData> &
|
|
30
|
-
|
|
30
|
+
RowModelFns_Aggregation<TFeatures, TData> &
|
|
31
31
|
RowModelFns_RowSorting<TFeatures, TData>
|
|
32
32
|
> {}
|
|
@@ -10,7 +10,7 @@ import type { StockFeatures } from '../features/stockFeatures'
|
|
|
10
10
|
import type { RowModel } from '../core/row-models/coreRowModelsFeature.types'
|
|
11
11
|
import type { FilterFn } from '../features/column-filtering/columnFilteringFeature.types'
|
|
12
12
|
import type { SortFn } from '../features/row-sorting/rowSortingFeature.types'
|
|
13
|
-
import type {
|
|
13
|
+
import type { AggregationFnDef } from '../features/aggregation/aggregationFeature.types'
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* Detects whether a type is `any`.
|
|
@@ -90,9 +90,9 @@ export type NonFeatureKeys =
|
|
|
90
90
|
*/
|
|
91
91
|
export interface FeatureSlotPrereqs {
|
|
92
92
|
/**
|
|
93
|
-
* Named aggregation functions
|
|
93
|
+
* Named aggregation functions require the independent aggregation feature.
|
|
94
94
|
*/
|
|
95
|
-
aggregationFns: '
|
|
95
|
+
aggregationFns: 'aggregationFeature'
|
|
96
96
|
/**
|
|
97
97
|
* Column resizing builds on the column sizing state and APIs.
|
|
98
98
|
*/
|
|
@@ -184,11 +184,13 @@ export interface TableFeatures
|
|
|
184
184
|
* Registry of aggregation functions available to this table by name.
|
|
185
185
|
*
|
|
186
186
|
* Keys registered here become the valid string values for `aggregationFn` on
|
|
187
|
-
* column definitions, with full inference.
|
|
188
|
-
*
|
|
189
|
-
* `aggregationFns: {
|
|
187
|
+
* column definitions, with full inference. Import the built-in aggregation
|
|
188
|
+
* functions you use individually and register them by their conventional
|
|
189
|
+
* names: `aggregationFns: { sum: aggregationFn_sum, myCustomAggregationFn }`.
|
|
190
|
+
* Spreading the exported `aggregationFns` registry also works, but puts
|
|
191
|
+
* every built-in aggregation function in your bundle.
|
|
190
192
|
*/
|
|
191
|
-
aggregationFns?: Record<string,
|
|
193
|
+
aggregationFns?: Record<string, AggregationFnDef<any, any, any, any>>
|
|
192
194
|
/**
|
|
193
195
|
* Type-only slot for declaring the type of `columnDef.meta` for all columns
|
|
194
196
|
* of this table.
|
|
@@ -243,8 +245,11 @@ export interface TableFeatures
|
|
|
243
245
|
*
|
|
244
246
|
* Keys registered here become the valid string values for `filterFn` on
|
|
245
247
|
* column definitions and the `globalFilterFn` option, with full inference.
|
|
246
|
-
*
|
|
247
|
-
*
|
|
248
|
+
* Import the built-in filter functions you use individually and register
|
|
249
|
+
* them by their conventional names:
|
|
250
|
+
* `filterFns: { includesString: filterFn_includesString, myCustomFilterFn }`.
|
|
251
|
+
* Spreading the exported `filterFns` registry also works, but puts every
|
|
252
|
+
* built-in filter function in your bundle.
|
|
248
253
|
*/
|
|
249
254
|
filterFns?: Record<string, FilterFn<any, any>>
|
|
250
255
|
/**
|
|
@@ -281,8 +286,11 @@ export interface TableFeatures
|
|
|
281
286
|
* Registry of sorting functions available to this table by name.
|
|
282
287
|
*
|
|
283
288
|
* Keys registered here become the valid string values for `sortFn` on column
|
|
284
|
-
* definitions, with full inference.
|
|
285
|
-
*
|
|
289
|
+
* definitions, with full inference. Import the built-in sorting functions
|
|
290
|
+
* you use individually and register them by their conventional names:
|
|
291
|
+
* `sortFns: { alphanumeric: sortFn_alphanumeric, myCustomSortFn }`. Spreading
|
|
292
|
+
* the exported `sortFns` registry also works, but puts every built-in
|
|
293
|
+
* sorting function in your bundle.
|
|
286
294
|
*/
|
|
287
295
|
sortFns?: Record<string, SortFn<any, any>>
|
|
288
296
|
/**
|
|
@@ -4,6 +4,7 @@ import type { TableOptions_Columns } from '../core/columns/coreColumnsFeature.ty
|
|
|
4
4
|
import type { TableOptions_Rows } from '../core/rows/coreRowsFeature.types'
|
|
5
5
|
import type { TableOptions_Table } from '../core/table/coreTablesFeature.types'
|
|
6
6
|
import type { TableOptions_ColumnFiltering } from '../features/column-filtering/columnFilteringFeature.types'
|
|
7
|
+
import type { TableOptions_Aggregation } from '../features/aggregation/aggregationFeature.types'
|
|
7
8
|
import type { TableOptions_ColumnGrouping } from '../features/column-grouping/columnGroupingFeature.types'
|
|
8
9
|
import type { TableOptions_ColumnOrdering } from '../features/column-ordering/columnOrderingFeature.types'
|
|
9
10
|
import type { TableOptions_ColumnPinning } from '../features/column-pinning/columnPinningFeature.types'
|
|
@@ -58,6 +59,7 @@ export interface TableOptions_FeatureMap<
|
|
|
58
59
|
in out TFeatures extends TableFeatures,
|
|
59
60
|
in out TData extends RowData,
|
|
60
61
|
> {
|
|
62
|
+
aggregationFeature: TableOptions_Aggregation
|
|
61
63
|
columnFilteringFeature: TableOptions_ColumnFiltering<TFeatures, TData>
|
|
62
64
|
columnGroupingFeature: TableOptions_ColumnGrouping
|
|
63
65
|
columnOrderingFeature: TableOptions_ColumnOrdering
|
|
@@ -74,6 +76,7 @@ export interface TableOptions_FeatureMap<
|
|
|
74
76
|
}
|
|
75
77
|
|
|
76
78
|
type TableOptions_StockFeatureKeys =
|
|
79
|
+
| 'aggregationFeature'
|
|
77
80
|
| 'columnFilteringFeature'
|
|
78
81
|
| 'columnGroupingFeature'
|
|
79
82
|
| 'columnOrderingFeature'
|
|
@@ -133,7 +136,8 @@ export type TableOptions_All<
|
|
|
133
136
|
TData extends RowData,
|
|
134
137
|
> = TableOptions_Core<TFeatures, TData> &
|
|
135
138
|
Partial<
|
|
136
|
-
|
|
139
|
+
TableOptions_Aggregation &
|
|
140
|
+
TableOptions_ColumnFiltering<TFeatures, TData> &
|
|
137
141
|
TableOptions_ColumnGrouping &
|
|
138
142
|
TableOptions_ColumnOrdering &
|
|
139
143
|
TableOptions_ColumnPinning &
|
package/src/types/type-utils.ts
CHANGED
|
@@ -6,6 +6,14 @@ export type RowData = Record<string, any> | Array<any>
|
|
|
6
6
|
|
|
7
7
|
export type CellData = unknown
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* Normalizes a row's value before a filter or sort comparator sees it.
|
|
11
|
+
*
|
|
12
|
+
* Attach as `resolveDataValue` on filter/sort functions built with
|
|
13
|
+
* `constructFilterFn`/`constructSortFn` (e.g. to lowercase or strip diacritics).
|
|
14
|
+
*/
|
|
15
|
+
export type TransformDataValueFn = (dataValue: any) => any
|
|
16
|
+
|
|
9
17
|
export type PartialKeys<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>
|
|
10
18
|
|
|
11
19
|
export type RequiredKeys<T, K extends keyof T> = Omit<T, K> &
|
|
@@ -84,7 +84,7 @@ export function initTableWorker<
|
|
|
84
84
|
// per group. Sync tables aggregate lazily (visible cells only), so
|
|
85
85
|
// auto-aggregating every column would explode on high-cardinality
|
|
86
86
|
// grouping for values nothing renders. Read the RAW column defs:
|
|
87
|
-
//
|
|
87
|
+
// aggregationFeature injects default aggregatedCell/aggregationFn
|
|
88
88
|
// into every resolved columnDef, so the resolved defs can't tell
|
|
89
89
|
// explicit from default.
|
|
90
90
|
aggregateColumnIds = flattenColumnDefs(config.columns as Array<any>)
|
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
//#region src/fns/aggregationFns.ts
|
|
3
|
-
/**
|
|
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.
|
|
8
|
-
*/
|
|
9
|
-
function aggregationFn_sum(columnId, _leafRows, childRows) {
|
|
10
|
-
let sumValue = 0;
|
|
11
|
-
for (let i = 0; i < childRows.length; i++) {
|
|
12
|
-
const nextValue = childRows[i].getValue(columnId);
|
|
13
|
-
sumValue += typeof nextValue === "number" ? nextValue : 0;
|
|
14
|
-
}
|
|
15
|
-
return sumValue;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Finds the minimum numeric child-row value for a grouped column.
|
|
19
|
-
*
|
|
20
|
-
* Nullish and non-number values are ignored. Returns `undefined` when no
|
|
21
|
-
* numeric value is found.
|
|
22
|
-
*/
|
|
23
|
-
function aggregationFn_min(columnId, _leafRows, childRows) {
|
|
24
|
-
let minValue;
|
|
25
|
-
for (let i = 0; i < childRows.length; i++) {
|
|
26
|
-
const value = childRows[i].getValue(columnId);
|
|
27
|
-
if (typeof value === "number" && (minValue === void 0 || value < minValue)) minValue = value;
|
|
28
|
-
}
|
|
29
|
-
return minValue;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Finds the maximum numeric child-row value for a grouped column.
|
|
33
|
-
*
|
|
34
|
-
* Nullish and non-number values are ignored. Returns `undefined` when no
|
|
35
|
-
* numeric value is found.
|
|
36
|
-
*/
|
|
37
|
-
function aggregationFn_max(columnId, _leafRows, childRows) {
|
|
38
|
-
let maxValue;
|
|
39
|
-
for (let i = 0; i < childRows.length; i++) {
|
|
40
|
-
const value = childRows[i].getValue(columnId);
|
|
41
|
-
if (typeof value === "number" && (maxValue === void 0 || value > maxValue)) maxValue = value;
|
|
42
|
-
}
|
|
43
|
-
return maxValue;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Finds the numeric extent for a grouped column.
|
|
47
|
-
*
|
|
48
|
-
* Returns `[min, max]`, where each entry is `undefined` when no numeric value is
|
|
49
|
-
* present.
|
|
50
|
-
*/
|
|
51
|
-
function aggregationFn_extent(columnId, _leafRows, childRows) {
|
|
52
|
-
let minValue;
|
|
53
|
-
let maxValue;
|
|
54
|
-
for (let i = 0; i < childRows.length; i++) {
|
|
55
|
-
const value = childRows[i].getValue(columnId);
|
|
56
|
-
if (typeof value === "number") if (minValue === void 0) minValue = maxValue = value;
|
|
57
|
-
else {
|
|
58
|
-
if (minValue > value) minValue = value;
|
|
59
|
-
if (maxValue < value) maxValue = value;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
return [minValue, maxValue];
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Averages numeric leaf-row values for a grouped column.
|
|
66
|
-
*
|
|
67
|
-
* Number-like values are coerced with unary `+`; nullish and non-numeric values
|
|
68
|
-
* are ignored.
|
|
69
|
-
*/
|
|
70
|
-
function aggregationFn_mean(columnId, leafRows) {
|
|
71
|
-
let count = 0;
|
|
72
|
-
let sumValue = 0;
|
|
73
|
-
for (let i = 0; i < leafRows.length; i++) {
|
|
74
|
-
const value = leafRows[i].getValue(columnId);
|
|
75
|
-
if (value != null && typeof value === "number") {
|
|
76
|
-
++count;
|
|
77
|
-
sumValue += value;
|
|
78
|
-
} else if (value != null) {
|
|
79
|
-
const numValue = +value;
|
|
80
|
-
if (!Number.isNaN(numValue)) {
|
|
81
|
-
++count;
|
|
82
|
-
sumValue += numValue;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
if (count) return sumValue / count;
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Computes the median of numeric leaf-row values for a grouped column.
|
|
90
|
-
*
|
|
91
|
-
* All values must be numbers. If any value is non-numeric, or no leaf rows are
|
|
92
|
-
* present, the result is `undefined`.
|
|
93
|
-
*/
|
|
94
|
-
function aggregationFn_median(columnId, leafRows) {
|
|
95
|
-
if (!leafRows.length) return;
|
|
96
|
-
const values = new Array(leafRows.length);
|
|
97
|
-
for (let i = 0; i < leafRows.length; i++) {
|
|
98
|
-
const v = leafRows[i].getValue(columnId);
|
|
99
|
-
if (typeof v !== "number") return;
|
|
100
|
-
values[i] = v;
|
|
101
|
-
}
|
|
102
|
-
if (values.length === 1) return values[0];
|
|
103
|
-
const mid = Math.floor(values.length / 2);
|
|
104
|
-
values.sort((a, b) => a - b);
|
|
105
|
-
return values.length % 2 !== 0 ? values[mid] : (values[mid - 1] + values[mid]) / 2;
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Collects unique leaf-row values for a grouped column.
|
|
109
|
-
*
|
|
110
|
-
* Values are compared with JavaScript `Set` semantics.
|
|
111
|
-
*/
|
|
112
|
-
function aggregationFn_unique(columnId, leafRows) {
|
|
113
|
-
const set = /* @__PURE__ */ new Set();
|
|
114
|
-
for (let i = 0; i < leafRows.length; i++) set.add(leafRows[i].getValue(columnId));
|
|
115
|
-
return Array.from(set.values());
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* Counts unique leaf-row values for a grouped column.
|
|
119
|
-
*
|
|
120
|
-
* Values are compared with JavaScript `Set` semantics.
|
|
121
|
-
*/
|
|
122
|
-
function aggregationFn_uniqueCount(columnId, leafRows) {
|
|
123
|
-
const set = /* @__PURE__ */ new Set();
|
|
124
|
-
for (let i = 0; i < leafRows.length; i++) set.add(leafRows[i].getValue(columnId));
|
|
125
|
-
return set.size;
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* Counts the number of leaf rows in the group.
|
|
129
|
-
*
|
|
130
|
-
* The column id is ignored because the result is based only on group size.
|
|
131
|
-
*/
|
|
132
|
-
function aggregationFn_count(_columnId, leafRows) {
|
|
133
|
-
return leafRows.length;
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* The built-in aggregation function registry.
|
|
137
|
-
*
|
|
138
|
-
* Pass this object to grouped row model creation or extend it with custom aggregation functions for grouped columns.
|
|
139
|
-
*/
|
|
140
|
-
const aggregationFns = {
|
|
141
|
-
sum: aggregationFn_sum,
|
|
142
|
-
min: aggregationFn_min,
|
|
143
|
-
max: aggregationFn_max,
|
|
144
|
-
extent: aggregationFn_extent,
|
|
145
|
-
mean: aggregationFn_mean,
|
|
146
|
-
median: aggregationFn_median,
|
|
147
|
-
unique: aggregationFn_unique,
|
|
148
|
-
uniqueCount: aggregationFn_uniqueCount,
|
|
149
|
-
count: aggregationFn_count
|
|
150
|
-
};
|
|
151
|
-
|
|
152
|
-
//#endregion
|
|
153
|
-
exports.aggregationFn_count = aggregationFn_count;
|
|
154
|
-
exports.aggregationFn_extent = aggregationFn_extent;
|
|
155
|
-
exports.aggregationFn_max = aggregationFn_max;
|
|
156
|
-
exports.aggregationFn_mean = aggregationFn_mean;
|
|
157
|
-
exports.aggregationFn_median = aggregationFn_median;
|
|
158
|
-
exports.aggregationFn_min = aggregationFn_min;
|
|
159
|
-
exports.aggregationFn_sum = aggregationFn_sum;
|
|
160
|
-
exports.aggregationFn_unique = aggregationFn_unique;
|
|
161
|
-
exports.aggregationFn_uniqueCount = aggregationFn_uniqueCount;
|
|
162
|
-
exports.aggregationFns = aggregationFns;
|
|
163
|
-
//# sourceMappingURL=aggregationFns.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
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 let sumValue = 0\n for (let i = 0; i < childRows.length; i++) {\n const nextValue = childRows[i]!.getValue(columnId)\n sumValue += typeof nextValue === 'number' ? nextValue : 0\n }\n return sumValue\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 for (let i = 0; i < childRows.length; i++) {\n const value = childRows[i]!.getValue(columnId)\n\n if (\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 for (let i = 0; i < childRows.length; i++) {\n const value = childRows[i]!.getValue(columnId)\n if (\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 for (let i = 0; i < childRows.length; i++) {\n const value = childRows[i]!.getValue(columnId)\n if (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 for (let i = 0; i < leafRows.length; i++) {\n const value = leafRows[i]!.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,85 +0,0 @@
|
|
|
1
|
-
import { RowData } from "../types/type-utils.cjs";
|
|
2
|
-
import { Row } from "../types/Row.cjs";
|
|
3
|
-
import { TableFeatures } from "../types/TableFeatures.cjs";
|
|
4
|
-
|
|
5
|
-
//#region src/fns/aggregationFns.d.ts
|
|
6
|
-
/**
|
|
7
|
-
* Sums numeric child-row values for a grouped column.
|
|
8
|
-
*
|
|
9
|
-
* Non-number values contribute `0`. Child rows are used so nested group totals
|
|
10
|
-
* can reuse already aggregated values.
|
|
11
|
-
*/
|
|
12
|
-
declare function aggregationFn_sum<TFeatures extends TableFeatures, TData extends RowData>(columnId: string, _leafRows: Array<Row<TFeatures, TData>>, childRows: Array<Row<TFeatures, TData>>): number;
|
|
13
|
-
/**
|
|
14
|
-
* Finds the minimum numeric child-row value for a grouped column.
|
|
15
|
-
*
|
|
16
|
-
* Nullish and non-number values are ignored. Returns `undefined` when no
|
|
17
|
-
* numeric value is found.
|
|
18
|
-
*/
|
|
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;
|
|
20
|
-
/**
|
|
21
|
-
* Finds the maximum numeric child-row value for a grouped column.
|
|
22
|
-
*
|
|
23
|
-
* Nullish and non-number values are ignored. Returns `undefined` when no
|
|
24
|
-
* numeric value is found.
|
|
25
|
-
*/
|
|
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;
|
|
27
|
-
/**
|
|
28
|
-
* Finds the numeric extent for a grouped column.
|
|
29
|
-
*
|
|
30
|
-
* Returns `[min, max]`, where each entry is `undefined` when no numeric value is
|
|
31
|
-
* present.
|
|
32
|
-
*/
|
|
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)[];
|
|
34
|
-
/**
|
|
35
|
-
* Averages numeric leaf-row values for a grouped column.
|
|
36
|
-
*
|
|
37
|
-
* Number-like values are coerced with unary `+`; nullish and non-numeric values
|
|
38
|
-
* are ignored.
|
|
39
|
-
*/
|
|
40
|
-
declare function aggregationFn_mean<TFeatures extends TableFeatures, TData extends RowData>(columnId: string, leafRows: Array<Row<TFeatures, TData>>): number | undefined;
|
|
41
|
-
/**
|
|
42
|
-
* Computes the median of numeric leaf-row values for a grouped column.
|
|
43
|
-
*
|
|
44
|
-
* All values must be numbers. If any value is non-numeric, or no leaf rows are
|
|
45
|
-
* present, the result is `undefined`.
|
|
46
|
-
*/
|
|
47
|
-
declare function aggregationFn_median<TFeatures extends TableFeatures, TData extends RowData>(columnId: string, leafRows: Array<Row<TFeatures, TData>>): number | undefined;
|
|
48
|
-
/**
|
|
49
|
-
* Collects unique leaf-row values for a grouped column.
|
|
50
|
-
*
|
|
51
|
-
* Values are compared with JavaScript `Set` semantics.
|
|
52
|
-
*/
|
|
53
|
-
declare function aggregationFn_unique<TFeatures extends TableFeatures, TData extends RowData>(columnId: string, leafRows: Array<Row<TFeatures, TData>>): unknown[];
|
|
54
|
-
/**
|
|
55
|
-
* Counts unique leaf-row values for a grouped column.
|
|
56
|
-
*
|
|
57
|
-
* Values are compared with JavaScript `Set` semantics.
|
|
58
|
-
*/
|
|
59
|
-
declare function aggregationFn_uniqueCount<TFeatures extends TableFeatures, TData extends RowData>(columnId: string, leafRows: Array<Row<TFeatures, TData>>): number;
|
|
60
|
-
/**
|
|
61
|
-
* Counts the number of leaf rows in the group.
|
|
62
|
-
*
|
|
63
|
-
* The column id is ignored because the result is based only on group size.
|
|
64
|
-
*/
|
|
65
|
-
declare function aggregationFn_count<TFeatures extends TableFeatures, TData extends RowData>(_columnId: string, leafRows: Array<Row<TFeatures, TData>>): number;
|
|
66
|
-
/**
|
|
67
|
-
* The built-in aggregation function registry.
|
|
68
|
-
*
|
|
69
|
-
* Pass this object to grouped row model creation or extend it with custom aggregation functions for grouped columns.
|
|
70
|
-
*/
|
|
71
|
-
declare const aggregationFns: {
|
|
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;
|
|
81
|
-
};
|
|
82
|
-
type BuiltInAggregationFn = keyof typeof aggregationFns;
|
|
83
|
-
//#endregion
|
|
84
|
-
export { BuiltInAggregationFn, aggregationFn_count, aggregationFn_extent, aggregationFn_max, aggregationFn_mean, aggregationFn_median, aggregationFn_min, aggregationFn_sum, aggregationFn_unique, aggregationFn_uniqueCount, aggregationFns };
|
|
85
|
-
//# sourceMappingURL=aggregationFns.d.cts.map
|