@automattic/charts 0.57.0 → 0.59.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (267) hide show
  1. package/CHANGELOG.md +36 -2
  2. package/README.md +7 -54
  3. package/dist/index.cjs +9607 -21
  4. package/dist/index.cjs.map +1 -1
  5. package/dist/index.css +32 -49
  6. package/dist/index.css.map +1 -1
  7. package/dist/index.d.cts +1612 -33
  8. package/dist/index.d.ts +1612 -33
  9. package/dist/index.js +9640 -54
  10. package/dist/index.js.map +1 -1
  11. package/package.json +9 -126
  12. package/src/charts/bar-chart/bar-chart.module.scss +0 -5
  13. package/src/charts/bar-chart/bar-chart.tsx +142 -149
  14. package/src/charts/bar-chart/test/bar-chart.test.tsx +48 -31
  15. package/src/charts/leaderboard-chart/leaderboard-chart.tsx +54 -74
  16. package/src/charts/leaderboard-chart/test/leaderboard-chart.test.tsx +4 -5
  17. package/src/charts/leaderboard-chart/types.ts +1 -11
  18. package/src/charts/line-chart/line-chart.module.scss +0 -5
  19. package/src/charts/line-chart/line-chart.tsx +202 -193
  20. package/src/charts/line-chart/private/line-chart-annotations-overlay.tsx +1 -2
  21. package/src/charts/line-chart/test/line-chart.test.tsx +49 -27
  22. package/src/charts/line-chart/types.ts +0 -1
  23. package/src/charts/pie-chart/pie-chart.module.scss +2 -10
  24. package/src/charts/pie-chart/pie-chart.tsx +212 -212
  25. package/src/charts/pie-chart/test/composition-api.test.tsx +44 -3
  26. package/src/charts/pie-chart/test/pie-chart.test.tsx +51 -44
  27. package/src/charts/pie-semi-circle-chart/pie-semi-circle-chart.module.scss +2 -8
  28. package/src/charts/pie-semi-circle-chart/pie-semi-circle-chart.tsx +166 -168
  29. package/src/charts/pie-semi-circle-chart/test/pie-semi-circle-chart.test.tsx +58 -30
  30. package/src/charts/private/chart-composition/index.ts +2 -0
  31. package/src/charts/private/chart-composition/render-legend-slot.ts +22 -0
  32. package/src/charts/private/chart-composition/test/render-legend-slot.test.tsx +60 -0
  33. package/src/charts/private/chart-composition/test/use-chart-children.test.tsx +91 -0
  34. package/src/charts/private/chart-composition/use-chart-children.ts +34 -2
  35. package/src/charts/private/chart-layout/chart-layout.module.scss +7 -0
  36. package/src/charts/private/chart-layout/chart-layout.tsx +106 -0
  37. package/src/charts/private/chart-layout/index.ts +2 -0
  38. package/src/charts/private/chart-layout/test/chart-layout.test.tsx +167 -0
  39. package/src/charts/private/single-chart-context/single-chart-context.tsx +2 -2
  40. package/src/charts/private/svg-empty-state/index.ts +1 -0
  41. package/src/charts/private/svg-empty-state/svg-empty-state.module.scss +7 -0
  42. package/src/charts/private/svg-empty-state/svg-empty-state.tsx +40 -0
  43. package/src/components/legend/hooks/test/use-chart-legend-items.test.tsx +12 -8
  44. package/src/components/legend/hooks/use-chart-legend-items.ts +12 -13
  45. package/src/components/legend/index.ts +1 -8
  46. package/src/components/legend/legend.tsx +33 -8
  47. package/src/components/legend/private/base-legend.module.scss +19 -37
  48. package/src/components/legend/private/base-legend.tsx +0 -2
  49. package/src/components/legend/test/legend.test.tsx +93 -1
  50. package/src/components/legend/types.ts +7 -34
  51. package/src/hooks/index.ts +1 -1
  52. package/src/hooks/use-data-with-percentages.ts +24 -0
  53. package/src/hooks/use-interactive-legend-data.ts +18 -15
  54. package/src/index.ts +66 -9
  55. package/src/providers/chart-context/global-charts-provider.tsx +7 -1
  56. package/src/providers/chart-context/hooks/use-chart-registration.ts +2 -1
  57. package/src/providers/chart-context/types.ts +2 -2
  58. package/src/types.ts +110 -45
  59. package/src/utils/date-parsing.ts +10 -1
  60. package/src/utils/test/date-parsing.test.ts +12 -0
  61. package/src/utils/test/resolve-css-var.test.ts +4 -2
  62. package/tsup.config.ts +1 -1
  63. package/dist/base-tooltip-DOq93wjU.d.cts +0 -38
  64. package/dist/base-tooltip-DOq93wjU.d.ts +0 -38
  65. package/dist/charts/bar-chart/index.cjs +0 -15
  66. package/dist/charts/bar-chart/index.cjs.map +0 -1
  67. package/dist/charts/bar-chart/index.css +0 -153
  68. package/dist/charts/bar-chart/index.css.map +0 -1
  69. package/dist/charts/bar-chart/index.d.cts +0 -37
  70. package/dist/charts/bar-chart/index.d.ts +0 -37
  71. package/dist/charts/bar-chart/index.js +0 -15
  72. package/dist/charts/bar-chart/index.js.map +0 -1
  73. package/dist/charts/bar-list-chart/index.cjs +0 -16
  74. package/dist/charts/bar-list-chart/index.cjs.map +0 -1
  75. package/dist/charts/bar-list-chart/index.css +0 -153
  76. package/dist/charts/bar-list-chart/index.css.map +0 -1
  77. package/dist/charts/bar-list-chart/index.d.cts +0 -92
  78. package/dist/charts/bar-list-chart/index.d.ts +0 -92
  79. package/dist/charts/bar-list-chart/index.js +0 -16
  80. package/dist/charts/bar-list-chart/index.js.map +0 -1
  81. package/dist/charts/conversion-funnel-chart/index.cjs +0 -11
  82. package/dist/charts/conversion-funnel-chart/index.cjs.map +0 -1
  83. package/dist/charts/conversion-funnel-chart/index.css +0 -251
  84. package/dist/charts/conversion-funnel-chart/index.css.map +0 -1
  85. package/dist/charts/conversion-funnel-chart/index.d.cts +0 -97
  86. package/dist/charts/conversion-funnel-chart/index.d.ts +0 -97
  87. package/dist/charts/conversion-funnel-chart/index.js +0 -11
  88. package/dist/charts/conversion-funnel-chart/index.js.map +0 -1
  89. package/dist/charts/geo-chart/index.cjs +0 -13
  90. package/dist/charts/geo-chart/index.cjs.map +0 -1
  91. package/dist/charts/geo-chart/index.css +0 -117
  92. package/dist/charts/geo-chart/index.css.map +0 -1
  93. package/dist/charts/geo-chart/index.d.cts +0 -67
  94. package/dist/charts/geo-chart/index.d.ts +0 -67
  95. package/dist/charts/geo-chart/index.js +0 -13
  96. package/dist/charts/geo-chart/index.js.map +0 -1
  97. package/dist/charts/leaderboard-chart/index.cjs +0 -20
  98. package/dist/charts/leaderboard-chart/index.cjs.map +0 -1
  99. package/dist/charts/leaderboard-chart/index.css +0 -172
  100. package/dist/charts/leaderboard-chart/index.css.map +0 -1
  101. package/dist/charts/leaderboard-chart/index.d.cts +0 -46
  102. package/dist/charts/leaderboard-chart/index.d.ts +0 -46
  103. package/dist/charts/leaderboard-chart/index.js +0 -20
  104. package/dist/charts/leaderboard-chart/index.js.map +0 -1
  105. package/dist/charts/line-chart/index.cjs +0 -15
  106. package/dist/charts/line-chart/index.cjs.map +0 -1
  107. package/dist/charts/line-chart/index.css +0 -225
  108. package/dist/charts/line-chart/index.css.map +0 -1
  109. package/dist/charts/line-chart/index.d.cts +0 -99
  110. package/dist/charts/line-chart/index.d.ts +0 -99
  111. package/dist/charts/line-chart/index.js +0 -15
  112. package/dist/charts/line-chart/index.js.map +0 -1
  113. package/dist/charts/pie-chart/index.cjs +0 -18
  114. package/dist/charts/pie-chart/index.cjs.map +0 -1
  115. package/dist/charts/pie-chart/index.css +0 -143
  116. package/dist/charts/pie-chart/index.css.map +0 -1
  117. package/dist/charts/pie-chart/index.d.cts +0 -97
  118. package/dist/charts/pie-chart/index.d.ts +0 -97
  119. package/dist/charts/pie-chart/index.js +0 -18
  120. package/dist/charts/pie-chart/index.js.map +0 -1
  121. package/dist/charts/pie-semi-circle-chart/index.cjs +0 -17
  122. package/dist/charts/pie-semi-circle-chart/index.cjs.map +0 -1
  123. package/dist/charts/pie-semi-circle-chart/index.css +0 -144
  124. package/dist/charts/pie-semi-circle-chart/index.css.map +0 -1
  125. package/dist/charts/pie-semi-circle-chart/index.d.cts +0 -94
  126. package/dist/charts/pie-semi-circle-chart/index.d.ts +0 -94
  127. package/dist/charts/pie-semi-circle-chart/index.js +0 -17
  128. package/dist/charts/pie-semi-circle-chart/index.js.map +0 -1
  129. package/dist/charts/sparkline/index.cjs +0 -16
  130. package/dist/charts/sparkline/index.cjs.map +0 -1
  131. package/dist/charts/sparkline/index.css +0 -242
  132. package/dist/charts/sparkline/index.css.map +0 -1
  133. package/dist/charts/sparkline/index.d.cts +0 -113
  134. package/dist/charts/sparkline/index.d.ts +0 -113
  135. package/dist/charts/sparkline/index.js +0 -16
  136. package/dist/charts/sparkline/index.js.map +0 -1
  137. package/dist/chunk-2A34OA5O.cjs +0 -51
  138. package/dist/chunk-2A34OA5O.cjs.map +0 -1
  139. package/dist/chunk-2NCY7R4G.js +0 -3897
  140. package/dist/chunk-2NCY7R4G.js.map +0 -1
  141. package/dist/chunk-32DH6JDF.js +0 -1263
  142. package/dist/chunk-32DH6JDF.js.map +0 -1
  143. package/dist/chunk-4OPFE4RM.js +0 -614
  144. package/dist/chunk-4OPFE4RM.js.map +0 -1
  145. package/dist/chunk-6CCZL2JJ.js +0 -63
  146. package/dist/chunk-6CCZL2JJ.js.map +0 -1
  147. package/dist/chunk-77OKCVQN.cjs +0 -421
  148. package/dist/chunk-77OKCVQN.cjs.map +0 -1
  149. package/dist/chunk-7FQX4ALL.cjs +0 -219
  150. package/dist/chunk-7FQX4ALL.cjs.map +0 -1
  151. package/dist/chunk-ASLARV7L.cjs +0 -81
  152. package/dist/chunk-ASLARV7L.cjs.map +0 -1
  153. package/dist/chunk-BCX5THDQ.js +0 -403
  154. package/dist/chunk-BCX5THDQ.js.map +0 -1
  155. package/dist/chunk-BPYKWMI7.js +0 -194
  156. package/dist/chunk-BPYKWMI7.js.map +0 -1
  157. package/dist/chunk-CZGYJKG6.js +0 -421
  158. package/dist/chunk-CZGYJKG6.js.map +0 -1
  159. package/dist/chunk-D2UH4CFE.cjs +0 -120
  160. package/dist/chunk-D2UH4CFE.cjs.map +0 -1
  161. package/dist/chunk-DAU3HNEG.js +0 -344
  162. package/dist/chunk-DAU3HNEG.js.map +0 -1
  163. package/dist/chunk-H2V4JMSA.js +0 -219
  164. package/dist/chunk-H2V4JMSA.js.map +0 -1
  165. package/dist/chunk-I2276W3I.cjs +0 -66
  166. package/dist/chunk-I2276W3I.cjs.map +0 -1
  167. package/dist/chunk-I35UYJJR.cjs +0 -468
  168. package/dist/chunk-I35UYJJR.cjs.map +0 -1
  169. package/dist/chunk-IU4DYUAV.js +0 -120
  170. package/dist/chunk-IU4DYUAV.js.map +0 -1
  171. package/dist/chunk-KXRWNFQJ.js +0 -51
  172. package/dist/chunk-KXRWNFQJ.js.map +0 -1
  173. package/dist/chunk-OP6PHB2U.js +0 -81
  174. package/dist/chunk-OP6PHB2U.js.map +0 -1
  175. package/dist/chunk-PXLEMUGJ.js +0 -165
  176. package/dist/chunk-PXLEMUGJ.js.map +0 -1
  177. package/dist/chunk-RCY6XLGU.cjs +0 -63
  178. package/dist/chunk-RCY6XLGU.cjs.map +0 -1
  179. package/dist/chunk-RHHVEJHJ.cjs +0 -1263
  180. package/dist/chunk-RHHVEJHJ.cjs.map +0 -1
  181. package/dist/chunk-TO3OQBXG.cjs +0 -165
  182. package/dist/chunk-TO3OQBXG.cjs.map +0 -1
  183. package/dist/chunk-V36ERY7Y.js +0 -375
  184. package/dist/chunk-V36ERY7Y.js.map +0 -1
  185. package/dist/chunk-VJM5XCB4.cjs +0 -614
  186. package/dist/chunk-VJM5XCB4.cjs.map +0 -1
  187. package/dist/chunk-VTS3PNMS.cjs +0 -344
  188. package/dist/chunk-VTS3PNMS.cjs.map +0 -1
  189. package/dist/chunk-WLODYNLB.js +0 -1067
  190. package/dist/chunk-WLODYNLB.js.map +0 -1
  191. package/dist/chunk-XKRJL2QT.cjs +0 -375
  192. package/dist/chunk-XKRJL2QT.cjs.map +0 -1
  193. package/dist/chunk-XWYZIFZW.js +0 -66
  194. package/dist/chunk-XWYZIFZW.js.map +0 -1
  195. package/dist/chunk-Y3NNQMAX.cjs +0 -194
  196. package/dist/chunk-Y3NNQMAX.cjs.map +0 -1
  197. package/dist/chunk-YE2T52VZ.cjs +0 -1067
  198. package/dist/chunk-YE2T52VZ.cjs.map +0 -1
  199. package/dist/chunk-Z26M4V2M.js +0 -468
  200. package/dist/chunk-Z26M4V2M.js.map +0 -1
  201. package/dist/chunk-Z45KX47P.cjs +0 -3897
  202. package/dist/chunk-Z45KX47P.cjs.map +0 -1
  203. package/dist/chunk-ZH4F5RMG.cjs +0 -403
  204. package/dist/chunk-ZH4F5RMG.cjs.map +0 -1
  205. package/dist/components/legend/index.cjs +0 -11
  206. package/dist/components/legend/index.cjs.map +0 -1
  207. package/dist/components/legend/index.css +0 -103
  208. package/dist/components/legend/index.css.map +0 -1
  209. package/dist/components/legend/index.d.cts +0 -37
  210. package/dist/components/legend/index.d.ts +0 -37
  211. package/dist/components/legend/index.js +0 -11
  212. package/dist/components/legend/index.js.map +0 -1
  213. package/dist/components/tooltip/index.cjs +0 -12
  214. package/dist/components/tooltip/index.cjs.map +0 -1
  215. package/dist/components/tooltip/index.css +0 -13
  216. package/dist/components/tooltip/index.css.map +0 -1
  217. package/dist/components/tooltip/index.d.cts +0 -71
  218. package/dist/components/tooltip/index.d.ts +0 -71
  219. package/dist/components/tooltip/index.js +0 -12
  220. package/dist/components/tooltip/index.js.map +0 -1
  221. package/dist/components/trend-indicator/index.cjs +0 -8
  222. package/dist/components/trend-indicator/index.cjs.map +0 -1
  223. package/dist/components/trend-indicator/index.css +0 -27
  224. package/dist/components/trend-indicator/index.css.map +0 -1
  225. package/dist/components/trend-indicator/index.d.cts +0 -44
  226. package/dist/components/trend-indicator/index.d.ts +0 -44
  227. package/dist/components/trend-indicator/index.js +0 -8
  228. package/dist/components/trend-indicator/index.js.map +0 -1
  229. package/dist/format-metric-value-MXm5DtQ_.d.cts +0 -24
  230. package/dist/format-metric-value-MXm5DtQ_.d.ts +0 -24
  231. package/dist/hooks/index.cjs +0 -31
  232. package/dist/hooks/index.cjs.map +0 -1
  233. package/dist/hooks/index.css +0 -103
  234. package/dist/hooks/index.css.map +0 -1
  235. package/dist/hooks/index.d.cts +0 -272
  236. package/dist/hooks/index.d.ts +0 -272
  237. package/dist/hooks/index.js +0 -31
  238. package/dist/hooks/index.js.map +0 -1
  239. package/dist/leaderboard-chart-BKYYXcg2.d.ts +0 -83
  240. package/dist/leaderboard-chart-DR7CGb0L.d.cts +0 -83
  241. package/dist/legend-C2grwnWk.d.cts +0 -9
  242. package/dist/legend-Cj0xM5dU.d.ts +0 -9
  243. package/dist/providers/index.cjs +0 -21
  244. package/dist/providers/index.cjs.map +0 -1
  245. package/dist/providers/index.css +0 -103
  246. package/dist/providers/index.css.map +0 -1
  247. package/dist/providers/index.d.cts +0 -28
  248. package/dist/providers/index.d.ts +0 -28
  249. package/dist/providers/index.js +0 -21
  250. package/dist/providers/index.js.map +0 -1
  251. package/dist/themes-BmVGrYnF.d.ts +0 -67
  252. package/dist/themes-CyjKm-P_.d.cts +0 -67
  253. package/dist/types-CuUEszrM.d.ts +0 -19
  254. package/dist/types-DZordNiO.d.cts +0 -505
  255. package/dist/types-DZordNiO.d.ts +0 -505
  256. package/dist/types-I67mddpr.d.cts +0 -78
  257. package/dist/types-I67mddpr.d.ts +0 -78
  258. package/dist/types-KtOPPzPX.d.cts +0 -19
  259. package/dist/utils/index.cjs +0 -44
  260. package/dist/utils/index.cjs.map +0 -1
  261. package/dist/utils/index.d.cts +0 -226
  262. package/dist/utils/index.d.ts +0 -226
  263. package/dist/utils/index.js +0 -44
  264. package/dist/utils/index.js.map +0 -1
  265. package/dist/with-responsive-CNfhzAUu.d.cts +0 -18
  266. package/dist/with-responsive-CNfhzAUu.d.ts +0 -18
  267. package/src/hooks/use-has-legend-child.ts +0 -22
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@automattic/charts",
3
- "version": "0.57.0",
3
+ "version": "0.59.0",
4
4
  "description": "Display charts within Automattic products.",
