@mantine/charts 9.0.0-alpha.6 → 9.0.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.
- package/README.md +2 -2
- package/cjs/AreaChart/AreaChart.cjs +1 -0
- package/cjs/AreaChart/AreaChart.cjs.map +1 -1
- package/cjs/AreaChart/AreaGradient.cjs +1 -0
- package/cjs/AreaChart/AreaGradient.cjs.map +1 -1
- package/cjs/AreaChart/AreaSplit.cjs +1 -0
- package/cjs/AreaChart/AreaSplit.cjs.map +1 -1
- package/cjs/BarChart/BarChart.cjs +21 -4
- package/cjs/BarChart/BarChart.cjs.map +1 -1
- package/cjs/BarsList/BarsList.cjs +1 -0
- package/cjs/BarsList/BarsList.cjs.map +1 -1
- package/cjs/BubbleChart/BubbleChart.cjs +1 -0
- package/cjs/BubbleChart/BubbleChart.cjs.map +1 -1
- package/cjs/ChartLegend/ChartLegend.cjs +1 -0
- package/cjs/ChartLegend/ChartLegend.cjs.map +1 -1
- package/cjs/ChartTooltip/ChartTooltip.cjs +1 -0
- package/cjs/ChartTooltip/ChartTooltip.cjs.map +1 -1
- package/cjs/CompositeChart/CompositeChart.cjs +1 -0
- package/cjs/CompositeChart/CompositeChart.cjs.map +1 -1
- package/cjs/DonutChart/DonutChart.cjs +6 -5
- package/cjs/DonutChart/DonutChart.cjs.map +1 -1
- package/cjs/FunnelChart/FunnelChart.cjs +9 -9
- package/cjs/FunnelChart/FunnelChart.cjs.map +1 -1
- package/cjs/Heatmap/Heatmap.cjs +1 -0
- package/cjs/Heatmap/Heatmap.cjs.map +1 -1
- package/cjs/Heatmap/HeatmapSplitWeeks.cjs +1 -0
- package/cjs/Heatmap/HeatmapSplitWeeks.cjs.map +1 -1
- package/cjs/Heatmap/HeatmapWeeks.cjs +1 -0
- package/cjs/Heatmap/HeatmapWeeks.cjs.map +1 -1
- package/cjs/Heatmap/get-heat-color/get-heat-color.cjs +1 -1
- package/cjs/Heatmap/get-heat-color/get-heat-color.cjs.map +1 -1
- package/cjs/LineChart/LineChart.cjs +1 -0
- package/cjs/LineChart/LineChart.cjs.map +1 -1
- package/cjs/PieChart/PieChart.cjs +6 -5
- package/cjs/PieChart/PieChart.cjs.map +1 -1
- package/cjs/PointLabel/PointLabel.cjs +1 -0
- package/cjs/PointLabel/PointLabel.cjs.map +1 -1
- package/cjs/RadarChart/RadarChart.cjs +1 -0
- package/cjs/RadarChart/RadarChart.cjs.map +1 -1
- package/cjs/RadialBarChart/RadialBarChart.cjs +1 -0
- package/cjs/RadialBarChart/RadialBarChart.cjs.map +1 -1
- package/cjs/ScatterChart/ScatterChart.cjs +1 -0
- package/cjs/ScatterChart/ScatterChart.cjs.map +1 -1
- package/cjs/Sparkline/Sparkline.cjs +1 -0
- package/cjs/Sparkline/Sparkline.cjs.map +1 -1
- package/esm/BarChart/BarChart.mjs +21 -6
- package/esm/BarChart/BarChart.mjs.map +1 -1
- package/esm/DonutChart/DonutChart.mjs +6 -6
- package/esm/DonutChart/DonutChart.mjs.map +1 -1
- package/esm/FunnelChart/FunnelChart.mjs +9 -10
- package/esm/FunnelChart/FunnelChart.mjs.map +1 -1
- package/esm/Heatmap/get-heat-color/get-heat-color.mjs +1 -1
- package/esm/Heatmap/get-heat-color/get-heat-color.mjs.map +1 -1
- package/esm/PieChart/PieChart.mjs +6 -6
- package/esm/PieChart/PieChart.mjs.map +1 -1
- package/lib/BarChart/BarChart.d.ts +1 -0
- package/lib/DonutChart/DonutChart.d.ts +3 -3
- package/lib/PieChart/PieChart.d.ts +3 -3
- package/package.json +3 -3
- package/cjs/SankeyChart/SankeyChart.cjs +0 -202
- package/cjs/SankeyChart/SankeyChart.cjs.map +0 -1
- package/cjs/SankeyChart/SankeyChart.module.cjs +0 -7
- package/cjs/SankeyChart/SankeyChart.module.cjs.map +0 -1
- package/cjs/Treemap/Treemap.cjs +0 -133
- package/cjs/Treemap/Treemap.cjs.map +0 -1
- package/cjs/Treemap/Treemap.module.cjs +0 -7
- package/cjs/Treemap/Treemap.module.cjs.map +0 -1
- package/esm/SankeyChart/SankeyChart.mjs +0 -200
- package/esm/SankeyChart/SankeyChart.mjs.map +0 -1
- package/esm/SankeyChart/SankeyChart.module.mjs +0 -7
- package/esm/SankeyChart/SankeyChart.module.mjs.map +0 -1
- package/esm/Treemap/Treemap.mjs +0 -131
- package/esm/Treemap/Treemap.mjs.map +0 -1
- package/esm/Treemap/Treemap.module.mjs +0 -7
- package/esm/Treemap/Treemap.module.mjs.map +0 -1
- package/lib/SankeyChart/SankeyChart.d.ts +0 -71
- package/lib/SankeyChart/index.d.ts +0 -12
- package/lib/Treemap/Treemap.d.ts +0 -57
- package/lib/Treemap/index.d.ts +0 -10
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DonutChart.mjs","names":["ReChartsPieChart","Tooltip","classes"],"sources":["../../src/DonutChart/DonutChart.tsx"],"sourcesContent":["import {\n Cell,\n CellProps,\n Pie,\n PieLabel,\n PieProps,\n PieChart as ReChartsPieChart,\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 rem,\n StylesApiProps,\n useMantineTheme,\n useProps,\n useResolvedStylesApi,\n useStyles,\n} from '@mantine/core';\nimport { ChartTooltip, ChartTooltipStylesNames } from '../ChartTooltip/ChartTooltip';\nimport classes from './DonutChart.module.css';\n\nexport interface DonutChartCell {\n name: string;\n value: number;\n color: MantineColor;\n}\n\nexport type DonutChartStylesNames = 'root' | 'label' | ChartTooltipStylesNames;\nexport type DonutChartCssVariables = {\n root: '--chart-stroke-color' | '--chart-labels-color' | '--chart-size';\n};\n\nexport interface DonutChartProps\n extends BoxProps, StylesApiProps<DonutChartFactory>, ElementProps<'div'> {\n /** Data used to render chart */\n data: DonutChartCell[];\n\n /** Determines whether the tooltip should be displayed when one of the section 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 `Pie` component */\n pieProps?: Partial<Omit<PieProps, 'ref'>>;\n\n /** Controls color of the segments stroke, by default depends on color scheme */\n strokeColor?: MantineColor;\n\n /** Controls text color of all labels, by default depends on color scheme */\n labelColor?: MantineColor;\n\n /** Controls padding between segments @default 0 */\n paddingAngle?: number;\n\n /** Determines whether each segment should have associated label @default false */\n withLabels?: boolean;\n\n /** Determines whether segments labels should have lines that connect the segment with the label @default true */\n withLabelsLine?: boolean;\n\n /** Controls thickness of the chart segments @default 20 */\n thickness?: number;\n\n /** Controls chart width and height, height is increased by 40 if `withLabels` prop is set. Cannot be less than `thickness`. @default 80 */\n size?: number;\n\n /** Controls width of segments stroke @default 1 */\n strokeWidth?: number;\n\n /** Controls angle at which chart starts. Set to `180` to render the chart as semicircle. @default 0 */\n startAngle?: number;\n\n /** Controls angle at which charts ends. Set to `0` to render the chart as semicircle. @default 360 */\n endAngle?: number;\n\n /** Determines which data is displayed in the tooltip. `'all'` – display all values, `'segment'` – display only hovered segment. @default 'all' */\n tooltipDataSource?: 'segment' | 'all';\n\n /** Chart label, displayed in the center of the chart */\n chartLabel?: string | number;\n\n /** Additional elements rendered inside `PieChart` component */\n children?: React.ReactNode;\n\n /** Props passed down to recharts `PieChart` component */\n pieChartProps?: React.ComponentProps<typeof ReChartsPieChart>;\n\n /** Type of labels to display, `'value'` by default */\n labelsType?: 'value' | 'percent';\n\n /** A function to format values inside the tooltip */\n valueFormatter?: (value: number) => string;\n\n /** Props passed down to recharts `Cell` component */\n cellProps?:\n | ((series: DonutChartCell) => Partial<Omit<CellProps, 'ref'>>)\n | Partial<Omit<CellProps, 'ref'>>;\n}\n\nexport type DonutChartFactory = Factory<{\n props: DonutChartProps;\n ref: HTMLDivElement;\n stylesNames: DonutChartStylesNames;\n vars: DonutChartCssVariables;\n}>;\n\nconst defaultProps = {\n withTooltip: true,\n withLabelsLine: true,\n paddingAngle: 0,\n thickness: 20,\n size: 160,\n strokeWidth: 1,\n startAngle: 0,\n endAngle: 360,\n labelsType: 'value',\n tooltipDataSource: 'all',\n} satisfies Partial<DonutChartProps>;\n\nconst varsResolver = createVarsResolver<DonutChartFactory>(\n (theme, { strokeColor, labelColor, withLabels, size }) => ({\n root: {\n '--chart-stroke-color': strokeColor ? getThemeColor(strokeColor, theme) : undefined,\n '--chart-labels-color': labelColor ? getThemeColor(labelColor, theme) : undefined,\n '--chart-size': withLabels ? rem(size! + 80) : rem(size),\n },\n })\n);\n\nconst getLabelValue = (\n labelsType: DonutChartProps['labelsType'],\n value: number | undefined,\n percent: number | undefined,\n valueFormatter?: DonutChartProps['valueFormatter']\n) => {\n if (labelsType === 'percent') {\n return `${((percent || 0) * 100).toFixed(0)}%`;\n }\n\n if (typeof valueFormatter === 'function') {\n return valueFormatter(value || 0);\n }\n\n return value;\n};\n\nconst getLabel =\n (labelsType: 'value' | 'percent', valueFormatter?: DonutChartProps['valueFormatter']): PieLabel =>\n ({ x, y, cx, cy, percent, value }) => (\n <text\n x={x}\n y={y}\n cx={cx}\n cy={cy}\n textAnchor={x > Number(cx) ? 'start' : 'end'}\n fill=\"var(--chart-labels-color, var(--mantine-color-dimmed))\"\n fontFamily=\"var(--mantine-font-family)\"\n fontSize={12}\n >\n <tspan x={x}>\n {getLabelValue(labelsType, Number(value), Number(percent), valueFormatter)}\n </tspan>\n </text>\n );\n\nexport const DonutChart = factory<DonutChartFactory>((_props) => {\n const props = useProps('DonutChart', defaultProps, _props);\n const {\n classNames,\n className,\n style,\n styles,\n unstyled,\n vars,\n data,\n withTooltip,\n tooltipAnimationDuration,\n tooltipProps,\n pieProps,\n paddingAngle,\n withLabels,\n withLabelsLine,\n size,\n thickness,\n strokeWidth,\n startAngle,\n endAngle,\n tooltipDataSource,\n chartLabel,\n children,\n pieChartProps,\n valueFormatter,\n strokeColor,\n labelsType,\n attributes,\n cellProps,\n ...others\n } = props;\n\n const theme = useMantineTheme();\n\n const getStyles = useStyles<DonutChartFactory>({\n name: 'DonutChart',\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<DonutChartFactory>({\n classNames,\n styles,\n props,\n });\n\n const cells = data.map((item, index) => (\n <Cell\n key={index}\n fill={getThemeColor(item.color, theme)}\n stroke=\"var(--chart-stroke-color, var(--mantine-color-body))\"\n strokeWidth={strokeWidth}\n {...(typeof cellProps === 'function' ? cellProps(item) : cellProps)}\n />\n ));\n\n return (\n <Box size={size} {...getStyles('root')} {...others}>\n <ResponsiveContainer>\n <ReChartsPieChart {...pieChartProps}>\n <Pie\n data={data as any}\n innerRadius={size / 2 - thickness}\n outerRadius={size / 2}\n dataKey=\"value\"\n isAnimationActive={false}\n paddingAngle={paddingAngle}\n startAngle={startAngle}\n endAngle={endAngle}\n label={withLabels ? getLabel(labelsType || 'value', valueFormatter) : false}\n labelLine={\n withLabelsLine\n ? {\n stroke: 'var(--chart-label-color, var(--mantine-color-dimmed))',\n strokeWidth: 1,\n }\n : false\n }\n {...pieProps}\n >\n {cells}\n </Pie>\n\n {chartLabel && (\n <text\n x=\"50%\"\n y=\"50%\"\n textAnchor=\"middle\"\n dominantBaseline=\"middle\"\n {...getStyles('label')}\n >\n {chartLabel}\n </text>\n )}\n\n {withTooltip && (\n <Tooltip\n animationDuration={tooltipAnimationDuration}\n isAnimationActive={false}\n content={({ payload }) => (\n <ChartTooltip\n payload={data}\n classNames={resolvedClassNames}\n styles={resolvedStyles}\n type=\"radial\"\n segmentId={\n tooltipDataSource === 'segment' ? (payload?.[0]?.name as string) : undefined\n }\n valueFormatter={valueFormatter}\n attributes={attributes}\n />\n )}\n {...tooltipProps}\n />\n )}\n\n {children}\n </ReChartsPieChart>\n </ResponsiveContainer>\n </Box>\n );\n});\n\nDonutChart.displayName = '@mantine/charts/DonutChart';\nDonutChart.classes = classes;\nDonutChart.varsResolver = varsResolver;\n"],"mappings":";;;;;;;AAuHA,MAAM,eAAe;CACnB,aAAa;CACb,gBAAgB;CAChB,cAAc;CACd,WAAW;CACX,MAAM;CACN,aAAa;CACb,YAAY;CACZ,UAAU;CACV,YAAY;CACZ,mBAAmB;CACpB;AAED,MAAM,eAAe,oBAClB,OAAO,EAAE,aAAa,YAAY,YAAY,YAAY,EACzD,MAAM;CACJ,wBAAwB,cAAc,cAAc,aAAa,MAAM,GAAG,KAAA;CAC1E,wBAAwB,aAAa,cAAc,YAAY,MAAM,GAAG,KAAA;CACxE,gBAAgB,aAAa,IAAI,OAAQ,GAAG,GAAG,IAAI,KAAK;CACzD,EACF,EACF;AAED,MAAM,iBACJ,YACA,OACA,SACA,mBACG;AACH,KAAI,eAAe,UACjB,QAAO,KAAK,WAAW,KAAK,KAAK,QAAQ,EAAE,CAAC;AAG9C,KAAI,OAAO,mBAAmB,WAC5B,QAAO,eAAe,SAAS,EAAE;AAGnC,QAAO;;AAGT,MAAM,YACH,YAAiC,oBACjC,EAAE,GAAG,GAAG,IAAI,IAAI,SAAS,YACxB,oBAAC,QAAD;CACK;CACA;CACC;CACA;CACJ,YAAY,IAAI,OAAO,GAAG,GAAG,UAAU;CACvC,MAAK;CACL,YAAW;CACX,UAAU;WAEV,oBAAC,SAAD;EAAU;YACP,cAAc,YAAY,OAAO,MAAM,EAAE,OAAO,QAAQ,EAAE,eAAe;EACpE,CAAA;CACH,CAAA;AAGX,MAAa,aAAa,SAA4B,WAAW;CAC/D,MAAM,QAAQ,SAAS,cAAc,cAAc,OAAO;CAC1D,MAAM,EACJ,YACA,WACA,OACA,QACA,UACA,MACA,MACA,aACA,0BACA,cACA,UACA,cACA,YACA,gBACA,MACA,WACA,aACA,YACA,UACA,mBACA,YACA,UACA,eACA,gBACA,aACA,YACA,YACA,WACA,GAAG,WACD;CAEJ,MAAM,QAAQ,iBAAiB;CAE/B,MAAM,YAAY,UAA6B;EAC7C,MAAM;EACN,SAAA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACD,CAAC;CAEF,MAAM,EAAE,oBAAoB,mBAAmB,qBAAwC;EACrF;EACA;EACA;EACD,CAAC;CAEF,MAAM,QAAQ,KAAK,KAAK,MAAM,UAC5B,oBAAC,MAAD;EAEE,MAAM,cAAc,KAAK,OAAO,MAAM;EACtC,QAAO;EACM;EACb,GAAK,OAAO,cAAc,aAAa,UAAU,KAAK,GAAG;EACzD,EALK,MAKL,CACF;AAEF,QACE,oBAAC,KAAD;EAAW;EAAM,GAAI,UAAU,OAAO;EAAE,GAAI;YAC1C,oBAAC,qBAAD,EAAA,UACE,qBAACA,UAAD;GAAkB,GAAI;aAAtB;IACE,oBAAC,KAAD;KACQ;KACN,aAAa,OAAO,IAAI;KACxB,aAAa,OAAO;KACpB,SAAQ;KACR,mBAAmB;KACL;KACF;KACF;KACV,OAAO,aAAa,SAAS,cAAc,SAAS,eAAe,GAAG;KACtE,WACE,iBACI;MACE,QAAQ;MACR,aAAa;MACd,GACD;KAEN,GAAI;eAEH;KACG,CAAA;IAEL,cACC,oBAAC,QAAD;KACE,GAAE;KACF,GAAE;KACF,YAAW;KACX,kBAAiB;KACjB,GAAI,UAAU,QAAQ;eAErB;KACI,CAAA;IAGR,eACC,oBAACC,WAAD;KACE,mBAAmB;KACnB,mBAAmB;KACnB,UAAU,EAAE,cACV,oBAAC,cAAD;MACE,SAAS;MACT,YAAY;MACZ,QAAQ;MACR,MAAK;MACL,WACE,sBAAsB,YAAa,UAAU,IAAI,OAAkB,KAAA;MAErD;MACJ;MACZ,CAAA;KAEJ,GAAI;KACJ,CAAA;IAGH;IACgB;MACC,CAAA;EAClB,CAAA;EAER;AAEF,WAAW,cAAc;AACzB,WAAW,UAAUC;AACrB,WAAW,eAAe"}
|
|
1
|
+
{"version":3,"file":"DonutChart.mjs","names":["ReChartsPieChart","Tooltip","classes"],"sources":["../../src/DonutChart/DonutChart.tsx"],"sourcesContent":["import {\n Pie,\n PieLabel,\n PieProps,\n PieChart as ReChartsPieChart,\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 rem,\n StylesApiProps,\n useMantineTheme,\n useProps,\n useResolvedStylesApi,\n useStyles,\n} from '@mantine/core';\nimport { ChartTooltip, ChartTooltipStylesNames } from '../ChartTooltip/ChartTooltip';\nimport classes from './DonutChart.module.css';\n\nexport interface DonutChartCell {\n name: string;\n value: number;\n color: MantineColor;\n}\n\nexport type DonutChartStylesNames = 'root' | 'label' | ChartTooltipStylesNames;\nexport type DonutChartCssVariables = {\n root: '--chart-stroke-color' | '--chart-labels-color' | '--chart-size';\n};\n\nexport interface DonutChartProps\n extends BoxProps, StylesApiProps<DonutChartFactory>, ElementProps<'div'> {\n /** Data used to render chart */\n data: DonutChartCell[];\n\n /** Determines whether the tooltip should be displayed when one of the section 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 `Pie` component */\n pieProps?: Partial<Omit<PieProps, 'ref'>>;\n\n /** Controls color of the segments stroke, by default depends on color scheme */\n strokeColor?: MantineColor;\n\n /** Controls text color of all labels, by default depends on color scheme */\n labelColor?: MantineColor;\n\n /** Controls padding between segments @default 0 */\n paddingAngle?: number;\n\n /** Determines whether each segment should have associated label @default false */\n withLabels?: boolean;\n\n /** Determines whether segments labels should have lines that connect the segment with the label @default true */\n withLabelsLine?: boolean;\n\n /** Controls thickness of the chart segments @default 20 */\n thickness?: number;\n\n /** Controls chart width and height, height is increased by 40 if `withLabels` prop is set. Cannot be less than `thickness`. @default 80 */\n size?: number;\n\n /** Controls width of segments stroke @default 1 */\n strokeWidth?: number;\n\n /** Controls angle at which chart starts. Set to `180` to render the chart as semicircle. @default 0 */\n startAngle?: number;\n\n /** Controls angle at which charts ends. Set to `0` to render the chart as semicircle. @default 360 */\n endAngle?: number;\n\n /** Determines which data is displayed in the tooltip. `'all'` – display all values, `'segment'` – display only hovered segment. @default 'all' */\n tooltipDataSource?: 'segment' | 'all';\n\n /** Chart label, displayed in the center of the chart */\n chartLabel?: string | number;\n\n /** Additional elements rendered inside `PieChart` component */\n children?: React.ReactNode;\n\n /** Props passed down to recharts `PieChart` component */\n pieChartProps?: React.ComponentProps<typeof ReChartsPieChart>;\n\n /** Type of labels to display, `'value'` by default */\n labelsType?: 'value' | 'percent';\n\n /** A function to format values inside the tooltip */\n valueFormatter?: (value: number) => string;\n\n /** Props passed down to each segment of the chart */\n cellProps?:\n | ((series: DonutChartCell) => Partial<Omit<React.SVGProps<SVGElement>, 'ref'>>)\n | Partial<Omit<React.SVGProps<SVGElement>, 'ref'>>;\n}\n\nexport type DonutChartFactory = Factory<{\n props: DonutChartProps;\n ref: HTMLDivElement;\n stylesNames: DonutChartStylesNames;\n vars: DonutChartCssVariables;\n}>;\n\nconst defaultProps = {\n withTooltip: true,\n withLabelsLine: true,\n paddingAngle: 0,\n thickness: 20,\n size: 160,\n strokeWidth: 1,\n startAngle: 0,\n endAngle: 360,\n labelsType: 'value',\n tooltipDataSource: 'all',\n} satisfies Partial<DonutChartProps>;\n\nconst varsResolver = createVarsResolver<DonutChartFactory>(\n (theme, { strokeColor, labelColor, withLabels, size }) => ({\n root: {\n '--chart-stroke-color': strokeColor ? getThemeColor(strokeColor, theme) : undefined,\n '--chart-labels-color': labelColor ? getThemeColor(labelColor, theme) : undefined,\n '--chart-size': withLabels ? rem(size! + 80) : rem(size),\n },\n })\n);\n\nconst getLabelValue = (\n labelsType: DonutChartProps['labelsType'],\n value: number | undefined,\n percent: number | undefined,\n valueFormatter?: DonutChartProps['valueFormatter']\n) => {\n if (labelsType === 'percent') {\n return `${((percent || 0) * 100).toFixed(0)}%`;\n }\n\n if (typeof valueFormatter === 'function') {\n return valueFormatter(value || 0);\n }\n\n return value;\n};\n\nconst getLabel =\n (labelsType: 'value' | 'percent', valueFormatter?: DonutChartProps['valueFormatter']): PieLabel =>\n ({ x, y, cx, cy, percent, value }) => (\n <text\n x={x}\n y={y}\n cx={cx}\n cy={cy}\n textAnchor={x > Number(cx) ? 'start' : 'end'}\n fill=\"var(--chart-labels-color, var(--mantine-color-dimmed))\"\n fontFamily=\"var(--mantine-font-family)\"\n fontSize={12}\n >\n <tspan x={x}>\n {getLabelValue(labelsType, Number(value), Number(percent), valueFormatter)}\n </tspan>\n </text>\n );\n\nexport const DonutChart = factory<DonutChartFactory>((_props) => {\n const props = useProps('DonutChart', defaultProps, _props);\n const {\n classNames,\n className,\n style,\n styles,\n unstyled,\n vars,\n data,\n withTooltip,\n tooltipAnimationDuration,\n tooltipProps,\n pieProps,\n paddingAngle,\n withLabels,\n withLabelsLine,\n size,\n thickness,\n strokeWidth,\n startAngle,\n endAngle,\n tooltipDataSource,\n chartLabel,\n children,\n pieChartProps,\n valueFormatter,\n strokeColor,\n labelsType,\n attributes,\n cellProps,\n ...others\n } = props;\n\n const theme = useMantineTheme();\n\n const getStyles = useStyles<DonutChartFactory>({\n name: 'DonutChart',\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<DonutChartFactory>({\n classNames,\n styles,\n props,\n });\n\n const pieData = data.map((item) => ({\n ...item,\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 }));\n\n return (\n <Box size={size} {...getStyles('root')} {...others}>\n <ResponsiveContainer>\n <ReChartsPieChart {...pieChartProps}>\n <Pie\n data={pieData as any}\n innerRadius={size / 2 - thickness}\n outerRadius={size / 2}\n dataKey=\"value\"\n isAnimationActive={false}\n paddingAngle={paddingAngle}\n startAngle={startAngle}\n endAngle={endAngle}\n label={withLabels ? getLabel(labelsType || 'value', valueFormatter) : false}\n labelLine={\n withLabelsLine\n ? {\n stroke: 'var(--chart-label-color, var(--mantine-color-dimmed))',\n strokeWidth: 1,\n }\n : false\n }\n {...pieProps}\n />\n\n {chartLabel && (\n <text\n x=\"50%\"\n y=\"50%\"\n textAnchor=\"middle\"\n dominantBaseline=\"middle\"\n {...getStyles('label')}\n >\n {chartLabel}\n </text>\n )}\n\n {withTooltip && (\n <Tooltip\n animationDuration={tooltipAnimationDuration}\n isAnimationActive={false}\n content={({ payload }) => (\n <ChartTooltip\n payload={data}\n classNames={resolvedClassNames}\n styles={resolvedStyles}\n type=\"radial\"\n segmentId={\n tooltipDataSource === 'segment' ? (payload?.[0]?.name as string) : undefined\n }\n valueFormatter={valueFormatter}\n attributes={attributes}\n />\n )}\n {...tooltipProps}\n />\n )}\n\n {children}\n </ReChartsPieChart>\n </ResponsiveContainer>\n </Box>\n );\n});\n\nDonutChart.displayName = '@mantine/charts/DonutChart';\nDonutChart.classes = classes;\nDonutChart.varsResolver = varsResolver;\n"],"mappings":";;;;;;;AAqHA,MAAM,eAAe;CACnB,aAAa;CACb,gBAAgB;CAChB,cAAc;CACd,WAAW;CACX,MAAM;CACN,aAAa;CACb,YAAY;CACZ,UAAU;CACV,YAAY;CACZ,mBAAmB;CACpB;AAED,MAAM,eAAe,oBAClB,OAAO,EAAE,aAAa,YAAY,YAAY,YAAY,EACzD,MAAM;CACJ,wBAAwB,cAAc,cAAc,aAAa,MAAM,GAAG,KAAA;CAC1E,wBAAwB,aAAa,cAAc,YAAY,MAAM,GAAG,KAAA;CACxE,gBAAgB,aAAa,IAAI,OAAQ,GAAG,GAAG,IAAI,KAAK;CACzD,EACF,EACF;AAED,MAAM,iBACJ,YACA,OACA,SACA,mBACG;AACH,KAAI,eAAe,UACjB,QAAO,KAAK,WAAW,KAAK,KAAK,QAAQ,EAAE,CAAC;AAG9C,KAAI,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AAS,eAAe,GAAG;KACtE,WACE,iBACI;MACE,QAAQ;MACR,aAAa;MACd,GACD;KAEN,GAAI;KACJ,CAAA;IAED,cACC,oBAAC,QAAD;KACE,GAAE;KACF,GAAE;KACF,YAAW;KACX,kBAAiB;KACjB,GAAI,UAAU,QAAQ;eAErB;KACI,CAAA;IAGR,eACC,oBAACC,WAAD;KACE,mBAAmB;KACnB,mBAAmB;KACnB,UAAU,EAAE,cACV,oBAAC,cAAD;MACE,SAAS;MACT,YAAY;MACZ,QAAQ;MACR,MAAK;MACL,WACE,sBAAsB,YAAa,UAAU,IAAI,OAAkB,KAAA;MAErD;MACJ;MACZ,CAAA;KAEJ,GAAI;KACJ,CAAA;IAGH;IACgB;MACC,CAAA;EAClB,CAAA;EAER;AAEF,WAAW,cAAc;AACzB,WAAW,UAAUC;AACrB,WAAW,eAAe"}
|
|
@@ -3,7 +3,7 @@ import { ChartTooltip } from "../ChartTooltip/ChartTooltip.mjs";
|
|
|
3
3
|
import FunnelChart_module_default from "./FunnelChart.module.mjs";
|
|
4
4
|
import { Box, createVarsResolver, factory, getThemeColor, rem, useMantineTheme, useProps, useResolvedStylesApi, useStyles } from "@mantine/core";
|
|
5
5
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
-
import {
|
|
6
|
+
import { Funnel, FunnelChart, LabelList, ResponsiveContainer, Tooltip as Tooltip$1 } from "recharts";
|
|
7
7
|
//#region packages/@mantine/charts/src/FunnelChart/FunnelChart.tsx
|
|
8
8
|
const defaultProps = {
|
|
9
9
|
withTooltip: true,
|
|
@@ -20,7 +20,7 @@ const varsResolver = createVarsResolver((theme, { strokeColor, labelColor, size
|
|
|
20
20
|
} }));
|
|
21
21
|
const FunnelChart$1 = factory((_props) => {
|
|
22
22
|
const props = useProps("FunnelChart", defaultProps, _props);
|
|
23
|
-
const { classNames, className, style, styles, unstyled, vars, data, withTooltip, tooltipAnimationDuration, tooltipProps, strokeWidth, withLabels, size, valueFormatter, children, funnelChartProps, funnelProps, labelsPosition, tooltipDataSource, attributes, ...others } = props;
|
|
23
|
+
const { classNames, className, style, styles, unstyled, vars, data, withTooltip, tooltipAnimationDuration, tooltipProps, strokeWidth, withLabels, size, valueFormatter, children, funnelChartProps, funnelProps, labelsPosition, tooltipDataSource, strokeColor, labelColor, attributes, ...others } = props;
|
|
24
24
|
const theme = useMantineTheme();
|
|
25
25
|
const getStyles = useStyles({
|
|
26
26
|
name: "FunnelChart",
|
|
@@ -47,14 +47,17 @@ const FunnelChart$1 = factory((_props) => {
|
|
|
47
47
|
children: /* @__PURE__ */ jsx(ResponsiveContainer, { children: /* @__PURE__ */ jsxs(FunnelChart, {
|
|
48
48
|
...funnelChartProps,
|
|
49
49
|
children: [
|
|
50
|
-
/* @__PURE__ */
|
|
51
|
-
data
|
|
50
|
+
/* @__PURE__ */ jsx(Funnel, {
|
|
51
|
+
data: data.map((entry) => ({
|
|
52
|
+
...entry,
|
|
53
|
+
fill: getThemeColor(entry.color, theme)
|
|
54
|
+
})),
|
|
52
55
|
dataKey: "value",
|
|
53
56
|
isAnimationActive: false,
|
|
54
57
|
stroke: "var(--chart-stroke-color, var(--mantine-color-body))",
|
|
55
58
|
strokeWidth,
|
|
56
59
|
...funnelProps,
|
|
57
|
-
children:
|
|
60
|
+
children: withLabels && /* @__PURE__ */ jsx(LabelList, {
|
|
58
61
|
position: labelsPosition,
|
|
59
62
|
fill: labelsPosition === "inside" ? "var(--chart-labels-color, var(--mantine-color-white))" : "var(--chart-labels-color, var(--mantine-color-dimmed))",
|
|
60
63
|
stroke: "none",
|
|
@@ -63,11 +66,7 @@ const FunnelChart$1 = factory((_props) => {
|
|
|
63
66
|
dataKey: (entry) => {
|
|
64
67
|
return typeof valueFormatter === "function" ? valueFormatter(entry.value) : entry.value;
|
|
65
68
|
}
|
|
66
|
-
})
|
|
67
|
-
fill: getThemeColor(entry.color, theme),
|
|
68
|
-
stroke: "var(--chart-stroke-color, var(--mantine-color-body))",
|
|
69
|
-
strokeWidth
|
|
70
|
-
}, index))]
|
|
69
|
+
})
|
|
71
70
|
}),
|
|
72
71
|
withTooltip && /* @__PURE__ */ jsx(Tooltip$1, {
|
|
73
72
|
animationDuration: tooltipAnimationDuration,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FunnelChart.mjs","names":["FunnelChart","RechartsFunnelChart","Tooltip","classes"],"sources":["../../src/FunnelChart/FunnelChart.tsx"],"sourcesContent":["import {\n
|
|
1
|
+
{"version":3,"file":"FunnelChart.mjs","names":["FunnelChart","RechartsFunnelChart","Tooltip","classes"],"sources":["../../src/FunnelChart/FunnelChart.tsx"],"sourcesContent":["import {\n Funnel,\n FunnelProps,\n LabelList,\n FunnelChart as RechartsFunnelChart,\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 rem,\n StylesApiProps,\n useMantineTheme,\n useProps,\n useResolvedStylesApi,\n useStyles,\n} from '@mantine/core';\nimport { ChartTooltip, ChartTooltipStylesNames } from '../ChartTooltip/ChartTooltip';\nimport classes from './FunnelChart.module.css';\n\nexport interface FunnelChartCell {\n key?: string | number;\n name: string;\n value: number;\n color: MantineColor;\n}\n\nexport type FunnelChartStylesNames = 'root' | ChartTooltipStylesNames;\nexport type FunnelChartCssVariables = {\n root: '--chart-stroke-color' | '--chart-labels-color' | '--chart-size';\n};\n\nexport interface FunnelChartProps\n extends BoxProps, StylesApiProps<FunnelChartFactory>, ElementProps<'div'> {\n /** Data used to render chart */\n data: FunnelChartCell[];\n\n /** Determines whether the tooltip should be displayed when a section 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 `Pie` component */\n funnelProps?: Partial<Omit<FunnelProps, 'ref'>>;\n\n /** Controls color of the segments stroke, by default depends on color scheme */\n strokeColor?: MantineColor;\n\n /** Controls text color of all labels @default 'white' */\n labelColor?: MantineColor;\n\n /** Controls chart width and height @default 300 */\n size?: number;\n\n /** Controls width of segments stroke @default 1 */\n strokeWidth?: number;\n\n /** Determines whether each segment should have associated label @default false */\n withLabels?: boolean;\n\n /** Controls labels position relative to the segment @default 'right' */\n labelsPosition?: 'right' | 'left' | 'inside';\n\n /** A function to format values inside the tooltip and labels */\n valueFormatter?: (value: number) => string;\n\n /** Determines which data is displayed in the tooltip. `'all'` – display all values, `'segment'` – display only hovered segment. @default 'all' */\n tooltipDataSource?: 'segment' | 'all';\n\n /** Additional elements rendered inside `FunnelChart` component */\n children?: React.ReactNode;\n\n /** Props passed down to recharts `FunnelChart` component */\n funnelChartProps?: React.ComponentProps<typeof RechartsFunnelChart>;\n}\n\nexport type FunnelChartFactory = Factory<{\n props: FunnelChartProps;\n ref: HTMLDivElement;\n stylesNames: FunnelChartStylesNames;\n vars: FunnelChartCssVariables;\n}>;\n\nconst defaultProps = {\n withTooltip: true,\n size: 300,\n strokeWidth: 1,\n withLabels: false,\n labelsPosition: 'right',\n tooltipDataSource: 'all',\n} satisfies Partial<FunnelChartProps>;\n\nconst varsResolver = createVarsResolver<FunnelChartFactory>(\n (theme, { strokeColor, labelColor, size }) => ({\n root: {\n '--chart-stroke-color': strokeColor ? getThemeColor(strokeColor, theme) : undefined,\n '--chart-labels-color': labelColor ? getThemeColor(labelColor, theme) : undefined,\n '--chart-size': rem(size),\n },\n })\n);\n\nexport const FunnelChart = factory<FunnelChartFactory>((_props) => {\n const props = useProps('FunnelChart', defaultProps, _props);\n const {\n classNames,\n className,\n style,\n styles,\n unstyled,\n vars,\n data,\n withTooltip,\n tooltipAnimationDuration,\n tooltipProps,\n strokeWidth,\n withLabels,\n size,\n valueFormatter,\n children,\n funnelChartProps,\n funnelProps,\n labelsPosition,\n tooltipDataSource,\n strokeColor,\n labelColor,\n attributes,\n ...others\n } = props;\n\n const theme = useMantineTheme();\n\n const getStyles = useStyles<FunnelChartFactory>({\n name: 'FunnelChart',\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<FunnelChartFactory>({\n classNames,\n styles,\n props,\n });\n\n return (\n <Box size={size} {...getStyles('root')} {...others}>\n <ResponsiveContainer>\n <RechartsFunnelChart {...funnelChartProps}>\n <Funnel\n data={data.map((entry) => ({\n ...entry,\n fill: getThemeColor(entry.color, theme),\n }))}\n dataKey=\"value\"\n isAnimationActive={false}\n stroke=\"var(--chart-stroke-color, var(--mantine-color-body))\"\n strokeWidth={strokeWidth}\n {...funnelProps}\n >\n {withLabels && (\n <LabelList\n position={labelsPosition}\n fill={\n labelsPosition === 'inside'\n ? 'var(--chart-labels-color, var(--mantine-color-white))'\n : 'var(--chart-labels-color, var(--mantine-color-dimmed))'\n }\n stroke=\"none\"\n fontFamily=\"var(--mantine-font-family)\"\n fontSize={12}\n dataKey={(entry) => {\n return typeof valueFormatter === 'function'\n ? valueFormatter(entry.value as number)\n : entry.value;\n }}\n />\n )}\n </Funnel>\n\n {withTooltip && (\n <Tooltip\n animationDuration={tooltipAnimationDuration}\n isAnimationActive={false}\n content={({ payload }) => (\n <ChartTooltip\n payload={data}\n classNames={resolvedClassNames}\n styles={resolvedStyles}\n type=\"radial\"\n segmentId={\n tooltipDataSource === 'segment' ? (payload?.[0]?.name as string) : undefined\n }\n valueFormatter={valueFormatter}\n attributes={attributes}\n />\n )}\n {...tooltipProps}\n />\n )}\n\n {children}\n </RechartsFunnelChart>\n </ResponsiveContainer>\n </Box>\n );\n});\n\nFunnelChart.displayName = '@mantine/charts/FunnelChart';\nFunnelChart.classes = classes;\nFunnelChart.varsResolver = varsResolver;\n"],"mappings":";;;;;;;AA+FA,MAAM,eAAe;CACnB,aAAa;CACb,MAAM;CACN,aAAa;CACb,YAAY;CACZ,gBAAgB;C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AAD;MACE,SAAS;MACT,YAAY;MACZ,QAAQ;MACR,MAAK;MACL,WACE,sBAAsB,YAAa,UAAU,IAAI,OAAkB,KAAA;MAErD;MACJ;MACZ,CAAA;KAEJ,GAAI;KACJ,CAAA;IAGH;IACmB;MACF,CAAA;EAClB,CAAA;EAER;AAEF,cAAY,cAAc;AAC1B,cAAY,UAAUC;AACtB,cAAY,eAAe"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
//#region packages/@mantine/charts/src/Heatmap/get-heat-color/get-heat-color.ts
|
|
3
3
|
function getHeatColor({ value, min, max, colors }) {
|
|
4
|
-
const percent = (value - min) / (max - min);
|
|
4
|
+
const percent = max === min ? 1 : (value - min) / (max - min);
|
|
5
5
|
return colors[Math.round((colors.length - 1) * percent)];
|
|
6
6
|
}
|
|
7
7
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-heat-color.mjs","names":[],"sources":["../../../src/Heatmap/get-heat-color/get-heat-color.ts"],"sourcesContent":["interface GetHeatColorInput {\n value: number;\n min: number;\n max: number;\n colors: string[];\n}\n\nexport function getHeatColor({ value, min, max, colors }: GetHeatColorInput) {\n const percent = (value - min) / (max - min);\n const colorIndex = Math.round((colors.length - 1) * percent);\n return colors[colorIndex];\n}\n"],"mappings":";;AAOA,SAAgB,aAAa,EAAE,OAAO,KAAK,KAAK,UAA6B;CAC3E,MAAM,
|
|
1
|
+
{"version":3,"file":"get-heat-color.mjs","names":[],"sources":["../../../src/Heatmap/get-heat-color/get-heat-color.ts"],"sourcesContent":["interface GetHeatColorInput {\n value: number;\n min: number;\n max: number;\n colors: string[];\n}\n\nexport function getHeatColor({ value, min, max, colors }: GetHeatColorInput) {\n const percent = max === min ? 1 : (value - min) / (max - min);\n const colorIndex = Math.round((colors.length - 1) * percent);\n return colors[colorIndex];\n}\n"],"mappings":";;AAOA,SAAgB,aAAa,EAAE,OAAO,KAAK,KAAK,UAA6B;CAC3E,MAAM,UAAU,QAAQ,MAAM,KAAK,QAAQ,QAAQ,MAAM;AAEzD,QAAO,OADY,KAAK,OAAO,OAAO,SAAS,KAAK,QAAQ"}
|
|
@@ -3,7 +3,7 @@ import { ChartTooltip } from "../ChartTooltip/ChartTooltip.mjs";
|
|
|
3
3
|
import PieChart_module_default from "./PieChart.module.mjs";
|
|
4
4
|
import { Box, createVarsResolver, factory, getThemeColor, rem, useMantineTheme, useProps, useResolvedStylesApi, useStyles } from "@mantine/core";
|
|
5
5
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
-
import {
|
|
6
|
+
import { Pie, PieChart, ResponsiveContainer, Tooltip as Tooltip$1 } from "recharts";
|
|
7
7
|
//#region packages/@mantine/charts/src/PieChart/PieChart.tsx
|
|
8
8
|
const defaultProps = {
|
|
9
9
|
withTooltip: false,
|
|
@@ -76,12 +76,13 @@ const PieChart$1 = factory((_props) => {
|
|
|
76
76
|
styles,
|
|
77
77
|
props
|
|
78
78
|
});
|
|
79
|
-
const
|
|
79
|
+
const pieData = data.map((item) => ({
|
|
80
|
+
...item,
|
|
80
81
|
fill: getThemeColor(item.color, theme),
|
|
81
82
|
stroke: "var(--chart-stroke-color, var(--mantine-color-body))",
|
|
82
83
|
strokeWidth,
|
|
83
84
|
...typeof cellProps === "function" ? cellProps(item) : cellProps
|
|
84
|
-
}
|
|
85
|
+
}));
|
|
85
86
|
return /* @__PURE__ */ jsx(Box, {
|
|
86
87
|
size,
|
|
87
88
|
...getStyles("root"),
|
|
@@ -90,7 +91,7 @@ const PieChart$1 = factory((_props) => {
|
|
|
90
91
|
...pieChartProps,
|
|
91
92
|
children: [
|
|
92
93
|
/* @__PURE__ */ jsx(Pie, {
|
|
93
|
-
data,
|
|
94
|
+
data: pieData,
|
|
94
95
|
innerRadius: 0,
|
|
95
96
|
outerRadius: size / 2,
|
|
96
97
|
dataKey: "value",
|
|
@@ -103,8 +104,7 @@ const PieChart$1 = factory((_props) => {
|
|
|
103
104
|
stroke: "var(--chart-label-color, var(--mantine-color-dimmed))",
|
|
104
105
|
strokeWidth: 1
|
|
105
106
|
} : false,
|
|
106
|
-
...pieProps
|
|
107
|
-
children: cells
|
|
107
|
+
...pieProps
|
|
108
108
|
}),
|
|
109
109
|
withTooltip && /* @__PURE__ */ jsx(Tooltip$1, {
|
|
110
110
|
animationDuration: tooltipAnimationDuration,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PieChart.mjs","names":["classes","PieChart","ReChartsPieChart","Tooltip"],"sources":["../../src/PieChart/PieChart.tsx"],"sourcesContent":["import {\n Cell,\n CellProps,\n Pie,\n PieLabel,\n PieProps,\n PieChart as ReChartsPieChart,\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 rem,\n StylesApiProps,\n useMantineTheme,\n useProps,\n useResolvedStylesApi,\n useStyles,\n} from '@mantine/core';\nimport { ChartTooltip, ChartTooltipStylesNames } from '../ChartTooltip/ChartTooltip';\nimport classes from './PieChart.module.css';\n\nexport interface PieChartCell {\n key?: string | number;\n name: string;\n value: number;\n color: MantineColor;\n}\n\nexport type PieChartStylesNames = 'root' | ChartTooltipStylesNames;\nexport type PieChartCssVariables = {\n root: '--chart-stroke-color' | '--chart-labels-color' | '--chart-size';\n};\n\nexport interface PieChartProps\n extends BoxProps, StylesApiProps<PieChartFactory>, ElementProps<'div'> {\n /** Data used to render chart */\n data: PieChartCell[];\n\n /** Determines whether the tooltip should be displayed when one of the section 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 `Pie` component */\n pieProps?: Partial<Omit<PieProps, 'ref'>>;\n\n /** Controls color of the segments stroke, by default depends on color scheme */\n strokeColor?: MantineColor;\n\n /** Controls text color of all labels, white by default */\n labelColor?: MantineColor;\n\n /** Controls padding between segments @default 0 */\n paddingAngle?: number;\n\n /** Determines whether each segment should have associated label @default false */\n withLabels?: boolean;\n\n /** Determines whether segments labels should have lines that connect the segment with the label @default true */\n withLabelsLine?: boolean;\n\n /** Controls chart width and height, height is increased by 40 if `withLabels` prop is set. Cannot be less than `thickness`. @default 80 */\n size?: number;\n\n /** Controls width of segments stroke @default 1 */\n strokeWidth?: number;\n\n /** Controls angle at which chart starts. Set to `180` to render the chart as semicircle. @default 0 */\n startAngle?: number;\n\n /** Controls angle at which charts ends. Set to `0` to render the chart as semicircle. @default 360 */\n endAngle?: number;\n\n /** Determines which data is displayed in the tooltip. `'all'` – display all values, `'segment'` – display only hovered segment. @default 'all' */\n tooltipDataSource?: 'segment' | 'all';\n\n /** Additional elements rendered inside `PieChart` component */\n children?: React.ReactNode;\n\n /** Props passed down to recharts `PieChart` component */\n pieChartProps?: React.ComponentProps<typeof ReChartsPieChart>;\n\n /** Controls labels position relative to the segment @default 'outside' */\n labelsPosition?: 'inside' | 'outside';\n\n /** Type of labels to display @default 'value' */\n labelsType?: 'value' | 'percent';\n\n /** A function to format values inside the tooltip */\n valueFormatter?: (value: number) => string;\n\n /** Props passed down to recharts `Cell` component */\n cellProps?:\n | ((series: PieChartCell) => Partial<Omit<CellProps, 'ref'>>)\n | Partial<Omit<CellProps, 'ref'>>;\n}\n\nexport type PieChartFactory = Factory<{\n props: PieChartProps;\n ref: HTMLDivElement;\n stylesNames: PieChartStylesNames;\n vars: PieChartCssVariables;\n}>;\n\nconst defaultProps = {\n withTooltip: false,\n withLabelsLine: true,\n paddingAngle: 0,\n size: 160,\n strokeWidth: 1,\n startAngle: 0,\n endAngle: 360,\n tooltipDataSource: 'all',\n labelsPosition: 'outside',\n labelsType: 'value',\n} satisfies Partial<PieChartProps>;\n\nconst varsResolver = createVarsResolver<PieChartFactory>(\n (theme, { strokeColor, labelColor, withLabels, size, labelsPosition }) => ({\n root: {\n '--chart-stroke-color': strokeColor ? getThemeColor(strokeColor, theme) : undefined,\n '--chart-labels-color': labelColor ? getThemeColor(labelColor, theme) : undefined,\n '--chart-size': withLabels && labelsPosition === 'outside' ? rem(size! + 80) : rem(size),\n },\n })\n);\n\nconst getLabelValue = (\n labelsType: PieChartProps['labelsType'],\n value: number | undefined,\n percent: number | undefined,\n valueFormatter?: PieChartProps['valueFormatter']\n) => {\n if (labelsType === 'percent' && typeof percent === 'number') {\n return `${(percent * 100).toFixed(0)}%`;\n }\n\n if (typeof valueFormatter === 'function' && typeof value === 'number') {\n return valueFormatter(value);\n }\n\n return value;\n};\n\nconst getInsideLabel =\n (labelsType: 'value' | 'percent', valueFormatter?: PieChartProps['valueFormatter']): PieLabel =>\n ({ cx, cy, midAngle, innerRadius, outerRadius, value, percent }) => {\n const RADIAN = Math.PI / 180;\n const radius = Number(innerRadius) + (Number(outerRadius) - Number(innerRadius)) * 0.5;\n const x = Number(cx) + radius * Math.cos(-(midAngle || 0) * RADIAN);\n const y = Number(cy) + radius * Math.sin(-(midAngle || 0) * RADIAN);\n\n return (\n <text\n x={x}\n y={y}\n textAnchor={x > Number(cx) ? 'start' : 'end'}\n dominantBaseline=\"central\"\n className={classes.label}\n >\n {getLabelValue(labelsType, Number(value), Number(percent), valueFormatter)}\n </text>\n );\n };\n\nconst getOutsideLabel =\n (labelsType: 'value' | 'percent', valueFormatter?: PieChartProps['valueFormatter']): PieLabel =>\n ({ x, y, cx, cy, percent, value }) => (\n <text\n x={x}\n y={y}\n cx={cx}\n cy={cy}\n textAnchor={x > Number(cx) ? 'start' : 'end'}\n fill=\"var(--chart-labels-color, var(--mantine-color-dimmed))\"\n fontFamily=\"var(--mantine-font-family)\"\n fontSize={12}\n >\n <tspan x={x}>\n {getLabelValue(labelsType, Number(value), Number(percent), valueFormatter)}\n </tspan>\n </text>\n );\n\nexport const PieChart = factory<PieChartFactory>((_props) => {\n const props = useProps('PieChart', defaultProps, _props);\n const {\n classNames,\n className,\n style,\n styles,\n unstyled,\n vars,\n data,\n withTooltip,\n tooltipAnimationDuration,\n tooltipProps,\n pieProps,\n paddingAngle,\n withLabels,\n withLabelsLine,\n size,\n strokeWidth,\n startAngle,\n endAngle,\n tooltipDataSource,\n children,\n pieChartProps,\n labelsPosition,\n valueFormatter,\n labelsType,\n strokeColor,\n attributes,\n cellProps,\n ...others\n } = props;\n\n const theme = useMantineTheme();\n\n const getStyles = useStyles<PieChartFactory>({\n name: 'PieChart',\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<PieChartFactory>({\n classNames,\n styles,\n props,\n });\n\n const cells = data.map((item, index) => (\n <Cell\n key={index}\n fill={getThemeColor(item.color, theme)}\n stroke=\"var(--chart-stroke-color, var(--mantine-color-body))\"\n strokeWidth={strokeWidth}\n {...(typeof cellProps === 'function' ? cellProps(item) : cellProps)}\n />\n ));\n\n return (\n <Box size={size} {...getStyles('root')} {...others}>\n <ResponsiveContainer>\n <ReChartsPieChart {...pieChartProps}>\n <Pie\n data={data as any}\n innerRadius={0}\n outerRadius={size / 2}\n dataKey=\"value\"\n isAnimationActive={false}\n paddingAngle={paddingAngle}\n startAngle={startAngle}\n endAngle={endAngle}\n label={\n withLabels\n ? labelsPosition === 'inside'\n ? getInsideLabel(labelsType || 'value', valueFormatter)\n : getOutsideLabel(labelsType || 'value', valueFormatter)\n : false\n }\n labelLine={\n withLabelsLine && labelsPosition === 'outside'\n ? {\n stroke: 'var(--chart-label-color, var(--mantine-color-dimmed))',\n strokeWidth: 1,\n }\n : false\n }\n {...pieProps}\n >\n {cells}\n </Pie>\n\n {withTooltip && (\n <Tooltip\n animationDuration={tooltipAnimationDuration}\n isAnimationActive={false}\n content={({ payload }) => (\n <ChartTooltip\n payload={data}\n classNames={resolvedClassNames}\n styles={resolvedStyles}\n type=\"radial\"\n segmentId={\n tooltipDataSource === 'segment' ? (payload?.[0]?.name as string) : undefined\n }\n valueFormatter={valueFormatter}\n attributes={attributes}\n />\n )}\n {...tooltipProps}\n />\n )}\n\n {children}\n </ReChartsPieChart>\n </ResponsiveContainer>\n </Box>\n );\n});\n\nPieChart.displayName = '@mantine/charts/PieChart';\nPieChart.classes = classes;\nPieChart.varsResolver = varsResolver;\n"],"mappings":";;;;;;;AAqHA,MAAM,eAAe;CACnB,aAAa;CACb,gBAAgB;CAChB,cAAc;CACd,MAAM;CACN,aAAa;CACb,YAAY;CACZ,UAAU;CACV,mBAAmB;CACnB,gBAAgB;CAChB,YAAY;CACb;AAED,MAAM,eAAe,oBAClB,OAAO,EAAE,aAAa,YAAY,YAAY,MAAM,sBAAsB,EACzE,MAAM;CACJ,wBAAwB,cAAc,cAAc,aAAa,MAAM,GAAG,KAAA;CAC1E,wBAAwB,aAAa,cAAc,YAAY,MAAM,GAAG,KAAA;CACxE,gBAAgB,cAAc,mBAAmB,YAAY,IAAI,OAAQ,GAAG,GAAG,IAAI,KAAK;CACzF,EACF,EACF;AAED,MAAM,iBACJ,YACA,OACA,SACA,mBACG;AACH,KAAI,eAAe,aAAa,OAAO,YAAY,SACjD,QAAO,IAAI,UAAU,KAAK,QAAQ,EAAE,CAAC;AAGvC,KAAI,OAAO,mBAAmB,cAAc,OAAO,UAAU,SAC3D,QAAO,eAAe,MAAM;AAG9B,QAAO;;AAGT,MAAM,kBACH,YAAiC,oBACjC,EAAE,IAAI,IAAI,UAAU,aAAa,aAAa,OAAO,cAAc;CAClE,MAAM,SAAS,KAAK,KAAK;CACzB,MAAM,SAAS,OAAO,YAAY,IAAI,OAAO,YAAY,GAAG,OAAO,YAAY,IAAI;CACnF,MAAM,IAAI,OAAO,GAAG,GAAG,SAAS,KAAK,IAAI,EAAE,YAAY,KAAK,OAAO;AAGnE,QACE,oBAAC,QAAD;EACK;EACH,GALM,OAAO,GAAG,GAAG,SAAS,KAAK,IAAI,EAAE,YAAY,KAAK,OAAO;EAM/D,YAAY,I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,OAAO;KACpB,SAAQ;KACR,mBAAmB;KACL;KACF;KACF;KACV,OACE,aACI,mBAAmB,WACjB,eAAe,cAAc,SAAS,eAAe,GACrD,gBAAgB,cAAc,SAAS,eAAe,GACxD;KAEN,WACE,kBAAkB,mBAAmB,YACjC;MACE,QAAQ;MACR,aAAa;MACd,GACD;KAEN,GAAI;eAEH;KACG,CAAA;IAEL,eACC,oBAACC,WAAD;KACE,mBAAmB;KACnB,mBAAmB;KACnB,UAAU,EAAE,cACV,oBAAC,cAAD;MACE,SAAS;MACT,YAAY;MACZ,QAAQ;MACR,MAAK;MACL,WACE,sBAAsB,YAAa,UAAU,IAAI,OAAkB,KAAA;MAErD;MACJ;MACZ,CAAA;KAEJ,GAAI;KACJ,CAAA;IAGH;IACgB;MACC,CAAA;EAClB,CAAA;EAER;AAEF,WAAS,cAAc;AACvB,WAAS,UAAUH;AACnB,WAAS,eAAe"}
|
|
1
|
+
{"version":3,"file":"PieChart.mjs","names":["classes","PieChart","ReChartsPieChart","Tooltip"],"sources":["../../src/PieChart/PieChart.tsx"],"sourcesContent":["import {\n Pie,\n PieLabel,\n PieProps,\n PieChart as ReChartsPieChart,\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 rem,\n StylesApiProps,\n useMantineTheme,\n useProps,\n useResolvedStylesApi,\n useStyles,\n} from '@mantine/core';\nimport { ChartTooltip, ChartTooltipStylesNames } from '../ChartTooltip/ChartTooltip';\nimport classes from './PieChart.module.css';\n\nexport interface PieChartCell {\n key?: string | number;\n name: string;\n value: number;\n color: MantineColor;\n}\n\nexport type PieChartStylesNames = 'root' | ChartTooltipStylesNames;\nexport type PieChartCssVariables = {\n root: '--chart-stroke-color' | '--chart-labels-color' | '--chart-size';\n};\n\nexport interface PieChartProps\n extends BoxProps, StylesApiProps<PieChartFactory>, ElementProps<'div'> {\n /** Data used to render chart */\n data: PieChartCell[];\n\n /** Determines whether the tooltip should be displayed when one of the section 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 `Pie` component */\n pieProps?: Partial<Omit<PieProps, 'ref'>>;\n\n /** Controls color of the segments stroke, by default depends on color scheme */\n strokeColor?: MantineColor;\n\n /** Controls text color of all labels, white by default */\n labelColor?: MantineColor;\n\n /** Controls padding between segments @default 0 */\n paddingAngle?: number;\n\n /** Determines whether each segment should have associated label @default false */\n withLabels?: boolean;\n\n /** Determines whether segments labels should have lines that connect the segment with the label @default true */\n withLabelsLine?: boolean;\n\n /** Controls chart width and height, height is increased by 40 if `withLabels` prop is set. Cannot be less than `thickness`. @default 80 */\n size?: number;\n\n /** Controls width of segments stroke @default 1 */\n strokeWidth?: number;\n\n /** Controls angle at which chart starts. Set to `180` to render the chart as semicircle. @default 0 */\n startAngle?: number;\n\n /** Controls angle at which charts ends. Set to `0` to render the chart as semicircle. @default 360 */\n endAngle?: number;\n\n /** Determines which data is displayed in the tooltip. `'all'` – display all values, `'segment'` – display only hovered segment. @default 'all' */\n tooltipDataSource?: 'segment' | 'all';\n\n /** Additional elements rendered inside `PieChart` component */\n children?: React.ReactNode;\n\n /** Props passed down to recharts `PieChart` component */\n pieChartProps?: React.ComponentProps<typeof ReChartsPieChart>;\n\n /** Controls labels position relative to the segment @default 'outside' */\n labelsPosition?: 'inside' | 'outside';\n\n /** Type of labels to display @default 'value' */\n labelsType?: 'value' | 'percent';\n\n /** A function to format values inside the tooltip */\n valueFormatter?: (value: number) => string;\n\n /** Props passed down to each segment of the chart */\n cellProps?:\n | ((series: PieChartCell) => Partial<Omit<React.SVGProps<SVGElement>, 'ref'>>)\n | Partial<Omit<React.SVGProps<SVGElement>, 'ref'>>;\n}\n\nexport type PieChartFactory = Factory<{\n props: PieChartProps;\n ref: HTMLDivElement;\n stylesNames: PieChartStylesNames;\n vars: PieChartCssVariables;\n}>;\n\nconst defaultProps = {\n withTooltip: false,\n withLabelsLine: true,\n paddingAngle: 0,\n size: 160,\n strokeWidth: 1,\n startAngle: 0,\n endAngle: 360,\n tooltipDataSource: 'all',\n labelsPosition: 'outside',\n labelsType: 'value',\n} satisfies Partial<PieChartProps>;\n\nconst varsResolver = createVarsResolver<PieChartFactory>(\n (theme, { strokeColor, labelColor, withLabels, size, labelsPosition }) => ({\n root: {\n '--chart-stroke-color': strokeColor ? getThemeColor(strokeColor, theme) : undefined,\n '--chart-labels-color': labelColor ? getThemeColor(labelColor, theme) : undefined,\n '--chart-size': withLabels && labelsPosition === 'outside' ? rem(size! + 80) : rem(size),\n },\n })\n);\n\nconst getLabelValue = (\n labelsType: PieChartProps['labelsType'],\n value: number | undefined,\n percent: number | undefined,\n valueFormatter?: PieChartProps['valueFormatter']\n) => {\n if (labelsType === 'percent' && typeof percent === 'number') {\n return `${(percent * 100).toFixed(0)}%`;\n }\n\n if (typeof valueFormatter === 'function' && typeof value === 'number') {\n return valueFormatter(value);\n }\n\n return value;\n};\n\nconst getInsideLabel =\n (labelsType: 'value' | 'percent', valueFormatter?: PieChartProps['valueFormatter']): PieLabel =>\n ({ cx, cy, midAngle, innerRadius, outerRadius, value, percent }) => {\n const RADIAN = Math.PI / 180;\n const radius = Number(innerRadius) + (Number(outerRadius) - Number(innerRadius)) * 0.5;\n const x = Number(cx) + radius * Math.cos(-(midAngle || 0) * RADIAN);\n const y = Number(cy) + radius * Math.sin(-(midAngle || 0) * RADIAN);\n\n return (\n <text\n x={x}\n y={y}\n textAnchor={x > Number(cx) ? 'start' : 'end'}\n dominantBaseline=\"central\"\n className={classes.label}\n >\n {getLabelValue(labelsType, Number(value), Number(percent), valueFormatter)}\n </text>\n );\n };\n\nconst getOutsideLabel =\n (labelsType: 'value' | 'percent', valueFormatter?: PieChartProps['valueFormatter']): PieLabel =>\n ({ x, y, cx, cy, percent, value }) => (\n <text\n x={x}\n y={y}\n cx={cx}\n cy={cy}\n textAnchor={x > Number(cx) ? 'start' : 'end'}\n fill=\"var(--chart-labels-color, var(--mantine-color-dimmed))\"\n fontFamily=\"var(--mantine-font-family)\"\n fontSize={12}\n >\n <tspan x={x}>\n {getLabelValue(labelsType, Number(value), Number(percent), valueFormatter)}\n </tspan>\n </text>\n );\n\nexport const PieChart = factory<PieChartFactory>((_props) => {\n const props = useProps('PieChart', defaultProps, _props);\n const {\n classNames,\n className,\n style,\n styles,\n unstyled,\n vars,\n data,\n withTooltip,\n tooltipAnimationDuration,\n tooltipProps,\n pieProps,\n paddingAngle,\n withLabels,\n withLabelsLine,\n size,\n strokeWidth,\n startAngle,\n endAngle,\n tooltipDataSource,\n children,\n pieChartProps,\n labelsPosition,\n valueFormatter,\n labelsType,\n strokeColor,\n attributes,\n cellProps,\n ...others\n } = props;\n\n const theme = useMantineTheme();\n\n const getStyles = useStyles<PieChartFactory>({\n name: 'PieChart',\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<PieChartFactory>({\n classNames,\n styles,\n props,\n });\n\n const pieData = data.map((item) => ({\n ...item,\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 }));\n\n return (\n <Box size={size} {...getStyles('root')} {...others}>\n <ResponsiveContainer>\n <ReChartsPieChart {...pieChartProps}>\n <Pie\n data={pieData as any}\n innerRadius={0}\n outerRadius={size / 2}\n dataKey=\"value\"\n isAnimationActive={false}\n paddingAngle={paddingAngle}\n startAngle={startAngle}\n endAngle={endAngle}\n label={\n withLabels\n ? labelsPosition === 'inside'\n ? getInsideLabel(labelsType || 'value', valueFormatter)\n : getOutsideLabel(labelsType || 'value', valueFormatter)\n : false\n }\n labelLine={\n withLabelsLine && labelsPosition === 'outside'\n ? {\n stroke: 'var(--chart-label-color, var(--mantine-color-dimmed))',\n strokeWidth: 1,\n }\n : false\n }\n {...pieProps}\n />\n\n {withTooltip && (\n <Tooltip\n animationDuration={tooltipAnimationDuration}\n isAnimationActive={false}\n content={({ payload }) => (\n <ChartTooltip\n payload={data}\n classNames={resolvedClassNames}\n styles={resolvedStyles}\n type=\"radial\"\n segmentId={\n tooltipDataSource === 'segment' ? (payload?.[0]?.name as string) : undefined\n }\n valueFormatter={valueFormatter}\n attributes={attributes}\n />\n )}\n {...tooltipProps}\n />\n )}\n\n {children}\n </ReChartsPieChart>\n </ResponsiveContainer>\n </Box>\n );\n});\n\nPieChart.displayName = '@mantine/charts/PieChart';\nPieChart.classes = classes;\nPieChart.varsResolver = varsResolver;\n"],"mappings":";;;;;;;AAmHA,MAAM,eAAe;CACnB,aAAa;CACb,gBAAgB;CAChB,cAAc;CACd,MAAM;CACN,aAAa;CACb,YAAY;CACZ,UAAU;CACV,mBAAmB;CACnB,gBAAgB;CAChB,YAAY;CACb;AAED,MAAM,eAAe,oBAClB,OAAO,EAAE,aAAa,YAAY,YAAY,MAAM,sBAAsB,EACzE,MAAM;CACJ,wBAAwB,cAAc,cAAc,aAAa,MAAM,GAAG,KAAA;CAC1E,wBAAwB,aAAa,cAAc,YAAY,MAAM,GAAG,KAAA;CACxE,gBAAgB,cAAc,mBAAmB,YAAY,IAAI,OAAQ,GAAG,GAAG,IAAI,KAAK;CACzF,EACF,EACF;AAED,MAAM,iBACJ,YACA,OACA,SACA,mBACG;AACH,KAAI,eAAe,aAAa,OAAO,YAAY,SACjD,QAAO,IAAI,UAAU,KAAK,QAAQ,EAAE,CAAC;AAGvC,KAAI,OAAO,mBAAmB,cAAc,OAAO,UAAU,SAC3D,QAAO,eAAe,MAAM;AAG9B,QAAO;;AAGT,MAAM,kBACH,YAAiC,oBACjC,EAAE,IAAI,IAAI,UAAU,aAAa,aAAa,OAAO,cAAc;CAClE,MAA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OAAO,MAAM;EACtC,QAAQ;EACR;EACA,GAAI,OAAO,cAAc,aAAa,UAAU,KAAK,GAAG;EACzD,EAAE;AAEH,QACE,oBAAC,KAAD;EAAW;EAAM,GAAI,UAAU,OAAO;EAAE,GAAI;YAC1C,oBAAC,qBAAD,EAAA,UACE,qBAACC,UAAD;GAAkB,GAAI;aAAtB;IACE,oBAAC,KAAD;KACE,MAAM;KACN,aAAa;KACb,aAAa,OAAO;KACpB,SAAQ;KACR,mBAAmB;KACL;KACF;KACF;KACV,OACE,aACI,mBAAmB,WACjB,eAAe,cAAc,SAAS,eAAe,GACrD,gBAAgB,cAAc,SAAS,eAAe,GACxD;KAEN,WACE,kBAAkB,mBAAmB,YACjC;MACE,QAAQ;MACR,aAAa;MACd,GACD;KAEN,GAAI;KACJ,CAAA;IAED,eACC,oBAACC,WAAD;KACE,mBAAmB;KACnB,mBAAmB;KACnB,UAAU,EAAE,cACV,oBAAC,cAAD;MACE,SAAS;MACT,YAAY;MACZ,QAAQ;MACR,MAAK;MACL,WACE,sBAAsB,YAAa,UAAU,IAAI,OAAkB,KAAA;MAErD;MACJ;MACZ,CAAA;KAEJ,GAAI;KACJ,CAAA;IAGH;IACgB;MACC,CAAA;EAClB,CAAA;EAER;AAEF,WAAS,cAAc;AACvB,WAAS,UAAUH;AACnB,WAAS,eAAe"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PieProps, PieChart as ReChartsPieChart, TooltipProps } from 'recharts';
|
|
2
2
|
import { BoxProps, ElementProps, Factory, MantineColor, StylesApiProps } from '@mantine/core';
|
|
3
3
|
import { ChartTooltipStylesNames } from '../ChartTooltip/ChartTooltip';
|
|
4
4
|
export interface DonutChartCell {
|
|
@@ -53,8 +53,8 @@ export interface DonutChartProps extends BoxProps, StylesApiProps<DonutChartFact
|
|
|
53
53
|
labelsType?: 'value' | 'percent';
|
|
54
54
|
/** A function to format values inside the tooltip */
|
|
55
55
|
valueFormatter?: (value: number) => string;
|
|
56
|
-
/** Props passed down to
|
|
57
|
-
cellProps?: ((series: DonutChartCell) => Partial<Omit<
|
|
56
|
+
/** Props passed down to each segment of the chart */
|
|
57
|
+
cellProps?: ((series: DonutChartCell) => Partial<Omit<React.SVGProps<SVGElement>, 'ref'>>) | Partial<Omit<React.SVGProps<SVGElement>, 'ref'>>;
|
|
58
58
|
}
|
|
59
59
|
export type DonutChartFactory = Factory<{
|
|
60
60
|
props: DonutChartProps;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PieProps, PieChart as ReChartsPieChart, TooltipProps } from 'recharts';
|
|
2
2
|
import { BoxProps, ElementProps, Factory, MantineColor, StylesApiProps } from '@mantine/core';
|
|
3
3
|
import { ChartTooltipStylesNames } from '../ChartTooltip/ChartTooltip';
|
|
4
4
|
export interface PieChartCell {
|
|
@@ -52,8 +52,8 @@ export interface PieChartProps extends BoxProps, StylesApiProps<PieChartFactory>
|
|
|
52
52
|
labelsType?: 'value' | 'percent';
|
|
53
53
|
/** A function to format values inside the tooltip */
|
|
54
54
|
valueFormatter?: (value: number) => string;
|
|
55
|
-
/** Props passed down to
|
|
56
|
-
cellProps?: ((series: PieChartCell) => Partial<Omit<
|
|
55
|
+
/** Props passed down to each segment of the chart */
|
|
56
|
+
cellProps?: ((series: PieChartCell) => Partial<Omit<React.SVGProps<SVGElement>, 'ref'>>) | Partial<Omit<React.SVGProps<SVGElement>, 'ref'>>;
|
|
57
57
|
}
|
|
58
58
|
export type PieChartFactory = Factory<{
|
|
59
59
|
props: PieChartProps;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mantine/charts",
|
|
3
|
-
"version": "9.0.0
|
|
3
|
+
"version": "9.0.0",
|
|
4
4
|
"description": "Charts components built with recharts and Mantine",
|
|
5
5
|
"homepage": "https://mantine.dev/",
|
|
6
6
|
"license": "MIT",
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
"directory": "packages/@mantine/charts"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
|
-
"@mantine/core": "9.0.0
|
|
39
|
-
"@mantine/hooks": "9.0.0
|
|
38
|
+
"@mantine/core": "9.0.0",
|
|
39
|
+
"@mantine/hooks": "9.0.0",
|
|
40
40
|
"react": "^19.2.0",
|
|
41
41
|
"react-dom": "^19.2.0",
|
|
42
42
|
"recharts": ">=3.2.1"
|
|
@@ -1,202 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
|
|
3
|
-
const require_ChartTooltip = require("../ChartTooltip/ChartTooltip.cjs");
|
|
4
|
-
const require_SankeyChart_module = require("./SankeyChart.module.cjs");
|
|
5
|
-
let _mantine_core = require("@mantine/core");
|
|
6
|
-
let react_jsx_runtime = require("react/jsx-runtime");
|
|
7
|
-
let react = require("react");
|
|
8
|
-
react = require_runtime.__toESM(react);
|
|
9
|
-
let recharts = require("recharts");
|
|
10
|
-
//#region packages/@mantine/charts/src/SankeyChart/SankeyChart.tsx
|
|
11
|
-
const defaultProps = {
|
|
12
|
-
height: 300,
|
|
13
|
-
nodeWidth: 10,
|
|
14
|
-
nodePadding: 10,
|
|
15
|
-
linkCurvature: .5,
|
|
16
|
-
iterations: 32,
|
|
17
|
-
linkOpacity: .4,
|
|
18
|
-
withTooltip: true,
|
|
19
|
-
tooltipAnimationDuration: 0
|
|
20
|
-
};
|
|
21
|
-
const varsResolver = (0, _mantine_core.createVarsResolver)((theme, { nodeColor, linkColor, textColor, height }) => ({ root: {
|
|
22
|
-
"--chart-node-color": nodeColor ? (0, _mantine_core.getThemeColor)(nodeColor, theme) : void 0,
|
|
23
|
-
"--chart-link-color": linkColor ? (0, _mantine_core.getThemeColor)(linkColor, theme) : void 0,
|
|
24
|
-
"--chart-text-color": textColor ? (0, _mantine_core.getThemeColor)(textColor, theme) : void 0,
|
|
25
|
-
"--chart-height": (0, _mantine_core.rem)(height)
|
|
26
|
-
} }));
|
|
27
|
-
const DEFAULT_COLORS = [
|
|
28
|
-
"var(--mantine-color-blue-filled)",
|
|
29
|
-
"var(--mantine-color-cyan-filled)",
|
|
30
|
-
"var(--mantine-color-teal-filled)",
|
|
31
|
-
"var(--mantine-color-green-filled)",
|
|
32
|
-
"var(--mantine-color-lime-filled)",
|
|
33
|
-
"var(--mantine-color-yellow-filled)",
|
|
34
|
-
"var(--mantine-color-orange-filled)",
|
|
35
|
-
"var(--mantine-color-red-filled)",
|
|
36
|
-
"var(--mantine-color-pink-filled)",
|
|
37
|
-
"var(--mantine-color-grape-filled)",
|
|
38
|
-
"var(--mantine-color-violet-filled)",
|
|
39
|
-
"var(--mantine-color-indigo-filled)"
|
|
40
|
-
];
|
|
41
|
-
function SankeyNodeContent({ x, y, width, height, index, payload, resolvedNodeColors, resolvedDefaultColors, valueFormatter }) {
|
|
42
|
-
const fill = resolvedNodeColors[index] || `var(--chart-node-color, ${resolvedDefaultColors[index % resolvedDefaultColors.length]})`;
|
|
43
|
-
const isLeaf = !payload.targetNodes || payload.targetNodes.length === 0;
|
|
44
|
-
const labelX = isLeaf ? x - 6 : x + width + 6;
|
|
45
|
-
const textAnchor = isLeaf ? "end" : "start";
|
|
46
|
-
const formattedValue = valueFormatter ? valueFormatter(payload.value) : payload.value;
|
|
47
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("g", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("rect", {
|
|
48
|
-
x,
|
|
49
|
-
y,
|
|
50
|
-
width,
|
|
51
|
-
height,
|
|
52
|
-
fill,
|
|
53
|
-
stroke: "none"
|
|
54
|
-
}), height >= 28 ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("text", {
|
|
55
|
-
x: labelX,
|
|
56
|
-
y: y + height / 2 - 7,
|
|
57
|
-
textAnchor,
|
|
58
|
-
dominantBaseline: "central",
|
|
59
|
-
fill: "var(--chart-text-color, var(--mantine-color-text))",
|
|
60
|
-
fontSize: 12,
|
|
61
|
-
fontFamily: "var(--mantine-font-family)",
|
|
62
|
-
children: payload.name
|
|
63
|
-
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("text", {
|
|
64
|
-
x: labelX,
|
|
65
|
-
y: y + height / 2 + 7,
|
|
66
|
-
textAnchor,
|
|
67
|
-
dominantBaseline: "central",
|
|
68
|
-
fill: "var(--chart-text-color, var(--mantine-color-text))",
|
|
69
|
-
fontSize: 12,
|
|
70
|
-
fontFamily: "var(--mantine-font-family)",
|
|
71
|
-
opacity: .8,
|
|
72
|
-
children: formattedValue
|
|
73
|
-
})] }) : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("text", {
|
|
74
|
-
x: labelX,
|
|
75
|
-
y: y + height / 2,
|
|
76
|
-
textAnchor,
|
|
77
|
-
dominantBaseline: "central",
|
|
78
|
-
fill: "var(--chart-text-color, var(--mantine-color-text))",
|
|
79
|
-
fontSize: 12,
|
|
80
|
-
fontFamily: "var(--mantine-font-family)",
|
|
81
|
-
children: [
|
|
82
|
-
payload.name,
|
|
83
|
-
" ",
|
|
84
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("tspan", {
|
|
85
|
-
opacity: .8,
|
|
86
|
-
children: formattedValue
|
|
87
|
-
})
|
|
88
|
-
]
|
|
89
|
-
})] });
|
|
90
|
-
}
|
|
91
|
-
function SankeyLinkContent({ sourceX, targetX, sourceY, targetY, sourceControlX, targetControlX, linkWidth, sourceResolvedColor, linkOpacity }) {
|
|
92
|
-
const fill = sourceResolvedColor || "var(--chart-link-color, var(--mantine-color-gray-4))";
|
|
93
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
|
|
94
|
-
d: `
|
|
95
|
-
M${sourceX},${sourceY + linkWidth / 2}
|
|
96
|
-
C${sourceControlX},${sourceY + linkWidth / 2}
|
|
97
|
-
${targetControlX},${targetY + linkWidth / 2}
|
|
98
|
-
${targetX},${targetY + linkWidth / 2}
|
|
99
|
-
L${targetX},${targetY - linkWidth / 2}
|
|
100
|
-
C${targetControlX},${targetY - linkWidth / 2}
|
|
101
|
-
${sourceControlX},${sourceY - linkWidth / 2}
|
|
102
|
-
${sourceX},${sourceY - linkWidth / 2}
|
|
103
|
-
Z
|
|
104
|
-
`,
|
|
105
|
-
fill,
|
|
106
|
-
opacity: linkOpacity,
|
|
107
|
-
stroke: "none"
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
const SankeyChart = (0, _mantine_core.factory)((_props) => {
|
|
111
|
-
const props = (0, _mantine_core.useProps)("SankeyChart", defaultProps, _props);
|
|
112
|
-
const { classNames, className, style, styles, unstyled, vars, data, height: chartHeight, nodeWidth, nodePadding, linkCurvature, iterations, nodeColor, colors, linkColor, linkOpacity, textColor, withTooltip, tooltipAnimationDuration, tooltipProps, sankeyProps, valueFormatter, children, attributes, ...others } = props;
|
|
113
|
-
const theme = (0, _mantine_core.useMantineTheme)();
|
|
114
|
-
const resolvedNodeColors = {};
|
|
115
|
-
data.nodes.forEach((node, index) => {
|
|
116
|
-
if (node.color) resolvedNodeColors[index] = (0, _mantine_core.getThemeColor)(node.color, theme);
|
|
117
|
-
});
|
|
118
|
-
const resolvedDefaultColors = colors ? colors.map((color) => (0, _mantine_core.getThemeColor)(color, theme)) : DEFAULT_COLORS;
|
|
119
|
-
const getStyles = (0, _mantine_core.useStyles)({
|
|
120
|
-
name: "SankeyChart",
|
|
121
|
-
classes: require_SankeyChart_module.default,
|
|
122
|
-
props,
|
|
123
|
-
className,
|
|
124
|
-
style,
|
|
125
|
-
classNames,
|
|
126
|
-
styles,
|
|
127
|
-
unstyled,
|
|
128
|
-
attributes,
|
|
129
|
-
vars,
|
|
130
|
-
varsResolver
|
|
131
|
-
});
|
|
132
|
-
const { resolvedClassNames, resolvedStyles } = (0, _mantine_core.useResolvedStylesApi)({
|
|
133
|
-
classNames,
|
|
134
|
-
styles,
|
|
135
|
-
props
|
|
136
|
-
});
|
|
137
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_mantine_core.Box, {
|
|
138
|
-
...getStyles("root"),
|
|
139
|
-
...others,
|
|
140
|
-
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(recharts.ResponsiveContainer, {
|
|
141
|
-
height: chartHeight,
|
|
142
|
-
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(recharts.Sankey, {
|
|
143
|
-
data,
|
|
144
|
-
nodeWidth,
|
|
145
|
-
nodePadding,
|
|
146
|
-
linkCurvature,
|
|
147
|
-
iterations,
|
|
148
|
-
node: (nodeProps) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SankeyNodeContent, {
|
|
149
|
-
...nodeProps,
|
|
150
|
-
resolvedNodeColors,
|
|
151
|
-
resolvedDefaultColors,
|
|
152
|
-
valueFormatter
|
|
153
|
-
}),
|
|
154
|
-
link: (linkProps) => {
|
|
155
|
-
const sourceIndex = linkProps.index >= 0 && linkProps.index < data.links.length ? data.links[linkProps.index].source : -1;
|
|
156
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SankeyLinkContent, {
|
|
157
|
-
...linkProps,
|
|
158
|
-
sourceResolvedColor: resolvedNodeColors[sourceIndex],
|
|
159
|
-
linkOpacity
|
|
160
|
-
});
|
|
161
|
-
},
|
|
162
|
-
...sankeyProps,
|
|
163
|
-
children: [withTooltip && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(recharts.Tooltip, {
|
|
164
|
-
animationDuration: tooltipAnimationDuration,
|
|
165
|
-
isAnimationActive: false,
|
|
166
|
-
content: ({ payload }) => {
|
|
167
|
-
const resolveColor = (item) => {
|
|
168
|
-
const nodeIndex = data.nodes.findIndex((n) => n.name === item.name);
|
|
169
|
-
if (nodeIndex !== -1) return resolvedNodeColors[nodeIndex] || resolvedDefaultColors[nodeIndex % resolvedDefaultColors.length];
|
|
170
|
-
const sourceNode = item.payload?.source;
|
|
171
|
-
if (sourceNode) {
|
|
172
|
-
const sourceIndex = data.nodes.findIndex((n) => n.name === sourceNode.name);
|
|
173
|
-
if (sourceIndex !== -1) return resolvedNodeColors[sourceIndex] || resolvedDefaultColors[sourceIndex % resolvedDefaultColors.length];
|
|
174
|
-
}
|
|
175
|
-
return "var(--mantine-color-blue-6)";
|
|
176
|
-
};
|
|
177
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_ChartTooltip.ChartTooltip, {
|
|
178
|
-
payload: payload?.map((item) => ({
|
|
179
|
-
name: item.name,
|
|
180
|
-
value: item.value,
|
|
181
|
-
color: resolveColor(item)
|
|
182
|
-
})) || [],
|
|
183
|
-
classNames: resolvedClassNames,
|
|
184
|
-
styles: resolvedStyles,
|
|
185
|
-
type: "radial",
|
|
186
|
-
valueFormatter,
|
|
187
|
-
attributes
|
|
188
|
-
});
|
|
189
|
-
},
|
|
190
|
-
...tooltipProps
|
|
191
|
-
}), children]
|
|
192
|
-
})
|
|
193
|
-
})
|
|
194
|
-
});
|
|
195
|
-
});
|
|
196
|
-
SankeyChart.displayName = "@mantine/charts/SankeyChart";
|
|
197
|
-
SankeyChart.classes = require_SankeyChart_module.default;
|
|
198
|
-
SankeyChart.varsResolver = varsResolver;
|
|
199
|
-
//#endregion
|
|
200
|
-
exports.SankeyChart = SankeyChart;
|
|
201
|
-
|
|
202
|
-
//# sourceMappingURL=SankeyChart.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SankeyChart.cjs","names":["Box","ResponsiveContainer","RechartsSankey","Tooltip","ChartTooltip","classes"],"sources":["../../src/SankeyChart/SankeyChart.tsx"],"sourcesContent":["import React from 'react';\nimport {\n Sankey as RechartsSankey,\n SankeyProps as RechartsSankeyProps,\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 rem,\n StylesApiProps,\n useMantineTheme,\n useProps,\n useResolvedStylesApi,\n useStyles,\n} from '@mantine/core';\nimport { ChartTooltip, ChartTooltipStylesNames } from '../ChartTooltip/ChartTooltip';\nimport classes from './SankeyChart.module.css';\n\nexport interface SankeyChartNode {\n name: string;\n color?: MantineColor;\n [key: string]: unknown;\n}\n\nexport interface SankeyChartLink {\n source: number;\n target: number;\n value: number;\n [key: string]: unknown;\n}\n\nexport interface SankeyChartData {\n nodes: SankeyChartNode[];\n links: SankeyChartLink[];\n}\n\nexport type SankeyChartStylesNames = 'root' | ChartTooltipStylesNames;\nexport type SankeyChartCssVariables = {\n root: '--chart-node-color' | '--chart-link-color' | '--chart-text-color' | '--chart-height';\n};\n\nexport interface SankeyChartProps\n extends BoxProps, StylesApiProps<SankeyChartFactory>, ElementProps<'div'> {\n /** Data used to render chart, must include `nodes` and `links` arrays */\n data: SankeyChartData;\n\n /** Controls chart height @default 300 */\n height?: number;\n\n /** The width of each node @default 10 */\n nodeWidth?: number;\n\n /** The padding between nodes @default 10 */\n nodePadding?: number;\n\n /** The curvature of links between nodes @default 0.5 */\n linkCurvature?: number;\n\n /** The number of relaxation iterations @default 32 */\n iterations?: number;\n\n /** Default color for nodes, by default depends on color scheme */\n nodeColor?: MantineColor;\n\n /** An array of colors used for nodes when no `color` is set on individual nodes */\n colors?: MantineColor[];\n\n /** Default color for links, by default depends on color scheme */\n linkColor?: MantineColor;\n\n /** Opacity of the link fill @default 0.4 */\n linkOpacity?: number;\n\n /** Determines whether the tooltip should be displayed when 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 `Sankey` component */\n sankeyProps?: Partial<Omit<RechartsSankeyProps, 'ref' | 'data'>>;\n\n /** Controls text color of labels @default dimmed */\n textColor?: MantineColor;\n\n /** A function to format values inside the tooltip and node labels */\n valueFormatter?: (value: number) => string;\n\n /** Additional elements rendered inside `Sankey` component */\n children?: React.ReactNode;\n}\n\nexport type SankeyChartFactory = Factory<{\n props: SankeyChartProps;\n ref: HTMLDivElement;\n stylesNames: SankeyChartStylesNames;\n vars: SankeyChartCssVariables;\n}>;\n\nconst defaultProps = {\n height: 300,\n nodeWidth: 10,\n nodePadding: 10,\n linkCurvature: 0.5,\n iterations: 32,\n linkOpacity: 0.4,\n withTooltip: true,\n tooltipAnimationDuration: 0,\n} satisfies Partial<SankeyChartProps>;\n\nconst varsResolver = createVarsResolver<SankeyChartFactory>(\n (theme, { nodeColor, linkColor, textColor, height }) => ({\n root: {\n '--chart-node-color': nodeColor ? getThemeColor(nodeColor, theme) : undefined,\n '--chart-link-color': linkColor ? getThemeColor(linkColor, theme) : undefined,\n '--chart-text-color': textColor ? getThemeColor(textColor, theme) : undefined,\n '--chart-height': rem(height),\n },\n })\n);\n\ninterface SankeyNodeContentProps {\n x: number;\n y: number;\n width: number;\n height: number;\n index: number;\n payload: { name: string; value: number; targetNodes: number[]; color?: string };\n resolvedNodeColors: Record<number, string>;\n resolvedDefaultColors: string[];\n valueFormatter?: (value: number) => string;\n}\n\nconst DEFAULT_COLORS = [\n 'var(--mantine-color-blue-filled)',\n 'var(--mantine-color-cyan-filled)',\n 'var(--mantine-color-teal-filled)',\n 'var(--mantine-color-green-filled)',\n 'var(--mantine-color-lime-filled)',\n 'var(--mantine-color-yellow-filled)',\n 'var(--mantine-color-orange-filled)',\n 'var(--mantine-color-red-filled)',\n 'var(--mantine-color-pink-filled)',\n 'var(--mantine-color-grape-filled)',\n 'var(--mantine-color-violet-filled)',\n 'var(--mantine-color-indigo-filled)',\n];\n\nfunction SankeyNodeContent({\n x,\n y,\n width,\n height,\n index,\n payload,\n resolvedNodeColors,\n resolvedDefaultColors,\n valueFormatter,\n}: SankeyNodeContentProps) {\n const fill =\n resolvedNodeColors[index] ||\n `var(--chart-node-color, ${resolvedDefaultColors[index % resolvedDefaultColors.length]})`;\n\n const isLeaf = !payload.targetNodes || payload.targetNodes.length === 0;\n const labelX = isLeaf ? x - 6 : x + width + 6;\n const textAnchor = isLeaf ? 'end' : 'start';\n const formattedValue = valueFormatter ? valueFormatter(payload.value) : payload.value;\n const stacked = height >= 28;\n\n return (\n <g>\n <rect x={x} y={y} width={width} height={height} fill={fill} stroke=\"none\" />\n {stacked ? (\n <>\n <text\n x={labelX}\n y={y + height / 2 - 7}\n textAnchor={textAnchor}\n dominantBaseline=\"central\"\n fill=\"var(--chart-text-color, var(--mantine-color-text))\"\n fontSize={12}\n fontFamily=\"var(--mantine-font-family)\"\n >\n {payload.name}\n </text>\n <text\n x={labelX}\n y={y + height / 2 + 7}\n textAnchor={textAnchor}\n dominantBaseline=\"central\"\n fill=\"var(--chart-text-color, var(--mantine-color-text))\"\n fontSize={12}\n fontFamily=\"var(--mantine-font-family)\"\n opacity={0.8}\n >\n {formattedValue}\n </text>\n </>\n ) : (\n <text\n x={labelX}\n y={y + height / 2}\n textAnchor={textAnchor}\n dominantBaseline=\"central\"\n fill=\"var(--chart-text-color, var(--mantine-color-text))\"\n fontSize={12}\n fontFamily=\"var(--mantine-font-family)\"\n >\n {payload.name} <tspan opacity={0.8}>{formattedValue}</tspan>\n </text>\n )}\n </g>\n );\n}\n\ninterface SankeyLinkContentProps {\n sourceX: number;\n targetX: number;\n sourceY: number;\n targetY: number;\n sourceControlX: number;\n targetControlX: number;\n linkWidth: number;\n index: number;\n payload: {\n source: { color?: string };\n target: { color?: string };\n };\n sourceResolvedColor?: string;\n linkOpacity: number;\n}\n\nfunction SankeyLinkContent({\n sourceX,\n targetX,\n sourceY,\n targetY,\n sourceControlX,\n targetControlX,\n linkWidth,\n sourceResolvedColor,\n linkOpacity,\n}: SankeyLinkContentProps) {\n const fill = sourceResolvedColor || 'var(--chart-link-color, var(--mantine-color-gray-4))';\n\n return (\n <path\n d={`\n M${sourceX},${sourceY + linkWidth / 2}\n C${sourceControlX},${sourceY + linkWidth / 2}\n ${targetControlX},${targetY + linkWidth / 2}\n ${targetX},${targetY + linkWidth / 2}\n L${targetX},${targetY - linkWidth / 2}\n C${targetControlX},${targetY - linkWidth / 2}\n ${sourceControlX},${sourceY - linkWidth / 2}\n ${sourceX},${sourceY - linkWidth / 2}\n Z\n `}\n fill={fill}\n opacity={linkOpacity}\n stroke=\"none\"\n />\n );\n}\n\nexport const SankeyChart = factory<SankeyChartFactory>((_props) => {\n const props = useProps('SankeyChart', defaultProps, _props);\n const {\n classNames,\n className,\n style,\n styles,\n unstyled,\n vars,\n data,\n height: chartHeight,\n nodeWidth,\n nodePadding,\n linkCurvature,\n iterations,\n nodeColor,\n colors,\n linkColor,\n linkOpacity,\n textColor,\n withTooltip,\n tooltipAnimationDuration,\n tooltipProps,\n sankeyProps,\n valueFormatter,\n children,\n attributes,\n ...others\n } = props;\n\n const theme = useMantineTheme();\n\n const resolvedNodeColors: Record<number, string> = {};\n data.nodes.forEach((node, index) => {\n if (node.color) {\n resolvedNodeColors[index] = getThemeColor(node.color, theme);\n }\n });\n\n const resolvedDefaultColors = colors\n ? colors.map((color) => getThemeColor(color, theme))\n : DEFAULT_COLORS;\n\n const getStyles = useStyles<SankeyChartFactory>({\n name: 'SankeyChart',\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<SankeyChartFactory>({\n classNames,\n styles,\n props,\n });\n\n return (\n <Box {...getStyles('root')} {...others}>\n <ResponsiveContainer height={chartHeight}>\n <RechartsSankey\n data={data as any}\n nodeWidth={nodeWidth}\n nodePadding={nodePadding}\n linkCurvature={linkCurvature}\n iterations={iterations}\n node={(nodeProps: any) => (\n <SankeyNodeContent\n {...nodeProps}\n resolvedNodeColors={resolvedNodeColors}\n resolvedDefaultColors={resolvedDefaultColors}\n valueFormatter={valueFormatter}\n />\n )}\n link={(linkProps: any) => {\n const sourceIndex =\n linkProps.index >= 0 && linkProps.index < data.links.length\n ? data.links[linkProps.index].source\n : -1;\n return (\n <SankeyLinkContent\n {...linkProps}\n sourceResolvedColor={resolvedNodeColors[sourceIndex]}\n linkOpacity={linkOpacity!}\n />\n );\n }}\n {...sankeyProps}\n >\n {withTooltip && (\n <Tooltip\n animationDuration={tooltipAnimationDuration}\n isAnimationActive={false}\n content={({ payload }) => {\n const resolveColor = (item: any) => {\n const nodeIndex = data.nodes.findIndex((n) => n.name === item.name);\n if (nodeIndex !== -1) {\n return (\n resolvedNodeColors[nodeIndex] ||\n resolvedDefaultColors[nodeIndex % resolvedDefaultColors.length]\n );\n }\n\n const sourceNode = item.payload?.source;\n if (sourceNode) {\n const sourceIndex = data.nodes.findIndex((n) => n.name === sourceNode.name);\n if (sourceIndex !== -1) {\n return (\n resolvedNodeColors[sourceIndex] ||\n resolvedDefaultColors[sourceIndex % resolvedDefaultColors.length]\n );\n }\n }\n\n return 'var(--mantine-color-blue-6)';\n };\n\n return (\n <ChartTooltip\n payload={\n payload?.map((item) => ({\n name: item.name as string,\n value: item.value as number,\n color: resolveColor(item),\n })) || []\n }\n classNames={resolvedClassNames}\n styles={resolvedStyles}\n type=\"radial\"\n valueFormatter={valueFormatter}\n attributes={attributes}\n />\n );\n }}\n {...tooltipProps}\n />\n )}\n\n {children}\n </RechartsSankey>\n </ResponsiveContainer>\n </Box>\n );\n});\n\nSankeyChart.displayName = '@mantine/charts/SankeyChart';\nSankeyChart.classes = classes;\nSankeyChart.varsResolver = varsResolver;\n"],"mappings":";;;;;;;;;;AA+GA,MAAM,eAAe;CACnB,QAAQ;CACR,WAAW;CACX,aAAa;CACb,eAAe;CACf,YAAY;CACZ,aAAa;CACb,aAAa;CACb,0BAA0B;CAC3B;AAED,MAAM,gBAAA,GAAA,cAAA,qBACH,OAAO,EAAE,WAAW,WAAW,WAAW,cAAc,EACvD,MAAM;CACJ,sBAAsB,aAAA,GAAA,cAAA,eAA0B,WAAW,MAAM,GAAG,KAAA;CACpE,sBAAsB,aAAA,GAAA,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;QACtB,MAAM,KAAK;QACX,OAAO,KAAK;QACZ,OAAO,aAAa,KAAK;QAC1B,EAAE,IAAI,EAAE;OAEX,YAAY;OACZ,QAAQ;OACR,MAAK;OACW;OACJ;OACZ,CAAA;;KAGN,GAAI;KACJ,CAAA,EAGH,SACc;;GACG,CAAA;EAClB,CAAA;EAER;AAEF,YAAY,cAAc;AAC1B,YAAY,UAAUC,2BAAAA;AACtB,YAAY,eAAe"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SankeyChart.module.cjs","names":[],"sources":["../../src/SankeyChart/SankeyChart.module.css"],"sourcesContent":[".root {\n min-height: var(--chart-height, auto);\n\n & :where(*) {\n outline: 0;\n }\n\n @mixin where-light {\n --chart-link-color: var(--mantine-color-gray-1);\n }\n\n @mixin where-dark {\n --chart-link-color: var(--mantine-color-dark-5);\n }\n}\n"],"mappings":""}
|