@univerjs-pro/sheets-pivot-chart 1.0.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/README.md +85 -0
- package/lib/cjs/facade.js +1 -0
- package/lib/cjs/index.js +1 -0
- package/lib/es/facade.js +1 -0
- package/lib/es/index.js +1 -0
- package/lib/facade.js +1 -0
- package/lib/index.js +1 -0
- package/lib/types/chart-builder/pivot-chart-config-adapter.d.ts +14 -0
- package/lib/types/commands/commands/insert-pivot-chart.command.d.ts +15 -0
- package/lib/types/commands/commands/pivot-chart.command.d.ts +124 -0
- package/lib/types/commands/mutations/pivot-chart-data-communication.mutation.d.ts +11 -0
- package/lib/types/commands/mutations/pivot-chart.mutation.d.ts +9 -0
- package/lib/types/config/config.d.ts +6 -0
- package/lib/types/controllers/pivot-chart-calculation.controller.d.ts +25 -0
- package/lib/types/controllers/pivot-chart-drawing.controller.d.ts +14 -0
- package/lib/types/controllers/pivot-chart-edit.controller.d.ts +17 -0
- package/lib/types/controllers/pivot-chart-runtime.controller.d.ts +26 -0
- package/lib/types/facade/f-enum.d.ts +15 -0
- package/lib/types/facade/f-event.d.ts +56 -0
- package/lib/types/facade/f-pivot-chart-builder.d.ts +73 -0
- package/lib/types/facade/f-pivot-chart.d.ts +487 -0
- package/lib/types/facade/f-pivot-table.d.ts +41 -0
- package/lib/types/facade/f-univer.d.ts +11 -0
- package/lib/types/facade/f-workbook.d.ts +28 -0
- package/lib/types/facade/f-worksheet.d.ts +61 -0
- package/lib/types/facade/index.d.ts +9 -0
- package/lib/types/facade/pivot-chart-facade-adapter.d.ts +41 -0
- package/lib/types/index.d.ts +15 -0
- package/lib/types/models/sheets-pivot-chart.model.d.ts +56 -0
- package/lib/types/plugin.d.ts +27 -0
- package/lib/types/services/pivot-chart-rpc.service.d.ts +35 -0
- package/lib/types/types.d.ts +175 -0
- package/lib/umd/facade.js +1 -0
- package/lib/umd/index.js +1 -0
- package/package.json +93 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { IPivotChartCalculationResult, IPivotChartRuntimeState } from '@univerjs-pro/pivot-chart';
|
|
2
|
+
import type { ISheetsPivotChartModelChange } from '@univerjs-pro/sheets-pivot-chart';
|
|
3
|
+
import type { IEventBase } from '@univerjs/core/facade';
|
|
4
|
+
import { FEventName } from '@univerjs/core/facade';
|
|
5
|
+
/** Common identity delivered by PivotChart lifecycle events. */
|
|
6
|
+
export interface IPivotChartEventParams extends IEventBase {
|
|
7
|
+
unitId: string;
|
|
8
|
+
subUnitId: string;
|
|
9
|
+
pivotChartId: string;
|
|
10
|
+
}
|
|
11
|
+
/** PivotChart definition change event parameters. */
|
|
12
|
+
export interface IPivotChartChangedEventParams extends IPivotChartEventParams {
|
|
13
|
+
/** Identifies whether the persisted definition or Sheet Drawing changed. */
|
|
14
|
+
kind: 'definition' | 'drawing';
|
|
15
|
+
/** Present when {@link kind} is `definition`. */
|
|
16
|
+
change?: ISheetsPivotChartModelChange;
|
|
17
|
+
}
|
|
18
|
+
/** PivotChart calculation state event parameters. */
|
|
19
|
+
export interface IPivotChartDataStateChangedEventParams extends IPivotChartEventParams {
|
|
20
|
+
state: IPivotChartRuntimeState;
|
|
21
|
+
}
|
|
22
|
+
/** PivotChart completed-render data event parameters. */
|
|
23
|
+
export interface IPivotChartRenderedEventParams extends IPivotChartEventParams {
|
|
24
|
+
result: IPivotChartCalculationResult;
|
|
25
|
+
}
|
|
26
|
+
/** @ignore */
|
|
27
|
+
interface IFSheetsPivotChartEventNameMixin {
|
|
28
|
+
readonly PivotChartAdded: 'PivotChartAdded';
|
|
29
|
+
readonly PivotChartRemoved: 'PivotChartRemoved';
|
|
30
|
+
readonly PivotChartChanged: 'PivotChartChanged';
|
|
31
|
+
readonly PivotChartRendered: 'PivotChartRendered';
|
|
32
|
+
readonly PivotChartDataStateChanged: 'PivotChartDataStateChanged';
|
|
33
|
+
}
|
|
34
|
+
/** @ignore */
|
|
35
|
+
interface ISheetsPivotChartEventParamConfig {
|
|
36
|
+
PivotChartAdded: IPivotChartEventParams;
|
|
37
|
+
PivotChartRemoved: IPivotChartEventParams;
|
|
38
|
+
PivotChartChanged: IPivotChartChangedEventParams;
|
|
39
|
+
PivotChartRendered: IPivotChartRenderedEventParams;
|
|
40
|
+
PivotChartDataStateChanged: IPivotChartDataStateChangedEventParams;
|
|
41
|
+
}
|
|
42
|
+
/** @ignore */
|
|
43
|
+
export declare class FSheetsPivotChartEventNameMixin extends FEventName implements IFSheetsPivotChartEventNameMixin {
|
|
44
|
+
get PivotChartAdded(): 'PivotChartAdded';
|
|
45
|
+
get PivotChartRemoved(): 'PivotChartRemoved';
|
|
46
|
+
get PivotChartChanged(): 'PivotChartChanged';
|
|
47
|
+
get PivotChartRendered(): 'PivotChartRendered';
|
|
48
|
+
get PivotChartDataStateChanged(): 'PivotChartDataStateChanged';
|
|
49
|
+
}
|
|
50
|
+
declare module '@univerjs/core/facade' {
|
|
51
|
+
interface FEventName extends IFSheetsPivotChartEventNameMixin {
|
|
52
|
+
}
|
|
53
|
+
interface IEventParamConfig extends ISheetsPivotChartEventParamConfig {
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
export {};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { IChartBuilderTypeMap } from '@univerjs-pro/engine-chart/facade';
|
|
2
|
+
import type { IPivotChartControls, PivotChartTypeString } from '@univerjs-pro/pivot-chart';
|
|
3
|
+
import type { ChartAnchorSpec } from '@univerjs-pro/sheets-chart';
|
|
4
|
+
import type { IPivotChartTableSourceSpec, ISheetPivotChartInfo, PivotChartRangeInput, PivotChartSourceSpec } from '@univerjs-pro/sheets-pivot-chart';
|
|
5
|
+
import type { FPivotTable } from '@univerjs-pro/sheets-pivot/facade';
|
|
6
|
+
type PivotChartUnsafeBuilderMethod = 'setSource' | 'setCategoryField' | 'setCategoryFields' | 'clearCategoryField' | 'clearCategoryFields' | 'setMultiLevelCategoryAxis' | 'setValueFields' | 'clearValueFields' | 'setAggregation' | 'clearAggregation';
|
|
7
|
+
type PivotChartEngineBuilder<T extends PivotChartTypeString> = Omit<IChartBuilderTypeMap<PivotChartRangeInput, PivotChartSourceSpec, ISheetPivotChartInfo>[T], PivotChartUnsafeBuilderMethod>;
|
|
8
|
+
type RebindPivotChartBuilder<TBuilder, TExtension> = {
|
|
9
|
+
[K in keyof TBuilder]: TBuilder[K] extends (...args: infer TArgs) => infer TResult ? TResult extends TBuilder ? (...args: TArgs) => RebindPivotChartBuilder<TBuilder, TExtension> & TExtension : (...args: TArgs) => TResult : TBuilder[K];
|
|
10
|
+
};
|
|
11
|
+
interface ISheetPivotChartBuilderExtensionMethods {
|
|
12
|
+
/**
|
|
13
|
+
* Links the new PivotChart to an existing PivotTable-owned report.
|
|
14
|
+
* @param {FPivotTable} pivotTable The PivotTable that owns the shared PivotModel.
|
|
15
|
+
* @returns {this} This Builder for chaining.
|
|
16
|
+
*/
|
|
17
|
+
setPivotTable(pivotTable: FPivotTable): this;
|
|
18
|
+
/**
|
|
19
|
+
* Links the new PivotChart using a stable PivotTable reference.
|
|
20
|
+
* @param {IPivotChartTableSourceSpec['pivotTableRef']} pivotTableRef The referenced PivotTable identity.
|
|
21
|
+
* @returns {this} This Builder for chaining.
|
|
22
|
+
*/
|
|
23
|
+
setPivotTableReference(pivotTableRef: IPivotChartTableSourceSpec['pivotTableRef']): this;
|
|
24
|
+
/**
|
|
25
|
+
* Sets the worksheet cell anchor used when inserting the PivotChart.
|
|
26
|
+
* @param {ChartAnchorSpec} anchor A1 notation or a zero-based row and column anchor.
|
|
27
|
+
* @returns {this} This Builder for chaining.
|
|
28
|
+
*/
|
|
29
|
+
setPosition(anchor: ChartAnchorSpec): this;
|
|
30
|
+
/**
|
|
31
|
+
* Sets the optional user-facing PivotChart name.
|
|
32
|
+
* @param {string} name The PivotChart name.
|
|
33
|
+
* @returns {this} This Builder for chaining.
|
|
34
|
+
*/
|
|
35
|
+
setName(name: string): this;
|
|
36
|
+
/**
|
|
37
|
+
* Merges persisted PivotChart button visibility controls.
|
|
38
|
+
* @param {Partial<IPivotChartControls>} controls The controls to override.
|
|
39
|
+
* @returns {this} This Builder for chaining.
|
|
40
|
+
*/
|
|
41
|
+
setControls(controls: Partial<IPivotChartControls>): this;
|
|
42
|
+
/**
|
|
43
|
+
* Shows or hides Pivot field buttons.
|
|
44
|
+
* @param {boolean} visible Whether field buttons are visible.
|
|
45
|
+
* @returns {this} This Builder for chaining.
|
|
46
|
+
*/
|
|
47
|
+
setFieldButtonsVisible(visible: boolean): this;
|
|
48
|
+
/**
|
|
49
|
+
* Shows or hides category hierarchy expand and collapse buttons.
|
|
50
|
+
* @param {boolean} visible Whether expand and collapse buttons are visible.
|
|
51
|
+
* @returns {this} This Builder for chaining.
|
|
52
|
+
*/
|
|
53
|
+
setExpandCollapseButtonsVisible(visible: boolean): this;
|
|
54
|
+
}
|
|
55
|
+
export interface ISheetPivotChartBuilderMethods extends ISheetPivotChartBuilderExtensionMethods {
|
|
56
|
+
/**
|
|
57
|
+
* Sets a range source that creates an independently owned PivotModel.
|
|
58
|
+
*
|
|
59
|
+
* A local A1 string and an `IRange` are resolved against the worksheet that created the Builder.
|
|
60
|
+
* A complete range identity can reference another worksheet in the supported Unit boundary.
|
|
61
|
+
*
|
|
62
|
+
* @param {PivotChartRangeInput} source The range source.
|
|
63
|
+
* @returns {this} This Builder for chaining.
|
|
64
|
+
*/
|
|
65
|
+
setSource(source: PivotChartRangeInput): this;
|
|
66
|
+
}
|
|
67
|
+
/** A type-specific PivotChart Builder with worksheet insertion options. */
|
|
68
|
+
export type FSheetPivotChartBuilderOf<T extends PivotChartTypeString> = RebindPivotChartBuilder<PivotChartEngineBuilder<T>, ISheetPivotChartBuilderMethods> & ISheetPivotChartBuilderMethods;
|
|
69
|
+
/** A prelinked PivotChart Builder whose report source cannot be replaced. */
|
|
70
|
+
export type FLinkedSheetPivotChartBuilderOf<T extends PivotChartTypeString> = Omit<FSheetPivotChartBuilderOf<T>, 'setSource' | 'setPivotTable' | 'setPivotTableReference'>;
|
|
71
|
+
/** A Builder copied from a live PivotChart whose report source cannot be replaced. */
|
|
72
|
+
export type FBoundSheetPivotChartBuilderOf<T extends PivotChartTypeString> = FLinkedSheetPivotChartBuilderOf<T>;
|
|
73
|
+
export {};
|
|
@@ -0,0 +1,487 @@
|
|
|
1
|
+
import type { ChartAppearanceTarget, ChartLegendSpec, ChartSubtitleSpec, ChartTitleSpec, IChartAppearanceSpec, InvalidValueType } from '@univerjs-pro/engine-chart';
|
|
2
|
+
import type { IPivotTableLabelFieldJSON, IPivotTableShowDataAsInfo, IPivotTableSnapshot, IPivotTableSortInfo, IPivotTableValueFieldJSON, IPivotTableValueFilter, IValueFilterInfoItem, PivotDateGroupFieldDateTypeEnum } from '@univerjs-pro/engine-pivot';
|
|
3
|
+
import type { IPivotChartControls, IPivotChartPivotTableReference, PivotChartTypeString } from '@univerjs-pro/pivot-chart';
|
|
4
|
+
import type { ChartAnchorSpec } from '@univerjs-pro/sheets-chart';
|
|
5
|
+
import type { IUnitRangeNameWithSubUnitId } from '@univerjs-pro/sheets-pivot';
|
|
6
|
+
import type { IPivotChartDataFieldInfo, IPivotChartFieldSettingOptions, ISheetPivotChartInfo } from '@univerjs-pro/sheets-pivot-chart';
|
|
7
|
+
import type { DeepReadonly, Injector } from '@univerjs/core';
|
|
8
|
+
import type { FBoundSheetPivotChartBuilderOf } from './f-pivot-chart-builder';
|
|
9
|
+
import { PivotTableFiledAreaEnum, PivotTableValuePositionEnum } from '@univerjs-pro/engine-pivot';
|
|
10
|
+
import { PivotChartSourceKind } from '@univerjs-pro/pivot-chart';
|
|
11
|
+
import { FPivotTable } from '@univerjs-pro/sheets-pivot/facade';
|
|
12
|
+
import { FBase } from '@univerjs/core/facade';
|
|
13
|
+
/**
|
|
14
|
+
* A live PivotChart hosted by a worksheet.
|
|
15
|
+
*
|
|
16
|
+
* The Chart visual and Drawing placement belong to this PivotChart. The effective Pivot report
|
|
17
|
+
* belongs either to this chart (range source) or to the referenced PivotTable (linked source).
|
|
18
|
+
* Linked PivotCharts therefore share field, filter, sort, Show Values As, and collapse changes.
|
|
19
|
+
*
|
|
20
|
+
* @example Create an owned PivotChart
|
|
21
|
+
* ```ts
|
|
22
|
+
* import '@univerjs-pro/sheets-pivot-chart/facade';
|
|
23
|
+
*
|
|
24
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
25
|
+
* const fWorksheet = fWorkbook.getSheetByName('Sales');
|
|
26
|
+
* const info = fWorksheet
|
|
27
|
+
* .newPivotChart(univerAPI.Enum.ChartTypeString.Column)
|
|
28
|
+
* .setSource('A1:G100')
|
|
29
|
+
* .setPosition('J2')
|
|
30
|
+
* .setSize(640, 360)
|
|
31
|
+
* .setTitle('Sales by region')
|
|
32
|
+
* .build();
|
|
33
|
+
* const fPivotChart = await fWorksheet.insertPivotChart(info);
|
|
34
|
+
* const sourceFields = fPivotChart.getSourceFieldsInfo();
|
|
35
|
+
* await fPivotChart.addField(sourceFields[0].id, univerAPI.Enum.PivotTableFiledAreaEnum.Row, 0);
|
|
36
|
+
* await fPivotChart.addField(sourceFields[5].id, univerAPI.Enum.PivotTableFiledAreaEnum.Value, 0);
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* @example Link multiple PivotCharts to one PivotTable
|
|
40
|
+
* ```ts
|
|
41
|
+
* import '@univerjs-pro/sheets-pivot-chart/facade';
|
|
42
|
+
*
|
|
43
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
44
|
+
* const fWorksheet = fWorkbook.getSheetByName('Dashboard');
|
|
45
|
+
* const fPivotTable = fWorkbook.getPivotTableById('pivot-table-1');
|
|
46
|
+
* if (!fWorksheet || !fPivotTable) throw new Error('Pivot source is unavailable.');
|
|
47
|
+
*
|
|
48
|
+
* const first = await fWorksheet.insertPivotChart(
|
|
49
|
+
* fPivotTable.newChart(univerAPI.Enum.ChartTypeString.Column).setPosition('A1').build()
|
|
50
|
+
* );
|
|
51
|
+
* const second = await fWorksheet.insertPivotChart(
|
|
52
|
+
* fPivotTable.newChart(univerAPI.Enum.ChartTypeString.Line).setPosition('J1').build()
|
|
53
|
+
* );
|
|
54
|
+
* const rowFieldId = first.getFieldIdsByArea(univerAPI.Enum.PivotTableFiledAreaEnum.Row)[0];
|
|
55
|
+
* await first.setLabelSort(rowFieldId, { type: univerAPI.Enum.PivotDataFieldSortOperatorEnum.ascending });
|
|
56
|
+
* console.log(second.getFieldsConfig()); // Reads the same PivotTable-owned report.
|
|
57
|
+
* ```
|
|
58
|
+
*
|
|
59
|
+
* @example Configure Show Values As and a value filter
|
|
60
|
+
* ```ts
|
|
61
|
+
* const rowFieldId = fPivotChart.getFieldIdsByArea(univerAPI.Enum.PivotTableFiledAreaEnum.Row)[0];
|
|
62
|
+
* const valueFieldId = fPivotChart.getFieldIdsByArea(univerAPI.Enum.PivotTableFiledAreaEnum.Value)[0];
|
|
63
|
+
* await fPivotChart.setShowDataAs(valueFieldId, {
|
|
64
|
+
* type: univerAPI.Enum.PivotShowAsTypeEnum.percentOfGrandTotal,
|
|
65
|
+
* baseFieldId: '',
|
|
66
|
+
* baseItem: '',
|
|
67
|
+
* });
|
|
68
|
+
* await fPivotChart.setValueFilter(rowFieldId, {
|
|
69
|
+
* operator: univerAPI.Enum.PivotFilterOperatorEnum.valueGreaterThan,
|
|
70
|
+
* expected: 1000,
|
|
71
|
+
* valueFieldId,
|
|
72
|
+
* });
|
|
73
|
+
* ```
|
|
74
|
+
*
|
|
75
|
+
* @example Handle an unavailable linked PivotTable
|
|
76
|
+
* ```ts
|
|
77
|
+
* if (fPivotChart.isLinkedToPivotTable() && !fPivotChart.getPivotTable()) {
|
|
78
|
+
* // Report writes resolve to false until the same PivotTable ID becomes available again.
|
|
79
|
+
* console.log(await fPivotChart.resetFields());
|
|
80
|
+
* // Per-chart visual changes remain available.
|
|
81
|
+
* fPivotChart.setTheme('default');
|
|
82
|
+
* }
|
|
83
|
+
* ```
|
|
84
|
+
*
|
|
85
|
+
* @hideconstructor
|
|
86
|
+
*/
|
|
87
|
+
export declare class FSheetPivotChart extends FBase {
|
|
88
|
+
readonly unitId: string;
|
|
89
|
+
readonly subUnitId: string;
|
|
90
|
+
readonly pivotChartId: string;
|
|
91
|
+
protected readonly _injector: Injector;
|
|
92
|
+
constructor(unitId: string, subUnitId: string, pivotChartId: string, _injector: Injector);
|
|
93
|
+
/**
|
|
94
|
+
* Returns the stable identifier of this PivotChart.
|
|
95
|
+
* @returns {string} The PivotChart identifier.
|
|
96
|
+
*/
|
|
97
|
+
getId(): string;
|
|
98
|
+
/**
|
|
99
|
+
* Returns the current PivotChart type.
|
|
100
|
+
* @returns {PivotChartTypeString} The supported Chart type.
|
|
101
|
+
*/
|
|
102
|
+
getType(): PivotChartTypeString;
|
|
103
|
+
/**
|
|
104
|
+
* Returns detached information that can be inspected, copied, or passed to {@link update}.
|
|
105
|
+
* @returns {DeepReadonly<ISheetPivotChartInfo>} A defensive PivotChart snapshot.
|
|
106
|
+
*/
|
|
107
|
+
getInfo(): DeepReadonly<ISheetPivotChartInfo>;
|
|
108
|
+
/**
|
|
109
|
+
* Creates a detached, source-locked Builder prefilled from this PivotChart.
|
|
110
|
+
* @returns {FBoundSheetPivotChartBuilderOf<PivotChartTypeString>} A source-locked Builder.
|
|
111
|
+
*/
|
|
112
|
+
toBuilder(): FBoundSheetPivotChartBuilderOf<PivotChartTypeString>;
|
|
113
|
+
/**
|
|
114
|
+
* Creates a detached, source-locked Builder converted to another supported Chart type.
|
|
115
|
+
* @param {T} type The target supported Chart type.
|
|
116
|
+
* @returns {FBoundSheetPivotChartBuilderOf<T>} A source-locked Builder for the target type.
|
|
117
|
+
*/
|
|
118
|
+
toBuilder<T extends PivotChartTypeString>(type: T): FBoundSheetPivotChartBuilderOf<T>;
|
|
119
|
+
/**
|
|
120
|
+
* Atomically updates visual configuration, controls, name, and placement.
|
|
121
|
+
*
|
|
122
|
+
* The source mode, source identity, and live PivotModel are locked. Use {@link setSourceRange}
|
|
123
|
+
* or the field APIs for report changes.
|
|
124
|
+
*
|
|
125
|
+
* @param {ISheetPivotChartInfo} info Detached information created by {@link getInfo} or {@link toBuilder}.
|
|
126
|
+
* @returns {Promise<this>} This live PivotChart after the command is accepted.
|
|
127
|
+
* @throws If the source, report fields, Chart type, or Drawing layout is invalid.
|
|
128
|
+
*/
|
|
129
|
+
update(info: ISheetPivotChartInfo): Promise<this>;
|
|
130
|
+
/**
|
|
131
|
+
* Returns whether this PivotChart owns a range report or references a PivotTable.
|
|
132
|
+
* @returns {PivotChartSourceKind} The current source ownership kind.
|
|
133
|
+
*/
|
|
134
|
+
getSourceKind(): PivotChartSourceKind;
|
|
135
|
+
/**
|
|
136
|
+
* Returns whether this PivotChart shares a PivotTable-owned report.
|
|
137
|
+
* @returns {boolean} `true` for a linked PivotChart.
|
|
138
|
+
*/
|
|
139
|
+
isLinkedToPivotTable(): boolean;
|
|
140
|
+
/**
|
|
141
|
+
* Returns the effective source range for owned and available linked reports.
|
|
142
|
+
* @returns {IUnitRangeNameWithSubUnitId | undefined} A defensive range snapshot, if available.
|
|
143
|
+
*/
|
|
144
|
+
getSourceRangeInfo(): IUnitRangeNameWithSubUnitId | undefined;
|
|
145
|
+
/**
|
|
146
|
+
* Updates the effective report source without changing its ownership mode.
|
|
147
|
+
*
|
|
148
|
+
* Linked PivotCharts delegate this operation to their referenced PivotTable.
|
|
149
|
+
*
|
|
150
|
+
* @param {IUnitRangeNameWithSubUnitId} source The complete source range identity.
|
|
151
|
+
* @returns {Promise<boolean>} Whether the source update was accepted.
|
|
152
|
+
*/
|
|
153
|
+
setSourceRange(source: IUnitRangeNameWithSubUnitId): Promise<boolean>;
|
|
154
|
+
/**
|
|
155
|
+
* Returns the stable linked PivotTable reference.
|
|
156
|
+
* @returns {DeepReadonly<IPivotChartPivotTableReference> | undefined} The reference for linked charts.
|
|
157
|
+
*/
|
|
158
|
+
getPivotTableReference(): DeepReadonly<IPivotChartPivotTableReference> | undefined;
|
|
159
|
+
/**
|
|
160
|
+
* Returns a live facade for the referenced PivotTable.
|
|
161
|
+
* @returns {FPivotTable | null} The shared PivotTable, or `null` while the reference is unavailable.
|
|
162
|
+
*/
|
|
163
|
+
getPivotTable(): FPivotTable | null;
|
|
164
|
+
/**
|
|
165
|
+
* Returns the current effective report fields configuration.
|
|
166
|
+
* @returns {DeepReadonly<IPivotTableSnapshot> | undefined} A defensive report snapshot, if available.
|
|
167
|
+
*/
|
|
168
|
+
getFieldsConfig(): DeepReadonly<IPivotTableSnapshot> | undefined;
|
|
169
|
+
/**
|
|
170
|
+
* Returns source fields available to the effective Pivot report.
|
|
171
|
+
* @returns {IPivotChartDataFieldInfo[]} Defensive field information in source order.
|
|
172
|
+
*/
|
|
173
|
+
getSourceFieldsInfo(): IPivotChartDataFieldInfo[];
|
|
174
|
+
/**
|
|
175
|
+
* Returns one report field setting.
|
|
176
|
+
* @param {string} fieldId The table-field identifier.
|
|
177
|
+
* @returns {IPivotTableValueFieldJSON | IPivotTableLabelFieldJSON | undefined} A defensive field snapshot.
|
|
178
|
+
*/
|
|
179
|
+
getFieldSetting(fieldId: string): IPivotTableValueFieldJSON | IPivotTableLabelFieldJSON | undefined;
|
|
180
|
+
/**
|
|
181
|
+
* Returns table-field identifiers in one report area.
|
|
182
|
+
* @param {PivotTableFiledAreaEnum} area The Pivot report area.
|
|
183
|
+
* @returns {string[]} Table-field identifiers in display order.
|
|
184
|
+
*/
|
|
185
|
+
getFieldIdsByArea(area: PivotTableFiledAreaEnum): string[];
|
|
186
|
+
/**
|
|
187
|
+
* Replaces all report fields in one command and one Pivot query.
|
|
188
|
+
* @param {IPivotTableSnapshot} config The complete fields configuration.
|
|
189
|
+
* @returns {Promise<boolean>} Whether the report update was accepted.
|
|
190
|
+
*/
|
|
191
|
+
setFieldsConfig(config: IPivotTableSnapshot): Promise<boolean>;
|
|
192
|
+
/**
|
|
193
|
+
* Removes all fields or only fields in one report area.
|
|
194
|
+
* @param {PivotTableFiledAreaEnum} [area] The area to clear; omit it to clear all report fields.
|
|
195
|
+
* @returns {Promise<boolean>} Whether the report update was accepted.
|
|
196
|
+
*/
|
|
197
|
+
resetFields(area?: PivotTableFiledAreaEnum): Promise<boolean>;
|
|
198
|
+
/**
|
|
199
|
+
* Adds one source field to a report area.
|
|
200
|
+
* @param {string | number} dataFieldIdOrIndex A source-field identifier or zero-based source index.
|
|
201
|
+
* @param {PivotTableFiledAreaEnum} area The target report area.
|
|
202
|
+
* @param {number} index The zero-based target index.
|
|
203
|
+
* @returns {Promise<boolean>} Whether the field was added.
|
|
204
|
+
*/
|
|
205
|
+
addField(dataFieldIdOrIndex: string | number, area: PivotTableFiledAreaEnum, index: number): Promise<boolean>;
|
|
206
|
+
/**
|
|
207
|
+
* Removes report fields by their table-field identifiers.
|
|
208
|
+
* @param {string[]} fieldIds The table-field identifiers to remove together.
|
|
209
|
+
* @returns {Promise<boolean>} Whether the fields were removed.
|
|
210
|
+
*/
|
|
211
|
+
removeField(fieldIds: string[]): Promise<boolean>;
|
|
212
|
+
/**
|
|
213
|
+
* Moves one report field to a zero-based area index.
|
|
214
|
+
* @param {string} fieldId The table-field identifier.
|
|
215
|
+
* @param {PivotTableFiledAreaEnum} area The target area.
|
|
216
|
+
* @param {number} index The zero-based target index.
|
|
217
|
+
* @returns {Promise<boolean>} Whether the field was moved.
|
|
218
|
+
*/
|
|
219
|
+
updateFieldPosition(fieldId: string, area: PivotTableFiledAreaEnum, index: number): Promise<boolean>;
|
|
220
|
+
/**
|
|
221
|
+
* Moves the synthetic multiple-values field.
|
|
222
|
+
* @param {PivotTableValuePositionEnum} position The row, column, or absent position.
|
|
223
|
+
* @param {number} index The zero-based row or column field index.
|
|
224
|
+
* @returns {Promise<boolean>} Whether the value position was updated.
|
|
225
|
+
*/
|
|
226
|
+
updateValuePosition(position: PivotTableValuePositionEnum, index: number): Promise<boolean>;
|
|
227
|
+
/**
|
|
228
|
+
* Updates a report field display name, format, aggregation, or Show Values As rule.
|
|
229
|
+
* @param {string} fieldId The table-field identifier.
|
|
230
|
+
* @param {IPivotChartFieldSettingOptions} setting The field properties to update together.
|
|
231
|
+
* @returns {Promise<boolean>} Whether the field setting was updated.
|
|
232
|
+
*/
|
|
233
|
+
setFieldSetting(fieldId: string, setting: IPivotChartFieldSettingOptions): Promise<boolean>;
|
|
234
|
+
/**
|
|
235
|
+
* Renames a report field.
|
|
236
|
+
* @param {string} fieldId The table-field identifier.
|
|
237
|
+
* @param {string} name The new display name.
|
|
238
|
+
* @returns {Promise<boolean>} Whether the field was renamed.
|
|
239
|
+
*/
|
|
240
|
+
renameField(fieldId: string, name: string): Promise<boolean>;
|
|
241
|
+
/**
|
|
242
|
+
* Returns the Show Values As rule for a value field.
|
|
243
|
+
* @param {string} fieldId The value table-field identifier.
|
|
244
|
+
* @returns {IPivotTableShowDataAsInfo | undefined} A defensive rule snapshot.
|
|
245
|
+
*/
|
|
246
|
+
getShowDataAs(fieldId: string): IPivotTableShowDataAsInfo | undefined;
|
|
247
|
+
/**
|
|
248
|
+
* Sets the Show Values As rule for a value field.
|
|
249
|
+
* @param {string} fieldId The value table-field identifier.
|
|
250
|
+
* @param {IPivotTableShowDataAsInfo} value The Show Values As rule.
|
|
251
|
+
* @returns {Promise<boolean>} Whether the rule was updated.
|
|
252
|
+
*/
|
|
253
|
+
setShowDataAs(fieldId: string, value: IPivotTableShowDataAsInfo): Promise<boolean>;
|
|
254
|
+
/**
|
|
255
|
+
* Restores normal value display for a value field.
|
|
256
|
+
* @param {string} fieldId The value table-field identifier.
|
|
257
|
+
* @returns {Promise<boolean>} Whether the rule was reset.
|
|
258
|
+
*/
|
|
259
|
+
resetShowDataAs(fieldId: string): Promise<boolean>;
|
|
260
|
+
/**
|
|
261
|
+
* Sets label sorting for a row or column field.
|
|
262
|
+
* @param {string} fieldId The row or column table-field identifier.
|
|
263
|
+
* @param {IPivotTableSortInfo} info The sort rule.
|
|
264
|
+
* @returns {Promise<boolean>} Whether sorting was updated.
|
|
265
|
+
*/
|
|
266
|
+
setLabelSort(fieldId: string, info: IPivotTableSortInfo): Promise<boolean>;
|
|
267
|
+
/**
|
|
268
|
+
* Clears label sorting for a row or column field.
|
|
269
|
+
* @param {string} fieldId The row or column table-field identifier.
|
|
270
|
+
* @returns {Promise<boolean>} Whether sorting was cleared.
|
|
271
|
+
*/
|
|
272
|
+
clearLabelSort(fieldId: string): Promise<boolean>;
|
|
273
|
+
/**
|
|
274
|
+
* Sets a manual label filter for a report field.
|
|
275
|
+
* @param {string} fieldId The table-field identifier.
|
|
276
|
+
* @param {string[]} items The selected item keys.
|
|
277
|
+
* @param {boolean} [isAll] Whether all current items are selected.
|
|
278
|
+
* @returns {Promise<boolean>} Whether the filter was updated.
|
|
279
|
+
*/
|
|
280
|
+
setLabelManualFilter(fieldId: string, items: string[], isAll?: boolean): Promise<boolean>;
|
|
281
|
+
/**
|
|
282
|
+
* Returns the value filter owned by a row or column field.
|
|
283
|
+
* @param {string} fieldId The row or column table-field identifier.
|
|
284
|
+
* @returns {IPivotTableValueFilter | undefined} A defensive filter snapshot.
|
|
285
|
+
*/
|
|
286
|
+
getValueFilter(fieldId: string): IPivotTableValueFilter | undefined;
|
|
287
|
+
/**
|
|
288
|
+
* Returns value filters in evaluation order.
|
|
289
|
+
* @returns {IValueFilterInfoItem[]} Defensive ordered filter snapshots.
|
|
290
|
+
*/
|
|
291
|
+
getValueFilters(): IValueFilterInfoItem[];
|
|
292
|
+
/**
|
|
293
|
+
* Sets, replaces, or removes the value filter owned by a row or column field.
|
|
294
|
+
* @param {string} fieldId The row or column table-field identifier.
|
|
295
|
+
* @param {Omit<IPivotTableValueFilter, 'type'>} [filter] The rule, or `undefined` to remove it.
|
|
296
|
+
* @returns {Promise<boolean>} Whether the value filter was updated.
|
|
297
|
+
*/
|
|
298
|
+
setValueFilter(fieldId: string, filter?: Omit<IPivotTableValueFilter, 'type'>): Promise<boolean>;
|
|
299
|
+
/**
|
|
300
|
+
* Removes the value filter owned by a row or column field.
|
|
301
|
+
* @param {string} fieldId The row or column table-field identifier.
|
|
302
|
+
* @returns {Promise<boolean>} Whether the value filter was removed.
|
|
303
|
+
*/
|
|
304
|
+
clearValueFilter(fieldId: string): Promise<boolean>;
|
|
305
|
+
/**
|
|
306
|
+
* Groups a row or column date field using a Pivot date interval.
|
|
307
|
+
* @param {string} fieldId The source date or existing date-group table-field identifier.
|
|
308
|
+
* @param {PivotDateGroupFieldDateTypeEnum} dateType The requested date interval.
|
|
309
|
+
* @returns {Promise<boolean>} Whether the date group was updated.
|
|
310
|
+
*/
|
|
311
|
+
setDateGroupType(fieldId: string, dateType: PivotDateGroupFieldDateTypeEnum): Promise<boolean>;
|
|
312
|
+
/**
|
|
313
|
+
* Collapses or expands a row hierarchy field or one item.
|
|
314
|
+
* @param {string} fieldId The row table-field identifier.
|
|
315
|
+
* @param {boolean} collapse Whether to collapse the target.
|
|
316
|
+
* @param {string} [item] An optional item key; omit it to target the whole field.
|
|
317
|
+
* @returns {Promise<boolean>} Whether the hierarchy state was updated.
|
|
318
|
+
*/
|
|
319
|
+
setCollapse(fieldId: string, collapse: boolean, item?: string): Promise<boolean>;
|
|
320
|
+
/**
|
|
321
|
+
* Expands the category hierarchy through the requested row field.
|
|
322
|
+
* @param {string} fieldId The deepest row table-field identifier to display.
|
|
323
|
+
* @returns {Promise<boolean>} Whether the category level was updated.
|
|
324
|
+
*/
|
|
325
|
+
setCategoryLevel(fieldId: string): Promise<boolean>;
|
|
326
|
+
/**
|
|
327
|
+
* Returns resolved PivotChart button visibility controls.
|
|
328
|
+
* @returns {DeepReadonly<IPivotChartControls>} A defensive resolved controls snapshot.
|
|
329
|
+
*/
|
|
330
|
+
getControls(): DeepReadonly<IPivotChartControls>;
|
|
331
|
+
/**
|
|
332
|
+
* Sets the current supported Chart type.
|
|
333
|
+
* @param {PivotChartTypeString} type The target supported type.
|
|
334
|
+
* @returns {this} This PivotChart for chaining.
|
|
335
|
+
* @throws If the type is not supported by PivotChart.
|
|
336
|
+
*/
|
|
337
|
+
setType(type: PivotChartTypeString): this;
|
|
338
|
+
/**
|
|
339
|
+
* Sets the Chart title.
|
|
340
|
+
* @param {ChartTitleSpec} value The title specification.
|
|
341
|
+
* @returns {this} This PivotChart for chaining.
|
|
342
|
+
*/
|
|
343
|
+
setTitle(value: ChartTitleSpec): this;
|
|
344
|
+
/**
|
|
345
|
+
* Clears the Chart title.
|
|
346
|
+
* @returns {this} This PivotChart for chaining.
|
|
347
|
+
*/
|
|
348
|
+
clearTitle(): this;
|
|
349
|
+
/**
|
|
350
|
+
* Sets the Chart subtitle.
|
|
351
|
+
* @param {ChartSubtitleSpec} value The subtitle specification.
|
|
352
|
+
* @returns {this} This PivotChart for chaining.
|
|
353
|
+
*/
|
|
354
|
+
setSubtitle(value: ChartSubtitleSpec): this;
|
|
355
|
+
/**
|
|
356
|
+
* Clears the Chart subtitle.
|
|
357
|
+
* @returns {this} This PivotChart for chaining.
|
|
358
|
+
*/
|
|
359
|
+
clearSubtitle(): this;
|
|
360
|
+
/**
|
|
361
|
+
* Sets the Chart legend.
|
|
362
|
+
* @param {ChartLegendSpec} value The legend specification.
|
|
363
|
+
* @returns {this} This PivotChart for chaining.
|
|
364
|
+
*/
|
|
365
|
+
setLegend(value: ChartLegendSpec): this;
|
|
366
|
+
/**
|
|
367
|
+
* Clears the Chart legend.
|
|
368
|
+
* @returns {this} This PivotChart for chaining.
|
|
369
|
+
*/
|
|
370
|
+
clearLegend(): this;
|
|
371
|
+
/**
|
|
372
|
+
* Sets the Chart theme.
|
|
373
|
+
* @param {string} name The registered theme name.
|
|
374
|
+
* @returns {this} This PivotChart for chaining.
|
|
375
|
+
*/
|
|
376
|
+
setTheme(name: string): this;
|
|
377
|
+
/**
|
|
378
|
+
* Clears the Chart theme.
|
|
379
|
+
* @returns {this} This PivotChart for chaining.
|
|
380
|
+
*/
|
|
381
|
+
clearTheme(): this;
|
|
382
|
+
/**
|
|
383
|
+
* Sets an explicit series palette.
|
|
384
|
+
* @param {readonly string[]} colors The series colors.
|
|
385
|
+
* @returns {this} This PivotChart for chaining.
|
|
386
|
+
*/
|
|
387
|
+
setPalette(colors: readonly string[]): this;
|
|
388
|
+
/**
|
|
389
|
+
* Clears the explicit series palette.
|
|
390
|
+
* @returns {this} This PivotChart for chaining.
|
|
391
|
+
*/
|
|
392
|
+
clearPalette(): this;
|
|
393
|
+
/**
|
|
394
|
+
* Sets common Chart appearance.
|
|
395
|
+
* @param {IChartAppearanceSpec} value The appearance overrides.
|
|
396
|
+
* @returns {this} This PivotChart for chaining.
|
|
397
|
+
*/
|
|
398
|
+
setAppearance(value: IChartAppearanceSpec): this;
|
|
399
|
+
/**
|
|
400
|
+
* Clears all or one common Chart appearance property.
|
|
401
|
+
* @param {ChartAppearanceTarget} [target] The property to clear; omit it to clear all appearance overrides.
|
|
402
|
+
* @returns {this} This PivotChart for chaining.
|
|
403
|
+
*/
|
|
404
|
+
clearAppearance(target?: ChartAppearanceTarget): this;
|
|
405
|
+
/**
|
|
406
|
+
* Enables or disables automatic gradient fill.
|
|
407
|
+
* @param {boolean} value Whether automatic gradients are enabled.
|
|
408
|
+
* @returns {this} This PivotChart for chaining.
|
|
409
|
+
*/
|
|
410
|
+
setAutoGradientFill(value: boolean): this;
|
|
411
|
+
/**
|
|
412
|
+
* Restores the default automatic-gradient behavior.
|
|
413
|
+
* @returns {this} This PivotChart for chaining.
|
|
414
|
+
*/
|
|
415
|
+
resetAutoGradientFill(): this;
|
|
416
|
+
/**
|
|
417
|
+
* Sets how invalid Pivot values are rendered.
|
|
418
|
+
* @param {InvalidValueType} value The invalid-value strategy.
|
|
419
|
+
* @returns {this} This PivotChart for chaining.
|
|
420
|
+
*/
|
|
421
|
+
setInvalidValueStrategy(value: InvalidValueType): this;
|
|
422
|
+
/**
|
|
423
|
+
* Restores the default invalid-value strategy.
|
|
424
|
+
* @returns {this} This PivotChart for chaining.
|
|
425
|
+
*/
|
|
426
|
+
resetInvalidValueStrategy(): this;
|
|
427
|
+
/**
|
|
428
|
+
* Merges PivotChart button visibility controls.
|
|
429
|
+
* @param {Partial<IPivotChartControls>} controls The controls to override.
|
|
430
|
+
* @returns {this} This PivotChart for chaining.
|
|
431
|
+
*/
|
|
432
|
+
setControls(controls: Partial<IPivotChartControls>): this;
|
|
433
|
+
/**
|
|
434
|
+
* Shows or hides all Pivot field buttons.
|
|
435
|
+
* @param {boolean} visible Whether field buttons are visible.
|
|
436
|
+
* @returns {this} This PivotChart for chaining.
|
|
437
|
+
*/
|
|
438
|
+
setFieldButtonsVisible(visible: boolean): this;
|
|
439
|
+
/**
|
|
440
|
+
* Shows or hides category hierarchy expand and collapse buttons.
|
|
441
|
+
* @param {boolean} visible Whether expand and collapse buttons are visible.
|
|
442
|
+
* @returns {this} This PivotChart for chaining.
|
|
443
|
+
*/
|
|
444
|
+
setExpandCollapseButtonsVisible(visible: boolean): this;
|
|
445
|
+
/**
|
|
446
|
+
* Sets the worksheet cell anchor of this PivotChart.
|
|
447
|
+
* @param {ChartAnchorSpec} anchor A1 notation or a zero-based row and column anchor.
|
|
448
|
+
* @returns {this} This PivotChart for chaining.
|
|
449
|
+
*/
|
|
450
|
+
setPosition(anchor: ChartAnchorSpec): this;
|
|
451
|
+
/**
|
|
452
|
+
* Sets the absolute worksheet Drawing position.
|
|
453
|
+
* @param {number} x The horizontal position in pixels.
|
|
454
|
+
* @param {number} y The vertical position in pixels.
|
|
455
|
+
* @returns {this} This PivotChart for chaining.
|
|
456
|
+
*/
|
|
457
|
+
setAbsolutePosition(x: number, y: number): this;
|
|
458
|
+
/**
|
|
459
|
+
* Sets the worksheet Drawing size.
|
|
460
|
+
* @param {number} width The width in pixels.
|
|
461
|
+
* @param {number} height The height in pixels.
|
|
462
|
+
* @returns {this} This PivotChart for chaining.
|
|
463
|
+
*/
|
|
464
|
+
setSize(width: number, height: number): this;
|
|
465
|
+
/** Moves this PivotChart to the front. @returns {this} This PivotChart for chaining. */
|
|
466
|
+
bringToFront(): this;
|
|
467
|
+
/** Moves this PivotChart forward by one level. @returns {this} This PivotChart for chaining. */
|
|
468
|
+
bringForward(): this;
|
|
469
|
+
/** Moves this PivotChart backward by one level. @returns {this} This PivotChart for chaining. */
|
|
470
|
+
sendBackward(): this;
|
|
471
|
+
/** Moves this PivotChart to the back. @returns {this} This PivotChart for chaining. */
|
|
472
|
+
sendToBack(): this;
|
|
473
|
+
/**
|
|
474
|
+
* Moves this PivotChart to a zero-based Drawing order index.
|
|
475
|
+
* @param {number} index The target zero-based z-order index.
|
|
476
|
+
* @returns {this} This PivotChart for chaining.
|
|
477
|
+
*/
|
|
478
|
+
setZOrder(index: number): this;
|
|
479
|
+
/**
|
|
480
|
+
* Removes this PivotChart and its worksheet Drawing.
|
|
481
|
+
* @returns {Promise<boolean>} Whether the removal was accepted.
|
|
482
|
+
*/
|
|
483
|
+
remove(): Promise<boolean>;
|
|
484
|
+
private _arrange;
|
|
485
|
+
private _apply;
|
|
486
|
+
private _commit;
|
|
487
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { PivotChartTypeString } from '@univerjs-pro/pivot-chart';
|
|
2
|
+
import type { FLinkedSheetPivotChartBuilderOf } from './f-pivot-chart-builder';
|
|
3
|
+
import { FPivotTable } from '@univerjs-pro/sheets-pivot/facade';
|
|
4
|
+
/** @ignore */
|
|
5
|
+
export interface IFPivotTablePivotChartMixin {
|
|
6
|
+
/**
|
|
7
|
+
* Creates a detached PivotChart Builder permanently linked to this PivotTable.
|
|
8
|
+
*
|
|
9
|
+
* Any Pivot report edit made through the table or one of its linked charts updates the one
|
|
10
|
+
* shared PivotModel. Chart visuals and Drawing placement remain independent per chart.
|
|
11
|
+
*
|
|
12
|
+
* @param {T} type The supported Chart type.
|
|
13
|
+
* @returns {FLinkedSheetPivotChartBuilderOf<T>} A prelinked, source-locked Builder.
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* import '@univerjs-pro/sheets-pivot-chart/facade';
|
|
17
|
+
*
|
|
18
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
19
|
+
* const fWorksheet = fWorkbook.getSheetByName('Dashboard');
|
|
20
|
+
* const fPivotTable = fWorkbook.getPivotTableById('pivot-table-1');
|
|
21
|
+
* if (!fWorksheet || !fPivotTable) throw new Error('Pivot source is unavailable.');
|
|
22
|
+
*
|
|
23
|
+
* const first = await fWorksheet.insertPivotChart(
|
|
24
|
+
* fPivotTable.newChart(univerAPI.Enum.ChartTypeString.Column).setPosition('A1').build()
|
|
25
|
+
* );
|
|
26
|
+
* const second = await fWorksheet.insertPivotChart(
|
|
27
|
+
* fPivotTable.newChart(univerAPI.Enum.ChartTypeString.Line).setPosition('J1').build()
|
|
28
|
+
* );
|
|
29
|
+
* console.log(first.getPivotTableReference(), second.getPivotTableReference());
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
newChart<T extends PivotChartTypeString>(type: T): FLinkedSheetPivotChartBuilderOf<T>;
|
|
33
|
+
}
|
|
34
|
+
/** @ignore */
|
|
35
|
+
export declare class FPivotTablePivotChartMixin extends FPivotTable implements IFPivotTablePivotChartMixin {
|
|
36
|
+
newChart<T extends PivotChartTypeString>(type: T): FLinkedSheetPivotChartBuilderOf<T>;
|
|
37
|
+
}
|
|
38
|
+
declare module '@univerjs-pro/sheets-pivot/facade' {
|
|
39
|
+
interface FPivotTable extends IFPivotTablePivotChartMixin {
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Injector } from '@univerjs/core';
|
|
2
|
+
import { FUniver } from '@univerjs/core/facade';
|
|
3
|
+
/** @ignore */
|
|
4
|
+
export declare class FUniverSheetsPivotChartMixin extends FUniver {
|
|
5
|
+
_initialize(injector: Injector): void;
|
|
6
|
+
private _registerModelEvent;
|
|
7
|
+
private _registerChangedEvent;
|
|
8
|
+
private _fireDrawingChanged;
|
|
9
|
+
private _registerCommandEvent;
|
|
10
|
+
private _fireCommandEvent;
|
|
11
|
+
}
|