import { type ChartPluginSignature } from "../../models/index.js"; import { type UseChartSeriesSignature } from "../../corePlugins/useChartSeries/index.js"; import { type SeriesItemIdentifier } from "../../../../models/index.js"; import { type ChartSeriesType } from "../../../../models/seriesType/config.js"; export type VisibilityIdentifier = Partial> & (SeriesItemIdentifier extends { subType?: infer U; } ? { type: T; subType: U; } : { type: T; }); export type VisibilityMap = Map; export type IsItemVisibleFunction = { /** * Function to check if an item is visible based on its identifier. * * @param {VisibilityIdentifier} identifier The identifier of the item to check. * @returns {boolean} Whether the item is visible. */ (identifier: VisibilityIdentifier): 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): void; } export interface UseChartVisibilityManagerParameters { /** * Callback fired when any hidden identifiers change. * @param {VisibilityIdentifier[]} hiddenItems The new list of hidden identifiers. */ onHiddenItemsChange?: (hiddenItems: VisibilityIdentifier[]) => 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[]; /** * 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[]; } 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]; }>;