{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "chart-panel-01",
  "description": "This period's area against the previous period's dashed line, with the change written as a sentence.",
  "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-01.tsx",
      "content": "'use client'\n\nimport {\n  BlockStateProvider,\n  type BlockStateProps,\n  getBlockState,\n} from '@/registry/components/dashboardblocks/block-state'\nimport {\n  chartActiveDot,\n  chartAxisProps,\n  chartGridProps,\n  chartLastDot,\n  chartLineCursor,\n  ChartTooltipContent,\n  chartValueAxisWidth,\n  type ChartValueFormatter,\n  useChartId,\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 {\n  formatCompact,\n  formatCurrency,\n  formatNumber,\n} from '@/registry/lib/dashboardblocks/format'\nimport {\n  Area,\n  CartesianGrid,\n  ComposedChart,\n  Line,\n  ResponsiveContainer,\n  Tooltip,\n  XAxis,\n  YAxis,\n} from 'recharts'\n\nimport { Card, CardContent } from '@/components/ui/card'\n\ninterface PeriodPoint {\n  current: number\n  label: string\n  previous: number\n}\n\ninterface ChartPanel1Props extends BlockStateProps {\n  /** Follows the previous total in the change sentence, such as `the previous 30 days`. @default 'the previous period' */\n  comparison?: string\n  currentLabel?: string\n  /** Leave out, or pass none, to show the empty state. */\n  data?: PeriodPoint[]\n  description: string\n  formatter?: ChartValueFormatter\n  previousLabel?: string\n  /** @default true */\n  showPrevious?: boolean\n  title: string\n}\n\nconst exampleProps: ChartPanel1Props = {\n  comparison: 'the previous 30 days',\n  currentLabel: 'September',\n  data: Array.from({ length: 30 }, (_, day) => ({\n    current: Math.round(\n      3900 + day * 42 + Math.sin(day / 2.2) * 420 - (day % 7 > 4 ? 520 : 0),\n    ),\n    label: `Sep ${day + 1}`,\n    previous: Math.round(\n      3700 + day * 18 + Math.sin(day / 2.8 + 1) * 360 - (day % 7 > 4 ? 480 : 0),\n    ),\n  })),\n  description: 'Daily revenue in September, against the 30 days before.',\n  formatter: (value) => formatCurrency(value),\n  previousLabel: 'Previous 30 days',\n  title: 'Revenue',\n}\n\nconst CURRENT_COLOR = 'var(--color-chart-2)'\nconst PREVIOUS_COLOR = 'var(--color-muted-foreground)'\n\nconst ChartPanel1 = (props: ChartPanel1Props) => {\n  const {\n    comparison = 'the previous period',\n    currentLabel = 'This period',\n    data = [],\n    description,\n    formatter = (value) => formatNumber(value),\n    previousLabel = 'Previous period',\n    showPrevious = true,\n    errorMessage,\n    status,\n    title,\n  } = props\n  const gradient = useChartId()\n\n  const currentTotal = data.reduce((sum, point) => sum + point.current, 0)\n  const previousTotal = data.reduce((sum, point) => sum + point.previous, 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                <KPIValue value={currentTotal} format={formatter} />\n                {showPrevious && (\n                  <KPIChange\n                    comparison={comparison}\n                    previous={previousTotal}\n                    value={currentTotal}\n                  />\n                )}\n              </div>\n              {showPrevious && (\n                <ChartPanelLegend\n                  items={[\n                    {\n                      color: CURRENT_COLOR,\n                      label: currentLabel,\n                      shape: 'line',\n                    },\n                    {\n                      color: PREVIOUS_COLOR,\n                      label: previousLabel,\n                      shape: 'line',\n                    },\n                  ]}\n                />\n              )}\n            </div>\n            <ChartPanelFigure className='h-64'>\n              <ResponsiveContainer width='100%' height='100%'>\n                <ComposedChart\n                  aria-label={`${title} chart`}\n                  data={data}\n                  margin={{ top: 8, right: 8, bottom: 0, left: 0 }}\n                >\n                  <defs>\n                    <linearGradient id={gradient} x1='0' y1='0' x2='0' y2='1'>\n                      <stop offset='0%' stopColor={CURRENT_COLOR} stopOpacity={0.3} />\n                      <stop offset='100%' stopColor={CURRENT_COLOR} stopOpacity={0} />\n                    </linearGradient>\n                  </defs>\n                  <CartesianGrid {...chartGridProps} />\n                  <XAxis\n                    {...chartAxisProps}\n                    dataKey='label'\n                    interval='preserveStartEnd'\n                    minTickGap={40}\n                  />\n                  <YAxis\n                    {...chartAxisProps}\n                    tickFormatter={(value: number) => formatCompact(value)}\n                    width={chartValueAxisWidth}\n                  />\n                  <Tooltip\n                    content={(tooltipProps) => (\n                      <ChartTooltipContent {...tooltipProps} valueFormatter={formatter} />\n                    )}\n                    cursor={chartLineCursor}\n                    itemSorter={(item) => (item.dataKey === 'current' ? 0 : 1)}\n                  />\n                  {showPrevious && (\n                    <Line\n                      activeDot={chartActiveDot}\n                      dataKey='previous'\n                      dot={false}\n                      name={previousLabel}\n                      stroke={PREVIOUS_COLOR}\n                      strokeDasharray='3 3'\n                      strokeWidth={1.5}\n                      type='monotone'\n                    />\n                  )}\n                  <Area\n                    activeDot={chartActiveDot}\n                    dataKey='current'\n                    dot={chartLastDot(data.length, CURRENT_COLOR)}\n                    fill={`url(#${gradient})`}\n                    name={currentLabel}\n                    stroke={CURRENT_COLOR}\n                    strokeLinecap='round'\n                    strokeLinejoin='round'\n                    strokeWidth={2}\n                    type='monotone'\n                  />\n                </ComposedChart>\n              </ResponsiveContainer>\n            </ChartPanelFigure>\n            <ChartPanelTable\n              caption={`${title}: ${description}`}\n              columns={[\n                { key: 'label', label: 'Day' },\n                { format: formatter, key: 'current', label: currentLabel },\n                ...(showPrevious\n                  ? [\n                      {\n                        format: formatter,\n                        key: 'previous',\n                        label: previousLabel,\n                      },\n                    ]\n                  : []),\n              ]}\n              rows={data}\n            />\n          </section>\n        </CardContent>\n      </Card>\n    </BlockStateProvider>\n  )\n}\n\nexport { ChartPanel1, exampleProps as chartPanel1ExampleProps, type ChartPanel1Props }\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/chart-panel/chart-panel-01.tsx"
    }
  ],
  "meta": {
    "shows": "This period's area against the previous period's dashed line, with the change written as a sentence.",
    "size": "full",
    "usedWith": [
      "stat-group-02",
      "breakdown-01",
      "data-table-02"
    ],
    "component": "ChartPanel1",
    "props": "{ comparison?: string; currentLabel?: string; data?: { current: number; label: string; previous: number }[]; description: string; formatter?: (value: number) => string; previousLabel?: string; showPrevious?: boolean; title: string; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