5
5
  "homepage": "https://github.com/Automattic/jetpack/tree/HEAD/projects/js-packages/charts/#readme",
6
6
  "bugs": {
@@ -22,79 +22,7 @@
22
22
  "import": "./dist/index.js",
23
23
  "require": "./dist/index.cjs"
24
24
  },
25
- "./bar-chart": {
26
- "import": "./dist/charts/bar-chart/index.js",
27
- "require": "./dist/charts/bar-chart/index.cjs"
28
- },
29
- "./bar-chart/style.css": "./dist/charts/bar-chart/index.css",
30
- "./bar-list-chart": {
31
- "import": "./dist/charts/bar-list-chart/index.js",
32
- "require": "./dist/charts/bar-list-chart/index.cjs"
33
- },
34
- "./bar-list-chart/style.css": "./dist/charts/bar-list-chart/index.css",
35
- "./conversion-funnel-chart": {
36
- "import": "./dist/charts/conversion-funnel-chart/index.js",
37
- "require": "./dist/charts/conversion-funnel-chart/index.cjs"
38
- },
39
- "./conversion-funnel-chart/style.css": "./dist/charts/conversion-funnel-chart/index.css",
40
- "./geo-chart": {
41
- "import": "./dist/charts/geo-chart/index.js",
42
- "require": "./dist/charts/geo-chart/index.cjs"
43
- },
44
- "./geo-chart/style.css": "./dist/charts/geo-chart/index.css",
45
- "./hooks": {
46
- "import": "./dist/hooks/index.js",
47
- "require": "./dist/hooks/index.cjs"
48
- },
49
- "./leaderboard-chart": {
50
- "import": "./dist/charts/leaderboard-chart/index.js",
51
- "require": "./dist/charts/leaderboard-chart/index.cjs"
52
- },
53
- "./leaderboard-chart/style.css": "./dist/charts/leaderboard-chart/index.css",
54
- "./legend": {
55
- "import": "./dist/components/legend/index.js",
56
- "require": "./dist/components/legend/index.cjs"
57
- },
58
- "./legend/style.css": "./dist/components/legend/index.css",
59
- "./line-chart": {
60
- "import": "./dist/charts/line-chart/index.js",
61
- "require": "./dist/charts/line-chart/index.cjs"
62
- },
63
- "./line-chart/style.css": "./dist/charts/line-chart/index.css",
64
- "./pie-chart": {
65
- "import": "./dist/charts/pie-chart/index.js",
66
- "require": "./dist/charts/pie-chart/index.cjs"
67
- },
68
- "./pie-chart/style.css": "./dist/charts/pie-chart/index.css",
69
- "./pie-semi-circle-chart": {
70
- "import": "./dist/charts/pie-semi-circle-chart/index.js",
71
- "require": "./dist/charts/pie-semi-circle-chart/index.cjs"
72
- },
73
- "./pie-semi-circle-chart/style.css": "./dist/charts/pie-semi-circle-chart/index.css",
74
- "./providers": {
75
- "import": "./dist/providers/index.js",
76
- "require": "./dist/providers/index.cjs"
77
- },
78
- "./sparkline": {
79
- "import": "./dist/charts/sparkline/index.js",
80
- "require": "./dist/charts/sparkline/index.cjs"
81
- },
82
- "./sparkline/style.css": "./dist/charts/sparkline/index.css",
83
25
  "./style.css": "./dist/index.css",
