UNPKG

bento-charts

Version:
86 lines (85 loc) 2.86 kB
import type { PieProps, BarProps, LabelProps } from 'recharts'; import type { CartesianChartProps } from 'recharts/types/util/types'; import { COUNT_KEY, OTHER_KEY } from '../constants/chartConstants'; export type CategoricalChartDataType = CategoricalChartDataItem[]; export interface CategoricalChartDataItem { x: string; y: number; id?: string; } export type TooltipPayload = TooltipPayloadItem[]; interface TooltipPayloadItem { name: string; payload: { x: string; }; value: number; } export type HexColor = `#${string}`; export type ChartThemeContext = { fill: HexColor[]; other: HexColor; }; export type ChartTypeContext = { [key in string]: ChartThemeContext; } & { default: ChartThemeContext; }; export type ChartTheme = { pie: ChartTypeContext; bar: ChartTypeContext; histogram: ChartTypeContext; }; export type FilterCallback<T> = (value: T, index: number, array: T[]) => boolean; export type UnitaryMapCallback<T> = (value: T, index: number, array: T[]) => T; export type ChartFilterCallback = FilterCallback<CategoricalChartDataItem>; export type ChartDataMapCallback = UnitaryMapCallback<CategoricalChartDataItem>; export type SupportedLng = 'en' | 'fr'; type TranslationWords = typeof COUNT_KEY | typeof OTHER_KEY; export type LngDictionary = { [key in TranslationWords]: string; }; export type TranslationObject = { [key in SupportedLng]: LngDictionary; }; export interface CategoricalChartDataWithTransforms { data: CategoricalChartDataType; preFilter?: ChartFilterCallback; dataMap?: ChartDataMapCallback; postFilter?: ChartFilterCallback; removeEmpty?: boolean; } export interface BaseChartComponentProps { height: number; width?: number | `${number}%`; } export interface BaseCategoricalChartProps extends BaseChartComponentProps, CategoricalChartDataWithTransforms { } export interface PieChartProps extends BaseCategoricalChartProps { colorTheme?: keyof ChartTheme['pie']; sort?: boolean; onClick?: PieProps['onClick']; chartThreshold?: number; maxLabelChars?: number; } export type BarCountFillMode = 'match' | 'neutral'; export interface BaseBarChartProps extends BaseCategoricalChartProps { chartFill: HexColor[]; otherFill: HexColor; title?: string; units: string; onClick?: BarProps['onClick']; onChartClick?: CartesianChartProps['onClick']; showBarCounts?: boolean; barCountFillMode?: BarCountFillMode; } export interface BarChartProps extends Omit<BaseBarChartProps, 'chartFill' | 'otherFill'> { colorTheme?: keyof ChartTheme['bar']; } export interface HistogramProps extends Omit<BaseBarChartProps, 'chartFill' | 'otherFill'> { colorTheme?: keyof ChartTheme['bar']; } export interface CustomBarLabelProps extends LabelProps { valuesMaxStringLength: number; } export {};