@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
package/cjs/Treemap/Treemap.cjs
DELETED
|
@@ -1,133 +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_Treemap_module = require("./Treemap.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/Treemap/Treemap.tsx
|
|
11
|
-
const defaultProps = {
|
|
12
|
-
dataKey: "value",
|
|
13
|
-
withTooltip: true,
|
|
14
|
-
tooltipAnimationDuration: 0,
|
|
15
|
-
height: 300,
|
|
16
|
-
strokeWidth: 1,
|
|
17
|
-
aspectRatio: .5 * (1 + Math.sqrt(5))
|
|
18
|
-
};
|
|
19
|
-
const varsResolver = (0, _mantine_core.createVarsResolver)((theme, { strokeColor, height }) => ({ root: {
|
|
20
|
-
"--chart-stroke-color": strokeColor ? (0, _mantine_core.getThemeColor)(strokeColor, theme) : void 0,
|
|
21
|
-
"--chart-height": (0, _mantine_core.rem)(height)
|
|
22
|
-
} }));
|
|
23
|
-
function TreemapContent({ x, y, width, height, depth, name, resolvedColors, resolvedLabelColors, index, strokeWidth }) {
|
|
24
|
-
const fill = resolvedColors[name] || `var(--mantine-color-blue-${index % 9 + 1})`;
|
|
25
|
-
const labelColor = resolvedLabelColors[name] || "var(--mantine-color-white)";
|
|
26
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("g", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("rect", {
|
|
27
|
-
x,
|
|
28
|
-
y,
|
|
29
|
-
width,
|
|
30
|
-
height,
|
|
31
|
-
fill: depth >= 1 ? fill : "transparent",
|
|
32
|
-
stroke: "var(--chart-stroke-color, var(--mantine-color-body))",
|
|
33
|
-
strokeWidth: depth >= 1 ? strokeWidth : 0
|
|
34
|
-
}), depth >= 1 && width > 30 && height > 20 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("text", {
|
|
35
|
-
x: x + width / 2,
|
|
36
|
-
y: y + height / 2,
|
|
37
|
-
textAnchor: "middle",
|
|
38
|
-
dominantBaseline: "central",
|
|
39
|
-
fill: labelColor,
|
|
40
|
-
fontSize: 12,
|
|
41
|
-
fontFamily: "var(--mantine-font-family)",
|
|
42
|
-
children: name
|
|
43
|
-
})] });
|
|
44
|
-
}
|
|
45
|
-
function resolveColors(data, theme, parentColor) {
|
|
46
|
-
const result = {};
|
|
47
|
-
for (const item of data) {
|
|
48
|
-
const color = item.color || parentColor;
|
|
49
|
-
if (color) result[item.name] = (0, _mantine_core.parseThemeColor)({
|
|
50
|
-
color,
|
|
51
|
-
theme
|
|
52
|
-
}).value;
|
|
53
|
-
if (item.children) Object.assign(result, resolveColors(item.children, theme, color));
|
|
54
|
-
}
|
|
55
|
-
return result;
|
|
56
|
-
}
|
|
57
|
-
function resolveLabelColors(resolvedColors, autoContrast, luminanceThreshold, textColor) {
|
|
58
|
-
const result = {};
|
|
59
|
-
for (const [name, color] of Object.entries(resolvedColors)) if (textColor) result[name] = textColor;
|
|
60
|
-
else if (autoContrast) result[name] = (0, _mantine_core.isLightColor)(color, luminanceThreshold) ? "var(--mantine-color-black)" : "var(--mantine-color-white)";
|
|
61
|
-
return result;
|
|
62
|
-
}
|
|
63
|
-
const Treemap = (0, _mantine_core.factory)((_props) => {
|
|
64
|
-
const props = (0, _mantine_core.useProps)("Treemap", defaultProps, _props);
|
|
65
|
-
const { classNames, className, style, styles, unstyled, vars, data, dataKey, aspectRatio, withTooltip, tooltipAnimationDuration, tooltipProps, treemapProps, strokeColor, textColor, height: chartHeight, strokeWidth, valueFormatter, autoContrast, children, attributes, ...others } = props;
|
|
66
|
-
const theme = (0, _mantine_core.useMantineTheme)();
|
|
67
|
-
const resolvedColors = resolveColors(data, theme);
|
|
68
|
-
const _autoContrast = (0, _mantine_core.getAutoContrastValue)(autoContrast, theme);
|
|
69
|
-
const _textColor = textColor ? (0, _mantine_core.getThemeColor)(textColor, theme) : void 0;
|
|
70
|
-
const resolvedLabelColors = resolveLabelColors(resolvedColors, _autoContrast, theme.luminanceThreshold, _textColor);
|
|
71
|
-
const getStyles = (0, _mantine_core.useStyles)({
|
|
72
|
-
name: "Treemap",
|
|
73
|
-
classes: require_Treemap_module.default,
|
|
74
|
-
props,
|
|
75
|
-
className,
|
|
76
|
-
style,
|
|
77
|
-
classNames,
|
|
78
|
-
styles,
|
|
79
|
-
unstyled,
|
|
80
|
-
attributes,
|
|
81
|
-
vars,
|
|
82
|
-
varsResolver
|
|
83
|
-
});
|
|
84
|
-
const { resolvedClassNames, resolvedStyles } = (0, _mantine_core.useResolvedStylesApi)({
|
|
85
|
-
classNames,
|
|
86
|
-
styles,
|
|
87
|
-
props
|
|
88
|
-
});
|
|
89
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_mantine_core.Box, {
|
|
90
|
-
...getStyles("root"),
|
|
91
|
-
...others,
|
|
92
|
-
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(recharts.ResponsiveContainer, {
|
|
93
|
-
height: chartHeight,
|
|
94
|
-
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(recharts.Treemap, {
|
|
95
|
-
data,
|
|
96
|
-
dataKey,
|
|
97
|
-
aspectRatio,
|
|
98
|
-
isAnimationActive: false,
|
|
99
|
-
content: (nodeProps) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TreemapContent, {
|
|
100
|
-
...nodeProps,
|
|
101
|
-
resolvedColors,
|
|
102
|
-
resolvedLabelColors,
|
|
103
|
-
strokeWidth
|
|
104
|
-
}),
|
|
105
|
-
...treemapProps,
|
|
106
|
-
children: [withTooltip && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(recharts.Tooltip, {
|
|
107
|
-
animationDuration: tooltipAnimationDuration,
|
|
108
|
-
isAnimationActive: false,
|
|
109
|
-
content: ({ payload }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_ChartTooltip.ChartTooltip, {
|
|
110
|
-
payload: payload?.map((item) => ({
|
|
111
|
-
name: item.name,
|
|
112
|
-
value: item.value,
|
|
113
|
-
color: resolvedColors[item.name] || "var(--mantine-color-blue-6)"
|
|
114
|
-
})) || [],
|
|
115
|
-
classNames: resolvedClassNames,
|
|
116
|
-
styles: resolvedStyles,
|
|
117
|
-
type: "radial",
|
|
118
|
-
valueFormatter,
|
|
119
|
-
attributes
|
|
120
|
-
}),
|
|
121
|
-
...tooltipProps
|
|
122
|
-
}), children]
|
|
123
|
-
})
|
|
124
|
-
})
|
|
125
|
-
});
|
|
126
|
-
});
|
|
127
|
-
Treemap.displayName = "@mantine/charts/Treemap";
|
|
128
|
-
Treemap.classes = require_Treemap_module.default;
|
|
129
|
-
Treemap.varsResolver = varsResolver;
|
|
130
|
-
//#endregion
|
|
131
|
-
exports.Treemap = Treemap;
|
|
132
|
-
|
|
133
|
-
//# sourceMappingURL=Treemap.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Treemap.cjs","names":["Box","ResponsiveContainer","RechartsTreemap","Tooltip","ChartTooltip","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>(\n (theme, { strokeColor, height }) => ({\n root: {\n '--chart-stroke-color': strokeColor ? getThemeColor(strokeColor, theme) : undefined,\n '--chart-height': rem(height),\n },\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:\n 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,EAAE;CACrC;AAED,MAAM,gBAAA,GAAA,cAAA,qBACH,OAAO,EAAE,aAAa,cAAc,EACnC,MAAM;CACJ,wBAAwB,eAAA,GAAA,cAAA,eAA4B,aAAa,MAAM,GAAG,KAAA;CAC1E,mBAAA,GAAA,cAAA,KAAsB,OAAO;CAC9B,EACF,EACF;AAeD,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;AAGhD,QACE,iBAAA,GAAA,kBAAA,MAAC,KAAD,EAAA,UAAA,CACE,iBAAA,GAAA,kBAAA,KAAC,QAAD;EACK;EACA;EACI;EACC;EACR,MAAM,SAAS,IAAI,OAAO;EAC1B,QAAO;EACP,aAAa,SAAS,IAAI,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1B,gBACA,eACA,MAAM,oBACN,WACD;CAED,MAAM,aAAA,GAAA,cAAA,WAAsC;EAC1C,MAAM;EACN,SAAA,uBAAA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACD,CAAC;CAEF,MAAM,EAAE,oBAAoB,oBAAA,GAAA,cAAA,sBAAwD;EAClF;EACA;EACA;EACD,CAAC;AAEF,QACE,iBAAA,GAAA,kBAAA,KAACA,cAAAA,KAAD;EAAK,GAAI,UAAU,OAAO;EAAE,GAAI;YAC9B,iBAAA,GAAA,kBAAA,KAACC,SAAAA,qBAAD;GAAqB,QAAQ;aAC3B,iBAAA,GAAA,kBAAA,MAACC,SAAAA,SAAD;IACQ;IACG;IACI;IACb,mBAAmB;IACnB,UAAU,cACR,iBAAA,GAAA,kBAAA,KAAC,gBAAD;KACE,GAAI;KACY;KACK;KACR;KACb,CAAA;IAEJ,GAAI;cAbN,CAeG,eACC,iBAAA,GAAA,kBAAA,KAACC,SAAAA,SAAD;KACE,mBAAmB;KACnB,mBAAmB;KACnB,UAAU,EAAE,cACV,iBAAA,GAAA,kBAAA,KAACC,qBAAAA,cAAD;MACE,SACE,SAAS,KAAK,UAAU;OACtB,MAAM,KAAK;OACX,OAAO,KAAK;OACZ,OACE,eAAe,KAAK,SAAmB;OAC1C,EAAE,IAAI,EAAE;MAEX,YAAY;MACZ,QAAQ;MACR,MAAK;MACW;MACJ;MACZ,CAAA;KAEJ,GAAI;KACJ,CAAA,EAGH,SACe;;GACE,CAAA;EAClB,CAAA;EAER;AAEF,QAAQ,cAAc;AACtB,QAAQ,UAAUC,uBAAAA;AAClB,QAAQ,eAAe"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Treemap.module.cjs","names":[],"sources":["../../src/Treemap/Treemap.module.css"],"sourcesContent":[".root {\n min-height: var(--chart-height, auto);\n\n & :where(*) {\n outline: 0;\n }\n}\n"],"mappings":""}
|
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { ChartTooltip } from "../ChartTooltip/ChartTooltip.mjs";
|
|
3
|
-
import SankeyChart_module_default from "./SankeyChart.module.mjs";
|
|
4
|
-
import { Box, createVarsResolver, factory, getThemeColor, rem, useMantineTheme, useProps, useResolvedStylesApi, useStyles } from "@mantine/core";
|
|
5
|
-
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
-
import "react";
|
|
7
|
-
import { ResponsiveContainer, Sankey, Tooltip as Tooltip$1 } from "recharts";
|
|
8
|
-
//#region packages/@mantine/charts/src/SankeyChart/SankeyChart.tsx
|
|
9
|
-
const defaultProps = {
|
|
10
|
-
height: 300,
|
|
11
|
-
nodeWidth: 10,
|
|
12
|
-
nodePadding: 10,
|
|
13
|
-
linkCurvature: .5,
|
|
14
|
-
iterations: 32,
|
|
15
|
-
linkOpacity: .4,
|
|
16
|
-
withTooltip: true,
|
|
17
|
-
tooltipAnimationDuration: 0
|
|
18
|
-
};
|
|
19
|
-
const varsResolver = createVarsResolver((theme, { nodeColor, linkColor, textColor, height }) => ({ root: {
|
|
20
|
-
"--chart-node-color": nodeColor ? getThemeColor(nodeColor, theme) : void 0,
|
|
21
|
-
"--chart-link-color": linkColor ? getThemeColor(linkColor, theme) : void 0,
|
|
22
|
-
"--chart-text-color": textColor ? getThemeColor(textColor, theme) : void 0,
|
|
23
|
-
"--chart-height": rem(height)
|
|
24
|
-
} }));
|
|
25
|
-
const DEFAULT_COLORS = [
|
|
26
|
-
"var(--mantine-color-blue-filled)",
|
|
27
|
-
"var(--mantine-color-cyan-filled)",
|
|
28
|
-
"var(--mantine-color-teal-filled)",
|
|
29
|
-
"var(--mantine-color-green-filled)",
|
|
30
|
-
"var(--mantine-color-lime-filled)",
|
|
31
|
-
"var(--mantine-color-yellow-filled)",
|
|
32
|
-
"var(--mantine-color-orange-filled)",
|
|
33
|
-
"var(--mantine-color-red-filled)",
|
|
34
|
-
"var(--mantine-color-pink-filled)",
|
|
35
|
-
"var(--mantine-color-grape-filled)",
|
|
36
|
-
"var(--mantine-color-violet-filled)",
|
|
37
|
-
"var(--mantine-color-indigo-filled)"
|
|
38
|
-
];
|
|
39
|
-
function SankeyNodeContent({ x, y, width, height, index, payload, resolvedNodeColors, resolvedDefaultColors, valueFormatter }) {
|
|
40
|
-
const fill = resolvedNodeColors[index] || `var(--chart-node-color, ${resolvedDefaultColors[index % resolvedDefaultColors.length]})`;
|
|
41
|
-
const isLeaf = !payload.targetNodes || payload.targetNodes.length === 0;
|
|
42
|
-
const labelX = isLeaf ? x - 6 : x + width + 6;
|
|
43
|
-
const textAnchor = isLeaf ? "end" : "start";
|
|
44
|
-
const formattedValue = valueFormatter ? valueFormatter(payload.value) : payload.value;
|
|
45
|
-
return /* @__PURE__ */ jsxs("g", { children: [/* @__PURE__ */ jsx("rect", {
|
|
46
|
-
x,
|
|
47
|
-
y,
|
|
48
|
-
width,
|
|
49
|
-
height,
|
|
50
|
-
fill,
|
|
51
|
-
stroke: "none"
|
|
52
|
-
}), height >= 28 ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("text", {
|
|
53
|
-
x: labelX,
|
|
54
|
-
y: y + height / 2 - 7,
|
|
55
|
-
textAnchor,
|
|
56
|
-
dominantBaseline: "central",
|
|
57
|
-
fill: "var(--chart-text-color, var(--mantine-color-text))",
|
|
58
|
-
fontSize: 12,
|
|
59
|
-
fontFamily: "var(--mantine-font-family)",
|
|
60
|
-
children: payload.name
|
|
61
|
-
}), /* @__PURE__ */ jsx("text", {
|
|
62
|
-
x: labelX,
|
|
63
|
-
y: y + height / 2 + 7,
|
|
64
|
-
textAnchor,
|
|
65
|
-
dominantBaseline: "central",
|
|
66
|
-
fill: "var(--chart-text-color, var(--mantine-color-text))",
|
|
67
|
-
fontSize: 12,
|
|
68
|
-
fontFamily: "var(--mantine-font-family)",
|
|
69
|
-
opacity: .8,
|
|
70
|
-
children: formattedValue
|
|
71
|
-
})] }) : /* @__PURE__ */ jsxs("text", {
|
|
72
|
-
x: labelX,
|
|
73
|
-
y: y + height / 2,
|
|
74
|
-
textAnchor,
|
|
75
|
-
dominantBaseline: "central",
|
|
76
|
-
fill: "var(--chart-text-color, var(--mantine-color-text))",
|
|
77
|
-
fontSize: 12,
|
|
78
|
-
fontFamily: "var(--mantine-font-family)",
|
|
79
|
-
children: [
|
|
80
|
-
payload.name,
|
|
81
|
-
" ",
|
|
82
|
-
/* @__PURE__ */ jsx("tspan", {
|
|
83
|
-
opacity: .8,
|
|
84
|
-
children: formattedValue
|
|
85
|
-
})
|
|
86
|
-
]
|
|
87
|
-
})] });
|
|
88
|
-
}
|
|
89
|
-
function SankeyLinkContent({ sourceX, targetX, sourceY, targetY, sourceControlX, targetControlX, linkWidth, sourceResolvedColor, linkOpacity }) {
|
|
90
|
-
const fill = sourceResolvedColor || "var(--chart-link-color, var(--mantine-color-gray-4))";
|
|
91
|
-
return /* @__PURE__ */ jsx("path", {
|
|
92
|
-
d: `
|
|
93
|
-
M${sourceX},${sourceY + linkWidth / 2}
|
|
94
|
-
C${sourceControlX},${sourceY + linkWidth / 2}
|
|
95
|
-
${targetControlX},${targetY + linkWidth / 2}
|
|
96
|
-
${targetX},${targetY + linkWidth / 2}
|
|
97
|
-
L${targetX},${targetY - linkWidth / 2}
|
|
98
|
-
C${targetControlX},${targetY - linkWidth / 2}
|
|
99
|
-
${sourceControlX},${sourceY - linkWidth / 2}
|
|
100
|
-
${sourceX},${sourceY - linkWidth / 2}
|
|
101
|
-
Z
|
|
102
|
-
`,
|
|
103
|
-
fill,
|
|
104
|
-
opacity: linkOpacity,
|
|
105
|
-
stroke: "none"
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
const SankeyChart = factory((_props) => {
|
|
109
|
-
const props = useProps("SankeyChart", defaultProps, _props);
|
|
110
|
-
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;
|
|
111
|
-
const theme = useMantineTheme();
|
|
112
|
-
const resolvedNodeColors = {};
|
|
113
|
-
data.nodes.forEach((node, index) => {
|
|
114
|
-
if (node.color) resolvedNodeColors[index] = getThemeColor(node.color, theme);
|
|
115
|
-
});
|
|
116
|
-
const resolvedDefaultColors = colors ? colors.map((color) => getThemeColor(color, theme)) : DEFAULT_COLORS;
|
|
117
|
-
const getStyles = useStyles({
|
|
118
|
-
name: "SankeyChart",
|
|
119
|
-
classes: SankeyChart_module_default,
|
|
120
|
-
props,
|
|
121
|
-
className,
|
|
122
|
-
style,
|
|
123
|
-
classNames,
|
|
124
|
-
styles,
|
|
125
|
-
unstyled,
|
|
126
|
-
attributes,
|
|
127
|
-
vars,
|
|
128
|
-
varsResolver
|
|
129
|
-
});
|
|
130
|
-
const { resolvedClassNames, resolvedStyles } = useResolvedStylesApi({
|
|
131
|
-
classNames,
|
|
132
|
-
styles,
|
|
133
|
-
props
|
|
134
|
-
});
|
|
135
|
-
return /* @__PURE__ */ jsx(Box, {
|
|
136
|
-
...getStyles("root"),
|
|
137
|
-
...others,
|
|
138
|
-
children: /* @__PURE__ */ jsx(ResponsiveContainer, {
|
|
139
|
-
height: chartHeight,
|
|
140
|
-
children: /* @__PURE__ */ jsxs(Sankey, {
|
|
141
|
-
data,
|
|
142
|
-
nodeWidth,
|
|
143
|
-
nodePadding,
|
|
144
|
-
linkCurvature,
|
|
145
|
-
iterations,
|
|
146
|
-
node: (nodeProps) => /* @__PURE__ */ jsx(SankeyNodeContent, {
|
|
147
|
-
...nodeProps,
|
|
148
|
-
resolvedNodeColors,
|
|
149
|
-
resolvedDefaultColors,
|
|
150
|
-
valueFormatter
|
|
151
|
-
}),
|
|
152
|
-
link: (linkProps) => {
|
|
153
|
-
const sourceIndex = linkProps.index >= 0 && linkProps.index < data.links.length ? data.links[linkProps.index].source : -1;
|
|
154
|
-
return /* @__PURE__ */ jsx(SankeyLinkContent, {
|
|
155
|
-
...linkProps,
|
|
156
|
-
sourceResolvedColor: resolvedNodeColors[sourceIndex],
|
|
157
|
-
linkOpacity
|
|
158
|
-
});
|
|
159
|
-
},
|
|
160
|
-
...sankeyProps,
|
|
161
|
-
children: [withTooltip && /* @__PURE__ */ jsx(Tooltip$1, {
|
|
162
|
-
animationDuration: tooltipAnimationDuration,
|
|
163
|
-
isAnimationActive: false,
|
|
164
|
-
content: ({ payload }) => {
|
|
165
|
-
const resolveColor = (item) => {
|
|
166
|
-
const nodeIndex = data.nodes.findIndex((n) => n.name === item.name);
|
|
167
|
-
if (nodeIndex !== -1) return resolvedNodeColors[nodeIndex] || resolvedDefaultColors[nodeIndex % resolvedDefaultColors.length];
|
|
168
|
-
const sourceNode = item.payload?.source;
|
|
169
|
-
if (sourceNode) {
|
|
170
|
-
const sourceIndex = data.nodes.findIndex((n) => n.name === sourceNode.name);
|
|
171
|
-
if (sourceIndex !== -1) return resolvedNodeColors[sourceIndex] || resolvedDefaultColors[sourceIndex % resolvedDefaultColors.length];
|
|
172
|
-
}
|
|
173
|
-
return "var(--mantine-color-blue-6)";
|
|
174
|
-
};
|
|
175
|
-
return /* @__PURE__ */ jsx(ChartTooltip, {
|
|
176
|
-
payload: payload?.map((item) => ({
|
|
177
|
-
name: item.name,
|
|
178
|
-
value: item.value,
|
|
179
|
-
color: resolveColor(item)
|
|
180
|
-
})) || [],
|
|
181
|
-
classNames: resolvedClassNames,
|
|
182
|
-
styles: resolvedStyles,
|
|
183
|
-
type: "radial",
|
|
184
|
-
valueFormatter,
|
|
185
|
-
attributes
|
|
186
|
-
});
|
|
187
|
-
},
|
|
188
|
-
...tooltipProps
|
|
189
|
-
}), children]
|
|
190
|
-
})
|
|
191
|
-
})
|
|
192
|
-
});
|
|
193
|
-
});
|
|
194
|
-
SankeyChart.displayName = "@mantine/charts/SankeyChart";
|
|
195
|
-
SankeyChart.classes = SankeyChart_module_default;
|
|
196
|
-
SankeyChart.varsResolver = varsResolver;
|
|
197
|
-
//#endregion
|
|
198
|
-
export { SankeyChart };
|
|
199
|
-
|
|
200
|
-
//# sourceMappingURL=SankeyChart.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SankeyChart.mjs","names":["RechartsSankey","Tooltip","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,eAAe,oBAClB,OAAO,EAAE,WAAW,WAAW,WAAW,cAAc,EACvD,MAAM;CACJ,sBAAsB,YAAY,cAAc,WAAW,MAAM,GAAG,KAAA;CACpE,sBAAsB,YAAY,cAAc,WAAW,MAAM,GAAG,KAAA;CACpE,sBAAsB,YAAY,cAAc,WAAW,MAAM,GAAG,KAAA;CACpE,kBAAkB,IAAI,OAAO;CAC9B,EACF,EACF;AAcD,MAAM,iBAAiB;CACrB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;AAED,SAAS,kBAAkB,EACzB,GACA,GACA,OACA,QACA,OACA,SACA,oBACA,uBACA,kBACyB;CACzB,MAAM,OACJ,mBAAmB,UACnB,2BAA2B,sBAAsB,QAAQ,sBAAsB,QAAQ;CAEzF,MAAM,SAAS,CAAC,QAAQ,eAAe,QAAQ,YAAY,WAAW;CACtE,MAAM,SAAS,SAAS,IAAI,IAAI,IAAI,QAAQ;CAC5C,MAAM,aAAa,SAAS,QAAQ;CACpC,MAAM,iBAAiB,iBAAiB,eAAe,QAAQ,MAAM,GAAG,QAAQ;AAGhF,QACE,qBAAC,KAAD,EAAA,UAAA,CACE,oBAAC,QAAD;EAAS;EAAM;EAAU;EAAe;EAAc;EAAM,QAAO;EAAS,CAAA,EAJhE,UAAU,KAMpB,qBAAA,UAAA,EAAA,UAAA,CACE,oBAAC,QAAD;EACE,GAAG;EACH,GAAG,IAAI,SAAS,IAAI;EACR;EACZ,kBAAiB;EACjB,MAAK;EACL,UAAU;EACV,YAAW;YAEV,QAAQ;EAC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AC1B,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;AACtB,YAAY,eAAe"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
//#region packages/@mantine/charts/src/SankeyChart/SankeyChart.module.css
|
|
3
|
-
var SankeyChart_module_default = { "root": "m_b42d2970" };
|
|
4
|
-
//#endregion
|
|
5
|
-
export { SankeyChart_module_default as default };
|
|
6
|
-
|
|
7
|
-
//# sourceMappingURL=SankeyChart.module.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SankeyChart.module.mjs","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":""}
|
package/esm/Treemap/Treemap.mjs
DELETED
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { ChartTooltip } from "../ChartTooltip/ChartTooltip.mjs";
|
|
3
|
-
import Treemap_module_default from "./Treemap.module.mjs";
|
|
4
|
-
import { Box, createVarsResolver, factory, getAutoContrastValue, getThemeColor, isLightColor, parseThemeColor, rem, useMantineTheme, useProps, useResolvedStylesApi, useStyles } from "@mantine/core";
|
|
5
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
-
import "react";
|
|
7
|
-
import { ResponsiveContainer, Tooltip as Tooltip$1, Treemap } from "recharts";
|
|
8
|
-
//#region packages/@mantine/charts/src/Treemap/Treemap.tsx
|
|
9
|
-
const defaultProps = {
|
|
10
|
-
dataKey: "value",
|
|
11
|
-
withTooltip: true,
|
|
12
|
-
tooltipAnimationDuration: 0,
|
|
13
|
-
height: 300,
|
|
14
|
-
strokeWidth: 1,
|
|
15
|
-
aspectRatio: .5 * (1 + Math.sqrt(5))
|
|
16
|
-
};
|
|
17
|
-
const varsResolver = createVarsResolver((theme, { strokeColor, height }) => ({ root: {
|
|
18
|
-
"--chart-stroke-color": strokeColor ? getThemeColor(strokeColor, theme) : void 0,
|
|
19
|
-
"--chart-height": rem(height)
|
|
20
|
-
} }));
|
|
21
|
-
function TreemapContent({ x, y, width, height, depth, name, resolvedColors, resolvedLabelColors, index, strokeWidth }) {
|
|
22
|
-
const fill = resolvedColors[name] || `var(--mantine-color-blue-${index % 9 + 1})`;
|
|
23
|
-
const labelColor = resolvedLabelColors[name] || "var(--mantine-color-white)";
|
|
24
|
-
return /* @__PURE__ */ jsxs("g", { children: [/* @__PURE__ */ jsx("rect", {
|
|
25
|
-
x,
|
|
26
|
-
y,
|
|
27
|
-
width,
|
|
28
|
-
height,
|
|
29
|
-
fill: depth >= 1 ? fill : "transparent",
|
|
30
|
-
stroke: "var(--chart-stroke-color, var(--mantine-color-body))",
|
|
31
|
-
strokeWidth: depth >= 1 ? strokeWidth : 0
|
|
32
|
-
}), depth >= 1 && width > 30 && height > 20 && /* @__PURE__ */ jsx("text", {
|
|
33
|
-
x: x + width / 2,
|
|
34
|
-
y: y + height / 2,
|
|
35
|
-
textAnchor: "middle",
|
|
36
|
-
dominantBaseline: "central",
|
|
37
|
-
fill: labelColor,
|
|
38
|
-
fontSize: 12,
|
|
39
|
-
fontFamily: "var(--mantine-font-family)",
|
|
40
|
-
children: name
|
|
41
|
-
})] });
|
|
42
|
-
}
|
|
43
|
-
function resolveColors(data, theme, parentColor) {
|
|
44
|
-
const result = {};
|
|
45
|
-
for (const item of data) {
|
|
46
|
-
const color = item.color || parentColor;
|
|
47
|
-
if (color) result[item.name] = parseThemeColor({
|
|
48
|
-
color,
|
|
49
|
-
theme
|
|
50
|
-
}).value;
|
|
51
|
-
if (item.children) Object.assign(result, resolveColors(item.children, theme, color));
|
|
52
|
-
}
|
|
53
|
-
return result;
|
|
54
|
-
}
|
|
55
|
-
function resolveLabelColors(resolvedColors, autoContrast, luminanceThreshold, textColor) {
|
|
56
|
-
const result = {};
|
|
57
|
-
for (const [name, color] of Object.entries(resolvedColors)) if (textColor) result[name] = textColor;
|
|
58
|
-
else if (autoContrast) result[name] = isLightColor(color, luminanceThreshold) ? "var(--mantine-color-black)" : "var(--mantine-color-white)";
|
|
59
|
-
return result;
|
|
60
|
-
}
|
|
61
|
-
const Treemap$1 = factory((_props) => {
|
|
62
|
-
const props = useProps("Treemap", defaultProps, _props);
|
|
63
|
-
const { classNames, className, style, styles, unstyled, vars, data, dataKey, aspectRatio, withTooltip, tooltipAnimationDuration, tooltipProps, treemapProps, strokeColor, textColor, height: chartHeight, strokeWidth, valueFormatter, autoContrast, children, attributes, ...others } = props;
|
|
64
|
-
const theme = useMantineTheme();
|
|
65
|
-
const resolvedColors = resolveColors(data, theme);
|
|
66
|
-
const _autoContrast = getAutoContrastValue(autoContrast, theme);
|
|
67
|
-
const _textColor = textColor ? getThemeColor(textColor, theme) : void 0;
|
|
68
|
-
const resolvedLabelColors = resolveLabelColors(resolvedColors, _autoContrast, theme.luminanceThreshold, _textColor);
|
|
69
|
-
const getStyles = useStyles({
|
|
70
|
-
name: "Treemap",
|
|
71
|
-
classes: Treemap_module_default,
|
|
72
|
-
props,
|
|
73
|
-
className,
|
|
74
|
-
style,
|
|
75
|
-
classNames,
|
|
76
|
-
styles,
|
|
77
|
-
unstyled,
|
|
78
|
-
attributes,
|
|
79
|
-
vars,
|
|
80
|
-
varsResolver
|
|
81
|
-
});
|
|
82
|
-
const { resolvedClassNames, resolvedStyles } = useResolvedStylesApi({
|
|
83
|
-
classNames,
|
|
84
|
-
styles,
|
|
85
|
-
props
|
|
86
|
-
});
|
|
87
|
-
return /* @__PURE__ */ jsx(Box, {
|
|
88
|
-
...getStyles("root"),
|
|
89
|
-
...others,
|
|
90
|
-
children: /* @__PURE__ */ jsx(ResponsiveContainer, {
|
|
91
|
-
height: chartHeight,
|
|
92
|
-
children: /* @__PURE__ */ jsxs(Treemap, {
|
|
93
|
-
data,
|
|
94
|
-
dataKey,
|
|
95
|
-
aspectRatio,
|
|
96
|
-
isAnimationActive: false,
|
|
97
|
-
content: (nodeProps) => /* @__PURE__ */ jsx(TreemapContent, {
|
|
98
|
-
...nodeProps,
|
|
99
|
-
resolvedColors,
|
|
100
|
-
resolvedLabelColors,
|
|
101
|
-
strokeWidth
|
|
102
|
-
}),
|
|
103
|
-
...treemapProps,
|
|
104
|
-
children: [withTooltip && /* @__PURE__ */ jsx(Tooltip$1, {
|
|
105
|
-
animationDuration: tooltipAnimationDuration,
|
|
106
|
-
isAnimationActive: false,
|
|
107
|
-
content: ({ payload }) => /* @__PURE__ */ jsx(ChartTooltip, {
|
|
108
|
-
payload: payload?.map((item) => ({
|
|
109
|
-
name: item.name,
|
|
110
|
-
value: item.value,
|
|
111
|
-
color: resolvedColors[item.name] || "var(--mantine-color-blue-6)"
|
|
112
|
-
})) || [],
|
|
113
|
-
classNames: resolvedClassNames,
|
|
114
|
-
styles: resolvedStyles,
|
|
115
|
-
type: "radial",
|
|
116
|
-
valueFormatter,
|
|
117
|
-
attributes
|
|
118
|
-
}),
|
|
119
|
-
...tooltipProps
|
|
120
|
-
}), children]
|
|
121
|
-
})
|
|
122
|
-
})
|
|
123
|
-
});
|
|
124
|
-
});
|
|
125
|
-
Treemap$1.displayName = "@mantine/charts/Treemap";
|
|
126
|
-
Treemap$1.classes = Treemap_module_default;
|
|
127
|
-
Treemap$1.varsResolver = varsResolver;
|
|
128
|
-
//#endregion
|
|
129
|
-
export { Treemap$1 as Treemap };
|
|
130
|
-
|
|
131
|
-
//# sourceMappingURL=Treemap.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
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>(\n (theme, { strokeColor, height }) => ({\n root: {\n '--chart-stroke-color': strokeColor ? getThemeColor(strokeColor, theme) : undefined,\n '--chart-height': rem(height),\n },\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:\n 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,EAAE;CACrC;AAED,MAAM,eAAe,oBAClB,OAAO,EAAE,aAAa,cAAc,EACnC,MAAM;CACJ,wBAAwB,cAAc,cAAc,aAAa,MAAM,GAAG,KAAA;CAC1E,kBAAkB,IAAI,OAAO;CAC9B,EACF,EACF;AAeD,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;AAGhD,QACE,qBAAC,KAAD,EAAA,UAAA,CACE,oBAAC,QAAD;EACK;EACA;EACI;EACC;EACR,MAAM,SAAS,IAAI,OAAO;EAC1B,QAAO;EACP,aAAa,SAAS,IAAI,cAAc;EACxC,CAAA,EACD,SAAS,KAbI,QAAQ,MAAM,SAAS,MAcnC,oBAAC,QAAD;EACE,GAAG,IAAI,QAAQ;EAC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C;AAEF,QACE,oBAAC,KAAD;EAAK,GAAI,UAAU,OAAO;EAAE,GAAI;YAC9B,oBAAC,qBAAD;GAAqB,QAAQ;aAC3B,qBAACC,SAAD;IACQ;IACG;IACI;IACb,mBAAmB;IACnB,UAAU,cACR,oBAAC,gBAAD;KACE,GAAI;KACY;KACK;KACR;KACb,CAAA;IAEJ,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,OACE,eAAe,KAAK,SAAmB;OAC1C,EAAE,IAAI,EAAE;MAEX,YAAY;MACZ,QAAQ;MACR,MAAK;MACW;MACJ;MACZ,CAAA;KAEJ,GAAI;KACJ,CAAA,EAGH,SACe;;GACE,CAAA;EAClB,CAAA;EAER;AAEF,UAAQ,cAAc;AACtB,UAAQ,UAAUC;AAClB,UAAQ,eAAe"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Treemap.module.mjs","names":[],"sources":["../../src/Treemap/Treemap.module.css"],"sourcesContent":[".root {\n min-height: var(--chart-height, auto);\n\n & :where(*) {\n outline: 0;\n }\n}\n"],"mappings":""}
|