{"version":3,"file":"RadarChart.mjs","names":["RadarChart","ReChartsRadarChart","Tooltip","classes"],"sources":["../../src/RadarChart/RadarChart.tsx"],"sourcesContent":["import { useState } from 'react';\nimport {\n  Legend,\n  LegendProps,\n  PolarAngleAxis,\n  PolarAngleAxisProps,\n  PolarGrid,\n  PolarGridProps,\n  PolarRadiusAxis,\n  PolarRadiusAxisProps,\n  Radar,\n  RadarProps,\n  RadarChart as ReChartsRadarChart,\n  ResponsiveContainer,\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  StylesApiProps,\n  useMantineTheme,\n  useProps,\n  useResolvedStylesApi,\n  useStyles,\n} from '@mantine/core';\nimport { ChartAnnouncer } from '../ChartAnnouncer/ChartAnnouncer';\nimport { ChartLegend, ChartLegendStylesNames } from '../ChartLegend';\nimport { ChartTooltip, ChartTooltipStylesNames } from '../ChartTooltip';\nimport { MantineChartDotProps } from '../types';\nimport { getLegendPosition } from '../utils';\nimport classes from './RadarChart.module.css';\n\nexport interface RadarChartSeries {\n  name: string;\n  color: MantineColor;\n  strokeColor?: MantineColor;\n  opacity?: number;\n  label?: string;\n}\n\nexport type RadarChartStylesNames =\n  | 'root'\n  | 'container'\n  | ChartTooltipStylesNames\n  | ChartLegendStylesNames;\nexport type RadarChartCssVariables = {\n  root: '--chart-grid-color' | '--chart-text-color';\n};\n\nexport interface RadarChartProps\n  extends BoxProps, StylesApiProps<RadarChartFactory>, ElementProps<'div'> {\n  /** Data used in the chart */\n  data: Record<string, any>[];\n\n  /** Determines which data should be consumed from the `data` array. */\n  series: RadarChartSeries[];\n\n  /** Key of the `data` object for axis values */\n  dataKey: string;\n\n  /** Controls color of the grid lines. By default, color depends on the color scheme. */\n  gridColor?: MantineColor;\n\n  /** Controls color of all text elements. By default, color depends on the color scheme. */\n  textColor?: MantineColor;\n\n  /** Determines whether PolarGrid component should be displayed @default true. */\n  withPolarGrid?: boolean;\n\n  /** Determines whether PolarAngleAxis component should be displayed @default true */\n  withPolarAngleAxis?: boolean;\n\n  /** Determines whether PolarRadiusAxisProps component should be displayed @default false */\n  withPolarRadiusAxis?: boolean;\n\n  /** Determines whether Tooltip component should be displayed @default false */\n  withTooltip?: boolean;\n\n  /** Props passed down to recharts Radar component */\n  radarProps?:\n    | ((series: RadarChartSeries) => Partial<Omit<RadarProps, 'ref'>>)\n    | Partial<Omit<RadarProps, 'ref'>>;\n\n  /** Props passed down to recharts RadarChart component */\n  radarChartProps?: React.ComponentProps<typeof ReChartsRadarChart>;\n\n  /** Props passed down to recharts PolarGrid component */\n  polarGridProps?: Omit<PolarGridProps, 'ref'>;\n\n  /** Props passed down to recharts PolarAngleAxis component */\n  polarAngleAxisProps?: Omit<PolarAngleAxisProps, 'ref'>;\n\n  /** Props passed down to recharts PolarRadiusAxis component */\n  polarRadiusAxisProps?: Omit<PolarRadiusAxisProps, 'ref'>;\n\n  /** Props passed down to recharts Legend component */\n  legendProps?: Omit<LegendProps, 'ref'>;\n\n  /** Props passed down to recharts Tooltip component */\n  tooltipProps?: Omit<TooltipProps<any, any>, 'ref'>;\n\n  /** Tooltip position animation duration in ms @default 0 */\n  tooltipAnimationDuration?: number;\n\n  /** Determines whether the legend should be displayed @default false */\n  withLegend?: boolean;\n\n  /** Determines whether dots should be displayed @default false */\n  withDots?: boolean;\n\n  /** Props passed down to all dots. Ignored if `withDots={false}` is set. */\n  dotProps?: MantineChartDotProps;\n\n  /** Props passed down to all active dots. Ignored if `withDots={false}` is set. */\n  activeDotProps?: MantineChartDotProps;\n\n  /** Additional components that are rendered inside recharts `RadarChart` component */\n  children?: React.ReactNode;\n\n  /** Determines whether the chart should be keyboard-navigable with the recharts accessibility layer, `true` by default */\n  accessibilityLayer?: boolean;\n}\n\nexport type RadarChartFactory = Factory<{\n  props: RadarChartProps;\n  ref: HTMLDivElement;\n  stylesNames: RadarChartStylesNames;\n  vars: RadarChartCssVariables;\n}>;\n\nconst defaultProps = {\n  withPolarGrid: true,\n  withPolarAngleAxis: true,\n  withPolarRadiusAxis: false,\n  withTooltip: false,\n  withDots: false,\n  tooltipAnimationDuration: 0,\n  accessibilityLayer: true,\n} satisfies Partial<RadarChartProps>;\n\nconst varsResolver = createVarsResolver<RadarChartFactory>((theme, { gridColor, textColor }) => ({\n  root: {\n    '--chart-grid-color': gridColor ? getThemeColor(gridColor, theme) : undefined,\n    '--chart-text-color': textColor ? getThemeColor(textColor, theme) : undefined,\n  },\n}));\n\nexport const RadarChart = factory<RadarChartFactory>((_props) => {\n  const props = useProps('RadarChart', defaultProps, _props);\n  const {\n    classNames,\n    className,\n    style,\n    styles,\n    unstyled,\n    vars,\n    data,\n    series,\n    dataKey,\n    gridColor,\n    textColor,\n    radarProps,\n    radarChartProps,\n    polarGridProps,\n    polarAngleAxisProps,\n    polarRadiusAxisProps,\n    tooltipProps,\n    withPolarGrid,\n    withPolarAngleAxis,\n    withPolarRadiusAxis,\n    withTooltip,\n    tooltipAnimationDuration,\n    children,\n    withLegend,\n    withDots,\n    dotProps,\n    activeDotProps,\n    legendProps,\n    attributes,\n    accessibilityLayer,\n    ...others\n  } = props;\n\n  const theme = useMantineTheme();\n\n  const getStyles = useStyles<RadarChartFactory>({\n    name: 'RadarChart',\n    classes,\n    props,\n    className,\n    style,\n    classNames,\n    styles,\n    unstyled,\n    attributes,\n    vars,\n    varsResolver,\n  });\n\n  const [highlightedArea, setHighlightedArea] = useState<string | number | null>(null);\n\n  const { resolvedClassNames, resolvedStyles } = useResolvedStylesApi<RadarChartFactory>({\n    classNames,\n    styles,\n    props,\n  });\n\n  const radars = series.map((item, index) => (\n    <Radar\n      key={index}\n      name={item.name}\n      dataKey={item.name}\n      stroke={getThemeColor(item.strokeColor || item.color, theme)}\n      fill={getThemeColor(item.color, theme)}\n      fillOpacity={\n        highlightedArea\n          ? highlightedArea === item.name\n            ? item.opacity || 0.4\n            : 0.05\n          : item.opacity || 0.4\n      }\n      dot={\n        withDots\n          ? {\n              fillOpacity: 1,\n              strokeOpacity: 0,\n              strokeWidth: 1,\n              fill: getThemeColor(item.color, theme),\n              stroke: getThemeColor(item.color, theme),\n              ...dotProps,\n            }\n          : false\n      }\n      activeDot={\n        withDots\n          ? {\n              fill: getThemeColor(item.color, theme),\n              stroke: getThemeColor(item.color, theme),\n              ...activeDotProps,\n            }\n          : false\n      }\n      strokeOpacity={highlightedArea ? (highlightedArea === item.name ? 1 : 0.1) : 1}\n      isAnimationActive={false}\n      {...(typeof radarProps === 'function' ? radarProps(item) : radarProps)}\n    />\n  ));\n\n  return (\n    <Box {...getStyles('root')} {...others}>\n      <ResponsiveContainer {...getStyles('container')}>\n        <ReChartsRadarChart\n          data={data}\n          accessibilityLayer={accessibilityLayer}\n          {...radarChartProps}\n        >\n          {(radarChartProps?.accessibilityLayer ?? accessibilityLayer) && (\n            <ChartAnnouncer series={series} labelKey={dataKey} />\n          )}\n          {withPolarGrid && <PolarGrid stroke=\"var(--chart-grid-color)\" {...polarGridProps} />}\n          {withPolarAngleAxis && <PolarAngleAxis dataKey={dataKey} {...polarAngleAxisProps} />}\n          {withPolarRadiusAxis && (\n            <PolarRadiusAxis stroke=\"var(--chart-grid-color)\" {...polarRadiusAxisProps} />\n          )}\n          {withTooltip && (\n            <Tooltip\n              animationDuration={tooltipAnimationDuration}\n              isAnimationActive={tooltipAnimationDuration !== 0}\n              cursor={{\n                stroke: 'var(--chart-grid-color)',\n                strokeWidth: 1,\n              }}\n              content={({ label, payload, labelFormatter }) => (\n                <ChartTooltip\n                  label={labelFormatter && payload ? labelFormatter(label, payload) : label}\n                  payload={payload}\n                  classNames={resolvedClassNames}\n                  styles={resolvedStyles}\n                  series={series}\n                  attributes={attributes}\n                />\n              )}\n              {...tooltipProps}\n            />\n          )}\n          {radars}\n          {withLegend && (\n            <Legend\n              verticalAlign=\"bottom\"\n              content={(payload) => (\n                <ChartLegend\n                  payload={payload.payload}\n                  onHighlight={setHighlightedArea}\n                  legendPosition={getLegendPosition(legendProps, 'bottom')}\n                  classNames={resolvedClassNames}\n                  styles={resolvedStyles}\n                  series={series}\n                  centered\n                  attributes={attributes}\n                />\n              )}\n              {...legendProps}\n            />\n          )}\n\n          {children}\n        </ReChartsRadarChart>\n      </ResponsiveContainer>\n    </Box>\n  );\n});\n\nRadarChart.displayName = '@mantine/charts/RadarChart';\nRadarChart.classes = classes;\nRadarChart.varsResolver = varsResolver;\n\nexport namespace RadarChart {\n  export type Props = RadarChartProps;\n  export type StylesNames = RadarChartStylesNames;\n  export type CssVariables = RadarChartCssVariables;\n  export type Factory = RadarChartFactory;\n  export type Series = RadarChartSeries;\n}\n"],"mappings":";;;;;;;;;;;AAyIA,MAAM,eAAe;CACnB,eAAe;CACf,oBAAoB;CACpB,qBAAqB;CACrB,aAAa;CACb,UAAU;CACV,0BAA0B;CAC1B,oBAAoB;AACtB;AAEA,MAAM,eAAe,oBAAuC,OAAO,EAAE,WAAW,iBAAiB,EAC/F,MAAM;CACJ,sBAAsB,YAAY,cAAc,WAAW,KAAK,IAAI,KAAA;CACpE,sBAAsB,YAAY,cAAc,WAAW,KAAK,IAAI,KAAA;AACtE,EACF,EAAE;AAEF,MAAaA,eAAa,SAA4B,WAAW;CAC/D,MAAM,QAAQ,SAAS,cAAc,cAAc,MAAM;CACzD,MAAM,EACJ,YACA,WACA,OACA,QACA,UACA,MACA,MACA,QACA,SACA,WACA,WACA,YACA,iBACA,gBACA,qBACA,sBACA,cACA,eACA,oBACA,qBACA,aACA,0BACA,UACA,YACA,UACA,UACA,gBACA,aACA,YACA,oBACA,GAAG,WACD;CAEJ,MAAM,QAAQ,gBAAgB;CAE9B,MAAM,YAAY,UAA6B;EAC7C,MAAM;EACN,SAAA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CAAC;CAED,MAAM,CAAC,iBAAiB,sBAAsB,SAAiC,IAAI;CAEnF,MAAM,EAAE,oBAAoB,mBAAmB,qBAAwC;EACrF;EAC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