{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "extends": "none",
  "name": "pie-chart",
  "title": "pie-chart",
  "description": "pie-chart",
  "dependencies": [
    "recharts"
  ],
  "registryDependencies": [
    "https://intentui.com/r/chart"
  ],
  "files": [
    {
      "path": "src/components/ui/pie-chart.tsx",
      "content": "'use client'\n\nimport type { ComponentProps } from 'react'\nimport { Cell, Pie, PieChart as PieChartPrimitive } from 'recharts'\nimport {\n  type BaseChartProps,\n  Chart,\n  ChartTooltip,\n  ChartTooltipContent,\n  DEFAULT_COLORS,\n  getColorValue,\n} from './chart'\n\ntype PieChartDatum = BaseChartProps['data'][number]\n\nfunction sumNumericArray(arr: number[]): number {\n  return arr.reduce((sum, num) => sum + num, 0)\n}\n\nfunction calculateDefaultLabel(data: BaseChartProps['data'], valueKey: string): number {\n  return sumNumericArray(\n    data.map((dataPoint) => {\n      const value = dataPoint[valueKey]\n      return typeof value === 'number' ? value : 0\n    })\n  )\n}\n\nfunction parseLabelInput(\n  labelInput: string | undefined,\n  valueFormatter: (value: number) => string,\n  data: BaseChartProps['data'],\n  valueKey: string\n): string {\n  return labelInput || valueFormatter(calculateDefaultLabel(data, valueKey))\n}\n\ninterface PieChartProps extends Omit<\n  BaseChartProps,\n  | 'hideGridLines'\n  | 'hideXAxis'\n  | 'hideYAxis'\n  | 'xAxisProps'\n  | 'yAxisProps'\n  | 'displayEdgeLabelsOnly'\n  | 'legend'\n  | 'legendProps'\n> {\n  variant?: 'pie' | 'donut'\n  nameKey?: string\n\n  chartProps?: Omit<ComponentProps<typeof PieChartPrimitive>, 'data' | 'stackOffset'>\n\n  label?: string\n  showLabel?: boolean\n  pieProps?: Omit<ComponentProps<typeof Pie>, 'data' | 'dataKey' | 'name'>\n}\n\nconst PieChart = ({\n  data = [],\n  dataKey,\n  colors = DEFAULT_COLORS,\n  config,\n  children,\n  label,\n  showLabel,\n\n  // Components\n  tooltip = true,\n  tooltipProps,\n\n  variant = 'pie',\n  nameKey,\n\n  chartProps,\n\n  valueFormatter = (value: number) => value.toString(),\n  pieProps,\n  ...props\n}: PieChartProps) => {\n  const parsedLabelInput = parseLabelInput(label, valueFormatter, data, dataKey)\n\n  return (\n    <Chart config={config} data={data} layout=\"radial\" dataKey={dataKey} {...props}>\n      {({ onLegendSelect }) => (\n        <PieChartPrimitive\n          data={data}\n          onClick={() => {\n            onLegendSelect(null)\n          }}\n          margin={{\n            bottom: 0,\n            left: 0,\n            right: 0,\n            top: 0,\n          }}\n          {...chartProps}\n        >\n          {showLabel && variant === 'donut' && (\n            <text\n              className=\"fill-fg font-semibold\"\n              x=\"50%\"\n              data-slot=\"label\"\n              y=\"50%\"\n              textAnchor=\"middle\"\n              dominantBaseline=\"middle\"\n            >\n              {parsedLabelInput}\n            </text>\n          )}\n\n          {!children ? (\n            <Pie\n              name={nameKey}\n              dataKey={dataKey}\n              data={data}\n              cx={pieProps?.cx ?? '50%'}\n              cy={pieProps?.cy ?? '50%'}\n              startAngle={pieProps?.startAngle ?? 90}\n              endAngle={pieProps?.endAngle ?? -270}\n              strokeLinejoin=\"round\"\n              innerRadius={variant === 'donut' ? '50%' : '0%'}\n              isAnimationActive\n              {...pieProps}\n            >\n              {data.map((datum: PieChartDatum, index: number) => {\n                const configKey =\n                  typeof datum.code === 'string'\n                    ? datum.code\n                    : typeof datum.name === 'string'\n                      ? datum.name\n                      : undefined\n\n                return (\n                  <Cell\n                    key={`cell-${index}`}\n                    fill={getColorValue(\n                      config?.[configKey ?? '']?.color ?? colors[index % colors.length]\n                    )}\n                  />\n                )\n              })}\n            </Pie>\n          ) : (\n            children\n          )}\n\n          {tooltip && (\n            <ChartTooltip\n              content={\n                typeof tooltip === 'boolean' ? (\n                  <ChartTooltipContent hideLabel labelSeparator={false} accessibilityLayer />\n                ) : (\n                  tooltip\n                )\n              }\n              {...tooltipProps}\n            />\n          )}\n        </PieChartPrimitive>\n      )}\n    </Chart>\n  )\n}\n\nexport type { PieChartProps }\nexport { PieChart }\n",
      "type": "registry:ui"
    }
  ],
  "type": "registry:ui"
}