{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "chart-panel-03",
  "description": "Monthly totals as stacked bars split by category, with the average and the latest total labelled.",
  "dependencies": [
    "recharts"
  ],
  "registryDependencies": [
    "card",
    "https://www.dashboardblocks.com/r/radix/block-state.json",
    "https://www.dashboardblocks.com/r/radix/chart-panel.json",
    "https://www.dashboardblocks.com/r/radix/kpi.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/chart-panel/chart-panel-03.tsx",
      "content": "'use client'\n\nimport {\n  BlockReady,\n  BlockStateProvider,\n  type BlockStateProps,\n  getBlockState,\n} from '@/registry/components/dashboardblocks/block-state'\nimport {\n  chartAxisProps,\n  chartBarCursor,\n  chartBarValueLabel,\n  chartGridProps,\n  chartReferenceLabel,\n  chartReferenceProps,\n  ChartTooltipContent,\n  chartValueAxisWidth,\n} from '@/registry/components/dashboardblocks/chart'\nimport {\n  ChartPanelFigure,\n  ChartPanelLegend,\n  ChartPanelTable,\n} from '@/registry/components/dashboardblocks/chart-panel'\nimport { KPIChange, KPIValue } from '@/registry/components/dashboardblocks/kpi'\nimport { formatCompact, formatNumber } from '@/registry/lib/dashboardblocks/format'\nimport {\n  Bar,\n  BarChart,\n  CartesianGrid,\n  LabelList,\n  ReferenceLine,\n  ResponsiveContainer,\n  Tooltip,\n  XAxis,\n  YAxis,\n} from 'recharts'\n\nimport { Card, CardContent } from '@/components/ui/card'\n\ninterface StackSeries {\n  color: string\n  key: string\n  label: string\n}\n\ninterface ChartPanel3Props extends BlockStateProps {\n  /** Leave out, or pass no months, to show the empty state. */\n  data?: Array<Record<string, number | string> & { label: string }>\n  description: string\n  series: StackSeries[]\n  title: string\n}\n\nconst exampleProps: ChartPanel3Props = {\n  data: [\n    { enterprise: 48, free: 492, label: 'Oct', pro: 164 },\n    { enterprise: 56, free: 522, label: 'Nov', pro: 171 },\n    { enterprise: 44, free: 474, label: 'Dec', pro: 158 },\n    { enterprise: 64, free: 564, label: 'Jan', pro: 196 },\n    { enterprise: 72, free: 606, label: 'Feb', pro: 214 },\n    { enterprise: 68, free: 588, label: 'Mar', pro: 222 },\n    { enterprise: 84, free: 654, label: 'Apr', pro: 248 },\n    { enterprise: 96, free: 696, label: 'May', pro: 263 },\n    { enterprise: 88, free: 672, label: 'Jun', pro: 271 },\n    { enterprise: 108, free: 744, label: 'Jul', pro: 302 },\n    { enterprise: 116, free: 786, label: 'Aug', pro: 318 },\n    { enterprise: 132, free: 834, label: 'Sep', pro: 347 },\n  ],\n  description: 'New accounts each month over the last 12 months, by plan.',\n  series: [\n    { color: 'var(--color-chart-2)', key: 'free', label: 'Free' },\n    { color: 'var(--color-chart-3)', key: 'pro', label: 'Pro' },\n    { color: 'var(--color-chart-4)', key: 'enterprise', label: 'Enterprise' },\n  ],\n  title: 'Signups by plan',\n}\n\nconst ChartPanel3 = (props: ChartPanel3Props) => {\n  const { data = [], description, series, errorMessage, status, title } = props\n  const totals = data.map((point) =>\n    series.reduce((sum, item) => sum + Number(point[item.key] ?? 0), 0),\n  )\n  const lastIndex = data.length - 1\n  const latest = data[lastIndex]\n  const prior = data[lastIndex - 1]\n  const average =\n    totals.length > 0 ? totals.reduce((sum, total) => sum + total, 0) / totals.length : 0\n  const format = (value: number) => formatNumber(value, { maximumFractionDigits: 0 })\n\n  return (\n    <BlockStateProvider errorMessage={errorMessage} state={getBlockState(status, data)}>\n      <Card>\n        <CardContent>\n          <section className='@container flex flex-col gap-4'>\n            <header className='flex flex-col gap-0.5'>\n              <h2 className='font-semibold tracking-tight'>{title}</h2>\n              <p className='text-muted-foreground text-sm'>{description}</p>\n            </header>\n            <div className='flex flex-wrap items-end justify-between gap-x-6 gap-y-3 border-t pt-4'>\n              <div className='flex flex-col gap-1'>\n                <BlockReady className='w-16 text-sm'>\n                  <p className='text-muted-foreground text-sm'>{latest?.label}</p>\n                </BlockReady>\n                <KPIValue value={totals[lastIndex]} format={format} />\n                <KPIChange\n                  comparison={`in ${prior?.label}`}\n                  previous={totals[lastIndex - 1]}\n                  value={totals[lastIndex]}\n                />\n              </div>\n              <ChartPanelLegend\n                items={series.map((item) => ({ color: item.color, label: item.label }))}\n              />\n            </div>\n            <ChartPanelFigure className='h-64'>\n              <ResponsiveContainer width='100%' height='100%'>\n                <BarChart\n                  aria-label={`${title} chart`}\n                  data={data}\n                  margin={{ top: 20, right: 8, bottom: 0, left: 0 }}\n                >\n                  <CartesianGrid {...chartGridProps} />\n                  <XAxis {...chartAxisProps} dataKey='label' />\n                  <YAxis\n                    {...chartAxisProps}\n                    tickFormatter={(value: number) => formatCompact(value)}\n                    width={chartValueAxisWidth}\n                  />\n                  <Tooltip\n                    content={(tooltipProps) => <ChartTooltipContent {...tooltipProps} />}\n                    cursor={chartBarCursor}\n                  />\n                  {series.map((item, index) => (\n                    <Bar\n                      key={item.key}\n                      dataKey={item.key}\n                      fill={item.color}\n                      maxBarSize={28}\n                      name={item.label}\n                      radius={index === series.length - 1 ? [4, 4, 0, 0] : 0}\n                      stackId='stack'\n                      stroke='var(--color-background)'\n                      strokeWidth={1}\n                    >\n                      {index === series.length - 1 && (\n                        <LabelList\n                          dataKey={item.key}\n                          content={chartBarValueLabel(lastIndex, () =>\n                            format(totals[lastIndex] ?? 0),\n                          )}\n                        />\n                      )}\n                    </Bar>\n                  ))}\n                  {average > 0 && (\n                    <ReferenceLine\n                      {...chartReferenceProps}\n                      y={average}\n                      label={{\n                        ...chartReferenceLabel,\n                        value: `avg ${format(average)}`,\n                        position: 'insideBottomLeft',\n                        dy: -4,\n                      }}\n                    />\n                  )}\n                </BarChart>\n              </ResponsiveContainer>\n            </ChartPanelFigure>\n            <ChartPanelTable\n              caption={`${title}: ${description}`}\n              columns={[\n                { key: 'label', label: 'Month' },\n                ...series.map((item) => ({ key: item.key, label: item.label })),\n              ]}\n              rows={data}\n            />\n          </section>\n        </CardContent>\n      </Card>\n    </BlockStateProvider>\n  )\n}\n\nexport { ChartPanel3, exampleProps as chartPanel3ExampleProps, type ChartPanel3Props }\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/chart-panel/chart-panel-03.tsx"
    }
  ],
  "meta": {
    "shows": "Monthly totals as stacked bars split by category, with the average and the latest total labelled.",
    "size": "full",
    "usedWith": [
      "breakdown-02",
      "data-table-02",
      "stat-group-01"
    ],
    "component": "ChartPanel3",
    "props": "{ data?: Record<string, string | number> & { label: string; }[]; description: string; series: { color: string; key: string; label: string }[]; title: string; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
