export type ColorValue = string; export type ColorArray = string[]; export type ColorFunction = (index: number, value: number) => string; export type DynamicColor = ColorValue | ColorArray | ColorFunction; export type DataValue = number | [number, number]; export type DataArray = DataValue[]; export interface DatasetConfig { /** Label for the dataset (shown in legend) */ label: string; /** Data values for this dataset */ data: DataArray; /** Background color(s) for bars */ backgroundColor?: DynamicColor; /** Border color(s) for bars */ borderColor?: DynamicColor; /** Border width in pixels */ borderWidth?: number; /** Border radius for bars (all corners or individual) */ borderRadius?: number | BorderRadiusConfig; /** Hover background color */ hoverBackgroundColor?: DynamicColor; /** Hover border color */ hoverBorderColor?: DynamicColor; /** Stack group identifier (for stacked charts) */ stack?: string; /** Bar thickness in pixels (auto if not specified) */ barThickness?: number; /** Maximum bar thickness */ maxBarThickness?: number; /** Minimum bar length (useful for small values) */ minBarLength?: number; /** Whether to show this dataset */ hidden?: boolean; /** Order for drawing (lower = drawn first) */ order?: number; /** Opacity (0-1) */ opacity?: number; } export interface BorderRadiusConfig { topLeft?: number; topRight?: number; bottomLeft?: number; bottomRight?: number; } export interface AxisConfig { /** Display the axis */ display?: boolean; /** Axis title configuration */ title?: { display?: boolean; text?: string; color?: string; fontSize?: number; fontWeight?: string | number; fontFamily?: string; padding?: number; }; /** Grid line configuration */ grid?: { display?: boolean; color?: string; lineWidth?: number; dashArray?: string; }; /** Tick configuration */ ticks?: { display?: boolean; color?: string; fontSize?: number; fontFamily?: string; padding?: number; maxTicksLimit?: number; stepSize?: number; callback?: (value: number, index: number) => string; }; /** Minimum value */ min?: number; /** Maximum value */ max?: number; /** Begin axis at zero */ beginAtZero?: boolean; /** Axis position */ position?: 'top' | 'left' | 'bottom' | 'right'; } export interface FontConfig { family?: string; size?: number; weight?: 'normal' | 'bold' | 'lighter' | 'bolder' | number; style?: 'normal' | 'italic'; } export interface PaddingConfig { top?: number; right?: number; bottom?: number; left?: number; } export interface LegendConfig { /** Display the legend */ display?: boolean; /** Position of the legend */ position?: 'top' | 'left' | 'bottom' | 'right'; /** Alignment of the legend */ align?: 'start' | 'center' | 'end'; /** Label configuration */ labels?: { color?: string; fontSize?: number; fontFamily?: string; padding?: number; boxWidth?: number; boxHeight?: number; usePointStyle?: boolean; }; /** On click handler */ onClick?: (datasetIndex: number, dataset: DatasetConfig) => void; } export interface TooltipConfig { /** Enable tooltips */ enabled?: boolean; /** Background color */ backgroundColor?: string; /** Text color */ textColor?: string; /** Font size */ fontSize?: number; /** Font family */ fontFamily?: string; /** Border color */ borderColor?: string; /** Border width */ borderWidth?: number; /** Corner radius */ cornerRadius?: number; /** Padding */ padding?: number; /** Custom format function */ formatter?: (value: DataValue, datasetLabel: string, label: string) => string; } export interface AnimationConfig { /** Enable animations */ enabled?: boolean; /** Animation duration in ms */ duration?: number; /** Easing function */ easing?: 'linear' | 'ease' | 'ease-in' | 'ease-out' | 'ease-in-out' | string; /** Delay before animation starts */ delay?: number; /** Stagger delay between bars */ staggerDelay?: number; } export interface BaseChartProps { /** Labels for the x-axis (categories) */ labels: string[]; /** Dataset configurations */ datasets: DatasetConfig[]; /** Chart title */ title?: string | { text: string; color?: string; fontSize?: number; fontWeight?: string | number; fontFamily?: string; align?: 'start' | 'center' | 'end'; padding?: number; }; /** X-axis configuration */ xAxis?: AxisConfig; /** Y-axis configuration */ yAxis?: AxisConfig; /** Legend configuration */ legend?: LegendConfig; /** Tooltip configuration */ tooltip?: TooltipConfig; /** Animation configuration */ animation?: AnimationConfig | boolean; /** Chart width (CSS value or number for pixels) */ width?: string | number; /** Chart height (CSS value or number for pixels) */ height?: string | number; /** Chart padding */ padding?: PaddingConfig | number; /** Chart background color */ backgroundColor?: string; /** Callback on bar click */ onBarClick?: (event: React.MouseEvent, data: BarClickData) => void; /** Callback on bar hover */ onBarHover?: (event: React.MouseEvent, data: BarClickData | null) => void; /** Additional CSS class name */ className?: string; /** Additional CSS styles */ style?: React.CSSProperties; /** Chart ID */ id?: string; /** Aria label for accessibility */ ariaLabel?: string; /** Show values on bars */ showValues?: boolean; /** Value label configuration */ valueLabels?: { color?: string; fontSize?: number; fontFamily?: string; position?: 'inside' | 'outside' | 'center'; formatter?: (value: number) => string; }; } export interface BarClickData { datasetIndex: number; dataIndex: number; value: DataValue; label: string; datasetLabel: string; } export interface BarChartProps extends BaseChartProps { /** Default border radius for all bars */ borderRadius?: number | BorderRadiusConfig; /** Orientation: vertical or horizontal */ orientation?: 'vertical' | 'horizontal'; /** Bar gap (spacing between bars in a group) */ barGap?: number; /** Group gap (spacing between groups) */ groupGap?: number; } export interface HorizontalBarChartProps extends BaseChartProps { /** Default border radius for all bars */ borderRadius?: number | BorderRadiusConfig; /** Bar gap (spacing between bars in a group) */ barGap?: number; /** Group gap (spacing between groups) */ groupGap?: number; } export interface StackedBarChartProps extends BaseChartProps { /** Default border radius for all bars */ borderRadius?: number | BorderRadiusConfig; /** Orientation: vertical or horizontal */ orientation?: 'vertical' | 'horizontal'; /** Group gap (spacing between groups) */ groupGap?: number; } export interface StackedBarChartWithGroupsProps extends BaseChartProps { /** Default border radius for all bars */ borderRadius?: number | BorderRadiusConfig; /** Orientation: vertical or horizontal */ orientation?: 'vertical' | 'horizontal'; /** Group gap (spacing between stack groups) */ groupGap?: number; /** Stack gap (spacing between stacks) */ stackGap?: number; } export interface FloatingBarChartProps extends BaseChartProps { /** Default border radius for all bars */ borderRadius?: number | BorderRadiusConfig; /** Orientation: vertical or horizontal */ orientation?: 'vertical' | 'horizontal'; /** Bar gap (spacing between bars in a group) */ barGap?: number; /** Group gap (spacing between groups) */ groupGap?: number; } export interface VerticalBarChartProps extends BaseChartProps { /** Default border radius for all bars */ borderRadius?: number | BorderRadiusConfig; /** Bar gap (spacing between bars in a group) */ barGap?: number; /** Group gap (spacing between groups) */ groupGap?: number; } export interface ThemeConfig { /** Primary color palette */ colors?: string[]; /** Font family */ fontFamily?: string; /** Base font size */ fontSize?: number; /** Grid color */ gridColor?: string; /** Text color */ textColor?: string; /** Background color */ backgroundColor?: string; /** Border radius */ borderRadius?: number; /** Tooltip background */ tooltipBackground?: string; /** Tooltip text color */ tooltipTextColor?: string; /** Axis line color */ axisColor?: string; } export type PresetTheme = 'default' | 'vibrant' | 'pastel' | 'monochrome' | 'dark' | 'ocean' | 'sunset' | 'forest' | 'candy' | 'corporate'; export interface ChartDimensions { width: number; height: number; chartWidth: number; chartHeight: number; padding: Required; } export interface ScaleConfig { min: number; max: number; step: number; ticks: number[]; } export interface BarRect { x: number; y: number; width: number; height: number; value: DataValue; label: string; datasetIndex: number; dataIndex: number; color: string; borderColor?: string; borderWidth?: number; borderRadius?: number | BorderRadiusConfig; opacity?: number; }