@automattic/charts 0.56.3 → 0.56.5

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 (186) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/charts/bar-chart/index.cjs +5 -5
  3. package/dist/charts/bar-chart/index.css +12 -0
  4. package/dist/charts/bar-chart/index.css.map +1 -1
  5. package/dist/charts/bar-chart/index.js +4 -4
  6. package/dist/charts/bar-list-chart/index.cjs +6 -6
  7. package/dist/charts/bar-list-chart/index.css +12 -0
  8. package/dist/charts/bar-list-chart/index.css.map +1 -1
  9. package/dist/charts/bar-list-chart/index.js +5 -5
  10. package/dist/charts/conversion-funnel-chart/index.cjs +5 -3
  11. package/dist/charts/conversion-funnel-chart/index.cjs.map +1 -1
  12. package/dist/charts/conversion-funnel-chart/index.css +14 -1
  13. package/dist/charts/conversion-funnel-chart/index.css.map +1 -1
  14. package/dist/charts/conversion-funnel-chart/index.d.cts +2 -0
  15. package/dist/charts/conversion-funnel-chart/index.d.ts +2 -0
  16. package/dist/charts/conversion-funnel-chart/index.js +4 -2
  17. package/dist/charts/geo-chart/index.cjs +4 -4
  18. package/dist/charts/geo-chart/index.css +12 -0
  19. package/dist/charts/geo-chart/index.css.map +1 -1
  20. package/dist/charts/geo-chart/index.js +3 -3
  21. package/dist/charts/leaderboard-chart/index.cjs +5 -5
  22. package/dist/charts/leaderboard-chart/index.css +12 -0
  23. package/dist/charts/leaderboard-chart/index.css.map +1 -1
  24. package/dist/charts/leaderboard-chart/index.js +4 -4
  25. package/dist/charts/line-chart/index.cjs +5 -5
  26. package/dist/charts/line-chart/index.css +12 -0
  27. package/dist/charts/line-chart/index.css.map +1 -1
  28. package/dist/charts/line-chart/index.js +4 -4
  29. package/dist/charts/pie-chart/index.cjs +7 -7
  30. package/dist/charts/pie-chart/index.css +12 -0
  31. package/dist/charts/pie-chart/index.css.map +1 -1
  32. package/dist/charts/pie-chart/index.js +6 -6
  33. package/dist/charts/pie-semi-circle-chart/index.cjs +7 -7
  34. package/dist/charts/pie-semi-circle-chart/index.css +12 -0
  35. package/dist/charts/pie-semi-circle-chart/index.css.map +1 -1
  36. package/dist/charts/pie-semi-circle-chart/index.js +6 -6
  37. package/dist/charts/sparkline/index.cjs +6 -6
  38. package/dist/charts/sparkline/index.css +12 -0
  39. package/dist/charts/sparkline/index.css.map +1 -1
  40. package/dist/charts/sparkline/index.js +5 -5
  41. package/dist/{chunk-OTZT3MC2.cjs → chunk-2A34OA5O.cjs} +19 -20
  42. package/dist/chunk-2A34OA5O.cjs.map +1 -0
  43. package/dist/{chunk-H34CJSR6.js → chunk-32ESS4MV.js} +406 -363
  44. package/dist/chunk-32ESS4MV.js.map +1 -0
  45. package/dist/{chunk-CEZGL6YP.js → chunk-6CCZL2JJ.js} +15 -7
  46. package/dist/chunk-6CCZL2JJ.js.map +1 -0
  47. package/dist/{chunk-NW3RUYK2.cjs → chunk-7QDEU3KN.cjs} +15 -22
  48. package/dist/chunk-7QDEU3KN.cjs.map +1 -0
  49. package/dist/chunk-7TQSPLIN.js +351 -0
  50. package/dist/chunk-7TQSPLIN.js.map +1 -0
  51. package/dist/{chunk-T4J6TI55.js → chunk-AFWQR3SM.js} +102 -79
  52. package/dist/chunk-AFWQR3SM.js.map +1 -0
  53. package/dist/{chunk-5XI443YP.js → chunk-BPYKWMI7.js} +72 -64
  54. package/dist/chunk-BPYKWMI7.js.map +1 -0
  55. package/dist/{chunk-TNRKEBTA.js → chunk-DBY6C4O2.js} +148 -164
  56. package/dist/{chunk-TNRKEBTA.js.map → chunk-DBY6C4O2.js.map} +1 -1
  57. package/dist/chunk-DLSUC7RN.js +1065 -0
  58. package/dist/chunk-DLSUC7RN.js.map +1 -0
  59. package/dist/{chunk-TVV7ZI7C.cjs → chunk-EJJO2QNB.cjs} +399 -356
  60. package/dist/chunk-EJJO2QNB.cjs.map +1 -0
  61. package/dist/{chunk-ODF5O5PV.cjs → chunk-FIFSYVN6.cjs} +154 -170
  62. package/dist/chunk-FIFSYVN6.cjs.map +1 -0
  63. package/dist/chunk-FY325WQ4.cjs +1065 -0
  64. package/dist/chunk-FY325WQ4.cjs.map +1 -0
  65. package/dist/{chunk-SRXJLAKG.cjs → chunk-I2276W3I.cjs} +28 -37
  66. package/dist/chunk-I2276W3I.cjs.map +1 -0
  67. package/dist/{chunk-7UJPVCMB.cjs → chunk-IHESL7H5.cjs} +265 -262
  68. package/dist/chunk-IHESL7H5.cjs.map +1 -0
  69. package/dist/chunk-JL4ZKKZU.cjs +375 -0
  70. package/dist/chunk-JL4ZKKZU.cjs.map +1 -0
  71. package/dist/chunk-KHRPRH4V.js +165 -0
  72. package/dist/chunk-KHRPRH4V.js.map +1 -0
  73. package/dist/{chunk-A3AEEGKR.js → chunk-KXRWNFQJ.js} +20 -21
  74. package/dist/chunk-KXRWNFQJ.js.map +1 -0
  75. package/dist/{chunk-2VPPTJS2.js → chunk-KXSLMOW5.js} +256 -253
  76. package/dist/chunk-KXSLMOW5.js.map +1 -0
  77. package/dist/chunk-LT4YOIMM.js +375 -0
  78. package/dist/chunk-LT4YOIMM.js.map +1 -0
  79. package/dist/chunk-LTPJPIDP.cjs +165 -0
  80. package/dist/chunk-LTPJPIDP.cjs.map +1 -0
  81. package/dist/chunk-NGHXTIUE.cjs +120 -0
  82. package/dist/chunk-NGHXTIUE.cjs.map +1 -0
  83. package/dist/chunk-PCOI2GT5.js +120 -0
  84. package/dist/chunk-PCOI2GT5.js.map +1 -0
  85. package/dist/{chunk-YYQ4IK5V.cjs → chunk-Q6G3BGCL.cjs} +103 -80
  86. package/dist/chunk-Q6G3BGCL.cjs.map +1 -0
  87. package/dist/{chunk-HIWNB5PK.cjs → chunk-RCY6XLGU.cjs} +13 -5
  88. package/dist/chunk-RCY6XLGU.cjs.map +1 -0
  89. package/dist/chunk-TKPK4RFS.cjs +351 -0
  90. package/dist/chunk-TKPK4RFS.cjs.map +1 -0
  91. package/dist/{chunk-C33AQZEC.js → chunk-TYIH5LMV.js} +16 -23
  92. package/dist/chunk-TYIH5LMV.js.map +1 -0
  93. package/dist/chunk-X6GX4QUJ.js +421 -0
  94. package/dist/chunk-X6GX4QUJ.js.map +1 -0
  95. package/dist/chunk-XCXAWMJQ.cjs +421 -0
  96. package/dist/chunk-XCXAWMJQ.cjs.map +1 -0
  97. package/dist/chunk-XWYZIFZW.js +66 -0
  98. package/dist/chunk-XWYZIFZW.js.map +1 -0
  99. package/dist/{chunk-7HROSZRS.cjs → chunk-Y3NNQMAX.cjs} +70 -62
  100. package/dist/chunk-Y3NNQMAX.cjs.map +1 -0
  101. package/dist/components/legend/index.cjs +2 -2
  102. package/dist/components/legend/index.css +12 -0
  103. package/dist/components/legend/index.css.map +1 -1
  104. package/dist/components/legend/index.js +1 -1
  105. package/dist/components/tooltip/index.cjs +2 -2
  106. package/dist/components/tooltip/index.js +1 -1
  107. package/dist/components/trend-indicator/index.cjs +2 -2
  108. package/dist/components/trend-indicator/index.js +1 -1
  109. package/dist/hooks/index.cjs +4 -2
  110. package/dist/hooks/index.cjs.map +1 -1
  111. package/dist/hooks/index.css +12 -0
  112. package/dist/hooks/index.css.map +1 -1
  113. package/dist/hooks/index.d.cts +28 -2
  114. package/dist/hooks/index.d.ts +28 -2
  115. package/dist/hooks/index.js +3 -1
  116. package/dist/index.cjs +18 -18
  117. package/dist/index.cjs.map +1 -1
  118. package/dist/index.css +14 -1
  119. package/dist/index.css.map +1 -1
  120. package/dist/index.d.cts +1 -1
  121. package/dist/index.d.ts +1 -1
  122. package/dist/index.js +17 -17
  123. package/dist/providers/index.cjs +2 -2
  124. package/dist/providers/index.css +12 -0
  125. package/dist/providers/index.css.map +1 -1
  126. package/dist/providers/index.d.cts +1 -1
  127. package/dist/providers/index.d.ts +1 -1
  128. package/dist/providers/index.js +1 -1
  129. package/dist/{themes-DQs9rbN5.d.cts → themes-BDVaIfBz.d.cts} +9 -0
  130. package/dist/{themes-CRV5fVzJ.d.ts → themes-mcS8QNkQ.d.ts} +9 -0
  131. package/package.json +6 -2
  132. package/src/charts/conversion-funnel-chart/conversion-funnel-chart.module.scss +2 -1
  133. package/src/charts/conversion-funnel-chart/conversion-funnel-chart.tsx +16 -6
  134. package/src/charts/conversion-funnel-chart/test/conversion-funnel-chart.test.tsx +34 -0
  135. package/src/charts/conversion-funnel-chart/types.ts +2 -0
  136. package/src/charts/pie-chart/pie-chart.tsx +2 -3
  137. package/src/hooks/index.ts +1 -0
  138. package/src/hooks/test/use-chart-margin.test.tsx +44 -0
  139. package/src/hooks/test/use-tooltip-portal-relocator.test.ts +216 -0
  140. package/src/hooks/use-chart-margin.tsx +92 -6
  141. package/src/hooks/use-tooltip-portal-relocator.module.scss +10 -0
  142. package/src/hooks/use-tooltip-portal-relocator.ts +177 -0
  143. package/src/providers/chart-context/global-charts-provider.tsx +18 -1
  144. package/tsup.config.ts +11 -0
  145. package/dist/chunk-2VPPTJS2.js.map +0 -1
  146. package/dist/chunk-5XI443YP.js.map +0 -1
  147. package/dist/chunk-7HROSZRS.cjs.map +0 -1
  148. package/dist/chunk-7UJPVCMB.cjs.map +0 -1
  149. package/dist/chunk-A3AEEGKR.js.map +0 -1
  150. package/dist/chunk-C33AQZEC.js.map +0 -1
  151. package/dist/chunk-CEZGL6YP.js.map +0 -1
  152. package/dist/chunk-COOC2TVQ.js +0 -167
  153. package/dist/chunk-COOC2TVQ.js.map +0 -1
  154. package/dist/chunk-EJHLLXBV.js +0 -362
  155. package/dist/chunk-EJHLLXBV.js.map +0 -1
  156. package/dist/chunk-FWMJ2FR2.js +0 -121
  157. package/dist/chunk-FWMJ2FR2.js.map +0 -1
  158. package/dist/chunk-GRYNIPWH.cjs +0 -385
  159. package/dist/chunk-GRYNIPWH.cjs.map +0 -1
  160. package/dist/chunk-H34CJSR6.js.map +0 -1
  161. package/dist/chunk-HIWNB5PK.cjs.map +0 -1
  162. package/dist/chunk-IZWC33YN.cjs +0 -357
  163. package/dist/chunk-IZWC33YN.cjs.map +0 -1
  164. package/dist/chunk-KOF32DBL.cjs +0 -1058
  165. package/dist/chunk-KOF32DBL.cjs.map +0 -1
  166. package/dist/chunk-LHWRZMF7.cjs +0 -362
  167. package/dist/chunk-LHWRZMF7.cjs.map +0 -1
  168. package/dist/chunk-MFRS2PEY.cjs +0 -121
  169. package/dist/chunk-MFRS2PEY.cjs.map +0 -1
  170. package/dist/chunk-MMDLXS6O.js +0 -75
  171. package/dist/chunk-MMDLXS6O.js.map +0 -1
  172. package/dist/chunk-NW3RUYK2.cjs.map +0 -1
  173. package/dist/chunk-ODF5O5PV.cjs.map +0 -1
  174. package/dist/chunk-OTZT3MC2.cjs.map +0 -1
  175. package/dist/chunk-SBRMWDWM.js +0 -357
  176. package/dist/chunk-SBRMWDWM.js.map +0 -1
  177. package/dist/chunk-SRXJLAKG.cjs.map +0 -1
  178. package/dist/chunk-T4J6TI55.js.map +0 -1
  179. package/dist/chunk-TVV7ZI7C.cjs.map +0 -1
  180. package/dist/chunk-XVMXWV3C.cjs +0 -167
  181. package/dist/chunk-XVMXWV3C.cjs.map +0 -1
  182. package/dist/chunk-YYQ4IK5V.cjs.map +0 -1
  183. package/dist/chunk-ZDNCF642.js +0 -1058
  184. package/dist/chunk-ZDNCF642.js.map +0 -1
  185. package/dist/chunk-ZWBUEHKF.js +0 -385
  186. package/dist/chunk-ZWBUEHKF.js.map +0 -1
