@mindfiredigital/pivothead
Version:
PivotHead is a powerful and flexible library for creating interactive pivot tables in JavaScript applications. It provides a core engine for data manipulation and, in the future, will be compatible with wrappers for React, Vue, Svelte, and Angular, making
253 lines • 8.41 kB
TypeScript
import { AggregationType, Dimension, Group, GroupConfig, MeasureConfig, PivotTableConfig, PivotTableState, FilterConfig, PaginationConfig } from '../types/interfaces';
/**
* Creates an instance of PivotEngine.
* @param {PivotTableConfig<T>} config - The configuration for the pivot table.
*/
export declare class PivotEngine<T extends Record<string, any>> {
private config;
private state;
private filterConfig;
private paginationConfig;
constructor(config: PivotTableConfig<T>);
private validateConfig;
private initializeState;
/**
* Loads data from a file or URL.
**/
private loadData;
/**
* Loads data from a file or URL.
* @param {File | string} source - The file or URL to load data from.
* @public
* @returns {Promise<void>} A promise that resolves when the data is loaded.
**/
private fetchRemoteData;
/**
* Process the data to be displayed in the table.
* @param {T[]} data - The data to process.
* @returns {ProcessedData} The processed data including headers, rows, and totals.
* @private
**/
private readFileData;
/**
* Initializes row sizes for the pivot table.
* @param {T[]} data - The data to initialize row sizes for.
* @returns {RowSize[]} An array of row sizes.
* @private
*/
private initializeRowSizes;
/**
* Processes the data for the pivot table.
* @param {T[]} data - The data to process.
* @returns {ProcessedData} The processed data including headers, rows, and totals.
* @private
*/
private processData;
/**
* Generates headers for the pivot table.
* @returns {string[]} An array of header strings.
* @private
*/
private generateHeaders;
/**
* Generates rows for the pivot table.
* @param {T[]} data - The data to generate rows from.
* @returns {any[][]} A 2D array representing the rows.
* @private
*/
private generateRows;
/**
* Calculates the value for a specific measure.
* @param {T} item - The data item.
* @param {MeasureConfig} measure - The measure configuration.
* @returns {number} The calculated measure value.
* @private
*/
private calculateMeasureValue;
/**
* Calculates totals for each measure in the pivot table.
* @param {T[]} data - The data to calculate totals from.
* @returns {Record<string, number>} An object with measure names as keys and their totals as values.
* @private
*/
private calculateTotals;
/**
* Sets the measures for the pivot table.
* @param {MeasureConfig[]} measureFields - The measure configurations to set.
* @public
*/
setMeasures(measureFields: MeasureConfig[]): void;
/**
* Sets the dimensions for the pivot table.
* @param {Dimension[]} dimensionFields - The dimension configurations to set.
* @public
*/
setDimensions(dimensionFields: Dimension[]): void;
/**
* Sets the aggregation type for the pivot table.
* @param {AggregationType} type - The aggregation type to set.
* @public
*/
setAggregation(type: AggregationType): void;
/**
* Formats a value based on the specified field's format.
* @param {any} value - The value to format.
* @param {string} field - The field name to use for formatting.
* @returns {string} The formatted value as a string.
* @public
*/
formatValue(value: any, field: string): string;
/**
* Sorts the pivot table data based on the specified field and direction.
* @param {string} field - The field to sort by.
* @param {'asc' | 'desc'} direction - The sort direction.
* @public
*/
sort(field: string, direction: 'asc' | 'desc'): void;
private applySort;
private sortData;
private getFieldValue;
private sortGroups;
/**
* Updates aggregates for all groups in the pivot table.
* @private
*/
private updateAggregates;
/**
* Applies grouping to the pivot table data.
* @private
*/
private applyGrouping;
/**
* Creates groups based on the specified fields and grouper function.
* @param {T[]} data - The data to group.
* @param {string[]} fields - The fields to group by.
* @param {(item: T, fields: string[]) => string} grouper - The grouping function.
* @returns {Group[]} An array of grouped data.
* @private
*/
private createGroups;
/**
* Sets the group configuration for the pivot table.
* @param {GroupConfig | null} groupConfig - The group configuration to set.
* @public
*/
setGroupConfig(groupConfig: GroupConfig | null): void;
/**
* Returns the grouped data.
* @returns {Group[]} An array of grouped data.
* @public
*/
getGroupedData(): Group[];
/**
* Returns the current state of the pivot table.
* @returns {PivotTableState<T>} The current state of the pivot table.
* @public
*/
getState(): PivotTableState<T>;
/**
* Resets the pivot table to its initial state.
* @public
*/
reset(): void;
/**
* Resizes a specific row in the pivot table.
* @param {number} index - The index of the row to resize.
* @param {number} height - The new height for the row.
* @public
*/
resizeRow(index: number, height: number): void;
/**
* Toggles the expansion state of a row.
* @param {string} rowId - The ID of the row to toggle.
* @public
*/
toggleRowExpansion(rowId: string): void;
/**
* Checks if a row is expanded.
* @param {string} rowId - The ID of the row to check.
* @returns {boolean} True if the row is expanded, false otherwise.
* @public
*/
isRowExpanded(rowId: string): boolean;
/**
* Handles dragging a row to a new position.
* @param {number} fromIndex - The original index of the row.
* @param {number} toIndex - The new index for the row.
* @public
*/
dragRow(fromIndex: number, toIndex: number): void;
/**
* Handles dragging a column to a new position.
* @param {number} fromIndex - The original index of the column.
* @param {number} toIndex - The new index for the column.
* @public
*/
dragColumn(fromIndex: number, toIndex: number): void;
private validateDragOperation;
/**
* Applies filters to the data
* @param {FilterConfig[]} filters - Array of filter configurations
* @public
*/
applyFilters(filters: FilterConfig[]): void;
/**
* Sets pagination configuration
* @param {PaginationConfig} config - Pagination configuration
* @public
*/
setPagination(config: PaginationConfig): void;
/**
* Refreshes data with current filters and pagination
* @private
*/
private refreshData;
/**
* Filters data based on filter configuration
* @param {T[]} data - Data to filter
* @private
*/
private filterData;
/**
* Paginates data based on pagination configuration
* @param {T[]} data - Data to paginate
* @private
*/
private paginateData;
/**
* Gets current pagination state
* @returns {PaginationConfig} Current pagination configuration
* @public
*/
getPaginationState(): PaginationConfig;
/**
* Gets current filter state
* @returns {FilterConfig[]} Current filter configuration
* @public
*/
getFilterState(): FilterConfig[];
/**
* Exports the pivot table data to HTML and downloads the file.
* @param {string} fileName - The name of the downloaded file (without extension).
* @public
*/
exportToHTML(fileName?: string): void;
/**
* Exports the pivot table data to PDF and downloads the file.
* @param {string} fileName - The name of the downloaded file (without extension).
* @public
*/
exportToPDF(fileName?: string): void;
/**
* Exports the pivot table data to Excel and downloads the file.
* @param {string} fileName - The name of the downloaded file (without extension).
* @public
*/
exportToExcel(fileName?: string): void;
/**
* Opens a print dialog with the formatted pivot table.
* @public
*/
openPrintDialog(): void;
}
//# sourceMappingURL=pivotEngine.d.ts.map