@mantine/charts 9.3.2 → 9.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/cjs/AreaChart/AreaChart.cjs.map +1 -1
  2. package/cjs/AreaChart/AreaGradient.cjs.map +1 -1
  3. package/cjs/AreaChart/AreaSplit.cjs.map +1 -1
  4. package/cjs/AreaChart/get-split-offset.cjs.map +1 -1
  5. package/cjs/BarChart/BarChart.cjs.map +1 -1
  6. package/cjs/BarsList/BarsList.cjs.map +1 -1
  7. package/cjs/BubbleChart/BubbleChart.cjs.map +1 -1
  8. package/cjs/ChartLegend/ChartLegend.cjs +6 -6
  9. package/cjs/ChartLegend/ChartLegend.cjs.map +1 -1
  10. package/cjs/ChartTooltip/ChartTooltip.cjs +5 -1
  11. package/cjs/ChartTooltip/ChartTooltip.cjs.map +1 -1
  12. package/cjs/CompositeChart/CompositeChart.cjs.map +1 -1
  13. package/cjs/DonutChart/DonutChart.cjs +31 -10
  14. package/cjs/DonutChart/DonutChart.cjs.map +1 -1
  15. package/cjs/FunnelChart/FunnelChart.cjs +27 -4
  16. package/cjs/FunnelChart/FunnelChart.cjs.map +1 -1
  17. package/cjs/Heatmap/Heatmap.cjs.map +1 -1
  18. package/cjs/Heatmap/HeatmapSplitWeeks.cjs.map +1 -1
  19. package/cjs/Heatmap/HeatmapWeeks.cjs.map +1 -1
  20. package/cjs/Heatmap/get-columns/get-columns.cjs.map +1 -1
  21. package/cjs/Heatmap/get-dates-range/get-dates-range.cjs.map +1 -1
  22. package/cjs/Heatmap/get-months-range/get-months-range.cjs.map +1 -1
  23. package/cjs/LineChart/LineChart.cjs.map +1 -1
  24. package/cjs/PieChart/PieChart.cjs +31 -10
  25. package/cjs/PieChart/PieChart.cjs.map +1 -1
  26. package/cjs/PointLabel/PointLabel.cjs.map +1 -1
  27. package/cjs/RadarChart/RadarChart.cjs.map +1 -1
  28. package/cjs/RadialBarChart/RadialBarChart.cjs +7 -5
  29. package/cjs/RadialBarChart/RadialBarChart.cjs.map +1 -1
  30. package/cjs/SankeyChart/SankeyChart.cjs.map +1 -1
  31. package/cjs/ScatterChart/ScatterChart.cjs.map +1 -1
  32. package/cjs/Sparkline/Sparkline.cjs.map +1 -1
  33. package/cjs/Treemap/Treemap.cjs.map +1 -1
  34. package/cjs/utils/get-pie-chart-data/get-pie-chart-data.cjs +18 -0
  35. package/cjs/utils/get-pie-chart-data/get-pie-chart-data.cjs.map +1 -0
  36. package/esm/AreaChart/AreaChart.mjs.map +1 -1
  37. package/esm/AreaChart/get-split-offset.mjs.map +1 -1
  38. package/esm/BarChart/BarChart.mjs.map +1 -1
  39. package/esm/BubbleChart/BubbleChart.mjs.map +1 -1
  40. package/esm/ChartLegend/ChartLegend.mjs +6 -6
  41. package/esm/ChartLegend/ChartLegend.mjs.map +1 -1
  42. package/esm/ChartTooltip/ChartTooltip.mjs +5 -1
  43. package/esm/ChartTooltip/ChartTooltip.mjs.map +1 -1
  44. package/esm/CompositeChart/CompositeChart.mjs.map +1 -1
  45. package/esm/DonutChart/DonutChart.mjs +32 -11
  46. package/esm/DonutChart/DonutChart.mjs.map +1 -1
  47. package/esm/FunnelChart/FunnelChart.mjs +28 -5
  48. package/esm/FunnelChart/FunnelChart.mjs.map +1 -1
  49. package/esm/Heatmap/Heatmap.mjs.map +1 -1
  50. package/esm/Heatmap/HeatmapSplitWeeks.mjs.map +1 -1
  51. package/esm/Heatmap/get-columns/get-columns.mjs.map +1 -1
  52. package/esm/Heatmap/get-dates-range/get-dates-range.mjs.map +1 -1
  53. package/esm/Heatmap/get-months-range/get-months-range.mjs.map +1 -1
  54. package/esm/LineChart/LineChart.mjs.map +1 -1
  55. package/esm/PieChart/PieChart.mjs +32 -11
  56. package/esm/PieChart/PieChart.mjs.map +1 -1
  57. package/esm/RadarChart/RadarChart.mjs.map +1 -1
  58. package/esm/RadialBarChart/RadialBarChart.mjs +7 -5
  59. package/esm/RadialBarChart/RadialBarChart.mjs.map +1 -1
  60. package/esm/SankeyChart/SankeyChart.mjs.map +1 -1
  61. package/esm/ScatterChart/ScatterChart.mjs.map +1 -1
  62. package/esm/Treemap/Treemap.mjs.map +1 -1
  63. package/esm/utils/get-pie-chart-data/get-pie-chart-data.mjs +18 -0
  64. package/esm/utils/get-pie-chart-data/get-pie-chart-data.mjs.map +1 -0
  65. package/lib/ChartLegend/ChartLegend.d.ts +2 -2
  66. package/lib/ChartTooltip/ChartTooltip.d.ts +3 -3
  67. package/lib/DonutChart/DonutChart.d.ts +7 -2
  68. package/lib/FunnelChart/FunnelChart.d.ts +7 -2
  69. package/lib/PieChart/PieChart.d.ts +7 -2
  70. package/lib/utils/get-pie-chart-data/get-pie-chart-data.d.ts +505 -0
  71. package/lib/utils/index.d.ts +1 -0
  72. package/package.json +5 -5
