import { type ChartPluginSignature } from "../../models/index.js"; import { type UseChartSeriesSignature } from "../../corePlugins/useChartSeries/index.js"; import { type SeriesId, type SeriesItemIdentifierWithType } from "../../../../models/index.js"; import { type ChartSeriesType } from "../../../../models/seriesType/config.js"; export type VisibilityIdentifier = Partial> & (SeriesItemIdentifierWithType extends { subType?: infer U; } ? { subType: U; seriesId: SeriesId; } : { seriesId: SeriesId; }); export type VisibilityIdentifierWithType = SeriesType extends any ? VisibilityIdentifier & { type: SeriesType; } : never; export type VisibilityMap = Map; export type IsItemVisibleFunction = { /** * Function to check if an item is visible based on its identifier. * * @param {VisibilityIdentifierWithType} identifier The identifier of the item to check. * @returns {boolean} Whether the item is visible. */ (identifier: VisibilityIdentifierWithType): boolean; }; export interface UseChartVisibilityManagerInstance { /** * Hide an item by its identifier. * * @param {VisibilityIdentifier} identifier The identifier of the item to hide. */ hideItem(identifier: VisibilityIdentifier): void; /** * Show an item by its identifier. * * @param {VisibilityIdentifier} identifier The identifier of the item to show. */ showItem(identifier: VisibilityIdentifier): void; /** * Toggle the visibility of an item by its identifier. * * @param {VisibilityIdentifier} identifier The identifier of the item to toggle. */ toggleItemVisibility(identifier: VisibilityIdentifier | VisibilityIdentifierWithType): void; } export interface UseChartVisibilityManagerParameters { /** * Callback fired when any hidden identifiers change. * @param {VisibilityIdentifierWithType[]} hiddenItems The new list of hidden identifiers. */ onHiddenItemsChange?: (hiddenItems: VisibilityIdentifierWithType[]) => void; /** * List of hidden series and/or items. * * Different chart types use different keys. * * @example * ```ts * [ * { * type: 'pie', * seriesId: 'series-1', * dataIndex: 3, * }, * { * type: 'line', * seriesId: 'series-2', * } * ] * ``` */ hiddenItems?: (VisibilityIdentifier | VisibilityIdentifierWithType)[]; /** * List of initially hidden series and/or items. * Used for uncontrolled state. * * Different chart types use different keys. * * @example * ```ts * [ * { * type: 'pie', * seriesId: 'series-1', * dataIndex: 3, * }, * { * type: 'line', * seriesId: 'series-2', * } * ] * ``` */ initialHiddenItems?: (VisibilityIdentifier | VisibilityIdentifierWithType)[]; } export type UseChartVisibilityManagerDefaultizedParameters = UseChartVisibilityManagerParameters; export interface UseChartVisibilityManagerState { visibilityManager: { /** * Map of hidden identifiers by their serialized form. */ visibilityMap: VisibilityMap; /** * Internal information to know if the user controls the state or not. */ isControlled: boolean; }; } export type UseChartVisibilityManagerSignature = ChartPluginSignature<{ instance: UseChartVisibilityManagerInstance; state: UseChartVisibilityManagerState; params: UseChartVisibilityManagerParameters; defaultizedParams: UseChartVisibilityManagerDefaultizedParameters; dependencies: [UseChartSeriesSignature]; }>;