@cdx-ui/components 0.3.4 → 0.3.6

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 (287) hide show
  1. package/README.md +1 -1
  2. package/coverage.svg +1 -1
  3. package/docs/components/bar-chart/content.md +703 -0
  4. package/docs/components/content.md +9 -1
  5. package/docs/components/line-chart/content.md +567 -0
  6. package/docs/components/pie-chart/content.md +493 -0
  7. package/docs/components/progress-segmented/content.md +1 -1
  8. package/docs/components/select/content.md +144 -2
  9. package/docs/components/stepper/content.md +599 -0
  10. package/docs/components/system-alert/content.md +533 -0
  11. package/docs/foundations/expressions/icons/content.md +1 -1
  12. package/docs/foundations/styles/tokens/all-tokens/content.md +2 -1
  13. package/docs/llms.txt +10 -0
  14. package/docs/patterns/content.md +1 -0
  15. package/docs/patterns/dashboard/content.md +423 -19
  16. package/docs/patterns/insights/content.md +590 -0
  17. package/docs/resources/release-notes/0.3.4/content.md +27 -0
  18. package/docs/resources/release-notes/0.3.5/content.md +7 -0
  19. package/docs/resources/release-notes/content.md +2 -0
  20. package/lib/commonjs/components/BarChart/geometry.js +1130 -0
  21. package/lib/commonjs/components/BarChart/geometry.js.map +1 -0
  22. package/lib/commonjs/components/BarChart/index.js +942 -0
  23. package/lib/commonjs/components/BarChart/index.js.map +1 -0
  24. package/lib/commonjs/components/BarChart/styles.js +26 -0
  25. package/lib/commonjs/components/BarChart/styles.js.map +1 -0
  26. package/lib/commonjs/components/Button/index.js +2 -2
  27. package/lib/commonjs/components/Button/index.js.map +1 -1
  28. package/lib/commonjs/components/Chip/styles.js +3 -1
  29. package/lib/commonjs/components/Chip/styles.js.map +1 -1
  30. package/lib/commonjs/components/LineChart/geometry.js +698 -0
  31. package/lib/commonjs/components/LineChart/geometry.js.map +1 -0
  32. package/lib/commonjs/components/LineChart/index.js +747 -0
  33. package/lib/commonjs/components/LineChart/index.js.map +1 -0
  34. package/lib/commonjs/components/LineChart/styles.js +25 -0
  35. package/lib/commonjs/components/LineChart/styles.js.map +1 -0
  36. package/lib/commonjs/components/PieChart/geometry.js +216 -0
  37. package/lib/commonjs/components/PieChart/geometry.js.map +1 -0
  38. package/lib/commonjs/components/PieChart/index.js +476 -0
  39. package/lib/commonjs/components/PieChart/index.js.map +1 -0
  40. package/lib/commonjs/components/PieChart/styles.js +88 -0
  41. package/lib/commonjs/components/PieChart/styles.js.map +1 -0
  42. package/lib/commonjs/components/ProgressCircle/ProgressCircleRing.js +9 -31
  43. package/lib/commonjs/components/ProgressCircle/ProgressCircleRing.js.map +1 -1
  44. package/lib/commonjs/components/ProgressCircle/ProgressRing.js +52 -0
  45. package/lib/commonjs/components/ProgressCircle/ProgressRing.js.map +1 -0
  46. package/lib/commonjs/components/ScrollShadow/useScrollShadow.js +8 -7
  47. package/lib/commonjs/components/ScrollShadow/useScrollShadow.js.map +1 -1
  48. package/lib/commonjs/components/Stepper/index.js +369 -0
  49. package/lib/commonjs/components/Stepper/index.js.map +1 -0
  50. package/lib/commonjs/components/Stepper/styles.js +211 -0
  51. package/lib/commonjs/components/Stepper/styles.js.map +1 -0
  52. package/lib/commonjs/components/Stepper/useStepperLabelFit.js +22 -0
  53. package/lib/commonjs/components/Stepper/useStepperLabelFit.js.map +1 -0
  54. package/lib/commonjs/components/Stepper/useStepperLabelFit.web.js +52 -0
  55. package/lib/commonjs/components/Stepper/useStepperLabelFit.web.js.map +1 -0
  56. package/lib/commonjs/components/Stepper/useStepperRingColors.js +31 -0
  57. package/lib/commonjs/components/Stepper/useStepperRingColors.js.map +1 -0
  58. package/lib/commonjs/components/SystemAlert/animation.js +218 -0
  59. package/lib/commonjs/components/SystemAlert/animation.js.map +1 -0
  60. package/lib/commonjs/components/SystemAlert/index.js +525 -0
  61. package/lib/commonjs/components/SystemAlert/index.js.map +1 -0
  62. package/lib/commonjs/components/SystemAlert/styles.js +178 -0
  63. package/lib/commonjs/components/SystemAlert/styles.js.map +1 -0
  64. package/lib/commonjs/components/SystemAlert/useSystemAlertStatusBarStyle.js +53 -0
  65. package/lib/commonjs/components/SystemAlert/useSystemAlertStatusBarStyle.js.map +1 -0
  66. package/lib/commonjs/components/Tabs/index.js +4 -0
  67. package/lib/commonjs/components/Tabs/index.js.map +1 -1
  68. package/lib/commonjs/components/Tabs/styles.js +1 -1
  69. package/lib/commonjs/components/Tabs/styles.js.map +1 -1
  70. package/lib/commonjs/components/chart/ChartInspector.js +610 -0
  71. package/lib/commonjs/components/chart/ChartInspector.js.map +1 -0
  72. package/lib/commonjs/components/chart/format.js +93 -0
  73. package/lib/commonjs/components/chart/format.js.map +1 -0
  74. package/lib/commonjs/components/chart/index.js +2 -0
  75. package/lib/commonjs/components/chart/index.js.map +1 -0
  76. package/lib/commonjs/components/chart/motion.js +97 -0
  77. package/lib/commonjs/components/chart/motion.js.map +1 -0
  78. package/lib/commonjs/components/chart/palette.js +178 -0
  79. package/lib/commonjs/components/chart/palette.js.map +1 -0
  80. package/lib/commonjs/components/chart/size.js +34 -0
  81. package/lib/commonjs/components/chart/size.js.map +1 -0
  82. package/lib/commonjs/components/chart/ticks.js +59 -0
  83. package/lib/commonjs/components/chart/ticks.js.map +1 -0
  84. package/lib/commonjs/components/chart/types.js +6 -0
  85. package/lib/commonjs/components/chart/types.js.map +1 -0
  86. package/lib/commonjs/components/chart/useChartHostWidth.js +27 -0
  87. package/lib/commonjs/components/chart/useChartHostWidth.js.map +1 -0
  88. package/lib/commonjs/components/index.js +60 -0
  89. package/lib/commonjs/components/index.js.map +1 -1
  90. package/lib/commonjs/figma/SystemAlert.Button.figma.js +28 -0
  91. package/lib/commonjs/figma/SystemAlert.Button.figma.js.map +1 -0
  92. package/lib/commonjs/figma/SystemAlert.Close.figma.js +22 -0
  93. package/lib/commonjs/figma/SystemAlert.Close.figma.js.map +1 -0
  94. package/lib/commonjs/figma/SystemAlert.Description.figma.js +20 -0
  95. package/lib/commonjs/figma/SystemAlert.Description.figma.js.map +1 -0
  96. package/lib/commonjs/figma/SystemAlert.IconButton.figma.js +31 -0
  97. package/lib/commonjs/figma/SystemAlert.IconButton.figma.js.map +1 -0
  98. package/lib/commonjs/figma/SystemAlert.figma.js +48 -0
  99. package/lib/commonjs/figma/SystemAlert.figma.js.map +1 -0
  100. package/lib/module/components/BarChart/geometry.js +1110 -0
  101. package/lib/module/components/BarChart/geometry.js.map +1 -0
  102. package/lib/module/components/BarChart/index.js +936 -0
  103. package/lib/module/components/BarChart/index.js.map +1 -0
  104. package/lib/module/components/BarChart/styles.js +22 -0
  105. package/lib/module/components/BarChart/styles.js.map +1 -0
  106. package/lib/module/components/Button/index.js +2 -2
  107. package/lib/module/components/Button/index.js.map +1 -1
  108. package/lib/module/components/Chip/styles.js +3 -1
  109. package/lib/module/components/Chip/styles.js.map +1 -1
  110. package/lib/module/components/LineChart/geometry.js +685 -0
  111. package/lib/module/components/LineChart/geometry.js.map +1 -0
  112. package/lib/module/components/LineChart/index.js +741 -0
  113. package/lib/module/components/LineChart/index.js.map +1 -0
  114. package/lib/module/components/LineChart/styles.js +21 -0
  115. package/lib/module/components/LineChart/styles.js.map +1 -0
  116. package/lib/module/components/PieChart/geometry.js +209 -0
  117. package/lib/module/components/PieChart/geometry.js.map +1 -0
  118. package/lib/module/components/PieChart/index.js +471 -0
  119. package/lib/module/components/PieChart/index.js.map +1 -0
  120. package/lib/module/components/PieChart/styles.js +84 -0
  121. package/lib/module/components/PieChart/styles.js.map +1 -0
  122. package/lib/module/components/ProgressCircle/ProgressCircleRing.js +10 -32
  123. package/lib/module/components/ProgressCircle/ProgressCircleRing.js.map +1 -1
  124. package/lib/module/components/ProgressCircle/ProgressRing.js +48 -0
  125. package/lib/module/components/ProgressCircle/ProgressRing.js.map +1 -0
  126. package/lib/module/components/ScrollShadow/useScrollShadow.js +8 -7
  127. package/lib/module/components/ScrollShadow/useScrollShadow.js.map +1 -1
  128. package/lib/module/components/Stepper/index.js +360 -0
  129. package/lib/module/components/Stepper/index.js.map +1 -0
  130. package/lib/module/components/Stepper/styles.js +206 -0
  131. package/lib/module/components/Stepper/styles.js.map +1 -0
  132. package/lib/module/components/Stepper/useStepperLabelFit.js +18 -0
  133. package/lib/module/components/Stepper/useStepperLabelFit.js.map +1 -0
  134. package/lib/module/components/Stepper/useStepperLabelFit.web.js +48 -0
  135. package/lib/module/components/Stepper/useStepperLabelFit.web.js.map +1 -0
  136. package/lib/module/components/Stepper/useStepperRingColors.js +28 -0
  137. package/lib/module/components/Stepper/useStepperRingColors.js.map +1 -0
  138. package/lib/module/components/SystemAlert/animation.js +213 -0
  139. package/lib/module/components/SystemAlert/animation.js.map +1 -0
  140. package/lib/module/components/SystemAlert/index.js +515 -0
  141. package/lib/module/components/SystemAlert/index.js.map +1 -0
  142. package/lib/module/components/SystemAlert/styles.js +174 -0
  143. package/lib/module/components/SystemAlert/styles.js.map +1 -0
  144. package/lib/module/components/SystemAlert/useSystemAlertStatusBarStyle.js +49 -0
  145. package/lib/module/components/SystemAlert/useSystemAlertStatusBarStyle.js.map +1 -0
  146. package/lib/module/components/Tabs/index.js +4 -0
  147. package/lib/module/components/Tabs/index.js.map +1 -1
  148. package/lib/module/components/Tabs/styles.js +1 -1
  149. package/lib/module/components/Tabs/styles.js.map +1 -1
  150. package/lib/module/components/chart/ChartInspector.js +600 -0
  151. package/lib/module/components/chart/ChartInspector.js.map +1 -0
  152. package/lib/module/components/chart/format.js +84 -0
  153. package/lib/module/components/chart/format.js.map +1 -0
  154. package/lib/module/components/chart/index.js +2 -0
  155. package/lib/module/components/chart/index.js.map +1 -0
  156. package/lib/module/components/chart/motion.js +89 -0
  157. package/lib/module/components/chart/motion.js.map +1 -0
  158. package/lib/module/components/chart/palette.js +168 -0
  159. package/lib/module/components/chart/palette.js.map +1 -0
  160. package/lib/module/components/chart/size.js +29 -0
  161. package/lib/module/components/chart/size.js.map +1 -0
  162. package/lib/module/components/chart/ticks.js +55 -0
  163. package/lib/module/components/chart/ticks.js.map +1 -0
  164. package/lib/module/components/chart/types.js +4 -0
  165. package/lib/module/components/chart/types.js.map +1 -0
  166. package/lib/module/components/chart/useChartHostWidth.js +23 -0
  167. package/lib/module/components/chart/useChartHostWidth.js.map +1 -0
  168. package/lib/module/components/index.js +5 -0
  169. package/lib/module/components/index.js.map +1 -1
  170. package/lib/module/figma/SystemAlert.Button.figma.js +22 -0
  171. package/lib/module/figma/SystemAlert.Button.figma.js.map +1 -0
  172. package/lib/module/figma/SystemAlert.Close.figma.js +18 -0
  173. package/lib/module/figma/SystemAlert.Close.figma.js.map +1 -0
  174. package/lib/module/figma/SystemAlert.Description.figma.js +14 -0
  175. package/lib/module/figma/SystemAlert.Description.figma.js.map +1 -0
  176. package/lib/module/figma/SystemAlert.IconButton.figma.js +25 -0
  177. package/lib/module/figma/SystemAlert.IconButton.figma.js.map +1 -0
  178. package/lib/module/figma/SystemAlert.figma.js +42 -0
  179. package/lib/module/figma/SystemAlert.figma.js.map +1 -0
  180. package/lib/typescript/components/BarChart/geometry.d.ts +236 -0
  181. package/lib/typescript/components/BarChart/geometry.d.ts.map +1 -0
  182. package/lib/typescript/components/BarChart/index.d.ts +193 -0
  183. package/lib/typescript/components/BarChart/index.d.ts.map +1 -0
  184. package/lib/typescript/components/BarChart/styles.d.ts +32 -0
  185. package/lib/typescript/components/BarChart/styles.d.ts.map +1 -0
  186. package/lib/typescript/components/Chip/styles.d.ts.map +1 -1
  187. package/lib/typescript/components/LineChart/geometry.d.ts +248 -0
  188. package/lib/typescript/components/LineChart/geometry.d.ts.map +1 -0
  189. package/lib/typescript/components/LineChart/index.d.ts +105 -0
  190. package/lib/typescript/components/LineChart/index.d.ts.map +1 -0
  191. package/lib/typescript/components/LineChart/styles.d.ts +12 -0
  192. package/lib/typescript/components/LineChart/styles.d.ts.map +1 -0
  193. package/lib/typescript/components/PieChart/geometry.d.ts +43 -0
  194. package/lib/typescript/components/PieChart/geometry.d.ts.map +1 -0
  195. package/lib/typescript/components/PieChart/index.d.ts +147 -0
  196. package/lib/typescript/components/PieChart/index.d.ts.map +1 -0
  197. package/lib/typescript/components/PieChart/styles.d.ts +27 -0
  198. package/lib/typescript/components/PieChart/styles.d.ts.map +1 -0
  199. package/lib/typescript/components/ProgressCircle/ProgressCircleRing.d.ts.map +1 -1
  200. package/lib/typescript/components/ProgressCircle/ProgressRing.d.ts +17 -0
  201. package/lib/typescript/components/ProgressCircle/ProgressRing.d.ts.map +1 -0
  202. package/lib/typescript/components/ScrollShadow/useScrollShadow.d.ts.map +1 -1
  203. package/lib/typescript/components/Stepper/index.d.ts +68 -0
  204. package/lib/typescript/components/Stepper/index.d.ts.map +1 -0
  205. package/lib/typescript/components/Stepper/styles.d.ts +46 -0
  206. package/lib/typescript/components/Stepper/styles.d.ts.map +1 -0
  207. package/lib/typescript/components/Stepper/useStepperLabelFit.d.ts +15 -0
  208. package/lib/typescript/components/Stepper/useStepperLabelFit.d.ts.map +1 -0
  209. package/lib/typescript/components/Stepper/useStepperLabelFit.web.d.ts +10 -0
  210. package/lib/typescript/components/Stepper/useStepperLabelFit.web.d.ts.map +1 -0
  211. package/lib/typescript/components/Stepper/useStepperRingColors.d.ts +6 -0
  212. package/lib/typescript/components/Stepper/useStepperRingColors.d.ts.map +1 -0
  213. package/lib/typescript/components/SystemAlert/animation.d.ts +56 -0
  214. package/lib/typescript/components/SystemAlert/animation.d.ts.map +1 -0
  215. package/lib/typescript/components/SystemAlert/index.d.ts +110 -0
  216. package/lib/typescript/components/SystemAlert/index.d.ts.map +1 -0
  217. package/lib/typescript/components/SystemAlert/styles.d.ts +38 -0
  218. package/lib/typescript/components/SystemAlert/styles.d.ts.map +1 -0
  219. package/lib/typescript/components/SystemAlert/useSystemAlertStatusBarStyle.d.ts +14 -0
  220. package/lib/typescript/components/SystemAlert/useSystemAlertStatusBarStyle.d.ts.map +1 -0
  221. package/lib/typescript/components/Tabs/index.d.ts.map +1 -1
  222. package/lib/typescript/components/chart/ChartInspector.d.ts +101 -0
  223. package/lib/typescript/components/chart/ChartInspector.d.ts.map +1 -0
  224. package/lib/typescript/components/chart/format.d.ts +16 -0
  225. package/lib/typescript/components/chart/format.d.ts.map +1 -0
  226. package/lib/typescript/components/chart/index.d.ts +3 -0
  227. package/lib/typescript/components/chart/index.d.ts.map +1 -0
  228. package/lib/typescript/components/chart/motion.d.ts +27 -0
  229. package/lib/typescript/components/chart/motion.d.ts.map +1 -0
  230. package/lib/typescript/components/chart/palette.d.ts +44 -0
  231. package/lib/typescript/components/chart/palette.d.ts.map +1 -0
  232. package/lib/typescript/components/chart/size.d.ts +25 -0
  233. package/lib/typescript/components/chart/size.d.ts.map +1 -0
  234. package/lib/typescript/components/chart/ticks.d.ts +3 -0
  235. package/lib/typescript/components/chart/ticks.d.ts.map +1 -0
  236. package/lib/typescript/components/chart/types.d.ts +163 -0
  237. package/lib/typescript/components/chart/types.d.ts.map +1 -0
  238. package/lib/typescript/components/chart/useChartHostWidth.d.ts +9 -0
  239. package/lib/typescript/components/chart/useChartHostWidth.d.ts.map +1 -0
  240. package/lib/typescript/components/index.d.ts +5 -0
  241. package/lib/typescript/components/index.d.ts.map +1 -1
  242. package/lib/typescript/figma/SystemAlert.Button.figma.d.ts +11 -0
  243. package/lib/typescript/figma/SystemAlert.Button.figma.d.ts.map +1 -0
  244. package/lib/typescript/figma/SystemAlert.Close.figma.d.ts +11 -0
  245. package/lib/typescript/figma/SystemAlert.Close.figma.d.ts.map +1 -0
  246. package/lib/typescript/figma/SystemAlert.Description.figma.d.ts +8 -0
  247. package/lib/typescript/figma/SystemAlert.Description.figma.d.ts.map +1 -0
  248. package/lib/typescript/figma/SystemAlert.IconButton.figma.d.ts +11 -0
  249. package/lib/typescript/figma/SystemAlert.IconButton.figma.d.ts.map +1 -0
  250. package/lib/typescript/figma/SystemAlert.figma.d.ts +8 -0
  251. package/lib/typescript/figma/SystemAlert.figma.d.ts.map +1 -0
  252. package/package.json +5 -5
  253. package/src/components/BarChart/geometry.ts +1469 -0
  254. package/src/components/BarChart/index.tsx +1424 -0
  255. package/src/components/BarChart/styles.ts +31 -0
  256. package/src/components/Button/index.tsx +1 -1
  257. package/src/components/Chip/styles.ts +3 -1
  258. package/src/components/LineChart/geometry.ts +957 -0
  259. package/src/components/LineChart/index.tsx +1109 -0
  260. package/src/components/LineChart/styles.ts +26 -0
  261. package/src/components/PieChart/geometry.ts +295 -0
  262. package/src/components/PieChart/index.tsx +715 -0
  263. package/src/components/PieChart/styles.ts +101 -0
  264. package/src/components/ProgressCircle/ProgressCircleRing.tsx +10 -39
  265. package/src/components/ProgressCircle/ProgressRing.tsx +60 -0
  266. package/src/components/ScrollShadow/useScrollShadow.ts +12 -11
  267. package/src/components/Stepper/index.tsx +452 -0
  268. package/src/components/Stepper/styles.ts +234 -0
  269. package/src/components/Stepper/useStepperLabelFit.ts +21 -0
  270. package/src/components/Stepper/useStepperLabelFit.web.ts +53 -0
  271. package/src/components/Stepper/useStepperRingColors.ts +29 -0
  272. package/src/components/SystemAlert/animation.ts +252 -0
  273. package/src/components/SystemAlert/index.tsx +684 -0
  274. package/src/components/SystemAlert/styles.ts +212 -0
  275. package/src/components/SystemAlert/useSystemAlertStatusBarStyle.ts +57 -0
  276. package/src/components/Tabs/index.tsx +4 -0
  277. package/src/components/Tabs/styles.ts +1 -1
  278. package/src/components/chart/ChartInspector.tsx +726 -0
  279. package/src/components/chart/format.ts +95 -0
  280. package/src/components/chart/index.ts +24 -0
  281. package/src/components/chart/motion.ts +98 -0
  282. package/src/components/chart/palette.tsx +247 -0
  283. package/src/components/chart/size.ts +21 -0
  284. package/src/components/chart/ticks.ts +53 -0
  285. package/src/components/chart/types.ts +183 -0
  286. package/src/components/chart/useChartHostWidth.ts +26 -0
  287. package/src/components/index.ts +5 -0