84
- "./tooltip": {
85
- "import": "./dist/components/tooltip/index.js",
86
- "require": "./dist/components/tooltip/index.cjs"
87
- },
88
- "./tooltip/style.css": "./dist/components/tooltip/index.css",
89
- "./trend-indicator": {
90
- "import": "./dist/components/trend-indicator/index.js",
91
- "require": "./dist/components/trend-indicator/index.cjs"
92
- },
93
- "./trend-indicator/style.css": "./dist/components/trend-indicator/index.css",
94
- "./utils": {
95
- "import": "./dist/utils/index.js",
96
- "require": "./dist/utils/index.cjs"
97
- },
98
26
  "./visx/group": {
99
27
  "import": "./dist/visx/group/index.js",
100
28
  "require": "./dist/visx/group/index.cjs"
@@ -115,51 +43,6 @@
115
43
  ".": [
116
44
  "./dist/index.d.ts"
117
45
  ],
118
- "bar-chart": [
119
- "./dist/charts/bar-chart/index.d.ts"
120
- ],
121
- "bar-list-chart": [
122
- "./dist/charts/bar-list-chart/index.d.ts"
123
- ],
124
- "conversion-funnel-chart": [
125
- "./dist/charts/conversion-funnel-chart/index.d.ts"
126
- ],
127
- "geo-chart": [
128
- "./dist/charts/geo-chart/index.d.ts"
129
- ],
130
- "hooks": [
131
- "./dist/hooks/index.d.ts"
132
- ],
133
- "leaderboard-chart": [
134
- "./dist/charts/leaderboard-chart/index.d.ts"
135
- ],
136
- "legend": [
137
- "./dist/components/legend/index.d.ts"
138
- ],
139
- "line-chart": [
140
- "./dist/charts/line-chart/index.d.ts"
141
- ],
142
- "pie-chart": [
143
- "./dist/charts/pie-chart/index.d.ts"
144
- ],
145
- "pie-semi-circle-chart": [
146
- "./dist/charts/pie-semi-circle-chart/index.d.ts"
147
- ],
148
- "sparkline": [
149
- "./dist/charts/sparkline/index.d.ts"
150
- ],
151
- "providers": [
152
- "./dist/providers/index.d.ts"
153
- ],
154
- "tooltip": [
155
- "./dist/components/tooltip/index.d.ts"
156
- ],
157
- "trend-indicator": [
158
- "./dist/components/trend-indicator/index.d.ts"
159
- ],
160
- "utils": [
161
- "./dist/utils/index.d.ts"
162
- ],
163
46
  "visx/group": [
164
47
  "./dist/visx/group/index.d.ts"
165
48
  ],
@@ -180,7 +63,7 @@
180
63
  "typecheck": "tsgo --noEmit"
181
64
  },
