{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "chart-panel-06",
  "description": "Several ordered lines, such as percentiles, in one hue from light to full strength, labelled at their ends, against an SLO line.",
  "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-06.tsx",
      "content": "'use client'\n\nimport {\n  BlockReady,\n  BlockStateProvider,\n  type BlockStateProps,\n  getBlockState,\n} from '@/registry/components/dashboardblocks/block-state'\nimport {\n  chartActiveDot,\n  chartAxisProps,\n  chartGridProps,\n  chartLineCursor,\n  chartReferenceLabel,\n  chartReferenceProps,\n  ChartTooltipContent,\n  chartValueAxisWidth,\n  type ChartValueFormatter,\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  CartesianGrid,\n  LabelList,\n  Line,\n  LineChart,\n  ReferenceLine,\n  ResponsiveContainer,\n  Tooltip,\n  XAxis,\n  YAxis,\n} from 'recharts'\n\nimport { Card, CardContent } from '@/components/ui/card'\n\ninterface Percentile {\n  key: string\n  label: string\n}\n\ninterface ChartPanel6Props extends BlockStateProps {\n  /** Follows `previous` in the change sentence. @default 'the previous period' */\n  comparison?: string\n  /** Leave out, or pass none, to show the empty state. */\n  data?: Array<Record<string, number | string> & { label: string }>\n  description: string\n  formatter?: ChartValueFormatter\n  /** The percentile key shown as the headline number and checked against `limit`. */\n  headline: string\n  labelHeading?: string\n  /** A target for the headline percentile, such as an SLO, drawn as a line. */\n  limit?: { label: string; value: number }\n  percentiles: Percentile[]\n  /** The headline percentile's value at the start of the comparison. */\n  previous?: number\n  title: string\n}\n\nconst exampleProps: ChartPanel6Props = {\n  data: Array.from({ length: 24 }, (_, hour) => {\n    const load = Math.sin(((hour - 6) / 24) * Math.PI * 2) * 0.5 + 0.5\n    const spike = hour === 14 ? 1.6 : 1\n    return {\n      label: `${String(hour).padStart(2, '0')}:00`,\n      p50: Math.round(62 + load * 18),\n      p95: Math.round((140 + load * 60) * (spike > 1 ? 1.25 : 1)),\n      p99: Math.round((260 + load * 120) * spike),\n    }\n  }),\n  comparison: 'this time yesterday',\n  description: 'Response time percentiles for each hour of the last 24.',\n  formatter: (value) => `${formatNumber(value)} ms`,\n  headline: 'p95',\n  limit: { label: 'SLO', value: 240 },\n  percentiles: [\n    { key: 'p50', label: 'p50' },\n    { key: 'p95', label: 'p95' },\n    { key: 'p99', label: 'p99' },\n  ],\n  previous: 151,\n  title: 'API latency',\n}\n\nconst rampColor = (index: number, count: number) => {\n  const strength = count <= 1 ? 100 : Math.round(45 + (55 * index) / (count - 1))\n  return `color-mix(in oklab, var(--color-chart-2) ${strength}%, var(--color-background))`\n}\n\nconst ChartPanel6 = (props: ChartPanel6Props) => {\n  const {\n    comparison = 'the previous period',\n    data = [],\n    description,\n    formatter = (value) => formatNumber(value),\n    headline,\n    labelHeading = 'Hour',\n    limit,\n    percentiles,\n    previous,\n    errorMessage,\n    status,\n    title,\n  } = props\n  const lastIndex = data.length - 1\n  const headlineValue = Number(data[lastIndex]?.[headline] ?? 0)\n  const over = limit\n    ? data.filter((point) => Number(point[headline] ?? 0) > limit.value).length\n    : 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                <p className='text-muted-foreground text-sm'>{headline} now</p>\n                <KPIValue value={headlineValue} format={formatter} />\n                <KPIChange\n                  comparison={comparison}\n                  goodDirection='down'\n                  previous={previous}\n                  value={headlineValue}\n                />\n                {limit && (\n                  <BlockReady className='text-sm'>\n                    <p className='text-muted-foreground text-sm'>\n                      {over === 0\n                        ? `Under the ${formatter(limit.value)} ${limit.label} all ${data.length} ${labelHeading.toLowerCase()}s.`\n                        : `Over the ${formatter(limit.value)} ${limit.label} in ${over} of ${data.length} ${labelHeading.toLowerCase()}s.`}\n                    </p>\n                  </BlockReady>\n                )}\n              </div>\n              <ChartPanelLegend\n                items={percentiles.map((item, index) => ({\n                  color: rampColor(index, percentiles.length),\n                  label: item.label,\n                  shape: 'line',\n                }))}\n              />\n            </div>\n            <ChartPanelFigure className='h-64'>\n              <ResponsiveContainer width='100%' height='100%'>\n                <LineChart\n                  aria-label={`${title} chart`}\n                  data={data}\n                  margin={{ top: 8, right: 40, bottom: 0, left: 0 }}\n                >\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) =>\n                      -percentiles.findIndex(\n                        (percentile) => percentile.key === item.dataKey,\n                      )\n                    }\n                  />\n                  {limit && (\n                    <ReferenceLine\n                      {...chartReferenceProps}\n                      y={limit.value}\n                      label={{\n                        ...chartReferenceLabel,\n                        value: `${limit.label} ${formatter(limit.value)}`,\n                        position: 'insideBottomLeft',\n                        dy: -4,\n                      }}\n                    />\n                  )}\n                  {percentiles.map((item, index) => (\n                    <Line\n                      key={item.key}\n                      activeDot={chartActiveDot}\n                      dataKey={item.key}\n                      dot={false}\n                      name={item.label}\n                      stroke={rampColor(index, percentiles.length)}\n                      strokeLinecap='round'\n                      strokeLinejoin='round'\n                      strokeWidth={item.key === headline ? 2.5 : 1.5}\n                      type='monotone'\n                    >\n                      <LabelList\n                        dataKey={item.key}\n                        content={({ index: pointIndex, x, y }) =>\n                          pointIndex === lastIndex ? (\n                            <text\n                              x={Number(x) + 8}\n                              y={Number(y)}\n                              dominantBaseline='middle'\n                              fontSize={11}\n                              fontWeight={item.key === headline ? 500 : 400}\n                              fill={\n                                item.key === headline\n                                  ? 'var(--color-foreground)'\n                                  : 'var(--color-muted-foreground)'\n                              }\n                            >\n                              {item.label}\n                            </text>\n                          ) : null\n                        }\n                      />\n                    </Line>\n                  ))}\n                </LineChart>\n              </ResponsiveContainer>\n            </ChartPanelFigure>\n            <ChartPanelTable\n              caption={`${title}: ${description}${limit ? ` ${limit.label}: ${formatter(limit.value)}.` : ''}`}\n              columns={[\n                { key: 'label', label: labelHeading },\n                ...percentiles.map((item) => ({\n                  format: formatter,\n                  key: item.key,\n                  label: item.label,\n                })),\n              ]}\n              rows={data}\n            />\n          </section>\n        </CardContent>\n      </Card>\n    </BlockStateProvider>\n  )\n}\n\nexport { ChartPanel6, exampleProps as chartPanel6ExampleProps, type ChartPanel6Props }\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/chart-panel/chart-panel-06.tsx"
    }
  ],
  "meta": {
    "shows": "Several ordered lines, such as percentiles, in one hue from light to full strength, labelled at their ends, against an SLO line.",
    "size": "full",
    "usedWith": [
      "alerts-01",
      "status-02",
      "deployments-01"
    ],
    "component": "ChartPanel6",
    "props": "{ comparison?: string; data?: Record<string, string | number> & { label: string; }[]; description: string; formatter?: (value: number) => string; headline: string; labelHeading?: string; limit?: { label: string; value: number }; percentiles: { key: string; label: string }[]; previous?: number; title: string; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