@@ -0,0 +1,936 @@
1
+ "use strict";
2
+
3
+ /* SVG `x`/`y` are paint coordinates. RN View `x`/`y` layout props are deprecated and share the name. */
4
+ /* eslint-disable @typescript-eslint/no-deprecated */
5
+ import { forwardRef, useEffect, useMemo, useRef, useState } from 'react';
6
+ import { ScrollView, Text, View } from 'react-native';
7
+ import Animated, { useAnimatedProps } from 'react-native-reanimated';
8
+ import { G, Line, Path, Svg, Text as SvgText } from 'react-native-svg';
9
+ import { dataAttributes, mergeDataAttributes } from '@cdx-ui/primitives';
10
+ import { cn, useControllableState } from '@cdx-ui/utils';
11
+ import { ChartInspector, ChartTooltipLayer, expandHitBox } from '../chart/ChartInspector';
12
+ import { defaultChartValueFormatter, formatChartPercent, resolveChartLocaleText, resolveValueFormatter } from '../chart/format';
13
+ import { useChartHostWidth } from '../chart/useChartHostWidth';
14
+ import { CHART_MOTION_DURATION, useChartMorph, useChartMotionEnabled, lerpVector } from '../chart/motion';
15
+ import { ChartLinearFills, chartFillUrl, chartSeriesColor, resolveChartColor, useChartChrome, useChartColorPaints, useChartGradientId, useChartPalette, useChartSimpleColor } from '../chart/palette';
16
+ import { BAR_GAP_RATIO, CATEGORY_GAP_RATIO, barKeyboardNeighbor, barPath, barValueAnchor, DEFAULT_STACK_GAP, formatWaterfallBarValue, isExpandAxis, layoutBarChart, overlayDelta, readBarValue, resolveBarChartContentSize, resolveBarChartGutters, resolveBarGroups, stackedTotalAnchors, waterfallValueAnchor } from './geometry';
17
+ import { BAR_RADIUS, barChartLegendItemVariants, barChartLegendLabelVariants, barChartLegendVariants, barChartRootVariants, resolveBarChartBox } from './styles';
18
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
19
+ const INACTIVE_OPACITY = 0.4;
20
+ const DASH = '6 4';
21
+ const SVG_OVERFLOW_VISIBLE = {
22
+ overflow: 'visible'
23
+ };
24
+ const LABEL_FADE_DURATION = 220;
25
+ const AnimatedPath = Animated.createAnimatedComponent(Path);
26
+
27
+ /** Keys of `TRow` whose value is a boolean. */
28
+
29
+ /** Running-total series. Each row is a change, except rows flagged as totals. */
30
+
31
+ /** Draws this series as a thinner comparison bar beside another series' bar. */
32
+
33
+ function resolveBarPlan(series) {
34
+ const toGeometry = item => ({
35
+ id: item.id,
36
+ dataKey: item.dataKey,
37
+ label: item.label ?? '',
38
+ stack: item.stack,
39
+ stackOffset: item.stackOffset
40
+ });
41
+ const waterfall = series.find(item => item.waterfall !== undefined);
42
+ if (waterfall !== undefined) {
43
+ return {
44
+ kind: 'waterfall',
45
+ series: [waterfall],
46
+ geometry: [toGeometry(waterfall)],
47
+ totalKey: waterfall.waterfall?.totalKey
48
+ };
49
+ }
50
+ for (const comparison of series) {
51
+ const primary = comparison.overlay === undefined ? undefined : series.find(item => item.id === comparison.overlay?.seriesId && item !== comparison);
52
+ if (primary !== undefined) {
53
+ const pair = [primary, comparison];
54
+ return {
55
+ kind: 'overlay',
56
+ series: pair,
57
+ geometry: pair.map(item => ({
58
+ ...toGeometry(item),
59
+ stack: undefined
60
+ })),
61
+ totalKey: undefined
62
+ };
63
+ }
64
+ }
65
+ return {
66
+ kind: 'bars',
67
+ series,
68
+ geometry: series.map(toGeometry),
69
+ totalKey: undefined
70
+ };
71
+ }
72
+ function sameItem(a, b) {
73
+ return a?.seriesId === b.seriesId && a.dataIndex === b.dataIndex;
74
+ }
75
+ function barSelection(bar) {
76
+ return {
77
+ seriesId: bar.seriesId,
78
+ dataIndex: bar.index
79
+ };
80
+ }
81
+ function barAccessibilityName(label, seriesLabel, formatted, change = null) {
82
+ const base = seriesLabel.length > 0 ? `${label}, ${seriesLabel}, ${formatted}` : `${label}, ${formatted}`;
83
+ return change === null ? base : `${base}, ${change}`;
84
+ }
85
+ function BarChartInner({
86
+ dataset,
87
+ series: seriesProp,
88
+ xAxis,
89
+ yAxis,
90
+ size = 'lg',
91
+ width: widthProp,
92
+ height: heightProp,
93
+ layout: orientation = 'vertical',
94
+ hideLegend = false,
95
+ grid,
96
+ palette: paletteProp = 'auto',
97
+ barLabel = false,
98
+ borderRadius = BAR_RADIUS,
99
+ stackGap = DEFAULT_STACK_GAP,
100
+ categoryGapRatio = CATEGORY_GAP_RATIO,
101
+ barGapRatio = BAR_GAP_RATIO,
102
+ referenceLines,
103
+ emphasizedIndex,
104
+ scrollable = true,
105
+ visiblePoints,
106
+ selectedItem,
107
+ defaultSelectedItem,
108
+ onSelectedItemChange,
109
+ tooltip: tooltipProp,
110
+ locale,
111
+ localeText: localeTextProp,
112
+ animation,
113
+ accessibilityLabel,
114
+ className,
115
+ style,
116
+ onLayout,
117
+ ...props
118
+ }, ref) {
119
+ const animated = useChartMotionEnabled(animation);
120
+ const simpleColor = useChartSimpleColor();
121
+ const gradientId = useChartGradientId('bar-fill');
122
+ const chrome = useChartChrome();
123
+ const palette = useChartPalette();
124
+ const paints = useChartColorPaints();
125
+ const localeText = useMemo(() => resolveChartLocaleText(localeTextProp), [localeTextProp]);
126
+ const plan = useMemo(() => resolveBarPlan(seriesProp), [seriesProp]);
127
+ const {
128
+ kind,
129
+ geometry
130
+ } = plan;
131
+ const overlay = kind === 'overlay';
132
+ const waterfall = kind === 'waterfall';
133
+ const expandAxis = useMemo(() => isExpandAxis(kind, resolveBarGroups(geometry)), [kind, geometry]);
134
+ const categoryAxis = (orientation === 'vertical' ? xAxis : yAxis)?.[0];
135
+ const valueAxis = (orientation === 'vertical' ? yAxis : xAxis)?.[0];
136
+ const categoryKey = categoryAxis?.dataKey;
137
+ const categoryLabelPosition = categoryAxis?.position;
138
+ const showTicks = valueAxis?.position !== 'none';
139
+ const showGrid = grid === undefined ? true : (orientation === 'vertical' ? grid.horizontal : grid.vertical) === true;
140
+ const tickLabelInterval = categoryAxis?.tickLabelInterval;
141
+ const categories = useMemo(() => dataset.map((row, index) => {
142
+ if (categoryKey === undefined) {
143
+ return String(index);
144
+ }
145
+ const raw = row[categoryKey];
146
+ return raw === null || raw === undefined ? '' : String(raw);
147
+ }), [dataset, categoryKey]);
148
+ const hasNegative = useMemo(() => dataset.some(row => geometry.some(item => (readBarValue(row, item.dataKey) ?? 0) < 0)), [dataset, geometry]);
149
+ const sourceById = useMemo(() => new Map(plan.series.map(item => [item.id, item])), [plan.series]);
150
+ const valueAxisMin = valueAxis?.min;
151
+ const valueAxisMax = valueAxis?.max;
152
+ const valueAxisTicks = valueAxis?.tickNumber;
153
+ const valueAxisFormatter = valueAxis?.valueFormatter;
154
+ const valueAxisConfig = useMemo(() => ({
155
+ min: valueAxisMin,
156
+ max: valueAxisMax,
157
+ tickNumber: valueAxisTicks
158
+ }), [valueAxisMin, valueAxisMax, valueAxisTicks]);
159
+ const percentFormatter = useMemo(() => value => value === null ? '' : formatChartPercent(value, locale), [locale]);
160
+ const formatTick = useMemo(() => {
161
+ const formatter = valueAxisFormatter ?? (expandAxis ? percentFormatter : defaultChartValueFormatter(locale));
162
+ return value => formatter(value, {
163
+ location: 'tick'
164
+ });
165
+ }, [valueAxisFormatter, expandAxis, percentFormatter, locale]);
166
+ const formatBar = (bar, location) => {
167
+ const source = sourceById.get(bar.seriesId);
168
+ const context = {
169
+ location,
170
+ seriesId: bar.seriesId,
171
+ dataIndex: bar.index
172
+ };
173
+ if (bar.expand === true && source?.valueFormatter === undefined) {
174
+ return (valueAxisFormatter ?? percentFormatter)(bar.plotValue / 100, context);
175
+ }
176
+ const formatter = resolveValueFormatter(source, valueAxis, locale);
177
+ const format = value => formatter(value, context);
178
+ return bar.waterfallRole === undefined ? format(bar.value) : formatWaterfallBarValue(bar, format);
179
+ };
180
+ const seriesLabelOf = bar => {
181
+ if (bar.waterfallRole === 'increase') {
182
+ return localeText.waterfallIncrease;
183
+ }
184
+ if (bar.waterfallRole === 'decrease') {
185
+ return localeText.waterfallDecrease;
186
+ }
187
+ return bar.seriesLabel;
188
+ };
189
+ const box = resolveBarChartBox(size, widthProp, heightProp);
190
+ const [hostWidth, handleHostLayout] = useChartHostWidth(onLayout);
191
+ const viewportWidth = hostWidth > 0 ? Math.min(hostWidth, box.width) : box.width;
192
+ const viewportHeight = box.height;
193
+ const gutters = useMemo(() => resolveBarChartGutters({
194
+ categories,
195
+ hasNegative,
196
+ orientation,
197
+ barLabel,
198
+ categoryLabelPosition,
199
+ showTicks,
200
+ overlay
201
+ }), [categories, hasNegative, orientation, barLabel, categoryLabelPosition, showTicks, overlay]);
202
+ const content = useMemo(() => resolveBarChartContentSize({
203
+ viewportWidth,
204
+ viewportHeight,
205
+ categoryCount: dataset.length,
206
+ orientation,
207
+ gutters,
208
+ scrollable,
209
+ visiblePoints
210
+ }), [viewportWidth, viewportHeight, dataset.length, orientation, gutters, scrollable, visiblePoints]);
211
+ const showCategoryLabel = useMemo(() => {
212
+ if (typeof tickLabelInterval !== 'function') {
213
+ return undefined;
214
+ }
215
+ return index => {
216
+ const row = dataset.at(index);
217
+ const value = row === undefined || categoryKey === undefined ? index : row[categoryKey];
218
+ return tickLabelInterval(value, index);
219
+ };
220
+ }, [tickLabelInterval, dataset, categoryKey]);
221
+ const layout = useMemo(() => layoutBarChart({
222
+ dataset,
223
+ categories,
224
+ series: geometry,
225
+ kind,
226
+ waterfallTotalKey: plan.totalKey,
227
+ width: content.width,
228
+ height: content.height,
229
+ orientation,
230
+ barLabel,
231
+ categoryLabelPosition,
232
+ showTicks,
233
+ referenceLines,
234
+ valueAxis: valueAxisConfig,
235
+ formatTick,
236
+ stackGap,
237
+ categoryGapRatio,
238
+ barGapRatio,
239
+ showCategoryLabel
240
+ }), [dataset, categories, geometry, kind, plan.totalKey, content.width, content.height, orientation, barLabel, categoryLabelPosition, showTicks, referenceLines, valueAxisConfig, formatTick, stackGap, categoryGapRatio, barGapRatio, showCategoryLabel]);
241
+ const overflowsX = content.width > viewportWidth + 0.5;
242
+ const overflowsY = content.height > viewportHeight + 0.5;
243
+ const fills = waterfall ? dataset.map((_, index) => palette[index % palette.length] ?? simpleColor) : plan.series.map((item, seriesIndex) => {
244
+ const custom = resolveChartColor(item.color, paints);
245
+ if (custom !== undefined) {
246
+ return custom;
247
+ }
248
+ if (overlay) {
249
+ return seriesIndex === 0 ? simpleColor : chrome.grid;
250
+ }
251
+ return paints[chartSeriesColor(seriesIndex, plan.series.length, paletteProp, 'bar')];
252
+ });
253
+ const summaryCategories = dataset.map((row, dataIndex) => ({
254
+ label: categories[dataIndex] ?? '',
255
+ values: plan.series.flatMap(item => {
256
+ const value = readBarValue(row, item.dataKey);
257
+ if (value === null) {
258
+ return [];
259
+ }
260
+ // An expand axis formats 0–1 shares; the summary reads raw values.
261
+ const formatter = resolveValueFormatter(item, expandAxis ? null : valueAxis, locale);
262
+ return [{
263
+ label: item.label ?? '',
264
+ formattedValue: formatter(value, {
265
+ location: 'a11y',
266
+ seriesId: item.id,
267
+ dataIndex
268
+ })
269
+ }];
270
+ })
271
+ }));
272
+ const summary = accessibilityLabel ?? localeText.barChartSummary(summaryCategories);
273
+ const trigger = tooltipProp?.trigger ?? 'axis';
274
+ const tooltip = trigger !== 'none';
275
+ const interactive = onSelectedItemChange !== undefined || selectedItem !== undefined || defaultSelectedItem !== undefined;
276
+ const [selectedState, setSelectedItem] = useControllableState({
277
+ prop: selectedItem,
278
+ defaultProp: defaultSelectedItem ?? null,
279
+ onChange: onSelectedItemChange
280
+ });
281
+ const selected = selectedState ?? null;
282
+ const visibleBars = layout.bars.filter(bar => bar.stackId !== undefined ? bar.width > 0 && bar.height > 0 : orientation === 'vertical' ? bar.width > 0 : bar.height > 0);
283
+ const inspectable = (interactive || tooltip) && visibleBars.length > 0;
284
+ const [activeIndex, setActiveIndex] = useState(null);
285
+ const [dismissed, setDismissed] = useState(false);
286
+ const [scrubbing, setScrubbing] = useState(false);
287
+ const scrollOffset = useRef({
288
+ x: 0,
289
+ y: 0
290
+ });
291
+ const selectedIndex = selected ? visibleBars.findIndex(bar => sameItem(selected, barSelection(bar))) : -1;
292
+ const activeBar = activeIndex === null ? undefined : visibleBars.at(activeIndex);
293
+ const highlightBar = activeBar ? barSelection(activeBar) : selectedIndex >= 0 && selected !== null ? selected : null;
294
+ const tooltipIndex = tooltip && !dismissed && activeIndex !== null ? activeIndex : null;
295
+ const activate = index => {
296
+ setDismissed(false);
297
+ setActiveIndex(prev => prev === index ? prev : index);
298
+ };
299
+ const deactivate = index => {
300
+ setActiveIndex(prev => prev === index ? null : prev);
301
+ };
302
+ const showLegend = !waterfall && plan.series.length > 0 && !hideLegend;
303
+ const plot = /*#__PURE__*/_jsx(BarPlot, {
304
+ layout: layout,
305
+ orientation: orientation,
306
+ overlay: overlay,
307
+ waterfall: waterfall,
308
+ showGrid: showGrid,
309
+ barLabel: barLabel,
310
+ formatBar: formatBar,
311
+ formatStackTotal: anchor => {
312
+ const context = {
313
+ location: 'label',
314
+ dataIndex: anchor.index
315
+ };
316
+ if (anchor.expand) {
317
+ return (valueAxisFormatter ?? percentFormatter)(anchor.total / 100, context);
318
+ }
319
+ return resolveValueFormatter(sourceById.get(anchor.seriesId), valueAxis, locale)(anchor.total, context);
320
+ },
321
+ fills: fills,
322
+ gradientId: gradientId,
323
+ chrome: chrome,
324
+ accent: simpleColor,
325
+ borderRadius: Math.max(borderRadius, 0),
326
+ animated: animated,
327
+ highlightBar: highlightBar,
328
+ emphasizedIndex: emphasizedIndex
329
+ });
330
+ const vertical = orientation === 'vertical';
331
+ const targets = inspectable ? barInspectorTargets({
332
+ bars: visibleBars,
333
+ layout,
334
+ orientation,
335
+ overlay,
336
+ waterfall,
337
+ trigger,
338
+ offsetX: vertical ? layout.plot.x : 0,
339
+ fills,
340
+ fallbackFill: chrome.grid,
341
+ formatBar,
342
+ seriesLabelOf,
343
+ localeText,
344
+ selectedIndex: selectedIndex >= 0 ? selectedIndex : null
345
+ }) : [];
346
+ const tip = tooltipIndex === null ? undefined : targets.at(tooltipIndex);
347
+ const dismissOnScroll = event => {
348
+ scrollOffset.current = event.nativeEvent.contentOffset;
349
+ if (tooltipIndex !== null) {
350
+ setDismissed(true);
351
+ }
352
+ };
353
+ const inspector = inspectable ? /*#__PURE__*/_jsx(BarInspector, {
354
+ bars: visibleBars,
355
+ targets: targets,
356
+ orientation: orientation,
357
+ summary: summary,
358
+ selectable: interactive,
359
+ activeIndex: activeIndex,
360
+ selectedIndex: selectedIndex >= 0 ? selectedIndex : null,
361
+ holdToScrub: overflowsX || overflowsY,
362
+ onScrubLockChange: setScrubbing,
363
+ onActivate: activate,
364
+ onDeactivate: deactivate,
365
+ onDismiss: () => {
366
+ setDismissed(true);
367
+ },
368
+ onSelectIndex: index => {
369
+ const bar = visibleBars.at(index);
370
+ if (bar) {
371
+ setDismissed(false);
372
+ const next = barSelection(bar);
373
+ setSelectedItem(sameItem(selected, next) ? null : next);
374
+ }
375
+ }
376
+ }) : null;
377
+ const tooltipLayer = tip !== undefined ? /*#__PURE__*/_jsx(ChartTooltipLayer, {
378
+ content: tip.tooltip,
379
+ noValueText: localeText.noValue,
380
+ slot: "bar-chart",
381
+ anchorX: vertical ? layout.plot.x + tip.anchorX - scrollOffset.current.x : tip.anchorX,
382
+ anchorY: vertical ? tip.anchorY : tip.anchorY - scrollOffset.current.y,
383
+ anchorRadius: tip.anchorRadius,
384
+ width: viewportWidth,
385
+ height: viewportHeight
386
+ }) : null;
387
+ const ticks = showTicks ? /*#__PURE__*/_jsx(_Fragment, {
388
+ children: layout.valueTicks.map(tick => /*#__PURE__*/_jsx(SvgText, {
389
+ x: tick.x,
390
+ y: tick.y,
391
+ fill: chrome.label,
392
+ fontFamily: chrome.fontFamily,
393
+ fontSize: chrome.labelSize,
394
+ textAnchor: orientation === 'vertical' ? 'end' : 'middle',
395
+ alignmentBaseline: "middle",
396
+ children: tick.text
397
+ }, `tick-${String(tick.value)}`))
398
+ }) : null;
399
+ const chart = /*#__PURE__*/_jsxs(View, {
400
+ style: {
401
+ width: '100%',
402
+ maxWidth: viewportWidth,
403
+ height: viewportHeight
404
+ },
405
+ ...dataAttributes({
406
+ slot: 'bar-chart-plot'
407
+ }),
408
+ children: [orientation === 'vertical' ? /*#__PURE__*/_jsxs(View, {
409
+ className: "w-full flex-row",
410
+ style: {
411
+ height: viewportHeight
412
+ },
413
+ children: [/*#__PURE__*/_jsx(Svg, {
414
+ width: layout.plot.x,
415
+ height: viewportHeight,
416
+ viewBox: `0 0 ${String(layout.plot.x)} ${String(content.height)}`,
417
+ accessible: false,
418
+ accessibilityElementsHidden: true,
419
+ importantForAccessibility: "no-hide-descendants",
420
+ children: ticks
421
+ }), /*#__PURE__*/_jsx(ScrollView, {
422
+ horizontal: true,
423
+ nestedScrollEnabled: true,
424
+ scrollEnabled: overflowsX && !scrubbing,
425
+ showsHorizontalScrollIndicator: overflowsX,
426
+ scrollEventThrottle: 16,
427
+ onScroll: dismissOnScroll,
428
+ className: "flex-1",
429
+ style: {
430
+ height: viewportHeight
431
+ },
432
+ children: /*#__PURE__*/_jsxs(View, {
433
+ style: {
434
+ width: content.width - layout.plot.x,
435
+ height: viewportHeight
436
+ },
437
+ children: [/*#__PURE__*/_jsx(Svg, {
438
+ width: content.width - layout.plot.x,
439
+ height: viewportHeight,
440
+ viewBox: `0 0 ${String(content.width - layout.plot.x)} ${String(content.height)}`,
441
+ style: SVG_OVERFLOW_VISIBLE,
442
+ pointerEvents: "none",
443
+ accessible: false,
444
+ accessibilityElementsHidden: true,
445
+ importantForAccessibility: "no-hide-descendants",
446
+ children: /*#__PURE__*/_jsx(G, {
447
+ transform: `translate(${String(-layout.plot.x)}, 0)`,
448
+ children: plot
449
+ })
450
+ }), inspector]
451
+ })
452
+ })]
453
+ }) : /*#__PURE__*/_jsxs(View, {
454
+ style: {
455
+ width: viewportWidth,
456
+ height: viewportHeight
457
+ },
458
+ children: [/*#__PURE__*/_jsx(ScrollView, {
459
+ nestedScrollEnabled: true,
460
+ scrollEnabled: overflowsY && !scrubbing,
461
+ showsVerticalScrollIndicator: overflowsY,
462
+ scrollEventThrottle: 16,
463
+ onScroll: dismissOnScroll,
464
+ style: {
465
+ height: viewportHeight - gutters.paddingBottom
466
+ },
467
+ children: /*#__PURE__*/_jsxs(View, {
468
+ style: {
469
+ width: viewportWidth,
470
+ height: content.height - gutters.paddingBottom
471
+ },
472
+ children: [/*#__PURE__*/_jsx(Svg, {
473
+ width: viewportWidth,
474
+ height: content.height - gutters.paddingBottom,
475
+ viewBox: `0 0 ${String(content.width)} ${String(content.height - gutters.paddingBottom)}`,
476
+ pointerEvents: "none",
477
+ accessible: false,
478
+ accessibilityElementsHidden: true,
479
+ importantForAccessibility: "no-hide-descendants",
480
+ children: plot
481
+ }), inspector]
482
+ })
483
+ }), /*#__PURE__*/_jsx(Svg, {
484
+ width: viewportWidth,
485
+ height: gutters.paddingBottom,
486
+ viewBox: `0 0 ${String(content.width)} ${String(gutters.paddingBottom)}`,
487
+ accessible: false,
488
+ accessibilityElementsHidden: true,
489
+ importantForAccessibility: "no-hide-descendants",
490
+ children: /*#__PURE__*/_jsx(G, {
491
+ transform: `translate(0, ${String(-(content.height - gutters.paddingBottom))})`,
492
+ children: ticks
493
+ })
494
+ })]
495
+ }), tooltipLayer]
496
+ });
497
+ return /*#__PURE__*/_jsxs(View, {
498
+ ref: ref,
499
+ className: cn(barChartRootVariants(), className),
500
+ style: style,
501
+ accessible: !inspectable && !showLegend,
502
+ accessibilityRole: !inspectable && !showLegend ? 'image' : undefined,
503
+ accessibilityLabel: !inspectable && !showLegend ? summary : undefined,
504
+ ...props,
505
+ onLayout: handleHostLayout,
506
+ ...mergeDataAttributes(props, dataAttributes({
507
+ slot: 'bar-chart'
508
+ })),
509
+ children: [chart, showLegend ? /*#__PURE__*/_jsx(View, {
510
+ className: barChartLegendVariants(),
511
+ ...dataAttributes({
512
+ slot: 'bar-chart-legend'
513
+ }),
514
+ children: plan.series.map((item, seriesIndex) => {
515
+ const isSelected = highlightBar?.seriesId === item.id;
516
+ return /*#__PURE__*/_jsxs(View, {
517
+ className: barChartLegendItemVariants(),
518
+ ...dataAttributes({
519
+ slot: 'bar-chart-legend-item'
520
+ }),
521
+ children: [/*#__PURE__*/_jsx(View, {
522
+ className: "h-2 w-3 rounded-sm",
523
+ style: {
524
+ backgroundColor: fills[seriesIndex]
525
+ }
526
+ }), /*#__PURE__*/_jsx(Text, {
527
+ className: barChartLegendLabelVariants({
528
+ selected: isSelected
529
+ }),
530
+ children: item.label !== undefined && item.label.length > 0 ? item.label : localeText.defaultSeriesLabel
531
+ })]
532
+ }, item.id);
533
+ })
534
+ }) : null]
535
+ });
536
+ }
537
+
538
+ /**
539
+ * Category bars from `dataset` rows. MUI X Charts–shaped: `series[].dataKey`, axis arrays,
540
+ * `layout`, `stack` groups, and `selectedItem`.
541
+ */
542
+ export const BarChart = /*#__PURE__*/forwardRef(BarChartInner);
543
+ BarChart.displayName = 'BarChart';
544
+ function BarPlot({
545
+ layout,
546
+ orientation,
547
+ overlay,
548
+ waterfall,
549
+ showGrid,
550
+ barLabel,
551
+ formatBar,
552
+ formatStackTotal,
553
+ fills,
554
+ gradientId,
555
+ chrome,
556
+ accent,
557
+ borderRadius,
558
+ animated,
559
+ highlightBar,
560
+ emphasizedIndex
561
+ }) {
562
+ const labeledBars = layout.bars.filter(bar => {
563
+ if (bar.stackId !== undefined) {
564
+ return false;
565
+ }
566
+ if (emphasizedIndex !== undefined && bar.index !== emphasizedIndex) {
567
+ return false;
568
+ }
569
+ return !overlay || bar.seriesIndex === 0;
570
+ });
571
+ const stackLabels = stackedTotalAnchors(layout.bars, orientation).filter(anchor => emphasizedIndex === undefined || anchor.index === emphasizedIndex);
572
+ const paintedBars = overlay ? [...layout.bars].sort((a, b) => b.seriesIndex - a.seriesIndex) : layout.bars;
573
+ return /*#__PURE__*/_jsxs(_Fragment, {
574
+ children: [/*#__PURE__*/_jsx(ChartLinearFills, {
575
+ idPrefix: gradientId,
576
+ colors: fills,
577
+ x2: orientation === 'vertical' ? '0%' : '100%',
578
+ y2: orientation === 'vertical' ? '100%' : '0%'
579
+ }), showGrid ? layout.gridLines.map(line => /*#__PURE__*/_jsx(Line, {
580
+ x1: line.x1,
581
+ y1: line.y1,
582
+ x2: line.x2,
583
+ y2: line.y2,
584
+ stroke: chrome.grid,
585
+ strokeWidth: 1
586
+ }, `grid-${String(line.x1)}-${String(line.y1)}`)) : /*#__PURE__*/_jsx(Line, {
587
+ x1: orientation === 'vertical' ? layout.plot.x : layout.baseline,
588
+ y1: orientation === 'vertical' ? layout.baseline : layout.plot.y,
589
+ x2: orientation === 'vertical' ? layout.plot.x + layout.plot.width : layout.baseline,
590
+ y2: orientation === 'vertical' ? layout.baseline : layout.plot.y + layout.plot.height,
591
+ stroke: chrome.grid,
592
+ strokeWidth: 1
593
+ }), layout.referenceLines.map((line, index) => /*#__PURE__*/_jsxs(G, {
594
+ children: [/*#__PURE__*/_jsx(Line, {
595
+ x1: line.x1,
596
+ y1: line.y1,
597
+ x2: line.x2,
598
+ y2: line.y2,
599
+ stroke: accent,
600
+ strokeWidth: 1,
601
+ strokeDasharray: DASH
602
+ }), line.label !== undefined && line.label.length > 0 ? /*#__PURE__*/_jsx(SvgText, {
603
+ x: line.x1 + 4,
604
+ y: orientation === 'vertical' ? line.y1 - 4 : line.y1 + 12,
605
+ fill: accent,
606
+ fontFamily: chrome.fontFamily,
607
+ fontSize: chrome.captionSize,
608
+ textAnchor: "start",
609
+ children: line.label
610
+ }) : null]
611
+ }, `ref-${String(line.x1)}-${String(line.y1)}-${String(index)}`)), layout.connectors.map((line, index) => /*#__PURE__*/_jsx(Line, {
612
+ x1: line.x1,
613
+ y1: line.y1,
614
+ x2: line.x2,
615
+ y2: line.y2,
616
+ stroke: chrome.grid,
617
+ strokeWidth: 1,
618
+ strokeDasharray: DASH
619
+ }, `wf-${String(line.x1)}-${String(line.y1)}-${String(index)}`)), paintedBars.map(bar => {
620
+ if (bar.width <= 0 || bar.height <= 0) {
621
+ return null;
622
+ }
623
+ const dimmed = highlightBar !== null && (bar.stackId !== undefined ? !sameItem(highlightBar, barSelection(bar)) : highlightBar.dataIndex !== bar.index);
624
+ const muted = emphasizedIndex !== undefined && bar.index !== emphasizedIndex;
625
+ const comparison = overlay && bar.seriesIndex > 0;
626
+ return /*#__PURE__*/_jsx(AnimatedBar, {
627
+ bar: bar,
628
+ orientation: orientation,
629
+ baseline: layout.baseline,
630
+ animated: animated,
631
+ fill: muted || waterfall && dimmed ? chrome.grid : comparison || waterfall ? fills[bar.seriesIndex] ?? chrome.grid : chartFillUrl(gradientId, bar.seriesIndex),
632
+ opacity: waterfall ? 1 : dimmed ? INACTIVE_OPACITY : 1,
633
+ radius: borderRadius
634
+ }, `${String(bar.index)}-${bar.seriesId}`);
635
+ }), layout.categoryLabels.map((item, index) => /*#__PURE__*/_jsx(SvgText, {
636
+ x: item.x,
637
+ y: item.y,
638
+ fill: chrome.label,
639
+ fontFamily: chrome.fontFamily,
640
+ fontSize: chrome.labelSize,
641
+ textAnchor: item.textAnchor,
642
+ alignmentBaseline: "middle",
643
+ children: item.label
644
+ }, `cat-${String(index)}-${item.label}`)), barLabel ? /*#__PURE__*/_jsx(ValueLabels, {
645
+ animated: animated,
646
+ motionKey: `${orientation}-${overlay ? '1' : '0'}-${layout.bars.map(bar => [bar.x, bar.y, bar.width, bar.height].join(',')).join(';')}`,
647
+ children: labelOpacity => /*#__PURE__*/_jsxs(_Fragment, {
648
+ children: [stackLabels.map(label => /*#__PURE__*/_jsx(SvgText, {
649
+ x: label.x,
650
+ y: label.y,
651
+ fill: chrome.label,
652
+ fillOpacity: labelOpacity,
653
+ fontFamily: chrome.fontFamily,
654
+ fontSize: chrome.captionSize,
655
+ textAnchor: label.textAnchor,
656
+ alignmentBaseline: "middle",
657
+ children: formatStackTotal(label)
658
+ }, `stack-val-${label.key}`)), labeledBars.map(bar => {
659
+ const anchor = waterfall ? waterfallValueAnchor(bar, orientation) : barValueAnchor(bar, orientation);
660
+ return /*#__PURE__*/_jsx(G, {
661
+ children: /*#__PURE__*/_jsx(SvgText, {
662
+ x: anchor.x,
663
+ y: anchor.y,
664
+ fill: chrome.label,
665
+ fillOpacity: labelOpacity,
666
+ fontFamily: chrome.fontFamily,
667
+ fontSize: chrome.captionSize,
668
+ textAnchor: anchor.textAnchor,
669
+ alignmentBaseline: "middle",
670
+ children: formatBar(bar, 'label')
671
+ })
672
+ }, `val-${String(bar.index)}-${bar.seriesId}`);
673
+ })]
674
+ })
675
+ }) : null]
676
+ });
677
+ }
678
+ function barTooltipContent(group, bar, trigger, fills, fallbackFill, formatBar, seriesLabelOf) {
679
+ const shown = trigger === 'axis' ? group : [bar];
680
+ return {
681
+ title: bar.label,
682
+ items: shown.map(item => ({
683
+ seriesId: item.seriesId,
684
+ label: seriesLabelOf(item),
685
+ color: fills[item.seriesIndex] ?? fallbackFill,
686
+ formattedValue: formatBar(item, 'tooltip')
687
+ }))
688
+ };
689
+ }
690
+
691
+ /**
692
+ * One hit target per drawn bar. Grouped bars get the full value-axis span of their slot so short
693
+ * bars stay easy to hover. Stacked segments keep their own rect, expanded to a 44px minimum
694
+ * (WCAG 2.5.8 / HIG) so a 9px-tall bar is still a usable touch target.
695
+ */
696
+ /** Targets in scroll-content coordinates, shifted left by `offsetX`. */
697
+ function barInspectorTargets({
698
+ bars,
699
+ layout,
700
+ orientation,
701
+ overlay,
702
+ waterfall,
703
+ trigger,
704
+ offsetX,
705
+ fills,
706
+ fallbackFill,
707
+ formatBar,
708
+ seriesLabelOf,
709
+ localeText,
710
+ selectedIndex
711
+ }) {
712
+ const {
713
+ plot
714
+ } = layout;
715
+ const vertical = orientation === 'vertical';
716
+ const groups = new Map();
717
+ bars.forEach(bar => {
718
+ const group = groups.get(bar.index);
719
+ if (group === undefined) {
720
+ groups.set(bar.index, [bar]);
721
+ } else {
722
+ group.push(bar);
723
+ }
724
+ });
725
+ const outlines = new Map([...groups].map(([categoryIndex, group]) => {
726
+ const start = Math.min(...group.map(item => vertical ? item.x : item.y));
727
+ const end = Math.max(...group.map(item => vertical ? item.x + item.width : item.y + item.height));
728
+ const outline = vertical ? {
729
+ left: start - offsetX - 4,
730
+ top: plot.y,
731
+ width: end - start + 8,
732
+ height: plot.height
733
+ } : {
734
+ left: plot.x - offsetX,
735
+ top: start - 4,
736
+ width: plot.width,
737
+ height: end - start + 8
738
+ };
739
+ return [categoryIndex, outline];
740
+ }));
741
+ const trendText = bar => {
742
+ if (!overlay || bar.seriesIndex !== 0) {
743
+ return null;
744
+ }
745
+ const group = groups.get(bar.index) ?? [];
746
+ const delta = overlayDelta(group, bar.index);
747
+ if (delta === null) {
748
+ return null;
749
+ }
750
+ const comparison = group.find(item => item.seriesIndex === 1);
751
+ return localeText.trend({
752
+ direction: delta > 0 ? 'up' : delta < 0 ? 'down' : 'none',
753
+ formattedDelta: formatBar({
754
+ ...bar,
755
+ value: Math.abs(delta)
756
+ }, 'a11y'),
757
+ comparisonLabel: comparison?.seriesLabel ?? ''
758
+ });
759
+ };
760
+ return bars.map((bar, index) => {
761
+ const x = bar.x - offsetX;
762
+ const raw = bar.stackId !== undefined || waterfall || !vertical ? {
763
+ left: x,
764
+ top: bar.y,
765
+ width: bar.width,
766
+ height: bar.height
767
+ } : {
768
+ left: x,
769
+ top: plot.y,
770
+ width: bar.width,
771
+ height: plot.height
772
+ };
773
+ const box = expandHitBox(raw.left, raw.top, raw.width, raw.height);
774
+ const group = groups.get(bar.index) ?? [bar];
775
+ const outline = outlines.get(bar.index);
776
+ return {
777
+ key: `hit-${String(bar.index)}-${bar.seriesId}`,
778
+ ...box,
779
+ outline,
780
+ anchorX: vertical ? x + bar.width / 2 : x + bar.width,
781
+ anchorY: bar.y,
782
+ anchorRadius: vertical ? bar.width / 2 : 0,
783
+ tooltip: barTooltipContent(group, bar, trigger === 'item' ? 'item' : 'axis', fills, fallbackFill, formatBar, seriesLabelOf),
784
+ accessibilityLabel: barAccessibilityName(bar.label, seriesLabelOf(bar), formatBar(bar, 'a11y'), trendText(bar)),
785
+ selected: selectedIndex === index
786
+ };
787
+ });
788
+ }
789
+ function BarInspector({
790
+ bars,
791
+ targets,
792
+ orientation,
793
+ summary,
794
+ selectable,
795
+ activeIndex,
796
+ selectedIndex,
797
+ onActivate,
798
+ onDeactivate,
799
+ onDismiss,
800
+ onSelectIndex,
801
+ holdToScrub,
802
+ onScrubLockChange
803
+ }) {
804
+ return /*#__PURE__*/_jsx(ChartInspector, {
805
+ targets: targets,
806
+ summary: summary,
807
+ selectable: selectable,
808
+ activeIndex: activeIndex,
809
+ selectedIndex: selectedIndex,
810
+ slot: "bar-chart",
811
+ holdToScrub: holdToScrub,
812
+ onScrubLockChange: onScrubLockChange,
813
+ hitTest: (x, y) => {
814
+ let best = null;
815
+ let bestDist = Number.POSITIVE_INFINITY;
816
+ targets.forEach((target, index) => {
817
+ if (x < target.left || x > target.left + target.width || y < target.top || y > target.top + target.height) {
818
+ return;
819
+ }
820
+ const dist = Math.hypot(x - (target.left + target.width / 2), y - (target.top + target.height / 2));
821
+ if (dist < bestDist) {
822
+ bestDist = dist;
823
+ best = index;
824
+ }
825
+ });
826
+ return best;
827
+ },
828
+ onActivate: onActivate,
829
+ onDeactivate: onDeactivate,
830
+ onDismiss: onDismiss,
831
+ onSelectIndex: onSelectIndex,
832
+ neighborIndex: (index, key) => barKeyboardNeighbor(bars, index, key, orientation)
833
+ });
834
+ }
835
+ function collapsedBar(bar, orientation, baseline) {
836
+ if (orientation === 'vertical') {
837
+ const onBaseline = Math.abs((bar.plotValue >= 0 ? bar.y + bar.height : bar.y) - baseline) < 1;
838
+ return onBaseline ? [bar.x, baseline, bar.width, 0] : [bar.x, bar.y + bar.height, bar.width, 0];
839
+ }
840
+ const onBaseline = Math.abs((bar.plotValue >= 0 ? bar.x : bar.x + bar.width) - baseline) < 1;
841
+ return onBaseline ? [baseline, bar.y, 0, bar.height] : [bar.x, bar.y, 0, bar.height];
842
+ }
843
+ function AnimatedBar({
844
+ bar,
845
+ orientation,
846
+ baseline,
847
+ animated,
848
+ fill,
849
+ opacity,
850
+ radius
851
+ }) {
852
+ const {
853
+ rounded,
854
+ roundAll,
855
+ value
856
+ } = bar;
857
+ const morph = useChartMorph([bar.x, bar.y, bar.width, bar.height], collapsedBar(bar, orientation, baseline), animated);
858
+ const {
859
+ from,
860
+ to,
861
+ progress
862
+ } = morph;
863
+ const animatedProps = useAnimatedProps(() => {
864
+ const [x = 0, y = 0, width = 0, height = 0] = lerpVector(from.get(), to.get(), progress.get());
865
+ return {
866
+ d: barPath({
867
+ x,
868
+ y,
869
+ width,
870
+ height,
871
+ rounded,
872
+ roundAll,
873
+ value
874
+ }, orientation, radius)
875
+ };
876
+ }, [from, to, progress, rounded, roundAll, value, orientation, radius]);
877
+ return /*#__PURE__*/_jsx(AnimatedPath, {
878
+ animatedProps: animatedProps,
879
+ fill: fill,
880
+ opacity: opacity
881
+ });
882
+ }
883
+ function ValueLabels({
884
+ animated,
885
+ motionKey,
886
+ children
887
+ }) {
888
+ const [shownKey, setShownKey] = useState(animated ? null : motionKey);
889
+ useEffect(() => {
890
+ if (!animated) {
891
+ setShownKey(motionKey);
892
+ return;
893
+ }
894
+ const id = setTimeout(() => setShownKey(motionKey), CHART_MOTION_DURATION);
895
+ return () => {
896
+ clearTimeout(id);
897
+ };
898
+ }, [animated, motionKey]);
899
+ if (!animated) {
900
+ return /*#__PURE__*/_jsx(_Fragment, {
901
+ children: children(1)
902
+ });
903
+ }
904
+ if (shownKey !== motionKey) {
905
+ return null;
906
+ }
907
+ return /*#__PURE__*/_jsx(FadeInLabels, {
908
+ children: children
909
+ }, motionKey);
910
+ }
911
+
912
+ /** Group opacity on native SVG flashes a full-opacity frame; fade each text's fill instead. */
913
+ function FadeInLabels({
914
+ children
915
+ }) {
916
+ const [opacity, setOpacity] = useState(0);
917
+ useEffect(() => {
918
+ let frame = 0;
919
+ const started = Date.now();
920
+ const tick = () => {
921
+ const t = Math.min(1, (Date.now() - started) / LABEL_FADE_DURATION);
922
+ setOpacity(1 - (1 - t) ** 3);
923
+ if (t < 1) {
924
+ frame = requestAnimationFrame(tick);
925
+ }
926
+ };
927
+ frame = requestAnimationFrame(tick);
928
+ return () => {
929
+ cancelAnimationFrame(frame);
930
+ };
931
+ }, []);
932
+ return /*#__PURE__*/_jsx(_Fragment, {
933
+ children: children(opacity)
934
+ });
935
+ }
936
+ //# sourceMappingURL=index.js.map