import type GridModel from './GridModel'; import type { GridMetrics, BoxCoordinates, Coordinate, CoordinateMap, VisibleIndex, VisibleToModelMap, ModelIndex, ModelSizeMap, MoveOperation, SizeMap } from './GridMetrics'; import { type GridFont, type GridTheme } from './GridTheme'; import { type DraggingColumn } from './mouse-handlers/GridColumnMoveMouseHandler'; export { getOrThrow } from '@deephaven/utils'; export interface GridMetricState { left: VisibleIndex; top: VisibleIndex; leftOffset: Coordinate; topOffset: Coordinate; width: number; height: number; context: CanvasRenderingContext2D; theme: GridTheme; model: GridModel; movedColumns: readonly MoveOperation[]; movedRows: readonly MoveOperation[]; isDraggingHorizontalScrollBar: boolean; isDraggingVerticalScrollBar: boolean; draggingColumn: DraggingColumn | null; } /** * Trim the provided map in place. Trims oldest inserted items down to the target size if the cache size is exceeded. * Instead of trimming one item on every tick, we trim half the items so there isn't a cache clear on every new item. * @param map The map to trim * @param cacheSize The maximum number of elements to cache * @param targetSize The number of elements to reduce the cache down to if `cacheSize` is exceeded */ export declare function trimMap(map: Map, cacheSize?: number, targetSize?: number): void; /** * Get the coordinates of floating items in one dimension. * Can be used for getting the y coordinates of floating rows, or x coordinates of floating columns, calculated using the `sizeMap` passed in. * @param startCount The number of floating items at the start (ie. `floatingTopRowCount` for rows, `floatingLeftColumnCount` for columns) * @param endCount The number of floating items at the end (ie. `floatingBottomRowCount` for rows, `floatingRightColumnCount` for columns) * @param totalCount Total number of items in this dimension (ie. `rowCount` for rows, `columnCount` for columns) * @param max The max coordinate value (ie. `maxY` for rows, `maxX` for columns) * @param sizeMap Map from index to size of item (ie. `rowHeightMap` for rows, `columnWidthMap` for columns) */ export declare function getFloatingCoordinates(startCount: number, endCount: number, totalCount: number, max: number, sizeMap: SizeMap): CoordinateMap; /** * Class to calculate all the metrics for drawing a grid. * Call getMetrics() with the state to get the full metrics. * Override this class and override the individual methods to provide additional functionality. */ export declare class GridMetricCalculator { /** The size of the caches this calculator stores */ static CACHE_SIZE: number; /** The maximum column width as a percentage of the full grid */ static MAX_COLUMN_WIDTH: number; /** The initial row heights if any overrides from the default calculated values */ initialRowHeights: ReadonlyMap; /** The initial column widths if any overrides from the default calculated values */ initialColumnWidths: ReadonlyMap; /** User set column widths */ protected userColumnWidths: ModelSizeMap; /** User set row heights */ protected userRowHeights: ModelSizeMap; /** Calculated column widths based on cell contents and caching largest value */ protected calculatedColumnWidths: ModelSizeMap; /** Calculated row heights based on cell contents and caching largest value */ protected calculatedRowHeights: ModelSizeMap; /** Calculated column widths based on cell contents */ protected contentColumnWidths: ModelSizeMap; /** Calculated row heights based on cell contents */ protected contentRowHeights: ModelSizeMap; /** Cache of fonts to estimated width of the smallest char */ protected fontWidthsLower: Map; /** Cache of fonts to estimated width of the largest char */ protected fontWidthsUpper: Map; /** Cache of fonts to width of all chars */ protected allCharWidths: Map>; /** Map from visible index to model index for rows (e.g. reversing movedRows operations) */ protected modelRows: VisibleToModelMap; /** Map from visible index to model index for columns (e.g. reversing movedColumns operations) */ protected modelColumns: VisibleToModelMap; /** List of moved row operations. Need to track the previous value so we know if modelRows needs to be cleared. */ protected movedRows: readonly MoveOperation[]; /** List of moved column operations. Need to track the previous value so we know if modelColumns needs to be cleared. */ protected movedColumns: readonly MoveOperation[]; constructor({ userColumnWidths, userRowHeights, calculatedColumnWidths, calculatedRowHeights, contentColumnWidths, contentRowHeights, fontWidthsLower, fontWidthsUpper, allCharWidths, modelRows, modelColumns, movedRows, movedColumns, initialRowHeights, initialColumnWidths, }?: { userColumnWidths?: Map | undefined; userRowHeights?: Map | undefined; calculatedColumnWidths?: Map | undefined; calculatedRowHeights?: Map | undefined; contentColumnWidths?: Map | undefined; contentRowHeights?: Map | undefined; fontWidthsLower?: Map | undefined; fontWidthsUpper?: Map | undefined; allCharWidths?: Map | undefined; modelRows?: Map | undefined; modelColumns?: Map | undefined; movedRows?: readonly MoveOperation[] | undefined; movedColumns?: readonly MoveOperation[] | undefined; initialRowHeights?: Map | undefined; initialColumnWidths?: Map | undefined; }); /** * Get the metrics for the provided metric state * @params state The state to get metrics for * @returns The full metrics */ getMetrics(state: GridMetricState): GridMetrics; /** * The x offset of the grid * @param state The current grid state * @returns x value of the left side of the first cell */ getGridX(state: GridMetricState): Coordinate; /** * The y offset of the grid * @param state The current grid state * @returns y value of the top side of the first cell */ getGridY(state: GridMetricState): Coordinate; /** * The height of the "visible" area (excludes floating areas) * @param state The current grid state * @param visibleRowHeights All the visible row heights * @returns The visible height in pixels */ getVisibleHeight(state: GridMetricState, visibleRowHeights?: SizeMap): number; /** * The width of the "visible" area (excludes floating areas) * @param state The current grid state * @param visibleColumnWidths All the visible column widths * @returns The visible width in pixels */ getVisibleWidth(state: GridMetricState, visibleColumnWidths?: SizeMap): number; /** * Retrieve the index of the first non-hidden item * @param itemSizes The size of the items in this dimension * @param getModelIndex A function to map from the Index to the ModelIndex * @param state The current grid state * @returns The first item that is not hidden */ getFirstIndex(itemSizes: ModelSizeMap, getModelIndex: (visibleIndex: VisibleIndex, state: GridMetricState) => ModelIndex, state: GridMetricState): VisibleIndex; /** * Get the first column index that isn't hidden * @param state The current grid state * @returns The first column that is not hidden */ getFirstColumn(state: GridMetricState): VisibleIndex; /** * Get the first row index that isn't hidden * @param state The current grid state * @returns The first row that is not hidden */ getFirstRow(state: GridMetricState): VisibleIndex; /** * Get the last column that can be the left most column (e.g. scrolled to the right) * If no right column is provided, then the last column is used. * @param state The current grid state * @param right The right-most column to be visible, or null to default to last cell * @param visibleWidth The width of the "visible" area (excluding floating items) * @returns The index of the last left visible column */ getLastLeft(state: GridMetricState, right: VisibleIndex | null, visibleWidth: number): VisibleIndex; /** * The last row that can be the top row (e.g. scrolled to the bottom) * If no bottom row is provided, then the last row that is not floating is used * @param state The current grid state * @param bottom The bottom-most row to be visible, or null to default to last cell * @param visibleHeight The height of the "visible" area (excluding floating items) * @returns The index of the last top visible row */ getLastTop(state: GridMetricState, bottom: VisibleIndex | null, visibleHeight: number): VisibleIndex; /** * Retrieve the top row to scroll to so the passed in `topVisible` is completely visible, taking the floating rows into account. * The `top` row is at the top underneath any floating rows, whereas `topVisible` is visible below the floating rows. * If there are no floating rows, they should be the same value. * @param state The grid metric state * @param topVisible The top row to be visible * @returns The index of the top row to scroll to (under the floating top rows) */ getTopForTopVisible(state: GridMetricState, topVisible: VisibleIndex): VisibleIndex; /** * Retrieve the top row to scroll to so the passed in `bottomVisible` is completely visible * at the bottom of the visible viewport, taking the floating rows into account. * @param state The grid metric state * @param bottomVisible The bottom row to be visible * @returns The index of the top row to scroll to (under the floating top rows) */ getTopForBottomVisible(state: GridMetricState, bottomVisible: VisibleIndex): VisibleIndex; /** * Retrieve the left column to scroll to so the passed in `leftVisible` is completely visible * at the left of the visible viewport, taking the floating columns into account. * @param state The grid metric state * @param leftVisible The left column to be visible * @returns The index of the left column to scroll to (under the floating left columns) */ getLeftForLeftVisible(state: GridMetricState, leftVisible: VisibleIndex): VisibleIndex; /** * Retrieve the left column to scroll to so the passed in `rightVisible` is completely visible * at the right of the visible viewport, taking the floating columns into account. * @param state The grid metric state * @param rightVisible The right column to be visible * @returns The index of the left column to scroll to (under the floating left columns) */ getLeftForRightVisible(state: GridMetricState, rightVisible: VisibleIndex): VisibleIndex; /** * Retrieve a map of the height of each floating row * @param state The grid metric state * @returns The heights of all the floating rows */ getFloatingRowHeights(state: GridMetricState): SizeMap; /** * Retrieve a map of the height of all the visible rows (non-floating) * @param state The grid metric state * @returns The heights of all the visible rows */ getVisibleRowHeights(state: GridMetricState): SizeMap; /** * Retrieve a map of the width of each floating column * @param state The grid metric state * @param firstColumn The first non-hidden column * @param treePaddingX The amount of padding taken up for the tree expansion buttons * @returns The widths of all the floating columns */ getFloatingColumnWidths(state: GridMetricState, firstColumn?: VisibleIndex, treePaddingX?: number): SizeMap; /** * Retrieve a map of the width of all the visible columns (non-floating) * @param state The grid metric state * @returns The widths of all the visible columns and an array of visible, non-hidden columns */ getVisibleColumnWidths(state: GridMetricState, firstColumn?: VisibleIndex, treePaddingX?: number): [SizeMap, VisibleIndex[]]; /** * Retrieve a map of all the floating columns to their x coordinate * @param state The grid metric state * @param columnWidthMap Map from visible index to column width * @param maxX The maximum X size for the grid * @returns Map of the x coordinate of all floating columns */ getFloatingColumnXs(state: GridMetricState, columnWidthMap: SizeMap, maxX: Coordinate): CoordinateMap; /** * Retrieve a map of all the visible columns to their x coordinate. * Starts at leftOffset with the first index in `visibleColumns`, then * calculates all the coordinates from there * @param visibleColumnWidths Map of visible column index to widths * @param visibleColumns All visible columns * @param leftOffset The left scroll offset * @returns Map of the x coordinate of all visible columns */ getVisibleColumnXs(visibleColumnWidths: SizeMap, visibleColumns: VisibleIndex[], leftOffset: number): CoordinateMap; /** * Retrieve a map of all the floating rows to their y coordinate * @param state The grid metric state * @param rowHeightMap Map of visible index to row height * @param maxY The maximum Y size for the grid * @returns Map of the y coordinate of all floating rows */ getFloatingRowYs(state: GridMetricState, rowHeightMap: SizeMap, maxY: Coordinate): CoordinateMap; /** * Retrieve a map of all the visible rows to their y coordinate. * Starts at topOffset with the first index in `visibleRows`, then * calculates all the coordinates from there * @param visibleRowHeights Map of visible row index to heights * @param visibleRows All visible rows * @param topOffset The top scroll offset * @returns Map of the y coordinate of all visible rows */ getVisibleRowYs(visibleRowHeights: SizeMap, visibleRows: VisibleIndex[], topOffset: number): CoordinateMap; /** * Calculates the tree box click areas that are visible. In relation to the columnX/rowY * @param visibleRowHeights Map of visible index to row height * @param modelRows Map from visible `Index` to `ModelIndex` * @param state The grid metric state * @returns Coordinates of tree boxes for each row */ getVisibleRowTreeBoxes(visibleRowHeights: SizeMap, modelRows: VisibleToModelMap, state: GridMetricState): Map; /** * Get the total width of the floating columns on the left * @param state The grid metric state * @param columnWidths Map of column index to width * @returns The total width of the floating left section */ getFloatingLeftWidth(state: GridMetricState, columnWidths?: SizeMap): number; /** * Get the total width of the floating columns on the right * @param state The grid metric state * @param columnWidths Map of column index to width * @returns The total width of the floating right section */ getFloatingRightWidth(state: GridMetricState, columnWidths?: SizeMap): number; /** * Get the total height of the floating rows on the top * @param state The grid metric state * @param rowHeights Map of row index to height * @returns The total height of the floating top section */ getFloatingTopHeight(state: GridMetricState, rowHeights?: SizeMap): number; /** * Get the total height of the floating rows on the bottom * @param state The grid metric state * @param rowHeights Map of row index to height * @returns The total height of the floating bottom section */ getFloatingBottomHeight(state: GridMetricState, rowHeights?: SizeMap): number; /** * Retrieve the index of the first fully visible row in the "visible" viewport of the grid. * E.g. First row visible after the floating rows, provided the visible rows. * @param state The grid metric state * @param visibleRowYs Map of row index to y coordinate * @param visibleRowHeights Map of row index to height * @param visibleRows Array of visible row indexes * @returns Index of the top visible row */ getTopVisible(state: GridMetricState, visibleRowYs: CoordinateMap, visibleRowHeights: SizeMap, visibleRows: VisibleIndex[]): VisibleIndex; /** * Retrieve the index of the first fully visible column in the "visible" viewport of the grid. * E.g. First column visible after the floating columns, provided the visible columns. * @param state The grid metric state * @param visibleColumnXs Map of column index to x coordinate * @param visibleColumnWidths Map of column index to widths * @param visibleColumns Array of visible row indexes * @returns Index of the left visible column */ getLeftVisible(state: GridMetricState, visibleColumnXs: CoordinateMap, visibleColumnWidths: SizeMap, visibleColumns: VisibleIndex[]): VisibleIndex; /** * Retrieve the index of the last fully visible row in the "visible" viewport of the grid. * E.g. Last row visible before the bottom floating rows, provided the visible rows. * @param state The grid metric state * @param visibleRowYs Map of row index to y coordinate * @param visibleRowHeights Map of row index to height * @param visibleRows Array of visible row indexes * @param gridY The starting y coordinate of the grid * @returns Index of the bottom visible row */ getBottomVisible(state: GridMetricState, visibleRowYs: CoordinateMap, visibleRowHeights: SizeMap, visibleRows: VisibleIndex[], gridY: Coordinate): VisibleIndex; /** * Retrieve the index of the last fully visible column in the "visible" viewport of the grid. * E.g. Last column visible before the floating columns, provided the visible columns. * @param state The grid metric state * @param visibleColumnXs Map of column index to x coordinate * @param visibleColumnWidths Map of column index to widths * @param visibleColumns Array of visible column indexes * @returns Index of the right visible column */ getRightVisible(state: GridMetricState, visibleColumnXs: CoordinateMap, visibleColumnWidths: SizeMap, visibleColumns: VisibleIndex[], gridX: Coordinate): VisibleIndex; /** * Retrieve the possible bottom of the visible viewport (not limited by data size) * @param state The grid metric state * @param visibleRows Array of visible row indexes * @param visibleRowYs Map of row index to y coordinate * @param visibleRowHeights Map of row index to height * @returns The index of the bottom viewport possible */ getBottomViewport(state: GridMetricState, visibleRows: VisibleIndex[], visibleRowYs: CoordinateMap, visibleRowHeights: SizeMap): VisibleIndex; /** * Retrieve the possible right of the visible viewport (not limited by data size) * @param state The grid metric state * @param visibleColumns Array of visible column indexes * @param visibleColumnXs Map of column index to x coordinate * @param visibleColumnWidths Map of column index to width * @returns The index of the right viewport possible */ getRightViewport(state: GridMetricState, visibleColumns: VisibleIndex[], visibleColumnXs: CoordinateMap, visibleColumnWidths: SizeMap): VisibleIndex; /** * Get the Index of the of the last index visible * @param items Array of visible item indexes * @param itemXs Map of index to coordinate * @param itemSizes Map of index to size * @param maxSize Full size of the grid * @param defaultItemSize Default size of an item * @returns The Index of the last index visible */ getLastIndexViewport(items: VisibleIndex[], itemXs: CoordinateMap, itemSizes: SizeMap, maxSize: number, defaultItemSize: number): VisibleIndex; /** * Get the size from the provided size map of the specified item * @param modelIndex The model index to get the size for * @param userSizes The user set sizes * @param getDefaultSize Method to get the default size for this item * @returns The size from the provided size map of the specified item */ getVisibleItemSize(modelIndex: ModelIndex, userSizes: ModelSizeMap, getDefaultSize: () => number): number; /** * Get the height of the specified row * @param row Index of the row to get the height of * @param state The grid metric state * @returns The height of the row specified */ getVisibleRowHeight(row: VisibleIndex, state: GridMetricState): number; /** * Get the width of the specified column * @param column Index of the column to get the width of * @param state The grid metric state * @param firstColumn Index of first visible column * @param treePaddingX The amount of tree padding to add to the first visible column * @returns The width of the column */ getVisibleColumnWidth(column: VisibleIndex, state: GridMetricState, firstColumn?: VisibleIndex, treePaddingX?: number): number; /** * Get a map of VisibleIndex to ModelIndex * @param visibleRows Array of visible row indexes * @param state The grid metric state * @returns Map of VisibleIndex to ModelIndex */ getModelRows(visibleRows: VisibleIndex[], state: GridMetricState): VisibleToModelMap; /** * Get the ModelIndex of the specified row * @param visibleRow Index of the row * @param state The grid metric state * @returns ModelIndex of the row */ getModelRow(visibleRow: VisibleIndex, state: GridMetricState): ModelIndex; /** * Get a map of Index to ModelIndex. Applies the move operations to get the transformation. * @param visibleColumns Array of visible column indexes * @param state The grid metric state * @returns Map of Index to ModelIndex */ getModelColumns(visibleColumns: VisibleIndex[], state: GridMetricState): VisibleToModelMap; /** * Get the ModelIndex of the specified column * @param visibleColumn Index of the column * @param state The grid metric state * @returns ModelIndex of the column */ getModelColumn(visibleColumn: VisibleIndex, state: GridMetricState): ModelIndex; /** * Calculate the height of the row specified. * @param row Index of the row to calculate the height for * @param modelRow ModelIndex of the row to calculate the height * @param state The grid metric state * @returns The height of the row */ calculateRowHeight(row: VisibleIndex, modelRow: ModelIndex, state: GridMetricState): number; /** * Calculates the column width based on the provided column model index * @param column Index of the column to calculate the width for * @param modelColumn ModelIndex of the column to calculate the width * @param state The grid metric state * @param firstColumn The first visible column * @param treePaddingX Tree padding offset for expandable rows * @returns The width of the column */ calculateColumnWidth(column: VisibleIndex, modelColumn: ModelIndex, state: GridMetricState, firstColumn?: VisibleIndex, treePaddingX?: number): number; /** * Checks if a column is hidden either by a user setting the width to 0 or by initial width being 0 * @param modelIndex the model index of the column to check * @returns true if the column is hidden, false otherwise */ isColumnHidden(modelIndex: ModelIndex): boolean; /** * Calculate the width of the specified column's header * @param modelColumn ModelIndex of the column to get the header width for * @param state The grid metric state * @returns The calculated width of the column header */ calculateColumnHeaderWidth(modelColumn: ModelIndex, state: GridMetricState, maxColumnWidth: number): number; /** * Calculate the width of the specified column's data * @param modelColumn ModelIndex of the column to get the data width for * @param state The grid metric state * @returns The calculated width of the column data */ calculateColumnDataWidth(modelColumn: ModelIndex, state: GridMetricState, maxColumnWidth: number): number; /** * Calculates the width of a string using widths of individual and pairs of characters to take into account font kerning * @param context The canvas rendering context * @param font The font to get the width for * @param text The text to calculate the width for * @param maxWidth The maximum width to calculate to */ calculateTextWidth(context: CanvasRenderingContext2D, font: string, text: string, maxWidth?: number): number; /** * The coordinate for where the tree padding should be drawn * @param state The grid metric state * @returns The coordinate for tree padding */ calculateTreePaddingX(state: GridMetricState): Coordinate; /** * Calculates the lower bound width of a character of the provided font. * @param font The font to get the width for * @param context The canvas rendering context */ calculateLowerFontWidth(font: GridFont, context: CanvasRenderingContext2D): void; /** * Calculates the upper bound width of a character of the provided font. * @param font The font to get the width for * @param context The canvas rendering context */ calculateUpperFontWidth(font: GridFont, context: CanvasRenderingContext2D): void; /** * Sets the width for the specified column * @param column The column model index to set * @param size The size to set it to */ setColumnWidth(column: ModelIndex, size: number): void; /** * Resets the column width for the specified column to the calculated width * @param column The column model index to reset */ resetColumnWidth(column: ModelIndex): void; /** * Sets the calculated width for the specified column * @param column The column model index to set * @param size The size to set it to */ setCalculatedColumnWidth(column: ModelIndex, size: number): void; /** * Resets all the calculated column widths * Useful if the theme minimum column width changes */ resetCalculatedColumnWidths(): void; /** * Sets the width for the specified row * @param row The row model index to set * @param size The size to set it to */ setRowHeight(row: ModelIndex, size: number): void; /** * Resets the row height for the specified row to the calculated height * @param row The row model index to reset */ resetRowHeight(row: ModelIndex): void; /** * Sets the calculated height for the specified row * @param row The column model index to set * @param size The size to set it to */ setCalculatedRowHeight(row: ModelIndex, size: number): void; /** * Resets all the calculated row heights * Useful if the theme row height changes */ resetCalculatedRowHeights(): void; } export default GridMetricCalculator; //# sourceMappingURL=GridMetricCalculator.d.ts.map