import { compactNumberFormatter } from "@/src/utils/numbers"; import { getColorsForCategories } from "@/src/features/dashboard/utils/getColorsForCategories"; import { isEmptyChart } from "@/src/features/dashboard/lib/score-analytics-utils"; import { BarChart, LineChart, type CustomTooltipProps } from "@tremor/react"; import { NoDataOrLoading } from "@/src/components/NoDataOrLoading"; import { Card } from "@/src/components/ui/card"; import { type ChartBin } from "@/src/features/scores/types"; import { cn } from "@/src/utils/tailwind"; import { Tooltip } from "@/src/features/dashboard/components/Tooltip"; export function CategoricalChart(props: { chartData: ChartBin[]; chartLabels: string[]; isLoading?: boolean; stack?: boolean; showXAxis?: boolean; className?: string; chartClass?: string; }) { const barCategoryGap = (chartLength: number): string => { if (chartLength > 7) return "10%"; if (chartLength > 5) return "20%"; if (chartLength > 3) return "30%"; else return "40%"; }; const colors = getColorsForCategories(props.chartLabels); const TooltipComponent = (tooltipProps: CustomTooltipProps) => ( Intl.NumberFormat("en-US").format(value).toString()} /> ); return isEmptyChart({ data: props.chartData }) ? ( ) : ( Intl.NumberFormat("en-US").format(number).toString() } yAxisWidth={48} barCategoryGap={barCategoryGap(props.chartData.length)} stack={props.stack ?? true} showXAxis={props.showXAxis ?? true} customTooltip={TooltipComponent} /> ); } export function NumericChart(props: { chartData: ChartBin[]; chartLabels: string[]; index: string; maxFractionDigits?: number; }) { const colors = getColorsForCategories(props.chartLabels); const TooltipComponent = (tooltipProps: CustomTooltipProps) => (
compactNumberFormatter(value, props.maxFractionDigits) } />
); return isEmptyChart({ data: props.chartData }) ? ( ) : ( { return compactNumberFormatter(value, props.maxFractionDigits); }} noDataText="No data" showAnimation={true} onValueChange={() => {}} enableLegendSlider={true} showXAxis={false} customTooltip={TooltipComponent} /> ); }