import { HoistModel, PlainObject, Theme } from '@xh/hoist/core'; import { Store, StoreRecord, StoreRecordId } from '@xh/hoist/data'; import { GridModel } from '@xh/hoist/cmp/grid'; import { FilterLike } from '@xh/hoist/data/filter/Types'; import { ReactNode } from 'react'; export interface TreeMapConfig { /** A store containing records to be displayed. */ store?: Store; /** Optional GridModel to bind to. */ gridModel?: GridModel; /** Maximum number of nodes to render. Be aware that increasing this can severely degrade performance. */ maxNodes?: number; /** * Maximum number of node labels to attempt to render. Defaults to 250, based on the fact that * the smaller boxes beyond that count are unlikely to be able to have enough room to render * labels in any case. Be aware that increasing this can degrade performance. */ maxLabels?: number; /** * Highcharts configuration object for the managed map. * Will be recursively merged into the top-level HC config generated by this model, the component. */ highchartsConfig?: PlainObject; /** StoreRecord field to use to determine node label. */ labelField?: string; /** StoreRecord field to use to determine node size. */ valueField?: string; /** StoreRecord field to use to determine node color. */ heatField?: string; /** Renderer to use when displaying value in the default tooltip. Should return HTML. */ valueRenderer?: TreeMapValueRendererFn; /** Renderer to use when displaying heat in the default tooltip. Should return HTML. */ heatRenderer?: TreeMapHeatRendererFn; /** * Value for providing a clamped, stable upper boundary on heat color intensity. * If not provided, maxHeat will be determined by the dataset on each load. */ maxHeat?: number; /** Maximum tree depth to render. */ maxDepth?: number; /** Layout algorithm to use. */ algorithm?: TreeMapAlgorithm; /** Heat color distribution mode. */ colorMode?: TreeMapColorMode; /** Theme to use. Leave undefined to use the global theme. */ theme?: Theme; /** * Callback to call when a node is clicked. * If not provided, by default will select a record when using a GridModel. */ onClick?: (StoreRecord: any, MouseEvent: any) => void; /** * Callback to call when a node is double-clicked. * If not provided, by default will expand / collapse a record when using a GridModel. */ onDoubleClick?: (StoreRecord: any, MouseEvent: any) => void; /** `true` to use the default tooltip renderer, or a custom tooltipFn. */ tooltip?: boolean | TreeMapTooltipFn; /** Element/text to render if TreeMap has no records. */ emptyText?: ReactNode; /** Data filter to apply to records. */ filter?: FilterLike; } export interface TreeMapModelDefaults { algorithm?: TreeMapAlgorithm; maxNodes?: number; } /** * Core Model for a TreeMap, backed by a data Store with fields mapped to each node's label * (display name), value (size), and heat (color). * * Can optionally bind to a GridModel to enable selection and expand/collapse syncing for * GridModels in `treeMode`. * * Supports Highcharts TreeMap algorithms: 'squarified', 'sliceAndDice', 'stripes', and 'strip'. * * Node colors are normalized to a 0-1 range and mapped to a colorAxis. The `colorMode` config * controls how: * - 'linear' - distributes values across the colorAxis according to the heatField. * - 'wash' - ignores heat intensity, applying a single positive/negative color. * - 'none' - ignores the colorAxis entirely, using the neutral color. * * Color customization can be managed by setting colorAxis stops via `highchartsConfig`. * See {@link https://www.highcharts.com/docs/chart-and-series-types/treemap} for Highcharts * TreeMap config options. */ export declare class TreeMapModel extends HoistModel { /** App-level defaults for TreeMapModel. Instance config takes precedence. */ static defaults: TreeMapModelDefaults; store: Store; gridModel: GridModel; maxNodes: number; maxLabels: number; valueRenderer: TreeMapValueRendererFn; heatRenderer: TreeMapHeatRendererFn; onClick: (StoreRecord: any, MouseEvent: any) => void; onDoubleClick: (StoreRecord: any, MouseEvent: any) => void; tooltip: boolean | TreeMapTooltipFn; emptyText: ReactNode; highchartsConfig: any; data: TreeMapRecord[]; labelField: string; valueField: string; heatField: string; maxHeat: number; maxDepth: number; algorithm: TreeMapAlgorithm; colorMode: TreeMapColorMode; theme: Theme; isMasking: boolean; _filter: any; constructor(config?: TreeMapConfig); get total(): number; get valueFieldLabel(): string; get heatFieldLabel(): string; get selectedIds(): StoreRecordId[]; get expandState(): PlainObject; get empty(): boolean; get error(): string; processAndSetData(sourceRecords: any): void; /** * Create a flat list of TreeMapRecords from hierarchical store data, ready to be * passed to HighCharts for rendering. Drilldown children are included according * to the bound GridModel's expandState. */ processRecordsRecursive(sourceRecords: any, parentId?: any, depth?: number): Partial[]; /** * Removes node labels if the number of nodes exceeds maxLabels. * This is a performance optimisation to mitigate slow SVG text rendering. Labels are prioritized * according to node size, from largest to smallest, on the basis that removed labels would * likely be hidden due to the size of the node. */ limitLabels(data: any): any; /** * Normalizes heatValues to colorValues between 0-1, where 0 is the maximum negative heat, * 1 is the maximum positive heat, and 0.5 is no heat. This allows the colorValue to map to * the colorAxis provided to Highcharts. * * Takes the colorMode into account: * a) 'linear' distributes normalized color values across the colorAxis. * b) 'wash' ignores the intensity of the heat value, applying a flat positive or negative color. * c) 'none' ignores the heat value altogether, coloring all nodes with the neutral color */ normaliseColorValues(data: any): any; normalizeToRange(value: any, fromMin: any, fromMax: any, toMin: any, toMax: any): any; valueIsValid(value: any): boolean; nodeIsExpanded(treePath: any): any; toggleNodeExpanded(treePath: any): void; defaultOnClick: (record: any, e: any) => void; defaultOnDoubleClick: (record: any) => void; } export interface TreeMapRecord { /** StoreRecordId of the StoreRecord from which TreeMapRecord was created. */ id: StoreRecordId; /** StoreRecord from which TreeMapRecord was created. */ record: StoreRecord; /** Used by Highcharts to determine the node label. */ name: string; /** Used by Highcharts to determine the node size. */ value: number; /** Transient property used to determine the Highcharts colorValue. */ heatValue: number; /** Used by Highcharts to determine the color in a heat map. */ colorValue: number; /** StoreRecordId of parent StoreRecord in hierarchical data. */ parent?: StoreRecordId; } /** Layout algorithm to use. */ export type TreeMapAlgorithm = 'squarified' | 'sliceAndDice' | 'stripes' | 'strip'; /** Heat color distribution mode. */ export type TreeMapColorMode = 'linear' | 'wash' | 'none'; /** * Normalized renderer function to display value in the tree map tooltip. * @returns the formatted value (html) for display. */ export type TreeMapValueRendererFn = (value: any, record: StoreRecord) => string; /** * Normalized renderer function to display heat in the tree map tooltip. * @returns the formatted value (html) for display. */ export type TreeMapHeatRendererFn = (value: any, record: StoreRecord) => string; /** * Normalized renderer function to produce a tree map tooltip. * @returns the formatted value (html) for display. */ export type TreeMapTooltipFn = (record: StoreRecord) => string;