@affino/datagrid-pivot 0.1.1
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/LICENSE +21 -0
- package/README.md +36 -0
- package/dist/contracts.d.ts +32 -0
- package/dist/contracts.d.ts.map +1 -0
- package/dist/contracts.js +1 -0
- package/dist/coreTypes.d.ts +163 -0
- package/dist/coreTypes.d.ts.map +1 -0
- package/dist/coreTypes.js +1 -0
- package/dist/drilldownContracts.d.ts +18 -0
- package/dist/drilldownContracts.d.ts.map +1 -0
- package/dist/drilldownContracts.js +1 -0
- package/dist/drilldownRuntime.d.ts +17 -0
- package/dist/drilldownRuntime.d.ts.map +1 -0
- package/dist/drilldownRuntime.js +103 -0
- package/dist/fieldRuntime.d.ts +8 -0
- package/dist/fieldRuntime.d.ts.map +1 -0
- package/dist/fieldRuntime.js +52 -0
- package/dist/helpers.d.ts +5 -0
- package/dist/helpers.d.ts.map +1 -0
- package/dist/helpers.js +161 -0
- package/dist/incrementalHelpers.d.ts +23 -0
- package/dist/incrementalHelpers.d.ts.map +1 -0
- package/dist/incrementalHelpers.js +107 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/layoutContracts.d.ts +28 -0
- package/dist/layoutContracts.d.ts.map +1 -0
- package/dist/layoutContracts.js +1 -0
- package/dist/layoutRuntime.d.ts +9 -0
- package/dist/layoutRuntime.d.ts.map +1 -0
- package/dist/layoutRuntime.js +160 -0
- package/dist/runtimeContracts.d.ts +30 -0
- package/dist/runtimeContracts.d.ts.map +1 -0
- package/dist/runtimeContracts.js +1 -0
- package/dist/runtimeHelpers.d.ts +34 -0
- package/dist/runtimeHelpers.d.ts.map +1 -0
- package/dist/runtimeHelpers.js +105 -0
- package/package.json +41 -0
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
const pivotPathValueCollator = new Intl.Collator(undefined, {
|
|
2
|
+
numeric: true,
|
|
3
|
+
sensitivity: "base",
|
|
4
|
+
});
|
|
5
|
+
export function createPivotAxisKey(prefix, segments) {
|
|
6
|
+
let encoded = prefix;
|
|
7
|
+
for (const segment of segments) {
|
|
8
|
+
encoded += `${segment.field.length}:${segment.field}${segment.value.length}:${segment.value}`;
|
|
9
|
+
}
|
|
10
|
+
return encoded;
|
|
11
|
+
}
|
|
12
|
+
export function createPivotAggregateKey(spec) {
|
|
13
|
+
return `pivot:agg:${spec.agg.length}:${spec.agg}${spec.field.length}:${spec.field}`;
|
|
14
|
+
}
|
|
15
|
+
export function createPivotColumnId(columnKey, valueSpec) {
|
|
16
|
+
return `pivot|${columnKey}|${createPivotAggregateKey(valueSpec)}`;
|
|
17
|
+
}
|
|
18
|
+
export function createPivotColumnLabel(columnPath, valueSpec, options = {}) {
|
|
19
|
+
const axisLabel = options.grandTotal
|
|
20
|
+
? "grand total"
|
|
21
|
+
: columnPath.length === 0
|
|
22
|
+
? "total"
|
|
23
|
+
: columnPath.map(segment => `${segment.field}=${segment.value}`).join(" · ");
|
|
24
|
+
const subtotalLabel = options.subtotal ? " · subtotal" : "";
|
|
25
|
+
return `${axisLabel}${subtotalLabel} · ${valueSpec.agg}(${valueSpec.field})`;
|
|
26
|
+
}
|
|
27
|
+
export function normalizePivotAxisValue(value, normalizeFieldValue) {
|
|
28
|
+
if (value == null) {
|
|
29
|
+
return "";
|
|
30
|
+
}
|
|
31
|
+
const normalized = normalizeFieldValue(value);
|
|
32
|
+
return normalized == null ? "" : String(normalized);
|
|
33
|
+
}
|
|
34
|
+
export function comparePivotPathSegments(left, right) {
|
|
35
|
+
const maxLength = Math.max(left.length, right.length);
|
|
36
|
+
for (let index = 0; index < maxLength; index += 1) {
|
|
37
|
+
const leftSegment = left[index];
|
|
38
|
+
const rightSegment = right[index];
|
|
39
|
+
if (!leftSegment && !rightSegment) {
|
|
40
|
+
return 0;
|
|
41
|
+
}
|
|
42
|
+
if (!leftSegment) {
|
|
43
|
+
return -1;
|
|
44
|
+
}
|
|
45
|
+
if (!rightSegment) {
|
|
46
|
+
return 1;
|
|
47
|
+
}
|
|
48
|
+
const fieldComparison = leftSegment.field < rightSegment.field
|
|
49
|
+
? -1
|
|
50
|
+
: leftSegment.field > rightSegment.field
|
|
51
|
+
? 1
|
|
52
|
+
: 0;
|
|
53
|
+
if (fieldComparison !== 0) {
|
|
54
|
+
return fieldComparison;
|
|
55
|
+
}
|
|
56
|
+
const valueComparison = pivotPathValueCollator.compare(leftSegment.value, rightSegment.value);
|
|
57
|
+
if (valueComparison !== 0) {
|
|
58
|
+
return valueComparison;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return 0;
|
|
62
|
+
}
|
|
63
|
+
export function isPivotPathPrefixOrEqual(prefix, candidate) {
|
|
64
|
+
if (prefix.length > candidate.length) {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
for (let index = 0; index < prefix.length; index += 1) {
|
|
68
|
+
const leftSegment = prefix[index];
|
|
69
|
+
const rightSegment = candidate[index];
|
|
70
|
+
if (!leftSegment || !rightSegment) {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
if (leftSegment.field !== rightSegment.field || leftSegment.value !== rightSegment.value) {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
export function normalizePivotColumns(columns) {
|
|
80
|
+
return columns.map(column => ({
|
|
81
|
+
id: column.id,
|
|
82
|
+
valueField: column.valueField,
|
|
83
|
+
agg: column.agg,
|
|
84
|
+
label: column.label,
|
|
85
|
+
...(column.subtotal ? { subtotal: true } : {}),
|
|
86
|
+
...(column.grandTotal ? { grandTotal: true } : {}),
|
|
87
|
+
columnPath: column.columnPath.map(segment => ({
|
|
88
|
+
field: segment.field,
|
|
89
|
+
value: segment.value,
|
|
90
|
+
})),
|
|
91
|
+
}));
|
|
92
|
+
}
|
|
93
|
+
export function serializePivotModelForIncrementalState(pivotModel) {
|
|
94
|
+
return JSON.stringify({
|
|
95
|
+
rows: pivotModel.rows,
|
|
96
|
+
columns: pivotModel.columns,
|
|
97
|
+
values: pivotModel.values.map(value => ({ field: value.field, agg: value.agg })),
|
|
98
|
+
rowSubtotals: pivotModel.rowSubtotals === true,
|
|
99
|
+
columnSubtotals: pivotModel.columnSubtotals === true,
|
|
100
|
+
grandTotal: pivotModel.grandTotal === true,
|
|
101
|
+
columnGrandTotal: pivotModel.columnGrandTotal === true,
|
|
102
|
+
columnSubtotalPosition: pivotModel.columnSubtotalPosition === "before" ? "before" : "after",
|
|
103
|
+
columnGrandTotalPosition: pivotModel.columnGrandTotalPosition === "first" ? "first" : "last",
|
|
104
|
+
});
|
|
105
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@affino/datagrid-pivot",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"author": "Anton Pavlov <a.pavlov@affino.dev>",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"description": "Community pivot API boundary for Affino DataGrid",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.js"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"main": "dist/index.js",
|
|
14
|
+
"types": "dist/index.d.ts",
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"sideEffects": false,
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/affinio/affinio.git",
|
|
22
|
+
"directory": "packages/datagrid-pivot"
|
|
23
|
+
},
|
|
24
|
+
"homepage": "https://github.com/affinio/affinio/tree/main/packages/datagrid-pivot#readme",
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"keywords": [
|
|
27
|
+
"datagrid",
|
|
28
|
+
"pivot",
|
|
29
|
+
"analytics",
|
|
30
|
+
"engine",
|
|
31
|
+
"headless"
|
|
32
|
+
],
|
|
33
|
+
"bugs": {
|
|
34
|
+
"url": "https://github.com/affinio/affinio/issues"
|
|
35
|
+
},
|
|
36
|
+
"module": "dist/index.js",
|
|
37
|
+
"scripts": {
|
|
38
|
+
"build": "tsc -p tsconfig.json",
|
|
39
|
+
"type-check": "tsc -p tsconfig.json --noEmit"
|
|
40
|
+
}
|
|
41
|
+
}
|