@xh/hoist 90.0.0 → 90.1.0
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/CHANGELOG.md +136 -54
- package/admin/columns/Tracking.ts +9 -3
- package/admin/tabs/activity/tracking/ActivityTrackingModel.ts +155 -47
- package/admin/tabs/activity/tracking/ActivityTrackingPanel.ts +25 -4
- package/admin/tabs/activity/tracking/chart/AggChartModel.ts +2 -3
- package/appcontainer/ImpersonationBarModel.ts +8 -5
- package/build/types/admin/tabs/activity/tracking/ActivityTrackingModel.d.ts +25 -5
- package/build/types/cmp/cubegrid/CubeGrid.d.ts +26 -0
- package/build/types/cmp/cubegrid/CubeGridModel.d.ts +103 -0
- package/build/types/cmp/cubegrid/CubeGridPivotModel.d.ts +181 -0
- package/build/types/cmp/cubegrid/Types.d.ts +85 -0
- package/build/types/cmp/cubegrid/index.d.ts +4 -0
- package/build/types/cmp/dataview/DataViewModel.d.ts +6 -10
- package/build/types/cmp/grid/GridModel.d.ts +8 -33
- package/build/types/cmp/grid/Types.d.ts +51 -1
- package/build/types/cmp/grid/columns/Column.d.ts +2 -1
- package/build/types/cmp/grid/columns/ColumnGroup.d.ts +6 -0
- package/build/types/cmp/grid/helpers/GridCountLabel.d.ts +6 -3
- package/build/types/cmp/grid/impl/ColumnWidthCalculator.d.ts +6 -0
- package/build/types/cmp/grid/impl/GridLikeModel.d.ts +3 -0
- package/build/types/cmp/grid/impl/MenuSupport.d.ts +13 -0
- package/build/types/cmp/pdfviewer/PdfViewer.d.ts +14 -0
- package/build/types/cmp/pdfviewer/PdfViewerModel.d.ts +150 -0
- package/build/types/cmp/pdfviewer/Types.d.ts +55 -0
- package/build/types/cmp/pdfviewer/impl/PdfFindInputModel.d.ts +14 -0
- package/build/types/cmp/pdfviewer/impl/PdfViewerToolbarModel.d.ts +34 -0
- package/build/types/cmp/pdfviewer/impl/ZoomOptions.d.ts +10 -0
- package/build/types/cmp/pdfviewer/index.d.ts +3 -0
- package/build/types/cmp/statcard/StatCard.d.ts +90 -0
- package/build/types/cmp/statcard/index.d.ts +1 -0
- package/build/types/cmp/store/StoreFilterField.d.ts +8 -9
- package/build/types/cmp/store/impl/StoreFilterFieldImplModel.d.ts +4 -4
- package/build/types/cmp/zoneGrid/ZoneGridModel.d.ts +6 -10
- package/build/types/core/types/Types.d.ts +6 -0
- package/build/types/data/Field.d.ts +8 -1
- package/build/types/data/Store.d.ts +12 -0
- package/build/types/data/cube/Cube.d.ts +2 -0
- package/build/types/data/cube/CubeField.d.ts +3 -2
- package/build/types/data/cube/Query.d.ts +66 -4
- package/build/types/data/cube/View.d.ts +82 -4
- package/build/types/data/cube/ViewRowData.d.ts +13 -0
- package/build/types/data/cube/aggregate/MedianAggregator.d.ts +19 -0
- package/build/types/data/cube/aggregate/SumIfSameAggregator.d.ts +30 -0
- package/build/types/data/cube/impl/RowCache.d.ts +5 -0
- package/build/types/data/cube/impl/RowDataGenerator.d.ts +26 -0
- package/build/types/data/cube/impl/ViewDiagnostics.d.ts +27 -0
- package/build/types/data/cube/pivot/PivotCellRow.d.ts +27 -0
- package/build/types/data/cube/pivot/PivotPath.d.ts +45 -0
- package/build/types/data/cube/pivot/impl/PivotCells.d.ts +111 -0
- package/build/types/data/cube/pivot/impl/PivotReference.d.ts +39 -0
- package/build/types/data/cube/pivot/impl/PivotStructure.d.ts +105 -0
- package/build/types/data/cube/row/BaseRow.d.ts +12 -0
- package/build/types/data/cube/row/LeafRow.d.ts +4 -4
- package/build/types/data/cube/row/ParentRow.d.ts +20 -4
- package/build/types/data/cube/row/RowUpdate.d.ts +2 -0
- package/build/types/data/index.d.ts +3 -0
- package/build/types/desktop/cmp/button/grid/ColAutosizeButton.d.ts +6 -3
- package/build/types/desktop/cmp/button/grid/ColChooserButton.d.ts +7 -3
- package/build/types/desktop/cmp/button/grid/ExpandToLevelButton.d.ts +6 -3
- package/build/types/desktop/cmp/button/grid/ExportButton.d.ts +6 -3
- package/build/types/desktop/cmp/grid/find/GridFindField.d.ts +8 -9
- package/build/types/desktop/cmp/grid/find/impl/GridFindFieldImplModel.d.ts +3 -4
- package/build/types/desktop/cmp/pdfviewer/impl/PdfViewerToolbar.d.ts +12 -0
- package/build/types/desktop/cmp/statcard/impl/StatCardInfoImpl.d.ts +12 -0
- package/build/types/dynamics/desktop.d.ts +2 -0
- package/build/types/dynamics/mobile.d.ts +1 -0
- package/build/types/icon/Icon.d.ts +12 -0
- package/build/types/kit/pdfjs/index.d.ts +23 -0
- package/build/types/kit/pdfjs/styles.d.ts +2 -0
- package/build/types/kit/swiper/index.d.ts +7 -7
- package/build/types/mobile/cmp/button/grid/ColAutosizeButton.d.ts +6 -3
- package/build/types/mobile/cmp/button/grid/ColChooserButton.d.ts +6 -3
- package/build/types/mobile/cmp/button/grid/ExpandCollapseButton.d.ts +4 -4
- package/build/types/mobile/cmp/button/grid/ExpandToLevelButton.d.ts +4 -4
- package/build/types/mobile/cmp/pdfviewer/impl/PdfViewerToolbar.d.ts +12 -0
- package/cmp/README.md +3 -0
- package/cmp/ag-grid/AgGrid.ts +25 -3
- package/cmp/cubegrid/CubeGrid.ts +60 -0
- package/cmp/cubegrid/CubeGridModel.ts +365 -0
- package/cmp/cubegrid/CubeGridPivotModel.ts +943 -0
- package/cmp/cubegrid/README.md +343 -0
- package/cmp/cubegrid/Types.ts +105 -0
- package/cmp/cubegrid/index.ts +10 -0
- package/cmp/dataview/DataViewModel.ts +13 -8
- package/cmp/grid/Grid.scss +21 -5
- package/cmp/grid/GridModel.ts +41 -47
- package/cmp/grid/Types.ts +58 -1
- package/cmp/grid/columns/Column.ts +3 -1
- package/cmp/grid/columns/ColumnGroup.ts +10 -0
- package/cmp/grid/helpers/GridCountLabel.ts +12 -5
- package/cmp/grid/impl/ColumnGroupHeader.ts +18 -4
- package/cmp/grid/impl/ColumnWidthCalculator.ts +24 -0
- package/cmp/grid/impl/GridLikeModel.ts +17 -0
- package/cmp/grid/impl/MenuSupport.ts +36 -20
- package/cmp/pdfviewer/PdfViewer.scss +48 -0
- package/cmp/pdfviewer/PdfViewer.ts +102 -0
- package/cmp/pdfviewer/PdfViewerModel.ts +641 -0
- package/cmp/pdfviewer/README.md +224 -0
- package/cmp/pdfviewer/Types.ts +72 -0
- package/cmp/pdfviewer/impl/PdfFindInputModel.ts +44 -0
- package/cmp/pdfviewer/impl/PdfViewerToolbarModel.ts +45 -0
- package/cmp/pdfviewer/impl/ZoomOptions.ts +36 -0
- package/cmp/pdfviewer/index.ts +9 -0
- package/cmp/statcard/StatCard.scss +181 -0
- package/cmp/statcard/StatCard.ts +320 -0
- package/cmp/statcard/index.ts +1 -0
- package/cmp/store/StoreFilterField.ts +8 -9
- package/cmp/store/impl/StoreFilterFieldImplModel.ts +14 -14
- package/cmp/zoneGrid/ZoneGridModel.ts +13 -8
- package/core/types/Types.ts +7 -0
- package/data/Field.ts +10 -0
- package/data/Store.ts +25 -2
- package/data/cube/Cube.ts +5 -0
- package/data/cube/CubeField.ts +5 -0
- package/data/cube/Query.ts +170 -17
- package/data/cube/README.md +77 -2
- package/data/cube/View.ts +211 -32
- package/data/cube/ViewRowData.ts +22 -0
- package/data/cube/aggregate/MedianAggregator.ts +88 -0
- package/data/cube/aggregate/SumIfSameAggregator.ts +128 -0
- package/data/cube/impl/RowCache.ts +32 -11
- package/data/cube/impl/RowDataGenerator.ts +96 -4
- package/data/cube/impl/ViewDiagnostics.ts +47 -0
- package/data/cube/pivot/PivotCellRow.ts +73 -0
- package/data/cube/pivot/PivotPath.ts +67 -0
- package/data/cube/pivot/impl/PivotCells.ts +538 -0
- package/data/cube/pivot/impl/PivotReference.ts +125 -0
- package/data/cube/pivot/impl/PivotStructure.ts +500 -0
- package/data/cube/row/BaseRow.ts +26 -0
- package/data/cube/row/LeafRow.ts +9 -8
- package/data/cube/row/ParentRow.ts +58 -25
- package/data/cube/row/RowUpdate.ts +8 -0
- package/data/index.ts +3 -0
- package/desktop/appcontainer/AppContainer.ts +5 -1
- package/desktop/cmp/button/grid/ColAutosizeButton.ts +21 -5
- package/desktop/cmp/button/grid/ColChooserButton.ts +11 -5
- package/desktop/cmp/button/grid/ExpandToLevelButton.ts +20 -5
- package/desktop/cmp/button/grid/ExportButton.ts +19 -7
- package/desktop/cmp/dash/canvas/DashCanvas.ts +26 -2
- package/desktop/cmp/grid/find/GridFindField.ts +8 -9
- package/desktop/cmp/grid/find/impl/GridFindFieldImplModel.ts +15 -16
- package/desktop/cmp/grid/impl/colchooser/ColChooserBucketModel.ts +1 -1
- package/desktop/cmp/pdfviewer/impl/PdfViewerToolbar.ts +190 -0
- package/desktop/cmp/statcard/impl/StatCardInfoImpl.ts +27 -0
- package/docs/README.md +6 -2
- package/docs/doc-registry.json +21 -5
- package/docs/upgrade-notes/v90-upgrade-notes.md +130 -0
- package/docs/version-compatibility.md +2 -1
- package/dynamics/desktop.ts +4 -0
- package/dynamics/mobile.ts +2 -0
- package/format/FormatNumber.ts +6 -2
- package/icon/Icon.ts +18 -0
- package/icon/index.ts +32 -0
- package/kit/README.md +2 -0
- package/kit/pdfjs/PdfJs.scss +25 -0
- package/kit/pdfjs/index.ts +103 -0
- package/kit/pdfjs/pdf_viewer.css +6481 -0
- package/kit/pdfjs/styles.ts +12 -0
- package/mcp/README.md +13 -0
- package/mcp/data/import-paths.ts +4 -8
- package/mcp/data/index-cache.ts +2 -1
- package/mcp/data/ts-registry.ts +8 -29
- package/mcp/util/paths.ts +26 -0
- package/mobile/appcontainer/AppContainer.ts +3 -1
- package/mobile/cmp/button/grid/ColAutosizeButton.ts +20 -5
- package/mobile/cmp/button/grid/ColChooserButton.ts +12 -5
- package/mobile/cmp/button/grid/ExpandCollapseButton.ts +10 -6
- package/mobile/cmp/button/grid/ExpandToLevelButton.ts +10 -6
- package/mobile/cmp/pdfviewer/impl/PdfViewerToolbar.ts +137 -0
- package/package.json +14 -8
- package/public/msal-redirect-bridge.min.js +1 -1
- package/styles/vars.scss +59 -0
|
@@ -0,0 +1,500 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This file belongs to Hoist, an application development toolkit
|
|
3
|
+
* developed by Extremely Heavy Industries (www.xh.io | info@xh.io)
|
|
4
|
+
*
|
|
5
|
+
* Copyright © 2026 Extremely Heavy Industries Inc.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type {PlainObject} from '@xh/hoist/core';
|
|
9
|
+
import {XH} from '@xh/hoist/core';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Pure combinatorial core of the pivot view: discovers the pivot path tree from a set of records,
|
|
13
|
+
* then plans the `(group node, pivot path)` cells that `PivotCells` materializes as rows.
|
|
14
|
+
*
|
|
15
|
+
* Framework-free and expressed over integer indices rather than objects - allocation-light, and
|
|
16
|
+
* testable in isolation (see `PivotStructure.spec.ts`). Callers map index to row object.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/** Separator between path segments, and between a path key and its measure. */
|
|
20
|
+
export const PATH_DELIMITER = '>>';
|
|
21
|
+
|
|
22
|
+
/** A cell's children are either all cells (group or pivot axis) or all leaf rows. */
|
|
23
|
+
export const CHILD_KIND_CELL = 0;
|
|
24
|
+
export const CHILD_KIND_LEAF = 1;
|
|
25
|
+
|
|
26
|
+
/** Sentinel segment for a null / blank pivot value. Unreachable by escaping a real value. */
|
|
27
|
+
const EMPTY_SEGMENT = '\\e';
|
|
28
|
+
|
|
29
|
+
export interface PivotRecordLike {
|
|
30
|
+
data: PlainObject;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** One node of the pivot path tree; index 0 is always the synthetic root path. */
|
|
34
|
+
export interface PivotPathSpec {
|
|
35
|
+
idx: number;
|
|
36
|
+
/** Index into the query's pivot `dimensions`; -1 for the root. */
|
|
37
|
+
dimIdx: number;
|
|
38
|
+
/** Raw dimension value, null for an empty segment. */
|
|
39
|
+
value: any;
|
|
40
|
+
/** Escaped, delimiter-joined path key; '' for the root. */
|
|
41
|
+
key: string;
|
|
42
|
+
depth: number;
|
|
43
|
+
parentIdx: number;
|
|
44
|
+
childIdxs: number[];
|
|
45
|
+
isEmpty: boolean;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface PivotPathDiscoveryConfig {
|
|
49
|
+
/**
|
|
50
|
+
* Throw a routine exception if the discovered path count exceeds this. Default 100; null
|
|
51
|
+
* to disable.
|
|
52
|
+
*/
|
|
53
|
+
maxPivotPaths?: number;
|
|
54
|
+
|
|
55
|
+
delimiter?: string;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface PivotPathDiscoveryResult {
|
|
59
|
+
/** Path tree in depth-first order, root at index 0. Parents always precede their children. */
|
|
60
|
+
paths: PivotPathSpec[];
|
|
61
|
+
/** Per input record, the index of its full-depth path. 0 (root) when not pivoting. */
|
|
62
|
+
pathIdxOfRecord: Int32Array;
|
|
63
|
+
pathParentIdx: Int32Array;
|
|
64
|
+
pathDepth: Int32Array;
|
|
65
|
+
/** Number of pivot dimensions. */
|
|
66
|
+
maxDepth: number;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface PivotStructureSpec {
|
|
70
|
+
groupCount: number;
|
|
71
|
+
/**
|
|
72
|
+
* Group-axis parent of each group node; -1 for a root. Parents MUST precede their children
|
|
73
|
+
* (`parentOfGroup[g] < g`), which lets the builds run as descending index scans.
|
|
74
|
+
*/
|
|
75
|
+
parentOfGroup: ArrayLike<number>;
|
|
76
|
+
/** 1 where a group's children are leaf rows rather than further groups. */
|
|
77
|
+
innermost: ArrayLike<number>;
|
|
78
|
+
/** Innermost group owning each leaf. */
|
|
79
|
+
leafOwnerGroup: ArrayLike<number>;
|
|
80
|
+
/** Full-depth path index of each leaf. */
|
|
81
|
+
leafPathIdx: ArrayLike<number>;
|
|
82
|
+
pathCount: number;
|
|
83
|
+
pathParentIdx: ArrayLike<number>;
|
|
84
|
+
pathDepth: ArrayLike<number>;
|
|
85
|
+
maxDepth: number;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export interface PivotStructure {
|
|
89
|
+
cellCount: number;
|
|
90
|
+
cellGroup: Int32Array;
|
|
91
|
+
cellPath: Int32Array;
|
|
92
|
+
/** Group-axis parent cell - `C(parent(G), P)`; -1 if none. */
|
|
93
|
+
cellParent: Int32Array;
|
|
94
|
+
/**
|
|
95
|
+
* Pivot-axis parent cell `C(G, parent(P))`; -1 unless G owns leaves and P is at depth 2+. At
|
|
96
|
+
* depth 1 that parent is G itself, already updated by its own children - the two routes stay
|
|
97
|
+
* disjoint, which rules out double counting.
|
|
98
|
+
*/
|
|
99
|
+
cellPivotParent: Int32Array;
|
|
100
|
+
cellChildKind: Uint8Array;
|
|
101
|
+
/** CSR offsets into `childIdx`, length `cellCount + 1`. */
|
|
102
|
+
childStart: Int32Array;
|
|
103
|
+
/** Cell indices or leaf indices, per the owning cell's `cellChildKind`. */
|
|
104
|
+
childIdx: Int32Array;
|
|
105
|
+
/** Per leaf, the cell it feeds - `C(G, fullPath)`; -1 when not pivoting. */
|
|
106
|
+
leafPivotParentCell: Int32Array;
|
|
107
|
+
/** Maps `groupIdx * pathCount + pathIdx` to a cell index. Retained for the reference spec. */
|
|
108
|
+
cellOfKey: Map<number, number>;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Build the global pivot path tree - the union of paths across all records - and stamp each record
|
|
113
|
+
* with its full-depth path index. A null / blank value forms its own segment;
|
|
114
|
+
* `excludeEmptyPivotValues` filters such records out upstream.
|
|
115
|
+
*/
|
|
116
|
+
export function discoverPivotPaths(
|
|
117
|
+
records: ArrayLike<PivotRecordLike>,
|
|
118
|
+
pivotDimNames: string[],
|
|
119
|
+
config: PivotPathDiscoveryConfig = {}
|
|
120
|
+
): PivotPathDiscoveryResult {
|
|
121
|
+
const {maxPivotPaths = 100, delimiter = PATH_DELIMITER} = config,
|
|
122
|
+
maxDepth = pivotDimNames.length;
|
|
123
|
+
|
|
124
|
+
interface Node {
|
|
125
|
+
value: any;
|
|
126
|
+
segKey: string;
|
|
127
|
+
isEmpty: boolean;
|
|
128
|
+
depth: number;
|
|
129
|
+
dimIdx: number;
|
|
130
|
+
children: Map<string, Node>;
|
|
131
|
+
emptyChild: Node;
|
|
132
|
+
idx: number;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const mkNode = (value: any, isEmpty: boolean, depth: number): Node => ({
|
|
136
|
+
value: isEmpty ? null : value,
|
|
137
|
+
segKey: isEmpty ? EMPTY_SEGMENT : escapeSegment(String(value)),
|
|
138
|
+
isEmpty,
|
|
139
|
+
depth,
|
|
140
|
+
dimIdx: depth - 1,
|
|
141
|
+
children: new Map(),
|
|
142
|
+
emptyChild: null,
|
|
143
|
+
idx: -1
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
const root = mkNode(null, false, 0),
|
|
147
|
+
recNodes: Node[] = new Array(records.length);
|
|
148
|
+
|
|
149
|
+
for (let i = 0; i < records.length; i++) {
|
|
150
|
+
const {data} = records[i];
|
|
151
|
+
let node = root;
|
|
152
|
+
for (let d = 0; d < maxDepth; d++) {
|
|
153
|
+
const raw = data[pivotDimNames[d]],
|
|
154
|
+
isEmpty = raw == null || raw === '';
|
|
155
|
+
|
|
156
|
+
if (isEmpty) {
|
|
157
|
+
node = node.emptyChild ??= mkNode(null, true, d + 1);
|
|
158
|
+
} else {
|
|
159
|
+
const mapKey = String(raw);
|
|
160
|
+
let child = node.children.get(mapKey);
|
|
161
|
+
if (!child) node.children.set(mapKey, (child = mkNode(raw, false, d + 1)));
|
|
162
|
+
node = child;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
recNodes[i] = node;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// Enforce the cardinality guard before any cell work, naming the offending dimension.
|
|
169
|
+
if (maxPivotPaths != null) {
|
|
170
|
+
let level = [root],
|
|
171
|
+
cumulative = 0;
|
|
172
|
+
for (let d = 0; d < maxDepth; d++) {
|
|
173
|
+
const next: Node[] = [];
|
|
174
|
+
level.forEach(n => {
|
|
175
|
+
n.children.forEach(c => next.push(c));
|
|
176
|
+
if (n.emptyChild) next.push(n.emptyChild);
|
|
177
|
+
});
|
|
178
|
+
cumulative += next.length;
|
|
179
|
+
if (cumulative > maxPivotPaths) {
|
|
180
|
+
// Routine - the data, not the code, is at fault. A View publishes it on its result.
|
|
181
|
+
throw XH.exception({
|
|
182
|
+
message:
|
|
183
|
+
`Pivot dimension '${pivotDimNames[d]}' produces ${cumulative} pivot paths, ` +
|
|
184
|
+
`exceeding max of ${maxPivotPaths}. Pivot on a lower-cardinality ` +
|
|
185
|
+
`dimension, or raise / disable the limit.`,
|
|
186
|
+
isRoutine: true,
|
|
187
|
+
dimension: pivotDimNames[d],
|
|
188
|
+
pathCount: cumulative,
|
|
189
|
+
maxPivotPaths
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
level = next;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// Assign indices depth-first in sorted order, so parents always precede their children and
|
|
197
|
+
// path order is stable across rebuilds.
|
|
198
|
+
const paths: PivotPathSpec[] = [];
|
|
199
|
+
const assign = (node: Node, parent: PivotPathSpec) => {
|
|
200
|
+
const spec: PivotPathSpec = {
|
|
201
|
+
idx: paths.length,
|
|
202
|
+
dimIdx: node.dimIdx,
|
|
203
|
+
value: node.value,
|
|
204
|
+
key: !parent
|
|
205
|
+
? ''
|
|
206
|
+
: parent.depth === 0
|
|
207
|
+
? node.segKey
|
|
208
|
+
: parent.key + delimiter + node.segKey,
|
|
209
|
+
depth: node.depth,
|
|
210
|
+
parentIdx: parent ? parent.idx : -1,
|
|
211
|
+
childIdxs: [],
|
|
212
|
+
isEmpty: node.isEmpty
|
|
213
|
+
};
|
|
214
|
+
node.idx = spec.idx;
|
|
215
|
+
paths.push(spec);
|
|
216
|
+
parent?.childIdxs.push(spec.idx);
|
|
217
|
+
|
|
218
|
+
const kids = Array.from(node.children.values()).sort((a, b) =>
|
|
219
|
+
compareValues(a.value, b.value)
|
|
220
|
+
);
|
|
221
|
+
if (node.emptyChild) kids.push(node.emptyChild);
|
|
222
|
+
kids.forEach(k => assign(k, spec));
|
|
223
|
+
};
|
|
224
|
+
assign(root, null);
|
|
225
|
+
|
|
226
|
+
const pathIdxOfRecord = new Int32Array(records.length);
|
|
227
|
+
for (let i = 0; i < records.length; i++) pathIdxOfRecord[i] = recNodes[i].idx;
|
|
228
|
+
|
|
229
|
+
const pathParentIdx = new Int32Array(paths.length),
|
|
230
|
+
pathDepth = new Int32Array(paths.length);
|
|
231
|
+
paths.forEach(p => {
|
|
232
|
+
pathParentIdx[p.idx] = p.parentIdx;
|
|
233
|
+
pathDepth[p.idx] = p.depth;
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
return {paths, pathIdxOfRecord, pathParentIdx, pathDepth, maxDepth};
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Synthetic field name a cell's value is written to on its owner row. The root path yields the
|
|
241
|
+
* measure's own name, so row-total columns bind to the plain field.
|
|
242
|
+
*/
|
|
243
|
+
export function pivotCellFieldName(
|
|
244
|
+
pathKey: string,
|
|
245
|
+
measureName: string,
|
|
246
|
+
delimiter: string = PATH_DELIMITER
|
|
247
|
+
): string {
|
|
248
|
+
return pathKey === '' ? measureName : pathKey + delimiter + measureName;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Plan the cell structure: which `(group, path)` cells are populated, each one's children, and how
|
|
253
|
+
* updates route up the group and pivot axes. Every cell's children partition its own leaf set,
|
|
254
|
+
* which keeps every aggregator correct down either axis.
|
|
255
|
+
*/
|
|
256
|
+
export function buildPivotStructure(spec: PivotStructureSpec): PivotStructure {
|
|
257
|
+
const {
|
|
258
|
+
groupCount,
|
|
259
|
+
parentOfGroup,
|
|
260
|
+
innermost,
|
|
261
|
+
leafOwnerGroup,
|
|
262
|
+
leafPathIdx,
|
|
263
|
+
pathCount,
|
|
264
|
+
pathParentIdx,
|
|
265
|
+
pathDepth,
|
|
266
|
+
maxDepth
|
|
267
|
+
} = spec,
|
|
268
|
+
leafCount = leafOwnerGroup.length;
|
|
269
|
+
|
|
270
|
+
// A group must decompose on exactly one axis - mixing leaves and child groups would give a cell
|
|
271
|
+
// two update routes into one parent.
|
|
272
|
+
const hasGroupChild = new Uint8Array(groupCount),
|
|
273
|
+
hasLeafChild = new Uint8Array(groupCount);
|
|
274
|
+
for (let g = 0; g < groupCount; g++) {
|
|
275
|
+
const p = parentOfGroup[g];
|
|
276
|
+
if (p >= g) {
|
|
277
|
+
throw new Error(
|
|
278
|
+
`Pivot group node ${g} has parent ${p}: parents must precede their children.`
|
|
279
|
+
);
|
|
280
|
+
}
|
|
281
|
+
if (p >= 0) hasGroupChild[p] = 1;
|
|
282
|
+
}
|
|
283
|
+
for (let l = 0; l < leafCount; l++) hasLeafChild[leafOwnerGroup[l]] = 1;
|
|
284
|
+
for (let g = 0; g < groupCount; g++) {
|
|
285
|
+
if (hasGroupChild[g] && hasLeafChild[g]) {
|
|
286
|
+
throw new Error(
|
|
287
|
+
`Pivot group node ${g} has both leaf and group children, which the pivot structure ` +
|
|
288
|
+
`cannot decompose. Bucketing within the pivot axis is not supported.`
|
|
289
|
+
);
|
|
290
|
+
}
|
|
291
|
+
if (hasLeafChild[g] && !innermost[g]) {
|
|
292
|
+
throw new Error(`Pivot group node ${g} owns leaves but is not marked innermost.`);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// Populated paths per group: prefixes of each leaf's path, unioned up the group axis as sorted
|
|
297
|
+
// arrays allocated only where non-empty. Descending index order is bottom-up, per the
|
|
298
|
+
// parents-before-children precondition.
|
|
299
|
+
const populated: number[][] = new Array(groupCount);
|
|
300
|
+
for (let l = 0; l < leafCount; l++) {
|
|
301
|
+
const g = leafOwnerGroup[l],
|
|
302
|
+
arr = populated[g] ?? (populated[g] = []);
|
|
303
|
+
for (let p = leafPathIdx[l]; p > 0; p = pathParentIdx[p]) arr.push(p);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
// Normalize up front, so every `mergeSorted` argument is sorted and unique.
|
|
307
|
+
for (let g = 0; g < groupCount; g++) {
|
|
308
|
+
if (populated[g]) sortedUnique(populated[g]);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
for (let g = groupCount - 1; g >= 0; g--) {
|
|
312
|
+
const arr = populated[g];
|
|
313
|
+
if (!arr) continue;
|
|
314
|
+
|
|
315
|
+
const pg = parentOfGroup[g];
|
|
316
|
+
if (pg >= 0) {
|
|
317
|
+
populated[pg] = populated[pg] ? mergeSorted(populated[pg], arr) : arr.slice();
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
// Cells, ordered by (group, path). Path indices are tree-ordered, so a cell always follows the
|
|
322
|
+
// cell for its parent path within the same group.
|
|
323
|
+
const cellGroupArr: number[] = [],
|
|
324
|
+
cellPathArr: number[] = [],
|
|
325
|
+
cellOfKey = new Map<number, number>();
|
|
326
|
+
for (let g = 0; g < groupCount; g++) {
|
|
327
|
+
const paths = populated[g];
|
|
328
|
+
if (!paths) continue;
|
|
329
|
+
for (const p of paths) {
|
|
330
|
+
cellOfKey.set(g * pathCount + p, cellGroupArr.length);
|
|
331
|
+
cellGroupArr.push(g);
|
|
332
|
+
cellPathArr.push(p);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
const cellCount = cellGroupArr.length,
|
|
337
|
+
cellGroup = Int32Array.from(cellGroupArr),
|
|
338
|
+
cellPath = Int32Array.from(cellPathArr),
|
|
339
|
+
cellParent = new Int32Array(cellCount).fill(-1),
|
|
340
|
+
cellPivotParent = new Int32Array(cellCount).fill(-1);
|
|
341
|
+
|
|
342
|
+
for (let c = 0; c < cellCount; c++) {
|
|
343
|
+
const g = cellGroup[c],
|
|
344
|
+
p = cellPath[c],
|
|
345
|
+
pg = parentOfGroup[g];
|
|
346
|
+
if (pg >= 0) cellParent[c] = cellOfKey.get(pg * pathCount + p) ?? -1;
|
|
347
|
+
if (hasLeafChild[g] && pathDepth[p] >= 2) {
|
|
348
|
+
cellPivotParent[c] = cellOfKey.get(g * pathCount + pathParentIdx[p]) ?? -1;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
// CSR child-group and child-path indices, plus leaves bucketed by their full-depth cell.
|
|
353
|
+
const childGroups = csrFromParents(parentOfGroup, groupCount),
|
|
354
|
+
childPaths = csrFromParents(pathParentIdx, pathCount),
|
|
355
|
+
leavesOfKey = new Map<number, number[]>();
|
|
356
|
+
for (let l = 0; l < leafCount; l++) {
|
|
357
|
+
const key = leafOwnerGroup[l] * pathCount + leafPathIdx[l];
|
|
358
|
+
let arr = leavesOfKey.get(key);
|
|
359
|
+
if (!arr) leavesOfKey.set(key, (arr = []));
|
|
360
|
+
arr.push(l);
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
const forEachChild = (c: number, fn: (idx: number) => void): number => {
|
|
364
|
+
const g = cellGroup[c],
|
|
365
|
+
p = cellPath[c];
|
|
366
|
+
|
|
367
|
+
if (!hasLeafChild[g]) {
|
|
368
|
+
for (let i = childGroups.start[g]; i < childGroups.start[g + 1]; i++) {
|
|
369
|
+
const cc = cellOfKey.get(childGroups.idx[i] * pathCount + p);
|
|
370
|
+
if (cc != null) fn(cc);
|
|
371
|
+
}
|
|
372
|
+
return CHILD_KIND_CELL;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
if (pathDepth[p] < maxDepth) {
|
|
376
|
+
for (let i = childPaths.start[p]; i < childPaths.start[p + 1]; i++) {
|
|
377
|
+
const cc = cellOfKey.get(g * pathCount + childPaths.idx[i]);
|
|
378
|
+
if (cc != null) fn(cc);
|
|
379
|
+
}
|
|
380
|
+
return CHILD_KIND_CELL;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
leavesOfKey.get(g * pathCount + p)?.forEach(fn);
|
|
384
|
+
return CHILD_KIND_LEAF;
|
|
385
|
+
};
|
|
386
|
+
|
|
387
|
+
const cellChildKind = new Uint8Array(cellCount),
|
|
388
|
+
childStart = new Int32Array(cellCount + 1);
|
|
389
|
+
for (let c = 0; c < cellCount; c++) {
|
|
390
|
+
let n = 0;
|
|
391
|
+
cellChildKind[c] = forEachChild(c, () => n++);
|
|
392
|
+
childStart[c + 1] = childStart[c] + n;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
const childIdx = new Int32Array(childStart[cellCount]);
|
|
396
|
+
for (let c = 0; c < cellCount; c++) {
|
|
397
|
+
let at = childStart[c];
|
|
398
|
+
forEachChild(c, i => (childIdx[at++] = i));
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
const leafPivotParentCell = new Int32Array(leafCount);
|
|
402
|
+
for (let l = 0; l < leafCount; l++) {
|
|
403
|
+
leafPivotParentCell[l] =
|
|
404
|
+
cellOfKey.get(leafOwnerGroup[l] * pathCount + leafPathIdx[l]) ?? -1;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
return {
|
|
408
|
+
cellCount,
|
|
409
|
+
cellGroup,
|
|
410
|
+
cellPath,
|
|
411
|
+
cellParent,
|
|
412
|
+
cellPivotParent,
|
|
413
|
+
cellChildKind,
|
|
414
|
+
childStart,
|
|
415
|
+
childIdx,
|
|
416
|
+
leafPivotParentCell,
|
|
417
|
+
cellOfKey
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
//------------------------
|
|
422
|
+
// Implementation
|
|
423
|
+
//------------------------
|
|
424
|
+
/** Injective, so distinct values can never produce the same path key. Nothing ever parses these. */
|
|
425
|
+
function escapeSegment(value: string): string {
|
|
426
|
+
return value.replace(/\\/g, '\\\\').replace(/>/g, '\\>');
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
function sortedUnique(values: number[]): number[] {
|
|
430
|
+
values.sort((a, b) => a - b);
|
|
431
|
+
let n = 0;
|
|
432
|
+
for (let i = 0; i < values.length; i++) {
|
|
433
|
+
if (i === 0 || values[i] !== values[i - 1]) values[n++] = values[i];
|
|
434
|
+
}
|
|
435
|
+
values.length = n;
|
|
436
|
+
return values;
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
/** Union of two ascending, duplicate-free arrays. */
|
|
440
|
+
function mergeSorted(a: number[], b: number[]): number[] {
|
|
441
|
+
const ret: number[] = [];
|
|
442
|
+
let i = 0,
|
|
443
|
+
j = 0;
|
|
444
|
+
while (i < a.length && j < b.length) {
|
|
445
|
+
if (a[i] === b[j]) {
|
|
446
|
+
ret.push(a[i++]);
|
|
447
|
+
j++;
|
|
448
|
+
} else if (a[i] < b[j]) {
|
|
449
|
+
ret.push(a[i++]);
|
|
450
|
+
} else {
|
|
451
|
+
ret.push(b[j++]);
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
while (i < a.length) ret.push(a[i++]);
|
|
455
|
+
while (j < b.length) ret.push(b[j++]);
|
|
456
|
+
return ret;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
function csrFromParents(
|
|
460
|
+
parentOf: ArrayLike<number>,
|
|
461
|
+
count: number
|
|
462
|
+
): {start: Int32Array; idx: Int32Array} {
|
|
463
|
+
const start = new Int32Array(count + 1);
|
|
464
|
+
for (let i = 0; i < count; i++) {
|
|
465
|
+
const p = parentOf[i];
|
|
466
|
+
if (p >= 0) start[p + 1]++;
|
|
467
|
+
}
|
|
468
|
+
for (let i = 0; i < count; i++) start[i + 1] += start[i];
|
|
469
|
+
|
|
470
|
+
const fill = start.slice(0, count),
|
|
471
|
+
idx = new Int32Array(start[count]);
|
|
472
|
+
for (let i = 0; i < count; i++) {
|
|
473
|
+
const p = parentOf[i];
|
|
474
|
+
if (p >= 0) idx[fill[p]++] = i;
|
|
475
|
+
}
|
|
476
|
+
return {start, idx};
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
/** Deterministic ascending order, independent of locale. */
|
|
480
|
+
function compareValues(a: any, b: any): number {
|
|
481
|
+
if (a === b) return 0;
|
|
482
|
+
const ta = typeOrder(a),
|
|
483
|
+
tb = typeOrder(b);
|
|
484
|
+
if (ta !== tb) return ta - tb;
|
|
485
|
+
|
|
486
|
+
if (ta === 0) return (a as number) - (b as number);
|
|
487
|
+
if (ta === 1) return (a ? 1 : 0) - (b ? 1 : 0);
|
|
488
|
+
if (ta === 2) return (a as Date).getTime() - (b as Date).getTime();
|
|
489
|
+
|
|
490
|
+
const sa = String(a),
|
|
491
|
+
sb = String(b);
|
|
492
|
+
return sa < sb ? -1 : sa > sb ? 1 : 0;
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
function typeOrder(v: any): number {
|
|
496
|
+
if (typeof v === 'number') return 0;
|
|
497
|
+
if (typeof v === 'boolean') return 1;
|
|
498
|
+
if (v instanceof Date) return 2;
|
|
499
|
+
return 3;
|
|
500
|
+
}
|
package/data/cube/row/BaseRow.ts
CHANGED
|
@@ -12,6 +12,27 @@ import {isArray, isEmpty} from 'lodash';
|
|
|
12
12
|
import type {View} from '../View';
|
|
13
13
|
import type {ViewRow} from '../ViewRow';
|
|
14
14
|
import type {ParentRow} from './ParentRow';
|
|
15
|
+
import type {RowUpdate} from './RowUpdate';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Send updates up both aggregation routes. `applyDataUpdate` rewrites each {@link RowUpdate} in
|
|
19
|
+
* place, so the second route receives clones.
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
22
|
+
export function propagateUpdate(
|
|
23
|
+
parent: ParentRow,
|
|
24
|
+
pivotParent: ParentRow,
|
|
25
|
+
updates: RowUpdate[],
|
|
26
|
+
updatedRows: Set<BaseRow>
|
|
27
|
+
) {
|
|
28
|
+
if (parent && pivotParent) {
|
|
29
|
+
const forPivot = updates.map(u => u.clone());
|
|
30
|
+
parent.applyDataUpdate(updates, updatedRows);
|
|
31
|
+
pivotParent.applyDataUpdate(forPivot, updatedRows);
|
|
32
|
+
} else {
|
|
33
|
+
(parent ?? pivotParent)?.applyDataUpdate(updates, updatedRows);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
15
36
|
|
|
16
37
|
/**
|
|
17
38
|
* Base class for a row within a dataset produced by a Cube / View.
|
|
@@ -39,6 +60,11 @@ export abstract class BaseRow implements ViewRow {
|
|
|
39
60
|
// which adopt their cube record's plain data object - see LeafRow and subclasses.
|
|
40
61
|
data: PlainObject;
|
|
41
62
|
parent: ParentRow = null;
|
|
63
|
+
/**
|
|
64
|
+
* Second aggregation parent, used by pivot views to propagate up the pivot axis. Null in a
|
|
65
|
+
* plain View. The two routes must reach disjoint ancestors - see {@link PivotStructure}.
|
|
66
|
+
*/
|
|
67
|
+
pivotParent: ParentRow = null;
|
|
42
68
|
children: BaseRow[] = null;
|
|
43
69
|
|
|
44
70
|
get isLeaf() {
|
package/data/cube/row/LeafRow.ts
CHANGED
|
@@ -11,7 +11,7 @@ import {isEmpty} from 'lodash';
|
|
|
11
11
|
import type {CubeField} from '../CubeField';
|
|
12
12
|
import type {View} from '../View';
|
|
13
13
|
import type {ViewRowData} from '../ViewRowData';
|
|
14
|
-
import {BaseRow} from './BaseRow';
|
|
14
|
+
import {BaseRow, propagateUpdate} from './BaseRow';
|
|
15
15
|
import {RowUpdate} from './RowUpdate';
|
|
16
16
|
|
|
17
17
|
/**
|
|
@@ -19,8 +19,8 @@ import {RowUpdate} from './RowUpdate';
|
|
|
19
19
|
* {@link LeafRow.applyLeafDataUpdate}.
|
|
20
20
|
*/
|
|
21
21
|
export interface LeafUpdateChanges {
|
|
22
|
-
/**
|
|
23
|
-
rows: Set<
|
|
22
|
+
/** Every row rewritten by the update - leaves and their ancestors alike. */
|
|
23
|
+
rows: Set<BaseRow>;
|
|
24
24
|
/**
|
|
25
25
|
* Names of every field changed by the update. Collected at the leaves only, which suffices
|
|
26
26
|
* because this path runs only with simple aggregators and no derived fields - a parent then
|
|
@@ -87,16 +87,17 @@ export abstract class LeafRow extends BaseRow {
|
|
|
87
87
|
// 2) Apply new values to our data, as per subclass strategy.
|
|
88
88
|
this.applyUpdatedData(updates, newData, changed.rows);
|
|
89
89
|
|
|
90
|
-
// 3) Propagate any updates to ancestors and consumers.
|
|
90
|
+
// 3) Propagate any updates to ancestors and consumers. In a pivot view a leaf has two
|
|
91
|
+
// parents - its innermost group row and its own full-path cell.
|
|
91
92
|
if (!isEmpty(updates)) {
|
|
92
|
-
this.parent
|
|
93
|
+
propagateUpdate(this.parent, this.pivotParent, updates, changed.rows);
|
|
93
94
|
}
|
|
94
95
|
}
|
|
95
96
|
|
|
96
97
|
protected abstract applyUpdatedData(
|
|
97
98
|
updates: RowUpdate[],
|
|
98
99
|
newData: PlainObject,
|
|
99
|
-
|
|
100
|
+
updatedRows: Set<BaseRow>
|
|
100
101
|
): void;
|
|
101
102
|
}
|
|
102
103
|
|
|
@@ -119,10 +120,10 @@ export class ExposedLeafRow extends LeafRow {
|
|
|
119
120
|
protected override applyUpdatedData(
|
|
120
121
|
updates: RowUpdate[],
|
|
121
122
|
newData: PlainObject,
|
|
122
|
-
|
|
123
|
+
updatedRows: Set<BaseRow>
|
|
123
124
|
) {
|
|
124
125
|
this.data._src = newData;
|
|
125
|
-
if (!isEmpty(updates))
|
|
126
|
+
if (!isEmpty(updates)) updatedRows.add(this);
|
|
126
127
|
}
|
|
127
128
|
}
|
|
128
129
|
|