@automattic/charts 0.58.0 → 1.0.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 +25 -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
@@ -1,617 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
-
3
-
4
- var _chunkTZRUHQOHcjs = require('./chunk-TZRUHQOH.cjs');
5
-
6
-
7
-
8
-
9
- var _chunkXVBH5XHEcjs = require('./chunk-XVBH5XHE.cjs');
10
-
11
-
12
-
13
- var _chunkY3NNQMAXcjs = require('./chunk-Y3NNQMAX.cjs');
14
-
15
-
16
- var _chunkREZTQ4PHcjs = require('./chunk-REZTQ4PH.cjs');
17
-
18
-
19
- var _chunkASLARV7Lcjs = require('./chunk-ASLARV7L.cjs');
20
-
21
-
22
-
23
-
24
-
25
-
26
-
27
-
28
-
29
-
30
-
31
-
32
-
33
- var _chunkWYK7EL5Rcjs = require('./chunk-WYK7EL5R.cjs');
34
-
35
-
36
-
37
- var _chunkMXGLYWVPcjs = require('./chunk-MXGLYWVP.cjs');
38
-
39
- // src/charts/bar-chart/bar-chart.tsx
40
- var _numberformatters = require('@automattic/number-formatters');
41
- var _pattern = require('@visx/pattern');
42
- var _xychart = require('@visx/xychart');
43
- var _i18n = require('@wordpress/i18n');
44
- var _clsx = require('clsx'); var _clsx2 = _interopRequireDefault(_clsx);
45
- var _react = require('react');
46
-
47
- // src/charts/bar-chart/bar-chart.module.scss
48
- var bar_chart_module_default = {
49
- "bar-chart__svg-wrapper": "a8ccharts-9CsqC0",
50
- "bar-chart": "a8ccharts-3gflnB",
51
- "bar-chart--animated": "a8ccharts-98W-yu",
52
- "rise": "a8ccharts-z6AsiQ",
53
- "bar-chart--animated-horizontal": "a8ccharts-HFA3FF",
54
- "stretch": "a8ccharts-DQp37O"
55
- };
56
-
57
- // src/charts/bar-chart/private/use-bar-chart-options.ts
58
-
59
-
60
-
61
- // src/charts/bar-chart/private/truncated-tick-component.tsx
62
-
63
-
64
- var _jsxruntime = require('react/jsx-runtime');
65
- var getScaleBandwidth = (scale) => {
66
- return scale && "bandwidth" in scale ? _nullishCoalesce(scale.bandwidth(), () => ( 0)) : 0;
67
- };
68
- var MIN_TICK_LABEL_WIDTH = 20;
69
- var TruncatedTickComponent = ({
70
- x,
71
- y,
72
- formattedValue,
73
- axis,
74
- textAnchor,
75
- fill,
76
- dy,
77
- ...textProps
78
- }) => {
79
- const {
80
- xScale,
81
- yScale
82
- } = _react.useContext.call(void 0, _xychart.DataContext) || {};
83
- const scale = axis === "x" ? xScale : yScale;
84
- const bandwidth = getScaleBandwidth(scale);
85
- const maxWidth = Math.max(bandwidth, MIN_TICK_LABEL_WIDTH);
86
- let textAlign = "center";
87
- if (textAnchor === "start") {
88
- textAlign = "left";
89
- } else if (textAnchor === "end") {
90
- textAlign = "right";
91
- } else if (textAnchor === "middle") {
92
- textAlign = "center";
93
- }
94
- let xOffset = 0;
95
- if (textAlign === "center") {
96
- xOffset = -maxWidth / 2;
97
- } else if (textAlign === "right") {
98
- xOffset = -maxWidth;
99
- }
100
- const {
101
- fontSize,
102
- fontFamily,
103
- fontWeight,
104
- fontStyle,
105
- letterSpacing,
106
- opacity
107
- } = textProps;
108
- const textStyles = {
109
- /**
110
- * SVG <text> elements are vertically aligned to the baseline by default, but HTML <div> elements inside <foreignObject>
111
- * are positioned relative to the top-left corner. To visually align the tick label like SVG text,
112
- * we shift the div up by 100% of its height and adjust by twice the SVG dy value (from visx) to approximate original placement.
113
- */
114
- transform: `translateY(calc(-100% + ${_nullishCoalesce(dy, () => ( "0"))} * 2))`,
115
- // Safari doesn't work well with foreignObject positioning. Use position: fixed as a workaround.
116
- ..._chunkMXGLYWVPcjs.isSafari.call(void 0, ) ? {
117
- position: "fixed"
118
- } : {},
119
- // Apply compatible SVG text styles
120
- fontSize,
121
- fontFamily,
122
- fontWeight,
123
- fontStyle,
124
- letterSpacing,
125
- opacity,
126
- // Convert svg text styles to CSS styles for the div
127
- color: _nullishCoalesce(fill, () => ( "inherit")),
128
- textAlign,
129
- // Ensure text is truncated with ellipsis, remains on one line, and shows the full value in a tooltip on hover.
130
- // The surrounding div uses CSS to handle overflow, and the 'title' attribute is set for accessibility.
131
- width: maxWidth,
132
- overflow: "hidden",
133
- textOverflow: "ellipsis",
134
- whiteSpace: "nowrap",
135
- cursor: "default",
136
- pointerEvents: "auto"
137
- };
138
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "foreignObject", {
139
- x: x + xOffset,
140
- y,
141
- width: maxWidth,
142
- height: 0,
143
- overflow: "visible",
144
- children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", {
145
- style: textStyles,
146
- title: formattedValue,
147
- children: formattedValue
148
- })
149
- });
150
- };
151
- var createTruncatedTickComponent = (axis) => (props) => {
152
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, TruncatedTickComponent, {
153
- ...props,
154
- axis
155
- });
156
- };
157
- var TruncatedXTickComponent = createTruncatedTickComponent("x");
158
- var TruncatedYTickComponent = createTruncatedTickComponent("y");
159
-
160
- // src/charts/bar-chart/private/use-bar-chart-options.ts
161
- var formatDateTick = (timestamp) => {
162
- const date = new Date(timestamp);
163
- return date.toLocaleDateString(void 0, {
164
- month: "short",
165
- day: "numeric"
166
- });
167
- };
168
- var getGroupPadding = (scale) => {
169
- return typeof scale.paddingInner === "number" ? scale.paddingInner : 0;
170
- };
171
- function useBarChartOptions(data, horizontal, options = {}) {
172
- const defaultOptions = _react.useMemo.call(void 0, () => {
173
- const bandScale = {
174
- type: "band",
175
- padding: 0.2,
176
- paddingInner: 0.1
177
- };
178
- const linearScale = {
179
- type: "linear",
180
- nice: true,
181
- zero: false
182
- };
183
- const labelFormatter = _optionalChain([data, 'optionalAccess', _ => _[0], 'optionalAccess', _2 => _2.data, 'optionalAccess', _3 => _3[0], 'optionalAccess', _4 => _4.label]) ? (label) => label : formatDateTick;
184
- const valueFormatter = _numberformatters.formatNumberCompact;
185
- const labelAccessor = (d) => _optionalChain([d, 'optionalAccess', _5 => _5.label]) || _optionalChain([d, 'optionalAccess', _6 => _6.date]);
186
- const valueAccessor = (d) => {
187
- const enhancedPoint = d;
188
- return _optionalChain([enhancedPoint, 'optionalAccess', _7 => _7.visualValue]) !== void 0 ? enhancedPoint.visualValue : _optionalChain([d, 'optionalAccess', _8 => _8.value]);
189
- };
190
- return {
191
- vertical: {
192
- xTickFormat: labelFormatter,
193
- yTickFormat: valueFormatter,
194
- tooltipLabelFormatter: labelFormatter,
195
- xAccessor: labelAccessor,
196
- yAccessor: valueAccessor,
197
- gridVisibility: "x",
198
- xScale: bandScale,
199
- yScale: linearScale
200
- },
201
- horizontal: {
202
- xTickFormat: valueFormatter,
203
- yTickFormat: labelFormatter,
204
- tooltipLabelFormatter: labelFormatter,
205
- xAccessor: valueAccessor,
206
- yAccessor: labelAccessor,
207
- gridVisibility: "y",
208
- xScale: linearScale,
209
- yScale: bandScale
210
- }
211
- };
212
- }, [data]);
213
- return _react.useMemo.call(void 0, () => {
214
- const orientationKey = horizontal ? "horizontal" : "vertical";
215
- const {
216
- xTickFormat,
217
- yTickFormat,
218
- tooltipLabelFormatter: defaultTooltipLabelFormatter,
219
- xAccessor,
220
- yAccessor,
221
- gridVisibility,
222
- xScale: baseXScale,
223
- yScale: baseYScale
224
- } = defaultOptions[orientationKey];
225
- const xScale = { ...baseXScale, ...options.xScale || {} };
226
- const yScale = { ...baseYScale, ...options.yScale || {} };
227
- const providedToolTipLabelFormatter = horizontal ? _optionalChain([options, 'access', _9 => _9.axis, 'optionalAccess', _10 => _10.y, 'optionalAccess', _11 => _11.tickFormat]) : _optionalChain([options, 'access', _12 => _12.axis, 'optionalAccess', _13 => _13.x, 'optionalAccess', _14 => _14.tickFormat]);
228
- const { labelOverflow: xLabelOverflow, ...xAxisOptions } = _optionalChain([options, 'access', _15 => _15.axis, 'optionalAccess', _16 => _16.x]) || {};
229
- const { labelOverflow: yLabelOverflow, ...yAxisOptions } = _optionalChain([options, 'access', _17 => _17.axis, 'optionalAccess', _18 => _18.y]) || {};
230
- return {
231
- gridVisibility,
232
- xScale,
233
- yScale,
234
- accessors: {
235
- xAccessor,
236
- yAccessor
237
- },
238
- axis: {
239
- x: {
240
- orientation: "bottom",
241
- numTicks: 4,
242
- tickFormat: xTickFormat,
243
- ...xLabelOverflow === "ellipsis" ? { tickComponent: TruncatedXTickComponent } : {},
244
- ...xAxisOptions
245
- },
246
- y: {
247
- orientation: "left",
248
- numTicks: 4,
249
- tickFormat: yTickFormat,
250
- ...yLabelOverflow === "ellipsis" ? { tickComponent: TruncatedYTickComponent } : {},
251
- ...yAxisOptions
252
- }
253
- },
254
- barGroup: {
255
- padding: getGroupPadding(horizontal ? yScale : xScale)
256
- },
257
- tooltip: {
258
- labelFormatter: providedToolTipLabelFormatter || defaultTooltipLabelFormatter
259
- }
260
- };
261
- }, [defaultOptions, options, horizontal]);
262
- }
263
-
264
- // src/charts/bar-chart/bar-chart.tsx
265
-
266
- var validateData = (data) => {
267
- if (!_optionalChain([data, 'optionalAccess', _19 => _19.length])) return "No data available";
268
- const hasInvalidData = data.some((series) => series.data.some((point) => isNaN(point.value) || point.value === null || point.value === void 0 || !point.label && (!("date" in point && point.date) || isNaN(point.date.getTime()))));
269
- if (hasInvalidData) return "Invalid data";
270
- return null;
271
- };
272
- var getPatternId = (chartId, index) => `bar-pattern-${chartId}-${index}`;
273
- var BarChartInternal = ({
274
- data,
275
- chartId: providedChartId,
276
- width,
277
- height,
278
- className,
279
- margin,
280
- withTooltips = false,
281
- showLegend = false,
282
- legend = {},
283
- gridVisibility: gridVisibilityProp,
284
- renderTooltip,
285
- options = {},
286
- orientation = "vertical",
287
- withPatterns = false,
288
- showZeroValues = false,
289
- animation,
290
- children,
291
- gap = "md"
292
- }) => {
293
- const legendInteractive = _nullishCoalesce(legend.interactive, () => ( false));
294
- const horizontal = orientation === "horizontal";
295
- const chartId = _chunkWYK7EL5Rcjs.useChartId.call(void 0, providedChartId);
296
- const theme = _chunkWYK7EL5Rcjs.useXYChartTheme.call(void 0, data);
297
- const dataSorted = _chunkWYK7EL5Rcjs.useChartDataTransform.call(void 0, data);
298
- const dataWithVisibleZeros = _chunkWYK7EL5Rcjs.useZeroValueDisplay.call(void 0, dataSorted, {
299
- enabled: showZeroValues,
300
- valueAxisLength: horizontal ? width : height
301
- });
302
- const legendItems = _chunkXVBH5XHEcjs.useChartLegendItems.call(void 0, dataSorted);
303
- const chartOptions = useBarChartOptions(dataWithVisibleZeros, horizontal, options);
304
- const defaultMargin = _chunkWYK7EL5Rcjs.useChartMargin.call(void 0, height, chartOptions, dataSorted, theme, horizontal);
305
- const [svgWrapperRef, , svgWrapperHeight] = _chunkWYK7EL5Rcjs.useElementSize.call(void 0, );
306
- const chartRef = _react.useRef.call(void 0, null);
307
- const {
308
- legendChildren,
309
- nonLegendChildren
310
- } = _chunkTZRUHQOHcjs.useChartChildren.call(void 0, children, "BarChart");
311
- const hasLegendChild = legendChildren.length > 0;
312
- const chartHeight = svgWrapperHeight > 0 ? svgWrapperHeight : height;
313
- const hasLegend = showLegend || hasLegendChild;
314
- const isWaitingForMeasurement = hasLegend ? svgWrapperHeight === 0 : !chartHeight;
315
- const [selectedIndex, setSelectedIndex] = _react.useState.call(void 0, void 0);
316
- const [isNavigating, setIsNavigating] = _react.useState.call(void 0, false);
317
- const totalPoints = Math.max(0, ...data.map((series) => _optionalChain([series, 'access', _20 => _20.data, 'optionalAccess', _21 => _21.length]) || 0)) * data.length;
318
- const {
319
- tooltipRef,
320
- onChartFocus,
321
- onChartBlur,
322
- onChartKeyDown
323
- } = _chunkY3NNQMAXcjs.useKeyboardNavigation.call(void 0, {
324
- selectedIndex,
325
- setSelectedIndex,
326
- isNavigating,
327
- setIsNavigating,
328
- chartRef,
329
- totalPoints
330
- });
331
- const {
332
- getElementStyles,
333
- isSeriesVisible
334
- } = _chunkWYK7EL5Rcjs.useGlobalChartsContext.call(void 0, );
335
- const providerTheme = _chunkWYK7EL5Rcjs.useGlobalChartsTheme.call(void 0, );
336
- const seriesWithVisibility = _react.useMemo.call(void 0, () => {
337
- if (!chartId || !legendInteractive) {
338
- return dataWithVisibleZeros.map((series, index) => ({
339
- series,
340
- index,
341
- isVisible: true
342
- }));
343
- }
344
- return dataWithVisibleZeros.map((series, index) => ({
345
- series,
346
- index,
347
- isVisible: isSeriesVisible(chartId, series.label)
348
- }));
349
- }, [dataWithVisibleZeros, chartId, isSeriesVisible, legendInteractive]);
350
- const allSeriesHidden = _react.useMemo.call(void 0, () => {
351
- return seriesWithVisibility.every(({
352
- isVisible
353
- }) => !isVisible);
354
- }, [seriesWithVisibility]);
355
- const getBarBackground = _react.useCallback.call(void 0, (index) => () => withPatterns ? `url(#${getPatternId(chartId, index)})` : getElementStyles({
356
- data: dataSorted[index],
357
- index
358
- }).color, [withPatterns, getElementStyles, dataSorted, chartId]);
359
- const renderDefaultTooltip = _react.useCallback.call(void 0, ({
360
- tooltipData
361
- }) => {
362
- const nearestDatum = _optionalChain([tooltipData, 'optionalAccess', _22 => _22.nearestDatum, 'optionalAccess', _23 => _23.datum]);
363
- if (!nearestDatum) return null;
364
- return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", {
365
- className: bar_chart_module_default["bar-chart__tooltip"],
366
- children: [/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", {
367
- className: bar_chart_module_default["bar-chart__tooltip-header"],
368
- children: _optionalChain([tooltipData, 'optionalAccess', _24 => _24.nearestDatum, 'optionalAccess', _25 => _25.key])
369
- }), /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", {
370
- className: bar_chart_module_default["bar-chart__tooltip-row"],
371
- children: [/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "span", {
372
- className: bar_chart_module_default["bar-chart__tooltip-label"],
373
- children: [chartOptions.tooltip.labelFormatter(nearestDatum.label || (nearestDatum.date ? nearestDatum.date.getTime() : 0), 0, []), ":"]
374
- }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", {
375
- className: bar_chart_module_default["bar-chart__tooltip-value"],
376
- children: _numberformatters.formatNumber.call(void 0, nearestDatum.value)
377
- })]
378
- })]
379
- });
380
- }, [chartOptions.tooltip]);
381
- const renderPattern = _react.useCallback.call(void 0, (index, color) => {
382
- const patternType = index % 4;
383
- const id = getPatternId(chartId, index);
384
- const commonProps = {
385
- id,
386
- stroke: "white",
387
- strokeWidth: 1,
388
- background: color
389
- };
390
- switch (patternType) {
391
- case 0:
392
- default:
393
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _pattern.PatternLines, {
394
- ...commonProps,
395
- width: 5,
396
- height: 5,
397
- orientation: ["diagonal"]
398
- }, id);
399
- case 1:
400
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _pattern.PatternCircles, {
401
- ...commonProps,
402
- width: 6,
403
- height: 6,
404
- fill: "white"
405
- }, id);
406
- case 2:
407
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _pattern.PatternWaves, {
408
- ...commonProps,
409
- width: 4,
410
- height: 4
411
- }, id);
412
- case 3:
413
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _pattern.PatternHexagons, {
414
- ...commonProps,
415
- size: 8,
416
- height: 3
417
- }, id);
418
- }
419
- }, [chartId]);
420
- const createPatternBorderStyle = _react.useCallback.call(void 0, (index, color) => {
421
- const patternId = getPatternId(chartId, index);
422
- return `
423
- .visx-bar[fill="url(#${patternId})"] {
424
- stroke: ${color};
425
- stroke-width: 1;
426
- }
427
- `;
428
- }, [chartId]);
429
- const createKeyboardHighlightStyle = _react.useCallback.call(void 0, () => {
430
- if (selectedIndex === void 0) return "";
431
- const maxDataPoints = Math.max(...data.map((s) => s.data.length));
432
- const dataPointIndex = Math.floor(selectedIndex / data.length);
433
- const seriesIndex = selectedIndex % data.length;
434
- if (dataPointIndex >= maxDataPoints || seriesIndex >= data.length) {
435
- return "";
436
- }
437
- const seriesData = data[seriesIndex];
438
- if (dataPointIndex >= seriesData.data.length) {
439
- return "";
440
- }
441
- const actualBarIndex = seriesIndex * maxDataPoints + dataPointIndex;
442
- const generatedStyles = `
443
- .bar-chart[data-chart-id="bar-chart-${chartId}"] .visx-bar-group .visx-bar:nth-child(${actualBarIndex + 1}) {
444
- stroke: #005fcc;
445
- stroke-width: 2px;
446
- }
447
- `;
448
- return generatedStyles;
449
- }, [selectedIndex, data, chartId]);
450
- const error = validateData(dataSorted);
451
- const isDataValid = !error;
452
- const chartMetadata = _react.useMemo.call(void 0, () => ({
453
- orientation,
454
- withPatterns
455
- }), [orientation, withPatterns]);
456
- _chunkWYK7EL5Rcjs.useChartRegistration.call(void 0, {
457
- chartId,
458
- legendItems,
459
- chartType: "bar",
460
- isDataValid,
461
- metadata: chartMetadata
462
- });
463
- const prefersReducedMotion = _chunkWYK7EL5Rcjs.usePrefersReducedMotion.call(void 0, );
464
- if (error) {
465
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", {
466
- className: _clsx2.default.call(void 0, "bar-chart", bar_chart_module_default["bar-chart"]),
467
- children: error
468
- });
469
- }
470
- const gridVisibility = _nullishCoalesce(gridVisibilityProp, () => ( chartOptions.gridVisibility));
471
- const highlightedBarStyle = createKeyboardHighlightStyle();
472
- const legendPosition = _nullishCoalesce(legend.position, () => ( "bottom"));
473
- const legendElement = showLegend && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXVBH5XHEcjs.Legend, {
474
- orientation: _nullishCoalesce(legend.orientation, () => ( "horizontal")),
475
- position: legendPosition,
476
- alignment: _nullishCoalesce(legend.alignment, () => ( "center")),
477
- labelStyles: legend.labelStyles,
478
- itemClassName: legend.itemClassName,
479
- itemStyles: legend.itemStyles,
480
- shapeStyles: legend.shapeStyles,
481
- className: bar_chart_module_default["bar-chart__legend"],
482
- shape: _nullishCoalesce(legend.shape, () => ( "rect")),
483
- chartId,
484
- interactive: legendInteractive
485
- });
486
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXVBH5XHEcjs.SingleChartContext.Provider, {
487
- value: {
488
- chartId,
489
- chartWidth: width,
490
- chartHeight
491
- },
492
- children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkREZTQ4PHcjs.Stack, {
493
- direction: "column",
494
- gap,
495
- className: _clsx2.default.call(void 0, "bar-chart", bar_chart_module_default["bar-chart"], {
496
- [bar_chart_module_default[`bar-chart--animated${horizontal ? "-horizontal" : ""}`]]: animation && !prefersReducedMotion
497
- }, className),
498
- style: {
499
- width,
500
- height,
501
- visibility: isWaitingForMeasurement ? "hidden" : "visible"
502
- },
503
- "data-chart-id": `bar-chart-${chartId}`,
504
- children: [legendPosition === "top" && legendElement, _chunkTZRUHQOHcjs.renderLegendSlot.call(void 0, legendChildren, "top"), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", {
505
- className: bar_chart_module_default["bar-chart__svg-wrapper"],
506
- ref: svgWrapperRef,
507
- role: "grid",
508
- "aria-label": _i18n.__.call(void 0, "Bar chart", "jetpack-charts"),
509
- tabIndex: 0,
510
- onKeyDown: onChartKeyDown,
511
- onFocus: onChartFocus,
512
- onBlur: onChartBlur,
513
- children: !isWaitingForMeasurement && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", {
514
- ref: chartRef,
515
- children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _xychart.XYChart, {
516
- theme,
517
- width,
518
- height: chartHeight,
519
- margin: {
520
- ...defaultMargin,
521
- ...margin
522
- },
523
- xScale: chartOptions.xScale,
524
- yScale: chartOptions.yScale,
525
- horizontal,
526
- pointerEventsDataKey: "nearest",
527
- children: [/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _xychart.Grid, {
528
- columns: gridVisibility.includes("y"),
529
- rows: gridVisibility.includes("x"),
530
- numTicks: 4
531
- }), withPatterns && /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, {
532
- children: [/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "defs", {
533
- children: dataSorted.map((seriesData, index) => renderPattern(index, getElementStyles({
534
- data: seriesData,
535
- index
536
- }).color))
537
- }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "style", {
538
- children: dataSorted.map((seriesData, index) => createPatternBorderStyle(index, getElementStyles({
539
- data: seriesData,
540
- index
541
- }).color))
542
- })]
543
- }), highlightedBarStyle && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "style", {
544
- children: highlightedBarStyle
545
- }), allSeriesHidden ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "text", {
546
- x: width / 2,
547
- y: chartHeight / 2,
548
- textAnchor: "middle",
549
- fill: _optionalChain([providerTheme, 'access', _26 => _26.gridStyles, 'optionalAccess', _27 => _27.stroke]) || "#ccc",
550
- fontSize: "14",
551
- fontFamily: "-apple-system,BlinkMacSystemFont,Roboto,Helvetica Neue,sans-serif",
552
- children: _i18n.__.call(void 0, "All series are hidden. Click legend items to show data.", "jetpack-charts")
553
- }) : null, /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _xychart.BarGroup, {
554
- padding: chartOptions.barGroup.padding,
555
- children: seriesWithVisibility.map(({
556
- series: seriesData,
557
- index,
558
- isVisible
559
- }) => {
560
- if (!isVisible) {
561
- return null;
562
- }
563
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _xychart.BarSeries, {
564
- dataKey: _optionalChain([seriesData, 'optionalAccess', _28 => _28.label]),
565
- data: seriesData.data,
566
- yAccessor: chartOptions.accessors.yAccessor,
567
- xAccessor: chartOptions.accessors.xAccessor,
568
- colorAccessor: getBarBackground(index)
569
- }, _optionalChain([seriesData, 'optionalAccess', _29 => _29.label]));
570
- })
571
- }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _xychart.Axis, {
572
- ...chartOptions.axis.x
573
- }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _xychart.Axis, {
574
- ...chartOptions.axis.y
575
- }), withTooltips && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkY3NNQMAXcjs.AccessibleTooltip, {
576
- detectBounds: true,
577
- snapTooltipToDatumX: true,
578
- snapTooltipToDatumY: true,
579
- renderTooltip: renderTooltip || renderDefaultTooltip,
580
- selectedIndex,
581
- tooltipRef,
582
- keyboardFocusedClassName: bar_chart_module_default["bar-chart__tooltip--keyboard-focused"],
583
- series: data,
584
- mode: "individual"
585
- })]
586
- })
587
- })
588
- }), legendPosition === "bottom" && legendElement, _chunkTZRUHQOHcjs.renderLegendSlot.call(void 0, legendChildren, "bottom"), nonLegendChildren]
589
- })
590
- });
591
- };
592
- var BarChartWithProvider = (props) => {
593
- const existingContext = _react.useContext.call(void 0, _chunkWYK7EL5Rcjs.GlobalChartsContext);
594
- if (existingContext) {
595
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, BarChartInternal, {
596
- ...props
597
- });
598
- }
599
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkWYK7EL5Rcjs.GlobalChartsProvider, {
600
- children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, BarChartInternal, {
601
- ...props
602
- })
603
- });
604
- };
605
- BarChartWithProvider.displayName = "BarChart";
606
- var BarChart = _chunkMXGLYWVPcjs.attachSubComponents.call(void 0, BarChartWithProvider, {
607
- Legend: _chunkXVBH5XHEcjs.Legend
608
- });
609
- var BarChartResponsive = _chunkMXGLYWVPcjs.attachSubComponents.call(void 0, _chunkASLARV7Lcjs.withResponsive.call(void 0, BarChartWithProvider), {
610
- Legend: _chunkXVBH5XHEcjs.Legend
611
- });
612
-
613
-
614
-
615
-
616
- exports.BarChart = BarChart; exports.BarChartResponsive = BarChartResponsive;
617
- //# sourceMappingURL=chunk-XC4KHJYX.cjs.map