@@ -70,15 +70,98 @@ import { useMemo as useMemo3 } from "react";
70
70
 
71
71
  // src/providers/chart-context/global-charts-provider.tsx
72
72
  import { hsl as d3Hsl2 } from "@visx/vendor/d3-color";
73
- import {
74
- createContext,
75
- useCallback as useCallback2,
76
- useMemo,
77
- useState,
78
- useEffect,
79
- useLayoutEffect,
80
- useRef as useRef2
81
- } from "react";
73
+ import { createContext, useCallback as useCallback2, useMemo, useState, useEffect as useEffect2, useLayoutEffect, useRef as useRef2 } from "react";
74
+
75
+ // src/hooks/use-tooltip-portal-relocator.ts
76
+ import { useEffect } from "react";
77
+
78
+ // src/hooks/use-tooltip-portal-relocator.module.scss
79
+ var use_tooltip_portal_relocator_module_default = {
80
+ "relocatedPortal": "a8ccharts-jCw5dQ"
81
+ };
82
+
83
+ // src/hooks/use-tooltip-portal-relocator.ts
84
+ function isVisxPortalNode(node) {
85
+ return node instanceof HTMLDivElement && node.parentElement === document.body && !node.id && !node.className && node.querySelector(".visx-tooltip") !== null;
86
+ }
87
+ var patchRefCount = 0;
88
+ var origRemoveChild = null;
89
+ var patchedRemoveChild = null;
90
+ var relocatedNodes = /* @__PURE__ */ new WeakSet();
91
+ function installRemoveChildPatch() {
92
+ if (patchRefCount++ > 0) {
93
+ return;
94
+ }
95
+ origRemoveChild = document.body.removeChild;
96
+ patchedRemoveChild = function(child) {
97
+ if (relocatedNodes.has(child) && child.parentNode !== this) {
98
+ relocatedNodes.delete(child);
99
+ child.parentNode?.removeChild(child);
100
+ return child;
101
+ }
102
+ return origRemoveChild.call(this, child);
103
+ };
104
+ document.body.removeChild = patchedRemoveChild;
105
+ }
106
+ function uninstallRemoveChildPatch() {
107
+ if (--patchRefCount > 0) {
108
+ return;
109
+ }
110
+ if (document.body.removeChild === patchedRemoveChild) {
111
+ document.body.removeChild = origRemoveChild;
112
+ }
113
+ origRemoveChild = null;
114
+ patchedRemoveChild = null;
115
+ }
116
+ function useTooltipPortalRelocator(containerRef) {
117
+ useEffect(() => {
118
+ const container = containerRef?.current;
119
+ if (!container) {
120
+ return;
121
+ }
122
+ const instanceNodes = /* @__PURE__ */ new Set();
123
+ const relocateNode = (node) => {
124
+ if (!isVisxPortalNode(node)) {
125
+ return;
126
+ }
127
+ node.classList.add(use_tooltip_portal_relocator_module_default.relocatedPortal);
128
+ const { activeElement } = node.ownerDocument;
129
+ const focusedElement = activeElement instanceof HTMLElement && node.contains(activeElement) ? activeElement : null;
130
+ container.insertBefore(node, container.firstChild);
131
+ relocatedNodes.add(node);
132
+ instanceNodes.add(node);
133
+ if (focusedElement) {
134
+ focusedElement.focus();
135
+ }
136
+ };
137
+ installRemoveChildPatch();
138
+ for (const child of Array.from(document.body.children)) {
139
+ relocateNode(child);
140
+ }
141
+ const observer = new MutationObserver((mutations) => {
142
+ for (const mutation of mutations) {
143
+ for (const node of mutation.addedNodes) {
144
+ relocateNode(node);
145
+ }
146
+ }
147
+ });
148
+ observer.observe(document.body, { childList: true });
149
+ return () => {
150
+ observer.disconnect();
151
+ for (const node of instanceNodes) {
152
+ if (node instanceof HTMLElement) {
153
+ node.classList.remove(use_tooltip_portal_relocator_module_default.relocatedPortal);
154
+ }
155
+ if (node.parentNode === container) {
156
+ document.body.appendChild(node);
157
+ }
158
+ relocatedNodes.delete(node);
159
+ }
160
+ instanceNodes.clear();
161
+ uninstallRemoveChildPatch();
162
+ };
163
+ }, [containerRef]);
164
+ }
82
165
 
