| 50 | } |
| 51 | |
| 52 | function ChartContainer({ |
| 53 | id, |
| 54 | className, |
| 55 | children, |
| 56 | config, |
| 57 | initialDimension = INITIAL_DIMENSION, |
| 58 | ...props |
| 59 | }: React.ComponentProps<"div"> & { |
| 60 | config: ChartConfig; |
| 61 | children: React.ComponentProps<typeof RechartsPrimitive.ResponsiveContainer>["children"]; |
| 62 | initialDimension?: { |
| 63 | width: number; |
| 64 | height: number; |
| 65 | }; |
| 66 | }) { |
| 67 | const uniqueId = React.useId(); |
| 68 | const chartId = `chart-${id ?? uniqueId.replace(/:/g, "")}`; |
| 69 | |
| 70 | return ( |
| 71 | <ChartContext.Provider value={{ config }}> |
| 72 | <div |
| 73 | data-slot="chart" |
| 74 | data-chart={chartId} |
| 75 | className={cn( |
| 76 | "flex aspect-video justify-center text-xs [&_.recharts-cartesian-axis-tick_text]:fill-muted-foreground [&_.recharts-cartesian-grid_line[stroke='#ccc']]:stroke-border/50 [&_.recharts-curve.recharts-tooltip-cursor]:stroke-border [&_.recharts-dot[stroke='#fff']]:stroke-transparent [&_.recharts-layer]:outline-hidden [&_.recharts-polar-grid_[stroke='#ccc']]:stroke-border [&_.recharts-radial-bar-background-sector]:fill-muted [&_.recharts-rectangle.recharts-tooltip-cursor]:fill-muted [&_.recharts-reference-line_[stroke='#ccc']]:stroke-border [&_.recharts-sector]:outline-hidden [&_.recharts-sector[stroke='#fff']]:stroke-transparent [&_.recharts-surface]:outline-hidden", |
| 77 | className, |
| 78 | )} |
| 79 | {...props} |
| 80 | > |
| 81 | <ChartStyle id={chartId} config={config} /> |
| 82 | <RechartsPrimitive.ResponsiveContainer initialDimension={initialDimension}> |
| 83 | {children} |
| 84 | </RechartsPrimitive.ResponsiveContainer> |
| 85 | </div> |
| 86 | </ChartContext.Provider> |
| 87 | ); |
| 88 | } |
| 89 | |
| 90 | const ChartStyle = ({ id, config }: { id: string; config: ChartConfig }) => { |
| 91 | const colorConfig = Object.entries(config).filter(([, config]) => config.theme ?? config.color); |