{"version":3,"sources":["../src/pie-chart.tsx"],"sourcesContent":["import type { HTMLUIProps, ThemeProps } from \"@yamada-ui/core\"\nimport type { TooltipDataSourceType } from \"./chart.types\"\nimport type { UseChartProps } from \"./use-chart\"\nimport type { UseChartLegendProps } from \"./use-chart-legend\"\nimport type { UseChartTooltipOptions } from \"./use-chart-tooltip\"\nimport type { UsePieChartOptions } from \"./use-pie-chart\"\nimport {\n  forwardRef,\n  omitThemeProps,\n  ui,\n  useComponentMultiStyle,\n} from \"@yamada-ui/core\"\nimport { cx } from \"@yamada-ui/utils\"\nimport { useMemo } from \"react\"\nimport {\n  Cell,\n  Legend,\n  Pie,\n  PieChart as RechartsPieChart,\n  ResponsiveContainer,\n  Tooltip,\n} from \"recharts\"\nimport { ChartLegend } from \"./chart-legend\"\nimport { ChartTooltip } from \"./chart-tooltip\"\nimport { ChartProvider, useChart } from \"./use-chart\"\nimport { useChartLegend } from \"./use-chart-legend\"\nimport { useChartTooltip } from \"./use-chart-tooltip\"\nimport { usePieChart } from \"./use-pie-chart\"\n\ninterface PieChartOptions {\n  /**\n   * Determines which data is displayed in the tooltip.\n   *\n   * @default 'all'\n   */\n  tooltipDataSource?: TooltipDataSourceType\n  /**\n   * Unit displayed next to each value in tooltip.\n   */\n  unit?: string\n  /**\n   * If `true`, legend is visible.\n   *\n   * @default false\n   */\n  withLegend?: boolean\n  /**\n   * If `true`, tooltip is visible.\n   *\n   * @default true\n   */\n  withTooltip?: boolean\n}\n\nexport interface PieChartProps\n  extends Omit<HTMLUIProps, \"fillOpacity\" | \"strokeWidth\">,\n    ThemeProps<\"pieChart\">,\n    PieChartOptions,\n    UsePieChartOptions,\n    Omit<UseChartTooltipOptions, \"labelFormatter\">,\n    UseChartLegendProps,\n    UseChartProps {}\n\n/**\n * `PieChart` is a component for drawing pie charts to compare multiple sets of data.\n *\n * @see Docs https://yamada-ui.com/components/data-display/pie-chart\n */\nexport const PieChart = forwardRef<PieChartProps, \"div\">((props, ref) => {\n  const [styles, mergedProps] = useComponentMultiStyle(\"PieChart\", props)\n  const {\n    className,\n    data,\n    endAngle,\n    innerRadius,\n    isPercent,\n    labelFormatter,\n    labelOffset,\n    outerRadius,\n    paddingAngle,\n    percent,\n    startAngle,\n    strokeWidth,\n    tooltipAnimationDuration,\n    tooltipDataSource = \"all\",\n    unit,\n    valueFormatter,\n    withLabelLines,\n    withLabels,\n    withLegend = false,\n    withTooltip = true,\n    cellProps,\n    chartProps,\n    containerProps,\n    legendProps,\n    pieProps,\n    tooltipProps,\n    ...rest\n  } = omitThemeProps(mergedProps)\n\n  const {\n    pieVars,\n    setHighlightedArea,\n    getCellProps,\n    getPieChartProps,\n    getPieProps,\n  } = usePieChart({\n    data,\n    endAngle,\n    innerRadius,\n    isPercent,\n    labelFormatter,\n    labelOffset,\n    outerRadius,\n    paddingAngle,\n    percent,\n    startAngle,\n    strokeWidth,\n    styles,\n    withLabelLines,\n    withLabels,\n    cellProps,\n    chartProps,\n    pieProps,\n  })\n  const { getContainerProps } = useChart({ containerProps })\n  const { getTooltipProps, tooltipProps: computedTooltipProps } =\n    useChartTooltip({\n      styles,\n      tooltipAnimationDuration,\n      tooltipProps,\n    })\n  const { getLegendProps, legendProps: computedLegendProps } = useChartLegend({\n    legendProps,\n  })\n\n  const cells = useMemo(\n    () =>\n      data.map(({ name }, index) => (\n        <Cell\n          key={`pie-cell-${name}`}\n          {...getCellProps({ className: \"ui-pie-chart__cell\", index })}\n        />\n      )),\n    [data, getCellProps],\n  )\n\n  return (\n    <ChartProvider value={{ styles }}>\n      <ui.div\n        ref={ref}\n        className={cx(\"ui-pie-chart\", className)}\n        __css={{ maxW: \"full\", vars: pieVars, ...styles.container }}\n        {...rest}\n      >\n        <ResponsiveContainer\n          {...getContainerProps({ className: \"ui-pie-chart__container\" })}\n        >\n          <RechartsPieChart\n            {...getPieChartProps({ className: \"ui-pie-chart__chart\" })}\n          >\n            <Pie\n              {...getPieProps({\n                className: \"ui-pie-chart__pie\",\n              })}\n            >\n              {cells}\n            </Pie>\n\n            {withLegend ? (\n              <Legend\n                content={({ payload }) => (\n                  <ChartLegend\n                    className=\"ui-pie-chart__legend\"\n                    payload={payload}\n                    onHighlight={setHighlightedArea}\n                    {...computedLegendProps}\n                  />\n                )}\n                {...getLegendProps()}\n              />\n            ) : null}\n\n            {withTooltip ? (\n              <Tooltip\n                content={({ label, payload }) => (\n                  <ChartTooltip\n                    className=\"ui-pie-chart__tooltip\"\n                    label={label}\n                    payload={tooltipDataSource === \"segment\" ? payload : data}\n                    unit={unit}\n                    valueFormatter={valueFormatter}\n                    {...computedTooltipProps}\n                  />\n                )}\n                {...getTooltipProps()}\n              />\n            ) : null}\n          </RechartsPieChart>\n        </ResponsiveContainer>\n      </ui.div>\n    </ChartProvider>\n  )\n})\n\nPieChart.displayName = \"PieChart\"\nPieChart.__ui__ = \"PieChart\"\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAMA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,UAAU;AACnB,SAAS,eAAe;AACxB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA,YAAY;AAAA,EACZ;AAAA,EACA;AAAA,OACK;AAsHC,cAmBE,YAnBF;AAvED,IAAM,WAAW,WAAiC,CAAC,OAAO,QAAQ;AACvE,QAAM,CAAC,QAAQ,WAAW,IAAI,uBAAuB,YAAY,KAAK;AACtE,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,oBAAoB;AAAA,IACpB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,aAAa;AAAA,IACb,cAAc;AAAA,IACd;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EACL,IAAI,eAAe,WAA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