83
166
  // src/providers/chart-context/private/get-chart-color.ts
84
167
  import { hsl as d3Hsl } from "@visx/vendor/d3-color";
@@ -229,14 +312,17 @@ var defaultTheme = {
229
312
  };
230
313
 
231
314
  // src/providers/chart-context/global-charts-provider.tsx
232
- import { jsx } from "react/jsx-runtime";
233
- var GlobalChartsContext = createContext(null);
234
- var GlobalChartsProvider = ({ children, theme }) => {
315
+ import { jsx as _jsx } from "react/jsx-runtime";
316
+ var GlobalChartsContext = /* @__PURE__ */ createContext(null);
317
+ var GlobalChartsProvider = ({
318
+ children,
319
+ theme,
320
+ portalContainer
321
+ }) => {
235
322
  const [charts, setCharts] = useState(() => /* @__PURE__ */ new Map());
236
- const [hiddenSeries, setHiddenSeries] = useState(
237
- () => /* @__PURE__ */ new Map()
238
- );
323
+ const [hiddenSeries, setHiddenSeries] = useState(() => /* @__PURE__ */ new Map());
239
324
  const wrapperRef = useRef2(null);
325
+ useTooltipPortalRelocator(portalContainer ?? wrapperRef);
240
326
  const providerTheme = useMemo(() => {
241
327
  return theme ? mergeThemes(defaultTheme, theme) : defaultTheme;
242
328
  }, [theme]);
@@ -248,7 +334,9 @@ var GlobalChartsProvider = ({ children, theme }) => {
248
334
  maxHue: 0
249
335
  }));
