@squadbase/vantage 0.6.2 → 0.7.0-dev1.19083f7

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 (355) hide show
  1. package/dist/add-4GHF2TX2.js +6 -0
  2. package/dist/add-4GHF2TX2.js.map +1 -0
  3. package/dist/{build-O5TVNH4E.js → build-U7GO26HR.js} +9 -9
  4. package/dist/{build-O5TVNH4E.js.map → build-U7GO26HR.js.map} +1 -1
  5. package/dist/{check-WFBEDHDR.js → check-MRVAIHG5.js} +7 -7
  6. package/dist/{check-WFBEDHDR.js.map → check-MRVAIHG5.js.map} +1 -1
  7. package/dist/chunk-2IAPIOPS.js +152 -0
  8. package/dist/chunk-2IAPIOPS.js.map +1 -0
  9. package/dist/chunk-3RJEOP3J.js +174 -0
  10. package/dist/chunk-3RJEOP3J.js.map +1 -0
  11. package/dist/{chunk-QDZA5JSL.js → chunk-AABMKHEU.js} +4 -4
  12. package/dist/{chunk-QDZA5JSL.js.map → chunk-AABMKHEU.js.map} +1 -1
  13. package/dist/{chunk-PVTHHV7X.js → chunk-ANZLVSEP.js} +28 -7
  14. package/dist/chunk-ANZLVSEP.js.map +1 -0
  15. package/dist/chunk-CKWPK4RO.js +50 -0
  16. package/dist/chunk-CKWPK4RO.js.map +1 -0
  17. package/dist/chunk-EG4PX726.js +678 -0
  18. package/dist/chunk-EG4PX726.js.map +1 -0
  19. package/dist/{chunk-3G43C6OL.js → chunk-GNXCX4WE.js} +46 -3
  20. package/dist/chunk-GNXCX4WE.js.map +1 -0
  21. package/dist/chunk-NYQJ5UY4.js +9028 -0
  22. package/dist/chunk-NYQJ5UY4.js.map +1 -0
  23. package/dist/chunk-NZ5QIIG4.js +74 -0
  24. package/dist/chunk-NZ5QIIG4.js.map +1 -0
  25. package/dist/{chunk-BCE22JSM.js → chunk-PJ4SPXHS.js} +52 -16
  26. package/dist/chunk-PJ4SPXHS.js.map +1 -0
  27. package/dist/{chunk-RPZAALCX.js → chunk-QNOX7WLZ.js} +256 -165
  28. package/dist/chunk-QNOX7WLZ.js.map +1 -0
  29. package/dist/{chunk-ZVANIULZ.js → chunk-RNTDBX6S.js} +4 -4
  30. package/dist/{chunk-ZVANIULZ.js.map → chunk-RNTDBX6S.js.map} +1 -1
  31. package/dist/{chunk-PXRX5PEC.js → chunk-ROHNXP7J.js} +73 -4
  32. package/dist/chunk-ROHNXP7J.js.map +1 -0
  33. package/dist/chunk-S5MDTHH7.js +466 -0
  34. package/dist/chunk-S5MDTHH7.js.map +1 -0
  35. package/dist/chunk-SDJTTMLK.js +1877 -0
  36. package/dist/chunk-SDJTTMLK.js.map +1 -0
  37. package/dist/{chunk-EP6JHXSR.js → chunk-SHZM3EXB.js} +68 -12
  38. package/dist/chunk-SHZM3EXB.js.map +1 -0
  39. package/dist/chunk-TRMHNMMZ.js +61 -0
  40. package/dist/chunk-TRMHNMMZ.js.map +1 -0
  41. package/dist/{chunk-A2UUGASH.js → chunk-U736PVHY.js} +2 -2
  42. package/dist/chunk-U736PVHY.js.map +1 -0
  43. package/dist/{chunk-JGRMRXXZ.js → chunk-UWSQUHX6.js} +4 -99
  44. package/dist/chunk-UWSQUHX6.js.map +1 -0
  45. package/dist/cli.js +15 -11
  46. package/dist/cli.js.map +1 -1
  47. package/dist/client/index.d.ts +34 -3
  48. package/dist/client/index.js +211 -12
  49. package/dist/client/index.js.map +1 -1
  50. package/dist/components/index.d.ts +2113 -30
  51. package/dist/components/index.js +7 -4
  52. package/dist/delta-text-CbrOaW83.d.ts +17 -0
  53. package/dist/{dev-NZRLOQCL.js → dev-O42JFQ64.js} +24 -13
  54. package/dist/dev-O42JFQ64.js.map +1 -0
  55. package/dist/doc/index.d.ts +215 -2
  56. package/dist/doc/index.js +423 -5
  57. package/dist/doc/index.js.map +1 -1
  58. package/dist/{docs-ZGDJUHJI.js → docs-JVP4RPKT.js} +3 -3
  59. package/dist/{docs-ZGDJUHJI.js.map → docs-JVP4RPKT.js.map} +1 -1
  60. package/dist/{doctor-VFKEMR54.js → doctor-YD3XAAOT.js} +8 -8
  61. package/dist/doctor-YD3XAAOT.js.map +1 -0
  62. package/dist/format-DihQkL1N.d.ts +249 -0
  63. package/dist/geo-japan-7BMSOJRX.js +8 -0
  64. package/dist/geo-japan-7BMSOJRX.js.map +1 -0
  65. package/dist/geo-us-GVOG7VXH.js +8 -0
  66. package/dist/geo-us-GVOG7VXH.js.map +1 -0
  67. package/dist/geo-world-35HL56UU.js +8 -0
  68. package/dist/geo-world-35HL56UU.js.map +1 -0
  69. package/dist/markdown/index.js +1 -1
  70. package/dist/markdown/index.js.map +1 -1
  71. package/dist/{preview-QDCIVVSR.js → preview-T6CLSQVX.js} +12 -4
  72. package/dist/preview-T6CLSQVX.js.map +1 -0
  73. package/dist/query/index.d.ts +0 -11
  74. package/dist/query/index.js +2 -2
  75. package/dist/{routes-RHP5FVGD.js → routes-PVKNT777.js} +6 -6
  76. package/dist/{routes-RHP5FVGD.js.map → routes-PVKNT777.js.map} +1 -1
  77. package/dist/{search-RFBELGY7.js → search-5LC4XPB5.js} +3 -3
  78. package/dist/{search-RFBELGY7.js.map → search-5LC4XPB5.js.map} +1 -1
  79. package/dist/slide/index.d.ts +272 -1
  80. package/dist/slide/index.js +1086 -19
  81. package/dist/slide/index.js.map +1 -1
  82. package/dist/table/index.js +14 -10
  83. package/dist/table/index.js.map +1 -1
  84. package/dist/ui/index.d.ts +148 -12
  85. package/dist/ui/index.js +1340 -88
  86. package/dist/ui/index.js.map +1 -1
  87. package/dist/{upgrade-GF2P67M6.js → upgrade-6DT7ADRP.js} +7 -7
  88. package/dist/{upgrade-GF2P67M6.js.map → upgrade-6DT7ADRP.js.map} +1 -1
  89. package/dist/vite/index.d.ts +10 -0
  90. package/dist/vite/index.js +4 -4
  91. package/docs/en/agent-skills.md +1 -1
  92. package/docs/en/changelog.md +82 -0
  93. package/docs/en/cli-reference.md +30 -0
  94. package/docs/en/components.md +42 -17
  95. package/docs/en/doc/delta-text.md +40 -0
  96. package/docs/en/doc/doc-action-items.md +49 -0
  97. package/docs/en/doc/doc-callout.md +38 -0
  98. package/docs/en/doc/doc-data-table.md +60 -0
  99. package/docs/en/doc/doc-executive-summary.md +64 -0
  100. package/docs/en/doc/doc-figure.md +56 -0
  101. package/docs/en/doc/doc-key-findings.md +61 -0
  102. package/docs/en/doc/doc-kpi-scorecard.md +80 -0
  103. package/docs/en/doc/doc-notes-and-sources.md +43 -0
  104. package/docs/en/doc/doc-report-header.md +46 -0
  105. package/docs/en/pages-and-metadata.md +15 -0
  106. package/docs/en/parts/area-chart.md +99 -0
  107. package/docs/en/parts/bar-chart.md +91 -0
  108. package/docs/en/parts/bar-list.md +50 -0
  109. package/docs/en/parts/category-bar.md +37 -0
  110. package/docs/en/parts/chart-frame.md +39 -0
  111. package/docs/en/parts/data-table.md +22 -0
  112. package/docs/en/parts/delta.md +51 -0
  113. package/docs/en/parts/donut-chart.md +72 -0
  114. package/docs/en/parts/format.md +43 -0
  115. package/docs/en/parts/funnel-steps.md +2 -1
  116. package/docs/en/parts/heatmap.md +53 -0
  117. package/docs/en/parts/kpi-card.md +58 -0
  118. package/docs/en/parts/legend.md +35 -0
  119. package/docs/en/parts/line-chart.md +94 -0
  120. package/docs/en/parts/metric-value.md +3 -2
  121. package/docs/en/parts/page-shell.md +1 -1
  122. package/docs/en/parts/progress-circle.md +33 -0
  123. package/docs/en/parts/sample-data.md +39 -0
  124. package/docs/en/parts/scatter-chart.md +56 -0
  125. package/docs/en/parts/sparkline.md +1 -1
  126. package/docs/en/parts/tracker.md +36 -0
  127. package/docs/en/parts/trend-indicator.md +17 -1
  128. package/docs/en/parts/updated-at.md +30 -0
  129. package/docs/en/parts/waterfall-chart.md +56 -0
  130. package/docs/en/slide/slide-chart-full.md +48 -0
  131. package/docs/en/slide/slide-chart-insight.md +52 -0
  132. package/docs/en/slide/slide-columns.md +46 -0
  133. package/docs/en/slide/slide-comparison.md +68 -0
  134. package/docs/en/slide/slide-cover.md +39 -0
  135. package/docs/en/slide/slide-exec-summary.md +47 -0
  136. package/docs/en/slide/slide-heading.md +38 -0
  137. package/docs/en/slide/slide-kpi-grid.md +55 -0
  138. package/docs/en/slide/slide-kpi-hero.md +58 -0
  139. package/docs/en/slide/slide-next-actions.md +49 -0
  140. package/docs/en/slide/slide-scorecard-table.md +54 -0
  141. package/docs/en/slide/slide-section.md +44 -0
  142. package/docs/en/slide/slide-source-line.md +34 -0
  143. package/docs/en/ui/alert-dialog.md +42 -0
  144. package/docs/en/ui/avatar.md +31 -0
  145. package/docs/en/ui/combobox.md +74 -0
  146. package/docs/en/ui/drawer.md +41 -0
  147. package/docs/en/ui/empty.md +1 -1
  148. package/docs/en/ui/error-state.md +4 -3
  149. package/docs/en/ui/field.md +42 -0
  150. package/docs/en/ui/hover-card.md +21 -0
  151. package/docs/en/ui/kbd.md +17 -0
  152. package/docs/en/ui/loading.md +1 -1
  153. package/docs/en/ui/pagination.md +36 -0
  154. package/docs/en/ui/radio-group.md +21 -0
  155. package/docs/en/ui/toast.md +44 -0
  156. package/docs/en/ui/toggle-group.md +4 -3
  157. package/docs/en/ui-and-theming.md +1 -1
  158. package/docs/index.json +1184 -114
  159. package/docs/ja/agent-skills.md +1 -1
  160. package/docs/ja/changelog.md +84 -0
  161. package/docs/ja/cli-reference.md +29 -0
  162. package/docs/ja/components.md +68 -101
  163. package/docs/ja/doc/delta-text.md +40 -0
  164. package/docs/ja/doc/doc-action-items.md +49 -0
  165. package/docs/ja/doc/doc-callout.md +38 -0
  166. package/docs/ja/doc/doc-data-table.md +60 -0
  167. package/docs/ja/doc/doc-executive-summary.md +64 -0
  168. package/docs/ja/doc/doc-figure.md +56 -0
  169. package/docs/ja/doc/doc-key-findings.md +61 -0
  170. package/docs/ja/doc/doc-kpi-scorecard.md +80 -0
  171. package/docs/ja/doc/doc-notes-and-sources.md +43 -0
  172. package/docs/ja/doc/doc-report-header.md +46 -0
  173. package/docs/ja/page-types/csv.md +83 -0
  174. package/docs/ja/page-types/doc.md +83 -0
  175. package/docs/ja/page-types/excel.md +82 -0
  176. package/docs/ja/page-types/slide.md +133 -0
  177. package/docs/ja/page-types.md +47 -0
  178. package/docs/ja/pages-and-metadata.md +15 -0
  179. package/docs/ja/parts/area-chart.md +85 -0
  180. package/docs/ja/parts/bar-chart.md +95 -0
  181. package/docs/ja/parts/bar-list.md +58 -0
  182. package/docs/ja/parts/category-bar.md +36 -0
  183. package/docs/ja/parts/chart-frame.md +36 -0
  184. package/docs/ja/parts/data-table.md +22 -0
  185. package/docs/ja/parts/delta.md +51 -0
  186. package/docs/ja/parts/donut-chart.md +66 -0
  187. package/docs/ja/parts/echart.md +3 -0
  188. package/docs/ja/parts/format.md +44 -0
  189. package/docs/ja/parts/funnel-steps.md +27 -8
  190. package/docs/ja/parts/heatmap.md +45 -0
  191. package/docs/ja/parts/kpi-card.md +56 -0
  192. package/docs/ja/parts/legend.md +36 -0
  193. package/docs/ja/parts/line-chart.md +84 -0
  194. package/docs/ja/parts/metric-value.md +3 -2
  195. package/docs/ja/parts/page-shell.md +1 -1
  196. package/docs/ja/parts/progress-circle.md +34 -0
  197. package/docs/ja/parts/sample-data.md +61 -0
  198. package/docs/ja/parts/scatter-chart.md +69 -0
  199. package/docs/ja/parts/sparkline.md +2 -2
  200. package/docs/ja/parts/tracker.md +32 -0
  201. package/docs/ja/parts/trend-indicator.md +17 -1
  202. package/docs/ja/parts/updated-at.md +27 -0
  203. package/docs/ja/parts/waterfall-chart.md +61 -0
  204. package/docs/ja/routing.md +8 -86
  205. package/docs/ja/slide/slide-chart-full.md +48 -0
  206. package/docs/ja/slide/slide-chart-insight.md +52 -0
  207. package/docs/ja/slide/slide-columns.md +46 -0
  208. package/docs/ja/slide/slide-comparison.md +68 -0
  209. package/docs/ja/slide/slide-cover.md +39 -0
  210. package/docs/ja/slide/slide-exec-summary.md +47 -0
  211. package/docs/ja/slide/slide-heading.md +38 -0
  212. package/docs/ja/slide/slide-kpi-grid.md +55 -0
  213. package/docs/ja/slide/slide-kpi-hero.md +58 -0
  214. package/docs/ja/slide/slide-next-actions.md +49 -0
  215. package/docs/ja/slide/slide-scorecard-table.md +54 -0
  216. package/docs/ja/slide/slide-section.md +44 -0
  217. package/docs/ja/slide/slide-source-line.md +34 -0
  218. package/docs/ja/ui/alert-dialog.md +41 -0
  219. package/docs/ja/ui/avatar.md +31 -0
  220. package/docs/ja/ui/combobox.md +74 -0
  221. package/docs/ja/ui/drawer.md +41 -0
  222. package/docs/ja/ui/empty.md +1 -1
  223. package/docs/ja/ui/error-state.md +4 -3
  224. package/docs/ja/ui/field.md +42 -0
  225. package/docs/ja/ui/hover-card.md +21 -0
  226. package/docs/ja/ui/kbd.md +16 -0
  227. package/docs/ja/ui/loading.md +1 -1
  228. package/docs/ja/ui/pagination.md +36 -0
  229. package/docs/ja/ui/radio-group.md +21 -0
  230. package/docs/ja/ui/toast.md +46 -0
  231. package/docs/ja/ui/toggle-group.md +4 -3
  232. package/docs/ja/ui-and-theming.md +14 -7
  233. package/package.json +43 -29
  234. package/registry/ui/accordion.tsx +76 -0
  235. package/registry/ui/alert-dialog.tsx +189 -0
  236. package/registry/ui/alert.tsx +80 -0
  237. package/registry/ui/app-shell.tsx +424 -0
  238. package/registry/ui/area-chart.tsx +3960 -0
  239. package/registry/ui/attention-list.tsx +465 -0
  240. package/registry/ui/avatar.tsx +110 -0
  241. package/registry/ui/badge.tsx +56 -0
  242. package/registry/ui/bar-chart.tsx +3954 -0
  243. package/registry/ui/bar-list.tsx +3998 -0
  244. package/registry/ui/box-plot-chart.tsx +4214 -0
  245. package/registry/ui/breadcrumb.tsx +128 -0
  246. package/registry/ui/button.tsx +62 -0
  247. package/registry/ui/calendar.tsx +223 -0
  248. package/registry/ui/card.tsx +107 -0
  249. package/registry/ui/category-bar.tsx +1498 -0
  250. package/registry/ui/chart-frame.tsx +1604 -0
  251. package/registry/ui/checkbox.tsx +30 -0
  252. package/registry/ui/collapsible.tsx +23 -0
  253. package/registry/ui/combo-chart.tsx +1851 -0
  254. package/registry/ui/combobox.tsx +310 -0
  255. package/registry/ui/command.tsx +198 -0
  256. package/registry/ui/dashboard-card.tsx +217 -0
  257. package/registry/ui/data-table.tsx +896 -157
  258. package/registry/ui/date-range-picker.tsx +544 -0
  259. package/registry/ui/delta.tsx +350 -0
  260. package/registry/ui/dialog.tsx +161 -0
  261. package/registry/ui/donut-chart.tsx +4006 -0
  262. package/registry/ui/drawer.tsx +229 -0
  263. package/registry/ui/dropdown-menu.tsx +274 -0
  264. package/registry/ui/echart.tsx +1178 -0
  265. package/registry/ui/field.tsx +240 -0
  266. package/registry/ui/filter-bar.tsx +551 -0
  267. package/registry/ui/funnel-steps.tsx +3843 -0
  268. package/registry/ui/heatmap.tsx +2027 -0
  269. package/registry/ui/histogram-chart.tsx +4284 -0
  270. package/registry/ui/hover-card.tsx +52 -0
  271. package/registry/ui/input-group.tsx +160 -0
  272. package/registry/ui/input.tsx +24 -0
  273. package/registry/ui/kbd.tsx +30 -0
  274. package/registry/ui/kpi-card.tsx +905 -0
  275. package/registry/ui/label.tsx +22 -0
  276. package/registry/ui/legend.tsx +3817 -0
  277. package/registry/ui/line-chart.tsx +3958 -0
  278. package/registry/ui/metric-value.tsx +62 -0
  279. package/registry/ui/multi-select.tsx +382 -0
  280. package/registry/ui/page-shell.tsx +420 -0
  281. package/registry/ui/pagination.tsx +140 -0
  282. package/registry/ui/paired-chart.tsx +4086 -0
  283. package/registry/ui/pivot-table.tsx +1259 -0
  284. package/registry/ui/placeholder.tsx +36 -0
  285. package/registry/ui/popover.tsx +92 -0
  286. package/registry/ui/progress-circle.tsx +1033 -0
  287. package/registry/ui/progress.tsx +85 -0
  288. package/registry/ui/radio-group.tsx +39 -0
  289. package/registry/ui/sample-data.tsx +230 -0
  290. package/registry/ui/scatter-chart.tsx +4503 -0
  291. package/registry/ui/scroll-area.tsx +56 -0
  292. package/registry/ui/searchable-select.tsx +352 -0
  293. package/registry/ui/section-header.tsx +43 -0
  294. package/registry/ui/segmented-control.tsx +76 -0
  295. package/registry/ui/select.tsx +255 -0
  296. package/registry/ui/separator.tsx +27 -0
  297. package/registry/ui/sheet.tsx +139 -0
  298. package/registry/ui/sidebar.tsx +725 -0
  299. package/registry/ui/skeleton.tsx +17 -0
  300. package/registry/ui/slider.tsx +56 -0
  301. package/registry/ui/sparkline.tsx +230 -0
  302. package/registry/ui/spinner.tsx +14 -0
  303. package/registry/ui/states.tsx +247 -0
  304. package/registry/ui/status-badge.tsx +286 -0
  305. package/registry/ui/switch.tsx +34 -0
  306. package/registry/ui/table.tsx +118 -0
  307. package/registry/ui/tabs.tsx +84 -0
  308. package/registry/ui/textarea.tsx +22 -0
  309. package/registry/ui/toast.tsx +250 -0
  310. package/registry/ui/toggle-group.tsx +91 -0
  311. package/registry/ui/toggle.tsx +47 -0
  312. package/registry/ui/tooltip.tsx +72 -0
  313. package/registry/ui/tracker.tsx +1015 -0
  314. package/registry/ui/treemap.tsx +1916 -0
  315. package/registry/ui/trend-indicator.tsx +217 -0
  316. package/registry/ui/updated-at.tsx +276 -0
  317. package/registry/ui/waterfall-chart.tsx +4561 -0
  318. package/skills/vantage-add-feature/SKILL.md +14 -7
  319. package/skills/vantage-design/SKILL.md +62 -52
  320. package/skills/vantage-design/references/extract.md +26 -27
  321. package/skills/vantage-design/references/format.md +12 -172
  322. package/skills/vantage-design/references/presets.md +50 -110
  323. package/skills/vantage-pitfalls/SKILL.md +10 -1
  324. package/skills/vantage-slide/SKILL.md +71 -36
  325. package/templates/AGENTS.md +54 -16
  326. package/templates/agents/api.md +36 -0
  327. package/templates/agents/csv.md +2 -1
  328. package/templates/agents/doc.md +52 -3
  329. package/templates/agents/page.md +91 -10
  330. package/templates/agents/slide.md +90 -4
  331. package/templates/agents/xlsx.md +2 -1
  332. package/theme.css +247 -132
  333. package/dist/add-EISGSZAH.js +0 -6
  334. package/dist/add-EISGSZAH.js.map +0 -1
  335. package/dist/chunk-3G43C6OL.js.map +0 -1
  336. package/dist/chunk-5ZOP4SQR.js +0 -47
  337. package/dist/chunk-5ZOP4SQR.js.map +0 -1
  338. package/dist/chunk-A2UUGASH.js.map +0 -1
  339. package/dist/chunk-BCE22JSM.js.map +0 -1
  340. package/dist/chunk-DTDVSFRY.js +0 -29
  341. package/dist/chunk-DTDVSFRY.js.map +0 -1
  342. package/dist/chunk-EP6JHXSR.js.map +0 -1
  343. package/dist/chunk-JGRMRXXZ.js.map +0 -1
  344. package/dist/chunk-KLEIVDUV.js +0 -165
  345. package/dist/chunk-KLEIVDUV.js.map +0 -1
  346. package/dist/chunk-LSRMRIXA.js +0 -2227
  347. package/dist/chunk-LSRMRIXA.js.map +0 -1
  348. package/dist/chunk-PVTHHV7X.js.map +0 -1
  349. package/dist/chunk-PXRX5PEC.js.map +0 -1
  350. package/dist/chunk-RPZAALCX.js.map +0 -1
  351. package/dist/chunk-T3FLAGI6.js +0 -316
  352. package/dist/chunk-T3FLAGI6.js.map +0 -1
  353. package/dist/dev-NZRLOQCL.js.map +0 -1
  354. package/dist/doctor-VFKEMR54.js.map +0 -1
  355. package/dist/preview-QDCIVVSR.js.map +0 -1
