@automattic/charts 0.58.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 (253) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +7 -54
  3. package/dist/index.cjs +9606 -22
  4. package/dist/index.cjs.map +1 -1
  5. package/dist/index.css +20 -25
  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 -56
  10. package/dist/index.js.map +1 -1
  11. package/package.json +8 -125
  12. package/src/charts/bar-chart/bar-chart.module.scss +0 -5
  13. package/src/charts/bar-chart/bar-chart.tsx +131 -137
  14. package/src/charts/leaderboard-chart/leaderboard-chart.tsx +23 -40
  15. package/src/charts/line-chart/line-chart.module.scss +0 -5
  16. package/src/charts/line-chart/line-chart.tsx +190 -183
  17. package/src/charts/line-chart/private/line-chart-annotations-overlay.tsx +1 -2
  18. package/src/charts/pie-chart/pie-chart.module.scss +2 -10
  19. package/src/charts/pie-chart/pie-chart.tsx +198 -199
  20. package/src/charts/pie-chart/test/composition-api.test.tsx +3 -3
  21. package/src/charts/pie-chart/test/pie-chart.test.tsx +42 -35
  22. package/src/charts/pie-semi-circle-chart/pie-semi-circle-chart.module.scss +2 -8
  23. package/src/charts/pie-semi-circle-chart/pie-semi-circle-chart.tsx +155 -155
  24. package/src/charts/pie-semi-circle-chart/test/pie-semi-circle-chart.test.tsx +25 -25
  25. package/src/charts/private/chart-layout/chart-layout.module.scss +7 -0
  26. package/src/charts/private/chart-layout/chart-layout.tsx +106 -0
  27. package/src/charts/private/chart-layout/index.ts +2 -0
  28. package/src/charts/private/chart-layout/test/chart-layout.test.tsx +167 -0
  29. package/src/charts/private/single-chart-context/single-chart-context.tsx +2 -2
  30. package/src/charts/private/svg-empty-state/index.ts +1 -0
  31. package/src/charts/private/svg-empty-state/svg-empty-state.module.scss +7 -0
  32. package/src/charts/private/svg-empty-state/svg-empty-state.tsx +40 -0
  33. package/src/components/legend/hooks/test/use-chart-legend-items.test.tsx +12 -8
  34. package/src/components/legend/hooks/use-chart-legend-items.ts +12 -13
  35. package/src/components/legend/legend.tsx +33 -8
  36. package/src/components/legend/test/legend.test.tsx +93 -1
  37. package/src/hooks/index.ts +1 -0
  38. package/src/hooks/use-data-with-percentages.ts +24 -0
  39. package/src/hooks/use-interactive-legend-data.ts +18 -15
  40. package/src/index.ts +65 -2
  41. package/src/providers/chart-context/global-charts-provider.tsx +7 -1
  42. package/src/providers/chart-context/hooks/use-chart-registration.ts +2 -1
  43. package/src/providers/chart-context/types.ts +2 -2
  44. package/src/types.ts +27 -7
  45. package/src/utils/test/resolve-css-var.test.ts +2 -0
  46. package/dist/base-tooltip-DOq93wjU.d.cts +0 -38
  47. package/dist/base-tooltip-DOq93wjU.d.ts +0 -38
  48. package/dist/charts/bar-chart/index.cjs +0 -17
  49. package/dist/charts/bar-chart/index.cjs.map +0 -1
  50. package/dist/charts/bar-chart/index.css +0 -141
  51. package/dist/charts/bar-chart/index.css.map +0 -1
  52. package/dist/charts/bar-chart/index.d.cts +0 -36
  53. package/dist/charts/bar-chart/index.d.ts +0 -36
  54. package/dist/charts/bar-chart/index.js +0 -17
  55. package/dist/charts/bar-chart/index.js.map +0 -1
  56. package/dist/charts/bar-list-chart/index.cjs +0 -18
  57. package/dist/charts/bar-list-chart/index.cjs.map +0 -1
  58. package/dist/charts/bar-list-chart/index.css +0 -141
  59. package/dist/charts/bar-list-chart/index.css.map +0 -1
  60. package/dist/charts/bar-list-chart/index.d.cts +0 -92
  61. package/dist/charts/bar-list-chart/index.d.ts +0 -92
  62. package/dist/charts/bar-list-chart/index.js +0 -18
  63. package/dist/charts/bar-list-chart/index.js.map +0 -1
  64. package/dist/charts/conversion-funnel-chart/index.cjs +0 -11
  65. package/dist/charts/conversion-funnel-chart/index.cjs.map +0 -1
  66. package/dist/charts/conversion-funnel-chart/index.css +0 -157
  67. package/dist/charts/conversion-funnel-chart/index.css.map +0 -1
  68. package/dist/charts/conversion-funnel-chart/index.d.cts +0 -97
  69. package/dist/charts/conversion-funnel-chart/index.d.ts +0 -97
  70. package/dist/charts/conversion-funnel-chart/index.js +0 -11
  71. package/dist/charts/conversion-funnel-chart/index.js.map +0 -1
  72. package/dist/charts/geo-chart/index.cjs +0 -13
  73. package/dist/charts/geo-chart/index.cjs.map +0 -1
  74. package/dist/charts/geo-chart/index.css +0 -23
  75. package/dist/charts/geo-chart/index.css.map +0 -1
  76. package/dist/charts/geo-chart/index.d.cts +0 -67
  77. package/dist/charts/geo-chart/index.d.ts +0 -67
  78. package/dist/charts/geo-chart/index.js +0 -13
  79. package/dist/charts/geo-chart/index.js.map +0 -1
  80. package/dist/charts/leaderboard-chart/index.cjs +0 -21
  81. package/dist/charts/leaderboard-chart/index.cjs.map +0 -1
  82. package/dist/charts/leaderboard-chart/index.css +0 -160
  83. package/dist/charts/leaderboard-chart/index.css.map +0 -1
  84. package/dist/charts/leaderboard-chart/index.d.cts +0 -46
  85. package/dist/charts/leaderboard-chart/index.d.ts +0 -46
  86. package/dist/charts/leaderboard-chart/index.js +0 -21
  87. package/dist/charts/leaderboard-chart/index.js.map +0 -1
  88. package/dist/charts/line-chart/index.cjs +0 -17
  89. package/dist/charts/line-chart/index.cjs.map +0 -1
  90. package/dist/charts/line-chart/index.css +0 -213
  91. package/dist/charts/line-chart/index.css.map +0 -1
  92. package/dist/charts/line-chart/index.d.cts +0 -98
  93. package/dist/charts/line-chart/index.d.ts +0 -98
  94. package/dist/charts/line-chart/index.js +0 -17
  95. package/dist/charts/line-chart/index.js.map +0 -1
  96. package/dist/charts/pie-chart/index.cjs +0 -19
  97. package/dist/charts/pie-chart/index.cjs.map +0 -1
  98. package/dist/charts/pie-chart/index.css +0 -131
  99. package/dist/charts/pie-chart/index.css.map +0 -1
  100. package/dist/charts/pie-chart/index.d.cts +0 -91
  101. package/dist/charts/pie-chart/index.d.ts +0 -91
  102. package/dist/charts/pie-chart/index.js +0 -19
  103. package/dist/charts/pie-chart/index.js.map +0 -1
  104. package/dist/charts/pie-semi-circle-chart/index.cjs +0 -18
  105. package/dist/charts/pie-semi-circle-chart/index.cjs.map +0 -1
  106. package/dist/charts/pie-semi-circle-chart/index.css +0 -132
  107. package/dist/charts/pie-semi-circle-chart/index.css.map +0 -1
  108. package/dist/charts/pie-semi-circle-chart/index.d.cts +0 -88
  109. package/dist/charts/pie-semi-circle-chart/index.d.ts +0 -88
  110. package/dist/charts/pie-semi-circle-chart/index.js +0 -18
  111. package/dist/charts/pie-semi-circle-chart/index.js.map +0 -1
  112. package/dist/charts/sparkline/index.cjs +0 -18
  113. package/dist/charts/sparkline/index.cjs.map +0 -1
  114. package/dist/charts/sparkline/index.css +0 -230
  115. package/dist/charts/sparkline/index.css.map +0 -1
  116. package/dist/charts/sparkline/index.d.cts +0 -113
  117. package/dist/charts/sparkline/index.d.ts +0 -113
  118. package/dist/charts/sparkline/index.js +0 -18
  119. package/dist/charts/sparkline/index.js.map +0 -1
  120. package/dist/chunk-2A34OA5O.cjs +0 -51
  121. package/dist/chunk-2A34OA5O.cjs.map +0 -1
  122. package/dist/chunk-2I67QUIV.js +0 -895
  123. package/dist/chunk-2I67QUIV.js.map +0 -1
  124. package/dist/chunk-2ICEEQOC.js +0 -1071
  125. package/dist/chunk-2ICEEQOC.js.map +0 -1
  126. package/dist/chunk-4B7BL2DD.js +0 -120
  127. package/dist/chunk-4B7BL2DD.js.map +0 -1
  128. package/dist/chunk-4OXMTKAL.js +0 -401
  129. package/dist/chunk-4OXMTKAL.js.map +0 -1
  130. package/dist/chunk-ASLARV7L.cjs +0 -81
  131. package/dist/chunk-ASLARV7L.cjs.map +0 -1
  132. package/dist/chunk-B6NLZFRW.js +0 -617
  133. package/dist/chunk-B6NLZFRW.js.map +0 -1
  134. package/dist/chunk-BBAUQOW6.cjs +0 -120
  135. package/dist/chunk-BBAUQOW6.cjs.map +0 -1
  136. package/dist/chunk-BPYKWMI7.js +0 -194
  137. package/dist/chunk-BPYKWMI7.js.map +0 -1
  138. package/dist/chunk-CMMHCTBX.cjs +0 -373
  139. package/dist/chunk-CMMHCTBX.cjs.map +0 -1
  140. package/dist/chunk-CPPXJATQ.cjs +0 -1071
  141. package/dist/chunk-CPPXJATQ.cjs.map +0 -1
  142. package/dist/chunk-DKU775VC.js +0 -219
  143. package/dist/chunk-DKU775VC.js.map +0 -1
  144. package/dist/chunk-GRA7Y2ZG.cjs +0 -401
  145. package/dist/chunk-GRA7Y2ZG.cjs.map +0 -1
  146. package/dist/chunk-I2276W3I.cjs +0 -66
  147. package/dist/chunk-I2276W3I.cjs.map +0 -1
  148. package/dist/chunk-JJIMABHT.js +0 -351
  149. package/dist/chunk-JJIMABHT.js.map +0 -1
  150. package/dist/chunk-KJHWXOCZ.js +0 -421
  151. package/dist/chunk-KJHWXOCZ.js.map +0 -1
  152. package/dist/chunk-KRWGSOJ2.js +0 -91
  153. package/dist/chunk-KRWGSOJ2.js.map +0 -1
  154. package/dist/chunk-KXRWNFQJ.js +0 -51
  155. package/dist/chunk-KXRWNFQJ.js.map +0 -1
  156. package/dist/chunk-LTFH7SEG.js +0 -373
  157. package/dist/chunk-LTFH7SEG.js.map +0 -1
  158. package/dist/chunk-MUNOKLLE.js +0 -165
  159. package/dist/chunk-MUNOKLLE.js.map +0 -1
  160. package/dist/chunk-MXGLYWVP.cjs +0 -351
  161. package/dist/chunk-MXGLYWVP.cjs.map +0 -1
  162. package/dist/chunk-OP6PHB2U.js +0 -81
  163. package/dist/chunk-OP6PHB2U.js.map +0 -1
  164. package/dist/chunk-OYC34VTO.cjs +0 -3957
  165. package/dist/chunk-OYC34VTO.cjs.map +0 -1
  166. package/dist/chunk-PQL5I3F6.cjs +0 -421
  167. package/dist/chunk-PQL5I3F6.cjs.map +0 -1
  168. package/dist/chunk-REZTQ4PH.cjs +0 -488
  169. package/dist/chunk-REZTQ4PH.cjs.map +0 -1
  170. package/dist/chunk-TZRUHQOH.cjs +0 -91
  171. package/dist/chunk-TZRUHQOH.cjs.map +0 -1
  172. package/dist/chunk-UTYVIOWZ.js +0 -3957
  173. package/dist/chunk-UTYVIOWZ.js.map +0 -1
  174. package/dist/chunk-W2LDIX26.cjs +0 -165
  175. package/dist/chunk-W2LDIX26.cjs.map +0 -1
  176. package/dist/chunk-WSG64BVN.cjs +0 -219
  177. package/dist/chunk-WSG64BVN.cjs.map +0 -1
  178. package/dist/chunk-WTQYGUNF.js +0 -400
  179. package/dist/chunk-WTQYGUNF.js.map +0 -1
  180. package/dist/chunk-WYK7EL5R.cjs +0 -895
  181. package/dist/chunk-WYK7EL5R.cjs.map +0 -1
  182. package/dist/chunk-XC4KHJYX.cjs +0 -617
  183. package/dist/chunk-XC4KHJYX.cjs.map +0 -1
  184. package/dist/chunk-XVBH5XHE.cjs +0 -400
  185. package/dist/chunk-XVBH5XHE.cjs.map +0 -1
  186. package/dist/chunk-XWYZIFZW.js +0 -66
  187. package/dist/chunk-XWYZIFZW.js.map +0 -1
  188. package/dist/chunk-Y3NNQMAX.cjs +0 -194
  189. package/dist/chunk-Y3NNQMAX.cjs.map +0 -1
  190. package/dist/chunk-YAFQVVDI.js +0 -488
  191. package/dist/chunk-YAFQVVDI.js.map +0 -1
  192. package/dist/components/legend/index.cjs +0 -12
  193. package/dist/components/legend/index.cjs.map +0 -1
  194. package/dist/components/legend/index.css +0 -91
  195. package/dist/components/legend/index.css.map +0 -1
  196. package/dist/components/legend/index.d.cts +0 -37
  197. package/dist/components/legend/index.d.ts +0 -37
  198. package/dist/components/legend/index.js +0 -12
  199. package/dist/components/legend/index.js.map +0 -1
  200. package/dist/components/tooltip/index.cjs +0 -12
  201. package/dist/components/tooltip/index.cjs.map +0 -1
  202. package/dist/components/tooltip/index.css +0 -13
  203. package/dist/components/tooltip/index.css.map +0 -1
  204. package/dist/components/tooltip/index.d.cts +0 -71
  205. package/dist/components/tooltip/index.d.ts +0 -71
  206. package/dist/components/tooltip/index.js +0 -12
  207. package/dist/components/tooltip/index.js.map +0 -1
  208. package/dist/components/trend-indicator/index.cjs +0 -8
  209. package/dist/components/trend-indicator/index.cjs.map +0 -1
  210. package/dist/components/trend-indicator/index.css +0 -27
  211. package/dist/components/trend-indicator/index.css.map +0 -1
  212. package/dist/components/trend-indicator/index.d.cts +0 -44
  213. package/dist/components/trend-indicator/index.d.ts +0 -44
  214. package/dist/components/trend-indicator/index.js +0 -8
  215. package/dist/components/trend-indicator/index.js.map +0 -1
  216. package/dist/format-metric-value-MXm5DtQ_.d.cts +0 -24
  217. package/dist/format-metric-value-MXm5DtQ_.d.ts +0 -24
  218. package/dist/hooks/index.cjs +0 -29
  219. package/dist/hooks/index.cjs.map +0 -1
  220. package/dist/hooks/index.css +0 -9
  221. package/dist/hooks/index.css.map +0 -1
  222. package/dist/hooks/index.d.cts +0 -264
  223. package/dist/hooks/index.d.ts +0 -264
  224. package/dist/hooks/index.js +0 -29
  225. package/dist/hooks/index.js.map +0 -1
  226. package/dist/leaderboard-chart-BSbg0ufV.d.cts +0 -79
  227. package/dist/leaderboard-chart-odEYxxEC.d.ts +0 -79
  228. package/dist/legend-DFkosEvC.d.cts +0 -9
  229. package/dist/legend-DLswHhOk.d.ts +0 -9
  230. package/dist/providers/index.cjs +0 -21
  231. package/dist/providers/index.cjs.map +0 -1
  232. package/dist/providers/index.css +0 -9
  233. package/dist/providers/index.css.map +0 -1
  234. package/dist/providers/index.d.cts +0 -28
  235. package/dist/providers/index.d.ts +0 -28
  236. package/dist/providers/index.js +0 -21
  237. package/dist/providers/index.js.map +0 -1
  238. package/dist/themes-D0qc5JaW.d.cts +0 -67
  239. package/dist/themes-itO4Ht5g.d.ts +0 -67
  240. package/dist/types-B5f6XQ7Q.d.cts +0 -19
  241. package/dist/types-BsHooDbM.d.ts +0 -19
  242. package/dist/types-BuSrRM4p.d.ts +0 -49
  243. package/dist/types-ChOUI9-N.d.cts +0 -545
  244. package/dist/types-ChOUI9-N.d.ts +0 -545
  245. package/dist/types-Dfw9VOKI.d.cts +0 -49
  246. package/dist/utils/index.cjs +0 -44
  247. package/dist/utils/index.cjs.map +0 -1
  248. package/dist/utils/index.d.cts +0 -226
  249. package/dist/utils/index.d.ts +0 -226
  250. package/dist/utils/index.js +0 -44
  251. package/dist/utils/index.js.map +0 -1
  252. package/dist/with-responsive-CNfhzAUu.d.cts +0 -18
  253. package/dist/with-responsive-CNfhzAUu.d.ts +0 -18
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@automattic/charts",
3
- "version": "0.58.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
  ],