182
65
  "dependencies": {
183
- "@automattic/number-formatters": "^1.1.1",
66
+ "@automattic/number-formatters": "^1.1.2",
184
67
  "@babel/runtime": "7.28.6",
185
68
  "@react-spring/web": "9.7.5",
186
69
  "@visx/annotation": "^3.12.0",
@@ -200,8 +83,8 @@
200
83
  "@visx/vendor": "^3.12.0",
201
84
  "@visx/xychart": "^3.12.0",
202
85
  "@wordpress/i18n": "^6.0.0",
203
- "@wordpress/theme": "0.7.0",
204
- "@wordpress/ui": "0.7.0",
86
+ "@wordpress/theme": "0.9.0",
87
+ "@wordpress/ui": "0.9.0",
205
88
  "clsx": "2.1.1",
206
89
  "date-fns": "^4.1.0",
207
90
  "deepmerge": "4.3.1",
@@ -215,8 +98,8 @@
215
98
  "@babel/core": "7.29.0",
216
99
  "@babel/preset-react": "7.28.5",
217
100
  "@babel/preset-typescript": "7.28.5",
218
- "@storybook/addon-docs": "10.2.11",
219
- "@storybook/react": "10.2.11",
101
+ "@storybook/addon-docs": "10.3.1",
102
+ "@storybook/react": "10.3.1",
220
103
  "@testing-library/dom": "^10.0.0",
221
104
  "@testing-library/jest-dom": "^6.0.0",
222
105
  "@testing-library/react": "^16.0.0",
@@ -226,8 +109,8 @@
226
109
  "@types/react-dom": "18.3.7",
227
110
  "@typescript/native-preview": "7.0.0-dev.20260225.1",
228
111
  "@visx/glyph": "3.12.0",
229
- "@wordpress/components": "32.2.0",
230
- "@wordpress/element": "6.40.0",
112
+ "@wordpress/components": "32.4.0",
113
+ "@wordpress/element": "6.42.0",
231
114
  "babel-jest": "30.2.0",
232
115
  "babel-plugin-react-remove-properties": "^0.3.1",
233
116
  "esbuild": "0.25.9",
@@ -241,7 +124,7 @@
241
124
  "react": "18.3.1",
242
125
  "react-dom": "18.3.1",
243
126
  "sass-embedded": "1.97.3",
244
- "storybook": "10.2.11",
127
+ "storybook": "10.3.1",
245
128
  "tsup": "8.5.1",
246
129
  "typescript": "5.9.3"
247
130
  },
