@tribepad/themis 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (326) hide show
  1. package/dist/elements/Accordion/index.js +325 -66
  2. package/dist/elements/Accordion/index.js.map +1 -1
  3. package/dist/elements/Accordion/index.mjs +317 -3
  4. package/dist/elements/Accordion/index.mjs.map +1 -1
  5. package/dist/elements/Avatar/index.js +461 -45
  6. package/dist/elements/Avatar/index.js.map +1 -1
  7. package/dist/elements/Avatar/index.mjs +456 -3
  8. package/dist/elements/Avatar/index.mjs.map +1 -1
  9. package/dist/elements/Badge/index.js +238 -36
  10. package/dist/elements/Badge/index.js.map +1 -1
  11. package/dist/elements/Badge/index.mjs +234 -4
  12. package/dist/elements/Badge/index.mjs.map +1 -1
  13. package/dist/elements/Breadcrumbs/index.js +808 -39
  14. package/dist/elements/Breadcrumbs/index.js.map +1 -1
  15. package/dist/elements/Breadcrumbs/index.mjs +810 -7
  16. package/dist/elements/Breadcrumbs/index.mjs.map +1 -1
  17. package/dist/elements/Button/index.js +282 -19
  18. package/dist/elements/Button/index.js.map +1 -1
  19. package/dist/elements/Button/index.mjs +283 -4
  20. package/dist/elements/Button/index.mjs.map +1 -1
  21. package/dist/elements/ButtonGroup/index.js +229 -56
  22. package/dist/elements/ButtonGroup/index.js.map +1 -1
  23. package/dist/elements/ButtonGroup/index.mjs +222 -3
  24. package/dist/elements/ButtonGroup/index.mjs.map +1 -1
  25. package/dist/elements/Card/Card.d.ts.map +1 -1
  26. package/dist/elements/Card/index.js +563 -67
  27. package/dist/elements/Card/index.js.map +1 -1
  28. package/dist/elements/Card/index.mjs +560 -6
  29. package/dist/elements/Card/index.mjs.map +1 -1
  30. package/dist/elements/Carousel/index.js +782 -14
  31. package/dist/elements/Carousel/index.js.map +1 -1
  32. package/dist/elements/Carousel/index.mjs +786 -8
  33. package/dist/elements/Carousel/index.mjs.map +1 -1
  34. package/dist/elements/Chart/index.js +1833 -36
  35. package/dist/elements/Chart/index.js.map +1 -1
  36. package/dist/elements/Chart/index.mjs +1832 -4
  37. package/dist/elements/Chart/index.mjs.map +1 -1
  38. package/dist/elements/Checkbox/index.js +310 -39
  39. package/dist/elements/Checkbox/index.js.map +1 -1
  40. package/dist/elements/Checkbox/index.mjs +306 -4
  41. package/dist/elements/Checkbox/index.mjs.map +1 -1
  42. package/dist/elements/CheckboxGroup/index.js +445 -59
  43. package/dist/elements/CheckboxGroup/index.js.map +1 -1
  44. package/dist/elements/CheckboxGroup/index.mjs +439 -4
  45. package/dist/elements/CheckboxGroup/index.mjs.map +1 -1
  46. package/dist/elements/DatePicker/index.js +871 -89
  47. package/dist/elements/DatePicker/index.js.map +1 -1
  48. package/dist/elements/DatePicker/index.mjs +853 -4
  49. package/dist/elements/DatePicker/index.mjs.map +1 -1
  50. package/dist/elements/Dropdown/index.js +189 -35
  51. package/dist/elements/Dropdown/index.js.map +1 -1
  52. package/dist/elements/Dropdown/index.mjs +184 -2
  53. package/dist/elements/Dropdown/index.mjs.map +1 -1
  54. package/dist/elements/FileField/index.js +1532 -129
  55. package/dist/elements/FileField/index.js.map +1 -1
  56. package/dist/elements/FileField/index.mjs +1507 -7
  57. package/dist/elements/FileField/index.mjs.map +1 -1
  58. package/dist/elements/FormLayout/index.js +166 -11
  59. package/dist/elements/FormLayout/index.js.map +1 -1
  60. package/dist/elements/FormLayout/index.mjs +167 -2
  61. package/dist/elements/FormLayout/index.mjs.map +1 -1
  62. package/dist/elements/Modal/index.js +228 -46
  63. package/dist/elements/Modal/index.js.map +1 -1
  64. package/dist/elements/Modal/index.mjs +220 -1
  65. package/dist/elements/Modal/index.mjs.map +1 -1
  66. package/dist/elements/NumberField/index.js +659 -48
  67. package/dist/elements/NumberField/index.js.map +1 -1
  68. package/dist/elements/NumberField/index.mjs +654 -6
  69. package/dist/elements/NumberField/index.mjs.map +1 -1
  70. package/dist/elements/OTPInput/index.js +729 -6
  71. package/dist/elements/OTPInput/index.js.map +1 -1
  72. package/dist/elements/OTPInput/index.mjs +732 -2
  73. package/dist/elements/OTPInput/index.mjs.map +1 -1
  74. package/dist/elements/Panel/index.js +326 -27
  75. package/dist/elements/Panel/index.js.map +1 -1
  76. package/dist/elements/Panel/index.mjs +323 -2
  77. package/dist/elements/Panel/index.mjs.map +1 -1
  78. package/dist/elements/Progress/index.js +181 -22
  79. package/dist/elements/Progress/index.js.map +1 -1
  80. package/dist/elements/Progress/index.mjs +181 -3
  81. package/dist/elements/Progress/index.mjs.map +1 -1
  82. package/dist/elements/RadioGroup/index.js +358 -34
  83. package/dist/elements/RadioGroup/index.js.map +1 -1
  84. package/dist/elements/RadioGroup/index.mjs +359 -4
  85. package/dist/elements/RadioGroup/index.mjs.map +1 -1
  86. package/dist/elements/Resizable/components/ResizableHandle.d.ts +0 -8
  87. package/dist/elements/Resizable/components/ResizableHandle.d.ts.map +1 -1
  88. package/dist/elements/Resizable/components/ResizablePanel.d.ts +0 -8
  89. package/dist/elements/Resizable/components/ResizablePanel.d.ts.map +1 -1
  90. package/dist/elements/Resizable/components/ResizablePanelGroup.d.ts +0 -8
  91. package/dist/elements/Resizable/components/ResizablePanelGroup.d.ts.map +1 -1
  92. package/dist/elements/Resizable/components/ResizablePopover.d.ts +0 -8
  93. package/dist/elements/Resizable/components/ResizablePopover.d.ts.map +1 -1
  94. package/dist/elements/Resizable/index.js +1568 -51
  95. package/dist/elements/Resizable/index.js.map +1 -1
  96. package/dist/elements/Resizable/index.mjs +1566 -6
  97. package/dist/elements/Resizable/index.mjs.map +1 -1
  98. package/dist/elements/Select/index.js +580 -22
  99. package/dist/elements/Select/index.js.map +1 -1
  100. package/dist/elements/Select/index.mjs +582 -2
  101. package/dist/elements/Select/index.mjs.map +1 -1
  102. package/dist/elements/Skeleton/index.js +77 -15
  103. package/dist/elements/Skeleton/index.js.map +1 -1
  104. package/dist/elements/Skeleton/index.mjs +78 -3
  105. package/dist/elements/Skeleton/index.mjs.map +1 -1
  106. package/dist/elements/Switch/index.js +153 -21
  107. package/dist/elements/Switch/index.js.map +1 -1
  108. package/dist/elements/Switch/index.mjs +149 -5
  109. package/dist/elements/Switch/index.mjs.map +1 -1
  110. package/dist/elements/Table/index.js +589 -68
  111. package/dist/elements/Table/index.js.map +1 -1
  112. package/dist/elements/Table/index.mjs +578 -5
  113. package/dist/elements/Table/index.mjs.map +1 -1
  114. package/dist/elements/Tabs/index.js +328 -63
  115. package/dist/elements/Tabs/index.js.map +1 -1
  116. package/dist/elements/Tabs/index.mjs +320 -3
  117. package/dist/elements/Tabs/index.mjs.map +1 -1
  118. package/dist/elements/TextField/index.js +695 -51
  119. package/dist/elements/TextField/index.js.map +1 -1
  120. package/dist/elements/TextField/index.mjs +684 -7
  121. package/dist/elements/TextField/index.mjs.map +1 -1
  122. package/dist/elements/TimeField/index.js +244 -33
  123. package/dist/elements/TimeField/index.js.map +1 -1
  124. package/dist/elements/TimeField/index.mjs +238 -2
  125. package/dist/elements/TimeField/index.mjs.map +1 -1
  126. package/dist/elements/Toast/index.js +727 -48
  127. package/dist/elements/Toast/index.js.map +1 -1
  128. package/dist/elements/Toast/index.mjs +724 -5
  129. package/dist/elements/Toast/index.mjs.map +1 -1
  130. package/dist/elements/Tooltip/index.js +315 -49
  131. package/dist/elements/Tooltip/index.js.map +1 -1
  132. package/dist/elements/Tooltip/index.mjs +310 -4
  133. package/dist/elements/Tooltip/index.mjs.map +1 -1
  134. package/dist/elements/index.js +12417 -799
  135. package/dist/elements/index.js.map +1 -1
  136. package/dist/elements/index.mjs +12233 -40
  137. package/dist/elements/index.mjs.map +1 -1
  138. package/dist/index.js +12452 -825
  139. package/dist/index.js.map +1 -1
  140. package/dist/index.mjs +12262 -42
  141. package/dist/index.mjs.map +1 -1
  142. package/dist/schemas/index.js +47 -21
  143. package/dist/schemas/index.js.map +1 -1
  144. package/dist/schemas/index.mjs +47 -2
  145. package/dist/schemas/index.mjs.map +1 -1
  146. package/dist/styles/index.js +161 -147
  147. package/dist/styles/index.js.map +1 -1
  148. package/dist/styles/index.mjs +128 -2
  149. package/dist/styles/index.mjs.map +1 -1
  150. package/dist/utils/index.js +7 -7
  151. package/dist/utils/index.js.map +1 -1
  152. package/dist/utils/index.mjs +9 -2
  153. package/dist/utils/index.mjs.map +1 -1
  154. package/package.json +1 -1
  155. package/dist/Carousel-NTZX5TOW.js +0 -16
  156. package/dist/Carousel-NTZX5TOW.js.map +0 -1
  157. package/dist/Carousel-YH3DOQJU.mjs +0 -7
  158. package/dist/Carousel-YH3DOQJU.mjs.map +0 -1
  159. package/dist/chunk-2HIUTHMU.mjs +0 -234
  160. package/dist/chunk-2HIUTHMU.mjs.map +0 -1
  161. package/dist/chunk-34GTFTDO.js +0 -431
  162. package/dist/chunk-34GTFTDO.js.map +0 -1
  163. package/dist/chunk-3H7ASYR7.js +0 -250
  164. package/dist/chunk-3H7ASYR7.js.map +0 -1
  165. package/dist/chunk-3IEN7JOP.js +0 -316
  166. package/dist/chunk-3IEN7JOP.js.map +0 -1
  167. package/dist/chunk-3JHN4GAL.js +0 -326
  168. package/dist/chunk-3JHN4GAL.js.map +0 -1
  169. package/dist/chunk-3MJPASQU.js +0 -232
  170. package/dist/chunk-3MJPASQU.js.map +0 -1
  171. package/dist/chunk-3XD2JUL3.js +0 -572
  172. package/dist/chunk-3XD2JUL3.js.map +0 -1
  173. package/dist/chunk-3YOY2VJ6.js +0 -189
  174. package/dist/chunk-3YOY2VJ6.js.map +0 -1
  175. package/dist/chunk-4DU5JSXB.js +0 -408
  176. package/dist/chunk-4DU5JSXB.js.map +0 -1
  177. package/dist/chunk-4E4E2GSS.js +0 -352
  178. package/dist/chunk-4E4E2GSS.js.map +0 -1
  179. package/dist/chunk-4NHAP4AN.mjs +0 -3
  180. package/dist/chunk-4NHAP4AN.mjs.map +0 -1
  181. package/dist/chunk-4S33J5NY.mjs +0 -415
  182. package/dist/chunk-4S33J5NY.mjs.map +0 -1
  183. package/dist/chunk-5SMGRT3G.mjs +0 -354
  184. package/dist/chunk-5SMGRT3G.mjs.map +0 -1
  185. package/dist/chunk-5SVLJN2C.mjs +0 -22
  186. package/dist/chunk-5SVLJN2C.mjs.map +0 -1
  187. package/dist/chunk-66WTU4EB.mjs +0 -299
  188. package/dist/chunk-66WTU4EB.mjs.map +0 -1
  189. package/dist/chunk-6S25NMOT.mjs +0 -335
  190. package/dist/chunk-6S25NMOT.mjs.map +0 -1
  191. package/dist/chunk-6SP7UB3D.js +0 -4
  192. package/dist/chunk-6SP7UB3D.js.map +0 -1
  193. package/dist/chunk-6TYWWQHM.mjs +0 -565
  194. package/dist/chunk-6TYWWQHM.mjs.map +0 -1
  195. package/dist/chunk-A3YUJA6W.mjs +0 -384
  196. package/dist/chunk-A3YUJA6W.mjs.map +0 -1
  197. package/dist/chunk-A6KEDVUR.js +0 -61
  198. package/dist/chunk-A6KEDVUR.js.map +0 -1
  199. package/dist/chunk-A77RUEWL.js +0 -730
  200. package/dist/chunk-A77RUEWL.js.map +0 -1
  201. package/dist/chunk-AA4IKMPE.mjs +0 -3
  202. package/dist/chunk-AA4IKMPE.mjs.map +0 -1
  203. package/dist/chunk-AKIA6GW6.mjs +0 -163
  204. package/dist/chunk-AKIA6GW6.mjs.map +0 -1
  205. package/dist/chunk-AL6P275L.mjs +0 -435
  206. package/dist/chunk-AL6P275L.mjs.map +0 -1
  207. package/dist/chunk-AZ3RJYTB.js +0 -37
  208. package/dist/chunk-AZ3RJYTB.js.map +0 -1
  209. package/dist/chunk-B5Q4UPL6.js +0 -32
  210. package/dist/chunk-B5Q4UPL6.js.map +0 -1
  211. package/dist/chunk-B6DHPMDP.mjs +0 -335
  212. package/dist/chunk-B6DHPMDP.mjs.map +0 -1
  213. package/dist/chunk-BDXKKMBZ.mjs +0 -184
  214. package/dist/chunk-BDXKKMBZ.mjs.map +0 -1
  215. package/dist/chunk-BL6E2DLZ.mjs +0 -52
  216. package/dist/chunk-BL6E2DLZ.mjs.map +0 -1
  217. package/dist/chunk-CGFDS4XS.mjs +0 -121
  218. package/dist/chunk-CGFDS4XS.mjs.map +0 -1
  219. package/dist/chunk-CJIW5TKI.js +0 -139
  220. package/dist/chunk-CJIW5TKI.js.map +0 -1
  221. package/dist/chunk-CKNISJOQ.js +0 -314
  222. package/dist/chunk-CKNISJOQ.js.map +0 -1
  223. package/dist/chunk-D6CBOECS.mjs +0 -1757
  224. package/dist/chunk-D6CBOECS.mjs.map +0 -1
  225. package/dist/chunk-DDWEVC2S.js +0 -166
  226. package/dist/chunk-DDWEVC2S.js.map +0 -1
  227. package/dist/chunk-DZ556D2F.mjs +0 -176
  228. package/dist/chunk-DZ556D2F.mjs.map +0 -1
  229. package/dist/chunk-E2KQFV3O.mjs +0 -10
  230. package/dist/chunk-E2KQFV3O.mjs.map +0 -1
  231. package/dist/chunk-EMMLADSC.js +0 -126
  232. package/dist/chunk-EMMLADSC.js.map +0 -1
  233. package/dist/chunk-EP4WOI5D.mjs +0 -926
  234. package/dist/chunk-EP4WOI5D.mjs.map +0 -1
  235. package/dist/chunk-FJRXLJC2.mjs +0 -160
  236. package/dist/chunk-FJRXLJC2.mjs.map +0 -1
  237. package/dist/chunk-FKQI434R.js +0 -345
  238. package/dist/chunk-FKQI434R.js.map +0 -1
  239. package/dist/chunk-FPKEAJRZ.mjs +0 -100
  240. package/dist/chunk-FPKEAJRZ.mjs.map +0 -1
  241. package/dist/chunk-FWQYB22U.js +0 -183
  242. package/dist/chunk-FWQYB22U.js.map +0 -1
  243. package/dist/chunk-GD5GHTMA.js +0 -189
  244. package/dist/chunk-GD5GHTMA.js.map +0 -1
  245. package/dist/chunk-GE5XTSDZ.js +0 -447
  246. package/dist/chunk-GE5XTSDZ.js.map +0 -1
  247. package/dist/chunk-GVE47ZAX.mjs +0 -32
  248. package/dist/chunk-GVE47ZAX.mjs.map +0 -1
  249. package/dist/chunk-HK46BT5U.mjs +0 -18
  250. package/dist/chunk-HK46BT5U.mjs.map +0 -1
  251. package/dist/chunk-HQVRMR6N.js +0 -365
  252. package/dist/chunk-HQVRMR6N.js.map +0 -1
  253. package/dist/chunk-HSGBJPJO.mjs +0 -398
  254. package/dist/chunk-HSGBJPJO.mjs.map +0 -1
  255. package/dist/chunk-I3AUTOMZ.mjs +0 -125
  256. package/dist/chunk-I3AUTOMZ.mjs.map +0 -1
  257. package/dist/chunk-IEI5LD5C.mjs +0 -1161
  258. package/dist/chunk-IEI5LD5C.mjs.map +0 -1
  259. package/dist/chunk-IIPTC2X7.mjs +0 -118
  260. package/dist/chunk-IIPTC2X7.mjs.map +0 -1
  261. package/dist/chunk-J7TLHF2Q.js +0 -4
  262. package/dist/chunk-J7TLHF2Q.js.map +0 -1
  263. package/dist/chunk-JJOWXFXQ.mjs +0 -765
  264. package/dist/chunk-JJOWXFXQ.mjs.map +0 -1
  265. package/dist/chunk-JPTSS2OA.mjs +0 -3
  266. package/dist/chunk-JPTSS2OA.mjs.map +0 -1
  267. package/dist/chunk-KFXXRLTP.js +0 -396
  268. package/dist/chunk-KFXXRLTP.js.map +0 -1
  269. package/dist/chunk-KPRRBSG6.mjs +0 -272
  270. package/dist/chunk-KPRRBSG6.mjs.map +0 -1
  271. package/dist/chunk-NFSBGRDB.mjs +0 -57
  272. package/dist/chunk-NFSBGRDB.mjs.map +0 -1
  273. package/dist/chunk-NGJVCFTM.js +0 -219
  274. package/dist/chunk-NGJVCFTM.js.map +0 -1
  275. package/dist/chunk-NSQ6MZJ6.mjs +0 -728
  276. package/dist/chunk-NSQ6MZJ6.mjs.map +0 -1
  277. package/dist/chunk-NYQYHT76.mjs +0 -296
  278. package/dist/chunk-NYQYHT76.mjs.map +0 -1
  279. package/dist/chunk-OLJJGI5B.js +0 -1193
  280. package/dist/chunk-OLJJGI5B.js.map +0 -1
  281. package/dist/chunk-Q3572X2J.js +0 -292
  282. package/dist/chunk-Q3572X2J.js.map +0 -1
  283. package/dist/chunk-QH7N7D4I.mjs +0 -210
  284. package/dist/chunk-QH7N7D4I.mjs.map +0 -1
  285. package/dist/chunk-R7XUIV25.js +0 -466
  286. package/dist/chunk-R7XUIV25.js.map +0 -1
  287. package/dist/chunk-RFFO4KPM.js +0 -135
  288. package/dist/chunk-RFFO4KPM.js.map +0 -1
  289. package/dist/chunk-RFX7QKA7.mjs +0 -180
  290. package/dist/chunk-RFX7QKA7.mjs.map +0 -1
  291. package/dist/chunk-SN5LFAP3.js +0 -940
  292. package/dist/chunk-SN5LFAP3.js.map +0 -1
  293. package/dist/chunk-T4COXKQ3.js +0 -24
  294. package/dist/chunk-T4COXKQ3.js.map +0 -1
  295. package/dist/chunk-TS54QM27.js +0 -125
  296. package/dist/chunk-TS54QM27.js.map +0 -1
  297. package/dist/chunk-UE2S4PCX.mjs +0 -220
  298. package/dist/chunk-UE2S4PCX.mjs.map +0 -1
  299. package/dist/chunk-UTW3QX2A.mjs +0 -282
  300. package/dist/chunk-UTW3QX2A.mjs.map +0 -1
  301. package/dist/chunk-V74LGMAE.js +0 -1767
  302. package/dist/chunk-V74LGMAE.js.map +0 -1
  303. package/dist/chunk-VIREG536.js +0 -12
  304. package/dist/chunk-VIREG536.js.map +0 -1
  305. package/dist/chunk-VY7M7346.js +0 -4
  306. package/dist/chunk-VY7M7346.js.map +0 -1
  307. package/dist/chunk-W3TJOO7H.mjs +0 -319
  308. package/dist/chunk-W3TJOO7H.mjs.map +0 -1
  309. package/dist/chunk-WIUOB36M.js +0 -54
  310. package/dist/chunk-WIUOB36M.js.map +0 -1
  311. package/dist/chunk-WJGLM4CY.js +0 -291
  312. package/dist/chunk-WJGLM4CY.js.map +0 -1
  313. package/dist/chunk-WNURH5OO.mjs +0 -453
  314. package/dist/chunk-WNURH5OO.mjs.map +0 -1
  315. package/dist/chunk-X25TNRSD.mjs +0 -364
  316. package/dist/chunk-X25TNRSD.mjs.map +0 -1
  317. package/dist/chunk-Y3GT7ETK.js +0 -108
  318. package/dist/chunk-Y3GT7ETK.js.map +0 -1
  319. package/dist/chunk-Z4FRNOF6.mjs +0 -115
  320. package/dist/chunk-Z4FRNOF6.mjs.map +0 -1
  321. package/dist/chunk-ZMYLD3BN.js +0 -166
  322. package/dist/chunk-ZMYLD3BN.js.map +0 -1
  323. package/dist/chunk-ZP2KV6EX.js +0 -815
  324. package/dist/chunk-ZP2KV6EX.js.map +0 -1
  325. package/dist/chunk-ZVKXFELU.js +0 -366
  326. package/dist/chunk-ZVKXFELU.js.map +0 -1