@@ -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.8.0",
204
- "@wordpress/ui": "0.8.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.3.0",
230
- "@wordpress/element": "6.41.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,7 +11,6 @@ import {
12
11
  useChartDataTransform,
13
12
  useZeroValueDisplay,
14
13
  useChartMargin,
15
- useElementSize,
16
14
  usePrefersReducedMotion,
17
15
  } from '../../hooks';
18
16
  import {
@@ -20,12 +18,13 @@ import {
20
18
  useChartId,
21
19
  useChartRegistration,
22
20
  useGlobalChartsContext,
23
- useGlobalChartsTheme,
24
21
  GlobalChartsContext,
25
22
  } from '../../providers';
26
23
  import { attachSubComponents } from '../../utils';
27
- import { useChartChildren, renderLegendSlot } from '../private/chart-composition';
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';
@@ -113,19 +112,19 @@ const BarChartInternal: FC< BarChartProps > = ( {
113
112
  const legendItems = useChartLegendItems( dataSorted );
114
113
  const chartOptions = useBarChartOptions( dataWithVisibleZeros, horizontal, options );
115
114
  const defaultMargin = useChartMargin( height, chartOptions, dataSorted, theme, horizontal );
116
- const [ svgWrapperRef, , svgWrapperHeight ] = useElementSize< HTMLDivElement >();
117
115
  const chartRef = useRef< HTMLDivElement >( null );
118
116
 
119
117
  // Process children for composition API (Legend, etc.)
120
118
  const { legendChildren, nonLegendChildren } = useChartChildren( children, 'BarChart' );
121
- const hasLegendChild = legendChildren.length > 0;
122
-
123
- // Use the measured SVG wrapper height, falling back to the passed height if provided.
124
- // When there's a legend (via prop or composition), we must wait for measurement because
125
- // the legend takes space and the svg-wrapper height will be less than the total height.
126
- const chartHeight = svgWrapperHeight > 0 ? svgWrapperHeight : height;
127
- const hasLegend = showLegend || hasLegendChild;
128
- const isWaitingForMeasurement = hasLegend ? svgWrapperHeight === 0 : ! chartHeight;
119
+ const [ measuredChartHeight, setMeasuredChartHeight ] = useState< number | undefined >();
120
+
121
+ const handleContentHeightChange = useCallback(
122
+ ( contentHeight: number ) => {
123
+ const chartHeight = contentHeight > 0 ? contentHeight : height;
124
+ setMeasuredChartHeight( chartHeight );
125
+ },
126
+ [ height ]
127
+ );
129
128
  const [ selectedIndex, setSelectedIndex ] = useState< number | undefined >( undefined );
130
129
  const [ isNavigating, setIsNavigating ] = useState( false );
131
130
 
@@ -143,7 +142,6 @@ const BarChartInternal: FC< BarChartProps > = ( {
143
142
  } );
144
143
 
145
144
  const { getElementStyles, isSeriesVisible } = useGlobalChartsContext();
146
- const providerTheme = useGlobalChartsTheme();
147
145
 
148
146
  // Add visibility information to series when using interactive legends
149
147
  const seriesWithVisibility = useMemo( () => {
@@ -343,11 +341,13 @@ const BarChartInternal: FC< BarChartProps > = ( {
343
341
  value={ {
344
342
  chartId,
345
343
  chartWidth: width,
346
- chartHeight,
344
+ chartHeight: measuredChartHeight || 0,
347
345
  } }
348
346
  >
349
- <Stack
350
- direction="column"
347
+ <ChartLayout
348
+ legendPosition={ legendPosition }
349
+ legendElement={ legendElement }
350
+ legendChildren={ legendChildren }
351
351
  gap={ gap }
352
352
  className={ clsx(
353
353
  'bar-chart',
@@ -358,133 +358,127 @@ const BarChartInternal: FC< BarChartProps > = ( {
358
358
  },
359
359
  className
360
360
  ) }
361
+ style={ { width, height } }
361
362
  data-testid="bar-chart"
362
- style={ {
363
- width,
364
- height,
365
- visibility: isWaitingForMeasurement ? 'hidden' : 'visible',
366
- } }
367
363
  data-chart-id={ `bar-chart-${ chartId }` }
364
+ trailingContent={ nonLegendChildren }
365
+ onContentHeightChange={ handleContentHeightChange }
368
366
  >
369
- { legendPosition === 'top' && legendElement }
370
- { renderLegendSlot( legendChildren, 'top' ) }
371
-
372
- <div
373
- className={ styles[ 'bar-chart__svg-wrapper' ] }
374
- ref={ svgWrapperRef }
375
- role="grid"
376
- aria-label={ __( 'Bar chart', 'jetpack-charts' ) }
377
- tabIndex={ 0 }
378
- onKeyDown={ onChartKeyDown }
379
- onFocus={ onChartFocus }
380
- onBlur={ onChartBlur }
381
- >
382
- { ! isWaitingForMeasurement && (
383
- <div ref={ chartRef }>
384
- <XYChart
385
- theme={ theme }
386
- width={ width }
387
- height={ chartHeight }
388
- margin={ {
389
- ...defaultMargin,
390
- ...margin,
391
- } }
392
- xScale={ chartOptions.xScale }
393
- yScale={ chartOptions.yScale }
394
- horizontal={ horizontal }
395
- pointerEventsDataKey="nearest"
396
- >
397
- <Grid
398
- columns={ gridVisibility.includes( 'y' ) }
399
- rows={ gridVisibility.includes( 'x' ) }
400
- numTicks={ 4 }
401
- />
402
-
403
- { withPatterns && (
404
- <>
405
- <defs data-testid="bar-chart-patterns">
406
- { dataSorted.map( ( seriesData, index ) =>
407
- renderPattern(
408
- index,
409
- getElementStyles( { data: seriesData, index } ).color
410
- )
411
- ) }
412
- </defs>
413
- <style>
414
- { dataSorted.map( ( seriesData, index ) =>
415
- createPatternBorderStyle(
416
- index,
417
- getElementStyles( { data: seriesData, index } ).color
418
- )
419
- ) }
420
- </style>
421
- </>
422
- ) }
423
-
424
- { highlightedBarStyle && <style>{ highlightedBarStyle }</style> }
425
-
426
- { allSeriesHidden ? (
427
- <text
428
- x={ width / 2 }
429
- y={ chartHeight / 2 }
430
- textAnchor="middle"
431
- fill={ providerTheme.gridStyles?.stroke || '#ccc' }
432
- fontSize="14"
433
- 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"
434
393
  >
435
- { __(
436
- 'All series are hidden. Click legend items to show data.',
437
- '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
+ </>
438
419
  ) }
439
- </text>
440
- ) : null }
441
-
442
- <BarGroup padding={ chartOptions.barGroup.padding }>
443
- { seriesWithVisibility.map( ( { series: seriesData, index, isVisible } ) => {
444
- // Skip rendering invisible series
445
- if ( ! isVisible ) {
446
- return null;
447
- }
448
-
449
- return (
450
- <BarSeries
451
- key={ seriesData?.label }
452
- dataKey={ seriesData?.label }
453
- data={ seriesData.data as DataPointDate[] }
454
- yAccessor={ chartOptions.accessors.yAccessor }
455
- xAccessor={ chartOptions.accessors.xAccessor }
456
- 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"
457
473
  />
458
- );
459
- } ) }
460
- </BarGroup>
461
-
462
- <Axis { ...chartOptions.axis.x } />
463
- <Axis { ...chartOptions.axis.y } />
464
-
465
- { withTooltips && (
466
- <AccessibleTooltip
467
- detectBounds
468
- snapTooltipToDatumX
469
- snapTooltipToDatumY
470
- renderTooltip={ renderTooltip || renderDefaultTooltip }
471
- selectedIndex={ selectedIndex }
472
- tooltipRef={ tooltipRef }
473
- keyboardFocusedClassName={ styles[ 'bar-chart__tooltip--keyboard-focused' ] }
474
- series={ data }
475
- mode="individual"
476
- />
477
- ) }
478
- </XYChart>
474
+ ) }
475
+ </XYChart>
476
+ </div>
477
+ ) }
479
478
  </div>
480
- ) }
481
- </div>
482
-
483
- { legendPosition === 'bottom' && legendElement }
484
- { renderLegendSlot( legendChildren, 'bottom' ) }
485
-
486
- { nonLegendChildren }
487
- </Stack>
479
+ );
480
+ } }
481
+ </ChartLayout>
488
482
  </SingleChartContext.Provider>
489
483
  );