@@ -1,10 +1,5 @@
1
1
  .bar-chart {
2
2
 
3
- &__svg-wrapper {
4
- flex: 1;
5
- min-height: 0; // Required for flex shrinking
6
- }
7
-
8
3
  svg {
9
4
  overflow: visible;
10
5
  }
@@ -2,7 +2,6 @@ import { formatNumber } from '@automattic/number-formatters';
2
2
  import { PatternLines, PatternCircles, PatternWaves, PatternHexagons } from '@visx/pattern';
3
3
  import { Axis, BarSeries, BarGroup, Grid, XYChart } from '@visx/xychart';
4
4
  import { __ } from '@wordpress/i18n';
5
- import { Stack } from '@wordpress/ui';
6
5
  import clsx from 'clsx';
7
6
  import { useCallback, useContext, useState, useRef, useMemo } from 'react';
8
7
  import { Legend, useChartLegendItems } from '../../components/legend';
@@ -12,8 +11,6 @@ import {
12
11
  useChartDataTransform,
13
12
  useZeroValueDisplay,
14
13
  useChartMargin,
15
- useElementSize,
16
- useHasLegendChild,
17
14
  usePrefersReducedMotion,
18
15
  } from '../../hooks';
19
16
  import {
@@ -21,11 +18,13 @@ import {
21
18
  useChartId,
22
19
  useChartRegistration,
23
20
  useGlobalChartsContext,
24
- useGlobalChartsTheme,
25
21
  GlobalChartsContext,
26
22
  } from '../../providers';
27
23
  import { attachSubComponents } from '../../utils';
24
+ import { useChartChildren } from '../private/chart-composition';
25
+ import { ChartLayout } from '../private/chart-layout';
28
26
  import { SingleChartContext } from '../private/single-chart-context';
27
+ import { SvgEmptyState } from '../private/svg-empty-state';
29
28
  import { withResponsive } from '../private/with-responsive';
30
29
  import styles from './bar-chart.module.scss';
31
30
  import { useBarChartOptions } from './private';
@@ -39,7 +38,6 @@ export interface BarChartProps extends BaseChartProps< SeriesData[] > {
39
38
  orientation?: 'horizontal' | 'vertical';
40
39
  withPatterns?: boolean;
41
40
  showZeroValues?: boolean;
42
- legendInteractive?: boolean;
43
41
  children?: ReactNode;
44
42
  }
45
43
 
@@ -85,24 +83,18 @@ const BarChartInternal: FC< BarChartProps > = ( {
85
83
  margin,
86
84
  withTooltips = false,
87
85
  showLegend = false,
88
- legendOrientation = 'horizontal',
89
- legendPosition = 'bottom',
90
- legendAlignment = 'center',
91
- legendMaxWidth,
92
- legendTextOverflow = 'wrap',
93
- legendItemClassName,
94
- legendShape = 'rect',
86
+ legend = {},
95
87
  gridVisibility: gridVisibilityProp,
96
88
  renderTooltip,
97
89
  options = {},
98
90
  orientation = 'vertical',
99
91
  withPatterns = false,
100
92
  showZeroValues = false,
101
- legendInteractive = false,
102
93
  animation,
103
94
  children,
104
95
  gap = 'md',
105
96
  } ) => {
97
+ const legendInteractive = legend.interactive ?? false;
106
98
  const horizontal = orientation === 'horizontal';
107
99
  const chartId = useChartId( providedChartId );
108
100
  const theme = useXYChartTheme( data );
@@ -120,18 +112,19 @@ const BarChartInternal: FC< BarChartProps > = ( {
120
112
  const legendItems = useChartLegendItems( dataSorted );
121
113
  const chartOptions = useBarChartOptions( dataWithVisibleZeros, horizontal, options );
122
114
  const defaultMargin = useChartMargin( height, chartOptions, dataSorted, theme, horizontal );
123
- const [ svgWrapperRef, , svgWrapperHeight ] = useElementSize< HTMLDivElement >();
124
115
  const chartRef = useRef< HTMLDivElement >( null );
125
116
 
126
- // Check if children contain a Legend component (composition pattern)
127
- const hasLegendChild = useHasLegendChild( children );
117
+ // Process children for composition API (Legend, etc.)
118
+ const { legendChildren, nonLegendChildren } = useChartChildren( children, 'BarChart' );
119
+ const [ measuredChartHeight, setMeasuredChartHeight ] = useState< number | undefined >();
128
120
 
129
- // Use the measured SVG wrapper height, falling back to the passed height if provided.
130
- // When there's a legend (via prop or composition), we must wait for measurement because
131
- // the legend takes space and the svg-wrapper height will be less than the total height.
132
- const chartHeight = svgWrapperHeight > 0 ? svgWrapperHeight : height;
133
- const hasLegend = showLegend || hasLegendChild;
134
- const isWaitingForMeasurement = hasLegend ? svgWrapperHeight === 0 : ! chartHeight;
121
+ const handleContentHeightChange = useCallback(
122
+ ( contentHeight: number ) => {
123
+ const chartHeight = contentHeight > 0 ? contentHeight : height;
124
+ setMeasuredChartHeight( chartHeight );
125
+ },
126
+ [ height ]
127
+ );
135
128
  const [ selectedIndex, setSelectedIndex ] = useState< number | undefined >( undefined );
136
129
  const [ isNavigating, setIsNavigating ] = useState( false );
137
130
 
@@ -149,7 +142,6 @@ const BarChartInternal: FC< BarChartProps > = ( {
149
142
  } );
150
143
 
151
144
  const { getElementStyles, isSeriesVisible } = useGlobalChartsContext();
152
- const providerTheme = useGlobalChartsTheme();
153
145
 
154
146
  // Add visibility information to series when using interactive legends
155
147
  const seriesWithVisibility = useMemo( () => {
@@ -327,15 +319,18 @@ const BarChartInternal: FC< BarChartProps > = ( {
327
319
  const gridVisibility = gridVisibilityProp ?? chartOptions.gridVisibility;
328
320
  const highlightedBarStyle = createKeyboardHighlightStyle();
329
321
 
322
+ const legendPosition = legend.position ?? 'bottom';
330
323
  const legendElement = showLegend && (
331
324
  <Legend
332
- orientation={ legendOrientation }
325
+ orientation={ legend.orientation ?? 'horizontal' }
333
326
  position={ legendPosition }
334
- alignment={ legendAlignment }
335
- labelStyles={ { maxWidth: legendMaxWidth, textOverflow: legendTextOverflow } }
336
- itemClassName={ legendItemClassName }
327
+ alignment={ legend.alignment ?? 'center' }
328
+ labelStyles={ legend.labelStyles }
329
+ itemClassName={ legend.itemClassName }
330
+ itemStyles={ legend.itemStyles }
331
+ shapeStyles={ legend.shapeStyles }
337
332
  className={ styles[ 'bar-chart__legend' ] }
338
- shape={ legendShape }
333
+ shape={ legend.shape ?? 'rect' }
339
334
  chartId={ chartId }
340
335
  interactive={ legendInteractive }
341
336
  />
@@ -346,11 +341,13 @@ const BarChartInternal: FC< BarChartProps > = ( {
346
341
  value={ {
347
342
  chartId,
348
343
  chartWidth: width,
349
- chartHeight,
344
+ chartHeight: measuredChartHeight || 0,
350
345
  } }
351
346
  >
352
- <Stack
353
- direction="column"
347
+ <ChartLayout
348
+ legendPosition={ legendPosition }
349
+ legendElement={ legendElement }
350
+ legendChildren={ legendChildren }
354
351
  gap={ gap }
355
352
  className={ clsx(
356
353
  'bar-chart',
@@ -361,131 +358,127 @@ const BarChartInternal: FC< BarChartProps > = ( {
361
358
  },
362
359
  className
363
360
  ) }
361
+ style={ { width, height } }
364
362
  data-testid="bar-chart"
365
- style={ {
366
- width,
367
- height,
368
- visibility: isWaitingForMeasurement ? 'hidden' : 'visible',
369
- } }
370
363
  data-chart-id={ `bar-chart-${ chartId }` }
364
+ trailingContent={ nonLegendChildren }
365
+ onContentHeightChange={ handleContentHeightChange }
371
366
  >
372
- { legendPosition === 'top' && legendElement }
373
-
374
- <div
375
- className={ styles[ 'bar-chart__svg-wrapper' ] }
376
- ref={ svgWrapperRef }
377
- role="grid"
378
- aria-label={ __( 'Bar chart', 'jetpack-charts' ) }
379
- tabIndex={ 0 }
380
- onKeyDown={ onChartKeyDown }
381
- onFocus={ onChartFocus }
382
- onBlur={ onChartBlur }
383
- >
384
- { ! isWaitingForMeasurement && (
385
- <div ref={ chartRef }>
386
- <XYChart
387
- theme={ theme }
388
- width={ width }
389
- height={ chartHeight }
390
- margin={ {
391
- ...defaultMargin,
392
- ...margin,
393
- } }
394
- xScale={ chartOptions.xScale }
395
- yScale={ chartOptions.yScale }
396
- horizontal={ horizontal }
397
- pointerEventsDataKey="nearest"
398
- >
399
- <Grid
400
- columns={ gridVisibility.includes( 'y' ) }
401
- rows={ gridVisibility.includes( 'x' ) }
402
- numTicks={ 4 }
403
- />
404
-
405
- { withPatterns && (
406
- <>
407
- <defs data-testid="bar-chart-patterns">
408
- { dataSorted.map( ( seriesData, index ) =>
409
- renderPattern(
410
- index,
411
- getElementStyles( { data: seriesData, index } ).color
412
- )
413
- ) }
414
- </defs>
415
- <style>
416
- { dataSorted.map( ( seriesData, index ) =>
417
- createPatternBorderStyle(
418
- index,
419
- getElementStyles( { data: seriesData, index } ).color
420
- )
421
- ) }
422
- </style>
423
- </>
424
- ) }
425
-
426
- { highlightedBarStyle && <style>{ highlightedBarStyle }</style> }
427
-
428
- { allSeriesHidden ? (
429
- <text
430
- x={ width / 2 }
431
- y={ chartHeight / 2 }
432
- textAnchor="middle"
433
- fill={ providerTheme.gridStyles?.stroke || '#ccc' }
434
- fontSize="14"
435
- fontFamily="-apple-system,BlinkMacSystemFont,Roboto,Helvetica Neue,sans-serif"
367
+ { ( { contentHeight } ) => {
368
+ const chartHeight = contentHeight > 0 ? contentHeight : height;
369
+
370
+ return (
371
+ <div
372
+ role="grid"
373
+ aria-label={ __( 'Bar chart', 'jetpack-charts' ) }
374
+ tabIndex={ 0 }
375
+ onKeyDown={ onChartKeyDown }
376
+ onFocus={ onChartFocus }
377
+ onBlur={ onChartBlur }
378
+ >
379
+ { chartHeight > 0 && (
380
+ <div ref={ chartRef }>
381
+ <XYChart
382
+ theme={ theme }
383
+ width={ width }
384
+ height={ chartHeight }
385
+ margin={ {
386
+ ...defaultMargin,
387
+ ...margin,
388
+ } }
389
+ xScale={ chartOptions.xScale }
390
+ yScale={ chartOptions.yScale }
391
+ horizontal={ horizontal }
392
+ pointerEventsDataKey="nearest"
436
393
  >
437
- { __(
438
- 'All series are hidden. Click legend items to show data.',
439
- 'jetpack-charts'
394
+ <Grid
395
+ columns={ gridVisibility.includes( 'y' ) }
396
+ rows={ gridVisibility.includes( 'x' ) }
397
+ numTicks={ 4 }
398
+ />
399
+
400
+ { withPatterns && (
401
+ <>
402
+ <defs data-testid="bar-chart-patterns">
403
+ { dataSorted.map( ( seriesData, index ) =>
404
+ renderPattern(
405
+ index,
406
+ getElementStyles( { data: seriesData, index } ).color
407
+ )
408
+ ) }
409
+ </defs>
410
+ <style>
411
+ { dataSorted.map( ( seriesData, index ) =>
412
+ createPatternBorderStyle(
413
+ index,
414
+ getElementStyles( { data: seriesData, index } ).color
415
+ )
416
+ ) }
417
+ </style>
418
+ </>
440
419
  ) }
441
- </text>
442
- ) : null }
443
-
444
- <BarGroup padding={ chartOptions.barGroup.padding }>
445
- { seriesWithVisibility.map( ( { series: seriesData, index, isVisible } ) => {
446
- // Skip rendering invisible series
447
- if ( ! isVisible ) {
448
- return null;
449
- }
450
-
451
- return (
452
- <BarSeries
453
- key={ seriesData?.label }
454
- dataKey={ seriesData?.label }
455
- data={ seriesData.data as DataPointDate[] }
456
- yAccessor={ chartOptions.accessors.yAccessor }
457
- xAccessor={ chartOptions.accessors.xAccessor }
458
- colorAccessor={ getBarBackground( index ) }
420
+
421
+ { highlightedBarStyle && <style>{ highlightedBarStyle }</style> }
422
+
423
+ { allSeriesHidden ? (
424
+ <SvgEmptyState
425
+ x={ width / 2 }
426
+ y={ chartHeight / 2 }
427
+ width={ width }
428
+ height={ chartHeight }
429
+ >
430
+ { __(
431
+ 'All series are hidden. Click legend items to show data.',
432
+ 'jetpack-charts'
433
+ ) }
434
+ </SvgEmptyState>
435
+ ) : null }
436
+
437
+ <BarGroup padding={ chartOptions.barGroup.padding }>
438
+ { seriesWithVisibility.map( ( { series: seriesData, index, isVisible } ) => {
439
+ // Skip rendering invisible series
440
+ if ( ! isVisible ) {
441
+ return null;
442
+ }
443
+
444
+ return (
445
+ <BarSeries
446
+ key={ seriesData?.label }
447
+ dataKey={ seriesData?.label }
448
+ data={ seriesData.data as DataPointDate[] }
449
+ yAccessor={ chartOptions.accessors.yAccessor }
450
+ xAccessor={ chartOptions.accessors.xAccessor }
451
+ colorAccessor={ getBarBackground( index ) }
452
+ />
453
+ );
454
+ } ) }
455
+ </BarGroup>
456
+
457
+ <Axis { ...chartOptions.axis.x } />
458
+ <Axis { ...chartOptions.axis.y } />
459
+
460
+ { withTooltips && (
461
+ <AccessibleTooltip
462
+ detectBounds
463
+ snapTooltipToDatumX
464
+ snapTooltipToDatumY
465
+ renderTooltip={ renderTooltip || renderDefaultTooltip }
466
+ selectedIndex={ selectedIndex }
467
+ tooltipRef={ tooltipRef }
468
+ keyboardFocusedClassName={
469
+ styles[ 'bar-chart__tooltip--keyboard-focused' ]
470
+ }
471
+ series={ data }
472
+ mode="individual"
459
473
  />
460
- );
461
- } ) }
462
- </BarGroup>
463
-
464
- <Axis { ...chartOptions.axis.x } />
465
- <Axis { ...chartOptions.axis.y } />
466
-
467
- { withTooltips && (
468
- <AccessibleTooltip
469
- detectBounds
470
- snapTooltipToDatumX
471
- snapTooltipToDatumY
472
- renderTooltip={ renderTooltip || renderDefaultTooltip }
473
- selectedIndex={ selectedIndex }
474
- tooltipRef={ tooltipRef }
475
- keyboardFocusedClassName={ styles[ 'bar-chart__tooltip--keyboard-focused' ] }
476
- series={ data }
477
- mode="individual"
478
- />
479
- ) }
480
- </XYChart>
474
+ ) }
475
+ </XYChart>
476
+ </div>
477
+ ) }
481
478
  </div>
482
- ) }
483
- </div>
484
-
485
- { legendPosition === 'bottom' && legendElement }
486
-
487
- { children }
488
- </Stack>
479
+ );
480
+ } }
481
+ </ChartLayout>
489
482
  </SingleChartContext.Provider>
490
483
  );
491
484
  };