import type { IconButtonProps } from '@mui/material' import type { ReactNode } from 'react' import type { BaseWidgetState } from '../../stores/types' /** * Brush selection result emitted by BrushToggle. * Contains raw indices so consumers can resolve data according to their widget type. */ export interface BrushSelectedItems { /** Data indices of the selected items in the dataset */ dataIndex: number[] /** Series index from the brush event (defaults to 0) */ seriesIndex: number } /** * A selection rectangle in x-axis data coords. Stored in the widget store so * it survives config-pipeline re-renders (which call `setOption` with * `notMerge: true` and wipe any ECharts-side state). The overlay re-projects * these to pixel positions on every chart render / resize. * * Both bar and histogram widgets use `xAxis.type === 'category'`, so the * coords are category indices (possibly fractional — `convertFromPixel` * returns floats like `1.3` between categories 1 and 2). */ export interface BrushRect { xStart: number xEnd: number } /** * State stored in widget store for brush functionality. */ export interface BrushConfig { /** Whether brush mode is enabled. */ brush?: boolean /** Persisted selection rectangles in data-axis coords. */ brushRects?: BrushRect[] /** Last selection emitted to the `onBrushSelected` callback. */ brushSelection?: BrushSelectedItems } export type BrushState = BaseWidgetState export interface BrushToggleProps { /** Widget ID to update brush state in the widget store */ id: string /** Callback fired when items are selected via brush */ onBrushSelected?: (items: BrushSelectedItems) => void /** When true, allows multiple brush selection areas. Brush stays active after each selection. */ multiBrush?: boolean /** * Initial brush-enabled state. Only applied on first mount if the widget * store has no `brush` value yet — subsequent remounts preserve whatever * state the user has toggled to. */ defaultEnabled?: boolean /** * Current selection count from the consumer (e.g. `selectedItems.length`). * When this transitions to `0` (typically when the user presses the clear * button in `WidgetSelectionSummary`), BrushToggle clears its persisted * brush rectangles and the on-chart selection. */ selections?: number /** Custom labels for the action */ labels?: { /** Tooltip when brush is disabled (button will enable brush) */ enable?: string /** Tooltip when brush is enabled (button will disable brush) */ disable?: string /** Accessibility label */ ariaLabel?: string } /** Props passed to the IconButton component */ IconButtonProps?: IconButtonProps /** Custom icon to display for brush toggle */ Icon?: ReactNode }