@tanstack/table-core 9.0.0-beta.47 → 9.0.0-beta.49
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-faceting/createFacetedMinMaxValues.cjs +7 -4
- package/dist/features/column-faceting/createFacetedMinMaxValues.cjs.map +1 -1
- package/dist/features/column-faceting/createFacetedMinMaxValues.js +8 -5
- package/dist/features/column-faceting/createFacetedMinMaxValues.js.map +1 -1
- package/dist/features/column-faceting/createFacetedRowModel.cjs +1 -1
- package/dist/features/column-faceting/createFacetedRowModel.cjs.map +1 -1
- package/dist/features/column-faceting/createFacetedRowModel.js +1 -1
- package/dist/features/column-faceting/createFacetedRowModel.js.map +1 -1
- package/dist/features/column-faceting/createFacetedUniqueValues.cjs +8 -4
- package/dist/features/column-faceting/createFacetedUniqueValues.cjs.map +1 -1
- package/dist/features/column-faceting/createFacetedUniqueValues.js +9 -5
- package/dist/features/column-faceting/createFacetedUniqueValues.js.map +1 -1
- package/dist/features/column-filtering/columnFilteringFeature.types.d.cts +1 -1
- package/dist/features/column-filtering/columnFilteringFeature.types.d.ts +1 -1
- package/dist/{fns → features/column-filtering}/filterFns.cjs +1 -1
- package/dist/features/column-filtering/filterFns.cjs.map +1 -0
- package/dist/{fns → features/column-filtering}/filterFns.d.cts +4 -4
- package/dist/{fns → features/column-filtering}/filterFns.d.ts +4 -4
- package/dist/{fns → features/column-filtering}/filterFns.js +1 -1
- 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 -87
- package/dist/features/column-grouping/columnGroupingFeature.types.d.ts +6 -87
- package/dist/features/column-grouping/columnGroupingFeature.utils.cjs +0 -64
- package/dist/features/column-grouping/columnGroupingFeature.utils.cjs.map +1 -1
- package/dist/features/column-grouping/columnGroupingFeature.utils.d.cts +2 -44
- package/dist/features/column-grouping/columnGroupingFeature.utils.d.ts +2 -44
- package/dist/features/column-grouping/columnGroupingFeature.utils.js +2 -63
- package/dist/features/column-grouping/columnGroupingFeature.utils.js.map +1 -1
- package/dist/features/column-grouping/createGroupedRowModel.cjs +23 -16
- package/dist/features/column-grouping/createGroupedRowModel.cjs.map +1 -1
- package/dist/features/column-grouping/createGroupedRowModel.d.cts +2 -6
- package/dist/features/column-grouping/createGroupedRowModel.d.ts +2 -6
- package/dist/features/column-grouping/createGroupedRowModel.js +25 -18
- package/dist/features/column-grouping/createGroupedRowModel.js.map +1 -1
- package/dist/features/global-filtering/globalFilteringFeature.utils.cjs +1 -1
- package/dist/features/global-filtering/globalFilteringFeature.utils.cjs.map +1 -1
- package/dist/features/global-filtering/globalFilteringFeature.utils.js +1 -1
- package/dist/features/global-filtering/globalFilteringFeature.utils.js.map +1 -1
- package/dist/features/row-sorting/rowSortingFeature.types.d.cts +1 -1
- package/dist/features/row-sorting/rowSortingFeature.types.d.ts +1 -1
- package/dist/features/row-sorting/rowSortingFeature.utils.cjs +1 -1
- package/dist/features/row-sorting/rowSortingFeature.utils.cjs.map +1 -1
- package/dist/features/row-sorting/rowSortingFeature.utils.js +1 -1
- package/dist/features/row-sorting/rowSortingFeature.utils.js.map +1 -1
- package/dist/{fns → features/row-sorting}/sortFns.cjs +1 -1
- package/dist/{fns/sortFns.js.map → features/row-sorting/sortFns.cjs.map} +1 -1
- package/dist/{fns → features/row-sorting}/sortFns.d.cts +4 -4
- package/dist/{fns → features/row-sorting}/sortFns.d.ts +4 -4
- package/dist/{fns → features/row-sorting}/sortFns.js +1 -1
- 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/index.cjs +7 -4
- package/dist/index.d.cts +7 -5
- package/dist/index.d.ts +7 -5
- 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 +4 -4
- package/dist/types/TableFeatures.d.ts +4 -4
- 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/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 +1 -1
- package/skills/column-filtering/SKILL.md +1 -1
- 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 +1 -1
- package/skills/grouping/SKILL.md +12 -18
- package/skills/migrate-v8-to-v9/SKILL.md +15 -2
- 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 +1 -1
- package/skills/table-features/SKILL.md +5 -2
- 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-faceting/createFacetedMinMaxValues.ts +33 -7
- package/src/features/column-faceting/createFacetedRowModel.ts +4 -1
- package/src/features/column-faceting/createFacetedUniqueValues.ts +45 -11
- package/src/features/column-filtering/columnFilteringFeature.types.ts +1 -1
- package/src/{fns → features/column-filtering}/filterFns.ts +4 -4
- package/src/features/column-grouping/columnGroupingFeature.ts +1 -20
- package/src/features/column-grouping/columnGroupingFeature.types.ts +4 -141
- package/src/features/column-grouping/columnGroupingFeature.utils.ts +1 -122
- package/src/features/column-grouping/createGroupedRowModel.ts +32 -41
- package/src/features/global-filtering/globalFilteringFeature.utils.ts +1 -1
- package/src/features/row-sorting/rowSortingFeature.types.ts +1 -1
- package/src/features/row-sorting/rowSortingFeature.utils.ts +1 -1
- package/src/{fns → features/row-sorting}/sortFns.ts +4 -7
- package/src/features/stockFeatures.ts +3 -0
- 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 +4 -4
- package/src/types/TableOptions.ts +5 -1
- package/src/worker/initTableWorker.ts +1 -1
- package/dist/fns/aggregationFns.cjs +0 -234
- package/dist/fns/aggregationFns.cjs.map +0 -1
- package/dist/fns/aggregationFns.d.cts +0 -139
- package/dist/fns/aggregationFns.d.ts +0 -139
- package/dist/fns/aggregationFns.js +0 -221
- package/dist/fns/aggregationFns.js.map +0 -1
- package/dist/fns/filterFns.cjs.map +0 -1
- package/dist/fns/filterFns.js.map +0 -1
- package/dist/fns/sortFns.cjs.map +0 -1
- package/src/fns/aggregationFns.ts +0 -303
|
@@ -1,303 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
AggregationFnDef,
|
|
3
|
-
CreatedAggregationFn,
|
|
4
|
-
} from '../features/column-grouping/columnGroupingFeature.types'
|
|
5
|
-
import type { RowData } from '../types/type-utils'
|
|
6
|
-
import type { TableFeatures } from '../types/TableFeatures'
|
|
7
|
-
import type { Row } from '../types/Row'
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Builds an `AggregationFn` from a value-level reducer plus optional
|
|
11
|
-
* `resolveDataValue` and `fromRows` settings.
|
|
12
|
-
*
|
|
13
|
-
* The `aggregate` reducer receives an array of the group rows' values, each
|
|
14
|
-
* already passed through `resolveDataValue` when one is defined. Keeping
|
|
15
|
-
* normalization in the resolver means a variant of an existing aggregation
|
|
16
|
-
* function only has to swap the resolver, not re-implement the computation.
|
|
17
|
-
*
|
|
18
|
-
* The definition is attached to the returned function, so a variant can be
|
|
19
|
-
* created by spreading a built-in aggregation function and overriding what
|
|
20
|
-
* differs. For example, a `min` that works on date columns:
|
|
21
|
-
*
|
|
22
|
-
* ```ts
|
|
23
|
-
* const earliest = constructAggregationFn({
|
|
24
|
-
* ...aggregationFn_min,
|
|
25
|
-
* resolveDataValue: (value) =>
|
|
26
|
-
* value instanceof Date ? value.getTime() : value,
|
|
27
|
-
* })
|
|
28
|
-
* ```
|
|
29
|
-
*
|
|
30
|
-
* The built-in `count`, `first`, and `last` aggregation functions are plain
|
|
31
|
-
* row-level functions instead: they read group position or size and never
|
|
32
|
-
* look at every value, so materializing a values array would be wasted work.
|
|
33
|
-
*/
|
|
34
|
-
export function constructAggregationFn<
|
|
35
|
-
TFeatures extends TableFeatures = any,
|
|
36
|
-
TData extends RowData = any,
|
|
37
|
-
>(
|
|
38
|
-
def: AggregationFnDef<TFeatures, TData>,
|
|
39
|
-
): CreatedAggregationFn<TFeatures, TData> {
|
|
40
|
-
const aggregationFn: CreatedAggregationFn<TFeatures, TData> = Object.assign(
|
|
41
|
-
<TRowFeatures extends TableFeatures, TRowData extends RowData>(
|
|
42
|
-
columnId: string,
|
|
43
|
-
leafRows: Array<Row<TRowFeatures, TRowData>>,
|
|
44
|
-
childRows: Array<Row<TRowFeatures, TRowData>>,
|
|
45
|
-
): any => {
|
|
46
|
-
const rows = aggregationFn.fromRows === 'childRows' ? childRows : leafRows
|
|
47
|
-
const resolveDataValue = aggregationFn.resolveDataValue
|
|
48
|
-
const values: Array<any> = new Array(rows.length)
|
|
49
|
-
for (let i = 0; i < rows.length; i++) {
|
|
50
|
-
const value = rows[i]!.getValue(columnId)
|
|
51
|
-
values[i] = resolveDataValue ? resolveDataValue(value) : value
|
|
52
|
-
}
|
|
53
|
-
// The def's reducer is typed against the factory's TFeatures/TData;
|
|
54
|
-
// the caller's row generics are erased at this boundary.
|
|
55
|
-
return aggregationFn.aggregate(values, rows as any, columnId)
|
|
56
|
-
},
|
|
57
|
-
def,
|
|
58
|
-
)
|
|
59
|
-
return aggregationFn
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Sums numeric child-row values for a grouped column.
|
|
64
|
-
*
|
|
65
|
-
* Non-number values contribute `0`. Child rows are used so nested group totals
|
|
66
|
-
* can reuse already aggregated values.
|
|
67
|
-
*/
|
|
68
|
-
export const aggregationFn_sum = constructAggregationFn({
|
|
69
|
-
fromRows: 'childRows',
|
|
70
|
-
aggregate: (values) => {
|
|
71
|
-
let sumValue = 0
|
|
72
|
-
for (let i = 0; i < values.length; i++) {
|
|
73
|
-
const nextValue = values[i]
|
|
74
|
-
sumValue += typeof nextValue === 'number' ? nextValue : 0
|
|
75
|
-
}
|
|
76
|
-
return sumValue
|
|
77
|
-
},
|
|
78
|
-
})
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Finds the minimum numeric child-row value for a grouped column.
|
|
82
|
-
*
|
|
83
|
-
* Nullish and non-number values are ignored. Returns `undefined` when no
|
|
84
|
-
* numeric value is found.
|
|
85
|
-
*/
|
|
86
|
-
export const aggregationFn_min = constructAggregationFn({
|
|
87
|
-
fromRows: 'childRows',
|
|
88
|
-
aggregate: (values) => {
|
|
89
|
-
let minValue: number | undefined
|
|
90
|
-
|
|
91
|
-
for (let i = 0; i < values.length; i++) {
|
|
92
|
-
const value = values[i]
|
|
93
|
-
if (
|
|
94
|
-
typeof value === 'number' &&
|
|
95
|
-
(minValue === undefined || value < minValue)
|
|
96
|
-
) {
|
|
97
|
-
minValue = value
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
return minValue
|
|
102
|
-
},
|
|
103
|
-
})
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Finds the maximum numeric child-row value for a grouped column.
|
|
107
|
-
*
|
|
108
|
-
* Nullish and non-number values are ignored. Returns `undefined` when no
|
|
109
|
-
* numeric value is found.
|
|
110
|
-
*/
|
|
111
|
-
export const aggregationFn_max = constructAggregationFn({
|
|
112
|
-
fromRows: 'childRows',
|
|
113
|
-
aggregate: (values) => {
|
|
114
|
-
let maxValue: number | undefined
|
|
115
|
-
|
|
116
|
-
for (let i = 0; i < values.length; i++) {
|
|
117
|
-
const value = values[i]
|
|
118
|
-
if (
|
|
119
|
-
typeof value === 'number' &&
|
|
120
|
-
(maxValue === undefined || value > maxValue)
|
|
121
|
-
) {
|
|
122
|
-
maxValue = value
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
return maxValue
|
|
127
|
-
},
|
|
128
|
-
})
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Finds the numeric extent for a grouped column.
|
|
132
|
-
*
|
|
133
|
-
* Returns `[min, max]`, where each entry is `undefined` when no numeric value is
|
|
134
|
-
* present.
|
|
135
|
-
*/
|
|
136
|
-
export const aggregationFn_extent = constructAggregationFn({
|
|
137
|
-
fromRows: 'childRows',
|
|
138
|
-
aggregate: (values) => {
|
|
139
|
-
let minValue: number | undefined
|
|
140
|
-
let maxValue: number | undefined
|
|
141
|
-
|
|
142
|
-
for (let i = 0; i < values.length; i++) {
|
|
143
|
-
const value = values[i]
|
|
144
|
-
if (typeof value === 'number') {
|
|
145
|
-
if (minValue === undefined) {
|
|
146
|
-
minValue = maxValue = value
|
|
147
|
-
} else {
|
|
148
|
-
if (minValue > value) minValue = value
|
|
149
|
-
if (maxValue! < value) maxValue = value
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
return [minValue, maxValue]
|
|
155
|
-
},
|
|
156
|
-
})
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* Averages numeric leaf-row values for a grouped column.
|
|
160
|
-
*
|
|
161
|
-
* Number-like values are coerced with unary `+`; nullish and non-numeric values
|
|
162
|
-
* are ignored.
|
|
163
|
-
*/
|
|
164
|
-
export const aggregationFn_mean = constructAggregationFn({
|
|
165
|
-
aggregate: (values) => {
|
|
166
|
-
let count = 0
|
|
167
|
-
let sumValue = 0
|
|
168
|
-
|
|
169
|
-
for (let i = 0; i < values.length; i++) {
|
|
170
|
-
const value = values[i]
|
|
171
|
-
if (value != null && typeof value === 'number') {
|
|
172
|
-
++count
|
|
173
|
-
sumValue += value
|
|
174
|
-
} else if (value != null) {
|
|
175
|
-
const numValue = +value
|
|
176
|
-
if (!Number.isNaN(numValue)) {
|
|
177
|
-
++count
|
|
178
|
-
sumValue += numValue
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
if (count) return sumValue / count
|
|
184
|
-
|
|
185
|
-
return
|
|
186
|
-
},
|
|
187
|
-
})
|
|
188
|
-
|
|
189
|
-
/**
|
|
190
|
-
* Computes the median of numeric leaf-row values for a grouped column.
|
|
191
|
-
*
|
|
192
|
-
* All values must be numbers. If any value is non-numeric, or no leaf rows are
|
|
193
|
-
* present, the result is `undefined`.
|
|
194
|
-
*/
|
|
195
|
-
export const aggregationFn_median = constructAggregationFn({
|
|
196
|
-
aggregate: (values: Array<number>) => {
|
|
197
|
-
if (!values.length) {
|
|
198
|
-
return
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
for (let i = 0; i < values.length; i++) {
|
|
202
|
-
if (typeof values[i] !== 'number') return
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
if (values.length === 1) {
|
|
206
|
-
return values[0]
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
const mid = Math.floor(values.length / 2)
|
|
210
|
-
values.sort((a, b) => a - b)
|
|
211
|
-
return values.length % 2 !== 0
|
|
212
|
-
? values[mid]
|
|
213
|
-
: (values[mid - 1]! + values[mid]!) / 2
|
|
214
|
-
},
|
|
215
|
-
})
|
|
216
|
-
|
|
217
|
-
/**
|
|
218
|
-
* Collects unique leaf-row values for a grouped column.
|
|
219
|
-
*
|
|
220
|
-
* Values are compared with JavaScript `Set` semantics.
|
|
221
|
-
*/
|
|
222
|
-
export const aggregationFn_unique = constructAggregationFn({
|
|
223
|
-
aggregate: (values) => Array.from(new Set(values).values()),
|
|
224
|
-
})
|
|
225
|
-
|
|
226
|
-
/**
|
|
227
|
-
* Counts unique leaf-row values for a grouped column.
|
|
228
|
-
*
|
|
229
|
-
* Values are compared with JavaScript `Set` semantics.
|
|
230
|
-
*/
|
|
231
|
-
export const aggregationFn_uniqueCount = constructAggregationFn({
|
|
232
|
-
aggregate: (values) => new Set(values).size,
|
|
233
|
-
})
|
|
234
|
-
|
|
235
|
-
/**
|
|
236
|
-
* Counts the number of leaf rows in the group.
|
|
237
|
-
*
|
|
238
|
-
* The column id is ignored because the result is based only on group size.
|
|
239
|
-
* This is a plain row-level function (not built with
|
|
240
|
-
* `constructAggregationFn`) because it never reads row values.
|
|
241
|
-
*/
|
|
242
|
-
export function aggregationFn_count<
|
|
243
|
-
TFeatures extends TableFeatures,
|
|
244
|
-
TData extends RowData,
|
|
245
|
-
>(_columnId: string, leafRows: Array<Row<TFeatures, TData>>) {
|
|
246
|
-
return leafRows.length
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
/**
|
|
250
|
-
* Returns the first leaf-row value for a grouped column.
|
|
251
|
-
*
|
|
252
|
-
* This is a plain row-level function (not built with
|
|
253
|
-
* `constructAggregationFn`) because it only reads one positional value.
|
|
254
|
-
*/
|
|
255
|
-
export function aggregationFn_first<
|
|
256
|
-
TFeatures extends TableFeatures,
|
|
257
|
-
TData extends RowData,
|
|
258
|
-
>(columnId: string, leafRows: Array<Row<TFeatures, TData>>) {
|
|
259
|
-
return leafRows[0]?.getValue(columnId)
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
/**
|
|
263
|
-
* Returns the last leaf-row value for a grouped column.
|
|
264
|
-
*
|
|
265
|
-
* This is a plain row-level function (not built with
|
|
266
|
-
* `constructAggregationFn`) because it only reads one positional value.
|
|
267
|
-
*/
|
|
268
|
-
export function aggregationFn_last<
|
|
269
|
-
TFeatures extends TableFeatures,
|
|
270
|
-
TData extends RowData,
|
|
271
|
-
>(columnId: string, leafRows: Array<Row<TFeatures, TData>>) {
|
|
272
|
-
return leafRows[leafRows.length - 1]?.getValue(columnId)
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
/**
|
|
276
|
-
* The built-in aggregation function registry.
|
|
277
|
-
*
|
|
278
|
-
* Registering this full object opts out of tree-shaking: every built-in
|
|
279
|
-
* aggregation function ends up in your bundle. Prefer importing the
|
|
280
|
-
* `aggregationFn_*` functions you actually use and registering just those in
|
|
281
|
-
* the `aggregationFns` slot, or passing them directly to the `aggregationFn`
|
|
282
|
-
* column option.
|
|
283
|
-
*
|
|
284
|
-
* @deprecated Import individual `aggregationFn_*` functions instead for a
|
|
285
|
-
* smaller bundle. This export still works and is not going away in v9, but
|
|
286
|
-
* built-in name resolution (including `aggregationFn: 'auto'`) only finds
|
|
287
|
-
* functions you register yourself.
|
|
288
|
-
*/
|
|
289
|
-
export const aggregationFns = {
|
|
290
|
-
sum: aggregationFn_sum,
|
|
291
|
-
min: aggregationFn_min,
|
|
292
|
-
max: aggregationFn_max,
|
|
293
|
-
extent: aggregationFn_extent,
|
|
294
|
-
mean: aggregationFn_mean,
|
|
295
|
-
median: aggregationFn_median,
|
|
296
|
-
unique: aggregationFn_unique,
|
|
297
|
-
uniqueCount: aggregationFn_uniqueCount,
|
|
298
|
-
count: aggregationFn_count,
|
|
299
|
-
first: aggregationFn_first,
|
|
300
|
-
last: aggregationFn_last,
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
export type BuiltInAggregationFn = keyof typeof aggregationFns
|