{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "chart",
  "title": "Chart",
  "description": "Chart components.",
  "dependencies": [
    "recharts"
  ],
  "registryDependencies": [
    "https://www.dashboardblocks.com/r/radix/block-state.json",
    "https://www.dashboardblocks.com/r/radix/format.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/chart.tsx",
      "content": "'use client'\n\nimport { useBlockState } from '@/registry/components/dashboardblocks/block-state'\nimport { formatNumber } from '@/registry/lib/dashboardblocks/format'\nimport {\n  type ComponentProps,\n  type ReactNode,\n  useEffect,\n  useId,\n  useLayoutEffect,\n  useRef,\n} from 'react'\nimport {\n  Area,\n  AreaChart,\n  Bar,\n  BarChart,\n  type BarProps,\n  type BarShapeProps,\n  Cell,\n  Line,\n  LabelList,\n  LineChart,\n  type LineProps,\n  Rectangle,\n  ReferenceLine,\n  ResponsiveContainer,\n  Text,\n  Tooltip,\n  type TooltipContentProps,\n  useActiveTooltipDataPoints,\n  useActiveTooltipLabel,\n  usePlotArea,\n  useXAxisScale,\n  XAxis,\n  YAxis,\n} from 'recharts'\nimport type { NameType, ValueType } from 'recharts/types/component/DefaultTooltipContent'\n\nimport { cn } from '@/lib/utils'\n\ntype AreaProps = ComponentProps<typeof Area>\n\ntype ChartValueFormatter = (value: number) => string\n\nconst chartAxisProps = {\n  axisLine: false,\n  tickLine: false,\n  tickMargin: 8,\n  tick: { fill: 'var(--color-muted-foreground)', fontSize: 12 },\n} as const\n\nconst chartGridProps = {\n  stroke: 'var(--color-border)',\n  strokeDasharray: '3 3',\n  vertical: false,\n} as const\n\nconst chartTimeGridProps = {\n  horizontal: false,\n  stroke: 'var(--color-border)',\n  strokeOpacity: 0.5,\n} as const\n\nconst chartValueAxisWidth = 48\n\ntype ChartEdgeTickProps = Omit<ComponentProps<typeof Text>, 'children'> & {\n  index?: number\n  payload?: { coordinate: number; value: unknown }\n  tickFormatter?: (value: never, index: number) => string\n  visibleTicksCount?: number\n}\n\n/**\n * An x axis label that keeps the first and last labels inside the chart: the first starts at its\n * point and the last ends at its point. Pass it as `tick={<ChartEdgeTick />}` with\n * `interval='preserveStartEnd'`.\n */\nfunction ChartEdgeTick({\n  index = 0,\n  payload,\n  tickFormatter,\n  visibleTicksCount = 0,\n  ...props\n}: ChartEdgeTickProps) {\n  if (!payload) return null\n  const first = index === 0\n  const last = visibleTicksCount > 1 && index === visibleTicksCount - 1\n  const label = tickFormatter\n    ? tickFormatter(payload.value as never, index)\n    : String(payload.value)\n  return (\n    <Text\n      {...props}\n      {...chartAxisProps.tick}\n      textAnchor={first ? 'start' : last ? 'end' : props.textAnchor}\n      x={first || last ? payload.coordinate : props.x}\n    >\n      {label}\n    </Text>\n  )\n}\n\nconst chartBarCursor = {\n  fill: 'var(--color-muted)',\n  fillOpacity: 0.5,\n} as const\n\nconst chartLineCursor = { stroke: 'var(--color-border)' } as const\n\nconst chartActiveDot = {\n  r: 4,\n  stroke: 'var(--color-background)',\n  strokeWidth: 2,\n} as const\n\nconst chartReferenceColor =\n  'color-mix(in oklab, var(--color-foreground) 40%, transparent)'\n\nconst chartReferenceProps = {\n  stroke: chartReferenceColor,\n  strokeDasharray: '3 3',\n} as const\n\nconst chartReferenceLabel = {\n  fill: 'var(--color-muted-foreground)',\n  fontSize: 11,\n} as const\n\n/**\n * The rest of a series beside a highlighted mark, at 30% of `color`. A main series that sits\n * beside a louder one (calls above their failures) passes a stronger `percent`, such as 70.\n */\nfunction chartFadedColor(color: string, percent = 30) {\n  return `color-mix(in oklab, ${color} ${percent}%, transparent)`\n}\n\n/**\n * Diagonal hatching over a light fill of `color`, for a part that is left over or estimated.\n * Put it in the chart's `<defs>` and fill with `url(#id)`; take `id` from `useChartId()`.\n */\nfunction ChartHatch({ color, id }: { color: string; id: string }) {\n  return (\n    <pattern\n      id={id}\n      width={6}\n      height={6}\n      patternTransform='rotate(45)'\n      patternUnits='userSpaceOnUse'\n    >\n      <rect width={6} height={6} fill={chartFadedColor(color)} />\n      <line\n        x1={0}\n        x2={0}\n        y1={0}\n        y2={6}\n        stroke={color}\n        strokeOpacity={0.35}\n        strokeWidth={2}\n      />\n    </pattern>\n  )\n}\n\n/**\n * Diagonal stripes of `color` as a CSS `background-image`, for an HTML bar or cell that is\n * estimated, projected or still filling. `ChartHatch` is the same for an SVG chart.\n */\nfunction chartHatchFill(color: string) {\n  return `repeating-linear-gradient(-45deg, color-mix(in oklab, ${color} 55%, transparent) 0 2px, color-mix(in oklab, ${color} 18%, transparent) 2px 5px)`\n}\n\n/** A gradient or pattern id that is safe inside `url(#…)`. */\nfunction useChartId() {\n  return useId().replace(/:/g, '')\n}\n\ninterface ChartDotProps {\n  cx?: number\n  cy?: number\n  index?: number\n}\n\n/** A `dot` for a line or area that marks only its last point. */\nfunction chartLastDot(count: number, color: string) {\n  return function LastDot({ cx, cy, index }: ChartDotProps) {\n    return index === count - 1 ? (\n      <circle\n        key={index}\n        cx={cx}\n        cy={cy}\n        r={4}\n        fill={color}\n        stroke='var(--color-background)'\n        strokeWidth={2}\n      />\n    ) : (\n      <g key={index} />\n    )\n  }\n}\n\n/** A `dot` for a line or area that marks its last point as still filling: the dot pulses until the period ends and the line takes `chartLastDot` instead. */\nfunction chartLiveDot(count: number, color: string) {\n  return function LiveDot({ cx, cy, index }: ChartDotProps) {\n    return index === count - 1 ? (\n      <g key={index}>\n        <circle\n          cx={cx}\n          cy={cy}\n          r={4}\n          fill={color}\n          opacity={0.5}\n          className='origin-center animate-ping [transform-box:fill-box] motion-reduce:hidden'\n        />\n        <circle\n          cx={cx}\n          cy={cy}\n          r={4}\n          fill={color}\n          stroke='var(--color-background)'\n          strokeWidth={2}\n        />\n      </g>\n    ) : (\n      <g key={index} />\n    )\n  }\n}\n\ninterface ChartBarLabelProps {\n  index?: number\n  value?: unknown\n  width?: number | string\n  x?: number | string\n  y?: number | string\n}\n\n/** A `LabelList` `content` that writes the value above the bar at `highlightIndex`. */\nconst NICE_STEPS = [1, 2, 2.5, 5]\n\n/** Round ticks from 0 that leave a little room above `max`, at most `intervals` steps. */\nfunction chartNiceTicks(max: number, intervals = 5) {\n  const target = Math.max(max, 0) * 1.05 || 1\n  const scale = 10 ** Math.floor(Math.log10(target / intervals))\n  const step =\n    [...NICE_STEPS, 10]\n      .map((nice) => nice * scale)\n      .find((candidate) => target / candidate <= intervals) ?? 10 * scale\n  return Array.from({ length: Math.ceil(target / step) + 1 }, (_, index) =>\n    Number((index * step).toPrecision(12)),\n  )\n}\n\n/** Whether the tooltip is on this point: `true` or `false`, or `null` while it's on none. */\nfunction useChartHovered(point: unknown): boolean | null {\n  const points = useActiveTooltipDataPoints()\n  if (!points || points.length === 0) return null\n  return points.includes(point)\n}\n\ninterface ChartHoverBarLook {\n  className?: string\n  color?: string\n  fill: string\n  fillOpacity?: number\n}\n\ninterface ChartHoverBarProps extends Omit<BarShapeProps, 'radius'> {\n  /** The bar's look from whether the tooltip is on its point, `null` while it's on none. */\n  look: (hovered: boolean | null) => ChartHoverBarLook\n  radius?: number | [number, number, number, number]\n}\n\n/**\n * A `Bar` `shape` that recolours itself as the tooltip moves, so a hover never draws the chart\n * again and the tooltip glides. Keep hover state out of the block: a `Cell` per bar that reads it\n * draws every bar again on each move.\n */\nfunction ChartHoverBar({\n  height,\n  look,\n  payload,\n  radius = 0,\n  width,\n  x,\n  y,\n}: ChartHoverBarProps) {\n  const { className, color, fill, fillOpacity } = look(useChartHovered(payload))\n  return (\n    <Rectangle\n      className={className}\n      color={color}\n      fill={fill}\n      fillOpacity={fillOpacity}\n      height={height}\n      radius={radius}\n      width={width}\n      x={x}\n      y={y}\n    />\n  )\n}\n\ninterface ChartRisingBarProps {\n  height?: number\n  index?: number\n  width?: number\n  x?: number\n  y?: number\n}\n\n/**\n * A `Bar` `shape` that grows from its base once `revealed`, each bar `stagger` milliseconds after\n * the one before, so a row of days fills from left to right. Turn the `Bar`'s own animation off.\n */\nfunction chartRisingBar({\n  fill,\n  revealed,\n  stagger = 20,\n}: {\n  fill: (index: number) => string\n  revealed: boolean\n  stagger?: number\n}) {\n  return function RisingBar({\n    height = 0,\n    index = 0,\n    width = 0,\n    x = 0,\n    y = 0,\n  }: ChartRisingBarProps) {\n    return (\n      <rect\n        x={x}\n        y={y}\n        width={width}\n        height={height}\n        rx={2}\n        fill={fill(index)}\n        className='origin-bottom transition-transform duration-500 ease-[cubic-bezier(0.2,0,0,1)] [transform-box:fill-box] motion-reduce:transition-none'\n        style={{\n          transform: revealed ? undefined : 'scaleY(0)',\n          transitionDelay: `${index * stagger}ms`,\n        }}\n      />\n    )\n  }\n}\n\nfunction chartBarValueLabel(\n  highlightIndex: number | undefined,\n  formatter: ChartValueFormatter = formatNumber,\n) {\n  return function BarValueLabel({ index, value, width, x, y }: ChartBarLabelProps) {\n    if (index !== highlightIndex) return null\n    return (\n      <text\n        x={Number(x) + Number(width) / 2}\n        y={Number(y) - 6}\n        textAnchor='middle'\n        fontSize={11}\n        fontWeight={500}\n        fill='var(--color-foreground)'\n      >\n        {formatter(Number(value))}\n      </text>\n    )\n  }\n}\n\nfunction ChartTooltipFrame({ children }: { children: ReactNode }) {\n  return (\n    <div className='bg-popover text-popover-foreground grid min-w-32 items-start gap-1.5 rounded-md px-2.5 py-1.5 text-xs shadow-md ring-1 ring-foreground/10'>\n      {children}\n    </div>\n  )\n}\n\ninterface ChartTooltipItemProps {\n  /** Draws a swatch before the name; leave it out for a plain label and value. */\n  color?: string\n  name?: ReactNode\n  value: ReactNode\n}\n\nfunction ChartTooltipItem({ color, name, value }: ChartTooltipItemProps) {\n  return (\n    <div className='flex items-center gap-1.5'>\n      {color !== undefined && (\n        <div\n          className='size-2.5 shrink-0 rounded-[2px]'\n          style={{ backgroundColor: color }}\n        />\n      )}\n      {name !== undefined && <span className='text-muted-foreground'>{name}</span>}\n      <span className='ml-auto pl-3 font-medium tabular-nums'>{value}</span>\n    </div>\n  )\n}\n\n/** A line under a tooltip's values about the hovered point, such as the release that shipped that day. */\nfunction ChartTooltipNote({ children }: { children: ReactNode }) {\n  return <div className='border-t pt-1.5'>{children}</div>\n}\n\ntype ChartTooltipContentProps = Partial<\n  Pick<TooltipContentProps<ValueType, NameType>, 'active' | 'label' | 'payload'>\n> & {\n  formatLabel?: (label: string) => string\n  valueFormatter?: ChartValueFormatter\n}\n\nfunction ChartTooltipContent({\n  active,\n  formatLabel,\n  label,\n  payload,\n  valueFormatter = formatNumber,\n}: ChartTooltipContentProps) {\n  if (!active || !payload || payload.length === 0) return null\n\n  const heading = label !== undefined && label !== '' ? String(label) : undefined\n\n  return (\n    <ChartTooltipFrame>\n      {heading && (\n        <span className='font-medium'>\n          {formatLabel ? formatLabel(heading) : heading}\n        </span>\n      )}\n      {payload.map((item, index) => (\n        <ChartTooltipItem\n          key={`${String(item.dataKey ?? item.name)}-${index}`}\n          color={\n            (item.color as string | undefined) ??\n            (item.payload as { fill?: string } | undefined)?.fill ??\n            'var(--color-foreground)'\n          }\n          name={payload.length > 1 ? item.name : undefined}\n          value={valueFormatter(Number(item.value))}\n        />\n      ))}\n    </ChartTooltipFrame>\n  )\n}\n\nfunction pointLabel(payload: ChartTooltipContentProps['payload']) {\n  const label = (payload?.[0]?.payload as { label?: string | number } | undefined)?.label\n  return label === undefined ? undefined : String(label)\n}\n\ninterface ChartFloatingTooltipProps {\n  active: boolean\n  children: ReactNode\n  /** Opens to the left of the point instead of the right, such as past the middle of the chart. */\n  flip?: boolean\n  /** The hovered point, in px from the top left of the nearest positioned parent. */\n  x: number\n  y: number\n}\n\nconst TOOLTIP_OFFSET = 10\n\nfunction clamp(value: number, min: number, max: number) {\n  return Math.max(min, Math.min(value, max))\n}\n\n/** The box of the nearest ancestor that clips what overflows it, such as a Card. */\nfunction clippingBox(node: HTMLElement) {\n  for (let parent = node.parentElement; parent; parent = parent.parentElement) {\n    const { overflowX, overflowY } = getComputedStyle(parent)\n    if (overflowX !== 'visible' || overflowY !== 'visible') {\n      return parent.getBoundingClientRect()\n    }\n  }\n  return new DOMRect(0, 0, window.innerWidth, window.innerHeight)\n}\n\nfunction ChartFloatingTooltip({\n  active,\n  children,\n  flip,\n  x,\n  y,\n}: ChartFloatingTooltipProps) {\n  const ref = useRef<HTMLDivElement>(null)\n  const shown = useRef(false)\n\n  useLayoutEffect(() => {\n    const node = ref.current\n    const parent = node?.offsetParent\n    const appearing = active && !shown.current\n    shown.current = active\n    if (!node || !parent || !active) return\n    const origin = parent.getBoundingClientRect()\n    const bounds = clippingBox(node)\n    const width = node.offsetWidth\n    const height = node.offsetHeight\n    const right = origin.left + x + TOOLTIP_OFFSET\n    const left = origin.left + x - TOOLTIP_OFFSET - width\n    const fitsRight = right + width <= bounds.right\n    const fitsLeft = left >= bounds.left\n    const across = flip\n      ? fitsLeft || !fitsRight\n        ? left\n        : right\n      : fitsRight || !fitsLeft\n        ? right\n        : left\n    const below = origin.top + y + TOOLTIP_OFFSET\n    const down =\n      below + height <= bounds.bottom ? below : origin.top + y - TOOLTIP_OFFSET - height\n    const toX = clamp(across, bounds.left, bounds.right - width) - origin.left\n    const toY = clamp(down, bounds.top, bounds.bottom - height) - origin.top\n    node.style.transform = `translate(${toX}px, ${toY}px)`\n    if (appearing) {\n      node.style.transition = 'none'\n      node.getBoundingClientRect()\n      node.style.transition = ''\n    }\n  })\n\n  return (\n    <div\n      ref={ref}\n      aria-hidden\n      className='pointer-events-none absolute top-0 left-0 z-10 transition-transform duration-400 ease-out motion-reduce:transition-none'\n      style={{ visibility: active ? 'visible' : 'hidden' }}\n    >\n      <ChartTooltipFrame>{children}</ChartTooltipFrame>\n    </div>\n  )\n}\n\ninterface ChartPlaceholderProps {\n  className?: string\n  height?: number | string\n}\n\nfunction ChartPlaceholder({ className, height = 180 }: ChartPlaceholderProps) {\n  const state = useBlockState()\n\n  return (\n    <div\n      aria-hidden\n      data-slot='chart-placeholder'\n      className={cn(\n        'w-full',\n        state === 'loading'\n          ? 'bg-muted animate-pulse rounded-md motion-reduce:animate-none'\n          : 'border-b border-dashed',\n        className,\n      )}\n      style={{ height }}\n    />\n  )\n}\n\ninterface TinyBarChartProps {\n  /** Turn off inside a `role='img'` wrapper, such as `KPIChart`: its children are hidden from assistive tech, so the chart's keyboard layer would be a tab stop that a screen reader announces as nothing. */\n  accessibilityLayer?: boolean\n  bars: BarProps[]\n  className?: string\n  /** Names the chart for keyboard and screen reader users while its keyboard layer is on. */\n  label?: string\n  data: unknown[]\n  /** Draws the bars before this index faded, such as last month's days before this month's. */\n  fadedBefore?: number\n  formatter?: ChartValueFormatter\n  height?: number | string\n  /** Draws this bar in full colour and the others faded, with its value above it. */\n  highlightIndex?: number\n  /** Writes the highlighted bar's value above it. @default true */\n  highlightLabel?: boolean\n  /** A dashed line across the bars, such as an average or a target. */\n  reference?: { label: string; value: number }\n  /** Shows the first letter of this key under each bar. */\n  xAxisKey?: string\n}\n\nfunction TinyBarChart({\n  accessibilityLayer = true,\n  bars,\n  className,\n  label,\n  data,\n  fadedBefore,\n  formatter,\n  height = 180,\n  highlightIndex,\n  highlightLabel = true,\n  reference,\n  xAxisKey,\n}: TinyBarChartProps) {\n  const state = useBlockState()\n  if (state) return <ChartPlaceholder className={className} height={height} />\n\n  const safeData = Array.isArray(data) ? data : []\n  const resolvedBars = Array.isArray(bars) && bars.length > 0 ? bars : []\n  const highlighted = highlightIndex !== undefined && highlightIndex >= 0\n  const labelled = highlighted && highlightLabel\n\n  return (\n    <div className={cn('w-full', className)} style={{ height }}>\n      <ResponsiveContainer width='100%' height='100%'>\n        <BarChart\n          accessibilityLayer={accessibilityLayer}\n          aria-label={label}\n          data={safeData}\n          margin={\n            labelled\n              ? { top: 18, right: 0, bottom: 0, left: 0 }\n              : highlighted\n                ? { top: 0, right: 0, bottom: 0, left: 0 }\n                : undefined\n          }\n        >\n          {xAxisKey && (\n            <XAxis\n              {...chartAxisProps}\n              dataKey={xAxisKey}\n              interval={0}\n              tickFormatter={(value: string) => String(value).charAt(0)}\n            />\n          )}\n          {reference && (\n            <ReferenceLine\n              {...chartReferenceProps}\n              y={reference.value}\n              label={{\n                ...chartReferenceLabel,\n                value: reference.label,\n                position: 'insideBottomLeft',\n                dy: -4,\n              }}\n            />\n          )}\n          <Tooltip\n            content={({ active, payload }) => (\n              <ChartTooltipContent\n                active={active}\n                label={pointLabel(payload)}\n                payload={payload}\n                valueFormatter={formatter}\n              />\n            )}\n            cursor={chartBarCursor}\n          />\n          {resolvedBars.map((barProps, index) => {\n            const dataKey =\n              typeof barProps.dataKey === 'string' || typeof barProps.dataKey === 'number'\n                ? barProps.dataKey\n                : index\n            const color =\n              typeof barProps.fill === 'object' ? barProps.fill.color : barProps.fill\n\n            return (\n              <Bar\n                key={String(dataKey)}\n                radius={barProps.radius ?? [4, 4, 0, 0]}\n                {...barProps}\n              >\n                {(highlighted || fadedBefore !== undefined) &&\n                  index === 0 &&\n                  safeData.map((_, cell) => (\n                    <Cell\n                      key={cell}\n                      fill={\n                        (highlighted ? cell === highlightIndex : true) &&\n                        cell >= (fadedBefore ?? 0)\n                          ? color\n                          : color && chartFadedColor(color)\n                      }\n                    />\n                  ))}\n                {labelled && index === 0 && (\n                  <LabelList\n                    dataKey={dataKey}\n                    content={chartBarValueLabel(highlightIndex, formatter)}\n                  />\n                )}\n              </Bar>\n            )\n          })}\n        </BarChart>\n      </ResponsiveContainer>\n    </div>\n  )\n}\n\ninterface TinyLineChartProps {\n  /** Turn off inside a `role='img'` wrapper, such as `KPIChart`: its children are hidden from assistive tech, so the chart's keyboard layer would be a tab stop that a screen reader announces as nothing. */\n  accessibilityLayer?: boolean\n  className?: string\n  /** Names the chart for keyboard and screen reader users while its keyboard layer is on. */\n  label?: string\n  data: unknown[]\n  formatter?: ChartValueFormatter\n  height?: number | string\n  lines: LineProps[]\n  /** A dashed line across the chart, such as a limit or a target. The chart's scale stretches to show it. */\n  reference?: { label: string; value: number }\n}\n\nfunction TinyLineChart({\n  accessibilityLayer = true,\n  className,\n  label,\n  data,\n  formatter,\n  height = 180,\n  lines,\n  reference,\n}: TinyLineChartProps) {\n  const state = useBlockState()\n  if (state) return <ChartPlaceholder className={className} height={height} />\n\n  const safeData = Array.isArray(data) ? data : []\n  const resolvedLines = Array.isArray(lines) && lines.length > 0 ? lines : []\n\n  return (\n    <div className={cn('w-full', className)} style={{ height }}>\n      <ResponsiveContainer width='100%' height='100%'>\n        <LineChart\n          accessibilityLayer={accessibilityLayer}\n          aria-label={label}\n          data={safeData}\n        >\n          {reference && (\n            <ReferenceLine\n              {...chartReferenceProps}\n              ifOverflow='extendDomain'\n              y={reference.value}\n              label={{\n                ...chartReferenceLabel,\n                value: reference.label,\n                position: 'insideBottomLeft',\n                dy: -4,\n              }}\n            />\n          )}\n          <Tooltip\n            content={({ active, payload }) => (\n              <ChartTooltipContent\n                active={active}\n                label={pointLabel(payload)}\n                payload={payload}\n                valueFormatter={formatter}\n              />\n            )}\n            cursor={chartLineCursor}\n          />\n          {resolvedLines.map((lineProps, index) => {\n            const dataKey =\n              typeof lineProps.dataKey === 'string' ||\n              typeof lineProps.dataKey === 'number'\n                ? lineProps.dataKey\n                : index\n\n            return (\n              <Line\n                key={String(dataKey)}\n                type={lineProps.type ?? 'monotone'}\n                strokeWidth={lineProps.strokeWidth ?? 2}\n                dot={lineProps.dot ?? { r: 4 }}\n                {...lineProps}\n              />\n            )\n          })}\n        </LineChart>\n      </ResponsiveContainer>\n    </div>\n  )\n}\n\ninterface TinyAreaChartProps {\n  /** Turn off inside a `role='img'` wrapper, such as `KPIChart`: its children are hidden from assistive tech, so the chart's keyboard layer would be a tab stop that a screen reader announces as nothing. */\n  accessibilityLayer?: boolean\n  /** An area's `fill` fades from its `fillOpacity` at the top to nothing at the bottom. Set `fill='none'` for a line. */\n  areas: AreaProps[]\n  className?: string\n  /** Names the chart for keyboard and screen reader users while its keyboard layer is on. */\n  label?: string\n  data: unknown[]\n  formatter?: ChartValueFormatter\n  height?: number | string\n  /** Marks the last point of the area with this `dataKey`. */\n  markLast?: string\n  /** `data` starts the scale near the lowest value, so small changes show. @default 'zero' */\n  scale?: 'zero' | 'data'\n  /** Shows the first letter of this key under each point. */\n  xAxisKey?: string\n}\n\nfunction TinyAreaChart({\n  accessibilityLayer = true,\n  areas,\n  className,\n  label,\n  data,\n  formatter,\n  height = 180,\n  markLast,\n  scale = 'zero',\n  xAxisKey,\n}: TinyAreaChartProps) {\n  const id = useChartId()\n  const state = useBlockState()\n  const safeData = Array.isArray(data) ? data : []\n  const resolvedAreas = Array.isArray(areas) && areas.length > 0 ? areas : []\n\n  if (state) return <ChartPlaceholder className={className} height={height} />\n\n  return (\n    <div className={cn('w-full', className)} style={{ height }}>\n      <ResponsiveContainer width='100%' height='100%'>\n        <AreaChart\n          accessibilityLayer={accessibilityLayer}\n          aria-label={label}\n          data={safeData}\n          margin={{ top: 6, right: 6, bottom: 0, left: 6 }}\n        >\n          <defs>\n            {resolvedAreas.map((areaProps, index) =>\n              typeof areaProps.fill === 'string' && areaProps.fill !== 'none' ? (\n                <linearGradient\n                  key={index}\n                  id={`${id}-${index}`}\n                  x1='0'\n                  y1='0'\n                  x2='0'\n                  y2='1'\n                >\n                  <stop\n                    offset='0%'\n                    stopColor={areaProps.fill}\n                    stopOpacity={Number(areaProps.fillOpacity ?? 0.3)}\n                  />\n                  <stop offset='100%' stopColor={areaProps.fill} stopOpacity={0} />\n                </linearGradient>\n              ) : null,\n            )}\n          </defs>\n          {xAxisKey && (\n            <XAxis\n              {...chartAxisProps}\n              dataKey={xAxisKey}\n              interval={0}\n              tickFormatter={(value: string) => String(value).charAt(0)}\n            />\n          )}\n          <YAxis\n            hide\n            domain={\n              scale === 'data'\n                ? [(min: number) => min - (Math.abs(min) || 1) * 0.15, 'dataMax']\n                : [0, 'auto']\n            }\n          />\n          <Tooltip\n            content={({ active, payload }) => (\n              <ChartTooltipContent\n                active={active}\n                label={pointLabel(payload)}\n                payload={payload}\n                valueFormatter={formatter}\n              />\n            )}\n            cursor={chartLineCursor}\n          />\n          {resolvedAreas.map((areaProps, index) => {\n            const dataKey =\n              typeof areaProps.dataKey === 'string' ||\n              typeof areaProps.dataKey === 'number'\n                ? areaProps.dataKey\n                : index\n            const gradient =\n              typeof areaProps.fill === 'string' && areaProps.fill !== 'none'\n            const stroke = String(areaProps.stroke ?? 'var(--color-chart-2)')\n\n            return (\n              <Area\n                key={String(dataKey)}\n                type={areaProps.type ?? 'monotone'}\n                strokeWidth={areaProps.strokeWidth ?? 2}\n                activeDot={chartActiveDot}\n                dot={markLast === dataKey ? chartLastDot(safeData.length, stroke) : false}\n                {...areaProps}\n                fill={gradient ? `url(#${id}-${index})` : 'none'}\n                fillOpacity={1}\n              />\n            )\n          })}\n        </AreaChart>\n      </ResponsiveContainer>\n    </div>\n  )\n}\n\ninterface ChartMarker {\n  /** The x axis value the marker stands on, such as the day in the axis's `dataKey`. */\n  x: string | number\n  label: string\n}\n\ntype ChartMarkerAnchor = 'start' | 'end'\n\nconst MARKER_CHAR_WIDTH = 6.6\nconst MARKER_GAP = 9\nconst MARKER_SPACE = 12\n\n/**\n * Where each marker's name goes: left of its line (`end`), or right of it (`start`) when the left\n * side runs off the plot. `null` when two names can't both fit, so every marker is drawn as a\n * numbered pin instead. `xs` are the markers' positions in px, left to right.\n */\nfunction layoutChartMarkers(\n  xs: number[],\n  labels: string[],\n  plot: { left: number; right: number },\n): ChartMarkerAnchor[] | null {\n  const anchors: ChartMarkerAnchor[] = []\n  let taken = plot.left - MARKER_SPACE\n  for (const [index, x] of xs.entries()) {\n    const width = labels[index].length * MARKER_CHAR_WIDTH\n    const before = x - MARKER_GAP - width\n    if (before >= plot.left && before >= taken + MARKER_SPACE) {\n      anchors.push('end')\n      taken = x\n      continue\n    }\n    const after = x + MARKER_GAP + width\n    if (after > plot.right || x < taken + MARKER_SPACE) return null\n    anchors.push('start')\n    taken = after\n  }\n  return anchors\n}\n\ninterface ChartMarkersProps {\n  /** Milliseconds before the first marker drops in, such as the time the chart's line takes to draw. @default 0 */\n  delay?: number\n  markers: ChartMarker[]\n  /** Called with the markers in their pins' order when the names don't fit and they show as numbered pins, and with `null` when they show their names. Draw `ChartMarkerKey` from it under the chart. */\n  onPinsChange?: (pins: ChartMarker[] | null) => void\n}\n\n/**\n * Named dashed lines across a cartesian chart, such as releases: put it inside the chart, and leave\n * about 24px of top margin for the names. A marker's line turns the chart's colour while the\n * tooltip is on its point. Names that don't fit become numbered pins.\n */\nfunction ChartMarkers({ delay = 0, markers, onPinsChange }: ChartMarkersProps) {\n  const scale = useXAxisScale()\n  const plot = usePlotArea()\n  const activeLabel = useActiveTooltipLabel()\n\n  const placed =\n    scale && plot\n      ? markers\n          .map((marker) => ({ ...marker, at: scale(marker.x, { position: 'middle' }) }))\n          .filter(\n            (marker): marker is ChartMarker & { at: number } => marker.at !== undefined,\n          )\n          .sort((a, b) => a.at - b.at)\n      : []\n  const anchors = plot\n    ? layoutChartMarkers(\n        placed.map((marker) => marker.at),\n        placed.map((marker) => marker.label),\n        { left: plot.x, right: plot.x + plot.width },\n      )\n    : []\n  const pins =\n    anchors === null ? JSON.stringify(placed.map(({ label, x }) => ({ label, x }))) : null\n\n  useEffect(() => {\n    onPinsChange?.(pins === null ? null : (JSON.parse(pins) as ChartMarker[]))\n  }, [onPinsChange, pins])\n\n  if (!plot) return null\n  const top = plot.y\n\n  return (\n    <g aria-hidden data-slot='chart-markers'>\n      {placed.map((marker, index) => {\n        const active =\n          activeLabel !== undefined && String(activeLabel) === String(marker.x)\n        const color = active ? 'var(--color-chart-2)' : 'var(--color-foreground)'\n        const anchor = anchors?.[index]\n        return (\n          <g\n            key={`${marker.x}-${marker.label}`}\n            className='animate-in fade-in slide-in-from-top-2 fill-mode-both duration-500 ease-out motion-reduce:animate-none'\n            style={{ animationDelay: `${delay + index * 180}ms` }}\n          >\n            <line\n              x1={marker.at}\n              x2={marker.at}\n              y1={top}\n              y2={top + plot.height}\n              stroke={active ? 'var(--color-chart-2)' : chartReferenceColor}\n              strokeDasharray='3 3'\n              className='transition-[stroke] duration-200'\n            />\n            {anchor ? (\n              <>\n                <circle\n                  cx={marker.at}\n                  cy={top - 7}\n                  r={3}\n                  fill={color}\n                  className='transition-[fill] duration-200'\n                />\n                <text\n                  x={anchor === 'end' ? marker.at - MARKER_GAP : marker.at + MARKER_GAP}\n                  y={top - 3}\n                  textAnchor={anchor}\n                  fontSize={12}\n                  fontWeight={500}\n                  fill={color}\n                  className='transition-[fill] duration-200'\n                >\n                  {marker.label}\n                </text>\n              </>\n            ) : (\n              <>\n                <circle\n                  cx={marker.at}\n                  cy={top - 10}\n                  r={8}\n                  fill={color}\n                  className='transition-[fill] duration-200'\n                />\n                <text\n                  x={marker.at}\n                  y={top - 6}\n                  textAnchor='middle'\n                  fontSize={11}\n                  fontWeight={600}\n                  fill='var(--color-background)'\n                >\n                  {index + 1}\n                </text>\n              </>\n            )}\n          </g>\n        )\n      })}\n    </g>\n  )\n}\n\n/** The names of `ChartMarkers` shown as numbered pins, in the pins' order: put it under the chart. */\nfunction ChartMarkerKey({\n  className,\n  markers,\n}: {\n  className?: string\n  markers: ChartMarker[]\n}) {\n  return (\n    <ol\n      aria-hidden\n      data-slot='chart-marker-key'\n      className={cn('flex flex-wrap gap-x-4 gap-y-1.5 text-xs', className)}\n    >\n      {markers.map((marker, index) => (\n        <li\n          key={`${marker.x}-${marker.label}`}\n          className='flex min-w-0 items-center gap-1.5'\n        >\n          {/* Not a step: an annotation's key, matching its marker on the chart */}\n          <span className='bg-foreground text-background grid size-4 shrink-0 place-items-center rounded-full font-semibold tabular-nums'>\n            {index + 1}\n          </span>\n          <span className='truncate'>{marker.label}</span>\n        </li>\n      ))}\n    </ol>\n  )\n}\n\nexport {\n  ChartFloatingTooltip,\n  ChartHatch,\n  ChartHoverBar,\n  ChartMarkerKey,\n  ChartEdgeTick,\n  ChartMarkers,\n  ChartPlaceholder,\n  ChartTooltipContent,\n  ChartTooltipFrame,\n  ChartTooltipItem,\n  ChartTooltipNote,\n  TinyAreaChart,\n  TinyBarChart,\n  TinyLineChart,\n  chartActiveDot,\n  chartAxisProps,\n  chartBarCursor,\n  chartBarValueLabel,\n  chartFadedColor,\n  chartHatchFill,\n  chartGridProps,\n  chartLastDot,\n  chartLineCursor,\n  chartLiveDot,\n  chartNiceTicks,\n  chartReferenceColor,\n  chartReferenceLabel,\n  chartReferenceProps,\n  chartRisingBar,\n  chartTimeGridProps,\n  chartValueAxisWidth,\n  layoutChartMarkers,\n  useChartHovered,\n  useChartId,\n}\n\nexport type {\n  ChartEdgeTickProps,\n  ChartHoverBarLook,\n  ChartHoverBarProps,\n  ChartMarker,\n  ChartMarkerAnchor,\n  ChartMarkersProps,\n  ChartPlaceholderProps,\n  ChartFloatingTooltipProps,\n  ChartTooltipContentProps,\n  ChartTooltipItemProps,\n  ChartValueFormatter,\n  TinyAreaChartProps,\n  TinyBarChartProps,\n  TinyLineChartProps,\n}\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/chart.tsx"
    }
  ],
  "type": "registry:component"
}
