{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "chart-panel-02",
  "description": "Tabs for related metrics, each showing its total and change, over a chart of the chosen one with its average.",
  "dependencies": [
    "recharts"
  ],
  "registryDependencies": [
    "card",
    "tabs",
    "https://www.dashboardblocks.com/r/radix/block-state.json",
    "https://www.dashboardblocks.com/r/radix/chart.json",
    "https://www.dashboardblocks.com/r/radix/chart-panel.json",
    "https://www.dashboardblocks.com/r/radix/stat-group.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/chart-panel/chart-panel-02.tsx",
      "content": "'use client'\n\nimport {\n  BlockStateProvider,\n  type BlockStateProps,\n} from '@/registry/components/dashboardblocks/block-state'\nimport {\n  ChartPlaceholder,\n  chartActiveDot,\n  chartAxisProps,\n  chartGridProps,\n  chartLastDot,\n  chartLineCursor,\n  chartReferenceLabel,\n  chartReferenceProps,\n  ChartTooltipContent,\n  chartValueAxisWidth,\n  useChartId,\n} from '@/registry/components/dashboardblocks/chart'\nimport {\n  ChartPanelFigure,\n  ChartPanelTable,\n} from '@/registry/components/dashboardblocks/chart-panel'\nimport {\n  Stat,\n  StatChange,\n  StatChangeContent,\n  StatGroup,\n  StatLabel,\n  type StatMetric,\n  StatValue,\n  formatStatValue,\n  getStatPlaceholders,\n} from '@/registry/components/dashboardblocks/stat-group'\nimport {\n  formatCompact,\n  formatNumber,\n  formatPercent,\n} from '@/registry/lib/dashboardblocks/format'\nimport { useState } from 'react'\nimport {\n  Area,\n  AreaChart,\n  CartesianGrid,\n  ReferenceLine,\n  ResponsiveContainer,\n  Tooltip,\n  XAxis,\n  YAxis,\n} from 'recharts'\n\nimport { Card, CardContent } from '@/components/ui/card'\nimport { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs'\n\ninterface ChartPanel2Props extends BlockStateProps {\n  /** Follows the previous value in each change, such as `the previous 14 days`. @default 'the previous period' */\n  comparison?: string\n  /** Leave out, or pass no days, to show the empty state. */\n  data?: Array<Record<string, number | string> & { label: string }>\n  description: string\n  /** Leave out, or pass none, to show the empty state. */\n  metrics?: StatMetric[]\n  /** How many metrics to sketch while loading. @default 3 */\n  placeholders?: number\n  title: string\n}\n\nconst exampleProps: ChartPanel2Props = {\n  comparison: 'the previous 14 days',\n  data: Array.from({ length: 14 }, (_, day) => {\n    const weekend = day % 7 > 4\n    const visitors = Math.round(\n      1650 + day * 22 + Math.sin(day / 1.6) * 260 - (weekend ? 420 : 0),\n    )\n    return {\n      bounceRate: Math.round(\n        44 - day * 0.3 + Math.cos(day / 1.8) * 3 + (weekend ? 4 : 0),\n      ),\n      label: `Sep ${day + 17}`,\n      pageviews: Math.round(visitors * (3.1 + Math.sin(day / 3) * 0.3)),\n      visitors,\n    }\n  }),\n  description: 'Sep 17 to 30, by day. Pick a metric to chart it.',\n  metrics: [\n    { key: 'visitors', label: 'Visitors', previous: 21_635, value: 24_318 },\n    { key: 'pageviews', label: 'Page views', previous: 75_119, value: 81_204 },\n    {\n      changeType: 'points',\n      formatter: (value) => formatPercent(value / 100),\n      goodDirection: 'down',\n      key: 'bounceRate',\n      label: 'Bounce rate',\n      previous: 44.2,\n      value: 41,\n    },\n  ],\n  title: 'Traffic',\n}\n\nconst SERIES_COLOR = 'var(--color-chart-2)'\n\nconst ChartPanel2 = (props: ChartPanel2Props) => {\n  const {\n    comparison = 'the previous period',\n    data = [],\n    description,\n    metrics = [],\n    placeholders = 3,\n    errorMessage,\n    status,\n    title,\n  } = props\n  const gradient = useChartId()\n  const [active, setActive] = useState<string>()\n  const empty = metrics.length === 0 || data.length === 0\n  const state = status ?? (empty ? 'empty' : undefined)\n\n  const header = (\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  )\n\n  if (state) {\n    return (\n      <BlockStateProvider errorMessage={errorMessage} state={state}>\n        <Card>\n          <CardContent>\n            <section className='@container flex flex-col gap-4'>\n              {header}\n              <StatGroup className='grid-cols-2 gap-x-6 gap-y-3 @xl:grid-cols-3'>\n                {getStatPlaceholders(placeholders).map((metric) => (\n                  <Stat key={metric.key}>\n                    <StatLabel />\n                    <StatValue className='text-3xl @2xl:text-4xl' />\n                    <StatChange className='text-xs' metric={metric} variant='short' />\n                  </Stat>\n                ))}\n              </StatGroup>\n              <ChartPlaceholder className='mt-1' height={240} />\n            </section>\n          </CardContent>\n        </Card>\n      </BlockStateProvider>\n    )\n  }\n\n  return (\n    <Card>\n      <CardContent>\n        <section className='@container flex flex-col gap-4'>\n          {header}\n          <Tabs\n            value={active ?? metrics[0]?.key}\n            onValueChange={(value) => setActive(String(value))}\n            className='gap-0'\n          >\n            <TabsList\n              aria-label={`${title} metrics`}\n              variant='line'\n              className='grid h-auto w-full grid-cols-2 items-stretch gap-x-6 gap-y-3 rounded-none border-t p-0 group-data-horizontal/tabs:h-auto @xl:grid-cols-3'\n            >\n              {metrics.map((metric) => (\n                <TabsTrigger\n                  key={metric.key}\n                  value={metric.key}\n                  className='h-auto min-w-0 flex-col items-start justify-start gap-1 rounded-none px-0 pt-3 pb-3 text-left font-normal whitespace-normal'\n                >\n                  <span className='text-muted-foreground text-sm'>{metric.label}</span>\n                  <span className='text-3xl font-light tracking-tight whitespace-nowrap tabular-nums @2xl:text-4xl'>\n                    {formatStatValue(metric)}\n                  </span>\n                  <StatChangeContent\n                    className='text-xs'\n                    comparison={comparison}\n                    metric={metric}\n                    variant='short'\n                  />\n                </TabsTrigger>\n              ))}\n            </TabsList>\n            {metrics.map((metric) => {\n              const format = metric.formatter ?? ((value: number) => formatNumber(value))\n              const values = data.map((point) => Number(point[metric.key] ?? 0))\n              const average =\n                values.length > 0\n                  ? values.reduce((sum, value) => sum + value, 0) / values.length\n                  : 0\n              return (\n                <TabsContent\n                  key={metric.key}\n                  value={metric.key}\n                  className='mt-1 flex flex-col gap-3 border-t pt-4'\n                >\n                  <ChartPanelFigure className='h-56'>\n                    <ResponsiveContainer width='100%' height='100%'>\n                      <AreaChart\n                        aria-label={`${title}: ${metric.label} 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\n                              offset='0%'\n                              stopColor={SERIES_COLOR}\n                              stopOpacity={0.3}\n                            />\n                            <stop\n                              offset='100%'\n                              stopColor={SERIES_COLOR}\n                              stopOpacity={0}\n                            />\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                          domain={['auto', 'auto']}\n                          tickFormatter={(value: number) =>\n                            metric.formatter\n                              ? metric.formatter(value)\n                              : formatCompact(value)\n                          }\n                          width={chartValueAxisWidth}\n                        />\n                        <Tooltip\n                          content={(tooltipProps) => (\n                            <ChartTooltipContent\n                              {...tooltipProps}\n                              valueFormatter={format}\n                            />\n                          )}\n                          cursor={chartLineCursor}\n                        />\n                        <ReferenceLine\n                          {...chartReferenceProps}\n                          y={average}\n                          label={{\n                            ...chartReferenceLabel,\n                            value: `avg ${format(Math.round(average))}`,\n                            position: 'insideBottomLeft',\n                            dy: -4,\n                          }}\n                        />\n                        <Area\n                          activeDot={chartActiveDot}\n                          dataKey={metric.key}\n                          dot={chartLastDot(data.length, SERIES_COLOR)}\n                          fill={`url(#${gradient})`}\n                          name={metric.label}\n                          stroke={SERIES_COLOR}\n                          strokeLinecap='round'\n                          strokeLinejoin='round'\n                          strokeWidth={2}\n                          type='monotone'\n                        />\n                      </AreaChart>\n                    </ResponsiveContainer>\n                  </ChartPanelFigure>\n                  <ChartPanelTable\n                    caption={`${title}: ${metric.label} by day`}\n                    columns={[\n                      { key: 'label', label: 'Day' },\n                      { format, key: metric.key, label: metric.label },\n                    ]}\n                    rows={data}\n                  />\n                </TabsContent>\n              )\n            })}\n          </Tabs>\n        </section>\n      </CardContent>\n    </Card>\n  )\n}\n\nexport { ChartPanel2, exampleProps as chartPanel2ExampleProps, type ChartPanel2Props }\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/chart-panel/chart-panel-02.tsx"
    }
  ],
  "meta": {
    "shows": "Tabs for related metrics, each showing its total and change, over a chart of the chosen one with its average.",
    "size": "full",
    "usedWith": [
      "realtime-01",
      "leaderboard-01",
      "geo-02"
    ],
    "component": "ChartPanel2",
    "props": "{ comparison?: string; data?: Record<string, string | number> & { label: string; }[]; description: string; metrics?: { changeType?: \"percent\" | \"points\" | \"count\"; detail?: ReactNode; formatter?: (value: number) => string; goodDirection?: \"up\" | \"down\"; key: string; label: string; previous?: number; tone?: \"warning\" | \"bad\"; value: number }[]; placeholders?: number; title: string; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
