@squadbase/vantage 0.6.2-dev1.42c4e48 → 0.6.2-dev1.51e401a

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 (295) hide show
  1. package/dist/{build-MFWRPYKW.js → build-U7GO26HR.js} +7 -7
  2. package/dist/{build-MFWRPYKW.js.map → build-U7GO26HR.js.map} +1 -1
  3. package/dist/{check-ZBIH422T.js → check-MRVAIHG5.js} +5 -5
  4. package/dist/{check-ZBIH422T.js.map → check-MRVAIHG5.js.map} +1 -1
  5. package/dist/chunk-2IAPIOPS.js +152 -0
  6. package/dist/chunk-2IAPIOPS.js.map +1 -0
  7. package/dist/chunk-3RJEOP3J.js +174 -0
  8. package/dist/chunk-3RJEOP3J.js.map +1 -0
  9. package/dist/chunk-77CISBMG.js +7581 -0
  10. package/dist/chunk-77CISBMG.js.map +1 -0
  11. package/dist/{chunk-V3LF7BE7.js → chunk-ANZLVSEP.js} +4 -5
  12. package/dist/chunk-ANZLVSEP.js.map +1 -0
  13. package/dist/{chunk-XQUSGIDG.js → chunk-CKWPK4RO.js} +10 -3
  14. package/dist/chunk-CKWPK4RO.js.map +1 -0
  15. package/dist/chunk-EG4PX726.js +678 -0
  16. package/dist/chunk-EG4PX726.js.map +1 -0
  17. package/dist/chunk-NZ5QIIG4.js +74 -0
  18. package/dist/chunk-NZ5QIIG4.js.map +1 -0
  19. package/dist/{chunk-7DZGJQ3P.js → chunk-PJ4SPXHS.js} +23 -6
  20. package/dist/chunk-PJ4SPXHS.js.map +1 -0
  21. package/dist/{chunk-OB6UBJXF.js → chunk-QNOX7WLZ.js} +127 -36
  22. package/dist/chunk-QNOX7WLZ.js.map +1 -0
  23. package/dist/{chunk-PXRX5PEC.js → chunk-ROHNXP7J.js} +73 -4
  24. package/dist/chunk-ROHNXP7J.js.map +1 -0
  25. package/dist/{chunk-CEXAQQ5W.js → chunk-S5MDTHH7.js} +180 -18
  26. package/dist/chunk-S5MDTHH7.js.map +1 -0
  27. package/dist/{chunk-IBGOCWJB.js → chunk-SDJTTMLK.js} +247 -86
  28. package/dist/chunk-SDJTTMLK.js.map +1 -0
  29. package/dist/{chunk-QEWCYW3I.js → chunk-SHZM3EXB.js} +29 -8
  30. package/dist/chunk-SHZM3EXB.js.map +1 -0
  31. package/dist/chunk-TRMHNMMZ.js +61 -0
  32. package/dist/chunk-TRMHNMMZ.js.map +1 -0
  33. package/dist/{chunk-A2UUGASH.js → chunk-U736PVHY.js} +2 -2
  34. package/dist/chunk-U736PVHY.js.map +1 -0
  35. package/dist/{chunk-JKLLFVEU.js → chunk-UWSQUHX6.js} +4 -99
  36. package/dist/chunk-UWSQUHX6.js.map +1 -0
  37. package/dist/cli.js +6 -6
  38. package/dist/client/index.d.ts +2 -0
  39. package/dist/client/index.js +8 -2
  40. package/dist/client/index.js.map +1 -1
  41. package/dist/components/index.d.ts +1617 -101
  42. package/dist/components/index.js +7 -4
  43. package/dist/delta-text-CbrOaW83.d.ts +17 -0
  44. package/dist/{dev-DCTOHQ6W.js → dev-O42JFQ64.js} +7 -7
  45. package/dist/{dev-DCTOHQ6W.js.map → dev-O42JFQ64.js.map} +1 -1
  46. package/dist/doc/index.d.ts +215 -2
  47. package/dist/doc/index.js +423 -5
  48. package/dist/doc/index.js.map +1 -1
  49. package/dist/{doctor-5E2VEZPK.js → doctor-YD3XAAOT.js} +5 -5
  50. package/dist/{doctor-5E2VEZPK.js.map → doctor-YD3XAAOT.js.map} +1 -1
  51. package/dist/format-DihQkL1N.d.ts +249 -0
  52. package/dist/markdown/index.js +1 -1
  53. package/dist/markdown/index.js.map +1 -1
  54. package/dist/query/index.js +2 -2
  55. package/dist/{routes-3SGAFDMC.js → routes-PVKNT777.js} +4 -4
  56. package/dist/{routes-3SGAFDMC.js.map → routes-PVKNT777.js.map} +1 -1
  57. package/dist/slide/index.d.ts +272 -1
  58. package/dist/slide/index.js +1025 -4
  59. package/dist/slide/index.js.map +1 -1
  60. package/dist/table/index.js +11 -8
  61. package/dist/table/index.js.map +1 -1
  62. package/dist/ui/index.d.ts +8 -2
  63. package/dist/ui/index.js +22 -112
  64. package/dist/ui/index.js.map +1 -1
  65. package/dist/{upgrade-DBBE6GIR.js → upgrade-6DT7ADRP.js} +4 -4
  66. package/dist/{upgrade-DBBE6GIR.js.map → upgrade-6DT7ADRP.js.map} +1 -1
  67. package/dist/vite/index.js +3 -3
  68. package/docs/en/agent-skills.md +1 -1
  69. package/docs/en/changelog.md +2 -0
  70. package/docs/en/components.md +42 -17
  71. package/docs/en/doc/delta-text.md +40 -0
  72. package/docs/en/doc/doc-action-items.md +49 -0
  73. package/docs/en/doc/doc-callout.md +38 -0
  74. package/docs/en/doc/doc-data-table.md +60 -0
  75. package/docs/en/doc/doc-executive-summary.md +64 -0
  76. package/docs/en/doc/doc-figure.md +56 -0
  77. package/docs/en/doc/doc-key-findings.md +61 -0
  78. package/docs/en/doc/doc-kpi-scorecard.md +80 -0
  79. package/docs/en/doc/doc-notes-and-sources.md +43 -0
  80. package/docs/en/doc/doc-report-header.md +46 -0
  81. package/docs/en/pages-and-metadata.md +15 -0
  82. package/docs/en/parts/area-chart.md +99 -0
  83. package/docs/en/parts/bar-chart.md +91 -0
  84. package/docs/en/parts/bar-list.md +50 -0
  85. package/docs/en/parts/category-bar.md +37 -0
  86. package/docs/en/parts/chart-frame.md +39 -0
  87. package/docs/en/parts/data-table.md +22 -0
  88. package/docs/en/parts/delta.md +51 -0
  89. package/docs/en/parts/donut-chart.md +72 -0
  90. package/docs/en/parts/format.md +43 -0
  91. package/docs/en/parts/funnel-steps.md +2 -1
  92. package/docs/en/parts/heatmap.md +53 -0
  93. package/docs/en/parts/kpi-card.md +58 -0
  94. package/docs/en/parts/legend.md +35 -0
  95. package/docs/en/parts/line-chart.md +94 -0
  96. package/docs/en/parts/metric-value.md +3 -2
  97. package/docs/en/parts/progress-circle.md +33 -0
  98. package/docs/en/parts/sample-data.md +39 -0
  99. package/docs/en/parts/scatter-chart.md +56 -0
  100. package/docs/en/parts/sparkline.md +1 -1
  101. package/docs/en/parts/tracker.md +36 -0
  102. package/docs/en/parts/trend-indicator.md +17 -1
  103. package/docs/en/parts/updated-at.md +30 -0
  104. package/docs/en/parts/waterfall-chart.md +56 -0
  105. package/docs/en/slide/slide-chart-full.md +48 -0
  106. package/docs/en/slide/slide-chart-insight.md +52 -0
  107. package/docs/en/slide/slide-columns.md +46 -0
  108. package/docs/en/slide/slide-comparison.md +68 -0
  109. package/docs/en/slide/slide-cover.md +39 -0
  110. package/docs/en/slide/slide-exec-summary.md +47 -0
  111. package/docs/en/slide/slide-heading.md +38 -0
  112. package/docs/en/slide/slide-kpi-grid.md +55 -0
  113. package/docs/en/slide/slide-kpi-hero.md +58 -0
  114. package/docs/en/slide/slide-next-actions.md +49 -0
  115. package/docs/en/slide/slide-scorecard-table.md +54 -0
  116. package/docs/en/slide/slide-section.md +44 -0
  117. package/docs/en/slide/slide-source-line.md +34 -0
  118. package/docs/en/ui/alert-dialog.md +42 -0
  119. package/docs/en/ui/avatar.md +31 -0
  120. package/docs/en/ui/combobox.md +74 -0
  121. package/docs/en/ui/drawer.md +41 -0
  122. package/docs/en/ui/empty.md +1 -1
  123. package/docs/en/ui/error-state.md +4 -3
  124. package/docs/en/ui/field.md +42 -0
  125. package/docs/en/ui/hover-card.md +21 -0
  126. package/docs/en/ui/kbd.md +17 -0
  127. package/docs/en/ui/loading.md +1 -1
  128. package/docs/en/ui/pagination.md +36 -0
  129. package/docs/en/ui/radio-group.md +21 -0
  130. package/docs/en/ui/toast.md +44 -0
  131. package/docs/en/ui/toggle-group.md +4 -3
  132. package/docs/en/ui-and-theming.md +1 -1
  133. package/docs/index.json +917 -77
  134. package/docs/ja/agent-skills.md +1 -1
  135. package/docs/ja/changelog.md +2 -0
  136. package/docs/ja/components.md +39 -16
  137. package/docs/ja/doc/delta-text.md +40 -0
  138. package/docs/ja/doc/doc-action-items.md +49 -0
  139. package/docs/ja/doc/doc-callout.md +38 -0
  140. package/docs/ja/doc/doc-data-table.md +60 -0
  141. package/docs/ja/doc/doc-executive-summary.md +64 -0
  142. package/docs/ja/doc/doc-figure.md +56 -0
  143. package/docs/ja/doc/doc-key-findings.md +61 -0
  144. package/docs/ja/doc/doc-kpi-scorecard.md +80 -0
  145. package/docs/ja/doc/doc-notes-and-sources.md +43 -0
  146. package/docs/ja/doc/doc-report-header.md +46 -0
  147. package/docs/ja/page-types/slide.md +1 -0
  148. package/docs/ja/pages-and-metadata.md +15 -0
  149. package/docs/ja/parts/area-chart.md +49 -25
  150. package/docs/ja/parts/bar-chart.md +50 -24
  151. package/docs/ja/parts/bar-list.md +31 -8
  152. package/docs/ja/parts/chart-frame.md +36 -0
  153. package/docs/ja/parts/data-table.md +22 -0
  154. package/docs/ja/parts/delta.md +51 -0
  155. package/docs/ja/parts/donut-chart.md +45 -26
  156. package/docs/ja/parts/format.md +44 -0
  157. package/docs/ja/parts/funnel-steps.md +27 -8
  158. package/docs/ja/parts/heatmap.md +45 -0
  159. package/docs/ja/parts/kpi-card.md +56 -0
  160. package/docs/ja/parts/legend.md +36 -0
  161. package/docs/ja/parts/line-chart.md +48 -22
  162. package/docs/ja/parts/metric-value.md +3 -2
  163. package/docs/ja/parts/sample-data.md +61 -0
  164. package/docs/ja/parts/scatter-chart.md +69 -0
  165. package/docs/ja/parts/sparkline.md +1 -1
  166. package/docs/ja/parts/trend-indicator.md +17 -1
  167. package/docs/ja/parts/updated-at.md +27 -0
  168. package/docs/ja/parts/waterfall-chart.md +61 -0
  169. package/docs/ja/slide/slide-chart-full.md +48 -0
  170. package/docs/ja/slide/slide-chart-insight.md +52 -0
  171. package/docs/ja/slide/slide-columns.md +46 -0
  172. package/docs/ja/slide/slide-comparison.md +68 -0
  173. package/docs/ja/slide/slide-cover.md +39 -0
  174. package/docs/ja/slide/slide-exec-summary.md +47 -0
  175. package/docs/ja/slide/slide-heading.md +38 -0
  176. package/docs/ja/slide/slide-kpi-grid.md +55 -0
  177. package/docs/ja/slide/slide-kpi-hero.md +58 -0
  178. package/docs/ja/slide/slide-next-actions.md +49 -0
  179. package/docs/ja/slide/slide-scorecard-table.md +54 -0
  180. package/docs/ja/slide/slide-section.md +44 -0
  181. package/docs/ja/slide/slide-source-line.md +34 -0
  182. package/docs/ja/ui/empty.md +1 -1
  183. package/docs/ja/ui/error-state.md +4 -3
  184. package/docs/ja/ui/loading.md +1 -1
  185. package/docs/ja/ui/toggle-group.md +4 -3
  186. package/docs/ja/ui-and-theming.md +2 -2
  187. package/package.json +26 -24
  188. package/registry/ui/accordion.tsx +4 -2
  189. package/registry/ui/alert-dialog.tsx +3 -3
  190. package/registry/ui/alert.tsx +3 -1
  191. package/registry/ui/app-shell.tsx +145 -2
  192. package/registry/ui/area-chart.tsx +3111 -166
  193. package/registry/ui/attention-list.tsx +465 -0
  194. package/registry/ui/avatar.tsx +1 -1
  195. package/registry/ui/badge.tsx +3 -1
  196. package/registry/ui/bar-chart.tsx +3105 -164
  197. package/registry/ui/bar-list.tsx +3877 -181
  198. package/registry/ui/box-plot-chart.tsx +4214 -0
  199. package/registry/ui/breadcrumb.tsx +3 -1
  200. package/registry/ui/button.tsx +3 -1
  201. package/registry/ui/calendar.tsx +3 -1
  202. package/registry/ui/card.tsx +4 -2
  203. package/registry/ui/category-bar.tsx +1233 -16
  204. package/registry/ui/chart-frame.tsx +1604 -0
  205. package/registry/ui/checkbox.tsx +3 -1
  206. package/registry/ui/collapsible.tsx +3 -1
  207. package/registry/ui/combobox.tsx +2 -2
  208. package/registry/ui/command.tsx +3 -1
  209. package/registry/ui/dashboard-card.tsx +71 -28
  210. package/registry/ui/data-table.tsx +882 -68
  211. package/registry/ui/date-range-picker.tsx +400 -65
  212. package/registry/ui/delta.tsx +350 -0
  213. package/registry/ui/dialog.tsx +5 -3
  214. package/registry/ui/donut-chart.tsx +3184 -182
  215. package/registry/ui/drawer.tsx +1 -1
  216. package/registry/ui/dropdown-menu.tsx +5 -3
  217. package/registry/ui/echart.tsx +761 -69
  218. package/registry/ui/field.tsx +1 -1
  219. package/registry/ui/filter-bar.tsx +212 -26
  220. package/registry/ui/funnel-steps.tsx +3622 -53
  221. package/registry/ui/heatmap.tsx +2027 -0
  222. package/registry/ui/histogram-chart.tsx +4284 -0
  223. package/registry/ui/hover-card.tsx +2 -2
  224. package/registry/ui/input-group.tsx +3 -1
  225. package/registry/ui/input.tsx +3 -1
  226. package/registry/ui/kbd.tsx +3 -1
  227. package/registry/ui/kpi-card.tsx +905 -0
  228. package/registry/ui/label.tsx +3 -1
  229. package/registry/ui/legend.tsx +3817 -0
  230. package/registry/ui/line-chart.tsx +3109 -158
  231. package/registry/ui/metric-value.tsx +9 -1
  232. package/registry/ui/multi-select.tsx +170 -14
  233. package/registry/ui/page-shell.tsx +244 -51
  234. package/registry/ui/pagination.tsx +3 -1
  235. package/registry/ui/paired-chart.tsx +4086 -0
  236. package/registry/ui/placeholder.tsx +8 -2
  237. package/registry/ui/popover.tsx +4 -2
  238. package/registry/ui/progress-circle.tsx +773 -12
  239. package/registry/ui/progress.tsx +3 -1
  240. package/registry/ui/radio-group.tsx +1 -1
  241. package/registry/ui/sample-data.tsx +230 -0
  242. package/registry/ui/scatter-chart.tsx +4503 -0
  243. package/registry/ui/scroll-area.tsx +3 -2
  244. package/registry/ui/searchable-select.tsx +153 -10
  245. package/registry/ui/section-header.tsx +5 -3
  246. package/registry/ui/segmented-control.tsx +7 -2
  247. package/registry/ui/select.tsx +4 -2
  248. package/registry/ui/separator.tsx +3 -1
  249. package/registry/ui/sheet.tsx +4 -2
  250. package/registry/ui/sidebar.tsx +4 -2
  251. package/registry/ui/skeleton.tsx +4 -2
  252. package/registry/ui/slider.tsx +4 -2
  253. package/registry/ui/sparkline.tsx +84 -9
  254. package/registry/ui/spinner.tsx +3 -1
  255. package/registry/ui/states.tsx +194 -8
  256. package/registry/ui/status-badge.tsx +246 -39
  257. package/registry/ui/switch.tsx +3 -1
  258. package/registry/ui/table.tsx +4 -2
  259. package/registry/ui/tabs.tsx +5 -3
  260. package/registry/ui/textarea.tsx +3 -1
  261. package/registry/ui/toast.tsx +2 -2
  262. package/registry/ui/toggle-group.tsx +3 -1
  263. package/registry/ui/toggle.tsx +3 -1
  264. package/registry/ui/tooltip.tsx +10 -4
  265. package/registry/ui/tracker.tsx +798 -19
  266. package/registry/ui/trend-indicator.tsx +164 -9
  267. package/registry/ui/updated-at.tsx +276 -0
  268. package/registry/ui/waterfall-chart.tsx +4561 -0
  269. package/skills/vantage-add-feature/SKILL.md +5 -0
  270. package/skills/vantage-design/SKILL.md +60 -52
  271. package/skills/vantage-design/references/extract.md +26 -27
  272. package/skills/vantage-design/references/format.md +12 -172
  273. package/skills/vantage-design/references/presets.md +50 -110
  274. package/skills/vantage-pitfalls/SKILL.md +5 -0
  275. package/skills/vantage-slide/SKILL.md +54 -36
  276. package/templates/AGENTS.md +45 -16
  277. package/templates/agents/api.md +7 -0
  278. package/templates/agents/doc.md +48 -0
  279. package/templates/agents/page.md +69 -2
  280. package/templates/agents/slide.md +77 -3
  281. package/theme.css +247 -149
  282. package/dist/chunk-5ZOP4SQR.js +0 -47
  283. package/dist/chunk-5ZOP4SQR.js.map +0 -1
  284. package/dist/chunk-7DZGJQ3P.js.map +0 -1
  285. package/dist/chunk-A2UUGASH.js.map +0 -1
  286. package/dist/chunk-AG6RZ2RR.js +0 -3208
  287. package/dist/chunk-AG6RZ2RR.js.map +0 -1
  288. package/dist/chunk-CEXAQQ5W.js.map +0 -1
  289. package/dist/chunk-IBGOCWJB.js.map +0 -1
  290. package/dist/chunk-JKLLFVEU.js.map +0 -1
  291. package/dist/chunk-OB6UBJXF.js.map +0 -1
  292. package/dist/chunk-PXRX5PEC.js.map +0 -1
  293. package/dist/chunk-QEWCYW3I.js.map +0 -1
  294. package/dist/chunk-V3LF7BE7.js.map +0 -1
  295. package/dist/chunk-XQUSGIDG.js.map +0 -1
