{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "off-the-charts",
  "title": "Off The Charts",
  "description": "Quarterly bars climb until the last one breaks its axis and overshoots the target at 260%.",
  "dependencies": ["remotion", "@remotion/google-fonts"],
  "files": [
    {
      "path": "registry/remocn/off-the-charts/index.tsx",
      "content": "\"use client\";\n\nimport { loadFont } from \"@remotion/google-fonts/BricolageGrotesque\";\nimport { useId } from \"react\";\nimport {\n  AbsoluteFill,\n  Easing,\n  interpolate,\n  spring,\n  useCurrentFrame,\n  useVideoConfig,\n} from \"remotion\";\n\nconst { fontFamily: sans } = loadFont(\"normal\", {\n  weights: [\"400\", \"500\"],\n  subsets: [\"latin\"],\n});\n\nexport interface OffTheChartsDatum {\n  label: string;\n  value: number;\n}\n\nexport interface OffTheChartsProps {\n  data?: OffTheChartsDatum[];\n  accentIndex?: number;\n  target?: number;\n  max?: number;\n  unit?: string;\n  targetLabel?: string;\n  value?: string;\n  caption?: string;\n  accent?: string;\n  speed?: number;\n  theme?: \"dark\" | \"light\";\n}\n\nconst DEFAULT_DATA: OffTheChartsDatum[] = [\n  { label: \"Q1\", value: 58 },\n  { label: \"Q2\", value: 74 },\n  { label: \"Q3\", value: 86 },\n  { label: \"Q4\", value: 260 },\n];\n\nconst EASE_IO = Easing.bezier(0.65, 0, 0.35, 1);\nconst EASE_OUT = Easing.bezier(0.22, 1, 0.36, 1);\nconst PUSH = Easing.bezier(0.45, 0, 0.3, 1);\nconst CLAMP = {\n  extrapolateLeft: \"clamp\",\n  extrapolateRight: \"clamp\",\n} as const;\n\nconst THEMES = {\n  dark: {\n    bg: \"#0A0A0B\",\n    fg: \"#F3F2EF\",\n    muted: \"#8B8A90\",\n    bar: \"#46464D\",\n    frame: \"rgba(243,242,239,0.42)\",\n    grid: \"rgba(243,242,239,0.1)\",\n    target: \"rgba(243,242,239,0.7)\",\n    heatTop: \"#ffe2c4\",\n    grain: 0.06,\n  },\n  light: {\n    bg: \"#F5F4F0\",\n    fg: \"#121214\",\n    muted: \"#6E6C67\",\n    bar: \"#CFCDC6\",\n    frame: \"rgba(18,18,20,0.42)\",\n    grid: \"rgba(18,18,20,0.1)\",\n    target: \"rgba(18,18,20,0.72)\",\n    heatTop: \"#ffbf8f\",\n    grain: 0.045,\n  },\n} as const;\n\nconst RISE = 40;\nconst PRESS = 66;\nconst BREAK = 69;\n\nfunction Grain({ opacity }: { opacity: number }) {\n  const id = `g${useId().replace(/[^a-zA-Z0-9_-]/g, \"\")}`;\n  return (\n    <svg\n      width=\"100%\"\n      height=\"100%\"\n      style={{ position: \"absolute\", inset: 0, opacity }}\n      aria-hidden\n    >\n      <filter id={id}>\n        <feTurbulence\n          type=\"fractalNoise\"\n          baseFrequency=\"0.9\"\n          numOctaves={2}\n          seed={29}\n          stitchTiles=\"stitch\"\n        />\n        <feColorMatrix values=\"0 0 0 0 0.5  0 0 0 0 0.5  0 0 0 0 0.5  0 0 0 0.9 0\" />\n      </filter>\n      <rect width=\"100%\" height=\"100%\" filter={`url(#${id})`} />\n    </svg>\n  );\n}\n\nconst lerp = (a: number, b: number, k: number) => a + (b - a) * k;\n\nfunction barPath(x: number, bottom: number, w: number, h: number, r0: number) {\n  const r = Math.max(0, Math.min(r0, h / 2, w / 2));\n  const top = bottom - h;\n  return `M${x} ${bottom} L${x} ${top + r} Q${x} ${top} ${x + r} ${top} L${x + w - r} ${top} Q${x + w} ${top} ${x + w} ${top + r} L${x + w} ${bottom} Z`;\n}\n\nexport function OffTheCharts({\n  data = DEFAULT_DATA,\n  accentIndex,\n  target = 100,\n  max = 150,\n  unit = \"%\",\n  targetLabel = \"Target\",\n  value,\n  caption = \"of the Q4 target\",\n  accent = \"#3B5BFD\",\n  speed = 1,\n  theme = \"dark\",\n}: OffTheChartsProps) {\n  const t = useCurrentFrame() * speed;\n  const { width, height, fps } = useVideoConfig();\n  const u = height / 720;\n  const p = THEMES[theme];\n  const heatId = `heat${useId().replace(/[^a-zA-Z0-9_-]/g, \"\")}`;\n\n  const rows = data.length > 0 ? data : DEFAULT_DATA;\n  const n = rows.length;\n  const ai =\n    accentIndex !== undefined && accentIndex >= 0 && accentIndex < n\n      ? accentIndex\n      : n - 1;\n  const peak = Math.max(rows[ai].value, max * 1.02);\n  const heroText = value ?? `${rows[ai].value}${unit}`;\n\n  const boxL = width * 0.15;\n  const boxR = width * 0.62;\n  const bottom = height * 0.84;\n  const ceiling = height * 0.13;\n  const px = (bottom - ceiling) / peak;\n  const boxT = bottom - max * px;\n  const slot = (boxR - boxL) / (n + 0.6);\n  const bw = Math.min(slot * 0.6, 96 * u);\n  const barX = (i: number) => boxL + slot * (i + 0.8) - bw / 2;\n  const aX = barX(ai);\n  const sw = Math.max(1, 1.25 * u);\n\n  const frameIn = interpolate(t, [0, 14], [0, 1], {\n    ...CLAMP,\n    easing: EASE_IO,\n  });\n  const gridIn = interpolate(t, [6, 20], [0, 1], CLAMP);\n  const targetDraw = interpolate(t, [10, 30], [0, 1], {\n    ...CLAMP,\n    easing: EASE_IO,\n  });\n  const targetLab = interpolate(t, [24, 36], [0, 1], {\n    ...CLAMP,\n    easing: EASE_OUT,\n  });\n\n  const rest = rows.map((d, i) => {\n    if (i === ai) return 0;\n    const order = i < ai ? i : i - 1;\n    return (\n      d.value *\n      interpolate(t, [18 + order * 4, 40 + order * 4], [0, 1], {\n        ...CLAMP,\n        easing: EASE_OUT,\n      })\n    );\n  });\n\n  const accentV = rows[ai].value;\n  const breaks = accentV > max;\n  const pressTo = breaks ? max : accentV;\n  const phaseA = interpolate(t, [RISE, PRESS], [0, pressTo], {\n    ...CLAMP,\n    easing: PUSH,\n  });\n  const tension = breaks\n    ? interpolate(t, [PRESS, BREAK], [0, 7 * u], {\n        ...CLAMP,\n        easing: Easing.bezier(0.55, 0, 1, 0.45),\n      })\n    : 0;\n  const release = spring({\n    frame: t - BREAK,\n    fps,\n    config: { damping: 15, stiffness: 120, mass: 0.8 },\n  });\n  const broken = breaks && t >= BREAK;\n  const aH = broken\n    ? lerp(max * px + 7 * u, accentV * px, release)\n    : phaseA * px + tension;\n  const aVal = aH / px;\n  const aTop = bottom - aH;\n\n  const snap = breaks\n    ? spring({\n        frame: t - BREAK,\n        fps,\n        config: { damping: 11, stiffness: 260, mass: 0.5 },\n      })\n    : 0;\n  const pad = 12 * u;\n  const half = bw / 2 + pad * snap;\n  const cx = aX + bw / 2;\n\n  const slashIn = broken\n    ? interpolate(snap, [0, 0.7], [0.4, 1], { ...CLAMP, easing: EASE_OUT })\n    : 0;\n  const slashLen = 16 * u;\n  const slashDx = slashLen * 0.36;\n\n  const hitAt = BREAK + 14;\n  const hero = spring({\n    frame: t - hitAt,\n    fps,\n    config: { damping: 16, stiffness: 150, mass: 0.7 },\n  });\n  const heroO = interpolate(t, [hitAt, hitAt + 7], [0, 1], CLAMP);\n  const cap = interpolate(t, [hitAt + 8, hitAt + 24], [0, 1], {\n    ...CLAMP,\n    easing: EASE_OUT,\n  });\n  const counterO =\n    interpolate(t, [RISE + 4, RISE + 10], [0, 1], CLAMP) *\n    interpolate(t, [hitAt - 4, hitAt + 2], [1, 0], CLAMP);\n\n  const ty = bottom - target * px;\n  const boxStop = Math.min(0.9, max / Math.max(accentV, max));\n  const gridVals = [0, max / 3, (2 * max) / 3, max];\n  const fmt = (v: number) => `${Math.round(v)}${v === 0 ? \"\" : unit}`;\n\n  const leftW = lerp(0, boxR - boxL, frameIn);\n  const upH = lerp(0, bottom - boxT, frameIn);\n  const topDraw = interpolate(t, [8, 22], [0, 1], {\n    ...CLAMP,\n    easing: EASE_IO,\n  });\n  const rightDraw = interpolate(t, [18, 30], [0, 1], {\n    ...CLAMP,\n    easing: EASE_IO,\n  });\n\n  return (\n    <AbsoluteFill style={{ background: p.bg, overflow: \"hidden\" }}>\n      <svg\n        width={width}\n        height={height}\n        style={{ position: \"absolute\", inset: 0 }}\n        aria-hidden\n      >\n        <defs>\n          {/* gradients.sh \"fluted\": in-chart blue, overheating past the frame. */}\n          <linearGradient\n            id={heatId}\n            gradientUnits=\"userSpaceOnUse\"\n            x1={0}\n            y1={bottom}\n            x2={0}\n            y2={bottom - accentV * px}\n          >\n            <stop offset={0} stopColor=\"#1d2a8f\" />\n            <stop offset={boxStop * 0.55} stopColor={accent} />\n            <stop offset={boxStop} stopColor=\"#2f7bff\" />\n            <stop offset={boxStop + 0.012} stopColor=\"#ff7a3d\" />\n            <stop offset={1} stopColor={p.heatTop} />\n          </linearGradient>\n        </defs>\n        {gridVals.slice(1, -1).map((g) => (\n          <line\n            key={`g-${g}`}\n            x1={boxL}\n            x2={boxR}\n            y1={bottom - g * px}\n            y2={bottom - g * px}\n            stroke={p.grid}\n            strokeWidth={sw}\n            opacity={gridIn}\n          />\n        ))}\n\n        <line\n          x1={boxL}\n          x2={boxL}\n          y1={bottom}\n          y2={bottom - upH}\n          stroke={p.frame}\n          strokeWidth={sw}\n        />\n        {rightDraw > 0 && (\n          <line\n            x1={boxR}\n            x2={boxR}\n            y1={boxT}\n            y2={lerp(boxT, bottom, rightDraw)}\n            stroke={p.frame}\n            strokeWidth={sw}\n          />\n        )}\n        {topDraw > 0 && !broken && tension > 0 && (\n          <polyline\n            points={`${boxL},${boxT} ${aX},${boxT - tension} ${aX + bw},${boxT - tension} ${boxR},${boxT}`}\n            fill=\"none\"\n            stroke={p.frame}\n            strokeWidth={sw}\n            strokeLinejoin=\"round\"\n          />\n        )}\n        {topDraw > 0 && (broken || tension <= 0) && (\n          <>\n            <line\n              x1={boxL}\n              x2={broken ? cx - half : lerp(boxL, boxR, topDraw)}\n              y1={boxT}\n              y2={boxT}\n              stroke={p.frame}\n              strokeWidth={sw}\n            />\n            {broken && (\n              <line\n                x1={cx + half}\n                x2={lerp(boxL, boxR, topDraw)}\n                y1={boxT}\n                y2={boxT}\n                stroke={p.frame}\n                strokeWidth={sw}\n              />\n            )}\n          </>\n        )}\n\n        {rows.map((d, i) => {\n          if (i === ai) return null;\n          const h = rest[i] * px;\n          if (h <= 0.01) return null;\n          return (\n            <path\n              key={`b-${d.label}`}\n              d={barPath(barX(i), bottom, bw, h, 4 * u)}\n              fill={p.bar}\n            />\n          );\n        })}\n\n        <line\n          x1={boxL}\n          x2={lerp(boxL, boxR, targetDraw)}\n          y1={ty}\n          y2={ty}\n          stroke={p.target}\n          strokeWidth={Math.max(1, 1.5 * u)}\n          strokeDasharray={`${7 * u} ${6 * u}`}\n        />\n\n        {aH > 0.01 && (\n          <path\n            d={barPath(aX, bottom, bw, aH, 4 * u)}\n            fill={`url(#${heatId})`}\n          />\n        )}\n\n        {broken &&\n          [cx - half, cx + half].map((x) => (\n            <line\n              key={`s-${x > cx ? \"r\" : \"l\"}`}\n              x1={x - slashDx * slashIn}\n              y1={boxT + (slashLen / 2) * slashIn}\n              x2={x + slashDx * slashIn}\n              y2={boxT - (slashLen / 2) * slashIn}\n              stroke={p.fg}\n              strokeWidth={Math.max(1, 1.6 * u)}\n              strokeLinecap=\"round\"\n              opacity={slashIn}\n            />\n          ))}\n\n        <line\n          x1={boxL}\n          x2={boxL + leftW}\n          y1={bottom}\n          y2={bottom}\n          stroke={p.frame}\n          strokeWidth={Math.max(1, 1.5 * u)}\n        />\n      </svg>\n\n      {gridVals.map((g) => (\n        <div\n          key={`gl-${g}`}\n          style={{\n            position: \"absolute\",\n            left: boxL - 150 * u,\n            width: 150 * u - 14 * u,\n            top: bottom - g * px - 10 * u,\n            height: 20 * u,\n            lineHeight: `${20 * u}px`,\n            textAlign: \"right\",\n            fontFamily: sans,\n            fontWeight: 400,\n            fontSize: 16 * u,\n            fontVariantNumeric: \"tabular-nums\",\n            color: p.muted,\n            opacity: gridIn,\n          }}\n        >\n          {fmt(g)}\n        </div>\n      ))}\n\n      <div\n        style={{\n          position: \"absolute\",\n          left: boxR + 14 * u,\n          top: ty - 10 * u,\n          height: 20 * u,\n          lineHeight: `${20 * u}px`,\n          fontFamily: sans,\n          fontWeight: 500,\n          fontSize: 16 * u,\n          color: p.fg,\n          opacity: targetLab,\n          transform: `translateX(${(1 - targetLab) * -6 * u}px)`,\n          whiteSpace: \"nowrap\",\n        }}\n      >\n        {targetLabel}\n      </div>\n\n      {rows.map((d, i) => (\n        <div\n          key={`c-${d.label}`}\n          style={{\n            position: \"absolute\",\n            left: barX(i) + bw / 2 - 80 * u,\n            width: 160 * u,\n            top: bottom + 14 * u,\n            textAlign: \"center\",\n            fontFamily: sans,\n            fontWeight: i === ai ? 500 : 400,\n            fontSize: 16 * u,\n            color: i === ai ? p.fg : p.muted,\n            opacity: interpolate(t, [6 + i * 2, 18 + i * 2], [0, 1], CLAMP),\n          }}\n        >\n          {d.label}\n        </div>\n      ))}\n\n      <div\n        style={{\n          position: \"absolute\",\n          left: aX,\n          width: bw,\n          top: aTop + 10 * u,\n          textAlign: \"center\",\n          fontFamily: sans,\n          fontWeight: 500,\n          fontSize: 16 * u,\n          letterSpacing: \"0\",\n          fontVariantNumeric: \"tabular-nums\",\n          color: broken ? \"#2B1206\" : \"#FFFFFF\",\n          opacity: counterO * interpolate(aH, [36 * u, 48 * u], [0, 1], CLAMP),\n          whiteSpace: \"nowrap\",\n        }}\n      >\n        {`${Math.round(aVal)}${unit}`}\n      </div>\n\n      <div\n        style={{\n          position: \"absolute\",\n          left: aX + bw + 30 * u,\n          top: aTop - 10 * u,\n          opacity: heroO,\n          transform: `translateY(${(1 - hero) * 18 * u}px)`,\n        }}\n      >\n        <div\n          style={{\n            fontFamily: sans,\n            fontWeight: 400,\n            fontSize: 150 * u,\n            lineHeight: 0.86,\n            letterSpacing: \"-0.04em\",\n            color: p.fg,\n            fontVariantNumeric: \"tabular-nums\",\n            whiteSpace: \"nowrap\",\n          }}\n        >\n          {heroText}\n        </div>\n        <div\n          style={{\n            marginTop: 16 * u,\n            fontFamily: sans,\n            fontWeight: 400,\n            fontSize: 24 * u,\n            letterSpacing: \"-0.01em\",\n            color: p.muted,\n            opacity: cap,\n            transform: `translateY(${(1 - cap) * 8 * u}px)`,\n            whiteSpace: \"nowrap\",\n          }}\n        >\n          {caption}\n        </div>\n      </div>\n\n      <AbsoluteFill\n        style={{\n          background: `radial-gradient(ellipse 85% 85% at 50% 50%, transparent 64%, ${p.bg} 100%)`,\n          opacity: 0.5,\n        }}\n      />\n      <Grain opacity={p.grain} />\n    </AbsoluteFill>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/remocn/off-the-charts.tsx"
    }
  ],
  "type": "registry:component"
}
