UNPKG

@univerjs-pro/engine-pivot

Version:

Pivot table calculation engine for Univer Pro.

292 lines (291 loc) 14.1 kB
import type { DataField } from '../field/data-field'; import type { FieldsCollection } from '../field/fields-collection'; import type { PivotView } from '../layout/pivot-view'; import type { IPivotTableChangeSet, IPivotTableFilterInfo, IPivotTableOptions, IPivotTableQueryData, IPivotTableSnapshot, IPivotTableSortInfo, IPivotTableValueFilter, PivotTableFiledAreaEnum, PivotTableValuePositionEnum } from '../types'; import { PivotCallbackEnum, PivotDataFieldDataTypeEnum, PivotSubtotalTypeEnum } from '../types'; import { PivotModel } from './model'; import { PivotTableLabelField, PivotTableValueField } from './table-field'; /** * @class PivotTable - represents the wrapper class pivot table. * @description The pivot table is a wrapper class which references the data fields collection and pivot table model. * @implements IPivotTable */ export declare class PivotTable { dataFieldsCollection: FieldsCollection; private _viewVersion; private _model; _bufferModel: PivotModel; private _tupleGroupCache; private _id; private static _callbacks; /** * Register callback functions that are executed at certain times * @param {PivotCallbackEnum} event - Enumeration of execution time * @param {(id?: string) => void} callback - Callback Function */ static registerCallbackWithEvent(event: PivotCallbackEnum, callback: (id?: string) => void): void; /** * Unregisters the callback function from the specified event. * @param {PivotCallbackEnum} event - Enumeration of execution time * @param {(id?: string) => void} callback - Callback Function */ static unRegisterCallbackWithEvent(event: PivotCallbackEnum, callback: (id?: string) => void): void; constructor(dataFieldsCollection: FieldsCollection, model?: PivotModel, id?: string); updateDataFieldsCollection(dataFieldsCollection: FieldsCollection): void; private _getModel; startCollectChangeset(): void; endCollectChangeset(): IPivotTableChangeSet[]; _generateModel(): void; createLabelFieldByDataFieldId(dataFieldId: string, tableName?: string, provideTableFieldId?: string): PivotTableLabelField | undefined; createValueFieldByDataFieldId(dataFieldId: string, provideTableFieldId?: string): PivotTableValueField | undefined; updateValuePosition(valuePosition: PivotTableValuePositionEnum, valueIndex: number): void; isColMultiMeasure(): boolean; isRowMultiMeasure(): boolean; /** * get the order index of ΣValue in row or col * @returns {number} -1 means not exist, otherwise the index of the ΣValue */ getValueIndex(): number; /** * - get the value position * @returns {PivotTableValuePositionEnum} the value position, only row or column */ getValuePosition(): PivotTableValuePositionEnum; /** * - iterate all pivot table fields * @param {(field: PivotTableLabelField | PivotTableValueField) => void} callback the callback function */ iterateField(callback: (field: PivotTableLabelField | PivotTableValueField) => void): void; /** * - iterate the dimension field, it means all the label fields * @param {(field: PivotTableLabelField | PivotTableValueField) => void} callback the callback function */ iterateFieldDim(callback: (field: PivotTableLabelField) => void): void; /** * - iterate the field by the area * @param {PivotTableFiledAreaEnum} area the area of the field enum * @param {(field: PivotTableLabelField | PivotTableValueField) => void} callback the callback function */ iterateFieldByArea(area: PivotTableFiledAreaEnum, callback: (field: PivotTableLabelField | PivotTableValueField) => void): void; /** * - get how many fields in the area * @param {PivotTableFiledAreaEnum} area - the area of the field enum * @returns {number} the field count */ getFieldCountByArea(area: PivotTableFiledAreaEnum): number; getValueFields(): string[]; /** * - get a unique field name in the pivot table * @param {string} autoName the given field name * @returns {string} the unique field name */ getUniqueValueFieldName(autoName: string): string; /** * - get the data field by the table field id * @param {string} tableField - the table field id * @returns {DataField|undefined} the data field or undefined */ getDataFieldByTableId(tableField: string): DataField | undefined; /** * - get all the table fields by use the data field id * @param dataFieldId * @returns {string[]} the table field ids */ getTableFieldsByDataFieldId(dataFieldId: string): (PivotTableLabelField | PivotTableValueField)[]; /** * - get the table field by the table field id * @param {string} tableFieldId - the table field id * @returns {PivotTableLabelField | PivotTableValueField | undefined} the table field or undefined */ getTableFieldById(tableFieldId: string): PivotTableLabelField | PivotTableValueField | undefined; /** * - check the field is exist in the pivot table or not * @param {string} tableFieldId the check field id * @returns {boolean} exist or not */ isExistField(tableFieldId: string): boolean; /** * - get the pivot table is empty or not * @returns {boolean} empty or not */ isEmpty(): boolean; /** * - get the data field by the data field id * @param {string} dataFieldId the data field id * @returns {DataField|undefined} the data field or undefined */ getDataFieldByDataFieldId(dataFieldId: string): DataField | undefined; /** * - get the data field id by the display name * @param {string} name - the display name of the data field. * @returns {string | undefined} - the data fieldId corresponding to the display name, or undefined if not found. */ getDataFieldIdByDisplayName(name: string): string | undefined; /** * - get all display names of the data fields * @returns {string[]} the all display names of the data fields */ getFieldDisplayNames(): string[]; getDataFieldItemInfo(dataField: DataField): { items: string[]; itemTypes: PivotDataFieldDataTypeEnum[]; }; getUniqueFieldId(): string; /** * - add a field to the pivot table by the source name , if the field is a measure field, it will be use auto name. * @param {string} dataFieldId data field name * @param {PivotTableFiledAreaEnum} area the area of the added field * @param {number} [index] the position of the field in the area, if not set, the field will be added to the end of the area. * @returns {PivotTableLabelField|PivotTableValueField} the added field */ addFieldWithSourceId(dataFieldId: string, area: PivotTableFiledAreaEnum, index?: number, provideTableFieldId?: string): PivotTableLabelField | PivotTableValueField | undefined; setOptions(options: IPivotTableOptions): void; /** * the func is only use for when refresh * @param {string} fieldId the table field id * @param {string} sourceName the source name of the field * @param {string} dataFieldId the data field id */ updateFieldSourceInfo(fieldId: string, sourceName: string, dataFieldId: string): void; /** * - Set the subtotal type of the field. only the value field can set the subtotal type. only effective for the value field. * @param {string} fieldId - The id of the field. * @param {PivotSubtotalTypeEnum} subtotalType - The subtotal type of the field. */ setSubtotalType(fieldId: string, subtotalType: PivotSubtotalTypeEnum): void; /** * - Rename the field. * @param {string} fieldId - The id of the field. * @param {string} displayName - The display name of the field. */ renameField(fieldId: string, displayName: string): void; /** * - Set the filter information of the dimension field. only the dimension field can set the filter information. * @param fieldId * @param filterInfo */ setLabelFilterInfo(fieldId: string, filterInfo: IPivotTableFilterInfo): void; /** * - Set the sort information of the dimension field. only the dimension field can set the sort information. * @param {string} fieldId - The id of the field. * @param {IPivotTableSortInfo} sortInfo - The sort information of the field. */ setSortInfo(fieldId: string, sortInfo: IPivotTableSortInfo | undefined): void; /** * - get the sort information of the dimension field. * @param fieldId - The id of the field. * @returns {IPivotTableSortInfo} -The sort information of the field. */ getSortInfo(fieldId: string): IPivotTableSortInfo | undefined; getFilterInfo(fieldId: string): IPivotTableFilterInfo | undefined; /** * get the filter information by the filter index * @param {number} index - The index of the filter field. * @returns {string | undefined} the table field id */ getFilterFieldIdByIndex(index: number): string | undefined; /** * - set the position of the field in the pivot table. which used in pivot panel drag field. * @param {string} fieldId - The id of the pivot table field. * @param {PivotTableFiledAreaEnum} area which area the field will be placed. * @param {number} index the index of the field in the area. */ updateFieldPosition(fieldId: string, area: PivotTableFiledAreaEnum, index: number): void; /** * - get a format for pivot table field, which will be applied in the pivot table view. the label field will use the format to format the date value. * @description when a show data as type is selected, we should set the format for the field. * @param {string} fieldId -the field id * @returns {string} the field format code */ getFieldFormat(fieldId: string): string | undefined; /** * - set the format for pivot table field, which will be applied in the pivot table view. the label field will use the format to format the date value. * @description when a show data as type is selected, we should set the format for the field. a label field which contains the date value should set the format. * @param {string} fieldId * @param {string|undefined} format */ setFieldFormat(fieldId: string, format: string | undefined): void; /** * - add a field to the pivot table * @param field * @param area * * @example * ```typescript * const pt= new PivotTable(fieldsCollection); * var areaField = pt.addFieldWithSourceName('区域', PivotTableFiledAreaEnum.Column); * pt.addFieldWithSourceName('省份', PivotTableFiledAreaEnum.Filter); * ``` */ addField(field: PivotTableLabelField | PivotTableValueField, area: PivotTableFiledAreaEnum, index?: number): void; removeField(fieldId: string): void; getOptions(): IPivotTableOptions; /** * @description Set the collapse status of the field. Those properties are used to save the collapse status of the field in the pivot table. * @param {string} fieldId - The id of the field. * @param {boolean} collapse - The collapse status of the field. * @param {string} [item] - The item of the field. */ setCollapse(fieldId: string, collapse: boolean, item?: string): void; /** * - get the pivot view need query or not * @param {number} viewVersion * @returns {boolean} - need query or not */ getNeedQuery(viewVersion: number): boolean; /** * @description Get the field position information by the field id. * @param {string} fieldId the field id * @returns {PositionInfo} - The position information of the field or undefined. */ getFieldPositionInfoById(fieldId: string): { area: PivotTableFiledAreaEnum | undefined; index: number; }; private _getTupleCache; private _getGroupInfo; /** * Set the value filter information of the pivot table. * @param {string} fieldId The base label field id of the value filter. * @param {IPivotTableValueFilter} filterInfo The value filter information. */ setValueFilterInfo(fieldId: string, filterInfo: IPivotTableValueFilter | undefined): void; /** * Get the value filter information list of the pivot table. * @returns {IPivotTableValueFilter[]} The value filter information list. */ getValueFilterInfos(): import("..").IValueFilterInfoItem[]; /** * Get the value filter information of the pivot table by the field id. * @param {string} fieldId The base label field id of the value filter. * @returns {IPivotTableValueFilter | undefined} The value filter information. */ getValueFilterInfo(fieldId: string): IPivotTableValueFilter | undefined; /** * Remove the value filter information of the pivot table by the field id. * @param fieldId */ removeValueFilterInfo(fieldId: string): void; /** * Remove the value filter information of the pivot table by the value field id. * @param {string} valueFieldId The value field id of the value filter. */ removeValueFilterInfoByValueFieldId(valueFieldId: string): void; /** * Find the tupleItem in the cache that matches the position order according to the passed array, * and after obtaining the row number array marked on it, * summarize and sort to get all the relevant source data rows * * The key point here is that `dimensionIdList` and `dimensionTableIdList` are one-to-one index corresponding * * @param {string[][]} tuple -A two-dimensional array with path and tableFieldId * @returns {number[]} -Sorted row numbers */ getIndexesByPathStr(tuple: string[][]): number[]; setDirty(dirty: boolean): void; reset(area?: PivotTableFiledAreaEnum): void; query(config?: IPivotTableQueryData): PivotView; toJSON(): IPivotTableSnapshot; fromJSON(data: IPivotTableSnapshot): void; dispose(): void; }