@@ -1,18 +1,132 @@
1
1
  // Copied by `vantage add ui tracker`. This file is yours to edit.
2
- // Generated from @squadbase/vantage src/components/tracker.tsx by `npm run registry` (in Vantage, edit src/, not registry/).
2
+ // Generated from @squadbase/squadkit registry/charts/tracker.tsx by `pnpm run registry` (in Vantage, edit packages/squadkit, not registry/).
3
+ "use client"
4
+
3
5
  /**
4
6
  * Tracker — a row of small blocks, one per period, each coloured by status:
5
7
  * uptime per day, batch-job results, daily target hit/miss. Hover a block to
6
- * see its tooltip. Plain HTML/CSS.
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).
7
13
  */
8
- import { forwardRef, type ComponentProps } from "react"
14
+ import { forwardRef, useCallback, useRef, type ComponentProps } from "react"
9
15
 
10
16
  import { cn } from "@squadbase/vantage/ui"
11
17
  import { Tooltip, TooltipContent, TooltipTrigger } from "@squadbase/vantage/ui"
12
18
  import type { ChartColor } from "@squadbase/vantage/components"
13
- import type { ValueFormatter } 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) ---------- */
14
114
 
15
- /* ---------- inlined from src/components/chart-utils.ts (internal to @squadbase/vantage) ---------- */
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
+ }
16
130
 
