@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,943 @@
|
|
|
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
|
+
import type {
|
|
8
|
+
ColumnGroupShowMode,
|
|
9
|
+
ColumnGroupSpec,
|
|
10
|
+
ColumnSpec,
|
|
11
|
+
ColumnState,
|
|
12
|
+
GridModel
|
|
13
|
+
} from '@xh/hoist/cmp/grid';
|
|
14
|
+
import {ColumnWidthCalculator} from '@xh/hoist/cmp/grid/impl/ColumnWidthCalculator';
|
|
15
|
+
import type {HAlign, HSide, ReactionSpec, Some, VSide} from '@xh/hoist/core';
|
|
16
|
+
import {HoistModel} from '@xh/hoist/core';
|
|
17
|
+
import type {Cube, CubeField, PivotCellField, PivotPath, View} from '@xh/hoist/data';
|
|
18
|
+
import type {GetMainMenuItemsParams} from '@xh/hoist/kit/ag-grid';
|
|
19
|
+
import {action, bindable, bindableRef, observable} from '@xh/hoist/mobx';
|
|
20
|
+
import {throwIf} from '@xh/hoist/utils/js';
|
|
21
|
+
import {
|
|
22
|
+
castArray,
|
|
23
|
+
compact,
|
|
24
|
+
find,
|
|
25
|
+
forEach,
|
|
26
|
+
groupBy,
|
|
27
|
+
isArray,
|
|
28
|
+
isEmpty,
|
|
29
|
+
isFunction,
|
|
30
|
+
isObject,
|
|
31
|
+
isString,
|
|
32
|
+
keyBy,
|
|
33
|
+
map,
|
|
34
|
+
mapValues,
|
|
35
|
+
max,
|
|
36
|
+
omit,
|
|
37
|
+
orderBy,
|
|
38
|
+
sortBy,
|
|
39
|
+
sumBy
|
|
40
|
+
} from 'lodash';
|
|
41
|
+
import type {CubeGridModel} from './CubeGridModel';
|
|
42
|
+
import type {PivotLinkedSizingOptions, PivotDimensionSpec, PivotMeasureSpec} from './Types';
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Configuration for the pivot region of a {@link CubeGridModel}, as `gridConfig` is for its
|
|
46
|
+
* GridModel. Applies when the query sets {@link QueryConfig.pivot}.
|
|
47
|
+
*
|
|
48
|
+
* @see CubeGridPivotModel
|
|
49
|
+
*/
|
|
50
|
+
export interface CubeGridPivotConfig {
|
|
51
|
+
/**
|
|
52
|
+
* The dimensions this grid can pivot on, in the order to offer them, with settings for each
|
|
53
|
+
* over `dimensionDefaults`. A dimension's settings follow it to whatever level the query
|
|
54
|
+
* pivots it at. Entries the query does not pivot on are ignored, and a pivot on a dimension
|
|
55
|
+
* not listed takes the defaults. See {@link CubeGridPivotModel.availableDimensions}.
|
|
56
|
+
*/
|
|
57
|
+
dimensions?: PivotDimensionSpec[];
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Defaults for every pivot dimension, under its own settings in `dimensions` - sort,
|
|
61
|
+
* collapsing, summaries shown while expanded, labels and classes.
|
|
62
|
+
*/
|
|
63
|
+
dimensionDefaults?: Omit<PivotDimensionSpec, 'field'>;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* The measures this grid can pivot, in display order, with settings for each over
|
|
67
|
+
* `measureDefaults` - chiefly the column config applied to every pivot column built for it
|
|
68
|
+
* under every path. Measures the query pivots without an entry follow in query order. See
|
|
69
|
+
* {@link CubeGridPivotModel.availableMeasures}.
|
|
70
|
+
*
|
|
71
|
+
* Pivot columns are not hideable and stay out of the column chooser - the region is the
|
|
72
|
+
* query's, so drop a measure from `pivot.measures` to remove its columns.
|
|
73
|
+
*/
|
|
74
|
+
measures?: PivotMeasureSpec[];
|
|
75
|
+
|
|
76
|
+
/** Defaults for every pivot measure, under its own settings in `measures`. */
|
|
77
|
+
measureDefaults?: Omit<PivotMeasureSpec, 'field'>;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* True to put each measure outermost, with the pivot paths beneath it, to compare one measure
|
|
81
|
+
* across paths. Default false, nesting the measures under each path. Applies only with
|
|
82
|
+
* multiple measures - a single measure is always laid out outermost. Outermost, each measure
|
|
83
|
+
* is a root group that collapses to its own row summary, with no group over the whole region,
|
|
84
|
+
* so the header is one level shallower. Leaf paths head their columns directly, and
|
|
85
|
+
* summaries are single columns, so `showCollapsedLabel` has no effect.
|
|
86
|
+
*/
|
|
87
|
+
measuresOutermost?: boolean;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* True (default) to head the pivot region with a root group, titled by the measure and first
|
|
91
|
+
* pivot dimension, that collapses to the row summary. False to drop it, saving a header row -
|
|
92
|
+
* the top-level path groups head the region directly, with the row summary beside them only
|
|
93
|
+
* if the first dimension's `showSummary` asks for it. Ignored with multiple measures
|
|
94
|
+
* outermost, as their root groups are what name the measures.
|
|
95
|
+
*/
|
|
96
|
+
showRootGroup?: boolean;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* True (default) to link every pivot column of a measure to one width, or options to tune it.
|
|
100
|
+
* The width is the measure's widest data, plus an even share of any room a displayed pivot
|
|
101
|
+
* label needs beyond the data of the columns it spans, up to `headerFitMaxWidth`. It follows
|
|
102
|
+
* as groups expand and collapse, and a manual resize moves all of the measure's columns. False
|
|
103
|
+
* to size each column on its own, as in any grid.
|
|
104
|
+
*/
|
|
105
|
+
linkedSizing?: boolean | PivotLinkedSizingOptions;
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Pivot header level to expand to on initial load, as {@link GridConfig.expandLevel} is for
|
|
109
|
+
* rows. 0 collapses the region to the row summary, 1 shows the top-level pivot groups
|
|
110
|
+
* collapsed to theirs, and so on. Default -1, all levels expanded. Initial state only -
|
|
111
|
+
* thereafter {@link GridModel.columnGroupState} tracks each group, keyed on its path, and
|
|
112
|
+
* persists it with `gridConfig.persistWith`. See {@link CubeGridPivotModel.expandToLevel}.
|
|
113
|
+
*/
|
|
114
|
+
expandLevel?: number;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* The pivot region of a {@link CubeGridModel} - its options, bindable for toolbar controls, and
|
|
119
|
+
* the column groups built from them: their paths, summaries, shared widths and expansion. Created
|
|
120
|
+
* by the CubeGridModel from its `pivotConfig`, which merges the region into its grid's columns.
|
|
121
|
+
*
|
|
122
|
+
* @see CubeGridPivotConfig
|
|
123
|
+
*/
|
|
124
|
+
export class CubeGridPivotModel extends HoistModel {
|
|
125
|
+
/** Pivot header level last expanded to, or -1 for all. Set via {@link expandToLevel}. */
|
|
126
|
+
@observable accessor expandLevel: number;
|
|
127
|
+
|
|
128
|
+
@bindableRef accessor dimensions: PivotDimensionSpec[];
|
|
129
|
+
@bindableRef accessor dimensionDefaults: Omit<PivotDimensionSpec, 'field'>;
|
|
130
|
+
@bindableRef accessor measures: PivotMeasureSpec[];
|
|
131
|
+
@bindableRef accessor measureDefaults: Omit<PivotMeasureSpec, 'field'>;
|
|
132
|
+
@bindable accessor measuresOutermost: boolean;
|
|
133
|
+
@bindable accessor showRootGroup: boolean;
|
|
134
|
+
@bindableRef accessor linkedSizing: boolean | PivotLinkedSizingOptions;
|
|
135
|
+
|
|
136
|
+
private readonly cubeGridModel: CubeGridModel;
|
|
137
|
+
|
|
138
|
+
/** @internal - created by {@link CubeGridModel}. */
|
|
139
|
+
constructor(
|
|
140
|
+
{
|
|
141
|
+
dimensions = [],
|
|
142
|
+
dimensionDefaults = null,
|
|
143
|
+
measures = [],
|
|
144
|
+
measureDefaults = null,
|
|
145
|
+
measuresOutermost = false,
|
|
146
|
+
showRootGroup = true,
|
|
147
|
+
linkedSizing = true,
|
|
148
|
+
expandLevel = -1
|
|
149
|
+
}: CubeGridPivotConfig,
|
|
150
|
+
cubeGridModel: CubeGridModel
|
|
151
|
+
) {
|
|
152
|
+
super();
|
|
153
|
+
this.cubeGridModel = cubeGridModel;
|
|
154
|
+
this.dimensions = dimensions;
|
|
155
|
+
this.dimensionDefaults = dimensionDefaults;
|
|
156
|
+
this.measures = measures;
|
|
157
|
+
this.measureDefaults = measureDefaults;
|
|
158
|
+
this.measuresOutermost = measuresOutermost;
|
|
159
|
+
this.showRootGroup = showRootGroup;
|
|
160
|
+
this.linkedSizing = linkedSizing;
|
|
161
|
+
this.expandLevel = expandLevel;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Expand the pivot column groups to the given level, or all for -1, as
|
|
166
|
+
* {@link GridModel.expandToLevel} does for rows. The region is level 0 and each path group
|
|
167
|
+
* the level of its depth. Later rebuilds mint new groups at this level too.
|
|
168
|
+
*/
|
|
169
|
+
@action
|
|
170
|
+
expandToLevel(level: number) {
|
|
171
|
+
this.expandLevel = level;
|
|
172
|
+
const {gridModel, _groupLevels} = this;
|
|
173
|
+
gridModel.setColumnGroupState(
|
|
174
|
+
gridModel.columnGroupState.map(it =>
|
|
175
|
+
_groupLevels.has(it.groupId)
|
|
176
|
+
? {
|
|
177
|
+
...it,
|
|
178
|
+
expanded: this.isLevelExpanded(_groupLevels.get(it.groupId))
|
|
179
|
+
}
|
|
180
|
+
: it
|
|
181
|
+
)
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
expandAll() {
|
|
186
|
+
this.expandToLevel(-1);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
collapseAll() {
|
|
190
|
+
this.expandToLevel(0);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/** @internal - number of pivot dimensions, or 0 when the region is empty. */
|
|
194
|
+
get maxDepth(): number {
|
|
195
|
+
return isEmpty(this._rootGroups) ? 0 : this.query.pivot.dimensions.length;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* @internal - labels for each level in {@link expandToLevel}, naming the pivot dimension it
|
|
200
|
+
* shows. Level 0 shows none and has no label - {@link collapseAll} reaches it.
|
|
201
|
+
*/
|
|
202
|
+
get resolvedLevelLabels(): string[] {
|
|
203
|
+
if (!this.maxDepth) return null;
|
|
204
|
+
return [null, ...this.query.pivot.dimensions.map(it => it.displayName)];
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/** @internal - true if the level is current, as {@link GridModel.isCurrentExpandLevel}. */
|
|
208
|
+
isCurrentExpandLevel(idx: number): boolean {
|
|
209
|
+
const {expandLevel, maxDepth} = this;
|
|
210
|
+
return expandLevel === idx || (idx === maxDepth && (expandLevel < 0 || expandLevel > idx));
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/** @internal - true if a header menu's column or group lies within the pivot region. */
|
|
214
|
+
isInRegion({column, columnGroup}: GetMainMenuItemsParams): boolean {
|
|
215
|
+
const cols = column ? [column] : (columnGroup?.getLeafColumns() ?? []);
|
|
216
|
+
return cols.some(it => this._colIds.has(it.getColId()));
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Dimensions to offer for pivoting - those listed in `dimensions`, or all of the cube's
|
|
221
|
+
* dimensions if none are.
|
|
222
|
+
*/
|
|
223
|
+
get availableDimensions(): CubeField[] {
|
|
224
|
+
return this.availableFields(this.dimensions, this.cube.dimensions, 'dimension');
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Measures to offer for pivoting - those listed in `measures`, or all of the cube's measures
|
|
229
|
+
* if none are.
|
|
230
|
+
*/
|
|
231
|
+
get availableMeasures(): CubeField[] {
|
|
232
|
+
return this.availableFields(this.measures, this.cube.measures, 'measure');
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/** @internal - options the built region depends on, tracked by the parent's rebuild. */
|
|
236
|
+
get regionDeps(): unknown[] {
|
|
237
|
+
return [
|
|
238
|
+
this.dimensions,
|
|
239
|
+
this.dimensionDefaults,
|
|
240
|
+
this.measures,
|
|
241
|
+
this.measureDefaults,
|
|
242
|
+
this.measuresOutermost,
|
|
243
|
+
this.showRootGroup,
|
|
244
|
+
this.linkedSizing
|
|
245
|
+
];
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/** @internal - leaf colIds of the built region. */
|
|
249
|
+
get colIds(): Set<string> {
|
|
250
|
+
return this._colIds;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/** @internal - the width shared by the column's measure, if one has been applied. */
|
|
254
|
+
widthFor(colId: string): number {
|
|
255
|
+
return this._widths.get(this._measureByColId.get(colId));
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/** @internal - starts syncing widths, once the parent's GridModel exists. */
|
|
259
|
+
initWidths() {
|
|
260
|
+
this.addReaction(this.widthsReaction(), this.sizingReaction());
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/** @internal - builds the pivot region: its root groups, or their children when hidden. */
|
|
264
|
+
buildRegion(): Array<ColumnSpec | ColumnGroupSpec> {
|
|
265
|
+
const {paths, cellFields} = this.view.result;
|
|
266
|
+
|
|
267
|
+
this.indexCellFields(cellFields);
|
|
268
|
+
|
|
269
|
+
// Resolved once per rebuild: each dimension's settings, by level, and each measure's
|
|
270
|
+
// column config, stripped of reserved keys.
|
|
271
|
+
const {dimensions, measures, dimensionDefaults, measureDefaults} = this;
|
|
272
|
+
[...dimensions, ...measures].forEach(it =>
|
|
273
|
+
throwIf(!it.field, 'Each pivot `dimensions` and `measures` entry must name a `field`.')
|
|
274
|
+
);
|
|
275
|
+
this._dimensionSpecs = (this.query.pivot?.dimensions ?? []).map(({name}) => ({
|
|
276
|
+
...DIMENSION_DEFAULTS,
|
|
277
|
+
...dimensionDefaults,
|
|
278
|
+
...find(dimensions, {field: name})
|
|
279
|
+
}));
|
|
280
|
+
this._columnsByMeasure = mapValues(keyBy(measures, 'field'), it =>
|
|
281
|
+
omit({...measureDefaults?.column, ...it.column}, RESERVED_COLUMN_KEYS)
|
|
282
|
+
);
|
|
283
|
+
this._defaultColumn = omit(measureDefaults?.column ?? {}, RESERVED_COLUMN_KEYS);
|
|
284
|
+
|
|
285
|
+
this._colIds = new Set();
|
|
286
|
+
this._groupLevels = new Map();
|
|
287
|
+
this._measureByColId = new Map();
|
|
288
|
+
this._rootGroups = [];
|
|
289
|
+
this._labelWidths = new Map();
|
|
290
|
+
if (!this.query.isPivoted || isEmpty(paths)) return [];
|
|
291
|
+
|
|
292
|
+
// Each root collapses to its row summaries: one group over the whole region, or one per
|
|
293
|
+
// measure. Its header names the first pivot dimension - the level directly beneath it -
|
|
294
|
+
// after the measure when it has one, with every dimension in the tooltip. Both use the
|
|
295
|
+
// fields' short display names, as the header has little room.
|
|
296
|
+
const {_rootPath: rootPath, pivotMeasures} = this,
|
|
297
|
+
dims = this.query.pivot.dimensions.map(it => it.shortDisplayName),
|
|
298
|
+
buildRoot = (fields: CubeField[]) => {
|
|
299
|
+
const measures = fields.map(it => it.shortDisplayName),
|
|
300
|
+
perMeasure = this.isMeasuresOutermost,
|
|
301
|
+
labels = perMeasure ? fields.map(it => this.measureHeader(it)) : [],
|
|
302
|
+
header = perMeasure ? `${measures[0]} by ${dims[0]}` : `By ${dims[0]}`,
|
|
303
|
+
tooltip = `${measures.join(', ')} by ${dims.join(' › ')}`,
|
|
304
|
+
pathCols = this.sortPaths(paths, 0).map(path =>
|
|
305
|
+
this.buildPathColumn(path, labels, [], fields)
|
|
306
|
+
),
|
|
307
|
+
groupId = this.groupIdFor(PIVOT_GROUP_ID, fields);
|
|
308
|
+
|
|
309
|
+
// Hidden, the root is kept only to walk for label widths - no header, no level.
|
|
310
|
+
if (!this.isRootGroupShown) {
|
|
311
|
+
return {
|
|
312
|
+
groupId,
|
|
313
|
+
headerName: null,
|
|
314
|
+
children: this.buildGroupChildren(
|
|
315
|
+
pathCols,
|
|
316
|
+
rootPath,
|
|
317
|
+
labels,
|
|
318
|
+
[],
|
|
319
|
+
fields,
|
|
320
|
+
false
|
|
321
|
+
)
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
return this.buildColGroup(
|
|
326
|
+
groupId,
|
|
327
|
+
header,
|
|
328
|
+
this.buildGroupChildren(pathCols, rootPath, labels, [], fields),
|
|
329
|
+
{level: 0, headerTooltip: tooltip !== header ? tooltip : null}
|
|
330
|
+
);
|
|
331
|
+
};
|
|
332
|
+
|
|
333
|
+
this._rootGroups = this.isMeasuresOutermost
|
|
334
|
+
? pivotMeasures.map(field => buildRoot([field]))
|
|
335
|
+
: [buildRoot(pivotMeasures)];
|
|
336
|
+
this._colIds = new Set(leafColIds(this._rootGroups));
|
|
337
|
+
return this.isRootGroupShown
|
|
338
|
+
? this._rootGroups
|
|
339
|
+
: this._rootGroups.flatMap(it => it.children);
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
//------------------------
|
|
343
|
+
// Implementation
|
|
344
|
+
//------------------------
|
|
345
|
+
|
|
346
|
+
private get view(): View {
|
|
347
|
+
return this.cubeGridModel.view;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
private get cube(): Cube {
|
|
351
|
+
return this.view.cube;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
private availableFields(specs: {field: string}[], all: CubeField[], kind: string): CubeField[] {
|
|
355
|
+
if (isEmpty(specs)) return all;
|
|
356
|
+
const byName = keyBy(all, 'name');
|
|
357
|
+
return specs.map(({field}) => {
|
|
358
|
+
throwIf(!byName[field], `Pivot ${kind} '${field}' is not a ${kind} of the cube.`);
|
|
359
|
+
return byName[field];
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
private get query() {
|
|
364
|
+
return this.view.query;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
private get gridModel(): GridModel {
|
|
368
|
+
return this.cubeGridModel.gridModel;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
private isLevelExpanded(level: number): boolean {
|
|
372
|
+
const {expandLevel} = this;
|
|
373
|
+
return expandLevel < 0 || level < expandLevel;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
// Each path appears once per measure when measures are outermost, so its group ids carry it.
|
|
377
|
+
// A lone measure laid out outermost keeps the nested ids, so its groups' state carries over
|
|
378
|
+
// when a second measure brings the nested layout back.
|
|
379
|
+
private groupIdFor(id: string, fields: CubeField[]): string {
|
|
380
|
+
return this.measuresOutermost ? `${fields[0].name}::${id}` : id;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
private measureHeader(field: CubeField): string {
|
|
384
|
+
const {headerName} = this.measureColumn(field);
|
|
385
|
+
return isString(headerName) ? headerName : field.displayName;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
private measureColumn(field: CubeField): Partial<ColumnSpec> {
|
|
389
|
+
return this._columnsByMeasure[field.name] ?? this._defaultColumn;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
// The settings of the dimension whose summary a group at this level collapses to - the
|
|
393
|
+
// dimension at the level below it. Defaults beyond the innermost dimension.
|
|
394
|
+
private dimensionSpec(level: number): Omit<PivotDimensionSpec, 'field'> {
|
|
395
|
+
return this._dimensionSpecs[level] ?? DIMENSION_DEFAULTS;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
// With one measure there is nothing to nest, and outermost saves the redundant header row.
|
|
399
|
+
private get isMeasuresOutermost(): boolean {
|
|
400
|
+
return this.measuresOutermost || this.pivotMeasures.length === 1;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
// Multiple measures outermost keep their roots, as only those name the measures.
|
|
404
|
+
private get isRootGroupShown(): boolean {
|
|
405
|
+
return this.showRootGroup || (this.measuresOutermost && this.pivotMeasures.length > 1);
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
// Measures in `measures` order, then any the app left unconfigured in query order.
|
|
409
|
+
private get pivotMeasures(): CubeField[] {
|
|
410
|
+
const fields = this.query.pivot?.measures ?? [],
|
|
411
|
+
listed = this.measures.map(it => it.field);
|
|
412
|
+
return sortBy(fields, it => {
|
|
413
|
+
const idx = listed.indexOf(it.name);
|
|
414
|
+
return idx === -1 ? listed.length : idx;
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
private summarySide(level: number): HSide {
|
|
419
|
+
return resolveSide(this.dimensionSpec(level).showSummary, 'left');
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
// A path's value belongs to the dimension at the level above it.
|
|
423
|
+
private pathLabel(path: PivotPath): string {
|
|
424
|
+
const {valueRenderer, emptyLabel} = this.dimensionSpec(path.depth - 1);
|
|
425
|
+
if (path.isEmpty) return emptyLabel;
|
|
426
|
+
return valueRenderer ? valueRenderer(path.value, path) : String(path.value);
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
private pathClass(path: PivotPath): string {
|
|
430
|
+
const {valueClass} = this.dimensionSpec(path.depth - 1);
|
|
431
|
+
return isFunction(valueClass)
|
|
432
|
+
? valueClass(path.isEmpty ? null : path.value, path)
|
|
433
|
+
: valueClass;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
// Keyed on path identity.
|
|
437
|
+
private indexCellFields(cellFields: PivotCellField[]) {
|
|
438
|
+
const byPath = new Map<PivotPath, Map<string, string>>();
|
|
439
|
+
let rootPath: PivotPath = null;
|
|
440
|
+
|
|
441
|
+
cellFields.forEach(({name, path, measure}) => {
|
|
442
|
+
if (path.isRoot) rootPath = path;
|
|
443
|
+
let byField = byPath.get(path);
|
|
444
|
+
if (!byField) byPath.set(path, (byField = new Map()));
|
|
445
|
+
byField.set(measure.name, name);
|
|
446
|
+
});
|
|
447
|
+
|
|
448
|
+
this._cellFieldNames = byPath;
|
|
449
|
+
this._rootPath = rootPath;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
// The tooltip carries the full path, as an ancestor's header is often scrolled out of view.
|
|
453
|
+
// Each value's class goes to every header and cell beneath it.
|
|
454
|
+
private buildPathColumn(
|
|
455
|
+
path: PivotPath,
|
|
456
|
+
ancestorLabels: string[],
|
|
457
|
+
ancestorClasses: string[],
|
|
458
|
+
fields: CubeField[]
|
|
459
|
+
): ColumnSpec | ColumnGroupSpec {
|
|
460
|
+
const label = this.pathLabel(path),
|
|
461
|
+
labels = [...ancestorLabels, label],
|
|
462
|
+
classes = compact([...ancestorClasses, this.pathClass(path)]),
|
|
463
|
+
headerTooltip = labels.join(' › ');
|
|
464
|
+
|
|
465
|
+
if (isEmpty(path.children)) {
|
|
466
|
+
// With measures outermost the measure heads the root, so a leaf path heads its own column.
|
|
467
|
+
if (this.isMeasuresOutermost) {
|
|
468
|
+
return {
|
|
469
|
+
...this.buildValueColumn(path, fields[0], ancestorLabels, classes, label),
|
|
470
|
+
headerTooltip
|
|
471
|
+
};
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
// Otherwise always a group, so the measure name stays visible beside any fixed columns.
|
|
475
|
+
return this.buildColGroup(
|
|
476
|
+
path.key,
|
|
477
|
+
label,
|
|
478
|
+
this.buildValueColumns(path, labels, classes, fields),
|
|
479
|
+
{level: path.depth, headerAlign: 'center', headerTooltip, headerClass: classes}
|
|
480
|
+
);
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
const childCols = this.sortPaths(path.children, path.depth).map(child =>
|
|
484
|
+
this.buildPathColumn(child, labels, classes, fields)
|
|
485
|
+
);
|
|
486
|
+
return this.buildColGroup(
|
|
487
|
+
this.groupIdFor(path.key, fields),
|
|
488
|
+
label,
|
|
489
|
+
this.buildGroupChildren(childCols, path, labels, classes, fields),
|
|
490
|
+
{level: path.depth, headerTooltip, headerClass: classes}
|
|
491
|
+
);
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
// Children of a group that collapses to its summary. The path groups show expanded. The
|
|
495
|
+
// summary sits under a summary header, always when asked and otherwise only while collapsed.
|
|
496
|
+
// Without that header on collapse, a second copy of the summary shows while collapsed, under
|
|
497
|
+
// colIds of its own, as AG Grid reuses a column's prior group when it moves out of one. AG
|
|
498
|
+
// Grid pads the copy, so the header depth stays fixed. With collapsing off there is only the
|
|
499
|
+
// summary group, only when asked. With measures outermost the summary is one column, under
|
|
500
|
+
// colIds of its own for the same reason.
|
|
501
|
+
private buildGroupChildren(
|
|
502
|
+
pathCols: Array<ColumnSpec | ColumnGroupSpec>,
|
|
503
|
+
summaryPath: PivotPath,
|
|
504
|
+
labels: string[],
|
|
505
|
+
classes: string[],
|
|
506
|
+
fields: CubeField[],
|
|
507
|
+
collapsible = this.dimensionSpec(summaryPath.depth).collapsible
|
|
508
|
+
): Array<ColumnSpec | ColumnGroupSpec> {
|
|
509
|
+
const {summaryLabel, showCollapsedLabel, summaryClass} = this.dimensionSpec(
|
|
510
|
+
summaryPath.depth
|
|
511
|
+
),
|
|
512
|
+
summarySide = this.summarySide(summaryPath.depth);
|
|
513
|
+
if (!summarySide && !collapsible) return pathCols;
|
|
514
|
+
|
|
515
|
+
const children = collapsible
|
|
516
|
+
? pathCols.map(it => ({...it, groupShowMode: 'expanded' as const}))
|
|
517
|
+
: pathCols;
|
|
518
|
+
|
|
519
|
+
if (this.isMeasuresOutermost) {
|
|
520
|
+
const [col] = this.buildSummaryColumns(
|
|
521
|
+
summaryPath,
|
|
522
|
+
labels,
|
|
523
|
+
classes,
|
|
524
|
+
fields,
|
|
525
|
+
MEASURE_SUMMARY_PREFIX
|
|
526
|
+
),
|
|
527
|
+
summary = {...col, groupShowMode: summarySide ? null : ('collapsed' as const)};
|
|
528
|
+
return summarySide === 'left' ? [summary, ...children] : [...children, summary];
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
const isBare = collapsible && !showCollapsedLabel,
|
|
532
|
+
summary: Array<ColumnSpec | ColumnGroupSpec> = isBare
|
|
533
|
+
? this.buildSummaryColumns(
|
|
534
|
+
summaryPath,
|
|
535
|
+
labels,
|
|
536
|
+
classes,
|
|
537
|
+
fields,
|
|
538
|
+
BARE_SUMMARY_PREFIX
|
|
539
|
+
).map(it => ({
|
|
540
|
+
...it,
|
|
541
|
+
groupShowMode: 'collapsed' as const,
|
|
542
|
+
excludeFromExport: !!summarySide
|
|
543
|
+
}))
|
|
544
|
+
: [];
|
|
545
|
+
|
|
546
|
+
if (summarySide || !isBare) {
|
|
547
|
+
summary.push(
|
|
548
|
+
this.buildColGroup(
|
|
549
|
+
`${summaryPath.isRoot ? PIVOT_GROUP_ID : summaryPath.key}:summary`,
|
|
550
|
+
summaryLabel,
|
|
551
|
+
this.buildSummaryColumns(summaryPath, labels, classes, fields, SUMMARY_PREFIX),
|
|
552
|
+
{
|
|
553
|
+
headerAlign: 'center',
|
|
554
|
+
groupShowMode: summarySide ? (isBare ? 'expanded' : null) : 'collapsed',
|
|
555
|
+
headerClass: [SUMMARY_HEADER_CLASS, summaryClass, ...classes]
|
|
556
|
+
}
|
|
557
|
+
)
|
|
558
|
+
);
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
return summarySide === 'left' ? [...summary, ...children] : [...children, ...summary];
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
// Row summaries are the pivot summaries at the root path - the same cells at different depths.
|
|
565
|
+
// A summary column binds the path's own cell but takes a colId of its own, so the root summary
|
|
566
|
+
// never collides with a fixed column bound to the same measure. All carry the summary classes,
|
|
567
|
+
// then the dimension's, then any the app adds.
|
|
568
|
+
// With measures outermost a summary is a lone column, headed by its label.
|
|
569
|
+
private buildSummaryColumns(
|
|
570
|
+
path: PivotPath,
|
|
571
|
+
labels: string[],
|
|
572
|
+
classes: string[],
|
|
573
|
+
fields: CubeField[],
|
|
574
|
+
prefix: string
|
|
575
|
+
): ColumnSpec[] {
|
|
576
|
+
const {summaryLabel, summaryClass} = this.dimensionSpec(path.depth),
|
|
577
|
+
cols = this.isMeasuresOutermost
|
|
578
|
+
? fields.map(field =>
|
|
579
|
+
this.buildValueColumn(path, field, labels, classes, summaryLabel)
|
|
580
|
+
)
|
|
581
|
+
: this.buildValueColumns(path, [...labels, summaryLabel], classes, fields);
|
|
582
|
+
return cols.map(col => ({
|
|
583
|
+
...col,
|
|
584
|
+
colId: this.noteMeasure(`${prefix}${col.colId}`, this._measureByColId.get(col.colId)),
|
|
585
|
+
cellClass: withClasses(col.cellClass, [SUMMARY_CELL_CLASS, summaryClass]),
|
|
586
|
+
headerClass: withClasses(col.headerClass, [SUMMARY_HEADER_CLASS, summaryClass])
|
|
587
|
+
}));
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
private buildValueColumns(
|
|
591
|
+
path: PivotPath,
|
|
592
|
+
labels: string[],
|
|
593
|
+
classes: string[],
|
|
594
|
+
fields: CubeField[]
|
|
595
|
+
): ColumnSpec[] {
|
|
596
|
+
return fields.map(field => this.buildValueColumn(path, field, labels, classes));
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
// The pivot region is the query's: these columns never move, hide or filter, and the chooser
|
|
600
|
+
// does not list them. A cell is an aggregate, so no query filter can express a condition on
|
|
601
|
+
// it. Field names are built from data values that may contain dots. The export header is the
|
|
602
|
+
// path's labels and the column's header, as the header alone repeats across paths. A
|
|
603
|
+
// `headerName` given here is a pivot label, replacing the spec's. While widths are shared it
|
|
604
|
+
// is fitted as group labels are, not by autosize. Without either, the header is the measure's
|
|
605
|
+
// short name and the export its full one. The value classes go before the measure's.
|
|
606
|
+
private buildValueColumn(
|
|
607
|
+
path: PivotPath,
|
|
608
|
+
field: CubeField,
|
|
609
|
+
labels: string[],
|
|
610
|
+
classes: string[],
|
|
611
|
+
headerName?: string
|
|
612
|
+
): ColumnSpec {
|
|
613
|
+
const name = this.cellFieldName(path, field),
|
|
614
|
+
spec = this.measureColumn(field),
|
|
615
|
+
isShortName = !headerName && spec.headerName === undefined;
|
|
616
|
+
return {
|
|
617
|
+
...(headerName && this.linkedSizing ? {autosizeIncludeHeader: false} : null),
|
|
618
|
+
...spec,
|
|
619
|
+
headerName: isShortName ? field.shortDisplayName : headerName || spec.headerName,
|
|
620
|
+
...(isEmpty(classes)
|
|
621
|
+
? null
|
|
622
|
+
: {
|
|
623
|
+
cellClass: withClasses(spec.cellClass, classes),
|
|
624
|
+
headerClass: withClasses(spec.headerClass, classes)
|
|
625
|
+
}),
|
|
626
|
+
colId: this.noteMeasure(name, field.name),
|
|
627
|
+
field: name,
|
|
628
|
+
movable: false,
|
|
629
|
+
hideable: false,
|
|
630
|
+
filterable: false,
|
|
631
|
+
excludeFromChooser: true,
|
|
632
|
+
enableDotSeparatedFieldPath: false,
|
|
633
|
+
exportName: ({column, gridModel}) => {
|
|
634
|
+
const {headerName} = column,
|
|
635
|
+
header = isFunction(headerName)
|
|
636
|
+
? headerName({column, gridModel, agParams: null})
|
|
637
|
+
: headerName;
|
|
638
|
+
return [
|
|
639
|
+
...labels,
|
|
640
|
+
!isShortName && isString(header) ? header : field.displayName
|
|
641
|
+
].join(' › ');
|
|
642
|
+
},
|
|
643
|
+
// Keeps the pivot block trailing: a fixed column cannot be dropped inside it.
|
|
644
|
+
agOptions: {lockPosition: 'right'}
|
|
645
|
+
};
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
// A group with a `level` is a pivot group that expands and collapses. Wide groups are
|
|
649
|
+
// left-aligned, as a centered label on one sits out of the viewport.
|
|
650
|
+
private buildColGroup(
|
|
651
|
+
groupId: string,
|
|
652
|
+
headerName: string,
|
|
653
|
+
children: Array<ColumnSpec | ColumnGroupSpec>,
|
|
654
|
+
{
|
|
655
|
+
level,
|
|
656
|
+
headerAlign = 'left',
|
|
657
|
+
groupShowMode,
|
|
658
|
+
headerTooltip,
|
|
659
|
+
headerClass
|
|
660
|
+
}: {
|
|
661
|
+
level?: number;
|
|
662
|
+
headerAlign?: HAlign;
|
|
663
|
+
groupShowMode?: ColumnGroupShowMode;
|
|
664
|
+
headerTooltip?: string;
|
|
665
|
+
headerClass?: string[];
|
|
666
|
+
}
|
|
667
|
+
): ColumnGroupSpec {
|
|
668
|
+
const isPivotLevel = level != null,
|
|
669
|
+
classes = compact(headerClass);
|
|
670
|
+
if (isPivotLevel) this._groupLevels.set(groupId, level);
|
|
671
|
+
return {
|
|
672
|
+
headerName,
|
|
673
|
+
headerAlign,
|
|
674
|
+
headerTooltip,
|
|
675
|
+
...(isEmpty(classes) ? null : {headerClass: classes}),
|
|
676
|
+
groupId,
|
|
677
|
+
children,
|
|
678
|
+
groupShowMode,
|
|
679
|
+
collapsed:
|
|
680
|
+
isPivotLevel &&
|
|
681
|
+
this.dimensionSpec(level).collapsible &&
|
|
682
|
+
!this.isLevelExpanded(level)
|
|
683
|
+
};
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
//------------------------
|
|
687
|
+
// Pivot column widths
|
|
688
|
+
//------------------------
|
|
689
|
+
private noteMeasure(colId: string, measure: string): string {
|
|
690
|
+
this._measureByColId.set(colId, measure);
|
|
691
|
+
return colId;
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
private widthsReaction(): ReactionSpec {
|
|
695
|
+
return {
|
|
696
|
+
equals: 'shallow',
|
|
697
|
+
track: () => [
|
|
698
|
+
this.gridModel.columnState,
|
|
699
|
+
this.gridModel.columnGroupState,
|
|
700
|
+
this.gridModel.sizingMode,
|
|
701
|
+
this.linkedSizing
|
|
702
|
+
],
|
|
703
|
+
run: () => this.syncPivotWidths()
|
|
704
|
+
};
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
// A new sizing needs fresh data widths - turned off, each column's own - as does a new layout,
|
|
708
|
+
// which changes the cell columns' headers.
|
|
709
|
+
private sizingReaction(): ReactionSpec {
|
|
710
|
+
return {
|
|
711
|
+
track: () => [this.linkedSizing, this.isMeasuresOutermost],
|
|
712
|
+
equals: 'structural',
|
|
713
|
+
run: () => {
|
|
714
|
+
const {gridModel} = this;
|
|
715
|
+
if (gridModel.autosizeOptions.mode === 'managed') gridModel.autosizeAsync();
|
|
716
|
+
}
|
|
717
|
+
};
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
// Every pivot column of a measure shares one width - see `linkedSizing`. An autosize
|
|
721
|
+
// sizes each column to its data, and the measure takes the widest, plus any padding the
|
|
722
|
+
// displayed group labels need. Any other change from the width last applied is a user's
|
|
723
|
+
// resize, which the measure's other columns follow, as is, until the next autosize.
|
|
724
|
+
@action
|
|
725
|
+
private syncPivotWidths() {
|
|
726
|
+
const {gridModel, _colIds, _measureByColId, _widths, _dataWidths, _manualWidths} = this,
|
|
727
|
+
isAutosize = gridModel.autosizeTask.isPending,
|
|
728
|
+
colsByMeasure = groupBy(
|
|
729
|
+
gridModel.columnState.filter(it => _colIds.has(it.colId)),
|
|
730
|
+
it => _measureByColId.get(it.colId)
|
|
731
|
+
);
|
|
732
|
+
|
|
733
|
+
// Off, columns size on their own. Applied widths are dropped, so turning it on again
|
|
734
|
+
// takes the columns as they are.
|
|
735
|
+
if (!this.linkedSizing) {
|
|
736
|
+
_widths.clear();
|
|
737
|
+
return;
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
if (isAutosize) _manualWidths.clear();
|
|
741
|
+
forEach(colsByMeasure, (cols, measure) => {
|
|
742
|
+
const applied = _widths.get(measure),
|
|
743
|
+
changed = cols.find(it => it.width != null && it.width !== applied);
|
|
744
|
+
if (!changed) return;
|
|
745
|
+
|
|
746
|
+
if (applied != null && !isAutosize) {
|
|
747
|
+
_manualWidths.set(measure, changed.width);
|
|
748
|
+
} else {
|
|
749
|
+
_dataWidths.set(measure, max(map(cols, 'width')));
|
|
750
|
+
}
|
|
751
|
+
});
|
|
752
|
+
|
|
753
|
+
const padding = this.calcLabelPadding(),
|
|
754
|
+
changes: Array<Partial<ColumnState>> = [];
|
|
755
|
+
forEach(colsByMeasure, (cols, measure) => {
|
|
756
|
+
const width =
|
|
757
|
+
_manualWidths.get(measure) ??
|
|
758
|
+
_dataWidths.get(measure) + (padding.get(measure) ?? 0);
|
|
759
|
+
_widths.set(measure, width);
|
|
760
|
+
cols.forEach(({colId, width: w}) => {
|
|
761
|
+
if (w !== width) changes.push({colId, width});
|
|
762
|
+
});
|
|
763
|
+
});
|
|
764
|
+
|
|
765
|
+
gridModel.updateColumnState(changes);
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
// Width to add to each measure's columns for the displayed pivot labels to fit, each claiming
|
|
769
|
+
// up to `headerFitMaxWidth`. A label short of the columns it spans shares the shortfall evenly
|
|
770
|
+
// among them, and only the measures it spans take its share.
|
|
771
|
+
private calcLabelPadding(): Map<string, number> {
|
|
772
|
+
const {_rootGroups, _measureByColId, _manualWidths, _dataWidths} = this,
|
|
773
|
+
{linkedSizing} = this,
|
|
774
|
+
maxWidth = (isObject(linkedSizing) ? linkedSizing.headerFitMaxWidth : null) ?? 140,
|
|
775
|
+
ret = new Map<string, number>();
|
|
776
|
+
if (!maxWidth) return ret;
|
|
777
|
+
|
|
778
|
+
const {bufferPx} = this.gridModel.autosizeOptions,
|
|
779
|
+
baseWidth = (colId: string) => {
|
|
780
|
+
const measure = _measureByColId.get(colId);
|
|
781
|
+
return _manualWidths.get(measure) ?? _dataWidths.get(measure) ?? 0;
|
|
782
|
+
};
|
|
783
|
+
|
|
784
|
+
_rootGroups.forEach(root =>
|
|
785
|
+
this.forEachDisplayedGroup(root, (label, colIds, isExpandable) => {
|
|
786
|
+
const width = Math.min(this.measureLabel(label, isExpandable) + bufferPx, maxWidth),
|
|
787
|
+
share = Math.ceil((width - sumBy(colIds, baseWidth)) / colIds.length);
|
|
788
|
+
colIds.forEach(colId => {
|
|
789
|
+
const measure = _measureByColId.get(colId);
|
|
790
|
+
ret.set(measure, Math.max(ret.get(measure) ?? 0, share));
|
|
791
|
+
});
|
|
792
|
+
})
|
|
793
|
+
);
|
|
794
|
+
return ret;
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
// Calls fn with each displayed pivot label, the columns it spans and whether it shows an
|
|
798
|
+
// expand icon, and returns the columns `group` spans.
|
|
799
|
+
private forEachDisplayedGroup(
|
|
800
|
+
group: ColumnGroupSpec,
|
|
801
|
+
fn: (label: string, colIds: string[], isExpandable: boolean) => void
|
|
802
|
+
): string[] {
|
|
803
|
+
const hiddenMode = this.gridModel.isColumnGroupExpanded(group.groupId)
|
|
804
|
+
? 'collapsed'
|
|
805
|
+
: 'expanded';
|
|
806
|
+
|
|
807
|
+
const ret: string[] = [];
|
|
808
|
+
let isExpandable = false;
|
|
809
|
+
group.children.forEach(child => {
|
|
810
|
+
if (child.groupShowMode) isExpandable = true;
|
|
811
|
+
if (child.groupShowMode === hiddenMode) return;
|
|
812
|
+
if ('children' in child) {
|
|
813
|
+
ret.push(...this.forEachDisplayedGroup(child, fn));
|
|
814
|
+
} else {
|
|
815
|
+
ret.push(child.colId);
|
|
816
|
+
// With measures outermost, a column's own header is a pivot label too.
|
|
817
|
+
if (this.isMeasuresOutermost && isString(child.headerName)) {
|
|
818
|
+
fn(child.headerName, [child.colId], false);
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
});
|
|
822
|
+
if (isString(group.headerName) && !isEmpty(ret)) fn(group.headerName, ret, isExpandable);
|
|
823
|
+
return ret;
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
private measureLabel(label: string, isExpandable: boolean): number {
|
|
827
|
+
const {sizingMode} = this.gridModel,
|
|
828
|
+
key = `${sizingMode}|${isExpandable}|${label}`;
|
|
829
|
+
let ret = this._labelWidths.get(key);
|
|
830
|
+
if (ret == null) {
|
|
831
|
+
ret = headerMeasurer.calcHeaderTextWidth(sizingMode, label, isExpandable);
|
|
832
|
+
this._labelWidths.set(key, ret);
|
|
833
|
+
}
|
|
834
|
+
return ret;
|
|
835
|
+
}
|
|
836
|
+
|
|
837
|
+
// Display only - `result.paths` is immutable.
|
|
838
|
+
// Paths at a depth are the values of the dimension at that level.
|
|
839
|
+
private sortPaths(paths: PivotPath[], depth: number): PivotPath[] {
|
|
840
|
+
const spec = this.dimensionSpec(depth).sortBy;
|
|
841
|
+
|
|
842
|
+
if (spec === 'asc' || spec === 'desc') return orderBy(paths, 'value', spec);
|
|
843
|
+
|
|
844
|
+
if (isFunction(spec)) return [...paths].sort(spec);
|
|
845
|
+
|
|
846
|
+
if (isArray(spec)) {
|
|
847
|
+
// One shared key for the unlisted, so the stable sort leaves them in view order.
|
|
848
|
+
return sortBy(paths, it => {
|
|
849
|
+
const idx = spec.indexOf(it.value);
|
|
850
|
+
return idx === -1 ? spec.length : idx;
|
|
851
|
+
});
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
return paths;
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
// Falls back to the measure's own name, which is exactly the root-path cell field.
|
|
858
|
+
private cellFieldName(path: PivotPath, field: CubeField): string {
|
|
859
|
+
return this._cellFieldNames.get(path)?.get(field.name) ?? field.name;
|
|
860
|
+
}
|
|
861
|
+
|
|
862
|
+
private _cellFieldNames: Map<PivotPath, Map<string, string>> = new Map();
|
|
863
|
+
private _rootPath: PivotPath = null;
|
|
864
|
+
private _dimensionSpecs: Omit<PivotDimensionSpec, 'field'>[] = [];
|
|
865
|
+
private _columnsByMeasure: Record<string, Partial<ColumnSpec>> = {};
|
|
866
|
+
private _defaultColumn: Partial<ColumnSpec> = {};
|
|
867
|
+
private _colIds: Set<string> = new Set();
|
|
868
|
+
private _groupLevels: Map<string, number> = new Map();
|
|
869
|
+
private _rootGroups: ColumnGroupSpec[] = [];
|
|
870
|
+
private _measureByColId: Map<string, string> = new Map();
|
|
871
|
+
private _widths: Map<string, number> = new Map();
|
|
872
|
+
private _dataWidths: Map<string, number> = new Map();
|
|
873
|
+
private _manualWidths: Map<string, number> = new Map();
|
|
874
|
+
private _labelWidths: Map<string, number> = new Map();
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
/**
|
|
878
|
+
* Group id of the column group spanning the pivot region. Its summary group is `pivot:summary`. With
|
|
879
|
+
* `measuresOutermost` there is no such group - each measure's root is `{field}::pivot`.
|
|
880
|
+
*/
|
|
881
|
+
export const PIVOT_GROUP_ID = 'pivot';
|
|
882
|
+
|
|
883
|
+
// ColumnSpec keys the grid sets on every pivot column, stripped from a measure's `column`.
|
|
884
|
+
// Identity and the export header come from the path, and the rest are this model's own.
|
|
885
|
+
const RESERVED_COLUMN_KEYS = [
|
|
886
|
+
'colId',
|
|
887
|
+
'isTreeColumn',
|
|
888
|
+
'hidden',
|
|
889
|
+
'hideable',
|
|
890
|
+
'filterable',
|
|
891
|
+
'excludeFromChooser',
|
|
892
|
+
'exportName',
|
|
893
|
+
'enableDotSeparatedFieldPath',
|
|
894
|
+
'omit',
|
|
895
|
+
'pinned',
|
|
896
|
+
'editable',
|
|
897
|
+
'editor',
|
|
898
|
+
'setValueFn',
|
|
899
|
+
'getValueFn',
|
|
900
|
+
'sortValue',
|
|
901
|
+
'agOptions'
|
|
902
|
+
] as const;
|
|
903
|
+
|
|
904
|
+
const SUMMARY_CELL_CLASS = 'xh-cube-grid__summary-cell',
|
|
905
|
+
SUMMARY_HEADER_CLASS = 'xh-cube-grid__summary-header';
|
|
906
|
+
|
|
907
|
+
// colId prefixes of the summary columns: under a summary header, bare while collapsed, and as the
|
|
908
|
+
// lone summary columns with measures outermost.
|
|
909
|
+
const SUMMARY_PREFIX = 'summary>>',
|
|
910
|
+
BARE_SUMMARY_PREFIX = 'collapsed>>',
|
|
911
|
+
MEASURE_SUMMARY_PREFIX = 'measureSummary>>';
|
|
912
|
+
|
|
913
|
+
const DIMENSION_DEFAULTS: Omit<PivotDimensionSpec, 'field'> = {
|
|
914
|
+
sortBy: null,
|
|
915
|
+
collapsible: true,
|
|
916
|
+
showSummary: false,
|
|
917
|
+
summaryLabel: 'Total',
|
|
918
|
+
showCollapsedLabel: true,
|
|
919
|
+
emptyLabel: '(empty)'
|
|
920
|
+
};
|
|
921
|
+
|
|
922
|
+
// Prepends classes to a class spec, wrapping a class function.
|
|
923
|
+
function withClasses<T extends (...args: any[]) => Some<string>>(
|
|
924
|
+
spec: T | Some<string>,
|
|
925
|
+
classes: string[]
|
|
926
|
+
): T | string[] {
|
|
927
|
+
const pre = compact(classes);
|
|
928
|
+
return isFunction(spec)
|
|
929
|
+
? (((...args) => [...pre, ...castArray(spec(...args) ?? [])]) as T)
|
|
930
|
+
: [...pre, ...castArray(spec ?? [])];
|
|
931
|
+
}
|
|
932
|
+
|
|
933
|
+
// Shared across grids - it holds a hidden header element for measuring.
|
|
934
|
+
const headerMeasurer = new ColumnWidthCalculator();
|
|
935
|
+
|
|
936
|
+
function leafColIds(cols: Array<ColumnSpec | ColumnGroupSpec>): string[] {
|
|
937
|
+
return cols.flatMap(it => ('children' in it ? leafColIds(it.children) : it.colId));
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
function resolveSide<T extends HSide | VSide>(val: boolean | T, dflt: T): T {
|
|
941
|
+
if (val === true) return dflt;
|
|
942
|
+
return val === false ? null : val;
|
|
943
|
+
}
|