@automattic/charts 0.56.2 → 0.56.4
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/CHANGELOG.md +14 -0
- package/dist/charts/bar-chart/index.cjs +5 -5
- package/dist/charts/bar-chart/index.css +12 -0
- package/dist/charts/bar-chart/index.css.map +1 -1
- package/dist/charts/bar-chart/index.js +4 -4
- package/dist/charts/bar-list-chart/index.cjs +6 -6
- package/dist/charts/bar-list-chart/index.css +12 -0
- package/dist/charts/bar-list-chart/index.css.map +1 -1
- package/dist/charts/bar-list-chart/index.js +5 -5
- package/dist/charts/conversion-funnel-chart/index.cjs +5 -3
- package/dist/charts/conversion-funnel-chart/index.cjs.map +1 -1
- package/dist/charts/conversion-funnel-chart/index.css +14 -1
- package/dist/charts/conversion-funnel-chart/index.css.map +1 -1
- package/dist/charts/conversion-funnel-chart/index.d.cts +2 -0
- package/dist/charts/conversion-funnel-chart/index.d.ts +2 -0
- package/dist/charts/conversion-funnel-chart/index.js +4 -2
- package/dist/charts/geo-chart/index.cjs +4 -4
- package/dist/charts/geo-chart/index.css +12 -0
- package/dist/charts/geo-chart/index.css.map +1 -1
- package/dist/charts/geo-chart/index.js +3 -3
- package/dist/charts/leaderboard-chart/index.cjs +5 -5
- package/dist/charts/leaderboard-chart/index.css +12 -0
- package/dist/charts/leaderboard-chart/index.css.map +1 -1
- package/dist/charts/leaderboard-chart/index.js +4 -4
- package/dist/charts/line-chart/index.cjs +5 -5
- package/dist/charts/line-chart/index.css +12 -0
- package/dist/charts/line-chart/index.css.map +1 -1
- package/dist/charts/line-chart/index.js +4 -4
- package/dist/charts/pie-chart/index.cjs +7 -7
- package/dist/charts/pie-chart/index.css +12 -0
- package/dist/charts/pie-chart/index.css.map +1 -1
- package/dist/charts/pie-chart/index.js +6 -6
- package/dist/charts/pie-semi-circle-chart/index.cjs +7 -7
- package/dist/charts/pie-semi-circle-chart/index.css +12 -0
- package/dist/charts/pie-semi-circle-chart/index.css.map +1 -1
- package/dist/charts/pie-semi-circle-chart/index.js +6 -6
- package/dist/charts/sparkline/index.cjs +6 -6
- package/dist/charts/sparkline/index.css +12 -0
- package/dist/charts/sparkline/index.css.map +1 -1
- package/dist/charts/sparkline/index.js +5 -5
- package/dist/{chunk-OTZT3MC2.cjs → chunk-2A34OA5O.cjs} +19 -20
- package/dist/chunk-2A34OA5O.cjs.map +1 -0
- package/dist/chunk-4YYROZDJ.cjs +375 -0
- package/dist/chunk-4YYROZDJ.cjs.map +1 -0
- package/dist/{chunk-YYQ4IK5V.cjs → chunk-5N77S5N3.cjs} +103 -80
- package/dist/chunk-5N77S5N3.cjs.map +1 -0
- package/dist/chunk-66BXSWMW.cjs +1065 -0
- package/dist/chunk-66BXSWMW.cjs.map +1 -0
- package/dist/{chunk-CEZGL6YP.js → chunk-6CCZL2JJ.js} +15 -7
- package/dist/chunk-6CCZL2JJ.js.map +1 -0
- package/dist/{chunk-NW3RUYK2.cjs → chunk-7QDEU3KN.cjs} +15 -22
- package/dist/chunk-7QDEU3KN.cjs.map +1 -0
- package/dist/{chunk-H34CJSR6.js → chunk-AWNCAKZY.js} +367 -358
- package/dist/chunk-AWNCAKZY.js.map +1 -0
- package/dist/{chunk-5XI443YP.js → chunk-BPYKWMI7.js} +72 -64
- package/dist/chunk-BPYKWMI7.js.map +1 -0
- package/dist/{chunk-7UJPVCMB.cjs → chunk-CERFRCXD.cjs} +265 -262
- package/dist/chunk-CERFRCXD.cjs.map +1 -0
- package/dist/chunk-CMHPXSCI.js +351 -0
- package/dist/chunk-CMHPXSCI.js.map +1 -0
- package/dist/chunk-EBDUXL5K.js +421 -0
- package/dist/chunk-EBDUXL5K.js.map +1 -0
- package/dist/{chunk-2VPPTJS2.js → chunk-FZYJM5PN.js} +256 -253
- package/dist/chunk-FZYJM5PN.js.map +1 -0
- package/dist/chunk-GBDFC74U.cjs +165 -0
- package/dist/chunk-GBDFC74U.cjs.map +1 -0
- package/dist/{chunk-ODF5O5PV.cjs → chunk-HNEG3EFJ.cjs} +154 -170
- package/dist/chunk-HNEG3EFJ.cjs.map +1 -0
- package/dist/{chunk-SRXJLAKG.cjs → chunk-I2276W3I.cjs} +28 -37
- package/dist/chunk-I2276W3I.cjs.map +1 -0
- package/dist/chunk-KKPZ4MVF.js +375 -0
- package/dist/chunk-KKPZ4MVF.js.map +1 -0
- package/dist/chunk-KMYJJTSR.cjs +421 -0
- package/dist/chunk-KMYJJTSR.cjs.map +1 -0
- package/dist/{chunk-A3AEEGKR.js → chunk-KXRWNFQJ.js} +20 -21
- package/dist/chunk-KXRWNFQJ.js.map +1 -0
- package/dist/{chunk-TVV7ZI7C.cjs → chunk-LSV7F26B.cjs} +362 -353
- package/dist/chunk-LSV7F26B.cjs.map +1 -0
- package/dist/{chunk-T4J6TI55.js → chunk-M7PRGJFE.js} +102 -79
- package/dist/chunk-M7PRGJFE.js.map +1 -0
- package/dist/{chunk-TNRKEBTA.js → chunk-PGJAZN2H.js} +148 -164
- package/dist/{chunk-TNRKEBTA.js.map → chunk-PGJAZN2H.js.map} +1 -1
- package/dist/chunk-R23BFDIW.js +1065 -0
- package/dist/chunk-R23BFDIW.js.map +1 -0
- package/dist/{chunk-HIWNB5PK.cjs → chunk-RCY6XLGU.cjs} +13 -5
- package/dist/chunk-RCY6XLGU.cjs.map +1 -0
- package/dist/chunk-RSYD434G.cjs +351 -0
- package/dist/chunk-RSYD434G.cjs.map +1 -0
- package/dist/{chunk-C33AQZEC.js → chunk-TYIH5LMV.js} +16 -23
- package/dist/chunk-TYIH5LMV.js.map +1 -0
- package/dist/chunk-WMWAUOQ4.js +165 -0
- package/dist/chunk-WMWAUOQ4.js.map +1 -0
- package/dist/chunk-XWYZIFZW.js +66 -0
- package/dist/chunk-XWYZIFZW.js.map +1 -0
- package/dist/{chunk-7HROSZRS.cjs → chunk-Y3NNQMAX.cjs} +70 -62
- package/dist/chunk-Y3NNQMAX.cjs.map +1 -0
- package/dist/chunk-ZXEFMKVP.cjs +120 -0
- package/dist/chunk-ZXEFMKVP.cjs.map +1 -0
- package/dist/chunk-ZY4FXLMM.js +120 -0
- package/dist/chunk-ZY4FXLMM.js.map +1 -0
- package/dist/components/legend/index.cjs +2 -2
- package/dist/components/legend/index.css +12 -0
- package/dist/components/legend/index.css.map +1 -1
- package/dist/components/legend/index.js +1 -1
- package/dist/components/tooltip/index.cjs +2 -2
- package/dist/components/tooltip/index.js +1 -1
- package/dist/components/trend-indicator/index.cjs +2 -2
- package/dist/components/trend-indicator/index.js +1 -1
- package/dist/hooks/index.cjs +4 -2
- package/dist/hooks/index.cjs.map +1 -1
- package/dist/hooks/index.css +12 -0
- package/dist/hooks/index.css.map +1 -1
- package/dist/hooks/index.d.cts +28 -2
- package/dist/hooks/index.d.ts +28 -2
- package/dist/hooks/index.js +3 -1
- package/dist/index.cjs +18 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.css +14 -1
- package/dist/index.css.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +17 -17
- package/dist/providers/index.cjs +2 -2
- package/dist/providers/index.css +12 -0
- package/dist/providers/index.css.map +1 -1
- package/dist/providers/index.d.cts +1 -1
- package/dist/providers/index.d.ts +1 -1
- package/dist/providers/index.js +1 -1
- package/dist/{themes-DQs9rbN5.d.cts → themes-BDVaIfBz.d.cts} +9 -0
- package/dist/{themes-CRV5fVzJ.d.ts → themes-mcS8QNkQ.d.ts} +9 -0
- package/package.json +7 -4
- package/src/charts/conversion-funnel-chart/conversion-funnel-chart.module.scss +2 -1
- package/src/charts/conversion-funnel-chart/conversion-funnel-chart.tsx +16 -6
- package/src/charts/conversion-funnel-chart/test/conversion-funnel-chart.test.tsx +34 -0
- package/src/charts/conversion-funnel-chart/types.ts +2 -0
- package/src/charts/pie-chart/pie-chart.tsx +2 -3
- package/src/hooks/index.ts +1 -0
- package/src/hooks/test/use-tooltip-portal-relocator.test.ts +216 -0
- package/src/hooks/use-tooltip-portal-relocator.module.scss +10 -0
- package/src/hooks/use-tooltip-portal-relocator.ts +177 -0
- package/src/providers/chart-context/global-charts-provider.tsx +18 -1
- package/tsup.config.ts +11 -0
- package/dist/chunk-2VPPTJS2.js.map +0 -1
- package/dist/chunk-5XI443YP.js.map +0 -1
- package/dist/chunk-7HROSZRS.cjs.map +0 -1
- package/dist/chunk-7UJPVCMB.cjs.map +0 -1
- package/dist/chunk-A3AEEGKR.js.map +0 -1
- package/dist/chunk-C33AQZEC.js.map +0 -1
- package/dist/chunk-CEZGL6YP.js.map +0 -1
- package/dist/chunk-COOC2TVQ.js +0 -167
- package/dist/chunk-COOC2TVQ.js.map +0 -1
- package/dist/chunk-EJHLLXBV.js +0 -362
- package/dist/chunk-EJHLLXBV.js.map +0 -1
- package/dist/chunk-FWMJ2FR2.js +0 -121
- package/dist/chunk-FWMJ2FR2.js.map +0 -1
- package/dist/chunk-GRYNIPWH.cjs +0 -385
- package/dist/chunk-GRYNIPWH.cjs.map +0 -1
- package/dist/chunk-H34CJSR6.js.map +0 -1
- package/dist/chunk-HIWNB5PK.cjs.map +0 -1
- package/dist/chunk-IZWC33YN.cjs +0 -357
- package/dist/chunk-IZWC33YN.cjs.map +0 -1
- package/dist/chunk-KOF32DBL.cjs +0 -1058
- package/dist/chunk-KOF32DBL.cjs.map +0 -1
- package/dist/chunk-LHWRZMF7.cjs +0 -362
- package/dist/chunk-LHWRZMF7.cjs.map +0 -1
- package/dist/chunk-MFRS2PEY.cjs +0 -121
- package/dist/chunk-MFRS2PEY.cjs.map +0 -1
- package/dist/chunk-MMDLXS6O.js +0 -75
- package/dist/chunk-MMDLXS6O.js.map +0 -1
- package/dist/chunk-NW3RUYK2.cjs.map +0 -1
- package/dist/chunk-ODF5O5PV.cjs.map +0 -1
- package/dist/chunk-OTZT3MC2.cjs.map +0 -1
- package/dist/chunk-SBRMWDWM.js +0 -357
- package/dist/chunk-SBRMWDWM.js.map +0 -1
- package/dist/chunk-SRXJLAKG.cjs.map +0 -1
- package/dist/chunk-T4J6TI55.js.map +0 -1
- package/dist/chunk-TVV7ZI7C.cjs.map +0 -1
- package/dist/chunk-XVMXWV3C.cjs +0 -167
- package/dist/chunk-XVMXWV3C.cjs.map +0 -1
- package/dist/chunk-YYQ4IK5V.cjs.map +0 -1
- package/dist/chunk-ZDNCF642.js +0 -1058
- package/dist/chunk-ZDNCF642.js.map +0 -1
- package/dist/chunk-ZWBUEHKF.js +0 -385
- package/dist/chunk-ZWBUEHKF.js.map +0 -1
|
@@ -18,30 +18,26 @@ var DIRECTION_LABELS = {
|
|
|
18
18
|
down: "Decrease",
|
|
19
19
|
neutral: "No change"
|
|
20
20
|
};
|
|
21
|
-
var Icon = ({
|
|
21
|
+
var Icon = ({
|
|
22
|
+
direction
|
|
23
|
+
}) => {
|
|
22
24
|
if (direction === "neutral") {
|
|
23
25
|
return null;
|
|
24
26
|
}
|
|
25
27
|
const isUp = direction === "up";
|
|
26
|
-
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
27
|
-
"
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
"
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
strokeLinecap: "round",
|
|
40
|
-
strokeLinejoin: "round"
|
|
41
|
-
}
|
|
42
|
-
)
|
|
43
|
-
}
|
|
44
|
-
);
|
|
28
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "svg", {
|
|
29
|
+
className: trend_indicator_module_default["trend-indicator__icon"],
|
|
30
|
+
viewBox: "0 0 16 16",
|
|
31
|
+
fill: "none",
|
|
32
|
+
"aria-hidden": "true",
|
|
33
|
+
children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "path", {
|
|
34
|
+
d: isUp ? "M8 13V3M4 7l4-4 4 4" : "M8 3v10M4 9l4 4 4-4",
|
|
35
|
+
stroke: "currentColor",
|
|
36
|
+
strokeWidth: "1.5",
|
|
37
|
+
strokeLinecap: "round",
|
|
38
|
+
strokeLinejoin: "round"
|
|
39
|
+
})
|
|
40
|
+
});
|
|
45
41
|
};
|
|
46
42
|
function TrendIndicator({
|
|
47
43
|
direction,
|
|
@@ -51,25 +47,20 @@ function TrendIndicator({
|
|
|
51
47
|
showIcon = true
|
|
52
48
|
}) {
|
|
53
49
|
const ariaLabel = `${DIRECTION_LABELS[direction]}: ${value}`;
|
|
54
|
-
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
|
|
55
|
-
"
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
showIcon && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Icon, { direction }),
|
|
66
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: trend_indicator_module_default["trend-indicator__value"], children: value })
|
|
67
|
-
]
|
|
68
|
-
}
|
|
69
|
-
);
|
|
50
|
+
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "span", {
|
|
51
|
+
className: _clsx2.default.call(void 0, trend_indicator_module_default["trend-indicator"], trend_indicator_module_default[`trend-indicator--${direction}`], className),
|
|
52
|
+
style,
|
|
53
|
+
"aria-label": ariaLabel,
|
|
54
|
+
children: [showIcon && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Icon, {
|
|
55
|
+
direction
|
|
56
|
+
}), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", {
|
|
57
|
+
className: trend_indicator_module_default["trend-indicator__value"],
|
|
58
|
+
children: value
|
|
59
|
+
})]
|
|
60
|
+
});
|
|
70
61
|
}
|
|
71
62
|
|
|
72
63
|
|
|
73
64
|
|
|
74
65
|
exports.TrendIndicator = TrendIndicator;
|
|
75
|
-
//# sourceMappingURL=chunk-
|
|
66
|
+
//# sourceMappingURL=chunk-I2276W3I.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/jetpack/jetpack/projects/js-packages/charts/dist/chunk-I2276W3I.cjs","../src/components/trend-indicator/trend-indicator.tsx","../src/components/trend-indicator/trend-indicator.module.scss"],"names":[],"mappings":"AAAA;ACAA,wEAAiB;ADEjB;AACA;AEH8E,IAAO,+BAAA,EAAQ;AAAA,EAC3F,iBAAA,EAAmB,kBAAA;AAAA,EACnB,qBAAA,EAAuB,kBAAA;AAAA,EACvB,uBAAA,EAAyB,kBAAA;AAAA,EACzB,0BAAA,EAA4B,kBAAA;AAAA,EAC5B,uBAAA,EAAyB,kBAAA;AAAA,EACzB,wBAAA,EAA0B;AAC5B,CAAA;AFKA;AACA;ACXA,+CAA2C;AAC3C,IAAM,iBAAA,EAAmB;AAAA,EACvB,EAAA,EAAI,UAAA;AAAA,EACJ,IAAA,EAAM,UAAA;AAAA,EACN,OAAA,EAAS;AACX,CAAA;AACA,IAAM,KAAA,EAAO,CAAC;AAAA,EACZ;AACF,CAAA,EAAA,GAAM;AACJ,EAAA,GAAA,CAAI,UAAA,IAAc,SAAA,EAAW;AAC3B,IAAA,OAAO,IAAA;AAAA,EACT;AACA,EAAA,MAAM,KAAA,EAAO,UAAA,IAAc,IAAA;AAC3B,EAAA,uBAAoB,6BAAA,KAAK,EAAO;AAAA,IAC9B,SAAA,EAAW,8BAAA,CAAO,uBAAuB,CAAA;AAAA,IACzC,OAAA,EAAS,WAAA;AAAA,IACT,IAAA,EAAM,MAAA;AAAA,IACN,aAAA,EAAe,MAAA;AAAA,IACf,QAAA,kBAAuB,6BAAA,MAAK,EAAQ;AAAA,MAClC,CAAA,EAAG,KAAA,EAAO,sBAAA,EAAwB,qBAAA;AAAA,MAClC,MAAA,EAAQ,cAAA;AAAA,MACR,WAAA,EAAa,KAAA;AAAA,MACb,aAAA,EAAe,OAAA;AAAA,MACf,cAAA,EAAgB;AAAA,IAClB,CAAC;AAAA,EACH,CAAC,CAAA;AACH,CAAA;AASO,SAAS,cAAA,CAAe;AAAA,EAC7B,SAAA;AAAA,EACA,KAAA;AAAA,EACA,SAAA;AAAA,EACA,KAAA;AAAA,EACA,SAAA,EAAW;AACb,CAAA,EAAG;AACD,EAAA,MAAM,UAAA,EAAY,CAAA,EAAA;AACE,EAAA;AACF,IAAA;AAChB,IAAA;AACc,IAAA;AACH,IAAA;AACT,MAAA;AACe,IAAA;AACJ,MAAA;AACD,MAAA;AACV,IAAA;AACH,EAAA;AACH;ADKqB;AACA;AACA;AACA","file":"/home/runner/work/jetpack/jetpack/projects/js-packages/charts/dist/chunk-I2276W3I.cjs","sourcesContent":[null,"import clsx from 'clsx';\nimport styles from './trend-indicator.module.scss';\nimport { jsx as _jsx, jsxs as _jsxs } from \"react/jsx-runtime\";\nconst DIRECTION_LABELS = {\n up: 'Increase',\n down: 'Decrease',\n neutral: 'No change'\n};\nconst Icon = ({\n direction\n}) => {\n if (direction === 'neutral') {\n return null;\n }\n const isUp = direction === 'up';\n return /*#__PURE__*/_jsx(\"svg\", {\n className: styles['trend-indicator__icon'],\n viewBox: \"0 0 16 16\",\n fill: \"none\",\n \"aria-hidden\": \"true\",\n children: /*#__PURE__*/_jsx(\"path\", {\n d: isUp ? 'M8 13V3M4 7l4-4 4 4' : 'M8 3v10M4 9l4 4 4-4',\n stroke: \"currentColor\",\n strokeWidth: \"1.5\",\n strokeLinecap: \"round\",\n strokeLinejoin: \"round\"\n })\n });\n};\n\n/**\n * TrendIndicator displays a directional trend with a value.\n * Used to show percentage changes or growth metrics.\n *\n * @param {TrendIndicatorProps} props - Component props\n * @return {JSX.Element} The rendered trend indicator\n */\nexport function TrendIndicator({\n direction,\n value,\n className,\n style,\n showIcon = true\n}) {\n const ariaLabel = `${DIRECTION_LABELS[direction]}: ${value}`;\n return /*#__PURE__*/_jsxs(\"span\", {\n className: clsx(styles['trend-indicator'], styles[`trend-indicator--${direction}`], className),\n style: style,\n \"aria-label\": ariaLabel,\n children: [showIcon && /*#__PURE__*/_jsx(Icon, {\n direction: direction\n }), /*#__PURE__*/_jsx(\"span\", {\n className: styles['trend-indicator__value'],\n children: value\n })]\n });\n}","import 'css-chunk:src/components/trend-indicator/trend-indicator.module.scss';export default {\n \"trend-indicator\": \"a8ccharts-tGw1PY\",\n \"trend-indicator--up\": \"a8ccharts-Fn-D1W\",\n \"trend-indicator--down\": \"a8ccharts-HqtGQO\",\n \"trend-indicator--neutral\": \"a8ccharts-S10nvO\",\n \"trend-indicator__icon\": \"a8ccharts-5HjpOT\",\n \"trend-indicator__value\": \"a8ccharts-muLL2Q\"\n};"]}
|
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getStringWidth
|
|
3
|
+
} from "./chunk-NFRB2POF.js";
|
|
4
|
+
import {
|
|
5
|
+
radial_wipe_animation_default
|
|
6
|
+
} from "./chunk-KXRWNFQJ.js";
|
|
7
|
+
import {
|
|
8
|
+
ChartHTML,
|
|
9
|
+
ChartSVG,
|
|
10
|
+
useChartChildren
|
|
11
|
+
} from "./chunk-6CCZL2JJ.js";
|
|
12
|
+
import {
|
|
13
|
+
BaseTooltip
|
|
14
|
+
} from "./chunk-BPYKWMI7.js";
|
|
15
|
+
import {
|
|
16
|
+
withResponsive
|
|
17
|
+
} from "./chunk-TYIH5LMV.js";
|
|
18
|
+
import {
|
|
19
|
+
GlobalChartsContext,
|
|
20
|
+
GlobalChartsProvider,
|
|
21
|
+
Legend,
|
|
22
|
+
SingleChartContext,
|
|
23
|
+
useChartId,
|
|
24
|
+
useChartLegendItems,
|
|
25
|
+
useChartRegistration,
|
|
26
|
+
useElementHeight,
|
|
27
|
+
useGlobalChartsContext,
|
|
28
|
+
useGlobalChartsTheme,
|
|
29
|
+
useInteractiveLegendData,
|
|
30
|
+
usePrefersReducedMotion
|
|
31
|
+
} from "./chunk-AWNCAKZY.js";
|
|
32
|
+
import {
|
|
33
|
+
attachSubComponents
|
|
34
|
+
} from "./chunk-TE63Y5PX.js";
|
|
35
|
+
|
|
36
|
+
// src/charts/pie-chart/pie-chart.tsx
|
|
37
|
+
import { Group } from "@visx/group";
|
|
38
|
+
import { Pie } from "@visx/shape";
|
|
39
|
+
import { useTooltip, useTooltipInPortal } from "@visx/tooltip";
|
|
40
|
+
import { __ } from "@wordpress/i18n";
|
|
41
|
+
import clsx from "clsx";
|
|
42
|
+
import { useCallback, useContext, useMemo } from "react";
|
|
43
|
+
|
|
44
|
+
// src/charts/pie-chart/pie-chart.module.scss
|
|
45
|
+
var pie_chart_module_default = {
|
|
46
|
+
"pie-chart": "a8ccharts-C-n-Gu",
|
|
47
|
+
"pie-chart--legend-top": "a8ccharts-Mu0uxl"
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
// src/charts/pie-chart/pie-chart.tsx
|
|
51
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
52
|
+
var renderDefaultPieTooltip = ({
|
|
53
|
+
tooltipData
|
|
54
|
+
}) => {
|
|
55
|
+
return /* @__PURE__ */ _jsx(BaseTooltip, {
|
|
56
|
+
data: tooltipData,
|
|
57
|
+
top: 0,
|
|
58
|
+
left: 0,
|
|
59
|
+
renderContainer: false
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
var validateData = (data) => {
|
|
63
|
+
if (!data.length) {
|
|
64
|
+
return {
|
|
65
|
+
isValid: false,
|
|
66
|
+
message: "No data available"
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
const hasNegativeValues = data.some((item) => item.percentage < 0 || item.value < 0);
|
|
70
|
+
if (hasNegativeValues) {
|
|
71
|
+
return {
|
|
72
|
+
isValid: false,
|
|
73
|
+
message: "Invalid data: Negative values are not allowed"
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
const totalPercentage = data.reduce((sum, item) => sum + item.percentage, 0);
|
|
77
|
+
if (Math.abs(totalPercentage - 100) > 0.01) {
|
|
78
|
+
return {
|
|
79
|
+
isValid: false,
|
|
80
|
+
message: "Invalid percentage total: Must equal 100"
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
isValid: true,
|
|
85
|
+
message: ""
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
var PieChartInternal = ({
|
|
89
|
+
data,
|
|
90
|
+
chartId: providedChartId,
|
|
91
|
+
withTooltips = false,
|
|
92
|
+
className,
|
|
93
|
+
showLegend = false,
|
|
94
|
+
legendOrientation = "horizontal",
|
|
95
|
+
legendPosition = "bottom",
|
|
96
|
+
legendAlignment = "center",
|
|
97
|
+
legendMaxWidth,
|
|
98
|
+
legendTextOverflow = "wrap",
|
|
99
|
+
legendItemClassName,
|
|
100
|
+
legendShape = "circle",
|
|
101
|
+
size,
|
|
102
|
+
animation,
|
|
103
|
+
thickness = 1,
|
|
104
|
+
padding = 0,
|
|
105
|
+
gapScale = 0,
|
|
106
|
+
cornerScale = 0,
|
|
107
|
+
showLabels = true,
|
|
108
|
+
legendValueDisplay = "percentage",
|
|
109
|
+
legendInteractive = false,
|
|
110
|
+
children = null,
|
|
111
|
+
tooltipOffsetX = 0,
|
|
112
|
+
tooltipOffsetY = -15,
|
|
113
|
+
renderTooltip = renderDefaultPieTooltip
|
|
114
|
+
}) => {
|
|
115
|
+
const providerTheme = useGlobalChartsTheme();
|
|
116
|
+
const chartId = useChartId(providedChartId);
|
|
117
|
+
const [legendRef, legendHeight] = useElementHeight();
|
|
118
|
+
const {
|
|
119
|
+
tooltipOpen,
|
|
120
|
+
tooltipLeft,
|
|
121
|
+
tooltipTop,
|
|
122
|
+
tooltipData,
|
|
123
|
+
hideTooltip,
|
|
124
|
+
showTooltip
|
|
125
|
+
} = useTooltip();
|
|
126
|
+
const {
|
|
127
|
+
containerRef,
|
|
128
|
+
TooltipInPortal,
|
|
129
|
+
containerBounds
|
|
130
|
+
} = useTooltipInPortal({
|
|
131
|
+
detectBounds: true,
|
|
132
|
+
scroll: true,
|
|
133
|
+
debounce: 0
|
|
134
|
+
});
|
|
135
|
+
const onMouseLeave = useCallback(() => {
|
|
136
|
+
if (!withTooltips) {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
hideTooltip();
|
|
140
|
+
}, [withTooltips, hideTooltip]);
|
|
141
|
+
const {
|
|
142
|
+
getElementStyles,
|
|
143
|
+
isSeriesVisible
|
|
144
|
+
} = useGlobalChartsContext();
|
|
145
|
+
const {
|
|
146
|
+
visibleData,
|
|
147
|
+
allSegmentsHidden,
|
|
148
|
+
legendData
|
|
149
|
+
} = useInteractiveLegendData({
|
|
150
|
+
data,
|
|
151
|
+
chartId,
|
|
152
|
+
legendInteractive,
|
|
153
|
+
isSeriesVisible
|
|
154
|
+
});
|
|
155
|
+
const legendOptions = useMemo(() => ({
|
|
156
|
+
showValues: true,
|
|
157
|
+
legendValueDisplay
|
|
158
|
+
}), [legendValueDisplay]);
|
|
159
|
+
const legendItems = useChartLegendItems(legendData, legendOptions);
|
|
160
|
+
const {
|
|
161
|
+
isValid,
|
|
162
|
+
message
|
|
163
|
+
} = validateData(data);
|
|
164
|
+
const {
|
|
165
|
+
svgChildren,
|
|
166
|
+
htmlChildren,
|
|
167
|
+
otherChildren
|
|
168
|
+
} = useChartChildren(children, "PieChart");
|
|
169
|
+
const chartMetadata = useMemo(() => ({
|
|
170
|
+
thickness,
|
|
171
|
+
gapScale,
|
|
172
|
+
cornerScale
|
|
173
|
+
}), [thickness, gapScale, cornerScale]);
|
|
174
|
+
useChartRegistration({
|
|
175
|
+
chartId,
|
|
176
|
+
legendItems,
|
|
177
|
+
chartType: "pie",
|
|
178
|
+
isDataValid: isValid,
|
|
179
|
+
metadata: chartMetadata
|
|
180
|
+
});
|
|
181
|
+
const prefersReducedMotion = usePrefersReducedMotion();
|
|
182
|
+
if (!isValid) {
|
|
183
|
+
return /* @__PURE__ */ _jsx("div", {
|
|
184
|
+
className: clsx("pie-chart", pie_chart_module_default["pie-chart"], className),
|
|
185
|
+
children: /* @__PURE__ */ _jsx("div", {
|
|
186
|
+
className: pie_chart_module_default["error-message"],
|
|
187
|
+
children: message
|
|
188
|
+
})
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
const width = size;
|
|
192
|
+
const height = size;
|
|
193
|
+
const adjustedHeight = showLegend && legendPosition === "top" ? height - legendHeight : height;
|
|
194
|
+
const radius = Math.min(width, adjustedHeight) / 2;
|
|
195
|
+
const centerX = width / 2;
|
|
196
|
+
const centerY = adjustedHeight / 2;
|
|
197
|
+
const padAngle = gapScale * (2 * Math.PI / data.length);
|
|
198
|
+
const outerRadius = radius - padding;
|
|
199
|
+
const innerRadius = thickness === 0 ? 0 : outerRadius * (1 - thickness);
|
|
200
|
+
const maxCornerRadius = (outerRadius - innerRadius) / 2;
|
|
201
|
+
const cornerRadius = cornerScale ? Math.min(cornerScale * outerRadius, maxCornerRadius) : 0;
|
|
202
|
+
const dataWithIndex = visibleData.map((d) => {
|
|
203
|
+
const originalIndex = data.findIndex((item) => item.label === d.label);
|
|
204
|
+
return {
|
|
205
|
+
...d,
|
|
206
|
+
index: originalIndex >= 0 ? originalIndex : 0
|
|
207
|
+
};
|
|
208
|
+
});
|
|
209
|
+
const accessors = {
|
|
210
|
+
value: (d) => d.value,
|
|
211
|
+
fill: (d) => {
|
|
212
|
+
return getElementStyles({
|
|
213
|
+
data: d,
|
|
214
|
+
index: d.index
|
|
215
|
+
}).color;
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
return /* @__PURE__ */ _jsx(SingleChartContext.Provider, {
|
|
219
|
+
value: {
|
|
220
|
+
chartId,
|
|
221
|
+
chartWidth: width,
|
|
222
|
+
chartHeight: adjustedHeight
|
|
223
|
+
},
|
|
224
|
+
children: /* @__PURE__ */ _jsxs("div", {
|
|
225
|
+
ref: containerRef,
|
|
226
|
+
className: clsx("pie-chart", pie_chart_module_default["pie-chart"], {
|
|
227
|
+
[pie_chart_module_default["pie-chart--legend-top"]]: showLegend && legendPosition === "top"
|
|
228
|
+
}, className),
|
|
229
|
+
children: [/* @__PURE__ */ _jsxs("svg", {
|
|
230
|
+
viewBox: `0 0 ${width} ${adjustedHeight}`,
|
|
231
|
+
preserveAspectRatio: "xMidYMid meet",
|
|
232
|
+
width,
|
|
233
|
+
height: adjustedHeight,
|
|
234
|
+
children: [/* @__PURE__ */ _jsx("defs", {
|
|
235
|
+
children: /* @__PURE__ */ _jsx(radial_wipe_animation_default, {
|
|
236
|
+
id: `radial-wipe-${chartId}`,
|
|
237
|
+
radius: outerRadius,
|
|
238
|
+
innerRadius
|
|
239
|
+
})
|
|
240
|
+
}), /* @__PURE__ */ _jsxs(Group, {
|
|
241
|
+
top: centerY,
|
|
242
|
+
left: centerX,
|
|
243
|
+
mask: animation && !prefersReducedMotion ? `url(#radial-wipe-${chartId})` : null,
|
|
244
|
+
children: [allSegmentsHidden ? /* @__PURE__ */ _jsx("text", {
|
|
245
|
+
textAnchor: "middle",
|
|
246
|
+
dy: ".33em",
|
|
247
|
+
fill: providerTheme.gridColor || "#ccc",
|
|
248
|
+
fontSize: "14",
|
|
249
|
+
fontFamily: "-apple-system,BlinkMacSystemFont,Roboto,Helvetica Neue,sans-serif",
|
|
250
|
+
children: __("All segments are hidden. Click legend items to show data.", "jetpack-charts")
|
|
251
|
+
}) : /* @__PURE__ */ _jsx(Pie, {
|
|
252
|
+
data: dataWithIndex,
|
|
253
|
+
pieValue: accessors.value,
|
|
254
|
+
outerRadius,
|
|
255
|
+
innerRadius,
|
|
256
|
+
padAngle,
|
|
257
|
+
cornerRadius,
|
|
258
|
+
children: (pie) => {
|
|
259
|
+
return pie.arcs.map((arc, index) => {
|
|
260
|
+
const [centroidX, centroidY] = pie.path.centroid(arc);
|
|
261
|
+
const hasSpaceForLabel = arc.endAngle - arc.startAngle >= 0.25;
|
|
262
|
+
const handleMouseMove = (event) => {
|
|
263
|
+
if (!withTooltips) {
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
if (containerBounds.width === 0 || containerBounds.height === 0) {
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
showTooltip({
|
|
270
|
+
tooltipData: arc.data,
|
|
271
|
+
tooltipLeft: event.clientX - containerBounds.left + tooltipOffsetX,
|
|
272
|
+
tooltipTop: event.clientY - containerBounds.top + tooltipOffsetY
|
|
273
|
+
});
|
|
274
|
+
};
|
|
275
|
+
const pathProps = {
|
|
276
|
+
d: pie.path(arc) || "",
|
|
277
|
+
fill: accessors.fill(arc.data)
|
|
278
|
+
};
|
|
279
|
+
const groupProps = {};
|
|
280
|
+
if (withTooltips) {
|
|
281
|
+
groupProps.onMouseMove = handleMouseMove;
|
|
282
|
+
groupProps.onMouseLeave = onMouseLeave;
|
|
283
|
+
}
|
|
284
|
+
const fontSize = 12;
|
|
285
|
+
const estimatedTextWidth = getStringWidth(arc.data.label, {
|
|
286
|
+
fontSize
|
|
287
|
+
});
|
|
288
|
+
const labelPadding = 6;
|
|
289
|
+
const backgroundWidth = estimatedTextWidth + labelPadding * 2;
|
|
290
|
+
const backgroundHeight = fontSize + labelPadding * 2;
|
|
291
|
+
return /* @__PURE__ */ _jsxs("g", {
|
|
292
|
+
...groupProps,
|
|
293
|
+
children: [/* @__PURE__ */ _jsx("path", {
|
|
294
|
+
...pathProps
|
|
295
|
+
}), showLabels && hasSpaceForLabel && /* @__PURE__ */ _jsxs("g", {
|
|
296
|
+
children: [providerTheme.labelBackgroundColor && /* @__PURE__ */ _jsx("rect", {
|
|
297
|
+
x: centroidX - backgroundWidth / 2,
|
|
298
|
+
y: centroidY - backgroundHeight / 2,
|
|
299
|
+
width: backgroundWidth,
|
|
300
|
+
height: backgroundHeight,
|
|
301
|
+
fill: providerTheme.labelBackgroundColor,
|
|
302
|
+
rx: 4,
|
|
303
|
+
ry: 4,
|
|
304
|
+
pointerEvents: "none"
|
|
305
|
+
}), /* @__PURE__ */ _jsx("text", {
|
|
306
|
+
x: centroidX,
|
|
307
|
+
y: centroidY,
|
|
308
|
+
dy: ".33em",
|
|
309
|
+
fill: providerTheme.labelTextColor || "#333",
|
|
310
|
+
fontSize,
|
|
311
|
+
textAnchor: "middle",
|
|
312
|
+
pointerEvents: "none",
|
|
313
|
+
children: arc.data.label
|
|
314
|
+
})]
|
|
315
|
+
})]
|
|
316
|
+
}, `arc-${index}`);
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
}), !allSegmentsHidden && svgChildren]
|
|
320
|
+
})]
|
|
321
|
+
}), showLegend && /* @__PURE__ */ _jsx(Legend, {
|
|
322
|
+
orientation: legendOrientation,
|
|
323
|
+
position: legendPosition,
|
|
324
|
+
alignment: legendAlignment,
|
|
325
|
+
maxWidth: legendMaxWidth,
|
|
326
|
+
textOverflow: legendTextOverflow,
|
|
327
|
+
legendItemClassName,
|
|
328
|
+
className: pie_chart_module_default["pie-chart-legend"],
|
|
329
|
+
shape: legendShape,
|
|
330
|
+
ref: legendRef,
|
|
331
|
+
chartId,
|
|
332
|
+
interactive: legendInteractive
|
|
333
|
+
}), withTooltips && tooltipOpen && tooltipData && /* @__PURE__ */ _jsx(TooltipInPortal, {
|
|
334
|
+
top: tooltipTop || 0,
|
|
335
|
+
left: tooltipLeft || 0,
|
|
336
|
+
children: /* @__PURE__ */ _jsx("div", {
|
|
337
|
+
role: "tooltip",
|
|
338
|
+
children: renderTooltip({
|
|
339
|
+
tooltipData
|
|
340
|
+
})
|
|
341
|
+
})
|
|
342
|
+
}), htmlChildren, otherChildren]
|
|
343
|
+
})
|
|
344
|
+
});
|
|
345
|
+
};
|
|
346
|
+
var PieChartWithProvider = (props) => {
|
|
347
|
+
const existingContext = useContext(GlobalChartsContext);
|
|
348
|
+
if (existingContext) {
|
|
349
|
+
return /* @__PURE__ */ _jsx(PieChartInternal, {
|
|
350
|
+
...props
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
return /* @__PURE__ */ _jsx(GlobalChartsProvider, {
|
|
354
|
+
children: /* @__PURE__ */ _jsx(PieChartInternal, {
|
|
355
|
+
...props
|
|
356
|
+
})
|
|
357
|
+
});
|
|
358
|
+
};
|
|
359
|
+
PieChartWithProvider.displayName = "PieChart";
|
|
360
|
+
var PieChart = attachSubComponents(PieChartWithProvider, {
|
|
361
|
+
Legend,
|
|
362
|
+
SVG: ChartSVG,
|
|
363
|
+
HTML: ChartHTML
|
|
364
|
+
});
|
|
365
|
+
var PieChartResponsive = attachSubComponents(withResponsive(PieChartWithProvider), {
|
|
366
|
+
Legend,
|
|
367
|
+
SVG: ChartSVG,
|
|
368
|
+
HTML: ChartHTML
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
export {
|
|
372
|
+
PieChart,
|
|
373
|
+
PieChartResponsive
|
|
374
|
+
};
|
|
375
|
+
//# sourceMappingURL=chunk-KKPZ4MVF.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/charts/pie-chart/pie-chart.tsx","../src/charts/pie-chart/pie-chart.module.scss"],"sourcesContent":["import { Group } from '@visx/group';\nimport { Pie } from '@visx/shape';\nimport { useTooltip, useTooltipInPortal } from '@visx/tooltip';\nimport { __ } from '@wordpress/i18n';\nimport clsx from 'clsx';\nimport { useCallback, useContext, useMemo } from 'react';\nimport { Legend, useChartLegendItems } from '../../components/legend';\nimport { BaseTooltip } from '../../components/tooltip';\nimport { useElementHeight, useInteractiveLegendData, usePrefersReducedMotion } from '../../hooks';\nimport { GlobalChartsProvider, useChartId, useChartRegistration, useGlobalChartsContext, useGlobalChartsTheme, GlobalChartsContext } from '../../providers';\nimport { attachSubComponents } from '../../utils';\nimport { getStringWidth } from '../../visx/text';\nimport { ChartSVG, ChartHTML, useChartChildren } from '../private/chart-composition';\nimport { RadialWipeAnimation } from '../private/radial-wipe-animation/';\nimport { SingleChartContext } from '../private/single-chart-context';\nimport { withResponsive } from '../private/with-responsive';\nimport styles from './pie-chart.module.scss';\n\n/**\n * Parameters passed to the renderTooltip function for pie charts.\n */\nimport { jsx as _jsx, jsxs as _jsxs } from \"react/jsx-runtime\";\n/**\n * Default tooltip renderer for pie charts.\n * Renders a BaseTooltip with the hovered segment's data.\n *\n * @param {PieChartRenderTooltipParams} params - The tooltip parameters containing the hovered data point\n * @return {ReactNode} The rendered tooltip content\n */\nconst renderDefaultPieTooltip = ({\n tooltipData\n}) => {\n return /*#__PURE__*/_jsx(BaseTooltip, {\n data: tooltipData,\n top: 0,\n left: 0,\n renderContainer: false\n });\n};\n\n// Base props type with optional responsive properties\n\n// Composition API types\n\n/**\n * Validates the pie chart data\n * @param data - The data to validate\n * @return Object containing validation result and error message\n */\nconst validateData = data => {\n if (!data.length) {\n return {\n isValid: false,\n message: 'No data available'\n };\n }\n\n // Check for negative values\n const hasNegativeValues = data.some(item => item.percentage < 0 || item.value < 0);\n if (hasNegativeValues) {\n return {\n isValid: false,\n message: 'Invalid data: Negative values are not allowed'\n };\n }\n\n // Validate total percentage\n const totalPercentage = data.reduce((sum, item) => sum + item.percentage, 0);\n if (Math.abs(totalPercentage - 100) > 0.01) {\n // Using small epsilon for floating point comparison\n return {\n isValid: false,\n message: 'Invalid percentage total: Must equal 100'\n };\n }\n return {\n isValid: true,\n message: ''\n };\n};\n\n/**\n * Renders a pie or donut chart using the provided data.\n *\n * @param {PieChartProps} props - Component props\n * @return {JSX.Element} The rendered chart component\n */\nconst PieChartInternal = ({\n data,\n chartId: providedChartId,\n withTooltips = false,\n className,\n showLegend = false,\n legendOrientation = 'horizontal',\n legendPosition = 'bottom',\n legendAlignment = 'center',\n legendMaxWidth,\n legendTextOverflow = 'wrap',\n legendItemClassName,\n legendShape = 'circle',\n size,\n animation,\n thickness = 1,\n padding = 0,\n gapScale = 0,\n cornerScale = 0,\n showLabels = true,\n legendValueDisplay = 'percentage',\n legendInteractive = false,\n children = null,\n tooltipOffsetX = 0,\n tooltipOffsetY = -15,\n renderTooltip = renderDefaultPieTooltip\n}) => {\n const providerTheme = useGlobalChartsTheme();\n const chartId = useChartId(providedChartId);\n const [legendRef, legendHeight] = useElementHeight();\n const {\n tooltipOpen,\n tooltipLeft,\n tooltipTop,\n tooltipData,\n hideTooltip,\n showTooltip\n } = useTooltip();\n\n // Set up portal tooltip for better z-index handling\n // We get containerBounds to cancel out stale offsets in the position calculation\n const {\n containerRef,\n TooltipInPortal,\n containerBounds\n } = useTooltipInPortal({\n detectBounds: true,\n scroll: true,\n debounce: 0\n });\n const onMouseLeave = useCallback(() => {\n if (!withTooltips) {\n return;\n }\n hideTooltip();\n }, [withTooltips, hideTooltip]);\n const {\n getElementStyles,\n isSeriesVisible\n } = useGlobalChartsContext();\n\n // Filter and recalculate data for interactive legends\n const {\n visibleData,\n allSegmentsHidden,\n legendData\n } = useInteractiveLegendData({\n data,\n chartId,\n legendInteractive,\n isSeriesVisible\n });\n\n // Memoize legend options to prevent unnecessary re-calculations\n const legendOptions = useMemo(() => ({\n showValues: true,\n legendValueDisplay\n }), [legendValueDisplay]);\n\n // Create legend items using legendData (has recalculated percentages for visible items)\n const legendItems = useChartLegendItems(legendData, legendOptions);\n const {\n isValid,\n message\n } = validateData(data);\n\n // Process children to extract compound components\n const {\n svgChildren,\n htmlChildren,\n otherChildren\n } = useChartChildren(children, 'PieChart');\n\n // Memoize metadata to prevent unnecessary re-registration\n const chartMetadata = useMemo(() => ({\n thickness,\n gapScale,\n cornerScale\n }), [thickness, gapScale, cornerScale]);\n\n // Register chart with context only if data is valid\n useChartRegistration({\n chartId,\n legendItems,\n chartType: 'pie',\n isDataValid: isValid,\n metadata: chartMetadata\n });\n const prefersReducedMotion = usePrefersReducedMotion();\n if (!isValid) {\n return /*#__PURE__*/_jsx(\"div\", {\n className: clsx('pie-chart', styles['pie-chart'], className),\n children: /*#__PURE__*/_jsx(\"div\", {\n className: styles['error-message'],\n children: message\n })\n });\n }\n const width = size;\n const height = size;\n const adjustedHeight = showLegend && legendPosition === 'top' ? height - legendHeight : height;\n\n // Calculate radius based on width/height\n const radius = Math.min(width, adjustedHeight) / 2;\n\n // Center the chart in the available space\n const centerX = width / 2;\n const centerY = adjustedHeight / 2;\n\n // Calculate the angle between each (use original data length for consistent spacing)\n const padAngle = gapScale * (2 * Math.PI / data.length);\n const outerRadius = radius - padding;\n const innerRadius = thickness === 0 ? 0 : outerRadius * (1 - thickness);\n const maxCornerRadius = (outerRadius - innerRadius) / 2;\n const cornerRadius = cornerScale ? Math.min(cornerScale * outerRadius, maxCornerRadius) : 0;\n\n // Map the data to include index for color assignment\n // When interactive, we need to find the original index to maintain consistent colors\n const dataWithIndex = visibleData.map(d => {\n const originalIndex = data.findIndex(item => item.label === d.label);\n return {\n ...d,\n index: originalIndex >= 0 ? originalIndex : 0\n };\n });\n const accessors = {\n value: d => d.value,\n fill: d => {\n return getElementStyles({\n data: d,\n index: d.index\n }).color;\n }\n };\n return /*#__PURE__*/_jsx(SingleChartContext.Provider, {\n value: {\n chartId,\n chartWidth: width,\n chartHeight: adjustedHeight\n },\n children: /*#__PURE__*/_jsxs(\"div\", {\n ref: containerRef,\n className: clsx('pie-chart', styles['pie-chart'], {\n [styles['pie-chart--legend-top']]: showLegend && legendPosition === 'top'\n }, className),\n children: [/*#__PURE__*/_jsxs(\"svg\", {\n viewBox: `0 0 ${width} ${adjustedHeight}`,\n preserveAspectRatio: \"xMidYMid meet\",\n width: width,\n height: adjustedHeight,\n children: [/*#__PURE__*/_jsx(\"defs\", {\n children: /*#__PURE__*/_jsx(RadialWipeAnimation, {\n id: `radial-wipe-${chartId}`,\n radius: outerRadius,\n innerRadius: innerRadius\n })\n }), /*#__PURE__*/_jsxs(Group, {\n top: centerY,\n left: centerX,\n mask: animation && !prefersReducedMotion ? `url(#radial-wipe-${chartId})` : null,\n children: [allSegmentsHidden ? /*#__PURE__*/_jsx(\"text\", {\n textAnchor: \"middle\",\n dy: \".33em\",\n fill: providerTheme.gridColor || '#ccc',\n fontSize: \"14\",\n fontFamily: \"-apple-system,BlinkMacSystemFont,Roboto,Helvetica Neue,sans-serif\",\n children: __('All segments are hidden. Click legend items to show data.', 'jetpack-charts')\n }) : /*#__PURE__*/_jsx(Pie, {\n data: dataWithIndex,\n pieValue: accessors.value,\n outerRadius: outerRadius,\n innerRadius: innerRadius,\n padAngle: padAngle,\n cornerRadius: cornerRadius,\n children: pie => {\n return pie.arcs.map((arc, index) => {\n const [centroidX, centroidY] = pie.path.centroid(arc);\n const hasSpaceForLabel = arc.endAngle - arc.startAngle >= 0.25;\n const handleMouseMove = event => {\n if (!withTooltips) {\n return;\n }\n\n // Don't show tooltip until container bounds are measured\n if (containerBounds.width === 0 || containerBounds.height === 0) {\n return;\n }\n\n // Use clientX/Y and subtract containerBounds to cancel out any stale offset.\n // TooltipInPortal calculates: tooltipLeft + containerBounds.left + scrollX\n // By passing (clientX - containerBounds.left), we get:\n // (clientX - containerBounds.left) + containerBounds.left + scrollX = clientX + scrollX\n // This gives correct page coordinates regardless of stale bounds.\n showTooltip({\n tooltipData: arc.data,\n tooltipLeft: event.clientX - containerBounds.left + tooltipOffsetX,\n tooltipTop: event.clientY - containerBounds.top + tooltipOffsetY\n });\n };\n const pathProps = {\n d: pie.path(arc) || '',\n fill: accessors.fill(arc.data)\n };\n const groupProps = {};\n if (withTooltips) {\n groupProps.onMouseMove = handleMouseMove;\n groupProps.onMouseLeave = onMouseLeave;\n }\n\n // Estimate text width more accurately for background sizing\n const fontSize = 12;\n const estimatedTextWidth = getStringWidth(arc.data.label, {\n fontSize\n });\n const labelPadding = 6;\n const backgroundWidth = estimatedTextWidth + labelPadding * 2;\n const backgroundHeight = fontSize + labelPadding * 2;\n return /*#__PURE__*/_jsxs(\"g\", {\n ...groupProps,\n children: [/*#__PURE__*/_jsx(\"path\", {\n ...pathProps\n }), showLabels && hasSpaceForLabel && /*#__PURE__*/_jsxs(\"g\", {\n children: [providerTheme.labelBackgroundColor && /*#__PURE__*/_jsx(\"rect\", {\n x: centroidX - backgroundWidth / 2,\n y: centroidY - backgroundHeight / 2,\n width: backgroundWidth,\n height: backgroundHeight,\n fill: providerTheme.labelBackgroundColor,\n rx: 4,\n ry: 4,\n pointerEvents: \"none\"\n }), /*#__PURE__*/_jsx(\"text\", {\n x: centroidX,\n y: centroidY,\n dy: \".33em\",\n fill: providerTheme.labelTextColor || '#333',\n fontSize: fontSize,\n textAnchor: \"middle\",\n pointerEvents: \"none\",\n children: arc.data.label\n })]\n })]\n }, `arc-${index}`);\n });\n }\n }), !allSegmentsHidden && svgChildren]\n })]\n }), showLegend && /*#__PURE__*/_jsx(Legend, {\n orientation: legendOrientation,\n position: legendPosition,\n alignment: legendAlignment,\n maxWidth: legendMaxWidth,\n textOverflow: legendTextOverflow,\n legendItemClassName: legendItemClassName,\n className: styles['pie-chart-legend'],\n shape: legendShape,\n ref: legendRef,\n chartId: chartId,\n interactive: legendInteractive\n }), withTooltips && tooltipOpen && tooltipData && /*#__PURE__*/_jsx(TooltipInPortal, {\n top: tooltipTop || 0,\n left: tooltipLeft || 0,\n children: /*#__PURE__*/_jsx(\"div\", {\n role: \"tooltip\",\n children: renderTooltip({\n tooltipData\n })\n })\n }), htmlChildren, otherChildren]\n })\n });\n};\nconst PieChartWithProvider = props => {\n const existingContext = useContext(GlobalChartsContext);\n\n // If we're already in a GlobalChartsProvider context, don't create a new one\n if (existingContext) {\n return /*#__PURE__*/_jsx(PieChartInternal, {\n ...props\n });\n }\n\n // Otherwise, create our own GlobalChartsProvider\n return /*#__PURE__*/_jsx(GlobalChartsProvider, {\n children: /*#__PURE__*/_jsx(PieChartInternal, {\n ...props\n })\n });\n};\nPieChartWithProvider.displayName = 'PieChart';\n\n// Create PieChart with composition API\nconst PieChart = attachSubComponents(PieChartWithProvider, {\n Legend: Legend,\n SVG: ChartSVG,\n HTML: ChartHTML\n});\n\n// Create responsive PieChart with composition API\nconst PieChartResponsive = attachSubComponents(withResponsive(PieChartWithProvider), {\n Legend: Legend,\n SVG: ChartSVG,\n HTML: ChartHTML\n});\nexport { PieChartResponsive as default, PieChart as PieChartUnresponsive };","import 'css-chunk:src/charts/pie-chart/pie-chart.module.scss';export default {\n \"pie-chart\": \"a8ccharts-C-n-Gu\",\n \"pie-chart--legend-top\": \"a8ccharts-Mu0uxl\"\n};"],"mappings":";;;;;;;;;;;;;;;;;;;;;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