UNPKG

@univerjs-pro/engine-pivot

Version:

Pivot table calculation engine for Univer Pro.

171 lines (170 loc) 7.07 kB
import type { IDataFieldInfo, IDataFieldJSON, IDataFieldValue } from '../types'; import { PivotDataFieldDataTypeEnum, PivotDataFieldTypeEnum } from '../types'; /** * Represents a data field in a pivot table , it match the excel pivot cache field data structure. * @param {string} id - The unique identifier of the data field. * @param {string} name - The name of the data field. Almost is the row header of pivot table data source, the custom field such as calculated field or grouped field will have a different name. * @method addRecord - Add a record to the data field. */ export declare class DataField { /** * @property {string} id - The unique identifier of the data field. */ readonly id: string; /** * @property {string} name - The name of the data field. */ name: string; /** * @property {string} hexCode - The hex code of the data field, which is used to create unique path in tuple group. */ hexCode: string; /** * @property {string} rangeKey - The range key of the data field. */ rangeKey: string; /** * @property {IDataFieldValue[]} records - The records of the data field. */ records: IDataFieldValue[]; /** * @property {string[]} items - The items of the data field. */ items: string[]; /** * @property {PivotDataFieldDataTypeEnum[]} itemTypes - The item types of the data field. */ itemTypes: PivotDataFieldDataTypeEnum[]; /** * @property {PivotDataFieldDataTypeEnum} fieldDataType - The data type of the data field. */ private _fieldDataType; /** * @property {boolean} hasInteger - Whether the data field has integer value. this property is used in number group. */ hasInteger: boolean; /** * @property {boolean} hasDecimal - Whether the data field has decimal value. this property is used in number group. */ hasDecimal: boolean; /** * @property {boolean} hasDate - Whether the data field has date value. this property is used in date group. */ hasDate: boolean; /** * @property {boolean} hasBlank - Whether the data field has blank value. The blank value is represented by a placeholder in Pivot table. in en-us locale, the placeholder is "(blank)". */ hasBlank: boolean; /** * @property {boolean} hasText - Whether the data field has text value. */ hasText: boolean; /** * @property {string} format - The format of the data field. only date field has format property, the format is the date format string. */ format: string; /** * @property {number} maxNumber - The max number of the data field. this property is used in number group to set the max value of the number group. */ maxNumber: number; /** * @property {number} minNumber - The min number of the data field. this property is used in number group to set the min value of the number group. */ minNumber: number; /** * @property {number} maxDate - The max date of the data field. this property is used in date group to set the max value of the date group. */ maxDate: number; /** * @property {number} minDate - The min date of the data field. this property is used in date group to set the min value of the date group. */ minDate: number; /** * @property {Record<string, number>} - The index of the items in the data field. */ private _itemIndexMap; /** * @property {Record<string, number[]>} itemsMap -Save the index of the items in the data field. The key is the item key, the value is the index array of the item in the data field. */ private _itemsMap; private _keyCounter; constructor(id: string, name: string, hexCode: string); /** * - Returns the name of the data field. * @returns {string} the range key of the data field. */ getRangeKey(): string; getformat(): string; /** * - set the range key of the data field. * @param {string} rangeKey the range key of the data field. */ setRangeKey(rangeKey: string): void; getId(): string; getName(): string; setName(name: string): void; /** * - if the field contains date value and blank only, the field data type is date. if the field contains number value and blank only, the field data type is number. otherwise, the field data type is text. * @returns {string} the name of the data field. */ getFieldDataType(): PivotDataFieldDataTypeEnum; /** * get field type, used to distinguish between group field and data field, the original data field type is normal field. * @returns {PivotDataFieldTypeEnum} the data field type */ getDataFieldType(): PivotDataFieldTypeEnum; /** * - Returns the shared key with the data field item, this can be combined in the tuple group with other data field item key to create a unique path. * @param {string} dataIndex the index in data records * @returns {string} key with field and item info */ getItemSharedKey(key: string): string; /** * - Returns the key of the data field item. the key logic should be same with addRecord method. * @param {number} index - the index of data records * @returns {string} The key of the data field item. */ getItemKey(index: number): string; /** * - get the type of date by key * @param {string} key - the key of the data field item. * @returns {PivotDataFieldDataTypeEnum} the data type */ getTypeByKey(key: string): PivotDataFieldDataTypeEnum; /** * - Returns the value of the data field record * @param {number} index - The index of the data field record. * @returns {IDataFieldValue} - The value of the data field record. */ getValue(index: number): IDataFieldValue; /** * @description Add a record to the data field. * @param {IDataFieldValue} record - The record to be added. * @param {number} index - The index of the record. * @returns {void} */ addRecord(record: IDataFieldValue, index: number): void; getIndexesByKey(key: string): number[]; getAllIndexMap(): Record<string, number[]>; /** * @description Update the item key in the data field. * @param {IDateValue} record - The date value. * @param {number} index - The index of the record. * @returns {void} */ private _updateDateItemKey; private _updateBlankItemKey; private _updateStringItemKey; private _updateNumberItemKey; private _updateOtherItemKey; private _updateItemKey; getItemsMap(): Record<string, number>; /** * @description Get the data field info for pivot table, some properties are not included in the data field info because they are not necessary for the pivot table. only the import/export need them. * @returns {IDataFieldInfo} The data field info. */ getFieldInfo(): IDataFieldInfo; toJSON(): IDataFieldJSON; fromJSON(data: IDataFieldJSON): void; reset(): void; }