@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
@@ -1,44 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
-
3
-
4
-
5
-
6
-
7
-
8
-
9
-
10
-
11
-
12
-
13
-
14
-
15
-
16
-
17
-
18
-
19
-
20
-
21
- var _chunkVTS3PNMScjs = require('../chunk-VTS3PNMS.cjs');
22
- require('../chunk-EMMSS5I5.cjs');
23
-
24
-
25
-
26
-
27
-
28
-
29
-
30
-
31
-
32
-
33
-
34
-
35
-
36
-
37
-
38
-
39
-
40
-
41
-
42
-
43
- exports.attachSubComponents = _chunkVTS3PNMScjs.attachSubComponents; exports.formatMetricValue = _chunkVTS3PNMScjs.formatMetricValue; exports.formatPercentage = _chunkVTS3PNMScjs.formatPercentage; exports.getColorDistance = _chunkVTS3PNMScjs.getColorDistance; exports.getItemShapeStyles = _chunkVTS3PNMScjs.getItemShapeStyles; exports.getLongestTickWidth = _chunkVTS3PNMScjs.getLongestTickWidth; exports.getSeriesLineStyles = _chunkVTS3PNMScjs.getSeriesLineStyles; exports.getSeriesStroke = _chunkVTS3PNMScjs.getSeriesStroke; exports.hexToRgba = _chunkVTS3PNMScjs.hexToRgba; exports.isSafari = _chunkVTS3PNMScjs.isSafari; exports.isValidHexColor = _chunkVTS3PNMScjs.isValidHexColor; exports.lightenHexColor = _chunkVTS3PNMScjs.lightenHexColor; exports.mergeThemes = _chunkVTS3PNMScjs.mergeThemes; exports.normalizeColorToHex = _chunkVTS3PNMScjs.normalizeColorToHex; exports.parseAsLocalDate = _chunkVTS3PNMScjs.parseAsLocalDate; exports.parseHslString = _chunkVTS3PNMScjs.parseHslString; exports.parseRgbString = _chunkVTS3PNMScjs.parseRgbString; exports.resolveCssVariable = _chunkVTS3PNMScjs.resolveCssVariable; exports.validateHexColor = _chunkVTS3PNMScjs.validateHexColor;
44
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["/home/runner/work/jetpack/jetpack/projects/js-packages/charts/dist/utils/index.cjs"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,yDAA8B;AAC9B,iCAA8B;AAC9B;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,wpCAAC","file":"/home/runner/work/jetpack/jetpack/projects/js-packages/charts/dist/utils/index.cjs"}
@@ -1,226 +0,0 @@
1
- export { M as MetricValueType, f as formatMetricValue } from '../format-metric-value-MXm5DtQ_.cjs';
2
- import { TickFormatter } from '@visx/axis';
3
- import { AnyD3Scale, ScaleInput } from '@visx/scale';
4
- import { j as SeriesData, C as ChartTheme, b as CompleteChartTheme } from '../types-DZordNiO.cjs';
5
- import { LegendShape } from '@visx/legend/lib/types';
6
- import { LineStyles } from '@visx/xychart';
7
- import '@visx/annotation/lib/components/CircleSubject';
8
- import '@visx/annotation/lib/components/Connector';
9
- import '@visx/annotation/lib/components/Label';
10
- import '@visx/annotation/lib/components/LineSubject';
11
- import '@visx/text/lib/Text';
12
- import '@wordpress/theme';
13
- import 'react';
14
- import 'react-google-charts';
15
-
16
- /**
17
- * Utility function to create chart components with composition API.
18
- *
19
- * This function attaches subcomponents to a chart component to enable
20
- * dot notation access like <Chart.Legend />, <Chart.Tooltip />, etc.
21
- *
22
- * @param Chart - The main chart component
23
- * @param subComponents - Object containing subcomponents to attach
24
- * @return Chart component with attached subcomponents
25
- */
26
- declare function attachSubComponents<TChart, TSubComponents extends Record<string, unknown>>(Chart: TChart, subComponents: TSubComponents): TChart & TSubComponents;
27
-
28
- /**
29
- * @file Date parsing utilities using date-fns for local timezone handling
30
- *
31
- * This module provides utilities for parsing various date string formats and converting
32
- * them to local timezone dates using the battle-tested date-fns library. For formats
33
- * without timezone info, they're treated as local. For formats with timezone info,
34
- * they're converted to the equivalent local time.
35
- *
36
- * Note: And specifically it prevents format `YYYY-MM-DD` being parsed as UTC date.
37
- *
38
- * Key Features:
39
- * - All parsed dates are in local timezone
40
- * - Converts timezone-aware strings to local equivalent
41
- * - Robust input validation and error handling using date-fns
42
- * - TypeScript type safety
43
- * - Much smaller codebase than custom parsing
44
- *
45
- * Supported Formats:
46
- * - YYYY-MM-DD (treated as local)
47
- * - YYYY-MM-DD HH:mm:ss (treated as local)
48
- * - YYYY-MM-DD HH:mm (treated as local)
49
- * - YYYY-MM-DDTHH:mm:ss (treated as local)
50
- * - YYYY-MM-DDTHH:mm:ss.SSS (treated as local)
51
- * - YYYY-MM-DDTHH:mm (treated as local)
52
- * - YYYY-MM-DDTHH:mm:ssZ (converted to local)
53
- * - YYYY-MM-DDTHH:mm:ss±HH:mm (converted to local)
54
- *
55
- * @example
56
- * ```typescript
57
- * parseAsLocalDate("2025-01-01"); // Local timezone
58
- * parseAsLocalDate("2025-01-01 14:30:00"); // Local timezone
59
- * parseAsLocalDate("2025-01-01 14:30"); // Local timezone
60
- * parseAsLocalDate("2025-01-01T14:30:45.123"); // Local timezone
61
- * parseAsLocalDate("2025-01-01T14:30:00Z"); // UTC 14:30 → Local equivalent
62
- * parseAsLocalDate("2025-01-01T14:30:00+05:00"); // +05:00 14:30 → Local equivalent
63
- * ```
64
- */
65
- /**
66
- * Parses any supported date string format and returns a local timezone date
67
- *
68
- * Uses date-fns for robust parsing and validation. For strings without timezone
69
- * info, treats as local timezone. For strings with timezone info, converts to
70
- * local timezone equivalent.
71
- *
72
- * Supports:
73
- * - YYYY-MM-DD (local)
74
- * - YYYY-MM-DD HH:mm:ss (local)
75
- * - YYYY-MM-DD HH:mm (local)
76
- * - YYYY-MM-DDTHH:mm:ss (local)
77
- * - YYYY-MM-DDTHH:mm:ss.SSS (local)
78
- * - YYYY-MM-DDTHH:mm (local)
79
- * - YYYY-MM-DDTHH:mm:ssZ (UTC → local)
80
- * - YYYY-MM-DDTHH:mm:ss±HH:mm (offset → local)
81
- * @param {string} dateString - The date string to parse into a local timezone date
82
- * @return {Date} A Date object representing the parsed date in local timezone, or an invalid Date if parsing fails
83
- */
84
- declare const parseAsLocalDate: (dateString: string) => Date;
85
-
86
- /**
87
- * Format a percentage value with smart decimal handling.
88
- * Uses `@automattic/number-formatters` for consistent formatting.
89
- * Removes unnecessary trailing zeros and caps at 2 decimal places.
90
- *
91
- * @param value - The percentage value (0-100 range)
92
- * @return Formatted percentage string (e.g., "30%", "30.1%", "30.25%")
93
- */
94
- declare const formatPercentage: (value: number) => string;
95
-
96
- /**
97
- * Returns the width of the longest tick.
98
- *
99
- * @param ticks - Ticks to get the width of.
100
- * @param formatTick - Function to format the tick.
101
- * @param {object} labelStyle - Style object for the label.
102
- * @return {number} - Width of the longest tick.
103
- */
104
- declare const getLongestTickWidth: <T extends AnyD3Scale>(ticks: ScaleInput<T>[], formatTick: TickFormatter<ScaleInput<T>>, labelStyle?: object) => number;
105
-
106
- /**
107
- * Utility function to get consolidated line styles for a series
108
- * This consolidates the logic used by both LineChart and Legend components
109
- *
110
- * @param {SeriesData} seriesData - The series data containing styling options
111
- * @param {number} index - The index of the series in the data array
112
- * @param {ChartTheme} providerTheme - The chart theme configuration
113
- * @return {LineStyles} The consolidated line styles for the series
114
- */
115
- declare function getSeriesLineStyles(seriesData: SeriesData, index: number, providerTheme: ChartTheme): LineStyles;
116
- /**
117
- * Utility function to get stroke color for a series
118
- *
119
- * @param {SeriesData} seriesData - The series data containing styling options
120
- * @param {number} index - The index of the series in the data array
121
- * @param {string[]} themeColors - Array of theme colors
122
- * @return {string} The stroke color for the series
123
- */
124
- declare function getSeriesStroke(seriesData: SeriesData, index: number, themeColors: string[]): string;
125
- /**
126
- * Utility function to get shape styles for a legend item
127
- *
128
- * @param {SeriesData} series - The series data containing styling options
129
- * @param {number} index - The index of the series in the data array
130
- * @param {ChartTheme} theme - The chart theme configuration
131
- * @param {LegendShape} legendShape - The shape to use for the item (optional)
132
- * @return {Record< string, unknown >} The shape styles for the item
133
- */
134
- declare function getItemShapeStyles(series: SeriesData, index: number, theme: ChartTheme, legendShape?: LegendShape<SeriesData[], number>): Record<string, unknown>;
135
-
136
- declare const isSafari: () => boolean;
137
-
138
- /**
139
- * Merges chart themes with proper precedence.
140
- * The second theme (override) takes precedence over the first theme (base).
141
- *
142
- * @param baseTheme - Base theme object
143
- * @param overrideTheme - Theme to override base with (takes precedence)
144
- * @return Merged theme with overrideTheme values taking precedence
145
- */
146
- declare function mergeThemes(baseTheme: CompleteChartTheme, overrideTheme: Partial<ChartTheme>): CompleteChartTheme;
147
- declare function mergeThemes(baseTheme: ChartTheme, overrideTheme: Partial<ChartTheme>): ChartTheme;
148
-
149
- /**
150
- * Check if a value is a valid 6-digit hex color
151
- * @param hex - The value to check
152
- * @return true if valid hex color format (e.g., '#ff0000')
153
- */
154
- declare const isValidHexColor: (hex: unknown) => hex is string;
155
- /**
156
- * Validate hex color format, throwing descriptive errors if invalid
157
- * @param hex - The hex color string to validate
158
- * @throws {Error} if hex string is malformed
159
- */
160
- declare const validateHexColor: (hex: unknown) => void;
161
- /**
162
- * Convert hex color to rgba with specified opacity.
163
- * This is genuinely reusable across chart components.
164
- * @param hex - The hex color string (e.g., '#ff0000')
165
- * @param alpha - The opacity value. Values outside the [0, 1] range will be clamped by the underlying d3 color library.
166
- * @return The rgba color string (e.g., 'rgba(255, 0, 0, 0.5)')
167
- * @throws {Error} if hex string is malformed or alpha is not a valid number
168
- */
169
- declare const hexToRgba: (hex: string, alpha: number) => string;
170
- /**
171
- * Calculate the perceptual distance between two HSL colors
172
- * @param hsl1 - first color in HSL format [h, s, l]
173
- * @param hsl2 - second color in HSL format [h, s, l]
174
- * @return distance value (0-100+, lower means more similar)
175
- */
176
- declare const getColorDistance: (hsl1: [number, number, number], hsl2: [number, number, number]) => number;
177
- /**
178
- * Parse an HSL string like 'hsl(120, 50%, 50%)' into an HSL tuple.
179
- *
180
- * @param hslString - HSL color string
181
- * @return HSL tuple [h, s, l] or null if invalid
182
- */
183
- declare const parseHslString: (hslString: string) => [number, number, number] | null;
184
- /**
185
- * Parse an RGB string like 'rgb(255, 0, 0)' into a hex color.
186
- *
187
- * @param rgbString - RGB color string
188
- * @return hex color string or null if invalid
189
- */
190
- declare const parseRgbString: (rgbString: string) => string | null;
191
- /**
192
- * Normalize any CSS color value to a hex color string.
193
- * Handles hex colors, HSL strings, RGB strings, and CSS variables.
194
- *
195
- * @param color - Any CSS color value
196
- * @param element - Optional DOM element for resolving CSS variables
197
- * @param resolveCss - Function to resolve CSS variables (injected for testability)
198
- * @return hex color string, or the original value if conversion fails
199
- */
200
- declare const normalizeColorToHex: (color: string, element?: HTMLElement | null, resolveCss?: (value: string, el?: HTMLElement | null) => string | null) => string;
201
- /**
202
- * Lighten a hex color by blending it with white.
203
- * Useful for creating color gradients or lighter variants.
204
- *
205
- * @param hex - Hex color string (e.g., '#98C8DF')
206
- * @param blend - Blend amount with white (0 = original color, 1 = white)
207
- * @return Lightened hex color string (e.g., '#cce4ef')
208
- * @throws {Error} if hex string is malformed
209
- */
210
- declare const lightenHexColor: (hex: string, blend: number) => string;
211
-
212
- /**
213
- * Resolves a CSS custom property (variable) to its computed value.
214
- * Handles multiple formats:
215
- * - Plain variable names: '--my-color'
216
- * - CSS var() syntax: 'var(--my-color)'
217
- * - CSS var() with fallback: 'var(--my-color, #ffffff)'
218
- * - Regular values (returned as-is): '#ffffff', 'red'
219
- *
220
- * @param value - A CSS variable name, var() expression, or regular value
221
- * @param element - Optional DOM element to resolve the variable from (defaults to document.documentElement)
222
- * @return The resolved value, fallback value, or null if unresolvable
223
- */
224
- declare const resolveCssVariable: (value: string, element?: HTMLElement | null) => string | null;
225
-
226
- export { attachSubComponents, formatPercentage, getColorDistance, getItemShapeStyles, getLongestTickWidth, getSeriesLineStyles, getSeriesStroke, hexToRgba, isSafari, isValidHexColor, lightenHexColor, mergeThemes, normalizeColorToHex, parseAsLocalDate, parseHslString, parseRgbString, resolveCssVariable, validateHexColor };
@@ -1,226 +0,0 @@
1
- export { M as MetricValueType, f as formatMetricValue } from '../format-metric-value-MXm5DtQ_.js';
2
- import { TickFormatter } from '@visx/axis';
3
- import { AnyD3Scale, ScaleInput } from '@visx/scale';
4
- import { j as SeriesData, C as ChartTheme, b as CompleteChartTheme } from '../types-DZordNiO.js';
5
- import { LegendShape } from '@visx/legend/lib/types';
6
- import { LineStyles } from '@visx/xychart';
7
- import '@visx/annotation/lib/components/CircleSubject';
8
- import '@visx/annotation/lib/components/Connector';
9
- import '@visx/annotation/lib/components/Label';
10
- import '@visx/annotation/lib/components/LineSubject';
11
- import '@visx/text/lib/Text';
12
- import '@wordpress/theme';
13
- import 'react';
14
- import 'react-google-charts';
15
-
16
- /**
17
- * Utility function to create chart components with composition API.
18
- *
19
- * This function attaches subcomponents to a chart component to enable
20
- * dot notation access like <Chart.Legend />, <Chart.Tooltip />, etc.
21
- *
22
- * @param Chart - The main chart component
23
- * @param subComponents - Object containing subcomponents to attach
24
- * @return Chart component with attached subcomponents
25
- */
26
- declare function attachSubComponents<TChart, TSubComponents extends Record<string, unknown>>(Chart: TChart, subComponents: TSubComponents): TChart & TSubComponents;
27
-
28
- /**
29
- * @file Date parsing utilities using date-fns for local timezone handling
30
- *
31
- * This module provides utilities for parsing various date string formats and converting
32
- * them to local timezone dates using the battle-tested date-fns library. For formats
33
- * without timezone info, they're treated as local. For formats with timezone info,
34
- * they're converted to the equivalent local time.
35
- *
36
- * Note: And specifically it prevents format `YYYY-MM-DD` being parsed as UTC date.
37
- *
38
- * Key Features:
39
- * - All parsed dates are in local timezone
40
- * - Converts timezone-aware strings to local equivalent
41
- * - Robust input validation and error handling using date-fns
42
- * - TypeScript type safety
43
- * - Much smaller codebase than custom parsing
44
- *
45
- * Supported Formats:
46
- * - YYYY-MM-DD (treated as local)
47
- * - YYYY-MM-DD HH:mm:ss (treated as local)
48
- * - YYYY-MM-DD HH:mm (treated as local)
49
- * - YYYY-MM-DDTHH:mm:ss (treated as local)
50
- * - YYYY-MM-DDTHH:mm:ss.SSS (treated as local)
51
- * - YYYY-MM-DDTHH:mm (treated as local)
52
- * - YYYY-MM-DDTHH:mm:ssZ (converted to local)
53
- * - YYYY-MM-DDTHH:mm:ss±HH:mm (converted to local)
54
- *
55
- * @example
56
- * ```typescript
57
- * parseAsLocalDate("2025-01-01"); // Local timezone
58
- * parseAsLocalDate("2025-01-01 14:30:00"); // Local timezone
59
- * parseAsLocalDate("2025-01-01 14:30"); // Local timezone
60
- * parseAsLocalDate("2025-01-01T14:30:45.123"); // Local timezone
61
- * parseAsLocalDate("2025-01-01T14:30:00Z"); // UTC 14:30 → Local equivalent
62
- * parseAsLocalDate("2025-01-01T14:30:00+05:00"); // +05:00 14:30 → Local equivalent
63
- * ```
64
- */
65
- /**
66
- * Parses any supported date string format and returns a local timezone date
67
- *
68
- * Uses date-fns for robust parsing and validation. For strings without timezone
69
- * info, treats as local timezone. For strings with timezone info, converts to
70
- * local timezone equivalent.
71
- *
72
- * Supports:
73
- * - YYYY-MM-DD (local)
74
- * - YYYY-MM-DD HH:mm:ss (local)
75
- * - YYYY-MM-DD HH:mm (local)
76
- * - YYYY-MM-DDTHH:mm:ss (local)
77
- * - YYYY-MM-DDTHH:mm:ss.SSS (local)
78
- * - YYYY-MM-DDTHH:mm (local)
79
- * - YYYY-MM-DDTHH:mm:ssZ (UTC → local)
80
- * - YYYY-MM-DDTHH:mm:ss±HH:mm (offset → local)
81
- * @param {string} dateString - The date string to parse into a local timezone date
82
- * @return {Date} A Date object representing the parsed date in local timezone, or an invalid Date if parsing fails
83
- */
84
- declare const parseAsLocalDate: (dateString: string) => Date;
85
-
86
- /**
87
- * Format a percentage value with smart decimal handling.
88
- * Uses `@automattic/number-formatters` for consistent formatting.
89
- * Removes unnecessary trailing zeros and caps at 2 decimal places.
90
- *
91
- * @param value - The percentage value (0-100 range)
92
- * @return Formatted percentage string (e.g., "30%", "30.1%", "30.25%")
93
- */
94
- declare const formatPercentage: (value: number) => string;
95
-
96
- /**
97
- * Returns the width of the longest tick.
98
- *
99
- * @param ticks - Ticks to get the width of.
100
- * @param formatTick - Function to format the tick.
101
- * @param {object} labelStyle - Style object for the label.
102
- * @return {number} - Width of the longest tick.
103
- */
104
- declare const getLongestTickWidth: <T extends AnyD3Scale>(ticks: ScaleInput<T>[], formatTick: TickFormatter<ScaleInput<T>>, labelStyle?: object) => number;
105
-
106
- /**
107
- * Utility function to get consolidated line styles for a series
108
- * This consolidates the logic used by both LineChart and Legend components
109
- *
110
- * @param {SeriesData} seriesData - The series data containing styling options
111
- * @param {number} index - The index of the series in the data array
112
- * @param {ChartTheme} providerTheme - The chart theme configuration
113
- * @return {LineStyles} The consolidated line styles for the series
114
- */
115
- declare function getSeriesLineStyles(seriesData: SeriesData, index: number, providerTheme: ChartTheme): LineStyles;
116
- /**
117
- * Utility function to get stroke color for a series
118
- *
119
- * @param {SeriesData} seriesData - The series data containing styling options
120
- * @param {number} index - The index of the series in the data array
121
- * @param {string[]} themeColors - Array of theme colors
122
- * @return {string} The stroke color for the series
123
- */
124
- declare function getSeriesStroke(seriesData: SeriesData, index: number, themeColors: string[]): string;
125
- /**
126
- * Utility function to get shape styles for a legend item
127
- *
128
- * @param {SeriesData} series - The series data containing styling options
129
- * @param {number} index - The index of the series in the data array
130
- * @param {ChartTheme} theme - The chart theme configuration
131
- * @param {LegendShape} legendShape - The shape to use for the item (optional)
132
- * @return {Record< string, unknown >} The shape styles for the item
133
- */
134
- declare function getItemShapeStyles(series: SeriesData, index: number, theme: ChartTheme, legendShape?: LegendShape<SeriesData[], number>): Record<string, unknown>;
135
-
136
- declare const isSafari: () => boolean;
137
-
138
- /**
139
- * Merges chart themes with proper precedence.
140
- * The second theme (override) takes precedence over the first theme (base).
141
- *
142
- * @param baseTheme - Base theme object
143
- * @param overrideTheme - Theme to override base with (takes precedence)
144
- * @return Merged theme with overrideTheme values taking precedence
145
- */
146
- declare function mergeThemes(baseTheme: CompleteChartTheme, overrideTheme: Partial<ChartTheme>): CompleteChartTheme;
147
- declare function mergeThemes(baseTheme: ChartTheme, overrideTheme: Partial<ChartTheme>): ChartTheme;
148
-
149
- /**
150
- * Check if a value is a valid 6-digit hex color
151
- * @param hex - The value to check
152
- * @return true if valid hex color format (e.g., '#ff0000')
153
- */
154
- declare const isValidHexColor: (hex: unknown) => hex is string;
155
- /**
156
- * Validate hex color format, throwing descriptive errors if invalid
157
- * @param hex - The hex color string to validate
158
- * @throws {Error} if hex string is malformed
159
- */
160
- declare const validateHexColor: (hex: unknown) => void;
161
- /**
162
- * Convert hex color to rgba with specified opacity.
163
- * This is genuinely reusable across chart components.
164
- * @param hex - The hex color string (e.g., '#ff0000')
165
- * @param alpha - The opacity value. Values outside the [0, 1] range will be clamped by the underlying d3 color library.
166
- * @return The rgba color string (e.g., 'rgba(255, 0, 0, 0.5)')
167
- * @throws {Error} if hex string is malformed or alpha is not a valid number
168
- */
169
- declare const hexToRgba: (hex: string, alpha: number) => string;
170
- /**
171
- * Calculate the perceptual distance between two HSL colors
172
- * @param hsl1 - first color in HSL format [h, s, l]
173
- * @param hsl2 - second color in HSL format [h, s, l]
174
- * @return distance value (0-100+, lower means more similar)
175
- */
176
- declare const getColorDistance: (hsl1: [number, number, number], hsl2: [number, number, number]) => number;
177
- /**
178
- * Parse an HSL string like 'hsl(120, 50%, 50%)' into an HSL tuple.
179
- *
180
- * @param hslString - HSL color string
181
- * @return HSL tuple [h, s, l] or null if invalid
182
- */
183
- declare const parseHslString: (hslString: string) => [number, number, number] | null;
184
- /**
185
- * Parse an RGB string like 'rgb(255, 0, 0)' into a hex color.
186
- *
187
- * @param rgbString - RGB color string
188
- * @return hex color string or null if invalid
189
- */
190
- declare const parseRgbString: (rgbString: string) => string | null;
191
- /**
192
- * Normalize any CSS color value to a hex color string.
193
- * Handles hex colors, HSL strings, RGB strings, and CSS variables.
194
- *
195
- * @param color - Any CSS color value
196
- * @param element - Optional DOM element for resolving CSS variables
197
- * @param resolveCss - Function to resolve CSS variables (injected for testability)
198
- * @return hex color string, or the original value if conversion fails
199
- */
200
- declare const normalizeColorToHex: (color: string, element?: HTMLElement | null, resolveCss?: (value: string, el?: HTMLElement | null) => string | null) => string;
201
- /**
202
- * Lighten a hex color by blending it with white.
203
- * Useful for creating color gradients or lighter variants.
204
- *
205
- * @param hex - Hex color string (e.g., '#98C8DF')
206
- * @param blend - Blend amount with white (0 = original color, 1 = white)
207
- * @return Lightened hex color string (e.g., '#cce4ef')
208
- * @throws {Error} if hex string is malformed
209
- */
210
- declare const lightenHexColor: (hex: string, blend: number) => string;
211
-
212
- /**
213
- * Resolves a CSS custom property (variable) to its computed value.
214
- * Handles multiple formats:
215
- * - Plain variable names: '--my-color'
216
- * - CSS var() syntax: 'var(--my-color)'
217
- * - CSS var() with fallback: 'var(--my-color, #ffffff)'
218
- * - Regular values (returned as-is): '#ffffff', 'red'
219
- *
220
- * @param value - A CSS variable name, var() expression, or regular value
221
- * @param element - Optional DOM element to resolve the variable from (defaults to document.documentElement)
222
- * @return The resolved value, fallback value, or null if unresolvable
223
- */
224
- declare const resolveCssVariable: (value: string, element?: HTMLElement | null) => string | null;
225
-
226
- export { attachSubComponents, formatPercentage, getColorDistance, getItemShapeStyles, getLongestTickWidth, getSeriesLineStyles, getSeriesStroke, hexToRgba, isSafari, isValidHexColor, lightenHexColor, mergeThemes, normalizeColorToHex, parseAsLocalDate, parseHslString, parseRgbString, resolveCssVariable, validateHexColor };
@@ -1,44 +0,0 @@
1
- import {
2
- attachSubComponents,
3
- formatMetricValue,
4
- formatPercentage,
5
- getColorDistance,
6
- getItemShapeStyles,
7
- getLongestTickWidth,
8
- getSeriesLineStyles,
9
- getSeriesStroke,
10
- hexToRgba,
11
- isSafari,
12
- isValidHexColor,
13
- lightenHexColor,
14
- mergeThemes,
15
- normalizeColorToHex,
16
- parseAsLocalDate,
17
- parseHslString,
18
- parseRgbString,
19
- resolveCssVariable,
20
- validateHexColor
21
- } from "../chunk-DAU3HNEG.js";
22
- import "../chunk-G3PMV62Z.js";
23
- export {
24
- attachSubComponents,
25
- formatMetricValue,
26
- formatPercentage,
27
- getColorDistance,
28
- getItemShapeStyles,
29
- getLongestTickWidth,
30
- getSeriesLineStyles,
31
- getSeriesStroke,
32
- hexToRgba,
33
- isSafari,
34
- isValidHexColor,
35
- lightenHexColor,
36
- mergeThemes,
37
- normalizeColorToHex,
38
- parseAsLocalDate,
39
- parseHslString,
40
- parseRgbString,
41
- resolveCssVariable,
42
- validateHexColor
43
- };
44
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,18 +0,0 @@
1
- type ResponsiveConfig = {
2
- /**
3
- * The maximum width of the chart. Defaults to 1200.
4
- */
5
- maxWidth?: number;
6
- /**
7
- * The aspect ratio of the chart (height = width * aspectRatio).
8
- * When provided, height is calculated from width.
9
- * When omitted, the chart fills the parent container's height.
10
- */
11
- aspectRatio?: number;
12
- /**
13
- * Child render updates upon resize are delayed until debounceTime milliseconds after the last resize event is observed.
14
- */
15
- resizeDebounceTime?: number;
16
- };
17
-
18
- export type { ResponsiveConfig as R };
@@ -1,18 +0,0 @@
1
- type ResponsiveConfig = {
2
- /**
3
- * The maximum width of the chart. Defaults to 1200.
4
- */
5
- maxWidth?: number;
6
- /**
7
- * The aspect ratio of the chart (height = width * aspectRatio).
8
- * When provided, height is calculated from width.
9
- * When omitted, the chart fills the parent container's height.
10
- */
11
- aspectRatio?: number;
12
- /**
13
- * Child render updates upon resize are delayed until debounceTime milliseconds after the last resize event is observed.
14
- */
15
- resizeDebounceTime?: number;
16
- };
17
-
18
- export type { ResponsiveConfig as R };
@@ -1,22 +0,0 @@
1
- import { Children, isValidElement, useMemo, type ReactNode } from 'react';
2
- import { Legend } from '../components/legend';
3
-
4
- /**
5
- * Hook to detect if children contain a Legend component (composition pattern).
6
- *
7
- * @param {ReactNode} children - React children to search through
8
- * @return {boolean} Whether a Legend component is present in children
9
- */
10
- export function useHasLegendChild( children: ReactNode ): boolean {
11
- return useMemo( () => {
12
- let found = false;
13
-
14
- Children.forEach( children, child => {
15
- if ( isValidElement( child ) && child.type === Legend ) {
16
- found = true;
17
- }
18
- } );
19
-
20
- return found;
21
- }, [ children ] );
22
- }