250
336
  useLayoutEffect(() => {
251
- const { colors } = providerTheme;
337
+ const {
338
+ colors
339
+ } = providerTheme;
252
340
  const resolvedColors = [];
253
341
  const hues = [];
254
342
  const existingHslColors = [];
@@ -269,11 +357,7 @@ var GlobalChartsProvider = ({ children, theme }) => {
269
357
  resolvedColors.push(colorValue);
270
358
  const hslColor = d3Hsl2(colorValue);
271
359
  if (!isNaN(hslColor.h)) {
272
- const hslTuple = [
273
- hslColor.h,
274
- hslColor.s * 100,
275
- hslColor.l * 100
276
- ];
360
+ const hslTuple = [hslColor.h, hslColor.s * 100, hslColor.l * 100];
277
361
  hues.push(hslTuple[0]);
278
362
  existingHslColors.push(hslTuple);
279
363
  minHue = Math.min(minHue, hslTuple[0]);
@@ -291,10 +375,8 @@ var GlobalChartsProvider = ({ children, theme }) => {
291
375
  maxHue
292
376
  });
293
377
  }, [providerTheme]);
294
- const [groupToColorMap, setGroupToColorMap] = useState(
295
- () => /* @__PURE__ */ new Map()
296
- );
297
- useEffect(() => {
378
+ const [groupToColorMap, setGroupToColorMap] = useState(() => /* @__PURE__ */ new Map());
379
+ useEffect2(() => {
298
380
  setGroupToColorMap(/* @__PURE__ */ new Map());
299
381
  }, [providerTheme.colors]);
300
382
  const registerChart = useCallback2((id, data) => {
@@ -307,52 +389,48 @@ var GlobalChartsProvider = ({ children, theme }) => {
307
389
  return newMap;
308
390
  });
309
391
  }, []);
310
- const getChartData = useCallback2(
311
- (id) => {
312
- return charts.get(id);
313
- },
314
- [charts]
315
- );
316
- const resolveColor = useCallback2(
317
- ({
318
- group,
319
- index,
320
- overrideColor
321
- }) => {
322
- if (overrideColor) {
323
- return normalizeColorToHex(overrideColor, wrapperRef.current, resolveCssVariable);
324
- }
325
- if (group) {
326
- const existing = groupToColorMap.get(group);
327
- if (existing) {
328
- return existing;
329
- }
330
- const assignedCount = groupToColorMap.size;
331
- const color = getChartColor(assignedCount, colorCache);
332
- groupToColorMap.set(group, color);
333
- return color;
392
+ const getChartData = useCallback2((id) => {
393
+ return charts.get(id);
394
+ }, [charts]);
395
+ const resolveColor = useCallback2(({
396
+ group,
397
+ index,
398
+ overrideColor
399
+ }) => {
400
+ if (overrideColor) {
401
+ return normalizeColorToHex(overrideColor, wrapperRef.current, resolveCssVariable);
402
+ }
403
+ if (group) {
404
+ const existing = groupToColorMap.get(group);
405
+ if (existing) {
406
+ return existing;
334
407
  }
335
- return getChartColor(index, colorCache);
336
- },
337
- [colorCache, groupToColorMap]
338
- );
339
- const getElementStyles = useCallback2(
340
- ({ data, index, overrideColor, legendShape }) => {
341
- const isSeriesData = data && typeof data === "object" && "data" in data && "options" in data;
342
- const isPointPercentageData = data && typeof data === "object" && "percentage" in data;
343
- return {
344
- color: resolveColor({
345
- group: data?.group,
346
- index,
347
- overrideColor: overrideColor || isSeriesData && data?.options?.stroke || isPointPercentageData && data?.color
348
- }),
349
- lineStyles: isSeriesData ? getSeriesLineStyles(data, index, providerTheme) : {},
350
- glyph: providerTheme.glyphs?.[index],
351
- shapeStyles: isSeriesData ? getItemShapeStyles(data, index, providerTheme, legendShape) : {}
352
- };
353
- },
354
- [providerTheme, resolveColor]
355
- );
408
+ const assignedCount = groupToColorMap.size;
409
+ const color = getChartColor(assignedCount, colorCache);
410
+ groupToColorMap.set(group, color);
411
+ return color;
412
+ }
413
+ return getChartColor(index, colorCache);
414
+ }, [colorCache, groupToColorMap]);
415
+ const getElementStyles = useCallback2(({
416
+ data,
417
+ index,
418
+ overrideColor,
419
+ legendShape
420
+ }) => {
421
+ const isSeriesData = data && typeof data === "object" && "data" in data && "options" in data;
422
+ const isPointPercentageData = data && typeof data === "object" && "percentage" in data;
423
+ return {
424
+ color: resolveColor({
425
+ group: data?.group,
426
+ index,
427
+ overrideColor: overrideColor || isSeriesData && data?.options?.stroke || isPointPercentageData && data?.color
428
+ }),
429
+ lineStyles: isSeriesData ? getSeriesLineStyles(data, index, providerTheme) : {},
430
+ glyph: providerTheme.glyphs?.[index],
431
+ shapeStyles: isSeriesData ? getItemShapeStyles(data, index, providerTheme, legendShape) : {}
432
+ };
433
+ }, [providerTheme, resolveColor]);
356
434
  const toggleSeriesVisibility = useCallback2((chartId, seriesLabel) => {
357
435
  setHiddenSeries((prev) => {
358
436
  const newMap = new Map(prev);
@@ -371,45 +449,35 @@ var GlobalChartsProvider = ({ children, theme }) => {
371
449
  return newMap;
372
450
  });
373
451
  }, []);
374
- const isSeriesVisible = useCallback2(
375
- (chartId, seriesLabel) => {
376
- const chartHidden = hiddenSeries.get(chartId);
377
- return !chartHidden || !chartHidden.has(seriesLabel);
378
- },
379
- [hiddenSeries]
380
- );
381
- const getHiddenSeries = useCallback2(
382
- (chartId) => {
383
- const set = hiddenSeries.get(chartId);
384
- return set ? new Set(set) : /* @__PURE__ */ new Set();
385
- },
386
- [hiddenSeries]
387
- );
388
- const value = useMemo(
389
- () => ({
390
- charts,
391
- registerChart,
392
- unregisterChart,
393
- getChartData,
394
- theme: providerTheme,
395
- getElementStyles,
396
- toggleSeriesVisibility,
397
- isSeriesVisible,
398
- getHiddenSeries
399
- }),
400
- [
401
- charts,
402
- registerChart,
403
- unregisterChart,
404
- getChartData,
405
- providerTheme,
406
- getElementStyles,
407
- toggleSeriesVisibility,
408
- isSeriesVisible,
409
- getHiddenSeries
410
- ]
411
- );
412
- return /* @__PURE__ */ jsx(GlobalChartsContext.Provider, { value, children: /* @__PURE__ */ jsx("div", { ref: wrapperRef, style: { display: "contents" }, children }) });
452
+ const isSeriesVisible = useCallback2((chartId, seriesLabel) => {
453
+ const chartHidden = hiddenSeries.get(chartId);
454
+ return !chartHidden || !chartHidden.has(seriesLabel);
455
+ }, [hiddenSeries]);
456
+ const getHiddenSeries = useCallback2((chartId) => {
457
+ const set = hiddenSeries.get(chartId);
458
+ return set ? new Set(set) : /* @__PURE__ */ new Set();
459
+ }, [hiddenSeries]);
460
+ const value = useMemo(() => ({
461
+ charts,
462
+ registerChart,
463
+ unregisterChart,
464
+ getChartData,
465
+ theme: providerTheme,
466
+ getElementStyles,
467
+ toggleSeriesVisibility,
468
+ isSeriesVisible,
469
+ getHiddenSeries
470
+ }), [charts, registerChart, unregisterChart, getChartData, providerTheme, getElementStyles, toggleSeriesVisibility, isSeriesVisible, getHiddenSeries]);
471
+ return /* @__PURE__ */ _jsx(GlobalChartsContext.Provider, {
472
+ value,
473
+ children: /* @__PURE__ */ _jsx("div", {
474
+ ref: wrapperRef,
475
+ style: {
476
+ display: "contents"
477
+ },
478
+ children
479
+ })
480
+ });
413
481
  };
414
482
 
415
483
  // src/providers/chart-context/hooks/use-global-charts-context.ts
@@ -430,7 +498,7 @@ var useChartId = (providedId) => {
430
498
  };
431
499
 
432
500
  // src/providers/chart-context/hooks/use-chart-registration.ts
433
- import { useEffect as useEffect2, useMemo as useMemo2 } from "react";
501
+ import { useEffect as useEffect3, useMemo as useMemo2 } from "react";
434
502
  var useChartRegistration = ({
435
503
  chartId,
436
504
  legendItems,
@@ -441,7 +509,7 @@ var useChartRegistration = ({
441
509
  const { registerChart, unregisterChart } = useGlobalChartsContext();
442
510
  const stableLegendItems = useDeepMemo(legendItems);
443
511
  const memoizedMetadata = useMemo2(() => metadata, [metadata]);
444
- useEffect2(() => {
512
+ useEffect3(() => {
445
513
  if (isDataValid) {
446
514
  registerChart(chartId, {
447
515
  legendItems: stableLegendItems,
@@ -516,13 +584,38 @@ var useChartDataTransform = (data) => {
516
584
  // src/hooks/use-chart-margin.tsx
517
585
  import { createScale, getTicks } from "@visx/scale";
518
586
  import { useMemo as useMemo5 } from "react";
587
+ var DEFAULT_MARGIN_TOP = 10;
588
+ var DEFAULT_MARGIN_RIGHT = 20;
589
+ var DEFAULT_MARGIN_BOTTOM = 20;
590
+ var DEFAULT_MARGIN_LEFT = 20;
591
+ var DEFAULT_BOTTOM_FOR_TOP_AXIS = 10;
592
+ var DEFAULT_FONT_SIZE = 12;
593
+ var DEFAULT_TICK_LENGTH = 8;
594
+ var DEFAULT_Y_TICK_WIDTH = 40;
595
+ var resolveFontSize = (val) => {
596
+ if (typeof val === "number" && !isNaN(val)) {
597
+ return val;
598
+ }
599
+ if (typeof val === "string") {
600
+ const parsed = parseFloat(val);
601
+ return isNaN(parsed) ? void 0 : parsed;
602
+ }
603
+ return void 0;
604
+ };
605
+ var getXAxisLabelMetrics = (theme, orientation) => {
606
+ const xAxisStyles = orientation === "top" ? theme.axisStyles?.x?.top : theme.axisStyles?.x?.bottom;
607
+ const fontSize = resolveFontSize(xAxisStyles?.axisLabel?.fontSize) || resolveFontSize(theme.svgLabelSmall?.fontSize) || DEFAULT_FONT_SIZE;
608
+ const tickLength = xAxisStyles?.tickLength ?? DEFAULT_TICK_LENGTH;
609
+ return {
610
+ fontSize,
611
+ tickLength
612
+ };
613
+ };
519
614
  var useChartMargin = (height, options, data, theme, horizontal = false) => {
520
615
  const yTicks = useMemo5(() => {
521
616
  const allDataPoints = data.flatMap((series) => series.data);
522
617
  if (horizontal) {
523
- return allDataPoints.map(
524
- (d) => d.label || options.axis?.y?.tickFormat(d.date.getTime(), 0, [])
525
- );
618
+ return allDataPoints.map((d) => d.label || options.axis?.y?.tickFormat(d.date.getTime(), 0, []));
526
619
  }
527
620
  const minY = Math.min(...allDataPoints.map((d) => d.value));
528
621
  const maxY = Math.max(...allDataPoints.map((d) => d.value));
@@ -534,24 +627,32 @@ var useChartMargin = (height, options, data, theme, horizontal = false) => {
534
627
  return getTicks(yScale, options.axis?.y?.numTicks);
535
628
  }, [options, data, height, horizontal]);
536
629
  return useMemo5(() => {
537
- const defaultMargin = { top: 10, right: 20, bottom: 20, left: 20 };
538
- const defaultTickWidth = 40;
630
+ const defaultMargin = {
631
+ top: DEFAULT_MARGIN_TOP,
632
+ right: DEFAULT_MARGIN_RIGHT,
633
+ bottom: DEFAULT_MARGIN_BOTTOM,
634
+ left: DEFAULT_MARGIN_LEFT
635
+ };
539
636
  const yAxisOrientation = options.axis?.y?.orientation;
540
637
  const yAxisStyles = yAxisOrientation === "right" ? theme.axisStyles.y.right : theme.axisStyles.y.left;
541
- const yTickWidth = getLongestTickWidth(
542
- yTicks,
543
- options.axis?.y?.tickFormat,
544
- yAxisStyles.axisLabel
545
- );
546
- const yMarginValue = (yTickWidth ?? defaultTickWidth) + (yAxisStyles?.tickLength ?? 0);
638
+ const yTickWidth = getLongestTickWidth(yTicks, options.axis?.y?.tickFormat, yAxisStyles.axisLabel);
639
+ const yMarginValue = (yTickWidth ?? DEFAULT_Y_TICK_WIDTH) + (yAxisStyles?.tickLength ?? 0);
547
640
  if (yAxisOrientation === "right") {
548
641
  defaultMargin.right = yMarginValue;
549
642
  } else {
550
643
  defaultMargin.left = yMarginValue;
551
644
  }
552
- if (options.axis?.x?.orientation === "top") {
553
- defaultMargin.top = 20;
554
- defaultMargin.bottom = 10;
645
+ const xOrientation = options.axis?.x?.orientation === "top" ? "top" : "bottom";
646
+ const {
647
+ fontSize,
648
+ tickLength
649
+ } = getXAxisLabelMetrics(theme, xOrientation);
650
+ const computedXMargin = fontSize + tickLength;
651
+ if (xOrientation === "top") {
652
+ defaultMargin.top = Math.max(defaultMargin.top, computedXMargin);
653
+ defaultMargin.bottom = DEFAULT_BOTTOM_FOR_TOP_AXIS;
654
+ } else {
655
+ defaultMargin.bottom = Math.max(defaultMargin.bottom, computedXMargin);
555
656
  }
556
657
  return defaultMargin;
557
658
  }, [options, theme, yTicks]);
@@ -590,7 +691,7 @@ import { useContext as useContext5, useMemo as useMemo6, forwardRef as forwardRe
590
691
 
591
692
  // src/charts/private/single-chart-context/single-chart-context.tsx
592
693
  import { createContext as createContext2 } from "react";
593
- var ChartInstanceContext = createContext2(null);
694
+ var ChartInstanceContext = /* @__PURE__ */ createContext2(null);
594
695
  var SingleChartContext = ChartInstanceContext;
595
696
 
596
697
  // src/charts/private/single-chart-context/use-single-chart-context.ts
@@ -609,11 +710,7 @@ import { Group } from "@visx/group";
609
710
  import { LegendItem, LegendLabel, LegendOrdinal, LegendShape } from "@visx/legend";
610
711
  import { scaleOrdinal } from "@visx/scale";
611
712
  import clsx from "clsx";
612
- import {
613
- forwardRef,
614
- useCallback as useCallback4,
615
- useContext as useContext4
616
- } from "react";
713
+ import { forwardRef, useCallback as useCallback4, useContext as useContext4 } from "react";
617
714
 
618
715
  // src/components/legend/utils/value-or-identity.ts
619
716
  function valueOrIdentity(_) {
@@ -657,7 +754,7 @@ var base_legend_module_default = {
657
754
  };
658
755
 
659
756
  // src/components/legend/private/base-legend.tsx
660
- import { jsx as jsx2, jsxs } from "react/jsx-runtime";
757
+ import { jsx as _jsx2, jsxs as _jsxs } from "react/jsx-runtime";
661
758
  var orientationToFlexDirection = {
662
759
  horizontal: "row",
663
760
  vertical: "column"
@@ -669,241 +766,186 @@ var LegendText = ({
669
766
  }) => {
670
767
  const isEllipsis = maxWidth != null && textOverflow === "ellipsis";
671
768
  const [textRef, isTruncated] = useTextTruncation(Boolean(isEllipsis));
672
- return /* @__PURE__ */ jsx2(
673
- "span",
674
- {
675
- ref: textRef,
676
- className: clsx(
677
- base_legend_module_default["legend-item-text"],
678
- maxWidth != null && base_legend_module_default[`legend-item-text--${textOverflow}`]
679
- ),
680
- style: {
681
- ...maxWidth != null && {
682
- maxWidth,
683
- minWidth: 0
684
- }
685
- },
686
- title: isEllipsis && isTruncated ? text : void 0,
687
- children: text
688
- }
689
- );
769
+ return /* @__PURE__ */ _jsx2("span", {
770
+ ref: textRef,
771
+ className: clsx(base_legend_module_default["legend-item-text"], maxWidth != null && base_legend_module_default[`legend-item-text--${textOverflow}`]),
772
+ style: {
773
+ ...maxWidth != null && {
774
+ maxWidth,
775
+ minWidth: 0
776
+ }
777
+ },
778
+ title: isEllipsis && isTruncated ? text : void 0,
779
+ children: text
780
+ });
690
781
  };
691
- var BaseLegend = forwardRef(
692
- ({
693
- items,
694
- className,
695
- orientation = "horizontal",
696
- position = "bottom",
697
- alignment = "center",
698
- maxWidth,
699
- textOverflow = "wrap",
700
- shape = "rect",
701
- fill = valueOrIdentityString,
702
- size = valueOrIdentityString,
703
- labelFormat = valueOrIdentity,
704
- labelTransform = labelTransformFactory,
705
- shapeWidth = 16,
706
- shapeHeight = 16,
707
- shapeMargin = "2px 4px 2px 0",
708
- labelAlign = "left",
709
- labelFlex = "0 0 auto",
710
- // Use natural width instead of expanding to fill space
711
- labelMargin = "0 4px",
712
- itemMargin = "0",
713
- itemDirection = "row",
714
- legendLabelProps,
715
- legendItemClassName,
716
- render,
717
- interactive = false,
718
- chartId,
719
- ...legendItemProps
720
- }, ref) => {
721
- const theme = useGlobalChartsTheme();
722
- const context = useContext4(GlobalChartsContext);
723
- const legendScale = scaleOrdinal({
724
- domain: items.map((item) => item.label),
725
- range: items.map((item) => item.color)
726
- });
727
- const domain = legendScale.domain();
728
- const getShapeStyle = useCallback4(
729
- ({ index }) => items[index]?.shapeStyle,
730
- [items]
731
- );
732
- const handleLegendClick = useCallback4(
733
- (seriesLabel) => {
734
- if (interactive && chartId && context) {
735
- context.toggleSeriesVisibility(chartId, seriesLabel);
736
- }
737
- },
738
- [interactive, chartId, context]
739
- );
740
- const isSeriesVisible = useCallback4(
741
- (seriesLabel) => {
742
- if (!interactive || !chartId || !context) {
743
- return true;
744
- }
745
- return context.isSeriesVisible(chartId, seriesLabel);
746
- },
747
- [interactive, chartId, context]
748
- );
749
- const createClickHandler = useCallback4(
750
- (labelText) => {
751
- if (!interactive) {
752
- return void 0;
753
- }
754
- return () => handleLegendClick(labelText);
755
- },
756
- [interactive, handleLegendClick]
757
- );
758
- const createKeyDownHandler = useCallback4(
759
- (labelText) => {
760
- if (!interactive) {
761
- return void 0;
762
- }
763
- return (event) => {
764
- if (event.key === "Enter" || event.key === " ") {
765
- event.preventDefault();
766
- handleLegendClick(labelText);
767
- }
768
- };
782
+ var BaseLegend = /* @__PURE__ */ forwardRef(({
783
+ items,
784
+ className,
785
+ orientation = "horizontal",
786
+ position = "bottom",
787
+ alignment = "center",
788
+ maxWidth,
789
+ textOverflow = "wrap",
790
+ shape = "rect",
791
+ fill = valueOrIdentityString,
792
+ size = valueOrIdentityString,
793
+ labelFormat = valueOrIdentity,
794
+ labelTransform = labelTransformFactory,
795
+ shapeWidth = 16,
796
+ shapeHeight = 16,
797
+ shapeMargin = "2px 4px 2px 0",
798
+ labelAlign = "left",
799
+ labelFlex = "0 0 auto",
800
+ // Use natural width instead of expanding to fill space
801
+ labelMargin = "0 4px",
802
+ itemMargin = "0",
803
+ itemDirection = "row",
804
+ legendLabelProps,
805
+ legendItemClassName,
806
+ render,
807
+ interactive = false,
808
+ chartId,
809
+ ...legendItemProps
810
+ }, ref) => {
811
+ const theme = useGlobalChartsTheme();
812
+ const context = useContext4(GlobalChartsContext);
813
+ const legendScale = scaleOrdinal({
814
+ domain: items.map((item) => item.label),
815
+ range: items.map((item) => item.color)
816
+ });
817
+ const domain = legendScale.domain();
818
+ const getShapeStyle = useCallback4(({
819
+ index
820
+ }) => items[index]?.shapeStyle, [items]);
821
+ const handleLegendClick = useCallback4((seriesLabel) => {
822
+ if (interactive && chartId && context) {
823
+ context.toggleSeriesVisibility(chartId, seriesLabel);
824
+ }
825
+ }, [interactive, chartId, context]);
826
+ const isSeriesVisible = useCallback4((seriesLabel) => {
827
+ if (!interactive || !chartId || !context) {
828
+ return true;
829
+ }
830
+ return context.isSeriesVisible(chartId, seriesLabel);
831
+ }, [interactive, chartId, context]);
832
+ const createClickHandler = useCallback4((labelText) => {
833
+ if (!interactive) {
834
+ return void 0;
835
+ }
836
+ return () => handleLegendClick(labelText);
837
+ }, [interactive, handleLegendClick]);
838
+ const createKeyDownHandler = useCallback4((labelText) => {
839
+ if (!interactive) {
840
+ return void 0;
841
+ }
842
+ return (event) => {
843
+ if (event.key === "Enter" || event.key === " ") {
844
+ event.preventDefault();
845
+ handleLegendClick(labelText);
846
+ }
847
+ };
848
+ }, [interactive, handleLegendClick]);
849
+ return render ? render(items) : /* @__PURE__ */ _jsx2(LegendOrdinal, {
850
+ scale: legendScale,
851
+ labelFormat,
852
+ labelTransform,
853
+ children: (labels) => /* @__PURE__ */ _jsx2("div", {
854
+ ref,
855
+ role: "list",
856
+ className: clsx(base_legend_module_default.legend, base_legend_module_default[`legend--${orientation}`], base_legend_module_default[`legend--alignment-${alignment}`], base_legend_module_default[`legend--position-${position}`], className),
857
+ style: {
858
+ flexDirection: orientationToFlexDirection[orientation],
859
+ ...theme.legendContainerStyles
769
860
  },
770
- [interactive, handleLegendClick]
771
- );
772
- return render ? render(items) : /* @__PURE__ */ jsx2(
773
- LegendOrdinal,
774
- {
775
- scale: legendScale,
776
- labelFormat,
777
- labelTransform,
778
- children: (labels) => /* @__PURE__ */ jsx2(
779
- "div",
780
- {
781
- ref,
782
- role: "list",
783
- "data-testid": `legend-${orientation}`,
784
- className: clsx(
785
- base_legend_module_default.legend,
786
- base_legend_module_default[`legend--${orientation}`],
787
- base_legend_module_default[`legend--alignment-${alignment}`],
788
- base_legend_module_default[`legend--position-${position}`],
789
- className
790
- ),
861
+ children: labels.map((label, i) => {
862
+ const visible = isSeriesVisible(label.text);
863
+ const handleClick = createClickHandler(label.text);
864
+ const handleKeyDown = createKeyDownHandler(label.text);
865
+ return /* @__PURE__ */ _jsxs(LegendItem, {
866
+ className: clsx("visx-legend-item", base_legend_module_default["legend-item"], interactive && base_legend_module_default["legend-item--interactive"], !visible && base_legend_module_default["legend-item--inactive"], legendItemClassName),
867
+ margin: itemMargin,
868
+ flexDirection: orientation === "vertical" && alignment === "end" ? "row-reverse" : itemDirection,
869
+ onClick: handleClick,
870
+ onKeyDown: handleKeyDown,
871
+ role: interactive ? "button" : void 0,
872
+ tabIndex: interactive ? 0 : void 0,
873
+ "aria-pressed": interactive ? visible : void 0,
874
+ "aria-label": interactive ? `${label.text}: ${visible ? "visible" : "hidden"}. Toggle visibility.` : void 0,
875
+ ...legendItemProps,
876
+ children: [items[i]?.renderGlyph ? /* @__PURE__ */ _jsx2("svg", {
877
+ width: items[i]?.glyphSize * 2,
878
+ height: items[i]?.glyphSize * 2,
879
+ children: /* @__PURE__ */ _jsx2(Group, {
880
+ children: items[i]?.renderGlyph({
881
+ key: `legend-glyph-${label.text}`,
882
+ datum: {},
883
+ index: i,
884
+ color: fill(label),
885
+ size: items[i]?.glyphSize,
886
+ x: items[i]?.glyphSize,
887
+ y: items[i]?.glyphSize
888
+ })
889
+ })
890
+ }) : /* @__PURE__ */ _jsx2(LegendShape, {
891
+ shape,
892
+ height: shapeHeight,
893
+ width: shapeWidth,
894
+ margin: shapeMargin,
895
+ item: domain[i],
896
+ itemIndex: i,
897
+ label,
898
+ fill,
899
+ size,
900
+ shapeStyle: getShapeStyle
901
+ }), /* @__PURE__ */ _jsxs(LegendLabel, {
902
+ className: clsx("visx-legend-label", base_legend_module_default["legend-item-label"]),
791
903
  style: {
792
- flexDirection: orientationToFlexDirection[orientation],
793
- ...theme.legendContainerStyles
904
+ justifyContent: labelAlign,
905
+ flex: labelFlex,
906
+ margin: labelMargin,
907
+ ...theme.legendLabelStyles
794
908
  },
795
- children: labels.map((label, i) => {
796
- const visible = isSeriesVisible(label.text);
797
- const handleClick = createClickHandler(label.text);
798
- const handleKeyDown = createKeyDownHandler(label.text);
799
- return /* @__PURE__ */ jsxs(
800
- LegendItem,
801
- {
802
- className: clsx(
803
- "visx-legend-item",
804
- base_legend_module_default["legend-item"],
805
- interactive && base_legend_module_default["legend-item--interactive"],
806
- !visible && base_legend_module_default["legend-item--inactive"],
807
- legendItemClassName
808
- ),
809
- "data-testid": "legend-item",
810
- margin: itemMargin,
811
- flexDirection: orientation === "vertical" && alignment === "end" ? "row-reverse" : itemDirection,
812
- onClick: handleClick,
813
- onKeyDown: handleKeyDown,
814
- role: interactive ? "button" : void 0,
815
- tabIndex: interactive ? 0 : void 0,
816
- "aria-pressed": interactive ? visible : void 0,
817
- "aria-label": interactive ? `${label.text}: ${visible ? "visible" : "hidden"}. Toggle visibility.` : void 0,
818
- ...legendItemProps,
819
- children: [
820
- items[i]?.renderGlyph ? /* @__PURE__ */ jsx2(
821
- "svg",
822
- {
823
- width: items[i]?.glyphSize * 2,
824
- height: items[i]?.glyphSize * 2,
825
- "data-testid": "legend-glyph",
826
- children: /* @__PURE__ */ jsx2(Group, { children: items[i]?.renderGlyph({
827
- key: `legend-glyph-${label.text}`,
828
- datum: {},
829
- index: i,
830
- color: fill(label),
831
- size: items[i]?.glyphSize,
832
- x: items[i]?.glyphSize,
833
- y: items[i]?.glyphSize
834
- }) })
835
- }
836
- ) : /* @__PURE__ */ jsx2(
837
- LegendShape,
838
- {
839
- shape,
840
- height: shapeHeight,
841
- width: shapeWidth,
842
- margin: shapeMargin,
843
- item: domain[i],
844
- itemIndex: i,
845
- label,
846
- fill,
847
- size,
848
- shapeStyle: getShapeStyle
849
- }
850
- ),
851
- /* @__PURE__ */ jsxs(
852
- LegendLabel,
853
- {
854
- className: clsx("visx-legend-label", base_legend_module_default["legend-item-label"]),
855
- style: {
856
- justifyContent: labelAlign,
857
- flex: labelFlex,
858
- margin: labelMargin,
859
- ...theme.legendLabelStyles
860
- },
861
- ...legendLabelProps,
862
- children: [
863
- /* @__PURE__ */ jsx2(
864
- LegendText,
865
- {
866
- text: label.text,
867
- textOverflow,
868
- maxWidth
869
- }
870
- ),
871
- items.find((item) => item.label === label.text)?.value && /* @__PURE__ */ jsxs("span", { className: base_legend_module_default["legend-item-value"], children: [
872
- "\xA0",
873
- items.find((item) => item.label === label.text)?.value
874
- ] })
875
- ]
876
- }
877
- )
878
- ]
879
- },
880
- `legend-${label.text}-${i}`
881
- );
882
- })
883
- }
884
- )
885
- }
886
- );
887
- }
888
- );
909
+ ...legendLabelProps,
910
+ children: [/* @__PURE__ */ _jsx2(LegendText, {
911
+ text: label.text,
912
+ textOverflow,
913
+ maxWidth
914
+ }), items.find((item) => item.label === label.text)?.value && /* @__PURE__ */ _jsxs("span", {
915
+ className: base_legend_module_default["legend-item-value"],
916
+ children: ["\xA0", items.find((item) => item.label === label.text)?.value]
917
+ })]
918
+ })]
919
+ }, `legend-${label.text}-${i}`);
920
+ })
921
+ })
922
+ });
923
+ });
889
924
 
890
925
  // src/components/legend/legend.tsx
891
- import { jsx as jsx3 } from "react/jsx-runtime";
892
- var Legend = forwardRef2(
893
- ({ chartId, items, ...props }, ref) => {
894
- const context = useContext5(GlobalChartsContext);
895
- const singleChartContext = useContext5(SingleChartContext);
896
- const contextChartId = chartId ?? singleChartContext?.chartId;
897
- const contextItems = useMemo6(() => {
898
- return contextChartId && context ? context.getChartData(contextChartId)?.legendItems : void 0;
899
- }, [contextChartId, context]);
900
- const legendItems = items || contextItems;
901
- if (!legendItems) {
902
- return null;
903
- }
904
- return /* @__PURE__ */ jsx3(BaseLegend, { ref, items: legendItems, ...props, chartId: contextChartId });
926
+ import { jsx as _jsx3 } from "react/jsx-runtime";
927
+ var Legend = /* @__PURE__ */ forwardRef2(({
928
+ chartId,
929
+ items,
930
+ ...props
931
+ }, ref) => {
932
+ const context = useContext5(GlobalChartsContext);
933
+ const singleChartContext = useContext5(SingleChartContext);
934
+ const contextChartId = chartId ?? singleChartContext?.chartId;
935
+ const contextItems = useMemo6(() => {
936
+ return contextChartId && context ? context.getChartData(contextChartId)?.legendItems : void 0;
937
+ }, [contextChartId, context]);
938
+ const legendItems = items || contextItems;
939
+ if (!legendItems) {
940
+ return null;
905
941
  }
906
- );
942
+ return /* @__PURE__ */ _jsx3(BaseLegend, {
943
+ ref,
944
+ items: legendItems,
945
+ ...props,
946
+ chartId: contextChartId
947
+ });
948
+ });
907
949
 
908
950
  // src/components/legend/hooks/use-chart-legend-items.ts
909
951
  import { formatNumber } from "@automattic/number-formatters";
@@ -1144,12 +1186,12 @@ var useInteractiveLegendData = ({
1144
1186
  };
1145
1187
 
1146
1188
  // src/hooks/use-prefers-reduced-motion.ts
1147
- import { useState as useState4, useEffect as useEffect3 } from "react";
1189
+ import { useState as useState4, useEffect as useEffect4 } from "react";
1148
1190
  var QUERY = "(prefers-reduced-motion: no-preference)";
1149
1191
  var getInitialState = () => !window.matchMedia(QUERY).matches;
1150
1192
  function usePrefersReducedMotion() {
1151
1193
  const [prefersReducedMotion, setPrefersReducedMotion] = useState4(getInitialState);
1152
- useEffect3(() => {
1194
+ useEffect4(() => {
1153
1195
  const mediaQueryList = window.matchMedia(QUERY);
1154
1196
  const listener = (event) => {
1155
1197
  setPrefersReducedMotion(!event.matches);
@@ -1165,6 +1207,7 @@ function usePrefersReducedMotion() {
1165
1207
  export {
1166
1208
  SingleChartContext,
1167
1209
  useSingleChartContext,
1210
+ useTooltipPortalRelocator,
1168
1211
  defaultTheme,
1169
1212
  GlobalChartsContext,
1170
1213
  GlobalChartsProvider,
@@ -1186,4 +1229,4 @@ export {
1186
1229
  Legend,
1187
1230
  useChartLegendItems
1188
1231
  };
1189
- //# sourceMappingURL=chunk-H34CJSR6.js.map
1232
+ //# sourceMappingURL=chunk-32ESS4MV.js.map