@univerjs-pro/engine-pivot 0.25.0 → 1.0.0-alpha.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.
@@ -1,9 +1,43 @@
1
1
  import type { PivotTable } from '../pivot/pivot-table';
2
+ import type { NodeTree } from '../summary/node-tree';
2
3
  import type { SummaryManager } from '../summary/summary-manager';
3
- import type { IPivotLayoutCtx, IPivotTableQueryData } from '../types';
4
+ import type { IPivotLayoutCtx, IPivotTableQueryData, IPivotViewInfo, IPivotViewValueType } from '../types';
4
5
  import type { PivotView } from './pivot-view';
5
- import { BaseLayout } from './base-layout';
6
- export declare class CompactLayout extends BaseLayout {
7
- static layout(pivotTable: PivotTable, SummaryManager: SummaryManager, queryData: IPivotTableQueryData): PivotView;
8
- static layoutRow(ctx: IPivotLayoutCtx): void;
6
+ import { TabularLayout } from './tabular';
7
+ export declare class CompactLayout extends TabularLayout {
8
+ static layout(pivotTable: PivotTable, summaryManager: SummaryManager, queryData: IPivotTableQueryData): PivotView;
9
+ static layoutRowFields(ctx: IPivotLayoutCtx): void;
10
+ static shouldSplitRootByValues(ctx: IPivotLayoutCtx): boolean;
11
+ static layoutRowChildren(ctx: IPivotLayoutCtx, nodeTree: NodeTree, row: number, valueIds: string[]): number;
12
+ static layoutRowNode(ctx: IPivotLayoutCtx, nodeTree: NodeTree, row: number, valueIds: string[]): {
13
+ itemSize: number;
14
+ topTotalSize: number;
15
+ bottomTotalSize: number;
16
+ };
17
+ static layoutRowNodeToCursor(ctx: IPivotLayoutCtx, nodeTree: NodeTree, row: number, valueIds: string[]): number;
18
+ static shouldWriteSubtotalAtBottom(ctx: IPivotLayoutCtx): boolean;
19
+ static shouldWriteMultiValueSubtotalAtBottom(ctx: IPivotLayoutCtx, nodeTree: NodeTree): boolean;
20
+ static writeParentItemRow(ctx: IPivotLayoutCtx, nodeTree: NodeTree, row: number): number;
21
+ static writeValueHeaderRow(ctx: IPivotLayoutCtx, nodeTree: NodeTree, row: number, valueId: string): number;
22
+ static writeRootValueHeaderRow(ctx: IPivotLayoutCtx, row: number, valueId: string): number;
23
+ static writeParentRows(ctx: IPivotLayoutCtx, nodeTree: NodeTree, row: number, valueIds: string[]): number;
24
+ static writeParentRow(ctx: IPivotLayoutCtx, nodeTree: NodeTree, row: number, valueIndex: number, valueLabel?: string): void;
25
+ static writeBottomSubtotalRows(ctx: IPivotLayoutCtx, nodeTree: NodeTree, row: number, valueIds: string[]): number;
26
+ static writeBottomSubtotalRow(ctx: IPivotLayoutCtx, nodeTree: NodeTree, row: number, valueIndex: number, valueLabel?: string): void;
27
+ static writeLeafRows(ctx: IPivotLayoutCtx, nodeTree: NodeTree, row: number, valueIds: string[]): number;
28
+ static shouldWriteLeafValuesUnderItem(ctx: IPivotLayoutCtx): boolean;
29
+ static writeLeafItemRow(ctx: IPivotLayoutCtx, nodeTree: NodeTree, row: number): number;
30
+ static writeLeafValueRow(ctx: IPivotLayoutCtx, nodeTree: NodeTree, row: number, valueIndex: number, valueLabel: string): void;
31
+ static writeGrandTotalRows(ctx: IPivotLayoutCtx, nodeTree: NodeTree, row: number, valueIds: string[]): number;
32
+ static layoutGrandTotalValues(ctx: IPivotLayoutCtx, nodeTree: NodeTree, row: number, measureIndex: number): void;
33
+ static createRowInfo(nodeTree: NodeTree, extra: Partial<IPivotViewInfo>): IPivotViewInfo;
34
+ static createGrandTotalInfo(nodeTree: NodeTree, valueIndex: number): IPivotViewInfo;
35
+ static getRowColCount(ctx: IPivotLayoutCtx): number;
36
+ static getRowLabelCol(_ctx: IPivotLayoutCtx, _nodeLevel: number): number;
37
+ static getValueLabelCol(_ctx: IPivotLayoutCtx, _nodeLevel: number): number;
38
+ static getNodeDisplayValue(nodeTree: NodeTree): IPivotViewValueType;
39
+ static applyNodeValueType(rowView: IPivotLayoutCtx['view']['rowView'], row: number, col: number, nodeTree: NodeTree): void;
40
+ static repeatRowLabelsForNode(_ctx: IPivotLayoutCtx, _nodeTree: NodeTree, _row: number): void;
41
+ static layoutColHeader(ctx: IPivotLayoutCtx): void;
42
+ static layoutCorner(ctx: IPivotLayoutCtx): void;
9
43
  }
@@ -1,9 +1,40 @@
1
1
  import type { PivotTable } from '../pivot/pivot-table';
2
+ import type { NodeTree } from '../summary/node-tree';
2
3
  import type { SummaryManager } from '../summary/summary-manager';
3
- import type { IPivotLayoutCtx, IPivotTableQueryData } from '../types';
4
+ import type { IPivotLayoutCtx, IPivotTableQueryData, IPivotViewInfo, IPivotViewValueType } from '../types';
4
5
  import type { PivotView } from './pivot-view';
5
- import { BaseLayout } from './base-layout';
6
- export declare class OutlineLayout extends BaseLayout {
7
- static layout(pivotTable: PivotTable, SummaryManager: SummaryManager, queryData: IPivotTableQueryData): PivotView;
8
- static layoutRow(ctx: IPivotLayoutCtx): void;
6
+ import { TabularLayout } from './tabular';
7
+ export declare class OutlineLayout extends TabularLayout {
8
+ static layout(pivotTable: PivotTable, summaryManager: SummaryManager, queryData: IPivotTableQueryData): PivotView;
9
+ static layoutRowFields(ctx: IPivotLayoutCtx): void;
10
+ static shouldSplitRootByValues(ctx: IPivotLayoutCtx): boolean;
11
+ static layoutRowChildren(ctx: IPivotLayoutCtx, nodeTree: NodeTree, row: number, valueIds: string[]): number;
12
+ static layoutRowNode(ctx: IPivotLayoutCtx, nodeTree: NodeTree, row: number, valueIds: string[]): {
13
+ itemSize: number;
14
+ topTotalSize: number;
15
+ bottomTotalSize: number;
16
+ };
17
+ static layoutRowNodeToCursor(ctx: IPivotLayoutCtx, nodeTree: NodeTree, row: number, valueIds: string[]): number;
18
+ static shouldWriteSubtotalAtBottom(ctx: IPivotLayoutCtx): boolean;
19
+ static shouldWriteMultiValueSubtotalAtBottom(ctx: IPivotLayoutCtx, nodeTree: NodeTree): boolean;
20
+ static writeParentItemRow(ctx: IPivotLayoutCtx, nodeTree: NodeTree, row: number): number;
21
+ static writeValueHeaderRow(ctx: IPivotLayoutCtx, nodeTree: NodeTree, row: number, valueId: string): number;
22
+ static writeRootValueHeaderRow(ctx: IPivotLayoutCtx, row: number, valueId: string): number;
23
+ static writeParentRows(ctx: IPivotLayoutCtx, nodeTree: NodeTree, row: number, valueIds: string[]): number;
24
+ static writeParentRow(ctx: IPivotLayoutCtx, nodeTree: NodeTree, row: number, valueIndex: number, valueLabel?: string): void;
25
+ static writeBottomSubtotalRows(ctx: IPivotLayoutCtx, nodeTree: NodeTree, row: number, valueIds: string[]): number;
26
+ static writeBottomSubtotalRow(ctx: IPivotLayoutCtx, nodeTree: NodeTree, row: number, valueIndex: number, valueLabel?: string): void;
27
+ static writeLeafRows(ctx: IPivotLayoutCtx, nodeTree: NodeTree, row: number, valueIds: string[]): number;
28
+ static shouldWriteLeafValuesUnderItem(ctx: IPivotLayoutCtx): boolean;
29
+ static writeLeafItemRow(ctx: IPivotLayoutCtx, nodeTree: NodeTree, row: number): number;
30
+ static writeLeafValueRow(ctx: IPivotLayoutCtx, nodeTree: NodeTree, row: number, valueIndex: number, valueLabel: string): void;
31
+ static writeGrandTotalRows(ctx: IPivotLayoutCtx, nodeTree: NodeTree, row: number, valueIds: string[]): number;
32
+ static layoutGrandTotalValues(ctx: IPivotLayoutCtx, nodeTree: NodeTree, row: number, measureIndex: number): void;
33
+ static createRowInfo(nodeTree: NodeTree, extra: Partial<IPivotViewInfo>): IPivotViewInfo;
34
+ static createGrandTotalInfo(nodeTree: NodeTree, valueIndex: number): IPivotViewInfo;
35
+ static getRowColCount(ctx: IPivotLayoutCtx): number;
36
+ static getRowLabelCol(ctx: IPivotLayoutCtx, nodeLevel: number): number;
37
+ static getValueLabelCol(ctx: IPivotLayoutCtx, nodeLevel: number): number;
38
+ static getNodeDisplayValue(nodeTree: NodeTree): IPivotViewValueType;
39
+ static applyNodeValueType(rowView: IPivotLayoutCtx['view']['rowView'], row: number, col: number, nodeTree: NodeTree): void;
9
40
  }
@@ -22,6 +22,7 @@ export declare class TabularLayout extends BaseLayout {
22
22
  static getMeasureInfoByIndex(ctx: IPivotLayoutCtx, valueQueryInfo: IPivotTableValueFieldQueryData[], rowInfo: IPivotViewInfo, colInfo: IPivotViewInfo): IPivotTableValueFieldQueryData;
23
23
  static layoutValueLeafNode(ctx: IPivotLayoutCtx, nodeTree: NodeTree, row: number, paths: string[], measureIndex: number): void;
24
24
  static getColIndexForRowHeader(nodeLevel: number, valueIndex: number, hasMultiValue: boolean): number;
25
+ static repeatRowLabelsForNode(ctx: IPivotLayoutCtx, nodeTree: NodeTree, row: number): void;
25
26
  static doRowBrachNode(ctx: IPivotLayoutCtx, nodeTree: NodeTree, row: number, valueIds: string[]): INodeSizeInfo;
26
27
  static layoutRowNode(ctx: IPivotLayoutCtx, nodeTree: NodeTree, row: number, valueIds: string[]): INodeSizeInfo;
27
28
  static updateRowSubtotal(ctx: IPivotLayoutCtx, row: number, nodeTree: NodeTree, valueIds: string[]): void;
@@ -97,6 +97,8 @@ export declare class PivotModel {
97
97
  * @returns {IPivotTableOptions} - The options of the pivot table.
98
98
  */
99
99
  getOptions(): IPivotTableOptions;
100
+ setLayout(layout: PivotLayoutTypeEnum): void;
101
+ getLayout(): PivotLayoutTypeEnum;
100
102
  /**
101
103
  * @description Set the collapse status of the field. Those properties are used to save the collapse status of the field in the pivot table.
102
104
  * @param {string} fieldId - The id of the field.
@@ -2,7 +2,7 @@ import type { DataField } from '../field/data-field';
2
2
  import type { FieldsCollection } from '../field/fields-collection';
3
3
  import type { PivotView } from '../layout/pivot-view';
4
4
  import type { IPivotTableChangeSet, IPivotTableFilterInfo, IPivotTableOptions, IPivotTableQueryData, IPivotTableSnapshot, IPivotTableSortInfo, IPivotTableValueFilter, PivotTableFiledAreaEnum, PivotTableValuePositionEnum } from '../types';
5
- import { PivotCallbackEnum, PivotDataFieldDataTypeEnum, PivotSubtotalTypeEnum } from '../types';
5
+ import { PivotCallbackEnum, PivotDataFieldDataTypeEnum, PivotLayoutTypeEnum, PivotSubtotalTypeEnum } from '../types';
6
6
  import { PivotModel } from './model';
7
7
  import { PivotTableLabelField, PivotTableValueField } from './table-field';
8
8
  /**
@@ -140,6 +140,8 @@ export declare class PivotTable {
140
140
  */
141
141
  addFieldWithSourceId(dataFieldId: string, area: PivotTableFiledAreaEnum, index?: number, provideTableFieldId?: string): PivotTableLabelField | PivotTableValueField | undefined;
142
142
  setOptions(options: IPivotTableOptions): void;
143
+ setLayout(layout: PivotLayoutTypeEnum): void;
144
+ getLayout(): PivotLayoutTypeEnum;
143
145
  /**
144
146
  * the func is only use for when refresh
145
147
  * @param {string} fieldId the table field id
@@ -285,6 +287,7 @@ export declare class PivotTable {
285
287
  setDirty(dirty: boolean): void;
286
288
  reset(area?: PivotTableFiledAreaEnum): void;
287
289
  query(config?: IPivotTableQueryData): PivotView;
290
+ private _layout;
288
291
  toJSON(): IPivotTableSnapshot;
289
292
  fromJSON(data: IPivotTableSnapshot): void;
290
293
  dispose(): void;
@@ -630,6 +630,21 @@ export declare enum PivotLayoutTypeEnum {
630
630
  */
631
631
  tabular = 3
632
632
  }
633
+ /**
634
+ * Enum for pivot table row subtotal display position.
635
+ * @readonly
636
+ * @enum {number}
637
+ */
638
+ export declare enum PivotSubtotalPositionEnum {
639
+ /**
640
+ * @property {number} top - show row subtotals at the top of each group
641
+ */
642
+ top = 1,
643
+ /**
644
+ * @property {number} bottom - show row subtotals at the bottom of each group
645
+ */
646
+ bottom = 2
647
+ }
633
648
  /**
634
649
  * Enum the execution time of callback functions
635
650
  * @enum {string}
@@ -166,7 +166,11 @@ export declare enum PivotTableChangeTypeEnum {
166
166
  /**
167
167
  * Set value filter to the field in the pivot table.
168
168
  */
169
- SetValueFilter = 12
169
+ SetValueFilter = 12,
170
+ /**
171
+ * Set report layout of the pivot table.
172
+ */
173
+ SetLayout = 13
170
174
  }
171
175
  /**
172
176
  * The change of adding field to the pivot table.
@@ -331,6 +335,23 @@ export interface IPivotTableSetOptionsChange {
331
335
  */
332
336
  newOptions: IPivotTableOptions;
333
337
  }
338
+ /**
339
+ * The change of setting report layout to the pivot table.
340
+ */
341
+ export interface IPivotTableSetLayoutChange {
342
+ /**
343
+ * @property {PivotTableChangeTypeEnum} type The type of the change.
344
+ */
345
+ type: PivotTableChangeTypeEnum.SetLayout;
346
+ /**
347
+ * @property {PivotLayoutTypeEnum} oldLayout The old layout of the pivot table.
348
+ */
349
+ oldLayout: PivotLayoutTypeEnum;
350
+ /**
351
+ * @property {PivotLayoutTypeEnum} newLayout The new layout of the pivot table.
352
+ */
353
+ newLayout: PivotLayoutTypeEnum;
354
+ }
334
355
  /**
335
356
  * The change of updating value position in the pivot table.
336
357
  */
@@ -458,4 +479,4 @@ export interface IPivotTableSetCollapseChange {
458
479
  */
459
480
  item?: string;
460
481
  }
461
- export type IPivotTableChangeSet = IPivotTableAddFieldChange | IPivotTableSetSubtotalTypeChange | IPivotTableRemoveFieldChange | IPivotTableRenameFieldChange | IPivotTableSetFilterInfoChange | IPivotTableSetSortInfoChange | IPivotTableUpdatePositionChange | IPivotTableUpdateValuePositionChange | IPivotTableSetOptionsChange | IPivotTableSetFormatChange | IPivotTableSetCollapseChange | IPivotUpdateSourceChange | IPivotTableSetValueFilterChange;
482
+ export type IPivotTableChangeSet = IPivotTableAddFieldChange | IPivotTableSetSubtotalTypeChange | IPivotTableRemoveFieldChange | IPivotTableRenameFieldChange | IPivotTableSetFilterInfoChange | IPivotTableSetSortInfoChange | IPivotTableUpdatePositionChange | IPivotTableUpdateValuePositionChange | IPivotTableSetOptionsChange | IPivotTableSetFormatChange | IPivotTableSetCollapseChange | IPivotUpdateSourceChange | IPivotTableSetValueFilterChange | IPivotTableSetLayoutChange;
@@ -1,7 +1,7 @@
1
1
  import type { PivotView } from '../layout/pivot-view';
2
2
  import type { NodeTree } from '../summary/node-tree';
3
3
  import type { SummaryManager } from '../summary/summary-manager';
4
- import type { PivotErrorTypeEnum } from './enum';
4
+ import type { PivotErrorTypeEnum, PivotSubtotalPositionEnum } from './enum';
5
5
  import type { IPivotTableGroupInfo, IPivotTableQueryData, IPivotTableValueFieldQueryData, IValueFilterInfoItem } from './interface';
6
6
  export interface IPivotViewItemData {
7
7
  [row: number]: IPivotViewColData;
@@ -70,6 +70,27 @@ export interface IPivotViewInfo {
70
70
  * the data field id
71
71
  */
72
72
  dataFieldId?: string;
73
+ /**
74
+ * Whether this row/column item is a top total. Compact and outline layouts can show subtotals
75
+ * on the parent row while keeping isBottomTotal for existing consumers that treat totals uniformly.
76
+ */
77
+ isTopTotal?: boolean;
78
+ /**
79
+ * Whether this item is a subtotal row/column.
80
+ */
81
+ isSubtotal?: boolean;
82
+ /**
83
+ * Whether this item represents a leaf row/column item.
84
+ */
85
+ isLeaf?: boolean;
86
+ /**
87
+ * Explicit semantic type for row-oriented consumers. Existing layouts can omit this field.
88
+ */
89
+ rowType?: 'item' | 'subtotal' | 'grandTotal' | 'value';
90
+ /**
91
+ * Whether this corner header should render as the compact row-label caption.
92
+ */
93
+ isRowLabel?: boolean;
73
94
  }
74
95
  /**
75
96
  * Represents the pivot cell style type enum
@@ -177,6 +198,10 @@ export interface IPivotTableOptions {
177
198
  * Whether to show grand total in column, if showColGrandTotal is false, the grand total in column will not be calculated and rendered
178
199
  */
179
200
  showColGrandTotal?: boolean;
201
+ /**
202
+ * Where row subtotals are displayed for outline layout.
203
+ */
204
+ rowSubtotalPosition?: PivotSubtotalPositionEnum;
180
205
  }
181
206
  export interface INodeSizeInfo {
182
207
  /**
@@ -223,6 +248,7 @@ export interface IPivotLayoutCtx {
223
248
  showRowGrandTotal: boolean;
224
249
  showColSubtotal: boolean;
225
250
  showColGrandTotal: boolean;
251
+ rowSubtotalPosition: PivotSubtotalPositionEnum;
226
252
  }
227
253
  export interface IPageViewItemRange {
228
254
  row: number;
@@ -232,6 +258,7 @@ export interface IPageViewItemRange {
232
258
  }
233
259
  export interface ILabelViewHeaderMapItem {
234
260
  isValue: boolean;
261
+ isColumnLabel?: boolean;
235
262
  level: number;
236
263
  tableFieldId: string;
237
264
  dataFieldId: string;