@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,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 { o as SeriesData, b as ChartTheme, c as CompleteChartTheme } from '../types-ChOUI9-N.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 { o as SeriesData, b as ChartTheme, c as CompleteChartTheme } from '../types-ChOUI9-N.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-JJIMABHT.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 };