17
131
  /** The series tokens, in palette order — the default `colors` of every typed chart. */
18
132
  const DEFAULT_CHART_COLORS: readonly ChartColor[] = [
@@ -25,13 +139,37 @@ const DEFAULT_CHART_COLORS: readonly ChartColor[] = [
25
139
 
26
140
  const TOKEN_NAME_RE = /^chart-[1-5]$/
27
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
+
28
150
  /**
29
151
  * A chart colour as a CSS value: `"chart-2"` → `var(--chart-2)` (so it follows
30
152
  * light/dark on its own), anything else passes through unchanged.
31
153
  */
32
154
  function chartColorToCss(color: ChartColor): string {
33
155
  const value = color.trim()
34
- return TOKEN_NAME_RE.test(value) ? `var(--${value})` : value
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
35
173
  }
36
174
 
37
175
  /** The `i`-th colour, cycling through `colors` (the token palette when empty). */
@@ -55,6 +193,115 @@ const numberFormat = new Intl.NumberFormat("ja-JP", { maximumFractionDigits: 2 }
55
193
  /** Default `valueFormatter`: grouped digits, up to two decimals (`1,234.5`). */
56
194
  const defaultValueFormatter: ValueFormatter = (value) => numberFormat.format(value)
57
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
+
58
305
  /**
59
306
  * A data cell as a number, or `null` for a gap. Numeric strings count — SQL
60
307
  * `DECIMAL` / `BIGINT` columns usually arrive as strings.
@@ -74,6 +321,237 @@ function clamp(value: number, min: number, max: number): number {
74
321
  return Math.min(max, Math.max(min, value))
75
322
  }
76
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
+
77
555
  /* ---------------------------------------------------------------- BarList */
78
556
 
79
557
  type BarListSortOrder = "ascending" | "descending" | "none"
@@ -86,6 +564,78 @@ function sortBarListData<T extends { value: number }>(data: readonly T[], sortOr
86
564
  return rows
87
565
  }
88
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
+
89
639
  /** Bar widths in percent of the largest value (at least a sliver for non-zero values). */
90
640
  function barListWidths(values: readonly number[]): number[] {
91
641
  const max = Math.max(0, ...values)
@@ -93,6 +643,102 @@ function barListWidths(values: readonly number[]): number[] {
93
643
  return values.map((v) => (v <= 0 ? 0 : Math.max(1, (v / max) * 100)))
94
644
  }
95
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
+
96
742
  /* ------------------------------------------------------------ CategoryBar */
97
743
 
98
744
  interface CategoryBarSegment {
@@ -127,9 +773,11 @@ interface CategoryBarLabel {
127
773
  * Tick labels under the bar: `0` at the start, then the running total at each
128
774
  * segment's end. A label closer than `minGap` percent to the one before is
129
775
  * dropped so narrow segments don't print on top of each other — except the
130
- * last one (the total), which replaces its neighbour instead.
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.
131
779
  */
132
- function categoryBarLabels(values: readonly number[], minGap = 8): CategoryBarLabel[] {
780
+ function categoryBarLabels(values: readonly number[], minGap = 8, markerPosition?: number): CategoryBarLabel[] {
133
781
  const segments = categoryBarSegments(values).filter((s) => s.width > 0)
134
782
  if (segments.length === 0) return []
135
783
  const labels: CategoryBarLabel[] = [{ position: 0, value: 0 }]
@@ -139,7 +787,46 @@ function categoryBarLabels(values: readonly number[], minGap = 8): CategoryBarLa
139
787
  if (label.position - prev.position >= minGap) labels.push(label)
140
788
  else if (i === segments.length - 1 && labels.length > 1) labels[labels.length - 1] = label
141
789
  })
142
- return labels
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)
143
830
  }
144
831
 
145
832
  /** Marker position in percent of the bar, clamped to its ends. */
@@ -184,14 +871,92 @@ function progressCircleGeometry(
184
871
  return { size: radius * 2, normalizedRadius, circumference, offset: circumference * (1 - ratio), ratio }
185
872
  }
186
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
+
187
952
  /* ---------- end of inlined code ---------- */
188
953
 
189
954
  export interface TrackerBlock {
190
955
  /** React の key。省略時は位置。 */
191
956
  key?: string | number
192
- /** ブロックの色。`"chart-1"`〜`"chart-5"` か CSS カラー(`"var(--destructive)"` など)。省略時は `defaultColor`。 */
957
+ /** ブロックの色。`"positive"` / `"negative"` / `"warning"` / `"info"`(面用の `--<tone>-fill`)、`"chart-1"`〜`"chart-5"`、CSS カラー。省略時は `defaultColor`。 */
193
958
  color?: ChartColor
194
- /** ホバーで出す説明(例: `"10/12 稼働率 99.2%"`)。 */
959
+ /** ホバーで出す説明。日付と状態・件数を入れる(例: `"10/12 失敗 3 件"`)。ブロックの accessible name にもなる。 */
195
960
  tooltip?: string
196
961
  }
197
962
 
@@ -205,26 +970,40 @@ export interface TrackerProps extends Omit<ComponentProps<"div">, "children"> {
205
970
 
206
971
  const DEFAULT_BLOCK_COLOR = "color-mix(in oklab, var(--muted-foreground) 35%, transparent)"
207
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
+
208
981
  export const Tracker = forwardRef<HTMLDivElement, TrackerProps>(function Tracker(
209
- { data, defaultColor, hoverEffect = true, className, ...props },
982
+ { data = NO_ROWS, defaultColor, hoverEffect = true, className, ...props },
210
983
  ref,
211
984
  ) {
212
- const fallback = defaultColor ? chartColorToCss(defaultColor) : DEFAULT_BLOCK_COLOR
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
213
992
  return (
214
- <div ref={ref} data-slot="tracker" className={cn("flex h-8 w-full gap-px", className)} {...props}>
993
+ <div ref={setRef} data-slot="tracker" className={cn("flex h-6 w-full gap-0.5", className)} {...props}>
215
994
  {data.map((block, i) => {
216
995
  const blockClass = cn(
217
- "h-full min-w-0 flex-1 rounded-[1px] first:rounded-l-[4px] last:rounded-r-[4px]",
218
- hoverEffect && "transition-opacity hover:opacity-60",
996
+ "h-full min-w-0 flex-1 rounded-[2px]",
997
+ hoverEffect && "transition-opacity hover:opacity-60 motion-reduce:transition-none",
219
998
  )
220
- const style = { background: block.color ? chartColorToCss(block.color) : fallback }
999
+ const style = { background: block.color ? blockColorToCss(block.color) : fallback }
221
1000
  return block.tooltip ? (
222
1001
  <Tooltip key={block.key ?? i}>
223
1002
  <TooltipTrigger
224
1003
  delay={0}
225
- render={<div data-slot="tracker-block" aria-label={block.tooltip} className={blockClass} style={style} />}
1004
+ render={<div data-slot="tracker-block" role="img" tabIndex={0} aria-label={block.tooltip} className={blockClass} style={style} />}
226
1005
  />
227
- <TooltipContent>{block.tooltip}</TooltipContent>
1006
+ <TooltipContent container={containerRef}>{block.tooltip}</TooltipContent>
228
1007
  </Tooltip>
229
1008
  ) : (
230
1009
  <div key={block.key ?? i} data-slot="tracker-block" className={blockClass} style={style} />