490
484
  };
@@ -16,7 +16,8 @@ import {
16
16
  useGlobalChartsTheme,
17
17
  } from '../../providers';
18
18
  import { formatMetricValue, attachSubComponents } from '../../utils';
19
- import { useChartChildren, renderLegendSlot } from '../private/chart-composition';
19
+ import { useChartChildren } from '../private/chart-composition';
20
+ import { ChartLayout } from '../private/chart-layout';
20
21
  import { SingleChartContext } from '../private/single-chart-context';
21
22
  import { withResponsive } from '../private/with-responsive';
22
23
  import { useLeaderboardLegendItems } from './hooks';
@@ -246,37 +247,30 @@ const LeaderboardChartInternal: FC< LeaderboardChartProps > = ( {
246
247
  // Handle empty or undefined data
247
248
  if ( ! data || data.length === 0 ) {
248
249
  return (
249
- <SingleChartContext.Provider
250
- value={ {
251
- chartId,
252
- chartWidth: 0, // LeaderboardChart doesn't need specific dimensions
253
- chartHeight: 0,
254
- } }
255
- >
256
- <Stack
257
- direction="column"
258
- data-testid="leaderboard-chart-container"
250
+ <SingleChartContext.Provider value={ { chartId } }>
251
+ <ChartLayout
252
+ legendPosition={ legendPosition }
253
+ legendElement={ false }
254
+ legendChildren={ legendChildren }
259
255
  className={ clsx(
260
256
  styles.leaderboardChart,
261
- { [ styles[ 'leaderboardChart--responsive' ] ]: ! propWidth && ! propHeight },
262
- { [ styles[ 'leaderboardChart--loading' ] ]: loading },
257
+ {
258
+ [ styles[ 'leaderboardChart--responsive' ] ]: ! propWidth && ! propHeight,
259
+ [ styles[ 'leaderboardChart--loading' ] ]: loading,
260
+ },
263
261
  className
264
262
  ) }
265
263
  gap={ gap }
266
- style={ {
267
- ...style,
268
- width: propWidth || undefined,
269
- height: propHeight || undefined,
270
- } }
264
+ style={ { ...style, width: propWidth || undefined, height: propHeight || undefined } }
265
+ data-testid="leaderboard-chart-container"
266
+ trailingContent={ nonLegendChildren }
271
267
  >
272
268
  <div className={ styles.emptyState }>
273
269
  { loading
274
270
  ? __( 'Loading…', 'jetpack-charts' )
275
271
  : __( 'No data available', 'jetpack-charts' ) }
276
272
  </div>
277
-
278
- { nonLegendChildren }
279
- </Stack>
273
+ </ChartLayout>
280
274
  </SingleChartContext.Provider>
281
275
  );
282
276
  }
@@ -297,16 +291,11 @@ const LeaderboardChartInternal: FC< LeaderboardChartProps > = ( {
297
291
  );
298
292
 
299
293
  return (
300
- <SingleChartContext.Provider
301
- value={ {
302
- chartId,
303
- chartWidth: 0, // LeaderboardChart doesn't need specific dimensions
304
- chartHeight: 0,
305
- } }
306
- >
307
- <Stack
308
- direction="column"
309
- data-testid="leaderboard-chart-container"
294
+ <SingleChartContext.Provider value={ { chartId } }>
295
+ <ChartLayout
296
+ legendPosition={ legendPosition }
297
+ legendElement={ legendElement }
298
+ legendChildren={ legendChildren }
310
299
  className={ clsx(
311
300
  styles.leaderboardChart,
312
301
  {
@@ -321,10 +310,9 @@ const LeaderboardChartInternal: FC< LeaderboardChartProps > = ( {
321
310
  width: propWidth || undefined,
322
311
  height: propHeight || undefined,
323
312
  } }
313
+ data-testid="leaderboard-chart-container"
314
+ trailingContent={ nonLegendChildren }
324
315
  >
325
- { legendPosition === 'top' && legendElement }
326
- { renderLegendSlot( legendChildren, 'top' ) }
327
-
328
316
  <div className={ styles.leaderboardChart__content }>
329
317
  { allSeriesHidden ? (
330
318
  <div className={ styles.emptyState }>
@@ -372,12 +360,7 @@ const LeaderboardChartInternal: FC< LeaderboardChartProps > = ( {
372
360
  </Grid>
373
361
  ) }
374
362
  </div>
375
-
376
- { legendPosition === 'bottom' && legendElement }
377
- { renderLegendSlot( legendChildren, 'bottom' ) }
378
-
379
- { nonLegendChildren }
380
- </Stack>
363
+ </ChartLayout>
381
364
  </SingleChartContext.Provider>
382
365
  );
383
366
  };
@@ -1,11 +1,6 @@
1
1
  .line-chart {
2
2
  position: relative;
3
3
 
4
- &__svg-wrapper {
5
- flex: 1;
6
- min-height: 0; // Required for flex shrinking
7
- }
8
-
9
4
  &--animated {
10
5
 
11
6
  path {