{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "chart",
  "title": "Chart",
  "type": "registry:ui",
  "files": [
    {
      "path": "packages/registry-native/components/chart/Chart.tsx",
      "content": "import * as React from 'react'\nimport { Text, View, type ViewProps } from 'react-native'\nimport Svg, { Circle, G, Line, Path } from 'react-native-svg'\nimport Animated, {\n  Easing,\n  useAnimatedProps,\n  useAnimatedStyle,\n  useReducedMotion,\n  useSharedValue,\n  withDelay,\n  withTiming,\n  type SharedValue,\n} from 'react-native-reanimated'\nimport { cn } from '@/lib/utils'\nimport { motionDurations } from '@/lib/motion'\nimport { useThemeColors } from '@/lib/theme'\n\n/** One chart point. Labels name the category for axes and screen readers. */\nexport interface ChartDatum {\n  label: string\n  value: number\n}\n\n/** Default segment palette (chart token hex values). Pass `colors` to\n *  DonutChart to override — e.g. with the dark-mode token values. */\nexport const chartPalette = ['#0d9488', '#2563eb', '#d97706', '#7c3aed', '#e11d48'] as const\n\nconst AnimatedPath = Animated.createAnimatedComponent(Path)\nconst AnimatedCircle = Animated.createAnimatedComponent(Circle)\n\nfunction summarize(kind: string, data: ChartDatum[]): string {\n  if (data.length === 0) return `${kind} chart, no data`\n  const parts = data.slice(0, 6).map((d) => `${d.label} ${d.value}`)\n  return `${kind} chart: ${parts.join(', ')}${data.length > 6 ? `, and ${data.length - 6} more` : ''}`\n}\n\n/** 0→1 sweep shared by every chart. Re-runs when the data identity changes;\n *  static under reduced motion. All consumers animate transform, opacity, or\n *  stroke dash only — never layout — so charts stay at display refresh. */\nfunction useSweep(data: ChartDatum[]): SharedValue<number> {\n  const reduced = useReducedMotion()\n  const progress = useSharedValue(reduced ? 1 : 0)\n  React.useEffect(() => {\n    progress.value = reduced\n      ? 1\n      : withTiming(1, { duration: motionDurations.slow * 2, easing: Easing.out(Easing.cubic) })\n  }, [data, reduced, progress])\n  return progress\n}\n\nfunction EmptyChart({ height, label }: { height: number; label: string }) {\n  return (\n    <View style={{ height }} className=\"items-center justify-center\" accessibilityLabel={label}>\n      <Text className=\"text-sm text-muted-foreground\">No data yet</Text>\n    </View>\n  )\n}\n\n/* ------------------------------------------------------------------ */\n/* BarChart                                                            */\n/* ------------------------------------------------------------------ */\n\nexport interface BarChartProps extends ViewProps {\n  data: ChartDatum[]\n  className?: string\n  barClassName?: string\n  height?: number\n  showLabels?: boolean\n}\n\nfunction Bar({ height, index, className }: { height: number; index: number; className?: string }) {\n  const reduced = useReducedMotion()\n  const scale = useSharedValue(reduced ? 1 : 0)\n  React.useEffect(() => {\n    scale.value = reduced\n      ? 1\n      : withDelay(\n          index * 40,\n          withTiming(1, { duration: motionDurations.slow + 150, easing: Easing.out(Easing.cubic) }),\n        )\n  }, [index, reduced, scale])\n  const grow = useAnimatedStyle(() => ({ transform: [{ scaleY: scale.value }] }))\n  // Keep the animated transform out of NativeWind's style resolution.\n  return (\n    <Animated.View cssInterop={false} style={[{ height, transformOrigin: 'bottom' }, grow]}>\n      <View className={cn('bg-chart-2 flex-1 rounded-t-[4px]', className)} />\n    </Animated.View>\n  )\n}\n\n/** Vertical bars scaled to the largest value. Bars grow from the baseline\n *  with a 40ms stagger (transform only). */\nfunction BarChart({\n  data,\n  className,\n  barClassName,\n  height = 160,\n  showLabels = true,\n  accessibilityLabel,\n  ...props\n}: BarChartProps) {\n  const label = accessibilityLabel ?? summarize('Bar', data)\n  const max = Math.max(...data.map((d) => d.value), 0)\n  if (data.length === 0 || max <= 0) return <EmptyChart height={height} label={label} />\n\n  return (\n    <View accessibilityRole=\"image\" accessibilityLabel={label} className={className} {...props}>\n      <View style={{ height }} className=\"flex-row items-end gap-2\">\n        {data.map((d, index) => (\n          <View key={`${d.label}-${index}`} className=\"flex-1\">\n            <Bar\n              height={height * Math.max(d.value / max, d.value > 0 ? 0.015 : 0)}\n              index={index}\n              className={barClassName}\n            />\n          </View>\n        ))}\n      </View>\n      <View className=\"h-px bg-border\" />\n      {showLabels ? (\n        <View className=\"flex-row gap-2 pt-2\">\n          {data.map((d, index) => (\n            <Text\n              key={`${d.label}-${index}`}\n              numberOfLines={1}\n              className=\"flex-1 text-center text-xs text-muted-foreground\"\n            >\n              {d.label}\n            </Text>\n          ))}\n        </View>\n      ) : null}\n    </View>\n  )\n}\n\n/* ------------------------------------------------------------------ */\n/* AreaChart                                                           */\n/* ------------------------------------------------------------------ */\n\nexport interface AreaChartProps extends ViewProps {\n  data: ChartDatum[]\n  /** Raw stroke/fill color (SVG cannot read utility classes). Defaults to\n   *  the theme foreground; pass a chart token hex for a colored series. */\n  color?: string\n  className?: string\n  height?: number\n  showLabels?: boolean\n}\n\nconst AREA_W = 300\nconst AREA_H = 100\nconst AREA_INSET = 5\n\n/** Line + filled area from a zero baseline, with hairline grid rows. The\n *  line draws on via stroke-dash offset; the fill fades in under it. */\nfunction AreaChart({\n  data,\n  color,\n  className,\n  height = 160,\n  showLabels = true,\n  accessibilityLabel,\n  ...props\n}: AreaChartProps) {\n  const colors = useThemeColors()\n  const stroke = color ?? colors.foreground\n  const progress = useSweep(data)\n  const label = accessibilityLabel ?? summarize('Area', data)\n  const max = Math.max(...data.map((d) => d.value), 0)\n\n  const points = React.useMemo(() => {\n    if (data.length === 0 || max <= 0) return []\n    return data.map((d, index) => ({\n      x: AREA_INSET + (index / Math.max(data.length - 1, 1)) * (AREA_W - AREA_INSET * 2),\n      y: AREA_H - AREA_INSET - (d.value / max) * (AREA_H - AREA_INSET * 2),\n    }))\n  }, [data, max])\n\n  const { line, area, length } = React.useMemo(() => {\n    if (points.length === 0) return { line: '', area: '', length: 0 }\n    const path = points.map((p, i) => `${i === 0 ? 'M' : 'L'} ${p.x} ${p.y}`).join(' ')\n    const last = points[points.length - 1]\n    const first = points[0]\n    let total = 0\n    for (let i = 1; i < points.length; i++) {\n      total += Math.hypot(points[i].x - points[i - 1].x, points[i].y - points[i - 1].y)\n    }\n    return { line: path, area: `${path} L ${last.x} ${AREA_H} L ${first.x} ${AREA_H} Z`, length: total }\n  }, [points])\n\n  const lineProps = useAnimatedProps(() => ({ strokeDashoffset: length * (1 - progress.value) }))\n  const areaProps = useAnimatedProps(() => ({ opacity: 0.12 * progress.value }))\n\n  if (data.length === 0 || max <= 0) return <EmptyChart height={height} label={label} />\n\n  const firstLabel = data[0]?.label\n  const midLabel = data[Math.floor(data.length / 2)]?.label\n  const lastLabel = data[data.length - 1]?.label\n  const lastPoint = points[points.length - 1]\n\n  return (\n    <View accessibilityRole=\"image\" accessibilityLabel={label} className={className} {...props}>\n      <Svg width=\"100%\" height={height} viewBox={`0 0 ${AREA_W} ${AREA_H}`} preserveAspectRatio=\"none\">\n        {[0.25, 0.5, 0.75].map((f) => (\n          <Line\n            key={f}\n            x1={AREA_INSET}\n            x2={AREA_W - AREA_INSET}\n            y1={AREA_H * f}\n            y2={AREA_H * f}\n            stroke={colors.input}\n            strokeWidth={0.75}\n          />\n        ))}\n        <AnimatedPath d={area} fill={stroke} stroke=\"none\" animatedProps={areaProps} />\n        <AnimatedPath\n          d={line}\n          fill=\"none\"\n          stroke={stroke}\n          strokeWidth={2}\n          strokeLinecap=\"round\"\n          strokeLinejoin=\"round\"\n          strokeDasharray={`${length}`}\n          animatedProps={lineProps}\n        />\n        {points.map((p, i) => (\n          <Circle key={i} cx={p.x} cy={p.y} r={i === points.length - 1 ? 3.2 : 1.8} fill={stroke} />\n        ))}\n        {lastPoint ? <Circle cx={lastPoint.x} cy={lastPoint.y} r={5.5} fill={stroke} opacity={0.18} /> : null}\n      </Svg>\n      {showLabels ? (\n        <View className=\"flex-row items-center justify-between pt-2\">\n          <Text className=\"text-xs text-muted-foreground\">{firstLabel}</Text>\n          <Text className=\"text-xs text-muted-foreground\">{midLabel}</Text>\n          <Text className=\"text-xs text-muted-foreground\">{lastLabel}</Text>\n        </View>\n      ) : null}\n    </View>\n  )\n}\n\n/* ------------------------------------------------------------------ */\n/* DonutChart                                                          */\n/* ------------------------------------------------------------------ */\n\nexport interface DonutChartProps extends ViewProps {\n  data: ChartDatum[]\n  /** Segment colors (raw SVG strokes), cycled in data order. */\n  colors?: string[]\n  className?: string\n  size?: number\n  thickness?: number\n  centerValue?: string\n  centerLabel?: string\n}\n\nfunction DonutSegment({\n  progress,\n  size,\n  radius,\n  thickness,\n  circumference,\n  length,\n  offset,\n  stroke,\n}: {\n  progress: SharedValue<number>\n  size: number\n  radius: number\n  thickness: number\n  circumference: number\n  length: number\n  offset: number\n  stroke: string\n}) {\n  const animatedProps = useAnimatedProps(() => ({\n    strokeDasharray: `${Math.max(length * progress.value, 0)} ${circumference}`,\n    strokeDashoffset: -offset * progress.value,\n  }))\n  return (\n    <AnimatedCircle\n      cx={size / 2}\n      cy={size / 2}\n      r={radius}\n      fill=\"none\"\n      stroke={stroke}\n      strokeWidth={thickness}\n      animatedProps={animatedProps}\n    />\n  )\n}\n\n/** Proportional ring segments sweeping in together from the top. Render\n *  your own legend rows beside it — the chart stays rendering-only. */\nfunction DonutChart({\n  data,\n  colors: palette,\n  className,\n  size = 168,\n  thickness = 22,\n  centerValue,\n  centerLabel,\n  accessibilityLabel,\n  ...props\n}: DonutChartProps) {\n  const colors = useThemeColors()\n  const progress = useSweep(data)\n  const label = accessibilityLabel ?? summarize('Donut', data)\n  const total = data.reduce((sum, d) => sum + Math.max(d.value, 0), 0)\n  if (data.length === 0 || total <= 0) return <EmptyChart height={size} label={label} />\n\n  const radius = (size - thickness) / 2\n  const circumference = 2 * Math.PI * radius\n  const gap = data.length > 1 ? 2.5 : 0\n  let cursor = 0\n  const segments = data.map((d, index) => {\n    const length = (Math.max(d.value, 0) / total) * circumference\n    const segment = { key: `${d.label}-${index}`, length: Math.max(length - gap, 0), offset: cursor, index }\n    cursor += length\n    return segment\n  })\n\n  return (\n    <View\n      accessibilityRole=\"image\"\n      accessibilityLabel={label}\n      style={{ width: size, height: size }}\n      className={cn('relative', className)}\n      {...props}\n    >\n      <Svg width={size} height={size} viewBox={`0 0 ${size} ${size}`}>\n        <Circle cx={size / 2} cy={size / 2} r={radius} fill=\"none\" stroke={colors.input} strokeWidth={thickness} />\n        <G transform={`rotate(-90 ${size / 2} ${size / 2})`}>\n          {segments.map((s) => (\n            <DonutSegment\n              key={s.key}\n              progress={progress}\n              size={size}\n              radius={radius}\n              thickness={thickness}\n              circumference={circumference}\n              length={s.length}\n              offset={s.offset}\n              stroke={(palette ?? chartPalette)[s.index % (palette ?? chartPalette).length]}\n            />\n          ))}\n        </G>\n      </Svg>\n      {centerValue || centerLabel ? (\n        <View className=\"absolute inset-0 items-center justify-center\" pointerEvents=\"none\">\n          {centerValue ? <Text className=\"text-xl font-semibold text-foreground\">{centerValue}</Text> : null}\n          {centerLabel ? <Text className=\"text-xs text-muted-foreground\">{centerLabel}</Text> : null}\n        </View>\n      ) : null}\n    </View>\n  )\n}\n\nexport { AreaChart, BarChart, DonutChart }\n",
      "type": "registry:ui",
      "target": "~/components/ui/chart/Chart.tsx"
    },
    {
      "path": "packages/registry-native/components/chart/index.ts",
      "content": "export {\n  AreaChart,\n  BarChart,\n  DonutChart,\n  chartPalette,\n  type AreaChartProps,\n  type BarChartProps,\n  type ChartDatum,\n  type DonutChartProps,\n} from './Chart'\n",
      "type": "registry:ui",
      "target": "~/components/ui/chart/index.ts"
    }
  ],
  "dependencies": [
    "react-native-reanimated",
    "react-native-svg"
  ],
  "devDependencies": [],
  "registryDependencies": [
    "https://native.uipkge.dev/r/native/motion.json"
  ],
  "description": "Lightweight SVG charts: BarChart (view bars, transform-grow), AreaChart (line + fill with draw-on stroke), DonutChart (sweep segments with center label). Shared { label, value } data shape, image-role a11y summaries, reduced-motion safe.",
  "categories": [
    "data-display"
  ]
}