{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "timeline-03",
  "description": "Every release on one line, sized as major, minor or patch, with the median gap and when the next one is due.",
  "dependencies": [
    "recharts"
  ],
  "registryDependencies": [
    "card",
    "https://www.dashboardblocks.com/r/radix/block-state.json",
    "https://www.dashboardblocks.com/r/radix/chart.json",
    "https://www.dashboardblocks.com/r/radix/details.json",
    "https://www.dashboardblocks.com/r/radix/kpi.json",
    "https://www.dashboardblocks.com/r/radix/timeline.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/timeline/timeline-03.tsx",
      "content": "'use client'\n\nimport {\n  BlockReady,\n  BlockStateProvider,\n  type BlockStateProps,\n  SkeletonText,\n  getBlockState,\n} from '@/registry/components/dashboardblocks/block-state'\nimport {\n  ChartPlaceholder,\n  ChartTooltipFrame,\n  chartTimeGridProps,\n} from '@/registry/components/dashboardblocks/chart'\nimport { Details } from '@/registry/components/dashboardblocks/details'\nimport { KPIValue } from '@/registry/components/dashboardblocks/kpi'\nimport {\n  TIMELINE_AXIS_HEIGHT,\n  TIMELINE_NOW_Z_INDEX,\n  TimelineAxisTick,\n  TimelineNowLabel,\n  formatTimelineDate,\n  getDaysBetween,\n  getTimelineTicks,\n} from '@/registry/components/dashboardblocks/timeline'\nimport {\n  CartesianGrid,\n  ReferenceLine,\n  ResponsiveContainer,\n  Scatter,\n  ScatterChart,\n  Tooltip,\n  XAxis,\n  YAxis,\n} from 'recharts'\n\nimport { Card, CardContent } from '@/components/ui/card'\n\nimport { cn } from '@/lib/utils'\n\ntype ReleaseKind = 'major' | 'minor' | 'patch'\n\ninterface Release {\n  date: Date\n  kind: ReleaseKind\n  version: string\n  summary?: string\n}\n\ninterface Timeline3Props extends BlockStateProps {\n  /** Defaults to a sentence about the median gap and when the next release is due. */\n  description?: string\n  end: Date\n  /** Pass a fixed date, so the block renders the same on the server and in the browser. */\n  now: Date\n  /** Oldest first. Leave out, or pass none, to show the empty state. */\n  releases?: Release[]\n  start: Date\n  title: string\n}\n\nconst date = (month: number, day: number) => new Date(Date.UTC(2026, month - 1, day))\n\nconst exampleProps: Timeline3Props = {\n  end: date(10, 31),\n  now: date(9, 26),\n  releases: [\n    {\n      date: date(4, 8),\n      kind: 'minor',\n      summary: 'Saved views',\n      version: 'v2.4.0',\n    },\n    { date: date(4, 16), kind: 'patch', version: 'v2.4.1' },\n    { date: date(4, 29), kind: 'patch', version: 'v2.4.2' },\n    {\n      date: date(5, 20),\n      kind: 'minor',\n      summary: 'Scheduled reports',\n      version: 'v2.5.0',\n    },\n    { date: date(6, 3), kind: 'patch', version: 'v2.5.1' },\n    {\n      date: date(6, 24),\n      kind: 'minor',\n      summary: 'Webhooks',\n      version: 'v2.6.0',\n    },\n    { date: date(7, 1), kind: 'patch', version: 'v2.6.1' },\n    { date: date(7, 9), kind: 'patch', version: 'v2.6.2' },\n    {\n      date: date(8, 5),\n      kind: 'major',\n      summary: 'New editor and API v3',\n      version: 'v3.0.0',\n    },\n    { date: date(8, 12), kind: 'patch', version: 'v3.0.1' },\n    { date: date(8, 19), kind: 'patch', version: 'v3.0.2' },\n    {\n      date: date(9, 9),\n      kind: 'minor',\n      summary: 'Team spaces',\n      version: 'v3.1.0',\n    },\n    { date: date(9, 22), kind: 'patch', version: 'v3.1.1' },\n  ],\n  start: date(3, 25),\n  title: 'Release cadence',\n}\n\nconst KINDS: { kind: ReleaseKind; label: string }[] = [\n  { kind: 'major', label: 'Major' },\n  { kind: 'minor', label: 'Minor' },\n  { kind: 'patch', label: 'Patch' },\n]\nconst markerClass: Record<ReleaseKind, string> = {\n  major: 'size-4 bg-foreground ring-2 ring-background',\n  minor: 'size-3 bg-chart-2 ring-2 ring-background',\n  patch: 'size-2 border-[1.5px] border-muted-foreground bg-background',\n}\n\nconst DAY = 86_400_000\nconst PLOT_HEIGHT = 60\nconst BASELINE = 0.5\nconst MARKER_RADIUS: Record<ReleaseKind, number> = {\n  major: 8,\n  minor: 6,\n  patch: 4,\n}\n\ninterface Point {\n  release?: Release\n  x: number\n  y: number\n}\n\ninterface MarkerProps {\n  active?: boolean\n  cx?: number\n  cy?: number\n  payload?: Point\n}\n\nfunction ActiveRing({ cx, cy, r }: { cx: number; cy: number; r: number }) {\n  return (\n    <circle\n      cx={cx}\n      cy={cy}\n      fill='none'\n      r={r + 3}\n      stroke='var(--color-foreground)'\n      strokeWidth={2}\n    />\n  )\n}\n\nconst Timeline3 = (props: Timeline3Props) => {\n  const { end, now, releases = [], start, errorMessage, status, title } = props\n  const state = getBlockState(status, releases)\n  const ticks = getTimelineTicks(start, end, 'month')\n  const gaps = releases\n    .slice(1)\n    .map((release, index) => getDaysBetween(releases[index].date, release.date))\n  const sortedGaps = [...gaps].sort((a, b) => a - b)\n  const median = sortedGaps.length\n    ? sortedGaps[Math.floor((sortedGaps.length - 1) / 2)]\n    : 0\n  const last = releases[releases.length - 1]\n  const sinceLast = last ? getDaysBetween(last.date, now) : 0\n  const nextDue = last && median > 0 ? new Date(last.date.getTime() + median * DAY) : null\n  const dueIn = nextDue ? getDaysBetween(now, nextDue) : 0\n  const {\n    description = releases.length < 2\n      ? 'Too few releases yet for a typical gap.'\n      : `A release every ${median} days, so the next one is ${dueIn < 0 ? `${-dueIn} ${dueIn === -1 ? 'day' : 'days'} overdue` : `due ${nextDue ? formatTimelineDate(nextDue) : ''}`}.`,\n  } = props\n  const describe = (release: Release) =>\n    `${release.version}, ${formatTimelineDate(release.date)}, ${release.kind}${release.summary ? `: ${release.summary}` : ''}`\n\n  const points: Point[] = [\n    ...releases.map((release) => ({\n      release,\n      x: release.date.getTime(),\n      y: BASELINE,\n    })),\n    ...(nextDue && nextDue <= end ? [{ x: nextDue.getTime(), y: BASELINE }] : []),\n  ]\n  const nextDueNearEnd =\n    nextDue !== null &&\n    (nextDue.getTime() - start.getTime()) / (end.getTime() - start.getTime()) > 0.92\n\n  const marker = ({ active = false, cx = 0, cy = 0, payload }: MarkerProps) => {\n    if (!payload?.release)\n      return (\n        <g>\n          <circle\n            cx={cx}\n            cy={cy}\n            fill='var(--color-background)'\n            r={6}\n            stroke='var(--color-muted-foreground)'\n            strokeDasharray='2 2'\n            strokeWidth={1.5}\n          />\n          <text\n            fill='var(--color-muted-foreground)'\n            fontSize={11}\n            textAnchor={nextDueNearEnd ? 'end' : 'middle'}\n            x={nextDueNearEnd ? cx + 6 : cx}\n            y={cy + 20}\n          >\n            Next due\n          </text>\n          {active && <ActiveRing cx={cx} cy={cy} r={6} />}\n        </g>\n      )\n    const { kind, version } = payload.release\n    const r = MARKER_RADIUS[kind]\n    return (\n      <g>\n        <circle\n          cx={cx}\n          cy={cy}\n          fill={\n            kind === 'major'\n              ? 'var(--color-foreground)'\n              : kind === 'minor'\n                ? 'var(--color-chart-2)'\n                : 'var(--color-background)'\n          }\n          r={r}\n          stroke={\n            kind === 'patch' ? 'var(--color-muted-foreground)' : 'var(--color-background)'\n          }\n          strokeWidth={kind === 'patch' ? 1.5 : 2}\n        />\n        {kind === 'major' && (\n          <text\n            fill='var(--color-foreground)'\n            fontSize={11}\n            fontWeight={500}\n            textAnchor='middle'\n            x={cx}\n            y={cy - r - 4}\n          >\n            {version}\n          </text>\n        )}\n        {active && <ActiveRing cx={cx} cy={cy} r={r} />}\n      </g>\n    )\n  }\n\n  return (\n    <BlockStateProvider errorMessage={errorMessage} state={state}>\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              <BlockReady className='text-sm'>\n                <p className='text-muted-foreground text-sm'>{description}</p>\n              </BlockReady>\n            </header>\n            {(state === 'error' || state === 'empty') && (\n              <div className='border-t pt-4'>\n                <KPIValue className='text-2xl' />\n              </div>\n            )}\n            {state !== 'error' && state !== 'empty' && (\n              <dl className='grid grid-cols-3 gap-4 border-t pt-4'>\n                <div className='flex flex-col gap-0.5'>\n                  <dt className='text-muted-foreground text-sm'>Releases</dt>\n                  <dd className='text-2xl font-light tracking-tight tabular-nums'>\n                    {state === 'loading' ? (\n                      <SkeletonText className='w-[2em]' />\n                    ) : (\n                      releases.length\n                    )}\n                  </dd>\n                </div>\n                <div className='flex flex-col gap-0.5'>\n                  <dt className='text-muted-foreground text-sm'>Median gap</dt>\n                  <dd className='text-2xl font-light tracking-tight tabular-nums'>\n                    {state === 'loading' ? (\n                      <SkeletonText className='w-[3em]' />\n                    ) : (\n                      <>\n                        {median}\n                        <span className='text-muted-foreground ml-1 text-base font-normal tracking-normal'>\n                          days\n                        </span>\n                      </>\n                    )}\n                  </dd>\n                </div>\n                <div className='flex flex-col gap-0.5'>\n                  <dt className='text-muted-foreground text-sm'>Since last</dt>\n                  <dd className='text-2xl font-light tracking-tight tabular-nums'>\n                    {state === 'loading' ? (\n                      <SkeletonText className='w-[3em]' />\n                    ) : (\n                      <>\n                        {sinceLast}\n                        <span className='text-muted-foreground ml-1 text-base font-normal tracking-normal'>\n                          days\n                        </span>\n                      </>\n                    )}\n                  </dd>\n                </div>\n              </dl>\n            )}\n            {state && <ChartPlaceholder height={TIMELINE_AXIS_HEIGHT + PLOT_HEIGHT} />}\n            {!state && (\n              <div aria-hidden style={{ height: TIMELINE_AXIS_HEIGHT + PLOT_HEIGHT }}>\n                <ResponsiveContainer height='100%' width='100%'>\n                  <ScatterChart\n                    accessibilityLayer={false}\n                    margin={{ bottom: 0, left: 8, right: 8, top: 0 }}\n                  >\n                    <CartesianGrid {...chartTimeGridProps} />\n                    <XAxis\n                      allowDataOverflow\n                      axisLine={false}\n                      dataKey='x'\n                      domain={[start.getTime(), end.getTime()]}\n                      height={TIMELINE_AXIS_HEIGHT}\n                      interval={0}\n                      orientation='top'\n                      tick={<TimelineAxisTick />}\n                      tickLine={false}\n                      ticks={ticks.map((tick) => tick.getTime())}\n                      type='number'\n                    />\n                    <YAxis dataKey='y' domain={[0, 1]} hide type='number' />\n                    <ReferenceLine stroke='var(--color-border)' y={BASELINE} />\n                    {last && nextDue && nextDue <= end && (\n                      <ReferenceLine\n                        segment={[\n                          { x: last.date.getTime(), y: BASELINE },\n                          { x: nextDue.getTime(), y: BASELINE },\n                        ]}\n                        stroke='var(--color-muted-foreground)'\n                        strokeDasharray='3 3'\n                      />\n                    )}\n                    {now >= start && now <= end && (\n                      <ReferenceLine\n                        label={<TimelineNowLabel label='Now' />}\n                        stroke='var(--color-foreground)'\n                        x={now.getTime()}\n                        zIndex={TIMELINE_NOW_Z_INDEX}\n                      />\n                    )}\n                    <Tooltip\n                      content={({ active, payload }) => {\n                        const point = payload?.[0]?.payload as Point | undefined\n                        if (!active || !point) return null\n                        if (!point.release)\n                          return (\n                            <ChartTooltipFrame>\n                              <span className='font-medium'>Next due</span>\n                              <span className='text-muted-foreground tabular-nums'>\n                                {formatTimelineDate(new Date(point.x))}, if the {median}\n                                -day gap holds\n                              </span>\n                            </ChartTooltipFrame>\n                          )\n                        const { release } = point\n                        return (\n                          <ChartTooltipFrame>\n                            <span className='font-medium tabular-nums'>\n                              {release.version}\n                            </span>\n                            <Details className='text-muted-foreground'>\n                              {formatTimelineDate(release.date)}\n                              {KINDS.find((entry) => entry.kind === release.kind)?.label}\n                            </Details>\n                            {release.summary && <span>{release.summary}</span>}\n                          </ChartTooltipFrame>\n                        )\n                      }}\n                      cursor={false}\n                    />\n                    <Scatter\n                      activeShape={(props: MarkerProps) =>\n                        marker({ ...props, active: true })\n                      }\n                      data={points}\n                      isAnimationActive={false}\n                      shape={(props: MarkerProps) => marker(props)}\n                    />\n                  </ScatterChart>\n                </ResponsiveContainer>\n              </div>\n            )}\n            {state !== 'error' && state !== 'empty' && (\n              <ul\n                aria-hidden\n                className='text-muted-foreground flex flex-wrap items-center gap-x-3 gap-y-1 text-xs'\n              >\n                {KINDS.map((entry) => (\n                  <li key={entry.kind} className='flex items-center gap-1.5'>\n                    <span\n                      className={cn(\n                        'block rounded-full',\n                        markerClass[entry.kind],\n                        'ring-0',\n                      )}\n                    />\n                    {entry.label}\n                  </li>\n                ))}\n              </ul>\n            )}\n            {!state && (\n              <ul className='sr-only'>\n                {releases.map((release) => (\n                  <li key={release.version}>{describe(release)}</li>\n                ))}\n              </ul>\n            )}\n          </section>\n        </CardContent>\n      </Card>\n    </BlockStateProvider>\n  )\n}\n\nexport {\n  Timeline3,\n  exampleProps as timeline3ExampleProps,\n  type Release,\n  type Timeline3Props,\n}\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/timeline/timeline-03.tsx"
    }
  ],
  "meta": {
    "shows": "Every release on one line, sized as major, minor or patch, with the median gap and when the next one is due.",
    "size": "full",
    "usedWith": [
      "deployments-01",
      "deployments-03"
    ],
    "component": "Timeline3",
    "props": "{ description?: string; end: Date; now: Date; releases?: { date: Date; kind: \"major\" | \"minor\" | \"patch\"; version: string; summary?: string }[]; start: Date; title: string; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
