{"version":3,"file":"SunburstChart.cjs","names":["createVarsResolver","getThemeColor","rem","parseThemeColor","factory","useProps","useMantineTheme","useStyles","useResolvedStylesApi","useMemo","Box","ResponsiveContainer","RechartsSunburstChart","Tooltip","ChartTooltip","classes"],"sources":["../../src/SunburstChart/SunburstChart.tsx"],"sourcesContent":["import { useMemo } from 'react';\nimport {\n  ResponsiveContainer,\n  SunburstChart as RechartsSunburstChart,\n  SunburstChartProps as RechartsSunburstChartProps,\n  Tooltip,\n  TooltipProps,\n} from 'recharts';\nimport {\n  Box,\n  BoxProps,\n  createVarsResolver,\n  ElementProps,\n  factory,\n  Factory,\n  getThemeColor,\n  MantineColor,\n  MantineTheme,\n  parseThemeColor,\n  rem,\n  StylesApiProps,\n  useMantineTheme,\n  useProps,\n  useResolvedStylesApi,\n  useStyles,\n} from '@mantine/core';\nimport { ChartTooltip, ChartTooltipStylesNames } from '../ChartTooltip/ChartTooltip';\nimport classes from './SunburstChart.module.css';\n\nexport interface SunburstChartData {\n  name: string;\n  value?: number;\n  color?: MantineColor;\n  children?: SunburstChartData[];\n  [key: string]: unknown;\n}\n\nexport type SunburstChartStylesNames = 'root' | ChartTooltipStylesNames;\nexport type SunburstChartCssVariables = {\n  root: '--chart-stroke-color' | '--chart-size';\n};\n\nexport interface SunburstChartProps\n  extends BoxProps, StylesApiProps<SunburstChartFactory>, ElementProps<'div'> {\n  /** Data used to render chart */\n  data: SunburstChartData[];\n\n  /** Key in data object for the value @default 'value' */\n  dataKey?: string;\n\n  /** Determines whether the tooltip should be displayed when a node is hovered @default true */\n  withTooltip?: boolean;\n\n  /** Tooltip animation duration in ms @default 0 */\n  tooltipAnimationDuration?: number;\n\n  /** Props passed down to `Tooltip` recharts component */\n  tooltipProps?: Omit<TooltipProps<any, any>, 'ref'>;\n\n  /** Props passed down to recharts `SunburstChart` component */\n  sunburstChartProps?: Partial<Omit<RechartsSunburstChartProps, 'ref' | 'data' | 'dataKey'>>;\n\n  /** Controls color of the sectors stroke, by default depends on color scheme */\n  strokeColor?: MantineColor;\n\n  /** Controls chart width and height @default 300 */\n  size?: number;\n\n  /** Controls the radius of the inner circle at the center of the chart @default 50 */\n  innerRadius?: number;\n\n  /** Gap between sectors and rings in px @default 1 */\n  gap?: number;\n\n  /** Angle in degrees from which the chart should start @default 0 */\n  startAngle?: number;\n\n  /** Angle in degrees at which the chart should end @default 360 */\n  endAngle?: number;\n\n  /** Determines whether value labels are displayed inside each sector @default false */\n  withLabels?: boolean;\n\n  /** A function to format values inside the tooltip and labels */\n  valueFormatter?: (value: number) => string;\n\n  /** Additional elements rendered inside `SunburstChart` component */\n  children?: React.ReactNode;\n}\n\nexport type SunburstChartFactory = Factory<{\n  props: SunburstChartProps;\n  ref: HTMLDivElement;\n  stylesNames: SunburstChartStylesNames;\n  vars: SunburstChartCssVariables;\n}>;\n\nconst defaultProps = {\n  dataKey: 'value',\n  withTooltip: true,\n  tooltipAnimationDuration: 0,\n  size: 300,\n  innerRadius: 50,\n  gap: 1,\n  startAngle: 0,\n  endAngle: 360,\n} satisfies Partial<SunburstChartProps>;\n\nconst varsResolver = createVarsResolver<SunburstChartFactory>((theme, { strokeColor, size }) => ({\n  root: {\n    '--chart-stroke-color': strokeColor ? getThemeColor(strokeColor, theme) : undefined,\n    '--chart-size': rem(size),\n  },\n}));\n\nfunction resolveData(\n  data: SunburstChartData[],\n  theme: MantineTheme,\n  dataKey: string,\n  parentFill?: string\n): { resolved: any[]; total: number } {\n  let total = 0;\n\n  const resolved = data.map((item) => {\n    const resolvedColor = item.color\n      ? parseThemeColor({ color: item.color, theme }).value\n      : parentFill;\n    const fill = resolvedColor || undefined;\n\n    const result: any = {\n      ...item,\n      fill,\n    };\n\n    if (item.children) {\n      const child = resolveData(item.children, theme, dataKey, fill);\n      result.children = child.resolved;\n      if (result[dataKey] == null) {\n        result[dataKey] = child.total;\n      }\n      total += child.total;\n    } else {\n      total += Number(item[dataKey]) || 0;\n    }\n\n    return result;\n  });\n\n  return { resolved, total };\n}\n\nexport const SunburstChart = factory<SunburstChartFactory>((_props) => {\n  const props = useProps('SunburstChart', defaultProps, _props);\n  const {\n    classNames,\n    className,\n    style,\n    styles,\n    unstyled,\n    vars,\n    data,\n    dataKey,\n    withTooltip,\n    tooltipAnimationDuration,\n    tooltipProps,\n    sunburstChartProps,\n    strokeColor,\n    size,\n    innerRadius,\n    gap,\n    startAngle,\n    endAngle,\n    withLabels,\n    valueFormatter,\n    children,\n    attributes,\n    ...others\n  } = props;\n\n  const theme = useMantineTheme();\n\n  const getStyles = useStyles<SunburstChartFactory>({\n    name: 'SunburstChart',\n    classes,\n    props,\n    className,\n    style,\n    classNames,\n    styles,\n    unstyled,\n    attributes,\n    vars,\n    varsResolver,\n  });\n\n  const { resolvedClassNames, resolvedStyles } = useResolvedStylesApi<SunburstChartFactory>({\n    classNames,\n    styles,\n    props,\n  });\n\n  const rootData = useMemo(() => {\n    const { resolved, total } = resolveData(data, theme, dataKey!);\n    return {\n      name: 'root',\n      [dataKey!]: total,\n      children: resolved,\n    };\n  }, [data, theme, dataKey]);\n\n  return (\n    <Box size={size} {...getStyles('root')} {...others}>\n      <ResponsiveContainer>\n        <RechartsSunburstChart\n          data={rootData as any}\n          dataKey={dataKey as any}\n          innerRadius={innerRadius}\n          padding={gap}\n          ringPadding={0}\n          startAngle={startAngle}\n          endAngle={endAngle}\n          stroke=\"var(--chart-stroke-color, var(--mantine-color-body))\"\n          textOptions={\n            withLabels\n              ? {\n                  fontWeight: 'bold',\n                  fontSize: '.65rem',\n                  paintOrder: 'stroke fill',\n                  stroke: 'var(--chart-stroke-color, var(--mantine-color-body))',\n                  strokeWidth: 1,\n                  fill: 'var(--mantine-color-bright)',\n                  pointerEvents: 'none',\n                }\n              : { display: 'none' }\n          }\n          {...sunburstChartProps}\n        >\n          {withTooltip && (\n            <Tooltip\n              animationDuration={tooltipAnimationDuration}\n              isAnimationActive={false}\n              content={({ payload }) => (\n                <ChartTooltip\n                  payload={\n                    payload?.map((item) => ({\n                      name: item.name as string,\n                      value: item.value as number,\n                      color: (item.payload as any)?.fill || 'var(--mantine-color-blue-6)',\n                    })) || []\n                  }\n                  classNames={resolvedClassNames}\n                  styles={resolvedStyles}\n                  type=\"radial\"\n                  valueFormatter={valueFormatter}\n                  attributes={attributes}\n                />\n              )}\n              {...tooltipProps}\n            />\n          )}\n\n          {children}\n        </RechartsSunburstChart>\n      </ResponsiveContainer>\n    </Box>\n  );\n});\n\nSunburstChart.displayName = '@mantine/charts/SunburstChart';\nSunburstChart.classes = classes;\nSunburstChart.varsResolver = varsResolver;\n"],"mappings":";;;;;;;;AAiGA,MAAM,eAAe;CACnB,SAAS;CACT,aAAa;CACb,0BAA0B;CAC1B,MAAM;CACN,aAAa;CACb,KAAK;CACL,YAAY;CACZ,UAAU;AACZ;AAEA,MAAM,gBAAA,GAAeA,cAAAA,mBAAAA,EAA0C,OAAO,EAAE,aAAa,YAAY,EAC/F,MAAM;CACJ,wBAAwB,eAAA,GAAcC,cAAAA,cAAAA,CAAc,aAAa,KAAK,IAAI,KAAA;CAC1E,iBAAA,GAAgBC,cAAAA,IAAAA,CAAI,IAAI;AAC1B,EACF,EAAE;AAEF,SAAS,YACP,MACA,OACA,SACA,YACoC;CACpC,IAAI,QAAQ;CA2BZ,OAAO;EAAE,UAzBQ,KAAK,KAAK,SAAS;GAIlC,MAAM,QAHgB,KAAK,SAAA,GACvBC,cAAAA,gBAAAA,CAAgB;IAAE,OAAO,KAAK;IAAO;GAAM,CAAC,CAAC,CAAC,QAC9C,eAC0B,KAAA;GAE9B,MAAM,SAAc;IAClB,GAAG;IACH;GACF;GAEA,IAAI,KAAK,UAAU;IACjB,MAAM,QAAQ,YAAY,KAAK,UAAU,OAAO,SAAS,IAAI;IAC7D,OAAO,WAAW,MAAM;IACxB,IAAI,OAAO,YAAY,MACrB,OAAO,WAAW,MAAM;IAE1B,SAAS,MAAM;GACjB,OACE,SAAS,OAAO,KAAK,QAAQ,KAAK;GAGpC,OAAO;EACT,CAEgB;EAAG;C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