{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "chart",
  "type": "registry:ui",
  "title": "Chart",
  "description": "Bar charts for daily usage and categories, with tooltips and legends.",
  "categories": [
    "data-display"
  ],
  "dependencies": [
    "recharts@3.10.1"
  ],
  "registryDependencies": [
    "https://sprout.tulipfarm.ai/r/sprout-base.json"
  ],
  "files": [
    {
      "path": "registry/sprout/components/ui/chart.tsx",
      "type": "registry:ui",
      "target": "components/ui/chart.tsx",
      "content": "export {\n  ChartContainer,\n  ChartLegend,\n  ChartLegendContent,\n  ChartStyle,\n  ChartTooltip,\n  ChartTooltipContent,\n  chartColor,\n  chartIndicatorNames,\n  chartOtherColor,\n  chartPalette,\n  chartShade,\n  type ChartConfig,\n  type ChartContainerProps,\n  type ChartIndicator,\n  type ChartLegendContentProps,\n  type ChartRow,\n  type ChartSeries,\n  type ChartStack,\n  type ChartTooltipContentProps,\n  type ChartTooltipProps,\n  type UsageSeries,\n  type ValueFormatter,\n} from '@/lib/sprout/chart-kit';\nexport * from '@/lib/sprout/charts/bars';\nexport * from '@/lib/sprout/charts/lines';\nexport * from '@/lib/sprout/charts/parts';\nexport * from '@/lib/sprout/charts/more';\n"
    },
    {
      "path": "registry/sprout/lib/sprout/chart-kit.tsx",
      "type": "registry:lib",
      "target": "lib/sprout/chart-kit.tsx",
      "content": "'use client';\n\nimport {\n  createContext,\n  useContext,\n  useId,\n  useMemo,\n  type ComponentProps,\n  type ComponentType,\n  type CSSProperties,\n  type ReactNode,\n} from 'react';\nimport {\n  Legend,\n  Rectangle,\n  ResponsiveContainer,\n  Tooltip,\n  type BarShapeProps,\n  type DefaultLegendContentProps,\n  type DefaultTooltipContentProps,\n  type TooltipValueType,\n} from 'recharts';\nimport { cn } from '@/lib/sprout/classes';\n\nconst THEMES = { light: '', dark: '.dark' } as const;\n\nconst INITIAL_DIMENSION = { width: 320, height: 200 } as const;\n\nexport const chartIndicatorNames = ['dot', 'line', 'dashed'] as const;\nexport type ChartIndicator = (typeof chartIndicatorNames)[number];\n\nexport type ChartConfig = Record<\n  string,\n  {\n    label?: ReactNode;\n    icon?: ComponentType;\n  } & ({ color?: string; theme?: never } | { color?: never; theme: Record<keyof typeof THEMES, string> })\n>;\n\nconst cssKey = (key: string) => key.replace(/[^\\w-]/g, '_');\n\nexport function chartColor(key: string) {\n  return `var(--sprout-chart-color-${cssKey(key)})`;\n}\n\nconst ChartContext = createContext<{ config: ChartConfig } | null>(null);\n\nfunction useChart() {\n  const context = useContext(ChartContext);\n  if (!context) throw new Error('useChart must be used within a <ChartContainer />');\n  return context;\n}\n\nexport type ChartContainerProps = ComponentProps<'div'> & {\n  config: ChartConfig;\n  children: ComponentProps<typeof ResponsiveContainer>['children'];\n  initialDimension?: { width: number; height: number };\n};\n\nexport function ChartContainer({\n  id,\n  className,\n  children,\n  config,\n  initialDimension = INITIAL_DIMENSION,\n  ...props\n}: ChartContainerProps) {\n  const uniqueId = useId();\n  const chartId = `chart-${cssKey(id ?? uniqueId)}`;\n  const value = useMemo(() => ({ config }), [config]);\n  return (\n    <ChartContext.Provider value={value}>\n      <div data-slot=\"chart\" data-chart={chartId} className={cn('sprout-chart', className)} {...props}>\n        <ChartStyle id={chartId} config={config} />\n        <ResponsiveContainer initialDimension={initialDimension}>{children}</ResponsiveContainer>\n      </div>\n    </ChartContext.Provider>\n  );\n}\n\nexport function ChartStyle({ id, config }: { id: string; config: ChartConfig }) {\n  const colorConfig = Object.entries(config).filter(([, item]) => item.theme ?? item.color);\n  if (!colorConfig.length) return null;\n  const rules = (theme: keyof typeof THEMES) =>\n    colorConfig\n      .map(([key, item]) => {\n        const color = item.theme?.[theme] ?? item.color;\n        return color ? `  --sprout-chart-color-${cssKey(key)}: ${color};` : null;\n      })\n      .filter(Boolean)\n      .join('\\n');\n  const scope = `[data-chart=\"${cssKey(id)}\"]`;\n  const themed = colorConfig.some(([, item]) => item.theme);\n  const css = [\n    `${scope} {\\n${rules('light')}\\n}`,\n    themed ? `${THEMES.dark} ${scope} {\\n${rules('dark')}\\n}` : '',\n    themed\n      ? `@media (prefers-color-scheme: dark) {\\n:root:not(.light):not(.dark) ${scope} {\\n${rules('dark')}\\n}\\n}`\n      : '',\n  ]\n    .filter(Boolean)\n    .join('\\n');\n  return <style dangerouslySetInnerHTML={{ __html: css }} />;\n}\n\nexport type ChartTooltipProps = ComponentProps<typeof Tooltip>;\n\nexport function ChartTooltip(props: ChartTooltipProps) {\n  return <Tooltip animationDuration={160} {...props} />;\n}\n\ntype TooltipNameType = number | string;\n\nexport type ChartTooltipContentProps = ComponentProps<typeof Tooltip> &\n  ComponentProps<'div'> & {\n    hideLabel?: boolean;\n    hideIndicator?: boolean;\n    indicator?: ChartIndicator;\n    nameKey?: string;\n    labelKey?: string;\n    valueFormatter?: ValueFormatter;\n  } & Omit<DefaultTooltipContentProps<TooltipValueType, TooltipNameType>, 'accessibilityLayer'>;\n\nexport function ChartTooltipContent({\n  active,\n  payload,\n  className,\n  indicator = 'dot',\n  hideLabel = false,\n  hideIndicator = false,\n  label,\n  labelFormatter,\n  labelClassName,\n  formatter,\n  color,\n  nameKey,\n  labelKey,\n  valueFormatter = formatNumber,\n}: ChartTooltipContentProps) {\n  const { config } = useChart();\n\n  const tooltipLabel = useMemo(() => {\n    if (hideLabel || !payload?.length) return null;\n    const [item] = payload;\n    const key = `${labelKey ?? item?.dataKey ?? item?.name ?? 'value'}`;\n    const itemConfig = getPayloadConfigFromPayload(config, item, key);\n    const value = !labelKey && typeof label === 'string' ? (config[label]?.label ?? label) : itemConfig?.label;\n    if (labelFormatter)\n      return <div className={cn('sprout-chart-tooltip-label', labelClassName)}>{labelFormatter(value, payload)}</div>;\n    if (!value) return null;\n    return <div className={cn('sprout-chart-tooltip-label', labelClassName)}>{value}</div>;\n  }, [label, labelFormatter, payload, hideLabel, labelClassName, config, labelKey]);\n\n  if (!active || !payload?.length) return null;\n\n  const nestLabel = payload.length === 1 && indicator !== 'dot';\n\n  return (\n    <div data-slot=\"chart-tooltip\" data-indicator={indicator} className={cn('sprout-chart-tooltip', className)}>\n      {!nestLabel ? tooltipLabel : null}\n      <div className=\"sprout-chart-tooltip-items\">\n        {payload\n          .filter(item => item.type !== 'none')\n          .map((item, index) => {\n            const key = `${nameKey ?? item.name ?? item.dataKey ?? 'value'}`;\n            const itemConfig = getPayloadConfigFromPayload(config, item, key);\n            const indicatorColor = color ?? (item.payload as { fill?: string } | undefined)?.fill ?? item.color;\n            return (\n              <div key={index} data-slot=\"chart-tooltip-item\" className=\"sprout-chart-tooltip-item\">\n                {formatter && item?.value !== undefined && item.name ? (\n                  formatter(item.value, item.name, item, index, item.payload)\n                ) : (\n                  <>\n                    {itemConfig?.icon ? (\n                      <itemConfig.icon />\n                    ) : (\n                      !hideIndicator && (\n                        <span\n                          aria-hidden=\"true\"\n                          data-slot=\"chart-tooltip-indicator\"\n                          className=\"sprout-chart-tooltip-indicator\"\n                          style={\n                            {\n                              '--sprout-chart-indicator': indicatorColor,\n                            } as CSSProperties\n                          }\n                        />\n                      )\n                    )}\n                    <div className=\"sprout-chart-tooltip-row\" data-nested={nestLabel || undefined}>\n                      <div className=\"sprout-chart-tooltip-name\">\n                        {nestLabel ? tooltipLabel : null}\n                        <span>{itemConfig?.label ?? item.name}</span>\n                      </div>\n                      {item.value != null && (\n                        <span className=\"sprout-chart-tooltip-value\">\n                          {typeof item.value === 'number' ? valueFormatter(item.value) : String(item.value)}\n                        </span>\n                      )}\n                    </div>\n                  </>\n                )}\n              </div>\n            );\n          })}\n      </div>\n    </div>\n  );\n}\n\nexport const ChartLegend = Legend;\n\nexport type ChartLegendContentProps = ComponentProps<'div'> & {\n  hideIcon?: boolean;\n  nameKey?: string;\n} & DefaultLegendContentProps;\n\nexport function ChartLegendContent({\n  className,\n  hideIcon = false,\n  payload,\n  verticalAlign = 'bottom',\n  nameKey,\n}: ChartLegendContentProps) {\n  const { config } = useChart();\n  if (!payload?.length) return null;\n  return (\n    <div\n      data-slot=\"chart-legend\"\n      data-align={verticalAlign === 'top' ? 'top' : 'bottom'}\n      className={cn('sprout-chart-legend', className)}\n    >\n      {payload\n        .filter(item => item.type !== 'none')\n        .map((item, index) => {\n          const key = `${nameKey ?? item.dataKey ?? 'value'}`;\n          const itemConfig = getPayloadConfigFromPayload(config, item, key);\n          return (\n            <div key={index} data-slot=\"chart-legend-item\" className=\"sprout-chart-legend-item\">\n              {itemConfig?.icon && !hideIcon ? (\n                <itemConfig.icon />\n              ) : (\n                <span\n                  aria-hidden=\"true\"\n                  className=\"sprout-chart-legend-swatch\"\n                  style={{ backgroundColor: item.color }}\n                />\n              )}\n              {itemConfig?.label}\n            </div>\n          );\n        })}\n    </div>\n  );\n}\n\nfunction getPayloadConfigFromPayload(config: ChartConfig, payload: unknown, key: string) {\n  if (typeof payload !== 'object' || payload === null) return undefined;\n  const inner =\n    'payload' in payload && typeof payload.payload === 'object' && payload.payload !== null\n      ? (payload.payload as Record<string, unknown>)\n      : undefined;\n  const outer = payload as Record<string, unknown>;\n  let configLabelKey = key;\n  if (typeof outer[key] === 'string') configLabelKey = outer[key];\n  else if (inner && typeof inner[key] === 'string') configLabelKey = inner[key];\n  return configLabelKey in config ? config[configLabelKey] : config[key];\n}\n\nexport type ChartSeries = { key: string; label: string; color: string };\nexport type UsageSeries = ChartSeries;\n\nexport type ChartRow = Record<string, number | string | null | undefined>;\n\nexport type ValueFormatter = (value: number) => string;\n\nexport const formatNumber: ValueFormatter = value => value.toLocaleString();\n\nexport const chartPalette = [1, 2, 3, 4, 5].map(step => `var(--sprout-chart-${step})`);\n\nexport const chartOtherColor = 'var(--sprout-muted)';\n\nexport const partColor = (index: number) => chartPalette[index] ?? chartOtherColor;\n\nexport const chartShade = (color: string, step: number, steps = 5) =>\n  `color-mix(in oklab, ${color} ${Math.round((step / steps) * 100)}%, var(--sprout-surface))`;\n\nexport type ChartPart = { name: string; value: number; fill: string };\n\nexport function foldParts(rows: ChartRow[], category: string, value: string, limit = chartPalette.length): ChartPart[] {\n  const parts = rows\n    .map(row => ({\n      name: String(row[category] ?? ''),\n      value: Number(row[value]) || 0,\n    }))\n    .filter(part => part.value > 0)\n    .sort((a, b) => b.value - a.value);\n  const kept = parts.slice(0, limit);\n  const rest = parts.slice(kept.length);\n  const colored = kept.map((part, index) => ({\n    ...part,\n    fill: partColor(index),\n  }));\n  if (!rest.length) return colored;\n  return [\n    ...colored,\n    {\n      name: `${rest.length} more`,\n      value: rest.reduce((sum, part) => sum + part.value, 0),\n      fill: chartOtherColor,\n    },\n  ];\n}\n\nexport const partConfig = (parts: ChartPart[]): ChartConfig =>\n  Object.fromEntries(parts.map(part => [part.name, { label: part.name, color: part.fill }]));\n\nexport interface ReadyChartProps {\n  title?: string;\n  valueFormatter?: ValueFormatter;\n  className?: string;\n}\n\nexport const seriesConfig = (series: ChartSeries[]): ChartConfig =>\n  Object.fromEntries(series.map(item => [item.key, { label: item.label, color: item.color }]));\n\nexport const tooltipCursor = { fill: 'var(--sprout-hover)' };\n\nexport const quietAxis = { tickLine: false, axisLine: false } as const;\n\nexport const valueDomain = (max: number | undefined) =>\n  max === undefined ? undefined : ([(low: number) => Math.min(0, low), max] as [(low: number) => number, number]);\n\nexport const valueTicks = (max: number | undefined) => {\n  if (max === undefined) return undefined;\n  const scale = 10 ** Math.floor(Math.log10(max / 5));\n  const steps = (bases: number[]) => [scale, scale * 10].flatMap(size => bases.map(base => base * size));\n  const find = (bases: number[], most: number) =>\n    steps(bases).find(item => max / item <= most && Number.isInteger(+(max / item).toFixed(9)));\n  const round = [1, 2, 2.5, 5];\n  const other = [3, 4, 6, 8];\n  const step = find(round, 5) ?? find(other, 5) ?? find(round, 8) ?? find(other, 8);\n  return step ? Array.from({ length: Math.round(max / step) + 1 }, (_, index) => +(index * step).toFixed(9)) : [0, max];\n};\n\nexport type ChartStack = 'none' | 'stacked' | 'percent';\n\nexport const stackOffset = (stack: ChartStack) => (stack === 'percent' ? ('expand' as const) : undefined);\n\nexport const formatPercent: ValueFormatter = value => `${Math.round(value * 100)}%`;\n\nexport const dayLabel = (value: unknown, locale?: string) =>\n  new Date(\n    typeof value === 'number' || value instanceof Date ? value : `${String(value)}T00:00:00Z`,\n  ).toLocaleDateString(locale, {\n    month: 'short',\n    day: 'numeric',\n    timeZone: 'UTC',\n  });\n\nexport const configLegend = (config: ChartConfig) =>\n  function ConfigLegend() {\n    return (\n      <ChartLegendContent\n        payload={Object.keys(config).map(key => ({\n          value: key,\n          dataKey: key,\n          color: chartColor(key),\n        }))}\n      />\n    );\n  };\n\nexport const rowFillShape = (props: BarShapeProps) => (\n  <Rectangle {...props} fill={(props.payload as { fill: string }).fill} />\n);\n"
    },
    {
      "path": "registry/sprout/lib/sprout/charts/bars.tsx",
      "type": "registry:lib",
      "target": "lib/sprout/charts/bars.tsx",
      "content": "'use client';\n\nimport { useMemo } from 'react';\nimport { Bar, BarChart, CartesianGrid, ReferenceLine, XAxis, YAxis } from 'recharts';\nimport { cn } from '@/lib/sprout/classes';\nimport {\n  ChartContainer,\n  ChartLegend,\n  ChartLegendContent,\n  ChartTooltip,\n  ChartTooltipContent,\n  chartColor,\n  configLegend,\n  dayLabel,\n  formatNumber,\n  formatPercent,\n  quietAxis,\n  valueDomain,\n  valueTicks,\n  rowFillShape,\n  seriesConfig,\n  stackOffset,\n  tooltipCursor,\n  type ChartConfig,\n  type ChartRow,\n  type ChartSeries,\n  type ChartStack,\n  type ReadyChartProps,\n  type UsageSeries,\n} from '@/lib/sprout/chart-kit';\n\nexport type UsageDay = { date: string } & Record<string, number | string | null>;\n\nexport interface UsageChartProps {\n  days: UsageDay[];\n  series: UsageSeries[];\n  title?: string;\n  locale?: string;\n  className?: string;\n}\n\nexport function UsageChart({ days, series, title = 'Usage by day', locale, className }: UsageChartProps) {\n  const config = useMemo(() => seriesConfig(series), [series]);\n  const usageDay = (date: unknown) => dayLabel(date, locale);\n  return (\n    <ChartContainer data-variant=\"usage\" className={cn('sprout-chart-usage', className)} config={config}>\n      <BarChart data={days} accessibilityLayer title={title} barCategoryGap=\"20%\">\n        <CartesianGrid vertical={false} />\n        <XAxis dataKey=\"date\" tickFormatter={usageDay} {...quietAxis} minTickGap={24} />\n        <YAxis width={40} {...quietAxis} allowDecimals={false} />\n        <ChartTooltip cursor={tooltipCursor} content={<ChartTooltipContent labelFormatter={usageDay} />} />\n        {series.map((item, index) => (\n          <Bar\n            key={item.key}\n            dataKey={item.key}\n            stackId=\"usage\"\n            fill={chartColor(item.key)}\n            radius={index === series.length - 1 ? [3, 3, 0, 0] : 0}\n            isAnimationActive={false}\n          />\n        ))}\n      </BarChart>\n    </ChartContainer>\n  );\n}\n\nexport interface CategoryChartProps extends ReadyChartProps {\n  rows: ChartRow[];\n  category: string;\n  series: ChartSeries[];\n  horizontal?: boolean;\n  stack?: ChartStack;\n  max?: number;\n}\n\nconst hasNegative = (rows: ChartRow[], series: ChartSeries[]) =>\n  rows.some(row => series.some(item => Number(row[item.key]) < 0));\n\nexport function CategoryChart({\n  rows,\n  category,\n  series,\n  horizontal = false,\n  stack = 'none',\n  max,\n  title,\n  valueFormatter = formatNumber,\n  className,\n}: CategoryChartProps) {\n  const config = useMemo(() => seriesConfig(series), [series]);\n  const name = title ?? `${series.map(item => item.label).join(', ')} by ${category}`;\n  const stacked = stack !== 'none';\n  const end = horizontal ? [0, 3, 3, 0] : [3, 3, 0, 0];\n  const tick = stack === 'percent' ? formatPercent : valueFormatter;\n  const categoryAxis = { dataKey: category, ...quietAxis };\n  const valueAxis = {\n    ...quietAxis,\n    tickFormatter: tick,\n    domain: stack === 'percent' ? undefined : valueDomain(max),\n    ticks: stack === 'percent' ? undefined : valueTicks(max),\n  };\n  return (\n    <ChartContainer data-variant=\"category\" className={cn('sprout-chart-category', className)} config={config}>\n      <BarChart\n        data={rows}\n        accessibilityLayer\n        title={name}\n        layout={horizontal ? 'vertical' : 'horizontal'}\n        stackOffset={stackOffset(stack)}\n        barCategoryGap=\"24%\"\n      >\n        <CartesianGrid vertical={horizontal} horizontal={!horizontal} />\n        {horizontal ? (\n          <>\n            <XAxis type=\"number\" {...valueAxis} />\n            <YAxis type=\"category\" width=\"auto\" {...categoryAxis} interval={0} />\n          </>\n        ) : (\n          <>\n            <XAxis {...categoryAxis} minTickGap={16} />\n            <YAxis width=\"auto\" {...valueAxis} allowDecimals={stack === 'percent'} />\n          </>\n        )}\n        {hasNegative(rows, series) ? (\n          <ReferenceLine {...(horizontal ? { x: 0 } : { y: 0 })} stroke=\"var(--sprout-border-strong)\" />\n        ) : null}\n        <ChartTooltip cursor={tooltipCursor} content={<ChartTooltipContent valueFormatter={valueFormatter} />} />\n        <ChartLegend itemSorter={null} content={<ChartLegendContent />} />\n        {series.map((item, index) => (\n          <Bar\n            key={item.key}\n            dataKey={item.key}\n            stackId={stacked ? 'category' : undefined}\n            fill={chartColor(item.key)}\n            radius={!stacked || index === series.length - 1 ? (end as [number, number, number, number]) : 0}\n            maxBarSize={56}\n            isAnimationActive={false}\n          />\n        ))}\n      </BarChart>\n    </ChartContainer>\n  );\n}\n\nexport interface WaterfallChartProps extends ReadyChartProps {\n  rows: ChartRow[];\n  category: string;\n  value: string;\n  totals?: string[];\n  labels?: { increase?: string; decrease?: string; total?: string };\n}\n\ntype WaterfallKind = 'increase' | 'decrease' | 'total';\n\nconst waterfallColors: Record<WaterfallKind, string> = {\n  increase: 'var(--sprout-green)',\n  decrease: 'var(--sprout-red)',\n  total: 'var(--sprout-blue)',\n};\n\nexport function WaterfallChart({\n  rows,\n  category,\n  value,\n  totals = [],\n  labels,\n  title = 'Running total by step',\n  valueFormatter = formatNumber,\n  className,\n}: WaterfallChartProps) {\n  const steps = useMemo(() => {\n    let running = 0;\n    return rows.map(row => {\n      const name = String(row[category] ?? '');\n      const raw = row[value];\n      const change = Number(raw) || 0;\n      if (totals.includes(name)) {\n        if (raw != null && raw !== '') running = change;\n        return {\n          name,\n          kind: 'total' as const,\n          range: [0, running],\n          amount: running,\n          fill: waterfallColors.total,\n        };\n      }\n      const from = running;\n      running += change;\n      const kind: WaterfallKind = change < 0 ? 'decrease' : 'increase';\n      return {\n        name,\n        kind,\n        range: [from, running],\n        amount: change,\n        fill: waterfallColors[kind],\n      };\n    });\n  }, [rows, category, value, totals]);\n  const config = useMemo<ChartConfig>(\n    () => ({\n      increase: {\n        label: labels?.increase ?? 'Increase',\n        color: waterfallColors.increase,\n      },\n      decrease: {\n        label: labels?.decrease ?? 'Decrease',\n        color: waterfallColors.decrease,\n      },\n      total: { label: labels?.total ?? 'Total', color: waterfallColors.total },\n    }),\n    [labels],\n  );\n  return (\n    <ChartContainer data-variant=\"waterfall\" className={cn('sprout-chart-waterfall', className)} config={config}>\n      <BarChart data={steps} accessibilityLayer title={title} barCategoryGap=\"16%\">\n        <CartesianGrid vertical={false} />\n        <XAxis dataKey=\"name\" {...quietAxis} minTickGap={8} />\n        <YAxis width=\"auto\" {...quietAxis} tickFormatter={valueFormatter} />\n        <ReferenceLine y={0} stroke=\"var(--sprout-border-strong)\" />\n        <ChartLegend content={configLegend(config)} />\n        <ChartTooltip\n          cursor={tooltipCursor}\n          content={props => (\n            <ChartTooltipContent\n              active={props.active}\n              label={props.label}\n              nameKey=\"kind\"\n              valueFormatter={valueFormatter}\n              payload={props.payload?.map(item => ({\n                ...item,\n                value: (item.payload as { amount: number }).amount,\n              }))}\n            />\n          )}\n        />\n        <Bar dataKey=\"range\" radius={3} shape={rowFillShape} isAnimationActive={false} />\n      </BarChart>\n    </ChartContainer>\n  );\n}\n"
    },
    {
      "path": "registry/sprout/lib/sprout/charts/lines.tsx",
      "type": "registry:lib",
      "target": "lib/sprout/charts/lines.tsx",
      "content": "'use client';\n\nimport { useId, useMemo } from 'react';\nimport { Area, Bar, CartesianGrid, ComposedChart, Line, XAxis, YAxis } from 'recharts';\nimport { cn } from '@/lib/sprout/classes';\nimport {\n  ChartContainer,\n  ChartLegend,\n  ChartLegendContent,\n  ChartTooltip,\n  ChartTooltipContent,\n  chartColor,\n  formatNumber,\n  formatPercent,\n  quietAxis,\n  valueDomain,\n  valueTicks,\n  seriesConfig,\n  stackOffset,\n  tooltipCursor,\n  type ChartRow,\n  type ChartSeries,\n  type ChartStack,\n  type ReadyChartProps,\n  type ValueFormatter,\n} from '@/lib/sprout/chart-kit';\n\nexport type TrendCurve = 'smooth' | 'linear' | 'step';\n\nconst curveType = {\n  smooth: 'monotone',\n  linear: 'linear',\n  step: 'step',\n} as const;\n\ntype Mark = 'line' | 'area' | 'bar';\n\nexport type ComboSeries = ChartSeries & {\n  kind?: 'bar' | 'line';\n  axis?: 'left' | 'right';\n};\n\ninterface SeriesPlotProps extends ReadyChartProps {\n  variant: string;\n  rows: ChartRow[];\n  category: string;\n  series: (ChartSeries & { axis?: 'left' | 'right' })[];\n  mark: (item: ComboSeries) => Mark;\n  curve: TrendCurve;\n  dots: boolean;\n  stack: ChartStack;\n  categoryFormatter?: (value: unknown) => string;\n  rightValueFormatter?: ValueFormatter;\n  max?: number;\n}\n\nfunction SeriesPlot({\n  variant,\n  rows,\n  category,\n  series,\n  mark,\n  curve,\n  dots,\n  stack,\n  title,\n  valueFormatter = formatNumber,\n  rightValueFormatter = valueFormatter,\n  categoryFormatter,\n  max,\n  className,\n}: SeriesPlotProps) {\n  const config = useMemo(() => seriesConfig(series), [series]);\n  const gradient = `sprout-area-${useId().replace(/:/g, '')}`;\n  const stacked = stack !== 'none';\n  const right = series.some(item => item.axis === 'right');\n  const anyBar = series.some(item => mark(item) === 'bar');\n  const tick = stack === 'percent' ? formatPercent : valueFormatter;\n  const format = (key: string) =>\n    series.find(item => item.key === key)?.axis === 'right' ? rightValueFormatter : valueFormatter;\n  const name = title ?? `${series.map(item => item.label).join(', ')} by ${category}`;\n  const type = curveType[curve];\n  return (\n    <ChartContainer data-variant={variant} className={cn(`sprout-chart-${variant}`, className)} config={config}>\n      <ComposedChart\n        data={rows}\n        accessibilityLayer\n        title={name}\n        stackOffset={stackOffset(stack)}\n        barCategoryGap=\"24%\"\n        margin={{ top: 4, right: right ? 0 : 12, bottom: 0, left: 0 }}\n      >\n        <defs>\n          {series.map(item => (\n            <linearGradient key={item.key} id={`${gradient}-${item.key}`} x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\">\n              <stop offset=\"5%\" stopColor={chartColor(item.key)} stopOpacity={0.4} />\n              <stop offset=\"95%\" stopColor={chartColor(item.key)} stopOpacity={0.04} />\n            </linearGradient>\n          ))}\n        </defs>\n        <CartesianGrid vertical={false} />\n        <XAxis dataKey={category} tickFormatter={categoryFormatter} {...quietAxis} minTickGap={16} />\n        <YAxis\n          yAxisId=\"left\"\n          width=\"auto\"\n          tickFormatter={tick}\n          domain={stack === 'percent' ? undefined : valueDomain(max)}\n          ticks={stack === 'percent' ? undefined : valueTicks(max)}\n          {...quietAxis}\n        />\n        {right ? (\n          <YAxis yAxisId=\"right\" orientation=\"right\" width=\"auto\" tickFormatter={rightValueFormatter} {...quietAxis} />\n        ) : null}\n        <ChartTooltip\n          cursor={anyBar ? tooltipCursor : true}\n          content={props => (\n            <ChartTooltipContent\n              active={props.active}\n              label={props.label}\n              indicator={anyBar ? 'dot' : 'line'}\n              labelFormatter={\n                categoryFormatter\n                  ? (_, payload) => categoryFormatter((payload[0]?.payload as ChartRow | undefined)?.[category])\n                  : undefined\n              }\n              payload={props.payload?.map(item => ({\n                ...item,\n                value: typeof item.value === 'number' ? format(String(item.dataKey))(item.value) : item.value,\n              }))}\n            />\n          )}\n        />\n        {series.length > 1 ? (\n          <ChartLegend verticalAlign=\"top\" itemSorter={null} content={<ChartLegendContent />} />\n        ) : null}\n        {series.map((item, index) => {\n          const color = chartColor(item.key);\n          const shared = {\n            dataKey: item.key,\n            yAxisId: item.axis ?? 'left',\n            stackId: stacked ? 'series' : undefined,\n            isAnimationActive: false,\n          };\n          const kind = mark(item);\n          if (kind === 'bar')\n            return (\n              <Bar\n                key={item.key}\n                {...shared}\n                fill={color}\n                radius={!stacked || index === series.length - 1 ? [3, 3, 0, 0] : 0}\n              />\n            );\n          if (kind === 'area')\n            return (\n              <Area\n                key={item.key}\n                {...shared}\n                type={type}\n                stroke={color}\n                strokeWidth={2}\n                fill={`url(#${gradient}-${item.key})`}\n                dot={dots ? { r: 3, fill: color } : false}\n                activeDot={{ r: 4 }}\n              />\n            );\n          return (\n            <Line\n              key={item.key}\n              {...shared}\n              type={type}\n              stroke={color}\n              strokeWidth={2}\n              dot={dots ? { r: 3, fill: color } : false}\n              activeDot={{ r: 4 }}\n            />\n          );\n        })}\n      </ComposedChart>\n    </ChartContainer>\n  );\n}\n\ninterface TrendBaseProps extends ReadyChartProps {\n  rows: ChartRow[];\n  category: string;\n  series: ChartSeries[];\n  curve?: TrendCurve;\n  dots?: boolean;\n  categoryFormatter?: (value: unknown) => string;\n  max?: number;\n}\n\nexport type TrendChartProps = TrendBaseProps;\n\nexport function TrendChart({ curve = 'smooth', dots = false, ...props }: TrendChartProps) {\n  return <SeriesPlot variant=\"trend\" mark={() => 'line'} curve={curve} dots={dots} stack=\"none\" {...props} />;\n}\n\nexport interface AreaTrendChartProps extends TrendBaseProps {\n  stack?: ChartStack;\n}\n\nexport function AreaTrendChart({ curve = 'smooth', dots = false, stack = 'none', ...props }: AreaTrendChartProps) {\n  return <SeriesPlot variant=\"area\" mark={() => 'area'} curve={curve} dots={dots} stack={stack} {...props} />;\n}\n\nexport interface ComboChartProps extends ReadyChartProps {\n  rows: ChartRow[];\n  category: string;\n  series: ComboSeries[];\n  rightValueFormatter?: ValueFormatter;\n  categoryFormatter?: (value: unknown) => string;\n  stacked?: boolean;\n}\n\nexport function ComboChart({ stacked = false, ...props }: ComboChartProps) {\n  return (\n    <SeriesPlot\n      variant=\"combo\"\n      mark={item => item.kind ?? 'bar'}\n      curve=\"smooth\"\n      dots\n      stack={stacked ? 'stacked' : 'none'}\n      {...props}\n    />\n  );\n}\n\nexport interface SparklineProps {\n  values: number[];\n  title: string;\n  color?: string;\n  area?: boolean;\n  valueFormatter?: ValueFormatter;\n  className?: string;\n}\n\nexport function Sparkline({\n  values,\n  title,\n  color = 'var(--sprout-chart-1)',\n  area = false,\n  valueFormatter = formatNumber,\n  className,\n}: SparklineProps) {\n  const rows = useMemo(() => values.map((value, index) => ({ index, value })), [values]);\n  const config = useMemo(() => ({ value: { label: title, color } }), [title, color]);\n  const gradient = `sprout-spark-${useId().replace(/:/g, '')}`;\n  return (\n    <ChartContainer\n      data-variant=\"sparkline\"\n      className={cn('sprout-chart-sparkline', className)}\n      config={config}\n      initialDimension={{ width: 120, height: 40 }}\n    >\n      <ComposedChart data={rows} accessibilityLayer title={title} margin={{ top: 4, right: 4, bottom: 4, left: 4 }}>\n        <defs>\n          <linearGradient id={gradient} x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\">\n            <stop offset=\"5%\" stopColor={chartColor('value')} stopOpacity={0.3} />\n            <stop offset=\"95%\" stopColor={chartColor('value')} stopOpacity={0} />\n          </linearGradient>\n        </defs>\n        <YAxis hide domain={['dataMin', 'dataMax']} />\n        <ChartTooltip\n          cursor={false}\n          content={<ChartTooltipContent hideLabel indicator=\"line\" valueFormatter={valueFormatter} />}\n        />\n        <Area\n          dataKey=\"value\"\n          type=\"monotone\"\n          stroke={chartColor('value')}\n          strokeWidth={1.5}\n          fill={area ? `url(#${gradient})` : 'none'}\n          dot={false}\n          activeDot={{ r: 3 }}\n          isAnimationActive={false}\n        />\n      </ComposedChart>\n    </ChartContainer>\n  );\n}\n"
    },
    {
      "path": "registry/sprout/lib/sprout/charts/more.tsx",
      "type": "registry:lib",
      "target": "lib/sprout/charts/more.tsx",
      "content": "'use client';\n\nimport { useMemo, type CSSProperties } from 'react';\nimport {\n  CartesianGrid,\n  PolarAngleAxis,\n  PolarGrid,\n  Radar,\n  RadarChart,\n  Sankey,\n  Scatter,\n  ScatterChart,\n  XAxis,\n  YAxis,\n  ZAxis,\n  type SankeyLinkProps,\n  type SankeyNodeProps,\n} from 'recharts';\nimport { cn } from '@/lib/sprout/classes';\nimport {\n  ChartContainer,\n  ChartLegend,\n  ChartLegendContent,\n  ChartTooltip,\n  ChartTooltipContent,\n  chartColor,\n  chartShade,\n  configLegend,\n  formatNumber,\n  partColor,\n  quietAxis,\n  seriesConfig,\n  type ChartRow,\n  type ChartSeries,\n  type ReadyChartProps,\n  type ValueFormatter,\n} from '@/lib/sprout/chart-kit';\n\nconst HEAT_STEPS = 5;\n\nexport interface HeatmapChartProps extends ReadyChartProps {\n  rows: ChartRow[];\n  x: string;\n  y: string;\n  value: string;\n  color?: string;\n  scaleLabels?: [low: string, high: string];\n}\n\nexport function HeatmapChart({\n  rows,\n  x,\n  y,\n  value,\n  color = 'var(--sprout-chart-1)',\n  scaleLabels = ['Less', 'More'],\n  title = `${value} by ${y} and ${x}`,\n  valueFormatter = formatNumber,\n  className,\n}: HeatmapChartProps) {\n  const grid = useMemo(() => {\n    const columns = [...new Set(rows.map(row => String(row[x])))];\n    const lines = [...new Set(rows.map(row => String(row[y])))];\n    const cells = new Map(rows.map(row => [`${String(row[y])}\\u0000${String(row[x])}`, Number(row[value]) || 0]));\n    const max = Math.max(0, ...cells.values());\n    return { columns, lines, cells, max };\n  }, [rows, x, y, value]);\n  const shade = (step: number) => (step === 0 ? 'var(--sprout-secondary)' : chartShade(color, step));\n  const step = (amount: number) => (grid.max > 0 && amount > 0 ? Math.ceil((amount / grid.max) * HEAT_STEPS) : 0);\n  return (\n    <div data-slot=\"chart\" data-variant=\"heatmap\" className={cn('sprout-chart-heatmap', className)}>\n      <div className=\"sprout-chart-heatmap-scroll\">\n        <table\n          className=\"sprout-chart-heatmap-table\"\n          style={{ '--sprout-heat-columns': grid.columns.length } as CSSProperties}\n        >\n          <caption className=\"sprout-chart-sr-only\">{title}</caption>\n          <thead>\n            <tr>\n              <td />\n              {grid.columns.map(column => (\n                <th key={column} scope=\"col\">\n                  {column}\n                </th>\n              ))}\n            </tr>\n          </thead>\n          <tbody>\n            {grid.lines.map(line => (\n              <tr key={line}>\n                <th scope=\"row\">{line}</th>\n                {grid.columns.map(column => {\n                  const amount = grid.cells.get(`${line}\\u0000${column}`) ?? 0;\n                  const text = valueFormatter(amount);\n                  return (\n                    <td\n                      key={column}\n                      data-tip={`${line} · ${column}: ${text}`}\n                      style={{ backgroundColor: shade(step(amount)) }}\n                    >\n                      <span className=\"sprout-chart-sr-only\">{text}</span>\n                    </td>\n                  );\n                })}\n              </tr>\n            ))}\n          </tbody>\n        </table>\n      </div>\n      <div className=\"sprout-chart-heatmap-scale\" aria-hidden=\"true\">\n        <span>{scaleLabels[0]}</span>\n        {Array.from({ length: HEAT_STEPS + 1 }, (_, index) => (\n          <i key={index} style={{ backgroundColor: shade(index) }} />\n        ))}\n        <span>{scaleLabels[1]}</span>\n      </div>\n    </div>\n  );\n}\n\nexport type ScatterSeries = ChartSeries & { rows: ChartRow[] };\n\nexport interface ScatterPlotChartProps extends ReadyChartProps {\n  series: ScatterSeries[];\n  x: string;\n  y: string;\n  size?: string;\n  labels?: { x?: string; y?: string; size?: string };\n  xValueFormatter?: ValueFormatter;\n}\n\nexport function ScatterPlotChart({\n  series,\n  x,\n  y,\n  size,\n  labels,\n  title,\n  valueFormatter = formatNumber,\n  xValueFormatter = formatNumber,\n  className,\n}: ScatterPlotChartProps) {\n  const config = useMemo(() => seriesConfig(series), [series]);\n  return (\n    <ChartContainer data-variant=\"scatter\" className={cn('sprout-chart-scatter', className)} config={config}>\n      <ScatterChart\n        accessibilityLayer\n        title={title ?? `${labels?.y ?? y} by ${labels?.x ?? x}`}\n        margin={{ top: 8, right: 12, bottom: 0, left: 0 }}\n      >\n        <CartesianGrid />\n        <XAxis type=\"number\" dataKey={x} name={labels?.x ?? x} tickFormatter={xValueFormatter} {...quietAxis} />\n        <YAxis\n          type=\"number\"\n          dataKey={y}\n          name={labels?.y ?? y}\n          width=\"auto\"\n          tickFormatter={valueFormatter}\n          {...quietAxis}\n        />\n        {size ? (\n          <ZAxis type=\"number\" dataKey={size} name={labels?.size ?? size} range={[40, 480]} />\n        ) : (\n          <ZAxis range={[48, 48]} />\n        )}\n        <ChartTooltip\n          cursor={{ strokeDasharray: '3 3' }}\n          content={props => (\n            <ChartTooltipContent\n              active={props.active}\n              hideLabel\n              payload={props.payload?.map(item => ({\n                ...item,\n                value:\n                  typeof item.value === 'number'\n                    ? (item.dataKey === x ? xValueFormatter : valueFormatter)(item.value)\n                    : item.value,\n              }))}\n            />\n          )}\n        />\n        {series.length > 1 ? <ChartLegend content={configLegend(config)} /> : null}\n        {series.map(item => (\n          <Scatter\n            key={item.key}\n            name={item.label}\n            data={item.rows}\n            fill={chartColor(item.key)}\n            fillOpacity={0.8}\n            isAnimationActive={false}\n          />\n        ))}\n      </ScatterChart>\n    </ChartContainer>\n  );\n}\n\nexport interface SankeyChartProps extends ReadyChartProps {\n  nodes: { name: string }[];\n  links: { source: number; target: number; value: number }[];\n}\n\nexport function SankeyChart({\n  nodes,\n  links,\n  title = 'Flow between stages',\n  valueFormatter = formatNumber,\n  className,\n}: SankeyChartProps) {\n  const data = useMemo(() => ({ nodes, links }), [nodes, links]);\n  const config = useMemo(\n    () => Object.fromEntries(nodes.map((node, index) => [node.name, { label: node.name, color: partColor(index) }])),\n    [nodes],\n  );\n  const node = ({ x, y, width, height, index, payload }: SankeyNodeProps) => {\n    const last = !(payload as { targetLinks?: unknown[] }).targetLinks?.length;\n    return (\n      <g>\n        <rect x={x} y={y} width={width} height={height} rx={2} fill={partColor(index)} />\n        <text\n          x={last ? x - 8 : x + width + 8}\n          y={y + height / 2}\n          textAnchor={last ? 'end' : 'start'}\n          dominantBaseline=\"middle\"\n          className=\"sprout-chart-sankey-label\"\n        >\n          {payload.name}\n          <tspan className=\"sprout-chart-sankey-value\" dx={6}>\n            {valueFormatter(payload.value)}\n          </tspan>\n        </text>\n      </g>\n    );\n  };\n  const link = ({\n    sourceX,\n    targetX,\n    sourceY,\n    targetY,\n    sourceControlX,\n    targetControlX,\n    linkWidth,\n    payload,\n  }: SankeyLinkProps) => {\n    const source = nodes.findIndex(item => item.name === (payload.source as { name?: string }).name);\n    return (\n      <path\n        d={`M${sourceX},${sourceY}C${sourceControlX},${sourceY} ${targetControlX},${targetY} ${targetX},${targetY}`}\n        fill=\"none\"\n        stroke={partColor(source)}\n        strokeOpacity={0.28}\n        strokeWidth={linkWidth}\n        className=\"sprout-chart-sankey-link\"\n      />\n    );\n  };\n  return (\n    <ChartContainer\n      data-variant=\"sankey\"\n      className={cn('sprout-chart-sankey', className)}\n      config={config}\n      role=\"img\"\n      aria-label={title}\n    >\n      <Sankey\n        data={data}\n        nodePadding={24}\n        nodeWidth={10}\n        margin={{ top: 8, right: 8, bottom: 8, left: 8 }}\n        node={node}\n        link={link}\n      >\n        <ChartTooltip content={<ChartTooltipContent hideLabel valueFormatter={valueFormatter} />} />\n      </Sankey>\n    </ChartContainer>\n  );\n}\n\nexport interface RadarScoreChartProps extends ReadyChartProps {\n  rows: ChartRow[];\n  category: string;\n  series: ChartSeries[];\n}\n\nexport function RadarScoreChart({\n  rows,\n  category,\n  series,\n  title,\n  valueFormatter = formatNumber,\n  className,\n}: RadarScoreChartProps) {\n  const config = useMemo(() => seriesConfig(series), [series]);\n  return (\n    <ChartContainer data-variant=\"radar\" className={cn('sprout-chart-radar', className)} config={config}>\n      <RadarChart\n        data={rows}\n        accessibilityLayer\n        title={title ?? `${series.map(item => item.label).join(', ')} by ${category}`}\n        outerRadius=\"72%\"\n      >\n        <PolarGrid />\n        <PolarAngleAxis dataKey={category} />\n        <ChartTooltip content={<ChartTooltipContent indicator=\"line\" valueFormatter={valueFormatter} />} />\n        {series.length > 1 ? <ChartLegend itemSorter={null} content={<ChartLegendContent />} /> : null}\n        {series.map(item => (\n          <Radar\n            key={item.key}\n            dataKey={item.key}\n            stroke={chartColor(item.key)}\n            strokeWidth={2}\n            fill={chartColor(item.key)}\n            fillOpacity={0.18}\n            dot={{ r: 3, fillOpacity: 1 }}\n            isAnimationActive={false}\n          />\n        ))}\n      </RadarChart>\n    </ChartContainer>\n  );\n}\n"
    },
    {
      "path": "registry/sprout/lib/sprout/charts/parts.tsx",
      "type": "registry:lib",
      "target": "lib/sprout/charts/parts.tsx",
      "content": "'use client';\n\nimport { useMemo } from 'react';\nimport {\n  Bar,\n  BarChart,\n  Label,\n  Pie,\n  PieChart,\n  PolarAngleAxis,\n  PolarRadiusAxis,\n  RadialBar,\n  RadialBarChart,\n  Treemap,\n  XAxis,\n  YAxis,\n  type TreemapNode,\n} from 'recharts';\nimport { cn } from '@/lib/sprout/classes';\nimport {\n  ChartContainer,\n  ChartLegend,\n  ChartTooltip,\n  ChartTooltipContent,\n  chartShade,\n  configLegend,\n  foldParts,\n  formatNumber,\n  partConfig,\n  quietAxis,\n  rowFillShape,\n  tooltipCursor,\n  type ChartRow,\n  type ReadyChartProps,\n} from '@/lib/sprout/chart-kit';\n\ninterface PartChartProps extends ReadyChartProps {\n  rows: ChartRow[];\n  category: string;\n  value: string;\n}\n\nconst centerText = (viewBox: unknown, main: string, sub: string | undefined, lift = 0) => {\n  const box = viewBox as\n    | {\n        cx?: number;\n        cy?: number;\n        x?: number;\n        y?: number;\n        width?: number;\n        height?: number;\n      }\n    | undefined;\n  const cx = box?.cx ?? (box?.x ?? 0) + (box?.width ?? NaN) / 2;\n  const cy = box?.cy ?? (box?.y ?? 0) + (box?.height ?? NaN) / 2;\n  if (!Number.isFinite(cx) || !Number.isFinite(cy)) return null;\n  const y = cy - lift;\n  return (\n    <text x={cx} y={y} textAnchor=\"middle\" dominantBaseline=\"middle\" className=\"sprout-chart-center\">\n      <tspan x={cx} y={sub ? y - 8 : y} className=\"sprout-chart-center-value\">\n        {main}\n      </tspan>\n      {sub ? (\n        <tspan x={cx} y={y + 14} className=\"sprout-chart-center-label\">\n          {sub}\n        </tspan>\n      ) : null}\n    </text>\n  );\n};\n\nexport interface DonutChartProps extends PartChartProps {\n  variant?: 'donut' | 'pie';\n  totalLabel?: string;\n}\n\nexport function DonutChart({\n  rows,\n  category,\n  value,\n  variant = 'donut',\n  totalLabel,\n  title,\n  valueFormatter = formatNumber,\n  className,\n}: DonutChartProps) {\n  const parts = useMemo(() => foldParts(rows, category, value), [rows, category, value]);\n  const config = useMemo(() => partConfig(parts), [parts]);\n  const total = parts.reduce((sum, part) => sum + part.value, 0);\n  const donut = variant === 'donut';\n  return (\n    <ChartContainer data-variant={variant} className={cn('sprout-chart-donut', className)} config={config}>\n      <PieChart accessibilityLayer title={title ?? `${value} by ${category}`}>\n        <ChartTooltip content={<ChartTooltipContent hideLabel valueFormatter={valueFormatter} />} />\n        <ChartLegend content={configLegend(config)} />\n        <Pie\n          data={parts}\n          dataKey=\"value\"\n          nameKey=\"name\"\n          innerRadius={donut ? '62%' : 0}\n          outerRadius=\"92%\"\n          paddingAngle={donut && parts.length > 1 ? 2 : 0}\n          cornerRadius={donut ? 3 : 0}\n          stroke=\"var(--sprout-surface)\"\n          strokeWidth={donut ? 0 : 1}\n          isAnimationActive={false}\n        >\n          {donut ? (\n            <Label\n              position=\"center\"\n              content={({ viewBox }) => centerText(viewBox, valueFormatter(total), totalLabel)}\n            />\n          ) : null}\n        </Pie>\n      </PieChart>\n    </ChartContainer>\n  );\n}\n\nexport interface StepFunnelChartProps extends PartChartProps {\n  color?: string;\n}\n\nexport function StepFunnelChart({\n  rows,\n  category,\n  value,\n  color = 'var(--sprout-chart-1)',\n  title = 'Conversion by step',\n  valueFormatter = formatNumber,\n  className,\n}: StepFunnelChartProps) {\n  const steps = useMemo(() => {\n    const values = rows.map(row => Math.max(0, Number(row[value]) || 0));\n    const top = Math.max(0, ...values);\n    const first = values[0] || 1;\n    return rows.map((row, index) => {\n      const count = values[index] ?? 0;\n      const share = Math.round((count / first) * 100);\n      return {\n        name: String(row[category] ?? ''),\n        detail: `${valueFormatter(count)} · ${share}%`,\n        count,\n        range: [(top - count) / 2, (top + count) / 2],\n        fill: chartShade(color, rows.length * 2 - index, rows.length * 2),\n      };\n    });\n  }, [rows, category, value, color, valueFormatter]);\n  const config = useMemo(() => ({ count: { label: value, color } }), [value, color]);\n  return (\n    <ChartContainer\n      data-variant=\"funnel\"\n      className={cn('sprout-chart-funnel', className)}\n      style={{ height: `${steps.length * 2.5 + 1}rem` }}\n      config={config}\n    >\n      <BarChart\n        data={steps}\n        accessibilityLayer\n        title={title}\n        layout=\"vertical\"\n        barCategoryGap=\"12%\"\n        margin={{ top: 8, right: 0, bottom: 8, left: 0 }}\n      >\n        <XAxis type=\"number\" hide domain={[0, 'dataMax']} />\n        <YAxis yAxisId=\"name\" type=\"category\" dataKey=\"name\" width=\"auto\" {...quietAxis} interval={0} />\n        <YAxis\n          yAxisId=\"detail\"\n          type=\"category\"\n          dataKey=\"detail\"\n          orientation=\"right\"\n          width=\"auto\"\n          {...quietAxis}\n          interval={0}\n        />\n        <ChartTooltip\n          cursor={tooltipCursor}\n          content={props => (\n            <ChartTooltipContent\n              active={props.active}\n              label={props.label}\n              valueFormatter={valueFormatter}\n              payload={props.payload?.map(item => ({\n                ...item,\n                name: 'count',\n                value: (item.payload as { count: number }).count,\n                color,\n              }))}\n            />\n          )}\n        />\n        <Bar yAxisId=\"name\" dataKey=\"range\" radius={4} shape={rowFillShape} isAnimationActive={false} />\n      </BarChart>\n    </ChartContainer>\n  );\n}\n\nconst treemapBox = (node: TreemapNode, format: (value: number) => string) => {\n  const { x, y, width, height, depth } = node;\n  if (depth !== 1) return <g />;\n  const fill = (node as TreemapNode & { fill?: string }).fill;\n  const roomy = width > 64 && height > 36;\n  return (\n    <g>\n      <rect\n        x={x}\n        y={y}\n        width={width}\n        height={height}\n        rx={4}\n        fill={fill}\n        stroke=\"var(--sprout-surface)\"\n        strokeWidth={2}\n      />\n      {roomy ? (\n        <text x={x + 8} y={y + 18} className=\"sprout-chart-treemap-label\">\n          <tspan x={x + 8}>{node.name}</tspan>\n          <tspan x={x + 8} dy={16} className=\"sprout-chart-treemap-value\">\n            {format(node.value)}\n          </tspan>\n        </text>\n      ) : null}\n    </g>\n  );\n};\n\nexport type TreemapChartProps = PartChartProps;\n\nexport function TreemapChart({\n  rows,\n  category,\n  value,\n  title,\n  valueFormatter = formatNumber,\n  className,\n}: TreemapChartProps) {\n  const parts = useMemo(() => foldParts(rows, category, value), [rows, category, value]);\n  const config = useMemo(() => partConfig(parts), [parts]);\n  return (\n    <ChartContainer\n      data-variant=\"treemap\"\n      className={cn('sprout-chart-treemap', className)}\n      config={config}\n      role=\"img\"\n      aria-label={title ?? `${value} by ${category}`}\n    >\n      <Treemap\n        data={parts}\n        dataKey=\"value\"\n        nameKey=\"name\"\n        aspectRatio={4 / 3}\n        isAnimationActive={false}\n        content={(node: TreemapNode) => treemapBox(node, valueFormatter)}\n      >\n        <ChartTooltip content={<ChartTooltipContent hideLabel valueFormatter={valueFormatter} />} />\n      </Treemap>\n    </ChartContainer>\n  );\n}\n\nexport interface GaugeChartProps {\n  value: number;\n  max?: number;\n  label?: string;\n  title: string;\n  color?: string;\n  valueFormatter?: (value: number, max: number) => string;\n  className?: string;\n}\n\nconst percentOfMax = (value: number, max: number) => `${Math.round((value / (max || 1)) * 100)}%`;\n\nexport function GaugeChart({\n  value,\n  max = 100,\n  label,\n  title,\n  color = 'var(--sprout-chart-1)',\n  valueFormatter = percentOfMax,\n  className,\n}: GaugeChartProps) {\n  const data = useMemo(\n    () => [{ name: 'value', value: Math.min(Math.max(value, 0), max), fill: color }],\n    [value, max, color],\n  );\n  const config = useMemo(() => ({ value: { label: title, color } }), [title, color]);\n  return (\n    <ChartContainer\n      data-variant=\"gauge\"\n      className={cn('sprout-chart-gauge', className)}\n      config={config}\n      role=\"meter\"\n      aria-label={title}\n      aria-valuemin={0}\n      aria-valuemax={max}\n      aria-valuenow={data[0]!.value}\n      aria-valuetext={valueFormatter(value, max)}\n    >\n      <RadialBarChart data={data} startAngle={180} endAngle={0} cy=\"78%\" innerRadius=\"118%\" outerRadius=\"158%\">\n        <PolarAngleAxis type=\"number\" domain={[0, max]} tick={false} />\n        <RadialBar dataKey=\"value\" background cornerRadius={6} isAnimationActive={false} />\n        <PolarRadiusAxis tick={false} axisLine={false}>\n          <Label content={({ viewBox }) => centerText(viewBox, valueFormatter(value, max), label, 12)} />\n        </PolarRadiusAxis>\n      </RadialBarChart>\n    </ChartContainer>\n  );\n}\n"
    }
  ],
  "css": {
    "@layer base": {
      ":root, .light": {
        "--sprout-red": "oklch(58.58% .222 17.58)",
        "--sprout-orange": "oklch(64.61% .1943 41.12)",
        "--sprout-yellow": "oklch(65.2% .1388 73.08)",
        "--sprout-green": "oklch(62.71% .1699 149.21)",
        "--sprout-teal": "oklch(60.02% .1038 184.7)",
        "--sprout-sky": "oklch(58.76% .1389 241.97)",
        "--sprout-blue": "oklch(54.61% .2152 262.88)",
        "--sprout-indigo": "oklch(51.06% .2301 276.97)",
        "--sprout-purple": "oklch(55.75% .2525 302.32)",
        "--sprout-tan": "oklch(61.06% .0869 73.23)"
      },
      ".dark": {
        "--sprout-red": "oklch(65.79% .1955 13.34)",
        "--sprout-orange": "oklch(77.98% .1484 67.74)",
        "--sprout-yellow": "oklch(87.59% .1575 96.07)",
        "--sprout-green": "oklch(77.5% .1715 145.98)",
        "--sprout-teal": "oklch(77.28% .0993 201.91)",
        "--sprout-sky": "oklch(73.46% .111 235.16)",
        "--sprout-blue": "oklch(65.26% .1738 259.4)",
        "--sprout-indigo": "oklch(62.3% .1832 282.92)",
        "--sprout-purple": "oklch(66.45% .1843 308.71)",
        "--sprout-tan": "oklch(74.86% .0626 77.32)"
      },
      "@media (prefers-color-scheme: dark)": {
        ":root:not(.light):not(.dark)": {
          "--sprout-red": "oklch(65.79% .1955 13.34)",
          "--sprout-orange": "oklch(77.98% .1484 67.74)",
          "--sprout-yellow": "oklch(87.59% .1575 96.07)",
          "--sprout-green": "oklch(77.5% .1715 145.98)",
          "--sprout-teal": "oklch(77.28% .0993 201.91)",
          "--sprout-sky": "oklch(73.46% .111 235.16)",
          "--sprout-blue": "oklch(65.26% .1738 259.4)",
          "--sprout-indigo": "oklch(62.3% .1832 282.92)",
          "--sprout-purple": "oklch(66.45% .1843 308.71)",
          "--sprout-tan": "oklch(74.86% .0626 77.32)"
        }
      },
      ":root, .light, .dark": {
        "--sprout-chart-1": "var(--sprout-indigo)",
        "--sprout-chart-2": "var(--sprout-green)",
        "--sprout-chart-3": "var(--sprout-orange)",
        "--sprout-chart-4": "var(--sprout-red)",
        "--sprout-chart-5": "var(--sprout-sky)",
        "--sprout-chart-6": "var(--sprout-purple)",
        "--sprout-chart-7": "var(--sprout-yellow)",
        "--sprout-chart-8": "var(--sprout-teal)",
        "--sprout-chart-9": "var(--sprout-blue)",
        "--sprout-chart-10": "var(--sprout-tan)"
      }
    },
    "@layer components": {
      ".sprout-chart": {
        "aspect-ratio": "16 / 9",
        "min-width": "0",
        "font-family": "var(--sprout-font)",
        "font-size": "var(--sprout-text-xs)",
        "color": "var(--sprout-text)",
        "justify-content": "center",
        "line-height": "1rem",
        "display": "flex",
        "container-type": "inline-size"
      },
      ".sprout-chart .recharts-responsive-container > div > :not(.recharts-wrapper)": {
        "width": "100cqi"
      },
      ".sprout-chart-usage, .sprout-chart-category, .sprout-chart-trend, .sprout-chart-area, .sprout-chart-combo, .sprout-chart-donut, .sprout-chart-funnel, .sprout-chart-waterfall, .sprout-chart-timeline, .sprout-chart-scatter, .sprout-chart-treemap, .sprout-chart-sankey, .sprout-chart-radar, .sprout-chart-sparkline": {
        "aspect-ratio": "auto",
        "width": "100%"
      },
      ".sprout-chart-usage": {
        "height": "16rem"
      },
      ".sprout-chart-category, .sprout-chart-trend, .sprout-chart-area, .sprout-chart-combo, .sprout-chart-donut, .sprout-chart-waterfall, .sprout-chart-scatter, .sprout-chart-treemap": {
        "height": "18rem"
      },
      ".sprout-chart-sankey, .sprout-chart-radar": {
        "height": "20rem"
      },
      ".sprout-chart-sparkline": {
        "height": "2.5rem"
      },
      ".sprout-chart-gauge": {
        "aspect-ratio": "2 / 1.25",
        "width": "100%",
        "max-width": "20rem",
        "margin-inline": "auto"
      },
      ".sprout-chart .recharts-polar-angle-axis-tick-value": {
        "fill": "var(--sprout-muted)"
      },
      ".sprout-chart-center-value": {
        "fill": "var(--sprout-text)",
        "font-variant-numeric": "tabular-nums",
        "font-size": "1.5rem",
        "font-weight": "600"
      },
      ".sprout-chart-center-label": {
        "fill": "var(--sprout-muted)",
        "font-size": "var(--sprout-text-xs)"
      },
      ".sprout-chart-treemap-label": {
        "fill": "var(--sprout-surface)",
        "pointer-events": "none",
        "font-weight": "500"
      },
      ".sprout-chart-treemap-value": {
        "font-variant-numeric": "tabular-nums",
        "font-weight": "400"
      },
      ".sprout-chart-sankey-label": {
        "fill": "var(--sprout-text)",
        "font-weight": "500"
      },
      ".sprout-chart-sankey-value": {
        "fill": "var(--sprout-muted)",
        "font-variant-numeric": "tabular-nums",
        "font-weight": "400"
      },
      ".sprout-chart-sankey-link:hover": {
        "stroke-opacity": ".5"
      },
      ".sprout-chart-heatmap": {
        "width": "100%",
        "font-family": "var(--sprout-font)",
        "font-size": "var(--sprout-text-xs)",
        "color": "var(--sprout-muted)",
        "gap": "12px",
        "line-height": "1rem",
        "display": "grid"
      },
      ".sprout-chart-heatmap-scroll": {
        "overflow-x": "auto"
      },
      ".sprout-chart-heatmap-table": {
        "width": "100%",
        "min-width": "calc(var(--sprout-heat-columns) * 1.25rem + 3rem)",
        "border-collapse": "separate",
        "border-spacing": "3px",
        "table-layout": "fixed"
      },
      ".sprout-chart-heatmap-table th": {
        "white-space": "nowrap",
        "font-weight": "400"
      },
      ".sprout-chart-heatmap-table thead th": {
        "text-overflow": "clip",
        "text-align": "center",
        "overflow": "hidden"
      },
      ".sprout-chart-heatmap-table tbody th": {
        "text-align": "right",
        "width": "3rem",
        "padding-right": "6px"
      },
      ".sprout-chart-heatmap-table td": {
        "border-radius": "3px",
        "height": "1.5rem",
        "position": "relative"
      },
      ".sprout-chart-heatmap-table td[data-tip]:hover": {
        "outline": "1.5px solid var(--sprout-text)",
        "outline-offset": "1px"
      },
      ".sprout-chart-heatmap-table td[data-tip]:hover:after": {
        "content": "attr(data-tip)",
        "z-index": "1",
        "border": "1px solid var(--sprout-line)",
        "border-radius": "var(--sprout-radius-control)",
        "background": "var(--sprout-surface)",
        "color": "var(--sprout-text)",
        "box-shadow": "var(--sprout-shadow-overlay)",
        "white-space": "nowrap",
        "pointer-events": "none",
        "padding": "6px 10px",
        "position": "absolute",
        "bottom": "calc(100% + 6px)",
        "left": "50%",
        "translate": "-50%"
      },
      ".sprout-chart-heatmap-scale": {
        "justify-content": "flex-end",
        "align-items": "center",
        "gap": "3px",
        "display": "flex"
      },
      ".sprout-chart-heatmap-scale > i": {
        "border-radius": "2px",
        "width": "12px",
        "height": "12px"
      },
      ".sprout-chart-heatmap-scale > span:first-child": {
        "margin-right": "4px"
      },
      ".sprout-chart-heatmap-scale > span:last-child": {
        "margin-left": "4px"
      },
      ".sprout-chart-sr-only": {
        "clip-path": "inset(50%)",
        "white-space": "nowrap",
        "width": "1px",
        "height": "1px",
        "position": "absolute",
        "overflow": "hidden"
      },
      ".sprout-chart .recharts-cartesian-axis-tick-value": {
        "fill": "var(--sprout-muted)"
      },
      ".sprout-chart .recharts-cartesian-grid line[stroke=\"oklch(0.8452 0 0)\"], .sprout-chart .recharts-polar-grid [stroke=\"oklch(0.8452 0 0)\"], .sprout-chart .recharts-reference-line [stroke=\"oklch(0.8452 0 0)\"]": {
        "stroke": "var(--sprout-line)"
      },
      ".sprout-chart .recharts-curve.recharts-tooltip-cursor": {
        "stroke": "var(--sprout-border)"
      },
      ".sprout-chart .recharts-rectangle.recharts-tooltip-cursor": {
        "fill": "var(--sprout-hover)"
      },
      ".sprout-chart .recharts-radial-bar-background-sector": {
        "fill": "var(--sprout-secondary)"
      },
      ".sprout-chart .recharts-dot[stroke=\"oklch(1 0 0)\"], .sprout-chart .recharts-sector[stroke=\"oklch(1 0 0)\"]": {
        "stroke": "#0000"
      },
      ".sprout-chart .recharts-layer, .sprout-chart .recharts-sector, .sprout-chart .recharts-wrapper, .sprout-chart .recharts-surface": {
        "outline": "none"
      },
      ".sprout-chart .recharts-surface": {
        "border-radius": "var(--sprout-radius-control)",
        "overflow": "visible"
      },
      ".sprout-chart .recharts-surface:focus-visible": {
        "outline": "var(--sprout-focus-width) solid var(--sprout-focus-ring)",
        "outline-offset": "0"
      },
      ".sprout-chart-tooltip": {
        "border": "1px solid var(--sprout-line)",
        "border-radius": "var(--sprout-radius-control)",
        "background": "var(--sprout-surface)",
        "width": "max-content",
        "min-width": "8rem",
        "max-width": "20rem",
        "color": "var(--sprout-text)",
        "box-shadow": "var(--sprout-shadow-overlay)",
        "font-family": "var(--sprout-font)",
        "font-size": "var(--sprout-text-xs)",
        "align-items": "start",
        "gap": "6px",
        "padding": "6px 10px",
        "line-height": "1rem",
        "display": "grid"
      },
      ".sprout-chart-tooltip-label": {
        "font-weight": "500"
      },
      ".sprout-chart-tooltip-items": {
        "gap": "6px",
        "display": "grid"
      },
      ".sprout-chart-tooltip-item": {
        "flex-wrap": "wrap",
        "align-items": "stretch",
        "gap": "8px",
        "width": "100%",
        "display": "flex"
      },
      ".sprout-chart-tooltip[data-indicator=\"dot\"] .sprout-chart-tooltip-item": {
        "align-items": "center"
      },
      ".sprout-chart-tooltip-item > svg": {
        "width": "10px",
        "height": "10px",
        "color": "var(--sprout-muted)"
      },
      ".sprout-chart-tooltip-indicator": {
        "border": "0 solid var(--sprout-chart-indicator)",
        "background": "var(--sprout-chart-indicator)",
        "border-radius": "2px",
        "flex-shrink": "0"
      },
      "[data-indicator=\"dot\"] .sprout-chart-tooltip-indicator": {
        "width": "10px",
        "height": "10px"
      },
      "[data-indicator=\"line\"] .sprout-chart-tooltip-indicator": {
        "width": "4px"
      },
      "[data-indicator=\"dashed\"] .sprout-chart-tooltip-indicator": {
        "background": "none",
        "border-style": "dashed",
        "border-width": "1.5px",
        "width": "0"
      },
      "[data-indicator=\"dashed\"] .sprout-chart-tooltip-item:has([data-nested]) .sprout-chart-tooltip-indicator": {
        "margin-block": "2px"
      },
      ".sprout-chart-tooltip-row": {
        "flex": "1",
        "justify-content": "space-between",
        "align-items": "center",
        "gap": "12px",
        "line-height": "1",
        "display": "flex"
      },
      ".sprout-chart-tooltip-row[data-nested]": {
        "align-items": "flex-end"
      },
      ".sprout-chart-tooltip-name": {
        "gap": "6px",
        "display": "grid"
      },
      ".sprout-chart-tooltip-name > span": {
        "color": "var(--sprout-muted)"
      },
      ".sprout-chart-tooltip-value": {
        "font-variant-numeric": "tabular-nums",
        "color": "var(--sprout-text)",
        "font-family": "ui-monospace, SFMono-Regular, Menlo, monospace",
        "font-weight": "500"
      },
      ".sprout-chart-legend": {
        "font-family": "var(--sprout-font)",
        "font-size": "var(--sprout-text-xs)",
        "color": "var(--sprout-text)",
        "flex-wrap": "wrap",
        "justify-content": "center",
        "align-items": "center",
        "gap": "4px 16px",
        "padding-top": "12px",
        "line-height": "1rem",
        "display": "flex"
      },
      ".sprout-chart-legend[data-align=\"top\"]": {
        "padding-top": "0",
        "padding-bottom": "12px"
      },
      ".sprout-chart-legend-item": {
        "align-items": "center",
        "gap": "6px",
        "display": "flex"
      },
      ".sprout-chart-legend-item > svg": {
        "width": "12px",
        "height": "12px",
        "color": "var(--sprout-muted)"
      },
      ".sprout-chart-legend-swatch": {
        "border-radius": "2px",
        "flex-shrink": "0",
        "width": "8px",
        "height": "8px"
      },
      "@media (forced-colors: active)": {
        ".sprout-chart-tooltip": {
          "border-color": "canvastext"
        },
        ".sprout-chart-tooltip-indicator, .sprout-chart-legend-swatch, .sprout-chart-heatmap-table td, .sprout-chart-heatmap-scale > i": {
          "forced-color-adjust": "none"
        },
        ".sprout-chart .recharts-surface:focus-visible": {
          "outline-color": "highlight"
        }
      }
    }
  },
  "docs": "Docs and examples: https://sprout.tulipfarm.ai/components/chart/",
  "meta": {
    "source": "packages/sprout/src/components/chart.tsx"
  }
}
