@x-plat/design-system 0.19.0 → 0.21.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/dist/chunk-2EGVOUGV.cjs +93 -0
- package/dist/chunk-2T3BVV7R.js +0 -0
- package/dist/chunk-3FYYFDKQ.js +159 -0
- package/dist/chunk-3M3GFSHJ.js +67 -0
- package/dist/chunk-3WBHUFOA.cjs +48 -0
- package/dist/chunk-3XYYZQR5.cjs +22 -0
- package/dist/chunk-4EF7NVAL.js +67 -0
- package/dist/chunk-4ISERXK2.cjs +1 -0
- package/dist/chunk-4KYHHJ6Z.cjs +250 -0
- package/dist/chunk-4NSRDRXC.cjs +70 -0
- package/dist/chunk-4OXMRSVE.cjs +99 -0
- package/dist/chunk-55EPYLXN.js +30 -0
- package/dist/chunk-5CE3ADO5.js +254 -0
- package/dist/chunk-5F6Y2JD6.cjs +1 -0
- package/dist/chunk-5FMTMXSP.cjs +127 -0
- package/dist/chunk-5POCKDDY.js +36 -0
- package/dist/chunk-5VDI56BV.js +33 -0
- package/dist/chunk-5WLBUPSK.js +77 -0
- package/dist/chunk-5WNNWQHD.cjs +272 -0
- package/dist/chunk-66STZB6I.cjs +404 -0
- package/dist/chunk-6AIKCZN7.js +1455 -0
- package/dist/chunk-6IUJJUVP.js +18 -0
- package/dist/chunk-6P2B3ZGP.js +79 -0
- package/dist/chunk-764ILIDG.cjs +22 -0
- package/dist/chunk-7B44DWC4.js +0 -0
- package/dist/chunk-7BE6ETFY.js +18 -0
- package/dist/chunk-7BSUS5A4.js +97 -0
- package/dist/chunk-7RPWCDEW.cjs +20 -0
- package/dist/chunk-7ULXHGLO.cjs +77 -0
- package/dist/chunk-7YOI5XOW.js +55 -0
- package/dist/chunk-AFVTM5CP.js +0 -0
- package/dist/chunk-AN2WSL3B.cjs +1 -0
- package/dist/chunk-AT5Y5GLS.cjs +118 -0
- package/dist/chunk-AWPO2FI7.js +404 -0
- package/dist/chunk-BGXHIDUR.js +103 -0
- package/dist/chunk-BPZXL5TP.js +99 -0
- package/dist/chunk-BRTS5GWV.js +275 -0
- package/dist/chunk-BS3MLZCK.cjs +97 -0
- package/dist/chunk-BSPYYE2U.js +36 -0
- package/dist/chunk-BWJAEB42.js +48 -0
- package/dist/chunk-C4RMTISI.cjs +18 -0
- package/dist/chunk-C6M4XVR7.cjs +36 -0
- package/dist/chunk-CGC4D5MP.cjs +89 -0
- package/dist/chunk-CIRQYSQW.js +70 -0
- package/dist/chunk-CLOTWJNP.cjs +310 -0
- package/dist/chunk-CS7ZY35M.cjs +49 -0
- package/dist/chunk-CUV4RLDE.js +89 -0
- package/dist/chunk-CZAMLFSE.cjs +275 -0
- package/dist/chunk-D7QZLJ3Z.cjs +18 -0
- package/dist/chunk-DMSAAZ3M.cjs +92 -0
- package/dist/chunk-DUIZC7VJ.cjs +36 -0
- package/dist/chunk-DVBF4BDH.js +43 -0
- package/dist/chunk-EETYMP6K.cjs +584 -0
- package/dist/chunk-EFQL7JPX.js +0 -0
- package/dist/chunk-EFU7IAF5.cjs +12 -0
- package/dist/chunk-F3M2H5EX.cjs +79 -0
- package/dist/chunk-F436V2SX.cjs +254 -0
- package/dist/chunk-F664X2OY.js +250 -0
- package/dist/chunk-FF7ELUQW.cjs +1 -0
- package/dist/chunk-G3HE4S3Q.cjs +296 -0
- package/dist/chunk-GOPD5KUK.js +23 -0
- package/dist/chunk-GYTB24V6.cjs +107 -0
- package/dist/chunk-GZ657SGO.js +310 -0
- package/dist/chunk-H2QN65L6.cjs +1 -0
- package/dist/chunk-H6WUT7CK.js +22 -0
- package/dist/chunk-H76OQ75T.js +49 -0
- package/dist/chunk-HA3XONYI.js +18 -0
- package/dist/chunk-HF3UFXEU.js +296 -0
- package/dist/chunk-HGA47QVV.cjs +55 -0
- package/dist/chunk-HHPPAMXF.cjs +674 -0
- package/dist/chunk-HLV2XIE2.cjs +385 -0
- package/dist/chunk-HNQGIL45.cjs +96 -0
- package/dist/chunk-HQ37R7T3.js +53 -0
- package/dist/chunk-HXUGW4RR.js +187 -0
- package/dist/chunk-HYPRLWD3.js +272 -0
- package/dist/chunk-I7TLJUTP.cjs +6 -0
- package/dist/chunk-ICTWDTKC.cjs +1 -0
- package/dist/chunk-IPYKHDP4.cjs +187 -0
- package/dist/chunk-IRKREQ2X.cjs +18 -0
- package/dist/chunk-IVJJBMRY.js +92 -0
- package/dist/chunk-JPVIVOFG.js +26 -0
- package/dist/chunk-JYNBNSNF.js +151 -0
- package/dist/chunk-JZC3BXAC.js +93 -0
- package/dist/chunk-K5XPQWXN.cjs +92 -0
- package/dist/chunk-KQ3GOMHL.js +31 -0
- package/dist/chunk-KUJH72U6.cjs +159 -0
- package/dist/chunk-KVUXLC6M.cjs +479 -0
- package/dist/chunk-KZOJN57Q.js +19 -0
- package/dist/chunk-L3XPL4NP.cjs +53 -0
- package/dist/chunk-LOEMSXYB.js +0 -0
- package/dist/chunk-LU4KBPNG.cjs +23 -0
- package/dist/chunk-MWWWPQDB.js +26 -0
- package/dist/chunk-NCBB3WUJ.js +562 -0
- package/dist/chunk-NGCZTZST.cjs +562 -0
- package/dist/chunk-NSDKALIS.cjs +67 -0
- package/dist/chunk-NZHCRLNB.cjs +26 -0
- package/dist/chunk-OL4NANHB.js +0 -0
- package/dist/chunk-OTJRNKLR.js +96 -0
- package/dist/chunk-OWWFKTSK.js +0 -0
- package/dist/chunk-P2E3PB62.cjs +99 -0
- package/dist/chunk-P2QVFR7S.js +20 -0
- package/dist/chunk-P6ZGIYY7.cjs +18 -0
- package/dist/chunk-PFGSJJRY.cjs +19 -0
- package/dist/chunk-PNIUW7AJ.cjs +32 -0
- package/dist/chunk-Q2M2ONGO.js +70 -0
- package/dist/chunk-Q4PGP5KE.cjs +562 -0
- package/dist/chunk-QAI2YQPY.cjs +51 -0
- package/dist/chunk-QCD7UEZ3.cjs +59 -0
- package/dist/chunk-QEZ4R3SK.js +6 -0
- package/dist/chunk-QKDCPM2D.cjs +23 -0
- package/dist/chunk-QRGG3V7W.cjs +59 -0
- package/dist/chunk-QURIHUEC.js +107 -0
- package/dist/chunk-QY742LWN.js +30 -0
- package/dist/chunk-QYMRGYTN.js +127 -0
- package/dist/chunk-RLKJ2RZG.js +23 -0
- package/dist/chunk-RRR5BUOM.cjs +30 -0
- package/dist/chunk-RU3FCVXM.cjs +1 -0
- package/dist/chunk-RYTDVTV2.js +32 -0
- package/dist/chunk-RYYGUYDE.js +92 -0
- package/dist/chunk-SGLP4U3Y.cjs +67 -0
- package/dist/chunk-SJC543ZK.js +71 -0
- package/dist/chunk-SLYQK4SC.js +20 -0
- package/dist/chunk-SMLCOMLS.js +2888 -0
- package/dist/chunk-SNMOPLMH.cjs +372 -0
- package/dist/chunk-TRJUJYW7.cjs +151 -0
- package/dist/chunk-TTY5PE3P.js +30 -0
- package/dist/chunk-TXARYG3J.js +22 -0
- package/dist/chunk-TYXJU4EF.js +18 -0
- package/dist/chunk-U3PC7FYZ.cjs +26 -0
- package/dist/chunk-U67JM2WL.cjs +34 -0
- package/dist/chunk-UARGO5UG.js +59 -0
- package/dist/chunk-UCYE3H3F.cjs +43 -0
- package/dist/chunk-UGEGN35F.js +118 -0
- package/dist/chunk-UHUA3GQC.cjs +30 -0
- package/dist/chunk-UJQN477L.js +59 -0
- package/dist/chunk-UMX7DTFZ.cjs +70 -0
- package/dist/chunk-UT42P54P.js +372 -0
- package/dist/chunk-V76ZRGHQ.cjs +1 -0
- package/dist/chunk-VCIK366Y.cjs +1455 -0
- package/dist/chunk-VMA74ABT.cjs +137 -0
- package/dist/chunk-VSA62N2O.js +12 -0
- package/dist/chunk-WDAFLVQK.js +479 -0
- package/dist/chunk-WHMLMAMO.js +674 -0
- package/dist/chunk-WNBLKKLM.js +0 -0
- package/dist/chunk-WQ2GY7F3.js +46 -0
- package/dist/chunk-WRLCCK3M.cjs +30 -0
- package/dist/chunk-WVCZIOLY.js +562 -0
- package/dist/chunk-WZLGJQLW.js +385 -0
- package/dist/chunk-XB6FEBK6.js +34 -0
- package/dist/chunk-XMERDSRE.js +75 -0
- package/dist/chunk-XMLFKZYY.js +137 -0
- package/dist/chunk-XMM52J3T.js +584 -0
- package/dist/chunk-XZ7C5CGB.cjs +103 -0
- package/dist/chunk-YGFBAOKX.js +51 -0
- package/dist/chunk-YIN552MF.cjs +20 -0
- package/dist/chunk-YLC42E65.cjs +31 -0
- package/dist/chunk-YOTXRYJL.cjs +46 -0
- package/dist/chunk-ZAUGJZK7.js +99 -0
- package/dist/chunk-ZIZOQTDG.cjs +75 -0
- package/dist/chunk-ZMSV5VZI.cjs +2888 -0
- package/dist/chunk-ZN6MLZAE.cjs +71 -0
- package/dist/chunk-ZNCT6HXA.cjs +33 -0
- package/dist/components/Accordion/index.cjs +5 -1036
- package/dist/components/Accordion/index.js +5 -999
- package/dist/components/Alert/index.cjs +4 -69
- package/dist/components/Alert/index.js +4 -42
- package/dist/components/AutoResizeTextArea/index.cjs +6 -260
- package/dist/components/AutoResizeTextArea/index.js +6 -223
- package/dist/components/Avatar/index.cjs +4 -65
- package/dist/components/Avatar/index.js +4 -38
- package/dist/components/Badge/index.cjs +6 -69
- package/dist/components/Badge/index.js +5 -40
- package/dist/components/Box/index.cjs +4 -58
- package/dist/components/Box/index.js +4 -31
- package/dist/components/Breadcrumb/index.cjs +4 -42
- package/dist/components/Breadcrumb/index.js +3 -14
- package/dist/components/Button/index.cjs +5 -65
- package/dist/components/Button/index.js +5 -38
- package/dist/components/Calendar/index.cjs +6 -1317
- package/dist/components/Calendar/index.js +10 -1281
- package/dist/components/CardTab/index.cjs +4 -120
- package/dist/components/CardTab/index.js +4 -83
- package/dist/components/Chart/index.cjs +5 -708
- package/dist/components/Chart/index.js +4 -670
- package/dist/components/ChatInput/index.cjs +9 -390
- package/dist/components/ChatInput/index.js +9 -353
- package/dist/components/CheckBox/index.cjs +20 -1125
- package/dist/components/CheckBox/index.js +17 -1095
- package/dist/components/Chip/index.cjs +5 -55
- package/dist/components/Chip/index.js +5 -28
- package/dist/components/DatePicker/index.cjs +16 -2136
- package/dist/components/DatePicker/index.js +19 -2099
- package/dist/components/Divider/index.cjs +4 -58
- package/dist/components/Divider/index.js +4 -31
- package/dist/components/Drawer/index.cjs +5 -190
- package/dist/components/Drawer/index.js +5 -153
- package/dist/components/Dropdown/index.cjs +7 -375
- package/dist/components/Dropdown/index.js +7 -338
- package/dist/components/Editor/index.cjs +6 -1486
- package/dist/components/Editor/index.css +53 -0
- package/dist/components/Editor/index.d.cts +13 -0
- package/dist/components/Editor/index.d.ts +13 -0
- package/dist/components/Editor/index.js +6 -1453
- package/dist/components/EmptyState/index.cjs +4 -42
- package/dist/components/EmptyState/index.js +3 -14
- package/dist/components/FieldMessage/index.cjs +7 -182
- package/dist/components/FieldMessage/index.js +8 -154
- package/dist/components/FileUpload/index.cjs +7 -1171
- package/dist/components/FileUpload/index.js +7 -1134
- package/dist/components/HtmlTypeWriter/index.cjs +3 -171
- package/dist/components/HtmlTypeWriter/index.js +3 -133
- package/dist/components/IconButton/index.cjs +4 -65
- package/dist/components/IconButton/index.js +4 -38
- package/dist/components/ImageSelector/index.cjs +8 -1214
- package/dist/components/ImageSelector/index.js +8 -1177
- package/dist/components/Input/index.cjs +7 -429
- package/dist/components/Input/index.js +8 -392
- package/dist/components/Link/index.cjs +4 -61
- package/dist/components/Link/index.js +4 -34
- package/dist/components/LinkButton/index.cjs +5 -61
- package/dist/components/LinkButton/index.js +5 -34
- package/dist/components/Modal/index.cjs +5 -190
- package/dist/components/Modal/index.js +5 -153
- package/dist/components/NotificationBadge/index.cjs +5 -68
- package/dist/components/NotificationBadge/index.js +5 -40
- package/dist/components/Pagination/index.cjs +6 -1034
- package/dist/components/Pagination/index.js +6 -1007
- package/dist/components/PopOver/index.cjs +7 -363
- package/dist/components/PopOver/index.js +7 -326
- package/dist/components/Progress/index.cjs +5 -84
- package/dist/components/Progress/index.js +5 -57
- package/dist/components/Radio/index.cjs +7 -274
- package/dist/components/Radio/index.js +8 -237
- package/dist/components/Select/index.cjs +10 -1577
- package/dist/components/Select/index.js +11 -1540
- package/dist/components/Skeleton/index.cjs +4 -71
- package/dist/components/Skeleton/index.js +4 -44
- package/dist/components/Spinner/index.cjs +5 -88
- package/dist/components/Spinner/index.js +5 -61
- package/dist/components/Stat/index.cjs +5 -81
- package/dist/components/Stat/index.js +5 -54
- package/dist/components/Steps/index.cjs +7 -968
- package/dist/components/Steps/index.js +7 -941
- package/dist/components/Swiper/index.cjs +4 -357
- package/dist/components/Swiper/index.js +4 -320
- package/dist/components/Switch/index.cjs +7 -252
- package/dist/components/Switch/index.js +7 -215
- package/dist/components/Tab/index.cjs +4 -144
- package/dist/components/Tab/index.js +4 -107
- package/dist/components/Table/index.cjs +4 -310
- package/dist/components/Table/index.css +31 -5
- package/dist/components/Table/index.js +8 -273
- package/dist/components/Tag/index.cjs +6 -969
- package/dist/components/Tag/index.js +6 -942
- package/dist/components/TextArea/index.cjs +6 -229
- package/dist/components/TextArea/index.js +6 -192
- package/dist/components/TimePicker/index.cjs +9 -579
- package/dist/components/TimePicker/index.js +9 -542
- package/dist/components/Toast/index.cjs +5 -146
- package/dist/components/Toast/index.js +5 -108
- package/dist/components/ToggleChip/index.cjs +5 -66
- package/dist/components/ToggleChip/index.js +5 -39
- package/dist/components/Tooltip/index.cjs +6 -204
- package/dist/components/Tooltip/index.js +6 -167
- package/dist/components/Tour/index.cjs +6 -414
- package/dist/components/Tour/index.js +6 -377
- package/dist/components/Video/index.cjs +7 -796
- package/dist/components/Video/index.js +7 -759
- package/dist/components/index.cjs +140 -8315
- package/dist/components/index.css +31 -5
- package/dist/components/index.js +190 -8261
- package/dist/index.cjs +903 -13291
- package/dist/index.css +31 -5
- package/dist/index.js +524 -12499
- package/dist/layout/Grid/FullGrid/index.cjs +4 -46
- package/dist/layout/Grid/FullGrid/index.js +3 -18
- package/dist/layout/Grid/FullScreen/index.cjs +4 -46
- package/dist/layout/Grid/FullScreen/index.js +3 -18
- package/dist/layout/Grid/Item/index.cjs +5 -68
- package/dist/layout/Grid/Item/index.js +5 -41
- package/dist/layout/Grid/index.cjs +14 -109
- package/dist/layout/Grid/index.js +14 -79
- package/dist/layout/Header/index.cjs +4 -44
- package/dist/layout/Header/index.js +3 -16
- package/dist/layout/Layout/index.cjs +4 -42
- package/dist/layout/Layout/index.js +3 -14
- package/dist/layout/SideBar/index.cjs +6 -96
- package/dist/layout/SideBar/index.js +6 -57
- package/dist/layout/index.cjs +38 -209
- package/dist/layout/index.js +27 -153
- package/dist/tokens/index.cjs +627 -6119
- package/dist/tokens/index.js +324 -5489
- package/guidelines/components/editor.md +3 -0
- package/guidelines/components/table.md +23 -0
- package/guidelines/setup.md +7 -0
- package/package.json +6 -3
|
@@ -0,0 +1,674 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/components/Chart/Chart.tsx
|
|
2
|
+
var _react = require('react'); var _react2 = _interopRequireDefault(_react);
|
|
3
|
+
var _jsxruntime = require('react/jsx-runtime');
|
|
4
|
+
var CATEGORICAL_COUNT = 8;
|
|
5
|
+
var LINE_BAR_PALETTES = Array.from({ length: CATEGORICAL_COUNT }, (_, i) => {
|
|
6
|
+
const n = i + 1;
|
|
7
|
+
return [
|
|
8
|
+
`var(--semantic-categorical-${n}-bg)`,
|
|
9
|
+
`var(--semantic-categorical-${n}-area)`,
|
|
10
|
+
`var(--semantic-categorical-${n}-fill)`,
|
|
11
|
+
`var(--semantic-categorical-${n}-text)`
|
|
12
|
+
];
|
|
13
|
+
});
|
|
14
|
+
var PIE_COLORS = Array.from(
|
|
15
|
+
{ length: CATEGORICAL_COUNT },
|
|
16
|
+
(_, i) => `var(--semantic-categorical-${i + 1}-fill)`
|
|
17
|
+
);
|
|
18
|
+
var hashString = (str) => {
|
|
19
|
+
let hash = 0;
|
|
20
|
+
for (let i = 0; i < str.length; i++) {
|
|
21
|
+
hash = (hash << 5) - hash + str.charCodeAt(i) | 0;
|
|
22
|
+
}
|
|
23
|
+
return Math.abs(hash);
|
|
24
|
+
};
|
|
25
|
+
var getPalette = (palettes, index, key) => {
|
|
26
|
+
const offset = key ? hashString(key) : 0;
|
|
27
|
+
return palettes[(index + offset) % palettes.length];
|
|
28
|
+
};
|
|
29
|
+
var PADDING = { top: 20, right: 20, bottom: 30, left: 40 };
|
|
30
|
+
var toSmoothPath = (points) => {
|
|
31
|
+
if (points.length < 2) return "";
|
|
32
|
+
const p = points;
|
|
33
|
+
let d = `M ${p[0].x} ${p[0].y}`;
|
|
34
|
+
for (let i = 0; i < p.length - 1; i++) {
|
|
35
|
+
const p0 = p[Math.max(0, i - 1)];
|
|
36
|
+
const p1 = p[i];
|
|
37
|
+
const p2 = p[i + 1];
|
|
38
|
+
const p3 = p[Math.min(p.length - 1, i + 2)];
|
|
39
|
+
const cp1x = p1.x + (p2.x - p0.x) / 6;
|
|
40
|
+
const cp1y = p1.y + (p2.y - p0.y) / 6;
|
|
41
|
+
const cp2x = p2.x - (p3.x - p1.x) / 6;
|
|
42
|
+
const cp2y = p2.y - (p3.y - p1.y) / 6;
|
|
43
|
+
d += ` C ${cp1x} ${cp1y}, ${cp2x} ${cp2y}, ${p2.x} ${p2.y}`;
|
|
44
|
+
}
|
|
45
|
+
return d;
|
|
46
|
+
};
|
|
47
|
+
var useChartSize = (ref) => {
|
|
48
|
+
const [size, setSize] = _react2.default.useState({ width: 0, height: 0 });
|
|
49
|
+
_react2.default.useEffect(() => {
|
|
50
|
+
const el = ref.current;
|
|
51
|
+
if (!el) return;
|
|
52
|
+
let rafId = 0;
|
|
53
|
+
const observer = new ResizeObserver((entries) => {
|
|
54
|
+
cancelAnimationFrame(rafId);
|
|
55
|
+
rafId = requestAnimationFrame(() => {
|
|
56
|
+
const entry = entries[0];
|
|
57
|
+
if (!entry) return;
|
|
58
|
+
const { width, height } = entry.contentRect;
|
|
59
|
+
const w = Math.floor(width);
|
|
60
|
+
const h = Math.floor(height);
|
|
61
|
+
if (w <= 0 || h <= 0) return;
|
|
62
|
+
setSize((prev) => prev.width === w && prev.height === h ? prev : { width: w, height: h });
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
observer.observe(el);
|
|
66
|
+
return () => {
|
|
67
|
+
cancelAnimationFrame(rafId);
|
|
68
|
+
observer.disconnect();
|
|
69
|
+
};
|
|
70
|
+
}, [ref]);
|
|
71
|
+
return size;
|
|
72
|
+
};
|
|
73
|
+
var prefersReducedMotion = () => typeof window !== "undefined" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
74
|
+
var useChartAnimation = (containerRef, dataKey) => {
|
|
75
|
+
const [animate, setAnimate] = _react2.default.useState(false);
|
|
76
|
+
const prevDataKey = _react2.default.useRef(dataKey);
|
|
77
|
+
const hasAnimated = _react2.default.useRef(false);
|
|
78
|
+
_react2.default.useEffect(() => {
|
|
79
|
+
if (prefersReducedMotion()) return;
|
|
80
|
+
const el = containerRef.current;
|
|
81
|
+
if (!el) return;
|
|
82
|
+
const observer = new IntersectionObserver(
|
|
83
|
+
([entry]) => {
|
|
84
|
+
if (entry.isIntersecting && !hasAnimated.current) {
|
|
85
|
+
hasAnimated.current = true;
|
|
86
|
+
setAnimate(true);
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
{ threshold: 0.1 }
|
|
90
|
+
);
|
|
91
|
+
observer.observe(el);
|
|
92
|
+
return () => observer.disconnect();
|
|
93
|
+
}, [containerRef]);
|
|
94
|
+
_react2.default.useEffect(() => {
|
|
95
|
+
if (dataKey !== prevDataKey.current) {
|
|
96
|
+
prevDataKey.current = dataKey;
|
|
97
|
+
if (prefersReducedMotion()) return;
|
|
98
|
+
setAnimate(false);
|
|
99
|
+
requestAnimationFrame(() => {
|
|
100
|
+
requestAnimationFrame(() => setAnimate(true));
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
}, [dataKey]);
|
|
104
|
+
return animate || prefersReducedMotion();
|
|
105
|
+
};
|
|
106
|
+
var TOOLTIP_OFFSET = 12;
|
|
107
|
+
var useChartTooltip = (enabled) => {
|
|
108
|
+
const [tooltip, setTooltip] = _react2.default.useState({
|
|
109
|
+
visible: false,
|
|
110
|
+
x: 0,
|
|
111
|
+
y: 0,
|
|
112
|
+
content: ""
|
|
113
|
+
});
|
|
114
|
+
const containerRef = _react2.default.useRef(null);
|
|
115
|
+
const rafRef = _react2.default.useRef(0);
|
|
116
|
+
const move = _react2.default.useCallback((e) => {
|
|
117
|
+
if (!enabled) return;
|
|
118
|
+
const cx = e.clientX;
|
|
119
|
+
const cy = e.clientY;
|
|
120
|
+
cancelAnimationFrame(rafRef.current);
|
|
121
|
+
rafRef.current = requestAnimationFrame(() => {
|
|
122
|
+
const rect = _optionalChain([containerRef, 'access', _2 => _2.current, 'optionalAccess', _3 => _3.getBoundingClientRect, 'call', _4 => _4()]);
|
|
123
|
+
if (!rect) return;
|
|
124
|
+
setTooltip((prev) => ({ ...prev, x: cx - rect.left, y: cy - rect.top }));
|
|
125
|
+
});
|
|
126
|
+
}, [enabled]);
|
|
127
|
+
const show = _react2.default.useCallback((e, content) => {
|
|
128
|
+
if (!enabled) return;
|
|
129
|
+
const rect = _optionalChain([containerRef, 'access', _5 => _5.current, 'optionalAccess', _6 => _6.getBoundingClientRect, 'call', _7 => _7()]);
|
|
130
|
+
if (!rect) return;
|
|
131
|
+
setTooltip({ visible: true, x: e.clientX - rect.left, y: e.clientY - rect.top, content });
|
|
132
|
+
}, [enabled]);
|
|
133
|
+
const hide = _react2.default.useCallback(() => {
|
|
134
|
+
cancelAnimationFrame(rafRef.current);
|
|
135
|
+
setTooltip((prev) => ({ ...prev, visible: false }));
|
|
136
|
+
}, []);
|
|
137
|
+
return { tooltip, show, hide, move, containerRef };
|
|
138
|
+
};
|
|
139
|
+
var formatTick = (value, maxVal) => {
|
|
140
|
+
const step = maxVal / 4;
|
|
141
|
+
if (!Number.isFinite(step) || step <= 0) return "0";
|
|
142
|
+
const decimals = step >= 1 ? 0 : Math.min(4, Math.ceil(-Math.log10(step)));
|
|
143
|
+
const fixed = value.toFixed(decimals);
|
|
144
|
+
return decimals === 0 ? Number(fixed).toLocaleString("en-US") : fixed;
|
|
145
|
+
};
|
|
146
|
+
var GridLines = _react2.default.memo(({ width, height, chartH, maxVal }) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _jsxruntime.Fragment, { children: [0, 0.25, 0.5, 0.75, 1].map((ratio) => {
|
|
147
|
+
const y = PADDING.top + (1 - ratio) * chartH;
|
|
148
|
+
const val = formatTick(maxVal * ratio, maxVal);
|
|
149
|
+
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "g", { children: [
|
|
150
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "line", { x1: PADDING.left, y1: y, x2: width - PADDING.right, y2: y, className: "chart-grid" }),
|
|
151
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "text", { x: PADDING.left - 8, y: y + 4, className: "chart-axis-label", textAnchor: "end", children: val })
|
|
152
|
+
] }, ratio);
|
|
153
|
+
}) }));
|
|
154
|
+
GridLines.displayName = "GridLines";
|
|
155
|
+
var getLabelStep = (count, chartW) => {
|
|
156
|
+
const minLabelWidth = 40;
|
|
157
|
+
const maxLabels = Math.floor(chartW / minLabelWidth);
|
|
158
|
+
if (count <= maxLabels) return 1;
|
|
159
|
+
return Math.ceil(count / maxLabels);
|
|
160
|
+
};
|
|
161
|
+
var AxisLabels = _react2.default.memo(({ labels, count, chartW, height }) => {
|
|
162
|
+
const step = getLabelStep(count, chartW);
|
|
163
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _jsxruntime.Fragment, { children: labels.map((label, i) => {
|
|
164
|
+
if (i % step !== 0) return null;
|
|
165
|
+
const x = PADDING.left + i / (count - 1 || 1) * chartW;
|
|
166
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "text", { x, y: height - 8, className: "chart-axis-label", textAnchor: "middle", children: label }, i);
|
|
167
|
+
}) });
|
|
168
|
+
});
|
|
169
|
+
AxisLabels.displayName = "AxisLabels";
|
|
170
|
+
var useCrosshair = (seriesPoints, entries, labels, chartH) => {
|
|
171
|
+
const [activeIndex, setActiveIndex] = _react2.default.useState(null);
|
|
172
|
+
const handleMouseMove = _react2.default.useCallback((e) => {
|
|
173
|
+
const svg = e.currentTarget;
|
|
174
|
+
const rect = svg.getBoundingClientRect();
|
|
175
|
+
const mx = (e.clientX - rect.left) / rect.width * svg.viewBox.baseVal.width;
|
|
176
|
+
if (seriesPoints.length === 0 || seriesPoints[0].length === 0) return;
|
|
177
|
+
const points = seriesPoints[0];
|
|
178
|
+
const step = points.length > 1 ? Math.abs(points[1].x - points[0].x) : 20;
|
|
179
|
+
const threshold = step / 2;
|
|
180
|
+
let closest = 0;
|
|
181
|
+
let minDist = Math.abs(points[0].x - mx);
|
|
182
|
+
for (let i = 1; i < points.length; i++) {
|
|
183
|
+
const dist = Math.abs(points[i].x - mx);
|
|
184
|
+
if (dist < minDist) {
|
|
185
|
+
minDist = dist;
|
|
186
|
+
closest = i;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
setActiveIndex(minDist <= threshold ? closest : null);
|
|
190
|
+
}, [seriesPoints]);
|
|
191
|
+
const handleMouseLeave = _react2.default.useCallback(() => {
|
|
192
|
+
setActiveIndex(null);
|
|
193
|
+
}, []);
|
|
194
|
+
const tooltipContent = _react2.default.useMemo(() => {
|
|
195
|
+
if (activeIndex === null) return "";
|
|
196
|
+
return entries.map(([key], di) => {
|
|
197
|
+
const p = _optionalChain([seriesPoints, 'access', _8 => _8[di], 'optionalAccess', _9 => _9[activeIndex]]);
|
|
198
|
+
return p ? `${key}: ${p.v}` : "";
|
|
199
|
+
}).filter(Boolean).join(" / ");
|
|
200
|
+
}, [activeIndex, entries, seriesPoints]);
|
|
201
|
+
const getTooltipAt = _react2.default.useCallback((idx) => {
|
|
202
|
+
return entries.map(([key], di) => {
|
|
203
|
+
const p = _optionalChain([seriesPoints, 'access', _10 => _10[di], 'optionalAccess', _11 => _11[idx]]);
|
|
204
|
+
return p ? `${key}: ${p.v}` : "";
|
|
205
|
+
}).filter(Boolean).join(" / ");
|
|
206
|
+
}, [entries, seriesPoints]);
|
|
207
|
+
return { activeIndex, handleMouseMove, handleMouseLeave, tooltipContent, getTooltipAt };
|
|
208
|
+
};
|
|
209
|
+
var LineChart = _react2.default.memo(({ data, labels, width, height, animate, onHover, onMove, onLeave }) => {
|
|
210
|
+
const entries = _react2.default.useMemo(() => Object.entries(data), [data]);
|
|
211
|
+
const maxVal = _react2.default.useMemo(() => {
|
|
212
|
+
const allValues = entries.flatMap(([, v]) => v);
|
|
213
|
+
return Math.max(...allValues) * 1.2 || 1;
|
|
214
|
+
}, [entries]);
|
|
215
|
+
const count = labels.length;
|
|
216
|
+
const chartW = width - PADDING.left - PADDING.right;
|
|
217
|
+
const chartH = height - PADDING.top - PADDING.bottom;
|
|
218
|
+
const seriesPoints = _react2.default.useMemo(
|
|
219
|
+
() => entries.map(
|
|
220
|
+
([, values]) => values.map((v, i) => ({
|
|
221
|
+
x: PADDING.left + i / (count - 1 || 1) * chartW,
|
|
222
|
+
y: PADDING.top + (1 - v / maxVal) * chartH,
|
|
223
|
+
v
|
|
224
|
+
}))
|
|
225
|
+
),
|
|
226
|
+
[entries, count, chartW, chartH, maxVal]
|
|
227
|
+
);
|
|
228
|
+
const clipRef = _react2.default.useRef(null);
|
|
229
|
+
const { activeIndex, handleMouseMove, handleMouseLeave, getTooltipAt } = useCrosshair(seriesPoints, entries, labels, chartH);
|
|
230
|
+
_react2.default.useEffect(() => {
|
|
231
|
+
if (!animate || !clipRef.current) return;
|
|
232
|
+
clipRef.current.setAttribute("width", "0");
|
|
233
|
+
requestAnimationFrame(() => {
|
|
234
|
+
if (clipRef.current) {
|
|
235
|
+
clipRef.current.style.transition = "width 1200ms ease-out 200ms";
|
|
236
|
+
clipRef.current.setAttribute("width", `${width}`);
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
}, [animate, width]);
|
|
240
|
+
const activeX = activeIndex !== null ? _nullishCoalesce(_optionalChain([seriesPoints, 'access', _12 => _12[0], 'optionalAccess', _13 => _13[activeIndex], 'optionalAccess', _14 => _14.x]), () => ( null)) : null;
|
|
241
|
+
const lineClipId = "line-area-clip";
|
|
242
|
+
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
|
|
243
|
+
"svg",
|
|
244
|
+
{
|
|
245
|
+
viewBox: `0 0 ${width} ${height}`,
|
|
246
|
+
className: "chart-svg",
|
|
247
|
+
onMouseMove: (e) => {
|
|
248
|
+
handleMouseMove(e);
|
|
249
|
+
if (activeIndex !== null) {
|
|
250
|
+
onHover(e, `${labels[activeIndex]} \u2014 ${getTooltipAt(activeIndex)}`);
|
|
251
|
+
} else {
|
|
252
|
+
onLeave();
|
|
253
|
+
}
|
|
254
|
+
},
|
|
255
|
+
onMouseLeave: () => {
|
|
256
|
+
handleMouseLeave();
|
|
257
|
+
onLeave();
|
|
258
|
+
},
|
|
259
|
+
children: [
|
|
260
|
+
animate && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "defs", { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "clipPath", { id: lineClipId, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "rect", { ref: clipRef, x: "0", y: "0", width: animate ? 0 : width, height }) }) }),
|
|
261
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, GridLines, { width, height, chartH, maxVal }),
|
|
262
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, AxisLabels, { labels, count, chartW, height }),
|
|
263
|
+
entries.map(([key], di) => {
|
|
264
|
+
const palette = getPalette(LINE_BAR_PALETTES, di, key);
|
|
265
|
+
const color = palette[2];
|
|
266
|
+
const areaColor = palette[0];
|
|
267
|
+
const points = seriesPoints[di];
|
|
268
|
+
const gradientId = `line-gradient-${di}`;
|
|
269
|
+
const polyPoints = points.map((p) => `${p.x},${p.y}`).join(" ");
|
|
270
|
+
const areaD = `M ${points[0].x},${points[0].y} ${points.map((p) => `L ${p.x},${p.y}`).join(" ")} L ${points[points.length - 1].x},${PADDING.top + chartH} L ${points[0].x},${PADDING.top + chartH} Z`;
|
|
271
|
+
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "g", { children: [
|
|
272
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "defs", { children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "linearGradient", { id: gradientId, x1: "0", y1: "0", x2: "0", y2: "1", children: [
|
|
273
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "stop", { offset: "0%", stopColor: areaColor, stopOpacity: "0.2" }),
|
|
274
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "stop", { offset: "100%", stopColor: areaColor, stopOpacity: "0" })
|
|
275
|
+
] }) }),
|
|
276
|
+
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "g", { clipPath: animate ? `url(#${lineClipId})` : void 0, children: [
|
|
277
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "path", { d: areaD, fill: `url(#${gradientId})` }),
|
|
278
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "polyline", { points: polyPoints, fill: "none", stroke: color, strokeWidth: "2" })
|
|
279
|
+
] }),
|
|
280
|
+
activeIndex !== null && points[activeIndex] && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
281
|
+
"circle",
|
|
282
|
+
{
|
|
283
|
+
cx: points[activeIndex].x,
|
|
284
|
+
cy: points[activeIndex].y,
|
|
285
|
+
r: "5",
|
|
286
|
+
fill: color,
|
|
287
|
+
className: "chart-point-active"
|
|
288
|
+
}
|
|
289
|
+
)
|
|
290
|
+
] }, di);
|
|
291
|
+
}),
|
|
292
|
+
activeX !== null && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
293
|
+
"line",
|
|
294
|
+
{
|
|
295
|
+
x1: activeX,
|
|
296
|
+
y1: PADDING.top,
|
|
297
|
+
x2: activeX,
|
|
298
|
+
y2: PADDING.top + chartH,
|
|
299
|
+
className: "chart-crosshair"
|
|
300
|
+
}
|
|
301
|
+
),
|
|
302
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
303
|
+
"rect",
|
|
304
|
+
{
|
|
305
|
+
x: PADDING.left,
|
|
306
|
+
y: PADDING.top,
|
|
307
|
+
width: chartW,
|
|
308
|
+
height: chartH,
|
|
309
|
+
fill: "transparent",
|
|
310
|
+
style: { cursor: "crosshair" }
|
|
311
|
+
}
|
|
312
|
+
)
|
|
313
|
+
]
|
|
314
|
+
}
|
|
315
|
+
);
|
|
316
|
+
});
|
|
317
|
+
LineChart.displayName = "LineChart";
|
|
318
|
+
var CurveChart = _react2.default.memo(({ data, labels, width, height, animate, onHover, onMove, onLeave }) => {
|
|
319
|
+
const entries = _react2.default.useMemo(() => Object.entries(data), [data]);
|
|
320
|
+
const maxVal = _react2.default.useMemo(() => {
|
|
321
|
+
const allValues = entries.flatMap(([, v]) => v);
|
|
322
|
+
return Math.max(...allValues) * 1.2 || 1;
|
|
323
|
+
}, [entries]);
|
|
324
|
+
const count = labels.length;
|
|
325
|
+
const chartW = width - PADDING.left - PADDING.right;
|
|
326
|
+
const chartH = height - PADDING.top - PADDING.bottom;
|
|
327
|
+
const seriesPoints = _react2.default.useMemo(
|
|
328
|
+
() => entries.map(
|
|
329
|
+
([, values]) => values.map((v, i) => ({
|
|
330
|
+
x: PADDING.left + i / (count - 1 || 1) * chartW,
|
|
331
|
+
y: PADDING.top + (1 - v / maxVal) * chartH,
|
|
332
|
+
v
|
|
333
|
+
}))
|
|
334
|
+
),
|
|
335
|
+
[entries, count, chartW, chartH, maxVal]
|
|
336
|
+
);
|
|
337
|
+
const curveClipRef = _react2.default.useRef(null);
|
|
338
|
+
const { activeIndex, handleMouseMove, handleMouseLeave, getTooltipAt } = useCrosshair(seriesPoints, entries, labels, chartH);
|
|
339
|
+
_react2.default.useEffect(() => {
|
|
340
|
+
if (!animate || !curveClipRef.current) return;
|
|
341
|
+
curveClipRef.current.setAttribute("width", "0");
|
|
342
|
+
requestAnimationFrame(() => {
|
|
343
|
+
if (curveClipRef.current) {
|
|
344
|
+
curveClipRef.current.style.transition = "width 1200ms ease-out 200ms";
|
|
345
|
+
curveClipRef.current.setAttribute("width", `${width}`);
|
|
346
|
+
}
|
|
347
|
+
});
|
|
348
|
+
}, [animate, width]);
|
|
349
|
+
const activeX = activeIndex !== null ? _nullishCoalesce(_optionalChain([seriesPoints, 'access', _15 => _15[0], 'optionalAccess', _16 => _16[activeIndex], 'optionalAccess', _17 => _17.x]), () => ( null)) : null;
|
|
350
|
+
const curveClipId = "curve-area-clip";
|
|
351
|
+
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
|
|
352
|
+
"svg",
|
|
353
|
+
{
|
|
354
|
+
viewBox: `0 0 ${width} ${height}`,
|
|
355
|
+
className: "chart-svg",
|
|
356
|
+
onMouseMove: (e) => {
|
|
357
|
+
handleMouseMove(e);
|
|
358
|
+
if (activeIndex !== null && _optionalChain([seriesPoints, 'access', _18 => _18[0], 'optionalAccess', _19 => _19[activeIndex]])) {
|
|
359
|
+
const p = seriesPoints[0][activeIndex];
|
|
360
|
+
onHover(e, `${labels[activeIndex]} \u2014 ${getTooltipAt(activeIndex)}`);
|
|
361
|
+
} else {
|
|
362
|
+
onLeave();
|
|
363
|
+
}
|
|
364
|
+
},
|
|
365
|
+
onMouseLeave: () => {
|
|
366
|
+
handleMouseLeave();
|
|
367
|
+
onLeave();
|
|
368
|
+
},
|
|
369
|
+
children: [
|
|
370
|
+
animate && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "defs", { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "clipPath", { id: curveClipId, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "rect", { ref: curveClipRef, x: "0", y: "0", width: animate ? 0 : width, height }) }) }),
|
|
371
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, GridLines, { width, height, chartH, maxVal }),
|
|
372
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, AxisLabels, { labels, count, chartW, height }),
|
|
373
|
+
entries.map(([key], di) => {
|
|
374
|
+
const palette = getPalette(LINE_BAR_PALETTES, di, key);
|
|
375
|
+
const color = palette[2];
|
|
376
|
+
const areaColor = palette[0];
|
|
377
|
+
const points = seriesPoints[di];
|
|
378
|
+
const gradientId = `curve-gradient-${di}`;
|
|
379
|
+
const linePath = toSmoothPath(points);
|
|
380
|
+
const areaPath = linePath + ` L ${points[points.length - 1].x} ${PADDING.top + chartH} L ${points[0].x} ${PADDING.top + chartH} Z`;
|
|
381
|
+
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "g", { children: [
|
|
382
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "defs", { children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "linearGradient", { id: gradientId, x1: "0", y1: "0", x2: "0", y2: "1", children: [
|
|
383
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "stop", { offset: "0%", stopColor: areaColor, stopOpacity: "0.4" }),
|
|
384
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "stop", { offset: "100%", stopColor: areaColor, stopOpacity: "0.02" })
|
|
385
|
+
] }) }),
|
|
386
|
+
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "g", { clipPath: animate ? `url(#${curveClipId})` : void 0, children: [
|
|
387
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "path", { d: areaPath, fill: `url(#${gradientId})` }),
|
|
388
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "path", { d: linePath, fill: "none", stroke: color, strokeWidth: "2" })
|
|
389
|
+
] }),
|
|
390
|
+
activeIndex !== null && points[activeIndex] && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
391
|
+
"circle",
|
|
392
|
+
{
|
|
393
|
+
cx: points[activeIndex].x,
|
|
394
|
+
cy: points[activeIndex].y,
|
|
395
|
+
r: "5",
|
|
396
|
+
fill: color,
|
|
397
|
+
className: "chart-point-active"
|
|
398
|
+
}
|
|
399
|
+
)
|
|
400
|
+
] }, di);
|
|
401
|
+
}),
|
|
402
|
+
activeX !== null && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
403
|
+
"line",
|
|
404
|
+
{
|
|
405
|
+
x1: activeX,
|
|
406
|
+
y1: PADDING.top,
|
|
407
|
+
x2: activeX,
|
|
408
|
+
y2: PADDING.top + chartH,
|
|
409
|
+
className: "chart-crosshair"
|
|
410
|
+
}
|
|
411
|
+
),
|
|
412
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
413
|
+
"rect",
|
|
414
|
+
{
|
|
415
|
+
x: PADDING.left,
|
|
416
|
+
y: PADDING.top,
|
|
417
|
+
width: chartW,
|
|
418
|
+
height: chartH,
|
|
419
|
+
fill: "transparent",
|
|
420
|
+
style: { cursor: "crosshair" }
|
|
421
|
+
}
|
|
422
|
+
)
|
|
423
|
+
]
|
|
424
|
+
}
|
|
425
|
+
);
|
|
426
|
+
});
|
|
427
|
+
CurveChart.displayName = "CurveChart";
|
|
428
|
+
var BarChart = _react2.default.memo(({ data, labels, width, height, animate, onHover, onMove, onLeave }) => {
|
|
429
|
+
const entries = _react2.default.useMemo(() => Object.entries(data), [data]);
|
|
430
|
+
const maxVal = _react2.default.useMemo(() => {
|
|
431
|
+
const allValues = entries.flatMap(([, v]) => v);
|
|
432
|
+
return Math.max(...allValues) * 1.2 || 1;
|
|
433
|
+
}, [entries]);
|
|
434
|
+
const count = labels.length;
|
|
435
|
+
const groupCount = entries.length;
|
|
436
|
+
const chartW = width - PADDING.left - PADDING.right;
|
|
437
|
+
const chartH = height - PADDING.top - PADDING.bottom;
|
|
438
|
+
const groupW = chartW / count;
|
|
439
|
+
const barGap = groupCount > 1 ? 2 : 0;
|
|
440
|
+
const barW = Math.max(1, Math.min(32, (groupW * 0.7 - barGap * (groupCount - 1)) / groupCount));
|
|
441
|
+
const baseline = PADDING.top + chartH;
|
|
442
|
+
const bars = _react2.default.useMemo(
|
|
443
|
+
() => entries.map(
|
|
444
|
+
([, values], di) => values.map((v, i) => {
|
|
445
|
+
const totalBarsW = barW * groupCount + barGap * (groupCount - 1);
|
|
446
|
+
const h = Math.max(0, v / maxVal * chartH);
|
|
447
|
+
const x = PADDING.left + groupW * i + (groupW - totalBarsW) / 2 + (barW + barGap) * di;
|
|
448
|
+
const y = PADDING.top + chartH - h;
|
|
449
|
+
return { x, y, w: barW, h, v };
|
|
450
|
+
})
|
|
451
|
+
),
|
|
452
|
+
[entries, maxVal, chartH, groupW, barW, barGap, groupCount]
|
|
453
|
+
);
|
|
454
|
+
const barLabelStep = getLabelStep(count, chartW);
|
|
455
|
+
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "svg", { viewBox: `0 0 ${width} ${height}`, className: "chart-svg", children: [
|
|
456
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, GridLines, { width, height, chartH, maxVal }),
|
|
457
|
+
labels.map((label, i) => {
|
|
458
|
+
if (i % barLabelStep !== 0) return null;
|
|
459
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "text", { x: PADDING.left + groupW * i + groupW / 2, y: height - 8, className: "chart-axis-label", textAnchor: "middle", children: label }, i);
|
|
460
|
+
}),
|
|
461
|
+
entries.map(([key], di) => {
|
|
462
|
+
const palette = getPalette(LINE_BAR_PALETTES, di, key);
|
|
463
|
+
const color = palette[2];
|
|
464
|
+
return bars[di].map((b, i) => {
|
|
465
|
+
const r = Math.min(4, b.w / 2);
|
|
466
|
+
const d = b.h <= r ? `M ${b.x} ${b.y + b.h} V ${b.y} H ${b.x + b.w} V ${b.y + b.h} Z` : `M ${b.x} ${b.y + b.h} V ${b.y + r} Q ${b.x} ${b.y} ${b.x + r} ${b.y} H ${b.x + b.w - r} Q ${b.x + b.w} ${b.y} ${b.x + b.w} ${b.y + r} V ${b.y + b.h} Z`;
|
|
467
|
+
const delay = 100 + i * 80;
|
|
468
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
469
|
+
"path",
|
|
470
|
+
{
|
|
471
|
+
d,
|
|
472
|
+
fill: color,
|
|
473
|
+
className: `chart-bar ${animate ? "chart-bar-animate" : ""}`,
|
|
474
|
+
style: animate ? {
|
|
475
|
+
transformOrigin: `${b.x + b.w / 2}px ${baseline}px`,
|
|
476
|
+
animationDelay: `${delay}ms`
|
|
477
|
+
} : void 0,
|
|
478
|
+
onMouseEnter: (e) => onHover(e, `${key}: ${labels[i]} \u2014 ${b.v}`),
|
|
479
|
+
onMouseMove: onMove,
|
|
480
|
+
onMouseLeave: onLeave
|
|
481
|
+
},
|
|
482
|
+
`${di}-${i}`
|
|
483
|
+
);
|
|
484
|
+
});
|
|
485
|
+
})
|
|
486
|
+
] });
|
|
487
|
+
});
|
|
488
|
+
BarChart.displayName = "BarChart";
|
|
489
|
+
var PieDonutChart = _react2.default.memo(
|
|
490
|
+
({ data, labels, width, height, animate, isDoughnut, onHover, onMove, onLeave }) => {
|
|
491
|
+
const entries = _react2.default.useMemo(() => Object.entries(data), [data]);
|
|
492
|
+
const values = _react2.default.useMemo(() => entries.flatMap(([, v]) => v), [entries]);
|
|
493
|
+
const total = _react2.default.useMemo(() => values.reduce((a, b) => a + b, 0) || 1, [values]);
|
|
494
|
+
const size = Math.min(width, height);
|
|
495
|
+
const cx = size / 2;
|
|
496
|
+
const cy = size / 2;
|
|
497
|
+
const r = size * 0.4;
|
|
498
|
+
const innerR = isDoughnut ? r * 0.5 : 0;
|
|
499
|
+
const firstKey = _nullishCoalesce(_optionalChain([entries, 'access', _20 => _20[0], 'optionalAccess', _21 => _21[0]]), () => ( ""));
|
|
500
|
+
const colorOffset = hashString(firstKey);
|
|
501
|
+
const maskRef = _react2.default.useRef(null);
|
|
502
|
+
const maskR = r + 10;
|
|
503
|
+
const maskCircumference = 2 * Math.PI * maskR;
|
|
504
|
+
_react2.default.useEffect(() => {
|
|
505
|
+
if (!animate || !maskRef.current) return;
|
|
506
|
+
const el = maskRef.current;
|
|
507
|
+
el.style.strokeDasharray = `${maskCircumference}`;
|
|
508
|
+
el.style.strokeDashoffset = `${maskCircumference}`;
|
|
509
|
+
requestAnimationFrame(() => {
|
|
510
|
+
el.style.transition = "stroke-dashoffset 1000ms ease-out";
|
|
511
|
+
el.style.strokeDashoffset = "0";
|
|
512
|
+
});
|
|
513
|
+
}, [animate, maskCircumference]);
|
|
514
|
+
const sliceData = _react2.default.useMemo(() => {
|
|
515
|
+
let angle0 = -Math.PI / 2;
|
|
516
|
+
let cumulativeAngle = 0;
|
|
517
|
+
return values.map((v, i) => {
|
|
518
|
+
const angle = v / total * Math.PI * 2;
|
|
519
|
+
const endAngle = angle0 + angle;
|
|
520
|
+
const largeArc = angle > Math.PI ? 1 : 0;
|
|
521
|
+
const x1 = cx + r * Math.cos(angle0);
|
|
522
|
+
const y1 = cy + r * Math.sin(angle0);
|
|
523
|
+
const x2 = cx + r * Math.cos(endAngle);
|
|
524
|
+
const y2 = cy + r * Math.sin(endAngle);
|
|
525
|
+
let d;
|
|
526
|
+
if (innerR > 0) {
|
|
527
|
+
const ix1 = cx + innerR * Math.cos(angle0);
|
|
528
|
+
const iy1 = cy + innerR * Math.sin(angle0);
|
|
529
|
+
const ix2 = cx + innerR * Math.cos(endAngle);
|
|
530
|
+
const iy2 = cy + innerR * Math.sin(endAngle);
|
|
531
|
+
d = `M ${ix1} ${iy1} L ${x1} ${y1} A ${r} ${r} 0 ${largeArc} 1 ${x2} ${y2} L ${ix2} ${iy2} A ${innerR} ${innerR} 0 ${largeArc} 0 ${ix1} ${iy1} Z`;
|
|
532
|
+
} else {
|
|
533
|
+
d = `M ${cx} ${cy} L ${x1} ${y1} A ${r} ${r} 0 ${largeArc} 1 ${x2} ${y2} Z`;
|
|
534
|
+
}
|
|
535
|
+
const midAngle = angle0 + angle / 2;
|
|
536
|
+
const labelR = innerR > 0 ? (r + innerR) / 2 : r * 0.6;
|
|
537
|
+
const lx = cx + labelR * Math.cos(midAngle);
|
|
538
|
+
const ly = cy + labelR * Math.sin(midAngle);
|
|
539
|
+
const pct = Math.round(v / total * 100);
|
|
540
|
+
cumulativeAngle += angle;
|
|
541
|
+
const sliceEndRatio = cumulativeAngle / (Math.PI * 2);
|
|
542
|
+
const labelDelay = 1e3 * sliceEndRatio + 150;
|
|
543
|
+
angle0 = endAngle;
|
|
544
|
+
return { d, lx, ly, v, pct, angle, label: labels[i] || `${i + 1}`, labelDelay };
|
|
545
|
+
});
|
|
546
|
+
}, [values, total, cx, cy, r, innerR, labels]);
|
|
547
|
+
const maskId = `pie-mask-${isDoughnut ? "d" : "p"}`;
|
|
548
|
+
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "svg", { viewBox: `0 0 ${size} ${size}`, className: "chart-svg chart-pie", children: [
|
|
549
|
+
animate && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "defs", { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "mask", { id: maskId, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
550
|
+
"circle",
|
|
551
|
+
{
|
|
552
|
+
ref: maskRef,
|
|
553
|
+
cx,
|
|
554
|
+
cy,
|
|
555
|
+
r: maskR,
|
|
556
|
+
fill: "none",
|
|
557
|
+
stroke: "white",
|
|
558
|
+
strokeWidth: maskR * 2,
|
|
559
|
+
transform: `rotate(-90 ${cx} ${cy})`
|
|
560
|
+
}
|
|
561
|
+
) }) }),
|
|
562
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "g", { mask: animate ? `url(#${maskId})` : void 0, children: sliceData.map((s, i) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "g", { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
563
|
+
"path",
|
|
564
|
+
{
|
|
565
|
+
d: s.d,
|
|
566
|
+
fill: PIE_COLORS[(i + colorOffset) % PIE_COLORS.length],
|
|
567
|
+
className: "chart-slice",
|
|
568
|
+
onMouseEnter: (e) => onHover(e, `${s.label} \u2014 ${s.v.toLocaleString()} (${s.pct}%)`),
|
|
569
|
+
onMouseMove: onMove,
|
|
570
|
+
onMouseLeave: onLeave
|
|
571
|
+
}
|
|
572
|
+
) }, i)) })
|
|
573
|
+
] });
|
|
574
|
+
}
|
|
575
|
+
);
|
|
576
|
+
PieDonutChart.displayName = "PieDonutChart";
|
|
577
|
+
var ChartTooltip = ({ x, y, containerWidth, containerHeight, tooltipType, children }) => {
|
|
578
|
+
const ref = _react2.default.useRef(null);
|
|
579
|
+
const [pos, setPos] = _react2.default.useState({ left: 0, top: 0 });
|
|
580
|
+
_react2.default.useLayoutEffect(() => {
|
|
581
|
+
const el = ref.current;
|
|
582
|
+
if (!el) return;
|
|
583
|
+
const w = el.offsetWidth;
|
|
584
|
+
const h = el.offsetHeight;
|
|
585
|
+
let left = x + TOOLTIP_OFFSET;
|
|
586
|
+
let top = y - h - TOOLTIP_OFFSET;
|
|
587
|
+
if (left + w > containerWidth) left = x - w - TOOLTIP_OFFSET;
|
|
588
|
+
if (left < 0) left = 0;
|
|
589
|
+
if (top < 0) top = y + TOOLTIP_OFFSET;
|
|
590
|
+
if (top + h > containerHeight) top = containerHeight - h;
|
|
591
|
+
setPos({ left, top });
|
|
592
|
+
}, [x, y, containerWidth, containerHeight]);
|
|
593
|
+
const content = typeof children === "string" ? children : "";
|
|
594
|
+
const sepIdx = content.indexOf(" \u2014 ");
|
|
595
|
+
const title = sepIdx >= 0 ? content.slice(0, sepIdx) : content;
|
|
596
|
+
const desc = sepIdx >= 0 ? content.slice(sepIdx + 3) : "";
|
|
597
|
+
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
|
|
598
|
+
"div",
|
|
599
|
+
{
|
|
600
|
+
ref,
|
|
601
|
+
className: `lib-xplat-tooltip ${tooltipType} chart-tooltip-pos`,
|
|
602
|
+
style: { left: pos.left, top: pos.top },
|
|
603
|
+
children: [
|
|
604
|
+
title && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "tooltip-title", children: title }),
|
|
605
|
+
desc && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "tooltip-desc", children: desc })
|
|
606
|
+
]
|
|
607
|
+
}
|
|
608
|
+
);
|
|
609
|
+
};
|
|
610
|
+
var ChartLegend = ({ data, labels, shape }) => {
|
|
611
|
+
const entries = Object.entries(data);
|
|
612
|
+
if (shape === "pie" || shape === "doughnut") {
|
|
613
|
+
const values = entries.flatMap(([, v]) => v);
|
|
614
|
+
const total = values.reduce((a, b) => a + b, 0) || 1;
|
|
615
|
+
const firstKey = _nullishCoalesce(_optionalChain([entries, 'access', _22 => _22[0], 'optionalAccess', _23 => _23[0]]), () => ( ""));
|
|
616
|
+
const colorOffset = hashString(firstKey);
|
|
617
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "chart-legend", children: values.map((v, i) => {
|
|
618
|
+
const pct = Math.round(v / total * 100);
|
|
619
|
+
const color = PIE_COLORS[(i + colorOffset) % PIE_COLORS.length];
|
|
620
|
+
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "chart-legend-item", children: [
|
|
621
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "chart-legend-dot", style: { backgroundColor: color } }),
|
|
622
|
+
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "chart-legend-text", children: [
|
|
623
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "chart-legend-label", children: labels[i] || `${i + 1}` }),
|
|
624
|
+
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "span", { className: "chart-legend-value", children: [
|
|
625
|
+
v.toLocaleString(),
|
|
626
|
+
"(",
|
|
627
|
+
pct,
|
|
628
|
+
"%)"
|
|
629
|
+
] })
|
|
630
|
+
] })
|
|
631
|
+
] }, i);
|
|
632
|
+
}) });
|
|
633
|
+
}
|
|
634
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "chart-legend", children: entries.map(([key], di) => {
|
|
635
|
+
const palette = getPalette(LINE_BAR_PALETTES, di, key);
|
|
636
|
+
const color = palette[2];
|
|
637
|
+
const values = entries[di][1];
|
|
638
|
+
const sum = values.reduce((a, b) => a + b, 0);
|
|
639
|
+
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "chart-legend-item", children: [
|
|
640
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "chart-legend-dot", style: { backgroundColor: color } }),
|
|
641
|
+
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "chart-legend-text", children: [
|
|
642
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "chart-legend-label", children: key }),
|
|
643
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "chart-legend-value", children: sum.toLocaleString() })
|
|
644
|
+
] })
|
|
645
|
+
] }, di);
|
|
646
|
+
}) });
|
|
647
|
+
};
|
|
648
|
+
var Chart = _react2.default.memo((props) => {
|
|
649
|
+
const { variant, type, data, labels, legend, tooltip: showTooltip = true, tooltipType = "light" } = props;
|
|
650
|
+
const shape = _nullishCoalesce(_nullishCoalesce(variant, () => ( type)), () => ( "line"));
|
|
651
|
+
const showLegend = _nullishCoalesce(legend, () => ( (shape === "pie" || shape === "doughnut")));
|
|
652
|
+
const { tooltip, show, hide, move, containerRef } = useChartTooltip(showTooltip);
|
|
653
|
+
const { width, height } = useChartSize(containerRef);
|
|
654
|
+
const stableData = _react2.default.useMemo(() => data, [JSON.stringify(data)]);
|
|
655
|
+
const stableLabels = _react2.default.useMemo(() => labels, [JSON.stringify(labels)]);
|
|
656
|
+
const dataKey = _react2.default.useMemo(() => JSON.stringify(labels), [labels]);
|
|
657
|
+
const animate = useChartAnimation(containerRef, dataKey);
|
|
658
|
+
const ready = width > 0 && height > 0;
|
|
659
|
+
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "lib-xplat-chart", ref: containerRef, children: [
|
|
660
|
+
ready && shape === "line" && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, LineChart, { data: stableData, labels: stableLabels, width, height, animate, onHover: show, onMove: move, onLeave: hide }),
|
|
661
|
+
ready && shape === "curve" && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, CurveChart, { data: stableData, labels: stableLabels, width, height, animate, onHover: show, onMove: move, onLeave: hide }),
|
|
662
|
+
ready && shape === "bar" && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, BarChart, { data: stableData, labels: stableLabels, width, height, animate, onHover: show, onMove: move, onLeave: hide }),
|
|
663
|
+
ready && shape === "pie" && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, PieDonutChart, { data: stableData, labels: stableLabels, width, height, animate, onHover: show, onMove: move, onLeave: hide }),
|
|
664
|
+
ready && shape === "doughnut" && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, PieDonutChart, { data: stableData, labels: stableLabels, width, height, animate, isDoughnut: true, onHover: show, onMove: move, onLeave: hide }),
|
|
665
|
+
ready && showLegend && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ChartLegend, { data: stableData, labels: stableLabels, shape }),
|
|
666
|
+
tooltip.visible && tooltip.content && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ChartTooltip, { x: tooltip.x, y: tooltip.y, containerWidth: width, containerHeight: height, tooltipType, children: tooltip.content })
|
|
667
|
+
] });
|
|
668
|
+
});
|
|
669
|
+
Chart.displayName = "Chart";
|
|
670
|
+
var Chart_default = Chart;
|
|
671
|
+
|
|
672
|
+
|
|
673
|
+
|
|
674
|
+
exports.Chart_default = Chart_default;
|