@@ -1 +1 @@
1
- {"version":3,"file":"Treemap.mjs","names":["Treemap","RechartsTreemap","Tooltip","classes"],"sources":["../../src/Treemap/Treemap.tsx"],"sourcesContent":["import React from 'react';\nimport {\n Treemap as RechartsTreemap,\n TreemapProps as RechartsTreemapProps,\n ResponsiveContainer,\n Tooltip,\n TooltipProps,\n} from 'recharts';\nimport {\n Box,\n BoxProps,\n createVarsResolver,\n ElementProps,\n factory,\n Factory,\n getAutoContrastValue,\n getThemeColor,\n isLightColor,\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 './Treemap.module.css';\n\nexport interface TreemapData {\n name: string;\n value?: number;\n color?: MantineColor;\n children?: TreemapData[];\n [key: string]: unknown;\n}\n\nexport type TreemapStylesNames = 'root' | ChartTooltipStylesNames;\nexport type TreemapCssVariables = {\n root: '--chart-stroke-color' | '--chart-height';\n};\n\nexport interface TreemapProps\n extends BoxProps, StylesApiProps<TreemapFactory>, ElementProps<'div'> {\n /** Data used to render chart */\n data: TreemapData[];\n\n /** Key in data object for the value @default 'value' */\n dataKey?: string;\n\n /** The treemap will try to keep every single rectangle's aspect ratio near the aspectRatio given @default 1.618033988749895 */\n aspectRatio?: number;\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 `Treemap` component */\n treemapProps?: Partial<Omit<RechartsTreemapProps, 'ref' | 'data' | 'dataKey'>>;\n\n /** Controls color of the node stroke, by default depends on color scheme */\n strokeColor?: MantineColor;\n\n /** Controls text color of labels @default dimmed */\n textColor?: MantineColor;\n\n /** Controls chart height @default 300 */\n height?: number;\n\n /** Controls width of node stroke @default 1 */\n strokeWidth?: number;\n\n /** A function to format values inside the tooltip */\n valueFormatter?: (value: number) => string;\n\n /** Determines whether text color should be adjusted based on background color to improve contrast */\n autoContrast?: boolean;\n\n /** Additional elements rendered inside `Treemap` component */\n children?: React.ReactNode;\n}\n\nexport type TreemapFactory = Factory<{\n props: TreemapProps;\n ref: HTMLDivElement;\n stylesNames: TreemapStylesNames;\n vars: TreemapCssVariables;\n}>;\n\nconst defaultProps = {\n dataKey: 'value',\n withTooltip: true,\n tooltipAnimationDuration: 0,\n height: 300,\n strokeWidth: 1,\n aspectRatio: 0.5 * (1 + Math.sqrt(5)),\n} satisfies Partial<TreemapProps>;\n\nconst varsResolver = createVarsResolver<TreemapFactory>((theme, { strokeColor, height }) => ({\n root: {\n '--chart-stroke-color': strokeColor ? getThemeColor(strokeColor, theme) : undefined,\n '--chart-height': rem(height),\n },\n}));\n\ninterface TreemapContentProps {\n x: number;\n y: number;\n width: number;\n height: number;\n depth: number;\n name: string;\n resolvedColors: Record<string, string>;\n resolvedLabelColors: Record<string, string>;\n index: number;\n strokeWidth: number;\n}\n\nfunction TreemapContent({\n x,\n y,\n width,\n height,\n depth,\n name,\n resolvedColors,\n resolvedLabelColors,\n index,\n strokeWidth,\n}: TreemapContentProps) {\n const fill = resolvedColors[name] || `var(--mantine-color-blue-${(index % 9) + 1})`;\n const labelColor = resolvedLabelColors[name] || 'var(--mantine-color-white)';\n const showLabel = width > 30 && height > 20;\n\n return (\n <g>\n <rect\n x={x}\n y={y}\n width={width}\n height={height}\n fill={depth >= 1 ? fill : 'transparent'}\n stroke=\"var(--chart-stroke-color, var(--mantine-color-body))\"\n strokeWidth={depth >= 1 ? strokeWidth : 0}\n />\n {depth >= 1 && showLabel && (\n <text\n x={x + width / 2}\n y={y + height / 2}\n textAnchor=\"middle\"\n dominantBaseline=\"central\"\n fill={labelColor}\n fontSize={12}\n fontFamily=\"var(--mantine-font-family)\"\n >\n {name}\n </text>\n )}\n </g>\n );\n}\n\nfunction resolveColors(\n data: TreemapData[],\n theme: MantineTheme,\n parentColor?: string\n): Record<string, string> {\n const result: Record<string, string> = {};\n for (const item of data) {\n const color = item.color || parentColor;\n if (color) {\n result[item.name] = parseThemeColor({ color, theme }).value;\n }\n if (item.children) {\n Object.assign(result, resolveColors(item.children, theme, color));\n }\n }\n return result;\n}\n\nfunction resolveLabelColors(\n resolvedColors: Record<string, string>,\n autoContrast: boolean,\n luminanceThreshold: number,\n textColor?: string\n): Record<string, string> {\n const result: Record<string, string> = {};\n for (const [name, color] of Object.entries(resolvedColors)) {\n if (textColor) {\n result[name] = textColor;\n } else if (autoContrast) {\n result[name] = isLightColor(color, luminanceThreshold)\n ? 'var(--mantine-color-black)'\n : 'var(--mantine-color-white)';\n }\n }\n return result;\n}\n\nexport const Treemap = factory<TreemapFactory>((_props) => {\n const props = useProps('Treemap', defaultProps, _props);\n const {\n classNames,\n className,\n style,\n styles,\n unstyled,\n vars,\n data,\n dataKey,\n aspectRatio,\n withTooltip,\n tooltipAnimationDuration,\n tooltipProps,\n treemapProps,\n strokeColor,\n textColor,\n height: chartHeight,\n strokeWidth,\n valueFormatter,\n autoContrast,\n children,\n attributes,\n ...others\n } = props;\n\n const theme = useMantineTheme();\n const resolvedColors = resolveColors(data, theme);\n const _autoContrast = getAutoContrastValue(autoContrast, theme);\n const _textColor = textColor ? getThemeColor(textColor, theme) : undefined;\n const resolvedLabelColors = resolveLabelColors(\n resolvedColors,\n _autoContrast,\n theme.luminanceThreshold,\n _textColor\n );\n\n const getStyles = useStyles<TreemapFactory>({\n name: 'Treemap',\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<TreemapFactory>({\n classNames,\n styles,\n props,\n });\n\n return (\n <Box {...getStyles('root')} {...others}>\n <ResponsiveContainer height={chartHeight}>\n <RechartsTreemap\n data={data as any}\n dataKey={dataKey as any}\n aspectRatio={aspectRatio}\n isAnimationActive={false}\n content={(nodeProps: any) => (\n <TreemapContent\n {...nodeProps}\n resolvedColors={resolvedColors}\n resolvedLabelColors={resolvedLabelColors}\n strokeWidth={strokeWidth!}\n />\n )}\n {...treemapProps}\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: resolvedColors[item.name as string] || '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 </RechartsTreemap>\n </ResponsiveContainer>\n </Box>\n );\n});\n\nTreemap.displayName = '@mantine/charts/Treemap';\nTreemap.classes = classes;\nTreemap.varsResolver = varsResolver;\n"],"mappings":";;;;;;;;AAgGA,MAAM,eAAe;CACnB,SAAS;CACT,aAAa;CACb,0BAA0B;CAC1B,QAAQ;CACR,aAAa;CACb,aAAa,MAAO,IAAI,KAAK,KAA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{"version":3,"file":"Treemap.mjs","names":["Treemap","RechartsTreemap","Tooltip","classes"],"sources":["../../src/Treemap/Treemap.tsx"],"sourcesContent":["import React from 'react';\nimport {\n Treemap as RechartsTreemap,\n TreemapProps as RechartsTreemapProps,\n ResponsiveContainer,\n Tooltip,\n TooltipProps,\n} from 'recharts';\nimport {\n Box,\n BoxProps,\n createVarsResolver,\n ElementProps,\n factory,\n Factory,\n getAutoContrastValue,\n getThemeColor,\n isLightColor,\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 './Treemap.module.css';\n\nexport interface TreemapData {\n name: string;\n value?: number;\n color?: MantineColor;\n children?: TreemapData[];\n [key: string]: unknown;\n}\n\nexport type TreemapStylesNames = 'root' | ChartTooltipStylesNames;\nexport type TreemapCssVariables = {\n root: '--chart-stroke-color' | '--chart-height';\n};\n\nexport interface TreemapProps\n extends BoxProps, StylesApiProps<TreemapFactory>, ElementProps<'div'> {\n /** Data used to render chart */\n data: TreemapData[];\n\n /** Key in data object for the value @default 'value' */\n dataKey?: string;\n\n /** The treemap will try to keep every single rectangle's aspect ratio near the aspectRatio given @default 1.618033988749895 */\n aspectRatio?: number;\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 `Treemap` component */\n treemapProps?: Partial<Omit<RechartsTreemapProps, 'ref' | 'data' | 'dataKey'>>;\n\n /** Controls color of the node stroke, by default depends on color scheme */\n strokeColor?: MantineColor;\n\n /** Controls text color of labels @default dimmed */\n textColor?: MantineColor;\n\n /** Controls chart height @default 300 */\n height?: number;\n\n /** Controls width of node stroke @default 1 */\n strokeWidth?: number;\n\n /** A function to format values inside the tooltip */\n valueFormatter?: (value: number) => string;\n\n /** Determines whether text color should be adjusted based on background color to improve contrast */\n autoContrast?: boolean;\n\n /** Additional elements rendered inside `Treemap` component */\n children?: React.ReactNode;\n}\n\nexport type TreemapFactory = Factory<{\n props: TreemapProps;\n ref: HTMLDivElement;\n stylesNames: TreemapStylesNames;\n vars: TreemapCssVariables;\n}>;\n\nconst defaultProps = {\n dataKey: 'value',\n withTooltip: true,\n tooltipAnimationDuration: 0,\n height: 300,\n strokeWidth: 1,\n aspectRatio: 0.5 * (1 + Math.sqrt(5)),\n} satisfies Partial<TreemapProps>;\n\nconst varsResolver = createVarsResolver<TreemapFactory>((theme, { strokeColor, height }) => ({\n root: {\n '--chart-stroke-color': strokeColor ? getThemeColor(strokeColor, theme) : undefined,\n '--chart-height': rem(height),\n },\n}));\n\ninterface TreemapContentProps {\n x: number;\n y: number;\n width: number;\n height: number;\n depth: number;\n name: string;\n resolvedColors: Record<string, string>;\n resolvedLabelColors: Record<string, string>;\n index: number;\n strokeWidth: number;\n}\n\nfunction TreemapContent({\n x,\n y,\n width,\n height,\n depth,\n name,\n resolvedColors,\n resolvedLabelColors,\n index,\n strokeWidth,\n}: TreemapContentProps) {\n const fill = resolvedColors[name] || `var(--mantine-color-blue-${(index % 9) + 1})`;\n const labelColor = resolvedLabelColors[name] || 'var(--mantine-color-white)';\n const showLabel = width > 30 && height > 20;\n\n return (\n <g>\n <rect\n x={x}\n y={y}\n width={width}\n height={height}\n fill={depth >= 1 ? fill : 'transparent'}\n stroke=\"var(--chart-stroke-color, var(--mantine-color-body))\"\n strokeWidth={depth >= 1 ? strokeWidth : 0}\n />\n {depth >= 1 && showLabel && (\n <text\n x={x + width / 2}\n y={y + height / 2}\n textAnchor=\"middle\"\n dominantBaseline=\"central\"\n fill={labelColor}\n fontSize={12}\n fontFamily=\"var(--mantine-font-family)\"\n >\n {name}\n </text>\n )}\n </g>\n );\n}\n\nfunction resolveColors(\n data: TreemapData[],\n theme: MantineTheme,\n parentColor?: string\n): Record<string, string> {\n const result: Record<string, string> = {};\n for (const item of data) {\n const color = item.color || parentColor;\n if (color) {\n result[item.name] = parseThemeColor({ color, theme }).value;\n }\n if (item.children) {\n Object.assign(result, resolveColors(item.children, theme, color));\n }\n }\n return result;\n}\n\nfunction resolveLabelColors(\n resolvedColors: Record<string, string>,\n autoContrast: boolean,\n luminanceThreshold: number,\n textColor?: string\n): Record<string, string> {\n const result: Record<string, string> = {};\n for (const [name, color] of Object.entries(resolvedColors)) {\n if (textColor) {\n result[name] = textColor;\n } else if (autoContrast) {\n result[name] = isLightColor(color, luminanceThreshold)\n ? 'var(--mantine-color-black)'\n : 'var(--mantine-color-white)';\n }\n }\n return result;\n}\n\nexport const Treemap = factory<TreemapFactory>((_props) => {\n const props = useProps('Treemap', defaultProps, _props);\n const {\n classNames,\n className,\n style,\n styles,\n unstyled,\n vars,\n data,\n dataKey,\n aspectRatio,\n withTooltip,\n tooltipAnimationDuration,\n tooltipProps,\n treemapProps,\n strokeColor,\n textColor,\n height: chartHeight,\n strokeWidth,\n valueFormatter,\n autoContrast,\n children,\n attributes,\n ...others\n } = props;\n\n const theme = useMantineTheme();\n const resolvedColors = resolveColors(data, theme);\n const _autoContrast = getAutoContrastValue(autoContrast, theme);\n const _textColor = textColor ? getThemeColor(textColor, theme) : undefined;\n const resolvedLabelColors = resolveLabelColors(\n resolvedColors,\n _autoContrast,\n theme.luminanceThreshold,\n _textColor\n );\n\n const getStyles = useStyles<TreemapFactory>({\n name: 'Treemap',\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<TreemapFactory>({\n classNames,\n styles,\n props,\n });\n\n return (\n <Box {...getStyles('root')} {...others}>\n <ResponsiveContainer height={chartHeight}>\n <RechartsTreemap\n data={data as any}\n dataKey={dataKey as any}\n aspectRatio={aspectRatio}\n isAnimationActive={false}\n content={(nodeProps: any) => (\n <TreemapContent\n {...nodeProps}\n resolvedColors={resolvedColors}\n resolvedLabelColors={resolvedLabelColors}\n strokeWidth={strokeWidth!}\n />\n )}\n {...treemapProps}\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: resolvedColors[item.name as string] || '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 </RechartsTreemap>\n </ResponsiveContainer>\n </Box>\n );\n});\n\nTreemap.displayName = '@mantine/charts/Treemap';\nTreemap.classes = classes;\nTreemap.varsResolver = varsResolver;\n"],"mappings":";;;;;;;;AAgGA,MAAM,eAAe;CACnB,SAAS;CACT,aAAa;CACb,0BAA0B;CAC1B,QAAQ;CACR,aAAa;CACb,aAAa,MAAO,IAAI,KAAK,KAAK,CAAC;AACrC;AAEA,MAAM,eAAe,oBAAoC,OAAO,EAAE,aAAa,cAAc,EAC3F,MAAM;CACJ,wBAAwB,cAAc,cAAc,aAAa,KAAK,IAAI,KAAA;CAC1E,kBAAkB,IAAI,MAAM;AAC9B,EACF,EAAE;AAeF,SAAS,eAAe,EACtB,GACA,GACA,OACA,QACA,OACA,MACA,gBACA,qBACA,OACA,eACsB;CACtB,MAAM,OAAO,eAAe,SAAS,4BAA6B,QAAQ,IAAK,EAAE;CACjF,MAAM,aAAa,oBAAoB,SAAS;CAGhD,OACE,qBAAC,KAAD,EAAA,UAAA,CACE,oBAAC,QAAD;EACK;EACA;EACI;EACC;EACR,MAAM,SAAS,IAAI,OAAO;EAC1B,QAAO;EACP,aAAa,SAAS,IAAI,cAAc;CACzC,CAAA,GACA,SAAS,KAbI,QAAQ,MAAM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EACA;CACF,CAAC;CAED,MAAM,EAAE,oBAAoB,mBAAmB,qBAAqC;EAClF;EACA;EACA;CACF,CAAC;CAED,OACE,oBAAC,KAAD;EAAK,GAAI,UAAU,MAAM;EAAG,GAAI;YAC9B,oBAAC,qBAAD;GAAqB,QAAQ;aAC3B,qBAACC,SAAD;IACQ;IACG;IACI;IACb,mBAAmB;IACnB,UAAU,cACR,oBAAC,gBAAD;KACE,GAAI;KACY;KACK;KACR;IACd,CAAA;IAEH,GAAI;cAbN,CAeG,eACC,oBAACC,WAAD;KACE,mBAAmB;KACnB,mBAAmB;KACnB,UAAU,EAAE,cACV,oBAAC,cAAD;MACE,SACE,SAAS,KAAK,UAAU;OACtB,MAAM,KAAK;OACX,OAAO,KAAK;OACZ,OAAO,eAAe,KAAK,SAAmB;MAChD,EAAE,KAAK,CAAC;MAEV,YAAY;MACZ,QAAQ;MACR,MAAK;MACW;MACJ;KACb,CAAA;KAEH,GAAI;IACL,CAAA,GAGF,QACc;;EACE,CAAA;CAClB,CAAA;AAET,CAAC;AAED,UAAQ,cAAc;AACtB,UAAQ,UAAUC;AAClB,UAAQ,eAAe"}
@@ -0,0 +1,18 @@
1
+ "use client";
2
+ import { getThemeColor } from "@mantine/core";
3
+ //#region packages/@mantine/charts/src/utils/get-pie-chart-data/get-pie-chart-data.ts
4
+ function getPieChartData({ data, theme, strokeWidth, highlightedIndex, cellProps }) {
5
+ return data.map((item, index) => ({
6
+ ...item,
7
+ __segmentIndex: index,
8
+ fill: getThemeColor(item.color, theme),
9
+ stroke: "var(--chart-stroke-color, var(--mantine-color-body))",
10
+ strokeWidth,
11
+ ...typeof cellProps === "function" ? cellProps(item) : cellProps,
12
+ ...highlightedIndex !== null ? { fillOpacity: highlightedIndex === index ? 1 : .2 } : null
13
+ }));
14
+ }
15
+ //#endregion
16
+ export { getPieChartData };
17
+
18
+ //# sourceMappingURL=get-pie-chart-data.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-pie-chart-data.mjs","names":[],"sources":["../../../src/utils/get-pie-chart-data/get-pie-chart-data.ts"],"sourcesContent":["import { getThemeColor, MantineColor, MantineTheme } from '@mantine/core';\n\ninterface PieChartDataItem {\n color: MantineColor;\n [key: string]: any;\n}\n\ninterface GetPieChartDataInput<T extends PieChartDataItem> {\n data: T[];\n theme: MantineTheme;\n strokeWidth: number | undefined;\n highlightedIndex: number | null;\n cellProps:\n | ((item: T) => Partial<Omit<React.SVGProps<SVGElement>, 'ref'>>)\n | Partial<Omit<React.SVGProps<SVGElement>, 'ref'>>\n | undefined;\n}\n\nexport function getPieChartData<T extends PieChartDataItem>({\n data,\n theme,\n strokeWidth,\n highlightedIndex,\n cellProps,\n}: GetPieChartDataInput<T>) {\n return data.map((item, index) => ({\n ...item,\n __segmentIndex: index,\n fill: getThemeColor(item.color, theme),\n stroke: 'var(--chart-stroke-color, var(--mantine-color-body))',\n strokeWidth,\n ...(typeof cellProps === 'function' ? cellProps(item) : cellProps),\n ...(highlightedIndex !== null ? { fillOpacity: highlightedIndex === index ? 1 : 0.2 } : null),\n }));\n}\n"],"mappings":";;;AAkBA,SAAgB,gBAA4C,EAC1D,MACA,OACA,aACA,kBACA,aAC0B;CAC1B,OAAO,KAAK,KAAK,MAAM,WAAW;EAChC,GAAG;EACH,gBAAgB;EAChB,MAAM,cAAc,KAAK,OAAO,KAAK;EACrC,QAAQ;EACR;EACA,GAAI,OAAO,cAAc,aAAa,UAAU,IAAI,IAAI;EACxD,GAAI,qBAAqB,OAAO,EAAE,aAAa,qBAAqB,QAAQ,IAAI,GAAI,IAAI;CAC1F,EAAE;AACJ"}
@@ -1,12 +1,12 @@
1
1
  import { BoxProps, ElementProps, Factory, StylesApiProps } from '@mantine/core';
2
2
  import { ChartSeries } from '../types';
3
- export declare function getFilteredChartLegendPayload(payload: readonly Record<string, any>[]): Record<string, any>[];
3
+ export declare function getFilteredChartLegendPayload(payload: readonly Record<string, any>[], splitNestedKeys?: boolean): Record<string, any>[];
4
4
  export type ChartLegendStylesNames = 'legendItem' | 'legendItemColor' | 'legendItemName' | 'legend';
5
5
  export interface ChartLegendProps extends BoxProps, StylesApiProps<ChartLegendFactory>, ElementProps<'div'> {
6
6
  /** Chart data provided by recharts */
7
7
  payload: readonly Record<string, any>[] | undefined;
8
8
  /** Function called when mouse enters/leaves one of the legend items */
9
- onHighlight: (area: string | null) => void;
9
+ onHighlight: (area: string | number | null) => void;
10
10
  /** Position of the legend relative to the chart, used to apply margin on the corresponding side */
11
11
  legendPosition: 'top' | 'bottom' | 'middle';
12
12
  /** Data used for labels, only applicable for area charts: AreaChart, LineChart, BarChart */
@@ -1,6 +1,6 @@
1
1
  import { BoxProps, ElementProps, Factory, StylesApiProps } from '@mantine/core';
2
2
  import { ChartSeries } from '../types';
3
- export declare function getFilteredChartTooltipPayload(payload: readonly Record<string, any>[] | Record<string, any>[], segmentId?: string): Record<string, any>[];
3
+ export declare function getFilteredChartTooltipPayload(payload: readonly Record<string, any>[] | Record<string, any>[], segmentId?: string | number): Record<string, any>[];
4
4
  export type ChartTooltipStylesNames = 'tooltip' | 'tooltipItem' | 'tooltipItemBody' | 'tooltipItemColor' | 'tooltipItemName' | 'tooltipItemData' | 'tooltipLabel' | 'tooltipBody';
5
5
  export interface ChartTooltipProps extends BoxProps, StylesApiProps<ChartTooltipFactory>, ElementProps<'div'> {
6
6
  /** Main tooltip label */
@@ -11,8 +11,8 @@ export interface ChartTooltipProps extends BoxProps, StylesApiProps<ChartTooltip
11
11
  unit?: string;
12
12
  /** Tooltip type that determines the content and styles, `area` for LineChart, AreaChart and BarChart, `radial` for DonutChart and PieChart @default 'area' */
13
13
  type?: 'area' | 'radial' | 'scatter';
14
- /** Id of the segment to display data for. Only applicable when `type="radial"`. If not set, all data is rendered. */
15
- segmentId?: string;
14
+ /** Segment to display data for, identified by its index in the data array (preferred, isolates duplicate names) or by its name. Only applicable when `type="radial"`. If not set, all data is rendered. */
15
+ segmentId?: string | number;
16
16
  /** Chart series data, applicable only for `area` type */
17
17
  series?: ChartSeries[];
18
18
  /** A function to format values */
@@ -1,12 +1,13 @@
1
- import { PieProps, PieChart as ReChartsPieChart, TooltipProps } from 'recharts';
1
+ import { LegendProps, PieProps, PieChart as ReChartsPieChart, TooltipProps } from 'recharts';
2
2
  import { BoxProps, ElementProps, Factory, MantineColor, StylesApiProps } from '@mantine/core';
3
+ import { ChartLegendStylesNames } from '../ChartLegend';
3
4
  import { ChartTooltipStylesNames } from '../ChartTooltip/ChartTooltip';
4
5
  export interface DonutChartCell {
5
6
  name: string;
6
7
  value: number;
7
8
  color: MantineColor;
8
9
  }
9
- export type DonutChartStylesNames = 'root' | 'label' | ChartTooltipStylesNames;
10
+ export type DonutChartStylesNames = 'root' | 'label' | ChartTooltipStylesNames | ChartLegendStylesNames;
10
11
  export type DonutChartCssVariables = {
11
12
  root: '--chart-stroke-color' | '--chart-labels-color' | '--chart-size';
12
13
  };
@@ -15,6 +16,10 @@ export interface DonutChartProps extends BoxProps, StylesApiProps<DonutChartFact
15
16
  data: DonutChartCell[];
16
17
  /** Determines whether the tooltip should be displayed when one of the section is hovered @default true */
17
18
  withTooltip?: boolean;
19
+ /** Determines whether the legend should be displayed @default false */
20
+ withLegend?: boolean;
21
+ /** Props passed down to recharts `Legend` component */
22
+ legendProps?: Omit<LegendProps, 'ref'>;
18
23
  /** Tooltip animation duration in ms @default 0 */
19
24
  tooltipAnimationDuration?: number;
20
25
  /** Props passed down to `Tooltip` recharts component */
@@ -1,5 +1,6 @@
1
- import { FunnelProps, FunnelChart as RechartsFunnelChart, TooltipProps } from 'recharts';
1
+ import { FunnelProps, LegendProps, FunnelChart as RechartsFunnelChart, TooltipProps } from 'recharts';
2
2
  import { BoxProps, ElementProps, Factory, MantineColor, StylesApiProps } from '@mantine/core';
3
+ import { ChartLegendStylesNames } from '../ChartLegend';
3
4
  import { ChartTooltipStylesNames } from '../ChartTooltip/ChartTooltip';
4
5
  export interface FunnelChartCell {
5
6
  key?: string | number;
@@ -7,7 +8,7 @@ export interface FunnelChartCell {
7
8
  value: number;
8
9
  color: MantineColor;
9
10
  }
10
- export type FunnelChartStylesNames = 'root' | ChartTooltipStylesNames;
11
+ export type FunnelChartStylesNames = 'root' | ChartTooltipStylesNames | ChartLegendStylesNames;
11
12
  export type FunnelChartCssVariables = {
12
13
  root: '--chart-stroke-color' | '--chart-labels-color' | '--chart-size';
13
14
  };
@@ -16,6 +17,10 @@ export interface FunnelChartProps extends BoxProps, StylesApiProps<FunnelChartFa
16
17
  data: FunnelChartCell[];
17
18
  /** Determines whether the tooltip should be displayed when a section is hovered @default true */
18
19
  withTooltip?: boolean;
20
+ /** Determines whether the legend should be displayed @default false */
21
+ withLegend?: boolean;
22
+ /** Props passed down to recharts `Legend` component */
23
+ legendProps?: Omit<LegendProps, 'ref'>;
19
24
  /** Tooltip animation duration in ms @default 0 */
20
25
  tooltipAnimationDuration?: number;
21
26
  /** Props passed down to `Tooltip` recharts component */
@@ -1,5 +1,6 @@
1
- import { PieProps, PieChart as ReChartsPieChart, TooltipProps } from 'recharts';
1
+ import { LegendProps, PieProps, PieChart as ReChartsPieChart, TooltipProps } from 'recharts';
2
2
  import { BoxProps, ElementProps, Factory, MantineColor, StylesApiProps } from '@mantine/core';
3
+ import { ChartLegendStylesNames } from '../ChartLegend';
3
4
  import { ChartTooltipStylesNames } from '../ChartTooltip/ChartTooltip';
4
5
  export interface PieChartCell {
5
6
  key?: string | number;
@@ -7,7 +8,7 @@ export interface PieChartCell {
7
8
  value: number;
8
9
  color: MantineColor;
9
10
  }
10
- export type PieChartStylesNames = 'root' | ChartTooltipStylesNames;
11
+ export type PieChartStylesNames = 'root' | ChartTooltipStylesNames | ChartLegendStylesNames;
11
12
  export type PieChartCssVariables = {
12
13
  root: '--chart-stroke-color' | '--chart-labels-color' | '--chart-size';
13
14
  };
@@ -16,6 +17,10 @@ export interface PieChartProps extends BoxProps, StylesApiProps<PieChartFactory>
16
17
  data: PieChartCell[];
17
18
  /** Determines whether the tooltip should be displayed when one of the section is hovered @default true */
18
19
  withTooltip?: boolean;
20
+ /** Determines whether the legend should be displayed @default false */
21
+ withLegend?: boolean;
22
+ /** Props passed down to recharts `Legend` component */
23
+ legendProps?: Omit<LegendProps, 'ref'>;
19
24
  /** Tooltip animation duration in ms @default 0 */
20
25
  tooltipAnimationDuration?: number;
21
26
  /** Props passed down to `Tooltip` recharts component */