@@ -0,0 +1,1015 @@
1
+ // Copied by `vantage add ui tracker`. This file is yours to edit.
2
+ // Generated from @squadbase/squadkit registry/charts/tracker.tsx by `pnpm run registry` (in Vantage, edit packages/squadkit, not registry/).
3
+ "use client"
4
+
5
+ /**
6
+ * Tracker — a row of small blocks, one per period, each coloured by status:
7
+ * uptime per day, batch-job results, daily target hit/miss. Hover a block to
8
+ * see its tooltip. Plain HTML/CSS. Block colours are AREA colours: the meaning names
9
+ * (`"positive"` / `"negative"` / `"warning"` / `"info"`) resolve to the `--<tone>-fill`
10
+ * tokens (same strength in light and dark), not the text colours `--<tone>`. The colour
11
+ * never carries the meaning alone: put the date and the state in `tooltip`
12
+ * (also the block's accessible name).
13
+ */
14
+ import { forwardRef, useCallback, useRef, type ComponentProps } from "react"
15
+
16
+ import { cn } from "@squadbase/vantage/ui"
17
+ import { Tooltip, TooltipContent, TooltipTrigger } from "@squadbase/vantage/ui"
18
+ import type { ChartColor } from "@squadbase/vantage/components"
19
+ import { EMPTY_VALUE, formatValue, toValueFormatter, type ValueFormat } from "@squadbase/vantage/components"
20
+ import type { ChartColors, ChartSeriesColor, ChartTone, ValueFormatter } from "@squadbase/vantage/components"
21
+
22
+ /* ---------- inlined from @squadbase/squadkit registry/lib/locale.ts (internal to @squadbase/vantage) ---------- */
23
+
24
+ /**
25
+ * The display language of the parts and the defaults that follow it.
26
+ *
27
+ * The language comes from `<html lang>`: a tag starting with `ja` reads Japanese, anything else English.
28
+ * Without a usable `lang` (missing, invalid, or no `document` — SSR, Node) the locale is `FALLBACK_LOCALE`
29
+ * (`en-US`). A `locale` passed explicitly (a prop, an argument) always wins.
30
+ *
31
+ * Parts read the locale through `useLocale` (`hooks/use-locale`) and pass it down; the pure helpers here
32
+ * and in `format` / `comparison` / `chart-*` take it as an argument and fall back to `documentLocale()`.
33
+ */
34
+
35
+ /** The language of the built-in wording: Japanese or English. */
36
+ type UiLanguage = "ja" | "en"
37
+
38
+ /** The locale used when `<html lang>` gives none (and on the server). */
39
+ const FALLBACK_LOCALE = "en-US"
40
+
41
+ /** `"ja"` when `locale` starts with `ja` (`ja`, `ja-JP`), else `"en"`. A missing locale is `"en"`. */
42
+ function uiLanguage(locale: string | null | undefined): UiLanguage {
43
+ return typeof locale === "string" && locale.trim().toLowerCase().startsWith("ja") ? "ja" : "en"
44
+ }
45
+
46
+ /** A BCP 47 tag in its canonical form (`en-gb` → `en-GB`), or `FALLBACK_LOCALE` when it is empty or invalid. */
47
+ function normalizeLocale(tag: string | null | undefined): string {
48
+ const value = tag?.trim()
49
+ if (!value) return FALLBACK_LOCALE
50
+ try {
51
+ return Intl.getCanonicalLocales(value)[0] ?? FALLBACK_LOCALE
52
+ } catch {
53
+ return FALLBACK_LOCALE
54
+ }
55
+ }
56
+
57
+ /**
58
+ * The locale of the page: `document.documentElement.lang`, canonicalized. `FALLBACK_LOCALE` when it is empty or
59
+ * invalid, or there is no `document`. Parts read it through `useLocale`, never while rendering.
60
+ */
61
+ function documentLocale(): string {
62
+ if (typeof document === "undefined") return FALLBACK_LOCALE
63
+ return normalizeLocale(document.documentElement?.getAttribute("lang"))
64
+ }
65
+
66
+ /** `locale` when given, else the page's locale (`documentLocale()`). */
67
+ function resolveLocale(locale?: string | null): string {
68
+ return locale || documentLocale()
69
+ }
70
+
71
+ /** Picks the wording table of the locale's language. */
72
+ function pickLocale<T>(table: { ja: T; en: T }, locale?: string | null): T {
73
+ return table[uiLanguage(resolveLocale(locale))]
74
+ }
75
+
76
+ /** The currency `format="currency"` uses without a `currency`: JPY for Japanese, USD otherwise. */
77
+ function defaultCurrency(locale?: string | null): string {
78
+ return uiLanguage(resolveLocale(locale)) === "ja" ? "JPY" : "USD"
79
+ }
80
+
81
+ /** The month a fiscal year starts in (1–12) when none is given: April for Japanese, January otherwise. */
82
+ function defaultFiscalYearStartMonth(locale?: string | null): number {
83
+ return uiLanguage(resolveLocale(locale)) === "ja" ? 4 : 1
84
+ }
85
+
86
+ /** A day of the week, 0 = Sunday … 6 = Saturday (the `Date#getDay` / date-fns numbering). */
87
+ type WeekDay = 0 | 1 | 2 | 3 | 4 | 5 | 6
88
+
89
+ /** Locales whose week starts on Sunday when the runtime has no week data. */
90
+ const SUNDAY_FIRST = new Set(["en", "en-US", "en-CA"])
91
+
92
+ /**
93
+ * The first day of the week: Monday for Japanese; otherwise the locale's convention from `Intl.Locale`
94
+ * (`en-US` Sunday, `en-GB` Monday). Without week data in the runtime: Sunday for `en` / `en-US` / `en-CA`,
95
+ * Monday for the rest.
96
+ */
97
+ function weekStartsOn(locale?: string | null): WeekDay {
98
+ const tag = normalizeLocale(resolveLocale(locale))
99
+ if (uiLanguage(tag) === "ja") return 1
100
+ try {
101
+ const info = new Intl.Locale(tag) as Intl.Locale & {
102
+ getWeekInfo?: () => { firstDay: number }
103
+ weekInfo?: { firstDay: number }
104
+ }
105
+ const firstDay = info.getWeekInfo?.().firstDay ?? info.weekInfo?.firstDay
106
+ if (typeof firstDay === "number" && firstDay >= 1 && firstDay <= 7) return (firstDay % 7) as WeekDay
107
+ } catch {
108
+ // Fall through to the table below.
109
+ }
110
+ return SUNDAY_FIRST.has(tag) ? 0 : 1
111
+ }
112
+
113
+ /* ---------- inlined from @squadbase/squadkit registry/lib/chart-utils.ts (internal to @squadbase/vantage) ---------- */
114
+
115
+ const ROOT_PROP_KEYS = new Set(["id", "style", "role", "tabIndex", "lang", "hidden"])
116
+ const ROOT_PROP_PREFIX_RE = /^(data|aria)-/
117
+
118
+ /**
119
+ * The attributes of a typed chart's leftover props that belong on its root
120
+ * element: `id` / `style` / `role` / `tabIndex` / `lang` / `hidden`, `data-*` and `aria-*`.
121
+ * An allowlist, so a chart's own (or deprecated, ignored) props never reach the DOM.
122
+ */
123
+ function chartRootProps(rest: Record<string, unknown>): Record<string, unknown> {
124
+ const out: Record<string, unknown> = {}
125
+ for (const [key, value] of Object.entries(rest)) {
126
+ if (value !== undefined && (ROOT_PROP_KEYS.has(key) || ROOT_PROP_PREFIX_RE.test(key))) out[key] = value
127
+ }
128
+ return out
129
+ }
130
+
131
+ /** The series tokens, in palette order — the default `colors` of every typed chart. */
132
+ const DEFAULT_CHART_COLORS: readonly ChartColor[] = [
133
+ "chart-1",
134
+ "chart-2",
135
+ "chart-3",
136
+ "chart-4",
137
+ "chart-5",
138
+ ]
139
+
140
+ const TOKEN_NAME_RE = /^chart-[1-5]$/
141
+
142
+ /** The meaning colours; each is a theme token of the same name (`--positive`, …). */
143
+ const CHART_TONES: readonly ChartTone[] = ["positive", "warning", "negative", "neutral"]
144
+
145
+ /** Whether `color` is a meaning colour (`"positive"` / `"warning"` / `"negative"` / `"neutral"`). */
146
+ function isChartTone(color: string): color is ChartTone {
147
+ return (CHART_TONES as readonly string[]).includes(color.trim())
148
+ }
149
+
150
+ /**
151
+ * A chart colour as a CSS value: `"chart-2"` → `var(--chart-2)` (so it follows
152
+ * light/dark on its own), anything else passes through unchanged.
153
+ */
154
+ function chartColorToCss(color: ChartColor): string {
155
+ const value = color.trim()
156
+ return TOKEN_NAME_RE.test(value) || isChartTone(value) ? `var(--${value})` : value
157
+ }
158
+
159
+ /**
160
+ * A chart colour for an AREA (bar, slice, segment, ring): like `chartColorToCss`, but a meaning
161
+ * colour resolves to its area token (`"positive"` → `var(--positive-fill)`), which keeps the same
162
+ * lightness step from the page in light and dark. `--positive` etc. are for text and icons.
163
+ */
164
+ function chartFillToCss(color: ChartColor): string {
165
+ const value = color.trim()
166
+ return isChartTone(value) ? `var(--${value}-fill)` : chartColorToCss(color)
167
+ }
168
+
169
+ /** The colour name to resolve for an area: a meaning colour becomes its `-fill` token (`"positive"` → `"positive-fill"`), the rest is unchanged. */
170
+ function chartFillName(color: ChartColor): ChartColor {
171
+ const value = color.trim()
172
+ return isChartTone(value) ? `${value}-fill` : color
173
+ }
174
+
175
+ /** The `i`-th colour, cycling through `colors` (the token palette when empty). */
176
+ function chartColorAt(colors: readonly ChartColor[] | undefined, i: number): ChartColor {
177
+ const palette = colors && colors.length > 0 ? colors : DEFAULT_CHART_COLORS
178
+ return palette[i % palette.length]!
179
+ }
180
+
181
+ /** `colors` extended (by cycling) to exactly `count` entries. */
182
+ function chartColorsFor(colors: readonly ChartColor[] | undefined, count: number): ChartColor[] {
183
+ return Array.from({ length: count }, (_, i) => chartColorAt(colors, i))
184
+ }
185
+
186
+ /** A translucent version of a CSS colour (works for `var(--…)` too). */
187
+ function tintCss(cssColor: string, percent: number): string {
188
+ return `color-mix(in oklab, ${cssColor} ${percent}%, transparent)`
189
+ }
190
+
191
+ const numberFormat = new Intl.NumberFormat("ja-JP", { maximumFractionDigits: 2 })
192
+
193
+ /** Default `valueFormatter`: grouped digits, up to two decimals (`1,234.5`). */
194
+ const defaultValueFormatter: ValueFormatter = (value) => numberFormat.format(value)
195
+
196
+ /**
197
+ * The formatter a chart actually uses: an explicit `valueFormatter` wins, else
198
+ * `format` (default `"compact"`, so ¥1億 / 9.2万 on axes) via `toValueFormatter`.
199
+ */
200
+ function resolveValueFormatter(
201
+ valueFormatter: ValueFormatter | undefined,
202
+ format: ValueFormat | undefined,
203
+ locale?: string,
204
+ ): ValueFormatter {
205
+ return valueFormatter ?? toValueFormatter(format, locale)
206
+ }
207
+
208
+ /**
209
+ * The formatter of value-axis ticks and on-plot labels: an explicit
210
+ * `valueFormatter` wins; else `"compact"` / `"number"` / `"currency"` read in
211
+ * the short form (`1億`, `¥1億`, `¥4,520万` — a tick of `¥100,000,000` is
212
+ * too wide to read), and `"percent"` / `"multiple"` as `format` says. The short
213
+ * form goes through `formatValue` (compact notation, `digits` / `unit` dropped),
214
+ * so an axis tick and a KPI / tooltip of the same `format` always print the same
215
+ * currency sign and grouping.
216
+ */
217
+ function resolveAxisFormatter(
218
+ valueFormatter: ValueFormatter | undefined,
219
+ format: ValueFormat | undefined,
220
+ localeArg?: string,
221
+ ): ValueFormatter {
222
+ if (valueFormatter) return valueFormatter
223
+ const locale = resolveLocale(localeArg)
224
+ const spec = format === undefined ? { type: "compact" as const } : typeof format === "string" ? { type: format } : format
225
+ if (spec.type !== "compact" && spec.type !== "number" && spec.type !== "currency") return toValueFormatter(format, locale)
226
+ const currency = "currency" in spec ? spec.currency : undefined
227
+ const short: ValueFormat =
228
+ spec.type === "currency" ? { type: "currency", currency, notation: "compact" } : { type: "compact" }
229
+ return (value) => formatValue(value, short, locale)
230
+ }
231
+
232
+ interface CompactUnit {
233
+ token: string
234
+ size: number
235
+ }
236
+
237
+ const compactUnitCache = new Map<string, CompactUnit[] | null>()
238
+
239
+ /**
240
+ * The compact-notation unit words of a locale and their sizes, largest first: `兆` / `億` / `万` in ja,
241
+ * `T` / `B` / `M` / `K` in en. `null` when the locale's compact form puts anything between the number and its
242
+ * word (`1,5 Mio.`), where a token cannot be swapped in place.
243
+ */
244
+ function compactUnits(locale: string): CompactUnit[] | null {
245
+ const cached = compactUnitCache.get(locale)
246
+ if (cached !== undefined) return cached
247
+ let units: CompactUnit[] | null = []
248
+ try {
249
+ const compact = new Intl.NumberFormat(locale, { notation: "compact" })
250
+ const seen = new Set<string>()
251
+ for (let exp = 3; exp <= 15; exp++) {
252
+ const parts = compact.formatToParts(10 ** exp)
253
+ const at = parts.findIndex((p) => p.type === "compact")
254
+ if (at === -1) continue
255
+ if (parts[at - 1]?.type !== "integer" || at !== parts.length - 1) {
256
+ units = null
257
+ break
258
+ }
259
+ const token = parts[at]!.value
260
+ if (seen.has(token)) continue
261
+ seen.add(token)
262
+ units.push({ token, size: 10 ** exp })
263
+ }
264
+ } catch {
265
+ units = null
266
+ }
267
+ const sorted = units && units.length > 0 ? units.sort((a, b) => b.size - a.size) : null
268
+ compactUnitCache.set(locale, sorted)
269
+ return sorted
270
+ }
271
+
272
+ const escapeRegExp = (text: string) => text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")
273
+
274
+ /**
275
+ * The value-axis tick formatter for an axis whose largest tick is `top`: every tick reads in the unit of
276
+ * that largest tick, so units never mix on one axis (`¥0.5億` / `¥1億` / `¥1.5億`, not `¥5,000万` / `¥1億`;
277
+ * `$0.5M` / `$1M` / `$1.5M`, not `$500K` / `$1M`). Only the short forms (`compact` / `number` / `currency`,
278
+ * no `valueFormatter`) have units to align; any other format — an axis whose largest tick is under the smallest
279
+ * unit (1万 / 1K), or a locale whose compact form cannot be aligned in place — keeps `resolveAxisFormatter`'s output as it is.
280
+ */
281
+ function resolveAxisTickFormatter(
282
+ valueFormatter: ValueFormatter | undefined,
283
+ format: ValueFormat | undefined,
284
+ localeArg?: string,
285
+ ): (top: number) => ValueFormatter {
286
+ const locale = resolveLocale(localeArg)
287
+ const base = resolveAxisFormatter(valueFormatter, format, locale)
288
+ const spec = format === undefined ? { type: "compact" as const } : typeof format === "string" ? { type: format } : format
289
+ const units = !valueFormatter && (spec.type === "compact" || spec.type === "number" || spec.type === "currency") ? compactUnits(locale) : null
290
+ if (!units) return () => base
291
+ const number = new Intl.NumberFormat(locale, { maximumFractionDigits: 3 })
292
+ const numberToken = new RegExp(`\\d[\\d,]*(?:\\.\\d+)?(?:${units.map((u) => escapeRegExp(u.token)).join("|")})?`)
293
+ return (top) => {
294
+ const unit = units.find((u) => Math.abs(top) >= u.size)
295
+ if (!unit) return base
296
+ return (value) => {
297
+ const text = base(value)
298
+ if (value === 0 || !Number.isFinite(value)) return text
299
+ const scaled = `${number.format(Math.abs(value) / unit.size)}${unit.token}`
300
+ return text.replace(numberToken, () => scaled)
301
+ }
302
+ }
303
+ }
304
+
305
+ /**
306
+ * A data cell as a number, or `null` for a gap. Numeric strings count — SQL
307
+ * `DECIMAL` / `BIGINT` columns usually arrive as strings.
308
+ */
309
+ function toChartNumber(value: unknown): number | null {
310
+ if (typeof value === "number") return Number.isFinite(value) ? value : null
311
+ if (typeof value === "bigint") return Number(value)
312
+ if (typeof value === "string" && value.trim() !== "") {
313
+ const n = Number(value)
314
+ return Number.isFinite(n) ? n : null
315
+ }
316
+ return null
317
+ }
318
+
319
+ /** Clamp `value` into `[min, max]`. */
320
+ function clamp(value: number, min: number, max: number): number {
321
+ return Math.min(max, Math.max(min, value))
322
+ }
323
+
324
+ /* ------------------------------------------------------------ aggregation */
325
+
326
+ /** How many categories a chart colours individually; the rest fold into「その他」. */
327
+ const MAX_CHART_SERIES = 5
328
+
329
+ /** The series name the folded categories get, by language. */
330
+ const OTHER_SERIES_LABELS: Record<UiLanguage, string> = { ja: "その他", en: "Other" }
331
+
332
+ /** The series name the folded categories get in `locale` ("Other" / "その他"). Default the page's locale (`<html lang>`). */
333
+ function otherSeriesLabel(locale?: string): string {
334
+ return OTHER_SERIES_LABELS[uiLanguage(resolveLocale(locale))]
335
+ }
336
+
337
+ const OTHER_NAMES = new Set(Object.values(OTHER_SERIES_LABELS))
338
+
339
+ /** Whether a category / row is the "other" bucket by name (「その他」 or "Other", whatever the page language). */
340
+ function isOtherName(name: string | null | undefined): boolean {
341
+ return typeof name === "string" && OTHER_NAMES.has(name)
342
+ }
343
+
344
+ interface AggregatedItems<Item extends { name: string; value: number }> {
345
+ /** The `n` largest items, in their given order. All items when there are `n` or fewer. */
346
+ top: Item[]
347
+ /** The items folded into `other`, in their given order. */
348
+ rest: Item[]
349
+ /** The folded remainder, or `null` when nothing was folded. */
350
+ other: { name: string; value: number } | null
351
+ }
352
+
353
+ /**
354
+ * Keep the `n` largest items (by value; ties keep the earlier one) in their
355
+ * given order and fold the rest into one `otherLabel` item. Shared by every
356
+ * chart that caps its categories (Area / Line / Bar series, Donut slices,
357
+ * BarList rows).
358
+ */
359
+ function aggregateTopN<Item extends { name: string; value: number }>(
360
+ items: readonly Item[],
361
+ n: number = MAX_CHART_SERIES,
362
+ otherLabel: string = otherSeriesLabel(),
363
+ ): AggregatedItems<Item> {
364
+ if (items.length <= n) return { top: [...items], rest: [], other: null }
365
+ const ranked = items
366
+ .map((item, i) => ({ item, i }))
367
+ .sort((a, b) => b.item.value - a.item.value || a.i - b.i)
368
+ const keep = new Set(ranked.slice(0, n).map((r) => r.i))
369
+ const top = items.filter((_, i) => keep.has(i))
370
+ const rest = items.filter((_, i) => !keep.has(i))
371
+ return { top, rest, other: { name: otherLabel, value: rest.reduce((sum, item) => sum + item.value, 0) } }
372
+ }
373
+
374
+ interface AggregatedSeries {
375
+ /** Rows to draw: the input rows, plus an `otherCategory` column when categories were folded. */
376
+ data: Record<string, unknown>[]
377
+ /** Series to draw: the kept categories in their given order, then `otherCategory`. */
378
+ categories: string[]
379
+ /** The folded series' name, or `null`. */
380
+ otherCategory: string | null
381
+ }
382
+
383
+ /**
384
+ * Cap a cartesian chart at `n` series: rank the categories by the sum of their
385
+ * values, keep the top `n` and add a per-row sum of the rest as `otherLabel`.
386
+ */
387
+ function aggregateSeries(
388
+ data: readonly Record<string, unknown>[],
389
+ categories: readonly string[],
390
+ n: number = MAX_CHART_SERIES,
391
+ otherLabel: string = otherSeriesLabel(),
392
+ ): AggregatedSeries {
393
+ const totals = categories.map((name) => ({
394
+ name,
395
+ value: data.reduce((sum, row) => sum + (toChartNumber(row[name]) ?? 0), 0),
396
+ }))
397
+ const { top, rest, other } = aggregateTopN(totals, n, otherLabel)
398
+ if (!other) return { data: [...data], categories: [...categories], otherCategory: null }
399
+ const folded = rest.map((item) => item.name)
400
+ return {
401
+ data: data.map((row) => {
402
+ let sum: number | null = null
403
+ for (const name of folded) {
404
+ const v = toChartNumber(row[name])
405
+ if (v !== null) sum = (sum ?? 0) + v
406
+ }
407
+ return { ...row, [other.name]: sum }
408
+ }),
409
+ categories: [...top.map((item) => item.name), other.name],
410
+ otherCategory: other.name,
411
+ }
412
+ }
413
+
414
+ /**
415
+ * `aggregateSeries` that never folds `keep` (a comparison series) into「その他」: the others are capped
416
+ * at `n` as usual and `keep` is appended last, so it is drawn on top of the cap and never takes the first slot.
417
+ */
418
+ function aggregateSeriesKeeping(
419
+ data: readonly Record<string, unknown>[],
420
+ categories: readonly string[],
421
+ keep: string | undefined,
422
+ n: number = MAX_CHART_SERIES,
423
+ otherLabel: string = otherSeriesLabel(),
424
+ ): AggregatedSeries {
425
+ if (keep === undefined || !categories.includes(keep)) return aggregateSeries(data, categories, n, otherLabel)
426
+ const aggregated = aggregateSeries(
427
+ data,
428
+ categories.filter((c) => c !== keep),
429
+ n,
430
+ otherLabel,
431
+ )
432
+ return { ...aggregated, categories: [...aggregated.categories, keep] }
433
+ }
434
+
435
+ /**
436
+ * `seriesColorsFor` for a chart with a comparison series: the comparison takes no `--chart-*` token (the
437
+ * builder paints it in muted grey; its slot here is `""`), and the others are assigned as if it were absent,
438
+ * so a main series keeps its colour whether or not a comparison is drawn.
439
+ */
440
+ function seriesColorsWithComparison(
441
+ categories: readonly string[],
442
+ colors: ChartColors | undefined,
443
+ otherColor: string,
444
+ otherCategory: string | null,
445
+ allCategories: readonly string[],
446
+ comparison: string | undefined,
447
+ ): string[] {
448
+ if (comparison === undefined || !categories.includes(comparison)) {
449
+ return seriesColorsFor(categories, colors, otherColor, otherCategory, allCategories)
450
+ }
451
+ const main = categories.filter((c) => c !== comparison)
452
+ const mainColors = seriesColorsFor(
453
+ main,
454
+ colors,
455
+ otherColor,
456
+ otherCategory,
457
+ allCategories.filter((c) => c !== comparison),
458
+ )
459
+ return categories.map((c) => (c === comparison ? "" : (mainColors[main.indexOf(c)] ?? "")))
460
+ }
461
+
462
+ /**
463
+ * Colour per drawn series: the record's token for that category, else the
464
+ * array's token at the category's position in `allCategories` (cycled), else
465
+ * the token palette by drawn position. `otherCategory` — and a category the
466
+ * data itself names「その他」/ "Other" (`OTHER_SERIES_LABELS`) — always gets `otherColor`.
467
+ */
468
+ function seriesColorsFor(
469
+ categories: readonly string[],
470
+ colors: ChartColors | undefined,
471
+ otherColor: string,
472
+ otherCategory: string | null = null,
473
+ allCategories: readonly string[] = categories,
474
+ ): string[] {
475
+ const list = Array.isArray(colors) ? (colors as ChartSeriesColor[]) : undefined
476
+ const record = !Array.isArray(colors) && colors ? (colors as Partial<Record<string, ChartSeriesColor>>) : undefined
477
+ return categories.map((category, i) => {
478
+ if ((otherCategory !== null && category === otherCategory) || isOtherName(category)) return otherColor
479
+ const fromRecord = record?.[category]
480
+ if (fromRecord) return fromRecord
481
+ if (list && list.length > 0) {
482
+ const at = allCategories.indexOf(category)
483
+ return list[(at === -1 ? i : at) % list.length]!
484
+ }
485
+ return DEFAULT_CHART_COLORS[i % DEFAULT_CHART_COLORS.length]!
486
+ })
487
+ }
488
+
489
+ /* ------------------------------------------------------------------ Donut */
490
+
491
+ /** One drawn donut slice, largest first. */
492
+ interface DonutSlice {
493
+ name: string
494
+ /** Negative and missing values count as 0. */
495
+ value: number
496
+ /** A chart token (`"chart-1"`…), or `otherColor` for the folded slice. */
497
+ color: string
498
+ /** The folded「その他」slice. */
499
+ isOther: boolean
500
+ /** The input row, or a synthesized `{ [index]: "その他", [value]: sum }` for the folded slice. */
501
+ row: Record<string, unknown>
502
+ }
503
+
504
+ interface DonutSlicesConfig {
505
+ /** Label column. */
506
+ index: string
507
+ /** Value column. */
508
+ value: string
509
+ /** Slice colours by rank (cycled). Default: the token palette in order. */
510
+ colors?: readonly ChartSeriesColor[]
511
+ /** How many slices are drawn individually; the rest fold into「その他」. Default 5. */
512
+ maxSlices?: number
513
+ /** Colour of the folded slice (pass `CHART_OTHER_COLOR`). */
514
+ otherColor: string
515
+ otherLabel?: string
516
+ }
517
+
518
+ /**
519
+ * Donut slices: sorted by value (largest first, ties keep input order), the
520
+ * `maxSlices` largest kept and coloured by rank in fixed token order, the rest
521
+ * summed into one「その他」slice in `otherColor`.
522
+ */
523
+ function donutSlices(
524
+ data: readonly Record<string, unknown>[],
525
+ { index, value, colors, maxSlices = MAX_CHART_SERIES, otherColor, otherLabel = otherSeriesLabel() }: DonutSlicesConfig,
526
+ ): DonutSlice[] {
527
+ const items = data
528
+ .map((row, i) => {
529
+ const n = toChartNumber(row[value])
530
+ return { name: String(row[index] ?? ""), value: n !== null && n > 0 ? n : 0, row, i }
531
+ })
532
+ .sort((a, b) => b.value - a.value || a.i - b.i)
533
+ const { top, other } = aggregateTopN(items, Math.max(1, maxSlices), otherLabel)
534
+ const palette = colors && colors.length > 0 ? colors : DEFAULT_CHART_COLORS
535
+ const slices: DonutSlice[] = top.map((item, rank) => ({
536
+ name: item.name,
537
+ value: item.value,
538
+ // A row the data itself names「その他」/ "Other" is the same remainder: grey, like the folded slice.
539
+ color: isOtherName(item.name) ? otherColor : palette[rank % palette.length]!,
540
+ isOther: false,
541
+ row: item.row,
542
+ }))
543
+ if (other) {
544
+ slices.push({
545
+ name: other.name,
546
+ value: other.value,
547
+ color: otherColor,
548
+ isOther: true,
549
+ row: { [index]: other.name, [value]: other.value },
550
+ })
551
+ }
552
+ return slices
553
+ }
554
+
555
+ /* ---------------------------------------------------------------- BarList */
556
+
557
+ type BarListSortOrder = "ascending" | "descending" | "none"
558
+
559
+ /** Sort a copy of the rows by value; `"none"` keeps the given order. */
560
+ function sortBarListData<T extends { value: number }>(data: readonly T[], sortOrder: BarListSortOrder): T[] {
561
+ const rows = [...data]
562
+ if (sortOrder === "ascending") rows.sort((a, b) => a.value - b.value)
563
+ else if (sortOrder === "descending") rows.sort((a, b) => b.value - a.value)
564
+ return rows
565
+ }
566
+
567
+ /** BarList-only settings. */
568
+ interface BarListOptions {
569
+ /** 並べ順。既定 `"descending"`(大きい順)。`"none"` は渡した順。「その他」は常に最後。 */
570
+ sortOrder?: BarListSortOrder
571
+ /** 個別に出す行の数。超えた分は合計して「その他」の 1 行にまとめる。既定 5。 */
572
+ maxItems?: number
573
+ /** まとめた行のラベル。既定「その他」。 */
574
+ otherLabel?: string
575
+ /** 順位に入れず、常に「その他」へ足す行の名前。例 `["(not set)", "Unassigned"]`。 */
576
+ exclude?: readonly string[]
577
+ /** 値の横に構成比(「その他」も含めた全行の合計に対する割合。整数 %)を添える。例「¥8,240万 · 43%」。既定 `false`。 */
578
+ showShare?: boolean
579
+ }
580
+
581
+ /** One drawn BarList row. */
582
+ interface BarListRow<Row = Record<string, unknown>> {
583
+ /** React key: the row's `key`, else its name (`"__other"` for the folded row). */
584
+ key: string
585
+ name: string
586
+ value: number
587
+ /** Only for real rows; the folded row never links. */
588
+ href?: string
589
+ /** Legacy per-row colour (`BarListItem.color`). */
590
+ color?: ChartColor
591
+ /** The folded「その他」row. */
592
+ isOther: boolean
593
+ /** The input row (`null` for the folded row). */
594
+ row: Row | null
595
+ }
596
+
597
+ interface BarListRowsConfig extends BarListOptions {
598
+ /** Name column. Default `"name"`. */
599
+ index?: string
600
+ /** Value column. Default `"value"`. */
601
+ category?: string
602
+ }
603
+
604
+ /**
605
+ * The rows a BarList draws: read name / value (numeric strings count, gaps are
606
+ * 0), keep the `maxItems` largest (via `aggregateTopN`), sort them, and append
607
+ * the folded remainder as one「その他」row. Rows named in `exclude` skip the
608
+ * ranking and are always added to「その他」.
609
+ */
610
+ function barListRows<Row extends object>(
611
+ data: readonly Row[],
612
+ { index = "name", category = "value", sortOrder = "descending", maxItems = MAX_CHART_SERIES, otherLabel = otherSeriesLabel(), exclude }: BarListRowsConfig = {},
613
+ ): BarListRow<Row>[] {
614
+ const items = data.map((row): BarListRow<Row> => {
615
+ const cells = row as Record<string, unknown>
616
+ const name = String(cells[index] ?? "")
617
+ return {
618
+ key: typeof cells.key === "string" ? cells.key : name,
619
+ name,
620
+ value: toChartNumber(cells[category]) ?? 0,
621
+ href: typeof cells.href === "string" ? cells.href : undefined,
622
+ color: typeof cells.color === "string" ? cells.color : undefined,
623
+ isOther: false,
624
+ row,
625
+ }
626
+ })
627
+ const excluded = new Set(exclude ?? [])
628
+ const ranked = excluded.size > 0 ? items.filter((item) => !excluded.has(item.name)) : items
629
+ const outside = excluded.size > 0 ? items.filter((item) => excluded.has(item.name)) : []
630
+ const { top, other } = aggregateTopN(ranked, Math.max(0, maxItems), otherLabel)
631
+ const rows = sortBarListData(top, sortOrder)
632
+ if (other || outside.length > 0) {
633
+ const value = (other?.value ?? 0) + outside.reduce((sum, item) => sum + item.value, 0)
634
+ rows.push({ key: "__other", name: otherLabel, value, isOther: true, row: null })
635
+ }
636
+ return rows
637
+ }
638
+
639
+ /** Bar widths in percent of the largest value (at least a sliver for non-zero values). */
640
+ function barListWidths(values: readonly number[]): number[] {
641
+ const max = Math.max(0, ...values)
642
+ if (max === 0) return values.map(() => 0)
643
+ return values.map((v) => (v <= 0 ? 0 : Math.max(1, (v / max) * 100)))
644
+ }
645
+
646
+ /**
647
+ * How strongly the BarList bars are painted: every row the same tint of the bar
648
+ * colour (rank is the bar's length, not its weight). A tint over transparent, so
649
+ * it sits on the card in light and dark; it must stay visible against the card
650
+ * while the label printed over the bar keeps its contrast (see `tests/contrast.test.ts`).
651
+ */
652
+ const BAR_LIST_TINT = 45
653
+ /** 「その他」: a tint of the other colour, so it is the palest fill in the list (light and dark). */
654
+ const BAR_LIST_OTHER_TINT = 30
655
+
656
+ /**
657
+ * The fill of each BarList row: all real rows in the same tint of `color`
658
+ * (`BAR_LIST_TINT`), the folded「その他」row (and a row the data names「その他」/ "Other") in a tint of `otherColor`
659
+ * (`BAR_LIST_OTHER_TINT`) — the palest fill, a remainder never outweighs a
660
+ * ranked row. A legacy per-row `color` (or a threshold tone) replaces `color`
661
+ * for that row. A tint, not the solid token, so the label printed over the bar
662
+ * keeps its contrast.
663
+ */
664
+ function barListFills(
665
+ rows: readonly (Pick<BarListRow, "isOther" | "color"> & { name?: string })[],
666
+ color: ChartColor,
667
+ otherColor: string,
668
+ ): string[] {
669
+ return rows.map((row) =>
670
+ row.isOther || isOtherName(row.name)
671
+ ? tintCss(otherColor, BAR_LIST_OTHER_TINT)
672
+ : tintCss(chartColorToCss(row.color ?? color), BAR_LIST_TINT),
673
+ )
674
+ }
675
+
676
+ /** A row's share of `total` as text: whole percent (fixed, no decimals), `<1%` for a sliver, `0%` for nothing. */
677
+ function barListShareText(value: number, total: number): string {
678
+ const v = Number.isFinite(value) && value > 0 ? value : 0
679
+ if (total <= 0 || v === 0) return "0%"
680
+ const pct = (v / total) * 100
681
+ return pct < 1 ? "<1%" : `${Math.round(pct)}%`
682
+ }
683
+
684
+ /**
685
+ * The text at the end of each BarList row: the formatted value and, with
686
+ * `showShare`, its share of the total of all drawn rows (including「その他」,
687
+ * so the shares are of the whole list): `value` and `share` apart (the share is
688
+ * drawn muted), `text` as one string (「¥8,240万 · 43%」).
689
+ */
690
+ function barListValueTexts(
691
+ values: readonly number[],
692
+ formatter: ValueFormatter,
693
+ showShare = false,
694
+ ): { value: string; share?: string; text: string }[] {
695
+ const total = values.reduce((sum, v) => sum + (Number.isFinite(v) && v > 0 ? v : 0), 0)
696
+ return values.map((v) => {
697
+ const value = formatter(v)
698
+ if (!showShare) return { value, text: value }
699
+ const share = barListShareText(v, total)
700
+ return { value, share, text: `${value} · ${share}` }
701
+ })
702
+ }
703
+
704
+ /* -------------------------------------------------------------- DataTable */
705
+
706
+ /** The visually-hidden table `ChartFrame` renders next to the plot (`dataTable`). */
707
+ interface ChartDataTable {
708
+ /** 表の見出し(`<caption>`)。 */
709
+ caption?: string
710
+ /** 列見出し。先頭がラベル列。 */
711
+ columns: string[]
712
+ /** 行。セルは書式済みの文字列。 */
713
+ rows: string[][]
714
+ }
715
+
716
+ /**
717
+ * The chart's numbers as a table, for screen readers: one row per data row, the
718
+ * `index` cell then each category through `formatter` (gaps → `—`). `labels`
719
+ * renames column keys for the header (`{ sessions: "セッション" }`); `indexName` is the first column's header when `labels` has none for `index` (e.g. 「項目」, instead of the raw key).
720
+ */
721
+ function chartDataTable(
722
+ data: readonly Record<string, unknown>[],
723
+ index: string,
724
+ categories: readonly string[],
725
+ formatter: ValueFormatter,
726
+ labels?: Readonly<Record<string, string>>,
727
+ indexName?: string,
728
+ ): ChartDataTable {
729
+ const label = (key: string) => labels?.[key] ?? key
730
+ return {
731
+ columns: [labels?.[index] ?? indexName ?? index, ...categories.map(label)],
732
+ rows: data.map((row) => [
733
+ String(row[index] ?? ""),
734
+ ...categories.map((key) => {
735
+ const n = toChartNumber(row[key])
736
+ return n === null ? EMPTY_VALUE : formatter(n)
737
+ }),
738
+ ]),
739
+ }
740
+ }
741
+
742
+ /* ------------------------------------------------------------ CategoryBar */
743
+
744
+ interface CategoryBarSegment {
745
+ /** Width in percent of the whole bar. */
746
+ width: number
747
+ /** Where the segment starts, in percent. */
748
+ start: number
749
+ /** The running total at the segment's end — what its right-hand label shows. */
750
+ end: number
751
+ }
752
+
753
+ /** Lay the values side by side; negative values count as zero. */
754
+ function categoryBarSegments(values: readonly number[]): CategoryBarSegment[] {
755
+ const clean = values.map((v) => (Number.isFinite(v) && v > 0 ? v : 0))
756
+ const total = clean.reduce((sum, v) => sum + v, 0)
757
+ let running = 0
758
+ return clean.map((v) => {
759
+ const start = total === 0 ? 0 : (running / total) * 100
760
+ running += v
761
+ return { width: total === 0 ? 0 : (v / total) * 100, start, end: running }
762
+ })
763
+ }
764
+
765
+ interface CategoryBarLabel {
766
+ /** Position in percent of the bar. */
767
+ position: number
768
+ /** The running total printed there. */
769
+ value: number
770
+ }
771
+
772
+ /**
773
+ * Tick labels under the bar: `0` at the start, then the running total at each
774
+ * segment's end. A label closer than `minGap` percent to the one before is
775
+ * dropped so narrow segments don't print on top of each other — except the
776
+ * last one (the total), which replaces its neighbour instead. With a
777
+ * `markerPosition`, an inner label closer than `minGap` to the marker is dropped
778
+ * too — the marker sits right under it and the two read as one crowded spot.
779
+ */
780
+ function categoryBarLabels(values: readonly number[], minGap = 8, markerPosition?: number): CategoryBarLabel[] {
781
+ const segments = categoryBarSegments(values).filter((s) => s.width > 0)
782
+ if (segments.length === 0) return []
783
+ const labels: CategoryBarLabel[] = [{ position: 0, value: 0 }]
784
+ segments.forEach((s, i) => {
785
+ const label = { position: s.start + s.width, value: s.end }
786
+ const prev = labels[labels.length - 1]!
787
+ if (label.position - prev.position >= minGap) labels.push(label)
788
+ else if (i === segments.length - 1 && labels.length > 1) labels[labels.length - 1] = label
789
+ })
790
+ if (markerPosition === undefined || !Number.isFinite(markerPosition)) return labels
791
+ return labels.filter(
792
+ (label, i) => i === 0 || i === labels.length - 1 || Math.abs(label.position - markerPosition) >= minGap,
793
+ )
794
+ }
795
+
796
+ /**
797
+ * `labels` thinned to what fits side by side on a bar `width` px wide, given each label's printed text
798
+ * (`texts`, same order): a label that would touch the one before is dropped — except the last (the
799
+ * total), which replaces its neighbour instead. The first sits at the left edge, the last at the right
800
+ * edge, the rest centred on their position. The width is a rough estimate (full-width characters 12 px,
801
+ * the rest 7 px at 12 px type).
802
+ */
803
+ function categoryBarFitLabels(
804
+ labels: readonly CategoryBarLabel[],
805
+ texts: readonly string[],
806
+ width: number,
807
+ gap = 8,
808
+ ): CategoryBarLabel[] {
809
+ const textWidth = (text: string) => {
810
+ let w = 0
811
+ for (const ch of text) w += /[\u3000-\u9fff\uff00-\uffef]/.test(ch) ? 12 : 7
812
+ return w
813
+ }
814
+ const extent = (label: CategoryBarLabel, text: string): [number, number] => {
815
+ const w = textWidth(text)
816
+ if (label.position <= 0) return [0, w]
817
+ if (label.position >= 100) return [width - w, width]
818
+ const center = (label.position / 100) * width
819
+ return [center - w / 2, center + w / 2]
820
+ }
821
+ const kept: { label: CategoryBarLabel; extent: [number, number] }[] = []
822
+ labels.forEach((label, i) => {
823
+ const here = extent(label, texts[i] ?? "")
824
+ const touches = () => kept.length > 0 && kept[kept.length - 1]!.extent[1] + gap > here[0]
825
+ if (i === labels.length - 1) while (kept.length > 1 && touches()) kept.pop()
826
+ else if (touches()) return
827
+ kept.push({ label, extent: here })
828
+ })
829
+ return kept.map((k) => k.label)
830
+ }
831
+
832
+ /** Marker position in percent of the bar, clamped to its ends. */
833
+ function categoryBarMarkerPosition(value: number, values: readonly number[]): number {
834
+ const total = values.reduce((sum, v) => sum + (Number.isFinite(v) && v > 0 ? v : 0), 0)
835
+ if (total === 0) return 0
836
+ return clamp((value / total) * 100, 0, 100)
837
+ }
838
+
839
+ /** Index of the segment the marker sits on (the last one for a value past the end). */
840
+ function categoryBarMarkerSegment(value: number, values: readonly number[]): number {
841
+ const segments = categoryBarSegments(values)
842
+ const index = segments.findIndex((s) => s.width > 0 && value <= s.end)
843
+ if (index !== -1) return index
844
+ for (let i = segments.length - 1; i >= 0; i--) if (segments[i]!.width > 0) return i
845
+ return 0
846
+ }
847
+
848
+ /* --------------------------------------------------------- ProgressCircle */
849
+
850
+ interface ProgressCircleGeometry {
851
+ /** SVG width/height. */
852
+ size: number
853
+ /** Radius of the stroke's centre line. */
854
+ normalizedRadius: number
855
+ circumference: number
856
+ /** `stroke-dashoffset` for the value arc. */
857
+ offset: number
858
+ /** The value as a fraction of `max`, clamped to `[0, 1]`. */
859
+ ratio: number
860
+ }
861
+
862
+ function progressCircleGeometry(
863
+ value: number,
864
+ max: number,
865
+ radius: number,
866
+ strokeWidth: number,
867
+ ): ProgressCircleGeometry {
868
+ const ratio = max > 0 && Number.isFinite(value) ? clamp(value / max, 0, 1) : 0
869
+ const normalizedRadius = Math.max(0, radius - strokeWidth / 2)
870
+ const circumference = 2 * Math.PI * normalizedRadius
871
+ return { size: radius * 2, normalizedRadius, circumference, offset: circumference * (1 - ratio), ratio }
872
+ }
873
+
874
+ /* ---------------------------------------------------------------- summary */
875
+
876
+ interface ChartSummaryInput {
877
+ data: readonly Record<string, unknown>[]
878
+ /** The x-axis key. */
879
+ index: string
880
+ /** Series keys; the first one is described. */
881
+ categories: readonly string[]
882
+ /** Title of the chart, put in front when given. */
883
+ title?: string
884
+ /** Same as the chart's `format` (default `"compact"`). */
885
+ format?: ValueFormat
886
+ /** Wins over `format`. */
887
+ valueFormatter?: ValueFormatter
888
+ /** Language of the sentence. Default the page's locale (`<html lang>`). */
889
+ locale?: string
890
+ }
891
+
892
+ const SUMMARY_TEXT = {
893
+ ja: {
894
+ up: "、前の点より増加",
895
+ down: "、前の点より減少",
896
+ flat: "、前の点と横ばい",
897
+ latest: (label: string, value: string) => `最新 ${label} は ${value}`,
898
+ top: (name: string, share: string) => `最大は ${name}(${share})`,
899
+ },
900
+ en: {
901
+ up: ", up from the previous point",
902
+ down: ", down from the previous point",
903
+ flat: ", flat from the previous point",
904
+ latest: (label: string, value: string) => `Latest ${label}: ${value}`,
905
+ top: (name: string, share: string) => `Largest: ${name} (${share})`,
906
+ },
907
+ }
908
+
909
+ /**
910
+ * One-sentence summary built from the rows, for `summary="auto"`:
911
+ * 「<title>: 最新 <index> は <値>、前の点より増加/減少/横ばい」("<title>: Latest <index>: <value>, up from the previous point"). The direction is
912
+ * computed from the last two non-empty points of the first series — never
913
+ * written by hand, so it cannot contradict the data. `undefined` when there is
914
+ * no usable point.
915
+ */
916
+ function buildChartSummary(input: ChartSummaryInput): string | undefined {
917
+ const key = input.categories[0]
918
+ if (key === undefined) return undefined
919
+ const points: { label: string; value: number }[] = []
920
+ for (const row of input.data) {
921
+ const raw = row[key]
922
+ const value = raw === null || raw === undefined || raw === "" ? NaN : Number(raw)
923
+ if (Number.isFinite(value)) points.push({ label: String(row[input.index] ?? ""), value })
924
+ }
925
+ const latest = points[points.length - 1]
926
+ if (!latest) return undefined
927
+ const locale = resolveLocale(input.locale)
928
+ const t = SUMMARY_TEXT[uiLanguage(locale)]
929
+ const text = input.valueFormatter ?? toValueFormatter(input.format ?? "compact", locale)
930
+ const prev = points[points.length - 2]
931
+ const direction = !prev ? "" : latest.value > prev.value ? t.up : latest.value < prev.value ? t.down : t.flat
932
+ const head = input.title ? `${input.title}: ` : ""
933
+ return `${head}${t.latest(latest.label, text(latest.value))}${direction}`
934
+ }
935
+
936
+ /**
937
+ * `summary="auto"` for a donut: 「<title>: 最大は <名前>(<構成比>)」("<title>: Largest: <name> (<share>)") from the slices
938
+ * (largest first). `undefined` when there is nothing to describe. `locale` picks the language; default the page's.
939
+ */
940
+ function buildShareSummary(
941
+ slices: readonly { name: string; value: number }[],
942
+ title?: string,
943
+ locale?: string,
944
+ ): string | undefined {
945
+ const total = slices.reduce((sum, s) => sum + s.value, 0)
946
+ const top = slices[0]
947
+ if (!top || total <= 0) return undefined
948
+ const share = `${Math.round((top.value / total) * 1000) / 10}%`
949
+ return `${title ? `${title}: ` : ""}${SUMMARY_TEXT[uiLanguage(resolveLocale(locale))].top(top.name, share)}`
950
+ }
951
+
952
+ /* ---------- end of inlined code ---------- */
953
+
954
+ export interface TrackerBlock {
955
+ /** React の key。省略時は位置。 */
956
+ key?: string | number
957
+ /** ブロックの色。`"positive"` / `"negative"` / `"warning"` / `"info"`(面用の `--<tone>-fill`)、`"chart-1"`〜`"chart-5"`、CSS カラー。省略時は `defaultColor`。 */
958
+ color?: ChartColor
959
+ /** ホバーで出す説明。日付と状態・件数を入れる(例: `"10/12 失敗 3 件"`)。ブロックの accessible name にもなる。 */
960
+ tooltip?: string
961
+ }
962
+
963
+ export interface TrackerProps extends Omit<ComponentProps<"div">, "children"> {
964
+ data: TrackerBlock[]
965
+ /** `color` の無いブロックの色。既定は muted-foreground を淡くした灰色。 */
966
+ defaultColor?: ChartColor
967
+ /** ホバー中のブロックを薄くする。既定 `true`。 */
968
+ hoverEffect?: boolean
969
+ }
970
+
971
+ const DEFAULT_BLOCK_COLOR = "color-mix(in oklab, var(--muted-foreground) 35%, transparent)"
972
+
973
+ /** A block colour as CSS: the meaning names are the area (`-fill`) tokens, anything else as for the other charts. */
974
+ function blockColorToCss(color: ChartColor): string {
975
+ return chartFillToCss(color)
976
+ }
977
+
978
+ /** Rows not given yet (a draft fills props in steps): draw the empty state, keep the same array between renders. */
979
+ const NO_ROWS: never[] = []
980
+
981
+ export const Tracker = forwardRef<HTMLDivElement, TrackerProps>(function Tracker(
982
+ { data = NO_ROWS, defaultColor, hoverEffect = true, className, ...props },
983
+ ref,
984
+ ) {
985
+ const containerRef = useRef<HTMLDivElement>(null)
986
+ const setRef = useCallback((node: HTMLDivElement | null) => {
987
+ containerRef.current = node
988
+ if (typeof ref === "function") return ref(node)
989
+ if (ref) ref.current = node
990
+ }, [ref])
991
+ const fallback = defaultColor ? blockColorToCss(defaultColor) : DEFAULT_BLOCK_COLOR
992
+ return (
993
+ <div ref={setRef} data-slot="tracker" className={cn("flex h-6 w-full gap-0.5", className)} {...props}>
994
+ {data.map((block, i) => {
995
+ const blockClass = cn(
996
+ "h-full min-w-0 flex-1 rounded-[2px]",
997
+ hoverEffect && "transition-opacity hover:opacity-60 motion-reduce:transition-none",
998
+ )
999
+ const style = { background: block.color ? blockColorToCss(block.color) : fallback }
1000
+ return block.tooltip ? (
1001
+ <Tooltip key={block.key ?? i}>
1002
+ <TooltipTrigger
1003
+ delay={0}
1004
+ render={<div data-slot="tracker-block" role="img" tabIndex={0} aria-label={block.tooltip} className={blockClass} style={style} />}
1005
+ />
1006
+ <TooltipContent container={containerRef}>{block.tooltip}</TooltipContent>
1007
+ </Tooltip>
1008
+ ) : (
1009
+ <div key={block.key ?? i} data-slot="tracker-block" className={blockClass} style={style} />
1010
+ )
1011
+ })}
1012
+ </div>
1013
+ )
1014
+ })
1015
+ Tracker.displayName = "Tracker"