@@ -1,1767 +0,0 @@
1
- 'use strict';
2
-
3
- var chunkFWQYB22U_js = require('./chunk-FWQYB22U.js');
4
- var chunkVIREG536_js = require('./chunk-VIREG536.js');
5
- var chunkT4COXKQ3_js = require('./chunk-T4COXKQ3.js');
6
- var react = require('react');
7
- var classVarianceAuthority = require('class-variance-authority');
8
- var jsxRuntime = require('react/jsx-runtime');
9
- var reactAria = require('react-aria');
10
- var zod = require('zod');
11
-
12
- var chartVariants = classVarianceAuthority.cva(
13
- // Base classes
14
- "relative w-full overflow-hidden rounded-lg border",
15
- {
16
- variants: {
17
- variant: {
18
- default: "border-[var(--border)] bg-[var(--content-background)]",
19
- muted: "border-[var(--accent-background)] bg-[var(--accent-background)]/50"
20
- }
21
- },
22
- defaultVariants: {
23
- variant: "default"
24
- }
25
- }
26
- );
27
- var dataPointVariants = classVarianceAuthority.cva(
28
- // Base classes
29
- "cursor-pointer focus-visible:outline-none",
30
- {
31
- variants: {
32
- type: {
33
- bar: "",
34
- // Fill color set dynamically per series
35
- line: "stroke-2"
36
- // Stroke color set dynamically per series
37
- },
38
- state: {
39
- default: "",
40
- focused: "",
41
- // Focus ring provides visual feedback, no scale needed for data points
42
- selected: "opacity-80"
43
- }
44
- },
45
- defaultVariants: {
46
- type: "bar",
47
- state: "default"
48
- }
49
- }
50
- );
51
- classVarianceAuthority.cva(
52
- // Base classes
53
- "pointer-events-none",
54
- {
55
- variants: {
56
- visible: {
57
- true: "opacity-100",
58
- false: "opacity-0"
59
- }
60
- },
61
- defaultVariants: {
62
- visible: false
63
- }
64
- }
65
- );
66
- var legendVariants = classVarianceAuthority.cva(
67
- // Base classes - horizontal flex layout below chart
68
- "flex flex-wrap items-center justify-center gap-4 px-4 py-2",
69
- {
70
- variants: {
71
- visible: {
72
- true: "",
73
- false: "hidden"
74
- }
75
- },
76
- defaultVariants: {
77
- visible: true
78
- }
79
- }
80
- );
81
-
82
- // src/elements/Chart/chart.constants.ts
83
- var CHART_ASPECT_RATIO = 9 / 16;
84
- var CHART_PADDING = {
85
- top: 20,
86
- // Space for title overflow
87
- right: 20,
88
- // Space for y-axis label
89
- bottom: 60,
90
- // Space for x-axis labels + legend
91
- left: 60
92
- // Space for y-axis labels
93
- };
94
- var MIN_CHART_WIDTH = 300;
95
- var MIN_CHART_HEIGHT = 169;
96
- var BAR_GROUP_PADDING = 0.2;
97
- var BAR_PADDING = 0.1;
98
- var MIN_BAR_WIDTH = 20;
99
- var BAR_RADIUS = 4;
100
- var LINE_STROKE_WIDTH = 2;
101
- var POINT_RADIUS = 6;
102
- var LINE_PATTERNS = {
103
- solid: "none",
104
- dashed: "8 4",
105
- // 8px dash, 4px gap
106
- dotted: "2 4"
107
- // 2px dot, 4px gap
108
- };
109
- var GRID_COLOR = "var(--border)";
110
- var GRID_STROKE_WIDTH = 1;
111
- var GRID_STROKE_OPACITY = 0.7;
112
- var AXIS_COLOR = "var(--border)";
113
- var AXIS_STROKE_WIDTH = 1;
114
- var AXIS_TICK_SIZE = 6;
115
- var AXIS_LABEL_FONT_SIZE = 12;
116
- var MIN_TOUCH_TARGET = 44;
117
- var FOCUS_RING_OFFSET = 4;
118
- var FOCUS_RING_WIDTH = 2;
119
- var DEFAULT_SERIES_COLORS = [
120
- "var(--chart-1, hsl(221 83% 53%))",
121
- // Series 0 - Blue
122
- "var(--chart-2, hsl(142 71% 45%))",
123
- // Series 1 - Green
124
- "var(--chart-3, hsl(38 92% 50%))",
125
- // Series 2 - Orange
126
- "var(--chart-4, hsl(262 83% 58%))",
127
- // Series 3 - Purple
128
- "var(--chart-5, hsl(0 84% 60%))"
129
- // Series 4 - Red
130
- ];
131
- function niceNum(range, round) {
132
- const exponent = Math.floor(Math.log10(range));
133
- const fraction = range / Math.pow(10, exponent);
134
- let niceFraction;
135
- if (round) {
136
- if (fraction < 1.5) niceFraction = 1;
137
- else if (fraction < 3) niceFraction = 2;
138
- else if (fraction < 7) niceFraction = 5;
139
- else niceFraction = 10;
140
- } else {
141
- if (fraction <= 1) niceFraction = 1;
142
- else if (fraction <= 2) niceFraction = 2;
143
- else if (fraction <= 5) niceFraction = 5;
144
- else niceFraction = 10;
145
- }
146
- return niceFraction * Math.pow(10, exponent);
147
- }
148
- function calculateYAxisTicks(minValue, maxValue, tickCount = 5) {
149
- if (minValue === maxValue) {
150
- if (minValue === 0) {
151
- return [0, 25, 50, 75, 100];
152
- }
153
- minValue = minValue * 0.9;
154
- maxValue = maxValue * 1.1;
155
- }
156
- const range = niceNum(maxValue - minValue, false);
157
- const tickSpacing = niceNum(range / (tickCount - 1), true);
158
- const niceMin = Math.floor(minValue / tickSpacing) * tickSpacing;
159
- const niceMax = Math.ceil(maxValue / tickSpacing) * tickSpacing;
160
- const ticks = [];
161
- for (let tick = niceMin; tick <= niceMax; tick += tickSpacing) {
162
- ticks.push(tick);
163
- }
164
- return ticks;
165
- }
166
- function calculateBarLayout(plotWidth, labelCount, seriesCount, plotX = 0) {
167
- const groupWidth = plotWidth / labelCount;
168
- const availableWidth = groupWidth * (1 - BAR_GROUP_PADDING);
169
- const barWidth = Math.max(
170
- MIN_BAR_WIDTH,
171
- availableWidth / seriesCount * (1 - BAR_PADDING)
172
- );
173
- const getBarX = (labelIdx, seriesIdx) => {
174
- const groupCenter = plotX + groupWidth * labelIdx + groupWidth / 2;
175
- const totalBarsWidth = seriesCount * barWidth + (seriesCount - 1) * (BAR_PADDING * barWidth);
176
- const barsStart = groupCenter - totalBarsWidth / 2;
177
- return barsStart + seriesIdx * (barWidth + BAR_PADDING * barWidth);
178
- };
179
- return { barWidth, groupWidth, getBarX };
180
- }
181
-
182
- // src/elements/Chart/useChartDimensions.ts
183
- function useChartDimensions(containerRef) {
184
- const [dimensions, setDimensions] = react.useState({
185
- width: MIN_CHART_WIDTH,
186
- height: MIN_CHART_HEIGHT,
187
- padding: CHART_PADDING,
188
- plotArea: {
189
- x: CHART_PADDING.left,
190
- y: CHART_PADDING.top,
191
- width: MIN_CHART_WIDTH - CHART_PADDING.left - CHART_PADDING.right,
192
- height: MIN_CHART_HEIGHT - CHART_PADDING.top - CHART_PADDING.bottom
193
- }
194
- });
195
- react.useEffect(() => {
196
- const container = containerRef.current;
197
- if (!container) return;
198
- const updateDimensions = (width) => {
199
- const constrainedWidth = Math.max(width, MIN_CHART_WIDTH);
200
- const height = Math.max(
201
- constrainedWidth * CHART_ASPECT_RATIO,
202
- MIN_CHART_HEIGHT
203
- );
204
- const plotArea = {
205
- x: CHART_PADDING.left,
206
- y: CHART_PADDING.top,
207
- width: constrainedWidth - CHART_PADDING.left - CHART_PADDING.right,
208
- height: height - CHART_PADDING.top - CHART_PADDING.bottom
209
- };
210
- setDimensions({
211
- width: constrainedWidth,
212
- height,
213
- padding: CHART_PADDING,
214
- plotArea
215
- });
216
- };
217
- const observer = new ResizeObserver((entries) => {
218
- const entry = entries[0];
219
- if (!entry) return;
220
- updateDimensions(entry.contentRect.width);
221
- });
222
- updateDimensions(container.getBoundingClientRect().width);
223
- observer.observe(container);
224
- return () => {
225
- observer.disconnect();
226
- };
227
- }, [containerRef]);
228
- return dimensions;
229
- }
230
- function useRovingTabIndex2D(options) {
231
- const {
232
- rows,
233
- cols,
234
- initialRow = 0,
235
- initialCol = 0,
236
- wrap = false,
237
- onFocusChange
238
- } = options;
239
- const [focusedRow, setFocusedRow] = react.useState(initialRow);
240
- const [focusedCol, setFocusedCol] = react.useState(initialCol);
241
- const getColCount = react.useCallback(
242
- (row) => {
243
- return typeof cols === "function" ? cols(row) : cols;
244
- },
245
- [cols]
246
- );
247
- const notifyFocusChange = react.useCallback(
248
- (row, col) => {
249
- onFocusChange?.(row, col);
250
- },
251
- [onFocusChange]
252
- );
253
- const moveRight = react.useCallback(() => {
254
- setFocusedCol((currentCol) => {
255
- const maxCol = getColCount(focusedRow) - 1;
256
- let newCol = currentCol + 1;
257
- if (newCol > maxCol) {
258
- newCol = wrap ? 0 : maxCol;
259
- }
260
- if (newCol !== currentCol) {
261
- notifyFocusChange(focusedRow, newCol);
262
- }
263
- return newCol;
264
- });
265
- }, [focusedRow, getColCount, wrap, notifyFocusChange]);
266
- const moveLeft = react.useCallback(() => {
267
- setFocusedCol((currentCol) => {
268
- let newCol = currentCol - 1;
269
- const maxCol = getColCount(focusedRow) - 1;
270
- if (newCol < 0) {
271
- newCol = wrap ? maxCol : 0;
272
- }
273
- if (newCol !== currentCol) {
274
- notifyFocusChange(focusedRow, newCol);
275
- }
276
- return newCol;
277
- });
278
- }, [focusedRow, getColCount, wrap, notifyFocusChange]);
279
- const moveDown = react.useCallback(() => {
280
- setFocusedRow((currentRow) => {
281
- let newRow = currentRow + 1;
282
- if (newRow >= rows) {
283
- newRow = wrap ? 0 : rows - 1;
284
- }
285
- if (newRow !== currentRow) {
286
- const newMaxCol = getColCount(newRow) - 1;
287
- setFocusedCol((col) => {
288
- const constrainedCol = Math.min(col, newMaxCol);
289
- notifyFocusChange(newRow, constrainedCol);
290
- return constrainedCol;
291
- });
292
- }
293
- return newRow;
294
- });
295
- }, [rows, getColCount, wrap, notifyFocusChange]);
296
- const moveUp = react.useCallback(() => {
297
- setFocusedRow((currentRow) => {
298
- let newRow = currentRow - 1;
299
- if (newRow < 0) {
300
- newRow = wrap ? rows - 1 : 0;
301
- }
302
- if (newRow !== currentRow) {
303
- const newMaxCol = getColCount(newRow) - 1;
304
- setFocusedCol((col) => {
305
- const constrainedCol = Math.min(col, newMaxCol);
306
- notifyFocusChange(newRow, constrainedCol);
307
- return constrainedCol;
308
- });
309
- }
310
- return newRow;
311
- });
312
- }, [rows, getColCount, wrap, notifyFocusChange]);
313
- const moveToStart = react.useCallback(() => {
314
- setFocusedCol(0);
315
- notifyFocusChange(focusedRow, 0);
316
- }, [focusedRow, notifyFocusChange]);
317
- const moveToEnd = react.useCallback(() => {
318
- const maxCol = getColCount(focusedRow) - 1;
319
- setFocusedCol(maxCol);
320
- notifyFocusChange(focusedRow, maxCol);
321
- }, [focusedRow, getColCount, notifyFocusChange]);
322
- const setFocus = react.useCallback(
323
- (row, col) => {
324
- const constrainedRow = Math.max(0, Math.min(row, rows - 1));
325
- const maxCol = getColCount(constrainedRow) - 1;
326
- const constrainedCol = Math.max(0, Math.min(col, maxCol));
327
- setFocusedRow(constrainedRow);
328
- setFocusedCol(constrainedCol);
329
- notifyFocusChange(constrainedRow, constrainedCol);
330
- },
331
- [rows, getColCount, notifyFocusChange]
332
- );
333
- const getTabIndex = react.useCallback(
334
- (row, col) => {
335
- return row === focusedRow && col === focusedCol ? 0 : -1;
336
- },
337
- [focusedRow, focusedCol]
338
- );
339
- return react.useMemo(
340
- () => ({
341
- focusedRow,
342
- focusedCol,
343
- moveRight,
344
- moveLeft,
345
- moveDown,
346
- moveUp,
347
- moveToStart,
348
- moveToEnd,
349
- setFocus,
350
- getTabIndex
351
- }),
352
- [
353
- focusedRow,
354
- focusedCol,
355
- moveRight,
356
- moveLeft,
357
- moveDown,
358
- moveUp,
359
- moveToStart,
360
- moveToEnd,
361
- setFocus,
362
- getTabIndex
363
- ]
364
- );
365
- }
366
- var ChartContext = react.createContext(null);
367
- function useChartContext() {
368
- const context = react.useContext(ChartContext);
369
- if (!context) {
370
- throw new Error("useChartContext must be used within a ChartProvider");
371
- }
372
- return context;
373
- }
374
- function getAllLabels(data) {
375
- const labelSet = /* @__PURE__ */ new Set();
376
- data.forEach((series) => {
377
- series.data.forEach((point) => {
378
- labelSet.add(point.label);
379
- });
380
- });
381
- return Array.from(labelSet);
382
- }
383
- function calculateScales(data, dimensions, startAtZero) {
384
- const allLabels = getAllLabels(data);
385
- const { plotArea } = dimensions;
386
- let dataMin = Infinity;
387
- let dataMax = -Infinity;
388
- data.forEach((series) => {
389
- series.data.forEach((point) => {
390
- dataMin = Math.min(dataMin, point.value);
391
- dataMax = Math.max(dataMax, point.value);
392
- });
393
- });
394
- if (!isFinite(dataMin) || !isFinite(dataMax)) {
395
- dataMin = 0;
396
- dataMax = 100;
397
- }
398
- const yMin = startAtZero ? Math.min(0, dataMin) : dataMin;
399
- const yTicks = calculateYAxisTicks(yMin, dataMax);
400
- const yMax = yTicks[yTicks.length - 1] || dataMax;
401
- const adjustedYMin = yTicks[0] || yMin;
402
- const xScale = (labelIndex) => {
403
- if (allLabels.length <= 1) return plotArea.x + plotArea.width / 2;
404
- const step = plotArea.width / allLabels.length;
405
- return plotArea.x + step * labelIndex + step / 2;
406
- };
407
- const yRange = yMax - adjustedYMin || 1;
408
- const yScale = (value) => {
409
- const normalized = (value - adjustedYMin) / yRange;
410
- return plotArea.y + plotArea.height * (1 - normalized);
411
- };
412
- return {
413
- allLabels,
414
- xScale,
415
- yScale,
416
- yMin: adjustedYMin,
417
- yMax,
418
- yTicks
419
- };
420
- }
421
- function ChartProvider({
422
- children,
423
- containerRef,
424
- data,
425
- type,
426
- title,
427
- description,
428
- xAxisLabel,
429
- yAxisLabel,
430
- showTooltip,
431
- showGrid,
432
- showLegend,
433
- announceTrends,
434
- trendUpFormat,
435
- trendDownFormat,
436
- startAtZero,
437
- reducedMotion = true,
438
- onPointFocus: onPointFocusProp,
439
- onPointSelect: onPointSelectProp
440
- }) {
441
- const [selectedPoint, setSelectedPoint] = react.useState(null);
442
- const [announcement, setAnnouncement] = react.useState("");
443
- const [isTooltipVisible, setIsTooltipVisible] = react.useState(false);
444
- const [tooltipPoint, setTooltipPoint] = react.useState(null);
445
- const [currentTrend, setCurrentTrend] = react.useState(null);
446
- const [currentTrendDirection, setCurrentTrendDirection] = react.useState(null);
447
- const dimensions = useChartDimensions(containerRef);
448
- const scales = react.useMemo(
449
- () => calculateScales(data, dimensions, startAtZero),
450
- [data, dimensions, startAtZero]
451
- );
452
- void react.useMemo(
453
- () => Math.max(...data.map((s) => s.data.length)),
454
- [data]
455
- );
456
- const formatTrendText = react.useCallback(
457
- (percent, isUp) => {
458
- const format = isUp ? trendUpFormat : trendDownFormat;
459
- return format.replace("{percent}", String(percent));
460
- },
461
- [trendUpFormat, trendDownFormat]
462
- );
463
- const getTrendInfo = (seriesIndex, pointIndex) => {
464
- if (!announceTrends || pointIndex <= 0) return null;
465
- const series = data[seriesIndex];
466
- if (!series) return null;
467
- const currentPoint = series.data[pointIndex];
468
- const previousPoint = series.data[pointIndex - 1];
469
- if (!currentPoint || !previousPoint || previousPoint.value === 0) {
470
- return null;
471
- }
472
- const change = (currentPoint.value - previousPoint.value) / Math.abs(previousPoint.value) * 100;
473
- const isUp = change >= 0;
474
- const percent = Math.abs(Math.round(change));
475
- return {
476
- text: formatTrendText(percent, isUp),
477
- direction: isUp ? "up" : "down"
478
- };
479
- };
480
- const roving = useRovingTabIndex2D({
481
- rows: data.length,
482
- cols: (row) => data[row]?.data.length || 0,
483
- onFocusChange: (seriesIndex, pointIndex) => {
484
- const series = data[seriesIndex];
485
- const point = series?.data[pointIndex];
486
- if (!series || !point) return;
487
- const trendInfo = getTrendInfo(seriesIndex, pointIndex);
488
- setCurrentTrend(trendInfo?.text ?? null);
489
- setCurrentTrendDirection(trendInfo?.direction ?? null);
490
- const position = `${pointIndex + 1} of ${series.data.length}`;
491
- const seriesInfo = data.length > 1 ? `${series.name}: ` : "";
492
- const formattedValue = formatValue(point.value);
493
- const announcementTrend = trendInfo ? `, ${trendInfo.text}` : "";
494
- setAnnouncement(
495
- `${seriesInfo}${point.label}, ${formattedValue}${announcementTrend}. ${position}.`
496
- );
497
- if (showTooltip) {
498
- setIsTooltipVisible(true);
499
- setTooltipPoint({ series: seriesIndex, point: pointIndex });
500
- }
501
- onPointFocusProp?.(point, seriesIndex, pointIndex);
502
- }
503
- });
504
- const formatValue = react.useCallback((value2) => {
505
- const locale = typeof navigator !== "undefined" ? navigator.language : "en-US";
506
- return new Intl.NumberFormat(locale).format(value2);
507
- }, []);
508
- const calculateTrendForPoint = react.useCallback(
509
- (seriesIndex, pointIndex) => {
510
- if (!announceTrends) return null;
511
- if (pointIndex <= 0) return null;
512
- const series = data[seriesIndex];
513
- if (!series) return null;
514
- const currentPoint = series.data[pointIndex];
515
- const previousPoint = series.data[pointIndex - 1];
516
- if (!currentPoint || !previousPoint || previousPoint.value === 0) {
517
- return null;
518
- }
519
- const change = (currentPoint.value - previousPoint.value) / Math.abs(previousPoint.value) * 100;
520
- const isUp = change >= 0;
521
- const percent = Math.abs(Math.round(change));
522
- return {
523
- text: formatTrendText(percent, isUp),
524
- direction: isUp ? "up" : "down"
525
- };
526
- },
527
- [data, announceTrends, formatTrendText]
528
- );
529
- const getSeriesColor = react.useCallback((seriesIndex) => {
530
- return DEFAULT_SERIES_COLORS[seriesIndex % DEFAULT_SERIES_COLORS.length] ?? "var(--chart-1)";
531
- }, []);
532
- const getPointCoordinates = react.useCallback(
533
- (seriesIndex, pointIndex) => {
534
- const series = data[seriesIndex];
535
- const point = series?.data[pointIndex];
536
- if (!series || !point) return null;
537
- const labelIndex = scales.allLabels.indexOf(point.label);
538
- if (labelIndex === -1) return null;
539
- return {
540
- x: scales.xScale(labelIndex),
541
- y: scales.yScale(point.value)
542
- };
543
- },
544
- [data, scales]
545
- );
546
- const setFocus = react.useCallback(
547
- (series, point) => {
548
- roving.setFocus(series, point);
549
- },
550
- [roving]
551
- );
552
- const selectPoint = react.useCallback(
553
- (series, point) => {
554
- setSelectedPoint({ series, point });
555
- const seriesData = data[series];
556
- const pointData = seriesData?.data[point];
557
- if (seriesData && pointData) {
558
- onPointSelectProp?.(pointData, series, point);
559
- }
560
- },
561
- [data, onPointSelectProp]
562
- );
563
- const clearSelection = react.useCallback(() => {
564
- setSelectedPoint(null);
565
- }, []);
566
- const announce = react.useCallback((message) => {
567
- setAnnouncement(message);
568
- }, []);
569
- const showTooltipAt = react.useCallback(
570
- (series, point) => {
571
- if (showTooltip) {
572
- setIsTooltipVisible(true);
573
- setTooltipPoint({ series, point });
574
- const trendResult = calculateTrendForPoint(series, point);
575
- setCurrentTrend(trendResult?.text ?? null);
576
- setCurrentTrendDirection(trendResult?.direction ?? null);
577
- }
578
- },
579
- [showTooltip, calculateTrendForPoint]
580
- );
581
- const hideTooltip = react.useCallback(() => {
582
- setIsTooltipVisible(false);
583
- setTooltipPoint(null);
584
- }, []);
585
- const value = react.useMemo(
586
- () => ({
587
- // State
588
- focusedSeries: roving.focusedRow,
589
- focusedPoint: roving.focusedCol,
590
- selectedPoint,
591
- announcement,
592
- isTooltipVisible,
593
- tooltipPoint,
594
- currentTrend,
595
- currentTrendDirection,
596
- // Computed
597
- dimensions,
598
- scales,
599
- // Props passthrough
600
- data,
601
- type,
602
- title,
603
- description,
604
- xAxisLabel,
605
- yAxisLabel,
606
- showTooltip,
607
- showGrid,
608
- showLegend,
609
- announceTrends,
610
- trendUpFormat,
611
- trendDownFormat,
612
- startAtZero,
613
- reducedMotion,
614
- // Actions
615
- setFocus,
616
- selectPoint,
617
- clearSelection,
618
- announce,
619
- showTooltipAt,
620
- hideTooltip,
621
- // Helpers
622
- getTabIndex: roving.getTabIndex,
623
- formatValue,
624
- getSeriesColor,
625
- getPointCoordinates
626
- }),
627
- [
628
- roving.focusedRow,
629
- roving.focusedCol,
630
- roving.getTabIndex,
631
- selectedPoint,
632
- announcement,
633
- isTooltipVisible,
634
- tooltipPoint,
635
- currentTrend,
636
- currentTrendDirection,
637
- dimensions,
638
- scales,
639
- data,
640
- type,
641
- title,
642
- description,
643
- xAxisLabel,
644
- yAxisLabel,
645
- showTooltip,
646
- showGrid,
647
- showLegend,
648
- announceTrends,
649
- trendUpFormat,
650
- trendDownFormat,
651
- startAtZero,
652
- reducedMotion,
653
- setFocus,
654
- selectPoint,
655
- clearSelection,
656
- announce,
657
- showTooltipAt,
658
- hideTooltip,
659
- formatValue,
660
- getSeriesColor,
661
- getPointCoordinates
662
- ]
663
- );
664
- return /* @__PURE__ */ jsxRuntime.jsx(ChartContext.Provider, { value, children });
665
- }
666
- function ChartGrid({
667
- yTicks,
668
- yScale,
669
- plotX,
670
- plotWidth,
671
- visible
672
- }) {
673
- if (!visible) {
674
- return null;
675
- }
676
- return /* @__PURE__ */ jsxRuntime.jsx("g", { className: "chart-grid", "aria-hidden": "true", "data-testid": "chart-grid", children: yTicks.map((tick) => {
677
- const y = yScale(tick);
678
- return /* @__PURE__ */ jsxRuntime.jsx(
679
- "line",
680
- {
681
- x1: plotX,
682
- y1: y,
683
- x2: plotX + plotWidth,
684
- y2: y,
685
- stroke: GRID_COLOR,
686
- strokeWidth: GRID_STROKE_WIDTH,
687
- strokeOpacity: GRID_STROKE_OPACITY
688
- },
689
- tick
690
- );
691
- }) });
692
- }
693
- ChartGrid.displayName = "ChartGrid";
694
- function ChartAxis({
695
- allLabels,
696
- yTicks,
697
- xScale,
698
- yScale,
699
- plotArea,
700
- xAxisLabel,
701
- yAxisLabel,
702
- formatValue
703
- }) {
704
- const { x: plotX, y: plotY, width: plotWidth, height: plotHeight } = plotArea;
705
- return /* @__PURE__ */ jsxRuntime.jsxs("g", { className: "chart-axis", "aria-hidden": "true", "data-testid": "chart-axis", children: [
706
- /* @__PURE__ */ jsxRuntime.jsx(
707
- "line",
708
- {
709
- x1: plotX,
710
- y1: plotY + plotHeight,
711
- x2: plotX + plotWidth,
712
- y2: plotY + plotHeight,
713
- stroke: AXIS_COLOR,
714
- strokeWidth: AXIS_STROKE_WIDTH
715
- }
716
- ),
717
- /* @__PURE__ */ jsxRuntime.jsx(
718
- "line",
719
- {
720
- x1: plotX,
721
- y1: plotY,
722
- x2: plotX,
723
- y2: plotY + plotHeight,
724
- stroke: AXIS_COLOR,
725
- strokeWidth: AXIS_STROKE_WIDTH
726
- }
727
- ),
728
- allLabels.map((label, index) => {
729
- const x = xScale(index);
730
- const y = plotY + plotHeight;
731
- return /* @__PURE__ */ jsxRuntime.jsxs("g", { children: [
732
- /* @__PURE__ */ jsxRuntime.jsx(
733
- "line",
734
- {
735
- x1: x,
736
- y1: y,
737
- x2: x,
738
- y2: y + AXIS_TICK_SIZE,
739
- stroke: AXIS_COLOR,
740
- strokeWidth: AXIS_STROKE_WIDTH
741
- }
742
- ),
743
- /* @__PURE__ */ jsxRuntime.jsx(
744
- "text",
745
- {
746
- x,
747
- y: y + AXIS_TICK_SIZE + AXIS_LABEL_FONT_SIZE,
748
- textAnchor: "middle",
749
- fontSize: AXIS_LABEL_FONT_SIZE,
750
- fill: "currentColor",
751
- className: "text-[var(--content-foreground)]",
752
- children: label
753
- }
754
- )
755
- ] }, label);
756
- }),
757
- yTicks.map((tick) => {
758
- const x = plotX;
759
- const y = yScale(tick);
760
- return /* @__PURE__ */ jsxRuntime.jsxs("g", { children: [
761
- /* @__PURE__ */ jsxRuntime.jsx(
762
- "line",
763
- {
764
- x1: x - AXIS_TICK_SIZE,
765
- y1: y,
766
- x2: x,
767
- y2: y,
768
- stroke: AXIS_COLOR,
769
- strokeWidth: AXIS_STROKE_WIDTH
770
- }
771
- ),
772
- /* @__PURE__ */ jsxRuntime.jsx(
773
- "text",
774
- {
775
- x: x - AXIS_TICK_SIZE - 4,
776
- y,
777
- textAnchor: "end",
778
- dominantBaseline: "middle",
779
- fontSize: AXIS_LABEL_FONT_SIZE,
780
- fill: "currentColor",
781
- className: "text-[var(--content-foreground)]",
782
- children: formatValue(tick)
783
- }
784
- )
785
- ] }, tick);
786
- }),
787
- /* @__PURE__ */ jsxRuntime.jsx(
788
- "text",
789
- {
790
- x: plotX + plotWidth / 2,
791
- y: plotY + plotHeight + 45,
792
- textAnchor: "middle",
793
- fontSize: AXIS_LABEL_FONT_SIZE,
794
- fill: "currentColor",
795
- className: "text-[var(--content-foreground)] font-medium",
796
- children: xAxisLabel
797
- }
798
- ),
799
- /* @__PURE__ */ jsxRuntime.jsx(
800
- "text",
801
- {
802
- x: 15,
803
- y: plotY + plotHeight / 2,
804
- textAnchor: "middle",
805
- fontSize: AXIS_LABEL_FONT_SIZE,
806
- fill: "currentColor",
807
- className: "text-[var(--content-foreground)] font-medium",
808
- transform: `rotate(-90, 15, ${plotY + plotHeight / 2})`,
809
- children: yAxisLabel
810
- }
811
- )
812
- ] });
813
- }
814
- ChartAxis.displayName = "ChartAxis";
815
- function ChartDataPoint({
816
- type,
817
- x,
818
- y,
819
- width = POINT_RADIUS * 2,
820
- height = POINT_RADIUS * 2,
821
- color,
822
- seriesIndex,
823
- pointIndex,
824
- tabIndex,
825
- label,
826
- isSelected = false,
827
- onFocus,
828
- onBlur,
829
- onHover,
830
- onHoverEnd,
831
- onKeyDown
832
- }) {
833
- const ref = react.useRef(null);
834
- const { isFocusVisible, focusProps } = reactAria.useFocusRing();
835
- react.useEffect(() => {
836
- if (tabIndex === 0 && ref.current) {
837
- const activeElement = document.activeElement;
838
- const isChartFocused = activeElement?.closest('[role="graphics-document"]') !== null;
839
- if (isChartFocused) {
840
- ref.current.focus();
841
- }
842
- }
843
- }, [tabIndex]);
844
- const hitAreaSize = Math.max(MIN_TOUCH_TARGET, width, height);
845
- const hitX = type === "bar" ? x - (hitAreaSize - width) / 2 : x - hitAreaSize / 2;
846
- const hitY = type === "bar" ? y - (hitAreaSize - height) / 2 : y - hitAreaSize / 2;
847
- const handleFocus = (event) => {
848
- focusProps.onFocus?.(event);
849
- onFocus?.(seriesIndex, pointIndex);
850
- };
851
- const handleBlur = (event) => {
852
- focusProps.onBlur?.(event);
853
- onBlur?.();
854
- };
855
- const handleMouseEnter = (_event) => {
856
- onHover?.(seriesIndex, pointIndex);
857
- };
858
- const handleMouseLeave = (_event) => {
859
- onHoverEnd?.();
860
- };
861
- const state = isSelected ? "selected" : isFocusVisible ? "focused" : "default";
862
- return /* @__PURE__ */ jsxRuntime.jsxs(
863
- "g",
864
- {
865
- ref,
866
- role: "listitem",
867
- tabIndex,
868
- "aria-label": label,
869
- className: dataPointVariants({ type, state }),
870
- onFocus: handleFocus,
871
- onBlur: handleBlur,
872
- onMouseEnter: handleMouseEnter,
873
- onMouseLeave: handleMouseLeave,
874
- onKeyDown,
875
- "data-testid": `chart-point-${seriesIndex}-${pointIndex}`,
876
- children: [
877
- /* @__PURE__ */ jsxRuntime.jsx(
878
- "rect",
879
- {
880
- x: hitX,
881
- y: hitY,
882
- width: hitAreaSize,
883
- height: hitAreaSize,
884
- fill: "transparent",
885
- className: "cursor-pointer"
886
- }
887
- ),
888
- type === "bar" ? /* @__PURE__ */ jsxRuntime.jsx(
889
- "rect",
890
- {
891
- x,
892
- y,
893
- width,
894
- height,
895
- rx: BAR_RADIUS,
896
- ry: BAR_RADIUS,
897
- fill: color,
898
- className: "chart-bar"
899
- }
900
- ) : /* @__PURE__ */ jsxRuntime.jsx(
901
- "circle",
902
- {
903
- cx: x,
904
- cy: y,
905
- r: POINT_RADIUS,
906
- fill: color,
907
- className: "chart-point"
908
- }
909
- ),
910
- isFocusVisible && (type === "bar" ? /* @__PURE__ */ jsxRuntime.jsx(
911
- "rect",
912
- {
913
- x: x - FOCUS_RING_OFFSET,
914
- y: y - FOCUS_RING_OFFSET,
915
- width: width + FOCUS_RING_OFFSET * 2,
916
- height: height + FOCUS_RING_OFFSET * 2,
917
- rx: BAR_RADIUS + FOCUS_RING_OFFSET,
918
- ry: BAR_RADIUS + FOCUS_RING_OFFSET,
919
- fill: "none",
920
- stroke: "var(--ring)",
921
- strokeWidth: FOCUS_RING_WIDTH,
922
- className: "chart-focus-ring"
923
- }
924
- ) : /* @__PURE__ */ jsxRuntime.jsx(
925
- "circle",
926
- {
927
- cx: x,
928
- cy: y,
929
- r: POINT_RADIUS + FOCUS_RING_OFFSET,
930
- fill: "none",
931
- stroke: "var(--ring)",
932
- strokeWidth: FOCUS_RING_WIDTH,
933
- className: "chart-focus-ring"
934
- }
935
- ))
936
- ]
937
- }
938
- );
939
- }
940
- ChartDataPoint.displayName = "ChartDataPoint";
941
- function ChartBarSeries({
942
- series,
943
- seriesIndex,
944
- totalSeries,
945
- dimensions,
946
- scales,
947
- color,
948
- getTabIndex,
949
- selectedPoint,
950
- onPointFocus,
951
- onPointBlur,
952
- onPointHover,
953
- onPointHoverEnd,
954
- onKeyDown,
955
- formatValue
956
- }) {
957
- const { plotArea } = dimensions;
958
- const { allLabels, xScale: _xScale, yScale, yMin } = scales;
959
- const { barWidth, getBarX } = calculateBarLayout(
960
- plotArea.width,
961
- allLabels.length,
962
- totalSeries,
963
- plotArea.x
964
- );
965
- const baselineY = yScale(Math.max(0, yMin));
966
- return /* @__PURE__ */ jsxRuntime.jsx(
967
- "g",
968
- {
969
- className: "chart-bar-series",
970
- role: "list",
971
- "aria-label": `${series.name} series`,
972
- "data-testid": `chart-series-${seriesIndex}`,
973
- children: series.data.map((point, pointIndex) => {
974
- const labelIndex = allLabels.indexOf(point.label);
975
- if (labelIndex === -1) return null;
976
- const barX = getBarX(labelIndex, seriesIndex);
977
- const barY = yScale(point.value);
978
- const barHeight = Math.abs(baselineY - barY);
979
- const finalBarY = point.value >= 0 ? barY : baselineY;
980
- const isSelected = selectedPoint?.series === seriesIndex && selectedPoint?.point === pointIndex;
981
- const accessibleLabel = `${series.name}: ${point.label}, ${formatValue(point.value)}`;
982
- return /* @__PURE__ */ jsxRuntime.jsx(
983
- ChartDataPoint,
984
- {
985
- type: "bar",
986
- x: barX,
987
- y: finalBarY,
988
- width: barWidth,
989
- height: barHeight,
990
- color,
991
- seriesIndex,
992
- pointIndex,
993
- tabIndex: getTabIndex(seriesIndex, pointIndex),
994
- label: accessibleLabel,
995
- isSelected,
996
- onFocus: onPointFocus,
997
- onBlur: onPointBlur,
998
- onHover: onPointHover,
999
- onHoverEnd: onPointHoverEnd,
1000
- onKeyDown
1001
- },
1002
- `${point.label}-${pointIndex}`
1003
- );
1004
- })
1005
- }
1006
- );
1007
- }
1008
- ChartBarSeries.displayName = "ChartBarSeries";
1009
- function ChartLineSeries({
1010
- series,
1011
- seriesIndex,
1012
- scales,
1013
- color,
1014
- pattern,
1015
- getTabIndex,
1016
- selectedPoint,
1017
- onPointFocus,
1018
- onPointBlur,
1019
- onPointHover,
1020
- onPointHoverEnd,
1021
- onKeyDown,
1022
- formatValue
1023
- }) {
1024
- const { allLabels, xScale, yScale } = scales;
1025
- const points = react.useMemo(() => {
1026
- return series.data.map((point, pointIndex) => {
1027
- const labelIndex = allLabels.indexOf(point.label);
1028
- if (labelIndex === -1) return null;
1029
- return {
1030
- x: xScale(labelIndex),
1031
- y: yScale(point.value),
1032
- point,
1033
- pointIndex,
1034
- labelIndex
1035
- };
1036
- }).filter((p) => p !== null).sort((a, b) => a.labelIndex - b.labelIndex);
1037
- }, [series.data, allLabels, xScale, yScale]);
1038
- const pathD = react.useMemo(() => {
1039
- if (points.length === 0) return "";
1040
- return points.map((p, i) => `${i === 0 ? "M" : "L"} ${p.x} ${p.y}`).join(" ");
1041
- }, [points]);
1042
- const strokeDasharray = LINE_PATTERNS[pattern] === "none" ? void 0 : LINE_PATTERNS[pattern];
1043
- return /* @__PURE__ */ jsxRuntime.jsxs(
1044
- "g",
1045
- {
1046
- className: "chart-line-series",
1047
- role: "list",
1048
- "aria-label": `${series.name} series`,
1049
- "data-testid": `chart-series-${seriesIndex}`,
1050
- children: [
1051
- /* @__PURE__ */ jsxRuntime.jsx(
1052
- "path",
1053
- {
1054
- d: pathD,
1055
- fill: "none",
1056
- stroke: color,
1057
- strokeWidth: LINE_STROKE_WIDTH,
1058
- strokeDasharray,
1059
- strokeLinecap: "round",
1060
- strokeLinejoin: "round",
1061
- className: "chart-line",
1062
- "aria-hidden": "true"
1063
- }
1064
- ),
1065
- points.map(({ x, y, point, pointIndex }) => {
1066
- const isSelected = selectedPoint?.series === seriesIndex && selectedPoint?.point === pointIndex;
1067
- const accessibleLabel = `${series.name}: ${point.label}, ${formatValue(point.value)}`;
1068
- return /* @__PURE__ */ jsxRuntime.jsx(
1069
- ChartDataPoint,
1070
- {
1071
- type: "line",
1072
- x,
1073
- y,
1074
- color,
1075
- seriesIndex,
1076
- pointIndex,
1077
- tabIndex: getTabIndex(seriesIndex, pointIndex),
1078
- label: accessibleLabel,
1079
- isSelected,
1080
- onFocus: onPointFocus,
1081
- onBlur: onPointBlur,
1082
- onHover: onPointHover,
1083
- onHoverEnd: onPointHoverEnd,
1084
- onKeyDown
1085
- },
1086
- `${point.label}-${pointIndex}`
1087
- );
1088
- })
1089
- ]
1090
- }
1091
- );
1092
- }
1093
- ChartLineSeries.displayName = "ChartLineSeries";
1094
- function ChartSVG({
1095
- type,
1096
- data,
1097
- dimensions,
1098
- scales,
1099
- titleId,
1100
- descId,
1101
- showGrid,
1102
- xAxisLabel,
1103
- yAxisLabel,
1104
- getSeriesColor,
1105
- getTabIndex,
1106
- selectedPoint,
1107
- formatValue,
1108
- onKeyDown,
1109
- onPointFocus,
1110
- onPointBlur,
1111
- onPointHover,
1112
- onPointHoverEnd
1113
- }) {
1114
- const { width, height, plotArea } = dimensions;
1115
- const { allLabels, xScale, yScale, yTicks } = scales;
1116
- return /* @__PURE__ */ jsxRuntime.jsxs(
1117
- "svg",
1118
- {
1119
- role: "graphics-document",
1120
- "aria-roledescription": `${type} chart`,
1121
- "aria-labelledby": titleId,
1122
- "aria-describedby": descId,
1123
- viewBox: `0 0 ${width} ${height}`,
1124
- className: "h-full w-full",
1125
- style: { maxHeight: height },
1126
- "data-testid": "chart-svg",
1127
- children: [
1128
- /* @__PURE__ */ jsxRuntime.jsx(
1129
- ChartGrid,
1130
- {
1131
- yTicks,
1132
- yScale,
1133
- plotX: plotArea.x,
1134
- plotWidth: plotArea.width,
1135
- visible: showGrid
1136
- }
1137
- ),
1138
- /* @__PURE__ */ jsxRuntime.jsx(
1139
- ChartAxis,
1140
- {
1141
- allLabels,
1142
- yTicks,
1143
- xScale,
1144
- yScale,
1145
- plotArea,
1146
- xAxisLabel,
1147
- yAxisLabel,
1148
- formatValue
1149
- }
1150
- ),
1151
- data.map((series, seriesIndex) => {
1152
- const color = series.color || getSeriesColor(seriesIndex);
1153
- const pattern = series.pattern || "solid";
1154
- if (type === "bar") {
1155
- return /* @__PURE__ */ jsxRuntime.jsx(
1156
- ChartBarSeries,
1157
- {
1158
- series,
1159
- seriesIndex,
1160
- totalSeries: data.length,
1161
- dimensions,
1162
- scales,
1163
- color,
1164
- getTabIndex,
1165
- selectedPoint,
1166
- onPointFocus,
1167
- onPointBlur,
1168
- onPointHover,
1169
- onPointHoverEnd,
1170
- onKeyDown,
1171
- formatValue
1172
- },
1173
- series.name
1174
- );
1175
- }
1176
- return /* @__PURE__ */ jsxRuntime.jsx(
1177
- ChartLineSeries,
1178
- {
1179
- series,
1180
- seriesIndex,
1181
- scales,
1182
- color,
1183
- pattern,
1184
- getTabIndex,
1185
- selectedPoint,
1186
- onPointFocus,
1187
- onPointBlur,
1188
- onPointHover,
1189
- onPointHoverEnd,
1190
- onKeyDown,
1191
- formatValue
1192
- },
1193
- series.name
1194
- );
1195
- })
1196
- ]
1197
- }
1198
- );
1199
- }
1200
- ChartSVG.displayName = "ChartSVG";
1201
- var TOOLTIP_GAP = 8;
1202
- function ChartTooltip({
1203
- visible,
1204
- x,
1205
- y,
1206
- seriesName,
1207
- label,
1208
- value,
1209
- chartWidth,
1210
- chartHeight,
1211
- trend,
1212
- trendDirection
1213
- }) {
1214
- const tooltipRef = react.useRef(null);
1215
- const [position, setPosition] = react.useState({ left: 0, top: 0 });
1216
- const [side, setSide] = react.useState("top");
1217
- react.useEffect(() => {
1218
- if (!visible || !tooltipRef.current) return;
1219
- const tooltip = tooltipRef.current;
1220
- const tooltipRect = tooltip.getBoundingClientRect();
1221
- const tooltipWidth = tooltipRect.width || 120;
1222
- const tooltipHeight = tooltipRect.height || 50;
1223
- let left = x - tooltipWidth / 2;
1224
- let top = y - tooltipHeight - TOOLTIP_GAP;
1225
- let newSide = "top";
1226
- if (top < 0) {
1227
- top = y + TOOLTIP_GAP + 16;
1228
- newSide = "bottom";
1229
- }
1230
- if (left < 0) {
1231
- left = 0;
1232
- }
1233
- if (left + tooltipWidth > chartWidth) {
1234
- left = chartWidth - tooltipWidth;
1235
- }
1236
- setPosition({ left, top });
1237
- setSide(newSide);
1238
- }, [visible, x, y, chartWidth]);
1239
- if (!visible) {
1240
- return null;
1241
- }
1242
- return /* @__PURE__ */ jsxRuntime.jsxs(
1243
- "div",
1244
- {
1245
- ref: tooltipRef,
1246
- "aria-hidden": "true",
1247
- className: chunkFWQYB22U_js.tooltipContentVariants({ side }),
1248
- style: {
1249
- position: "absolute",
1250
- left: position.left,
1251
- top: position.top,
1252
- pointerEvents: "none"
1253
- },
1254
- "data-testid": "chart-tooltip",
1255
- children: [
1256
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "font-medium", children: seriesName }),
1257
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "opacity-80", children: [
1258
- label,
1259
- ": ",
1260
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "font-semibold", children: value })
1261
- ] }),
1262
- trend && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-xs opacity-70 mt-1 flex items-center gap-1", children: [
1263
- trendDirection === "up" ? /* @__PURE__ */ jsxRuntime.jsx(
1264
- "svg",
1265
- {
1266
- "aria-hidden": "true",
1267
- className: "h-3 w-3 text-green-500",
1268
- viewBox: "0 0 20 20",
1269
- fill: "currentColor",
1270
- children: /* @__PURE__ */ jsxRuntime.jsx(
1271
- "path",
1272
- {
1273
- fillRule: "evenodd",
1274
- d: "M10 17a.75.75 0 01-.75-.75V5.612L5.29 9.77a.75.75 0 01-1.08-1.04l5.25-5.5a.75.75 0 011.08 0l5.25 5.5a.75.75 0 11-1.08 1.04l-3.96-4.158V16.25A.75.75 0 0110 17z",
1275
- clipRule: "evenodd"
1276
- }
1277
- )
1278
- }
1279
- ) : trendDirection === "down" ? /* @__PURE__ */ jsxRuntime.jsx(
1280
- "svg",
1281
- {
1282
- "aria-hidden": "true",
1283
- className: "h-3 w-3 text-red-500",
1284
- viewBox: "0 0 20 20",
1285
- fill: "currentColor",
1286
- children: /* @__PURE__ */ jsxRuntime.jsx(
1287
- "path",
1288
- {
1289
- fillRule: "evenodd",
1290
- d: "M10 3a.75.75 0 01.75.75v10.638l3.96-4.158a.75.75 0 111.08 1.04l-5.25 5.5a.75.75 0 01-1.08 0l-5.25-5.5a.75.75 0 111.08-1.04l3.96 4.158V3.75A.75.75 0 0110 3z",
1291
- clipRule: "evenodd"
1292
- }
1293
- )
1294
- }
1295
- ) : null,
1296
- /* @__PURE__ */ jsxRuntime.jsx("span", { children: trend })
1297
- ] })
1298
- ]
1299
- }
1300
- );
1301
- }
1302
- ChartTooltip.displayName = "ChartTooltip";
1303
- function ChartLegend({
1304
- data,
1305
- visible,
1306
- type,
1307
- getSeriesColor
1308
- }) {
1309
- if (!visible) {
1310
- return null;
1311
- }
1312
- return /* @__PURE__ */ jsxRuntime.jsx(
1313
- "div",
1314
- {
1315
- className: legendVariants({ visible }),
1316
- role: "list",
1317
- "aria-label": "Chart legend",
1318
- "data-testid": "chart-legend",
1319
- children: data.map((series, index) => {
1320
- const color = series.color || getSeriesColor(index);
1321
- const pattern = series.pattern || "solid";
1322
- return /* @__PURE__ */ jsxRuntime.jsxs(
1323
- "div",
1324
- {
1325
- role: "listitem",
1326
- className: "flex items-center gap-2",
1327
- children: [
1328
- type === "bar" ? /* @__PURE__ */ jsxRuntime.jsx(
1329
- "div",
1330
- {
1331
- className: "h-3 w-3 rounded-sm",
1332
- style: { backgroundColor: color },
1333
- "data-testid": `legend-color-${index}`,
1334
- "aria-hidden": "true"
1335
- }
1336
- ) : /* @__PURE__ */ jsxRuntime.jsx(
1337
- "svg",
1338
- {
1339
- width: "24",
1340
- height: "12",
1341
- "aria-hidden": "true",
1342
- "data-testid": `legend-color-${index}`,
1343
- children: /* @__PURE__ */ jsxRuntime.jsx(
1344
- "line",
1345
- {
1346
- x1: "0",
1347
- y1: "6",
1348
- x2: "24",
1349
- y2: "6",
1350
- stroke: color,
1351
- strokeWidth: "2",
1352
- strokeDasharray: LINE_PATTERNS[pattern] === "none" ? void 0 : LINE_PATTERNS[pattern]
1353
- }
1354
- )
1355
- }
1356
- ),
1357
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm text-[var(--content-foreground)]", children: series.name })
1358
- ]
1359
- },
1360
- series.name
1361
- );
1362
- })
1363
- }
1364
- );
1365
- }
1366
- ChartLegend.displayName = "ChartLegend";
1367
- function ChartAnnouncer({
1368
- announcement
1369
- }) {
1370
- return /* @__PURE__ */ jsxRuntime.jsx(reactAria.VisuallyHidden, { children: /* @__PURE__ */ jsxRuntime.jsx(
1371
- "div",
1372
- {
1373
- role: "status",
1374
- "aria-live": "polite",
1375
- "aria-atomic": "true",
1376
- "data-testid": "chart-announcer",
1377
- children: announcement
1378
- }
1379
- ) });
1380
- }
1381
- ChartAnnouncer.displayName = "ChartAnnouncer";
1382
- function ChartDataTable({
1383
- data,
1384
- title,
1385
- xAxisLabel,
1386
- yAxisLabel,
1387
- formatValue,
1388
- allLabels
1389
- }) {
1390
- const isSingleSeries = data.length === 1;
1391
- return /* @__PURE__ */ jsxRuntime.jsx(reactAria.VisuallyHidden, { children: /* @__PURE__ */ jsxRuntime.jsxs("table", { "data-testid": "chart-data-table", children: [
1392
- /* @__PURE__ */ jsxRuntime.jsxs("caption", { children: [
1393
- title,
1394
- " data table"
1395
- ] }),
1396
- /* @__PURE__ */ jsxRuntime.jsx("thead", { children: /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
1397
- /* @__PURE__ */ jsxRuntime.jsx("th", { scope: "col", children: xAxisLabel }),
1398
- isSingleSeries ? /* @__PURE__ */ jsxRuntime.jsx("th", { scope: "col", children: yAxisLabel }) : data.map((series) => /* @__PURE__ */ jsxRuntime.jsxs("th", { scope: "col", children: [
1399
- series.name,
1400
- " (",
1401
- yAxisLabel,
1402
- ")"
1403
- ] }, series.name))
1404
- ] }) }),
1405
- /* @__PURE__ */ jsxRuntime.jsx("tbody", { children: allLabels.map((label) => /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
1406
- /* @__PURE__ */ jsxRuntime.jsx("th", { scope: "row", children: label }),
1407
- data.map((series) => {
1408
- const point = series.data.find((p) => p.label === label);
1409
- return /* @__PURE__ */ jsxRuntime.jsx("td", { children: point ? formatValue(point.value) : "\u2014" }, series.name);
1410
- })
1411
- ] }, label)) })
1412
- ] }) });
1413
- }
1414
- ChartDataTable.displayName = "ChartDataTable";
1415
- function useChartKeyboard(options) {
1416
- const { roving, onSelect, onClear, disabled = false } = options;
1417
- const onKeyDown = react.useCallback(
1418
- (event) => {
1419
- if (disabled) return;
1420
- switch (event.key) {
1421
- case "ArrowRight":
1422
- event.preventDefault();
1423
- roving.moveRight();
1424
- break;
1425
- case "ArrowLeft":
1426
- event.preventDefault();
1427
- roving.moveLeft();
1428
- break;
1429
- case "ArrowDown":
1430
- event.preventDefault();
1431
- roving.moveDown();
1432
- break;
1433
- case "ArrowUp":
1434
- event.preventDefault();
1435
- roving.moveUp();
1436
- break;
1437
- case "Home":
1438
- event.preventDefault();
1439
- roving.moveToStart();
1440
- break;
1441
- case "End":
1442
- event.preventDefault();
1443
- roving.moveToEnd();
1444
- break;
1445
- case "Enter":
1446
- case " ":
1447
- event.preventDefault();
1448
- onSelect?.();
1449
- break;
1450
- case "Escape":
1451
- event.preventDefault();
1452
- onClear?.();
1453
- break;
1454
- }
1455
- },
1456
- [roving, onSelect, onClear, disabled]
1457
- );
1458
- return { onKeyDown };
1459
- }
1460
- function ChartInner({ chartId }) {
1461
- const ctx = useChartContext();
1462
- const {
1463
- data,
1464
- type,
1465
- title,
1466
- xAxisLabel,
1467
- yAxisLabel,
1468
- showTooltip,
1469
- showGrid,
1470
- showLegend,
1471
- dimensions,
1472
- scales,
1473
- announcement,
1474
- isTooltipVisible,
1475
- tooltipPoint,
1476
- currentTrend,
1477
- currentTrendDirection,
1478
- selectedPoint,
1479
- getTabIndex,
1480
- formatValue,
1481
- getSeriesColor,
1482
- getPointCoordinates,
1483
- setFocus,
1484
- selectPoint,
1485
- clearSelection,
1486
- showTooltipAt,
1487
- hideTooltip
1488
- } = ctx;
1489
- const titleId = `${chartId}-title`;
1490
- const descId = `${chartId}-desc`;
1491
- const roving = useRovingTabIndex2D({
1492
- rows: data.length,
1493
- cols: (row) => data[row]?.data.length || 0,
1494
- onFocusChange: (seriesIndex, pointIndex) => {
1495
- setFocus(seriesIndex, pointIndex);
1496
- }
1497
- });
1498
- const { onKeyDown } = useChartKeyboard({
1499
- roving,
1500
- onSelect: () => {
1501
- selectPoint(roving.focusedRow, roving.focusedCol);
1502
- },
1503
- onClear: () => {
1504
- clearSelection();
1505
- }
1506
- });
1507
- const handlePointFocus = react.useCallback(
1508
- (seriesIndex, pointIndex) => {
1509
- roving.setFocus(seriesIndex, pointIndex);
1510
- showTooltipAt(seriesIndex, pointIndex);
1511
- },
1512
- [roving, showTooltipAt]
1513
- );
1514
- const handlePointBlur = react.useCallback(() => {
1515
- }, []);
1516
- const handlePointHover = react.useCallback(
1517
- (seriesIndex, pointIndex) => {
1518
- showTooltipAt(seriesIndex, pointIndex);
1519
- },
1520
- [showTooltipAt]
1521
- );
1522
- const handlePointHoverEnd = react.useCallback(() => {
1523
- hideTooltip();
1524
- }, [hideTooltip]);
1525
- const tooltipPosition = react.useMemo(() => {
1526
- if (!tooltipPoint) return { x: 0, y: 0 };
1527
- const coords = getPointCoordinates(tooltipPoint.series, tooltipPoint.point);
1528
- return coords || { x: 0, y: 0 };
1529
- }, [tooltipPoint, getPointCoordinates]);
1530
- const tooltipSeries = react.useMemo(
1531
- () => tooltipPoint ? data[tooltipPoint.series] : null,
1532
- [tooltipPoint, data]
1533
- );
1534
- const tooltipPointData = react.useMemo(
1535
- () => tooltipPoint ? tooltipSeries?.data[tooltipPoint.point] : null,
1536
- [tooltipPoint, tooltipSeries]
1537
- );
1538
- const shouldShowLegend = react.useMemo(
1539
- () => showLegend ?? data.length > 1,
1540
- [showLegend, data.length]
1541
- );
1542
- return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1543
- /* @__PURE__ */ jsxRuntime.jsx(ChartAnnouncer, { announcement }),
1544
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "relative", children: [
1545
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "relative z-0", children: /* @__PURE__ */ jsxRuntime.jsx(
1546
- ChartSVG,
1547
- {
1548
- type,
1549
- data,
1550
- dimensions,
1551
- scales,
1552
- titleId,
1553
- descId,
1554
- showGrid,
1555
- xAxisLabel,
1556
- yAxisLabel,
1557
- getSeriesColor,
1558
- getTabIndex,
1559
- selectedPoint,
1560
- formatValue,
1561
- onKeyDown,
1562
- onPointFocus: handlePointFocus,
1563
- onPointBlur: handlePointBlur,
1564
- onPointHover: handlePointHover,
1565
- onPointHoverEnd: handlePointHoverEnd
1566
- }
1567
- ) }),
1568
- showTooltip && tooltipPointData && tooltipSeries && /* @__PURE__ */ jsxRuntime.jsx(
1569
- ChartTooltip,
1570
- {
1571
- visible: isTooltipVisible,
1572
- x: tooltipPosition.x,
1573
- y: tooltipPosition.y,
1574
- seriesName: tooltipSeries.name,
1575
- label: tooltipPointData.label,
1576
- value: formatValue(tooltipPointData.value),
1577
- chartWidth: dimensions.width,
1578
- chartHeight: dimensions.height,
1579
- trend: currentTrend,
1580
- trendDirection: currentTrendDirection
1581
- }
1582
- )
1583
- ] }),
1584
- /* @__PURE__ */ jsxRuntime.jsx(
1585
- ChartLegend,
1586
- {
1587
- data,
1588
- visible: shouldShowLegend,
1589
- type,
1590
- getSeriesColor
1591
- }
1592
- ),
1593
- /* @__PURE__ */ jsxRuntime.jsx(
1594
- ChartDataTable,
1595
- {
1596
- data,
1597
- title,
1598
- xAxisLabel,
1599
- yAxisLabel,
1600
- formatValue,
1601
- allLabels: scales.allLabels
1602
- }
1603
- )
1604
- ] });
1605
- }
1606
- var ChartComponent = react.forwardRef(
1607
- ({
1608
- data,
1609
- type,
1610
- title,
1611
- description,
1612
- xAxisLabel,
1613
- yAxisLabel,
1614
- variant = "default",
1615
- className,
1616
- showTooltip = true,
1617
- showGrid = true,
1618
- showLegend,
1619
- announceTrends = false,
1620
- trendUpFormat = "up {percent}% from previous",
1621
- trendDownFormat = "down {percent}% from previous",
1622
- startAtZero = true,
1623
- reducedMotion,
1624
- onPointFocus,
1625
- onPointSelect,
1626
- id,
1627
- "aria-label": ariaLabel,
1628
- "aria-labelledby": ariaLabelledby,
1629
- "aria-describedby": ariaDescribedby,
1630
- "data-testid": dataTestId,
1631
- ...rest
1632
- }, ref) => {
1633
- const containerRef = react.useRef(null);
1634
- const generatedId = react.useId();
1635
- const chartId = id || `chart-${generatedId}`;
1636
- const titleId = `${chartId}-title`;
1637
- const descId = `${chartId}-desc`;
1638
- const shouldShowLegend = showLegend ?? data.length > 1;
1639
- return /* @__PURE__ */ jsxRuntime.jsxs(
1640
- "figure",
1641
- {
1642
- ref: (node) => {
1643
- if (typeof ref === "function") {
1644
- ref(node);
1645
- } else if (ref) {
1646
- ref.current = node;
1647
- }
1648
- containerRef.current = node;
1649
- },
1650
- id: chartId,
1651
- role: "figure",
1652
- "aria-label": ariaLabel,
1653
- "aria-labelledby": ariaLabelledby || titleId,
1654
- "aria-describedby": ariaDescribedby || descId,
1655
- "data-testid": dataTestId,
1656
- className: chunkVIREG536_js.cn(chartVariants({ variant }), "p-4", className),
1657
- ...rest,
1658
- children: [
1659
- /* @__PURE__ */ jsxRuntime.jsxs("figcaption", { className: "sr-only", children: [
1660
- /* @__PURE__ */ jsxRuntime.jsx("span", { id: titleId, children: title }),
1661
- /* @__PURE__ */ jsxRuntime.jsx("span", { id: descId, children: description })
1662
- ] }),
1663
- /* @__PURE__ */ jsxRuntime.jsx(
1664
- ChartProvider,
1665
- {
1666
- containerRef,
1667
- data,
1668
- type,
1669
- title,
1670
- description,
1671
- xAxisLabel,
1672
- yAxisLabel,
1673
- showTooltip,
1674
- showGrid,
1675
- showLegend: shouldShowLegend,
1676
- announceTrends,
1677
- trendUpFormat,
1678
- trendDownFormat,
1679
- startAtZero,
1680
- reducedMotion,
1681
- onPointFocus,
1682
- onPointSelect,
1683
- children: /* @__PURE__ */ jsxRuntime.jsx(ChartInner, { chartId })
1684
- }
1685
- )
1686
- ]
1687
- }
1688
- );
1689
- }
1690
- );
1691
- ChartComponent.displayName = "Chart";
1692
- var Chart = react.memo(ChartComponent);
1693
- Chart.displayName = "Chart";
1694
- var DataPointSchema = zod.z.object({
1695
- /** X-axis label (e.g., "January", "Q1 2024") */
1696
- label: zod.z.string().min(1, "Label is required"),
1697
- /** Y-axis value */
1698
- value: zod.z.number(),
1699
- /** Extended description for screen readers */
1700
- description: zod.z.string().optional()
1701
- });
1702
- var LinePatternSchema = zod.z.enum(["solid", "dashed", "dotted"]);
1703
- var DataSeriesSchema = zod.z.object({
1704
- /** Series name for legend and announcements */
1705
- name: zod.z.string().min(1, "Series name is required"),
1706
- /** CSS color (defaults to --chart-1 through --chart-5) */
1707
- color: zod.z.string().optional(),
1708
- /** Line pattern for accessibility (defaults to solid) */
1709
- pattern: LinePatternSchema.optional().default("solid"),
1710
- /** Data points in this series */
1711
- data: zod.z.array(DataPointSchema).min(1, "At least one data point required")
1712
- });
1713
- var ChartTypeSchema = zod.z.enum(["bar", "line"]);
1714
- var ChartVariantSchema = zod.z.enum(["default", "muted"]);
1715
- var ChartPropsSchema = chunkT4COXKQ3_js.BaseComponentPropsSchema.extend({
1716
- // Required props
1717
- /** Chart data - maximum 5 series (Decision 11) */
1718
- data: zod.z.array(DataSeriesSchema).min(1, "At least one data series required").max(5, "Maximum 5 series allowed"),
1719
- /** Chart type: bar or line */
1720
- type: ChartTypeSchema,
1721
- /** Chart title (displayed and used for accessibility) */
1722
- title: zod.z.string().min(1, "Title is required"),
1723
- /** Chart description (displayed and used for accessibility) */
1724
- description: zod.z.string().min(1, "Description is required"),
1725
- /** X-axis label */
1726
- xAxisLabel: zod.z.string().min(1, "X-axis label is required"),
1727
- /** Y-axis label */
1728
- yAxisLabel: zod.z.string().min(1, "Y-axis label is required"),
1729
- // Optional - Styling
1730
- /** Visual variant */
1731
- variant: ChartVariantSchema.optional().default("default"),
1732
- // Optional - Features
1733
- /** Show tooltip on focus/hover (default: true) */
1734
- showTooltip: zod.z.boolean().optional().default(true),
1735
- /** Show grid lines (default: true) */
1736
- showGrid: zod.z.boolean().optional().default(true),
1737
- /** Show legend (auto: shown when >1 series) */
1738
- showLegend: zod.z.boolean().optional(),
1739
- /** Announce trend percentages (default: false) */
1740
- announceTrends: zod.z.boolean().optional().default(false),
1741
- /** ICU format string for upward trend (use {percent} placeholder) */
1742
- trendUpFormat: zod.z.string().optional().default("up {percent}% from previous"),
1743
- /** ICU format string for downward trend (use {percent} placeholder) */
1744
- trendDownFormat: zod.z.string().optional().default("down {percent}% from previous"),
1745
- /** Y-axis starts at zero (default: true) - Decision 6 */
1746
- startAtZero: zod.z.boolean().optional().default(true),
1747
- // Optional - Accessibility
1748
- /** Override reduced motion preference */
1749
- reducedMotion: zod.z.boolean().optional(),
1750
- // Optional - Events (use z.unknown() since Zod can't validate function types at runtime)
1751
- /** Called when a data point receives focus */
1752
- onPointFocus: zod.z.unknown().optional(),
1753
- /** Called when a data point is selected (Enter/Space) */
1754
- onPointSelect: zod.z.unknown().optional()
1755
- });
1756
-
1757
- exports.Chart = Chart;
1758
- exports.ChartPropsSchema = ChartPropsSchema;
1759
- exports.ChartTypeSchema = ChartTypeSchema;
1760
- exports.ChartVariantSchema = ChartVariantSchema;
1761
- exports.DataPointSchema = DataPointSchema;
1762
- exports.DataSeriesSchema = DataSeriesSchema;
1763
- exports.LinePatternSchema = LinePatternSchema;
1764
- exports.chartVariants = chartVariants;
1765
- exports.dataPointVariants = dataPointVariants;
1766
- //# sourceMappingURL=chunk-V74LGMAE.js.map
1767
- //# sourceMappingURL=chunk-V74LGMAE.js.map