@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,895 +0,0 @@
1
- import {
2
- getColorDistance,
3
- getItemShapeStyles,
4
- getLongestTickWidth,
5
- getSeriesLineStyles,
6
- mergeThemes,
7
- normalizeColorToHex,
8
- parseAsLocalDate,
9
- resolveCssVariable
10
- } from "./chunk-JJIMABHT.js";
11
- import {
12
- __commonJS,
13
- __toESM
14
- } from "./chunk-G3PMV62Z.js";
15
-
16
- // ../../../node_modules/.pnpm/fast-deep-equal@3.1.3/node_modules/fast-deep-equal/index.js
17
- var require_fast_deep_equal = __commonJS({
18
- "../../../node_modules/.pnpm/fast-deep-equal@3.1.3/node_modules/fast-deep-equal/index.js"(exports, module) {
19
- "use strict";
20
- module.exports = function equal(a, b) {
21
- if (a === b) return true;
22
- if (a && b && typeof a == "object" && typeof b == "object") {
23
- if (a.constructor !== b.constructor) return false;
24
- var length, i, keys;
25
- if (Array.isArray(a)) {
26
- length = a.length;
27
- if (length != b.length) return false;
28
- for (i = length; i-- !== 0; )
29
- if (!equal(a[i], b[i])) return false;
30
- return true;
31
- }
32
- if (a.constructor === RegExp) return a.source === b.source && a.flags === b.flags;
33
- if (a.valueOf !== Object.prototype.valueOf) return a.valueOf() === b.valueOf();
34
- if (a.toString !== Object.prototype.toString) return a.toString() === b.toString();
35
- keys = Object.keys(a);
36
- length = keys.length;
37
- if (length !== Object.keys(b).length) return false;
38
- for (i = length; i-- !== 0; )
39
- if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false;
40
- for (i = length; i-- !== 0; ) {
41
- var key = keys[i];
42
- if (!equal(a[key], b[key])) return false;
43
- }
44
- return true;
45
- }
46
- return a !== a && b !== b;
47
- };
48
- }
49
- });
50
-
51
- // src/hooks/use-deep-memo.ts
52
- var import_fast_deep_equal = __toESM(require_fast_deep_equal(), 1);
53
- import { useRef } from "react";
54
- var useDeepMemo = (value) => {
55
- const ref = useRef(value);
56
- if (!(0, import_fast_deep_equal.default)(ref.current, value)) {
57
- ref.current = value;
58
- }
59
- return ref.current;
60
- };
61
-
62
- // src/hooks/use-chart-mouse-handler.ts
63
- import { localPoint } from "@visx/event";
64
- import { useTooltip } from "@visx/tooltip";
65
- import { useCallback } from "react";
66
- var useChartMouseHandler = ({
67
- withTooltips,
68
- offsetX = 0,
69
- offsetY = -10
70
- }) => {
71
- const { tooltipOpen, tooltipLeft, tooltipTop, tooltipData, hideTooltip, showTooltip } = useTooltip();
72
- const onMouseMove = useCallback(
73
- (event, data) => {
74
- if (!withTooltips) {
75
- return;
76
- }
77
- const coords = localPoint(event);
78
- if (!coords) {
79
- return;
80
- }
81
- showTooltip({
82
- tooltipData: data,
83
- tooltipLeft: coords.x + offsetX,
84
- tooltipTop: coords.y + offsetY
85
- });
86
- },
87
- [withTooltips, showTooltip, offsetX, offsetY]
88
- );
89
- const onMouseLeave = useCallback(() => {
90
- if (!withTooltips) {
91
- return;
92
- }
93
- hideTooltip();
94
- }, [withTooltips, hideTooltip]);
95
- return {
96
- onMouseMove,
97
- onMouseLeave,
98
- tooltipOpen,
99
- tooltipData: tooltipData || null,
100
- tooltipLeft,
101
- tooltipTop
102
- };
103
- };
104
-
105
- // src/hooks/use-xychart-theme.ts
106
- import { buildChartTheme } from "@visx/xychart";
107
- import { useMemo as useMemo3 } from "react";
108
-
109
- // src/providers/chart-context/global-charts-provider.tsx
110
- import { hsl as d3Hsl2 } from "@visx/vendor/d3-color";
111
- import { createContext, useCallback as useCallback2, useMemo, useState, useEffect as useEffect2, useLayoutEffect, useRef as useRef2 } from "react";
112
-
113
- // src/hooks/use-tooltip-portal-relocator.ts
114
- import { useEffect } from "react";
115
-
116
- // src/hooks/use-tooltip-portal-relocator.module.scss
117
- var use_tooltip_portal_relocator_module_default = {
118
- "relocatedPortal": "a8ccharts-jCw5dQ"
119
- };
120
-
121
- // src/hooks/use-tooltip-portal-relocator.ts
122
- function isVisxPortalNode(node) {
123
- return node instanceof HTMLDivElement && node.parentElement === document.body && !node.id && !node.className && node.querySelector(".visx-tooltip") !== null;
124
- }
125
- var patchRefCount = 0;
126
- var origRemoveChild = null;
127
- var patchedRemoveChild = null;
128
- var relocatedNodes = /* @__PURE__ */ new WeakSet();
129
- function installRemoveChildPatch() {
130
- if (patchRefCount++ > 0) {
131
- return;
132
- }
133
- origRemoveChild = document.body.removeChild;
134
- patchedRemoveChild = function(child) {
135
- if (relocatedNodes.has(child) && child.parentNode !== this) {
136
- relocatedNodes.delete(child);
137
- child.parentNode?.removeChild(child);
138
- return child;
139
- }
140
- return origRemoveChild.call(this, child);
141
- };
142
- document.body.removeChild = patchedRemoveChild;
143
- }
144
- function uninstallRemoveChildPatch() {
145
- if (--patchRefCount > 0) {
146
- return;
147
- }
148
- if (document.body.removeChild === patchedRemoveChild) {
149
- document.body.removeChild = origRemoveChild;
150
- }
151
- origRemoveChild = null;
152
- patchedRemoveChild = null;
153
- }
154
- function useTooltipPortalRelocator(containerRef) {
155
- useEffect(() => {
156
- const container = containerRef?.current;
157
- if (!container) {
158
- return;
159
- }
160
- const instanceNodes = /* @__PURE__ */ new Set();
161
- const relocateNode = (node) => {
162
- if (!isVisxPortalNode(node)) {
163
- return;
164
- }
165
- node.style.opacity = "0";
166
- node.classList.add(use_tooltip_portal_relocator_module_default.relocatedPortal);
167
- const { activeElement } = node.ownerDocument;
168
- const focusedElement = activeElement instanceof HTMLElement && node.contains(activeElement) ? activeElement : null;
169
- container.insertBefore(node, container.firstChild);
170
- relocatedNodes.add(node);
171
- instanceNodes.add(node);
172
- if (focusedElement) {
173
- focusedElement.focus();
174
- }
175
- requestAnimationFrame(() => {
176
- requestAnimationFrame(() => {
177
- node.style.opacity = "";
178
- });
179
- });
180
- };
181
- installRemoveChildPatch();
182
- for (const child of Array.from(document.body.children)) {
183
- relocateNode(child);
184
- }
185
- const observer = new MutationObserver((mutations) => {
186
- for (const mutation of mutations) {
187
- for (const node of mutation.addedNodes) {
188
- relocateNode(node);
189
- }
190
- }
191
- });
192
- observer.observe(document.body, { childList: true });
193
- return () => {
194
- observer.disconnect();
195
- for (const node of instanceNodes) {
196
- if (node instanceof HTMLElement) {
197
- node.classList.remove(use_tooltip_portal_relocator_module_default.relocatedPortal);
198
- }
199
- if (node.parentNode === container) {
200
- document.body.appendChild(node);
201
- }
202
- relocatedNodes.delete(node);
203
- }
204
- instanceNodes.clear();
205
- uninstallRemoveChildPatch();
206
- };
207
- }, [containerRef]);
208
- }
209
-
210
- // src/providers/chart-context/private/get-chart-color.ts
211
- import { hsl as d3Hsl } from "@visx/vendor/d3-color";
212
- var GOLDEN_RATIO = 0.618033988749;
213
- var MIN_COLOR_DISTANCE = 25;
214
- var MAX_COLOR_GENERATION_ATTEMPTS = 50;
215
- var VARIATION_ATTEMPT_OFFSET = 0.1;
216
- var BASE_SATURATION = 45;
217
- var SATURATION_VARIATION_STEPS = 3;
218
- var SATURATION_INCREMENT = 10;
219
- var BASE_LIGHTNESS = 35;
220
- var LIGHTNESS_VARIATION_STEPS = 4;
221
- var LIGHTNESS_INCREMENT = 8;
222
- var MIN_HUE_RANGE_DEGREES = 60;
223
- var HUE_RANGE_EXPANSION_FACTOR = 1.3;
224
- var HUE_WRAP_THRESHOLD_DEGREES = 180;
225
- var FULL_HUE_ROTATION_DEGREES = 360;
226
- var SINGLE_COLOR_HUE_RANGE_FACTOR = 0.33;
227
- var getChartColor = (index, colorCache) => {
228
- const {
229
- colors,
230
- hues,
231
- existingHslColors,
232
- minHue: cachedMinHue,
233
- maxHue: cachedMaxHue
234
- } = colorCache;
235
- if (index < colors.length) {
236
- return colors[index];
237
- }
238
- let minHue = cachedMinHue;
239
- let maxHue = cachedMaxHue;
240
- for (let attempt = 0; attempt < MAX_COLOR_GENERATION_ATTEMPTS; attempt++) {
241
- let hue = (index - colors.length + attempt * VARIATION_ATTEMPT_OFFSET) * GOLDEN_RATIO * FULL_HUE_ROTATION_DEGREES % FULL_HUE_ROTATION_DEGREES;
242
- if (hues.length > 0) {
243
- let hueRange = maxHue - minHue;
244
- if (hues.length === 1) {
245
- hueRange = FULL_HUE_ROTATION_DEGREES * SINGLE_COLOR_HUE_RANGE_FACTOR;
246
- } else if (hueRange > HUE_WRAP_THRESHOLD_DEGREES) {
247
- const altMinHue = Math.min(...hues.filter((h) => h > HUE_WRAP_THRESHOLD_DEGREES));
248
- const altMaxHue = Math.max(...hues.filter((h) => h < HUE_WRAP_THRESHOLD_DEGREES)) + FULL_HUE_ROTATION_DEGREES;
249
- const altRange = altMaxHue - altMinHue;
250
- if (altRange < hueRange) {
251
- minHue = altMinHue;
252
- maxHue = altMaxHue;
253
- hueRange = altRange;
254
- }
255
- }
256
- const expandedRange = Math.max(
257
- hueRange * HUE_RANGE_EXPANSION_FACTOR,
258
- MIN_HUE_RANGE_DEGREES
259
- );
260
- const rangeCenter = (minHue + maxHue) / 2;
261
- const expandedMin = rangeCenter - expandedRange / 2;
262
- hue = expandedMin + hue / FULL_HUE_ROTATION_DEGREES * expandedRange;
263
- hue = (hue % FULL_HUE_ROTATION_DEGREES + FULL_HUE_ROTATION_DEGREES) % FULL_HUE_ROTATION_DEGREES;
264
- }
265
- const saturation = BASE_SATURATION + (index + attempt) % SATURATION_VARIATION_STEPS * SATURATION_INCREMENT;
266
- const lightness = BASE_LIGHTNESS + (index + attempt) % LIGHTNESS_VARIATION_STEPS * LIGHTNESS_INCREMENT;
267
- const candidateHsl = [hue, saturation, lightness];
268
- let isSufficientlyDifferent = true;
269
- for (const existingHsl of existingHslColors) {
270
- if (getColorDistance(candidateHsl, existingHsl) < MIN_COLOR_DISTANCE) {
271
- isSufficientlyDifferent = false;
272
- break;
273
- }
274
- }
275
- if (isSufficientlyDifferent) {
276
- return d3Hsl(Math.round(hue), saturation / 100, lightness / 100).formatHex();
277
- }
278
- }
279
- const fallbackHue = (index - colors.length) * GOLDEN_RATIO * FULL_HUE_ROTATION_DEGREES % FULL_HUE_ROTATION_DEGREES;
280
- const fallbackSaturation = BASE_SATURATION + index % SATURATION_VARIATION_STEPS * SATURATION_INCREMENT;
281
- const fallbackLightness = BASE_LIGHTNESS + index % LIGHTNESS_VARIATION_STEPS * LIGHTNESS_INCREMENT;
282
- return d3Hsl(
283
- Math.round(fallbackHue),
284
- fallbackSaturation / 100,
285
- fallbackLightness / 100
286
- ).formatHex();
287
- };
288
-
289
- // src/providers/chart-context/themes.ts
290
- var defaultTheme = {
291
- backgroundColor: "#FFFFFF",
292
- // chart background color
293
- labelBackgroundColor: "transparent",
294
- // label background color (transparent by default)
295
- labelTextColor: "#FFFFFF",
296
- // label text color (white to match original behavior)
297
- colors: ["#98C8DF", "#006DAB", "#A6DC80", "#1F9828", "#FF8C8F"],
298
- gridStyles: {
299
- stroke: "#DCDCDE",
300
- strokeWidth: 1
301
- },
302
- tickLength: 4,
303
- gridColor: "",
304
- gridColorDark: "",
305
- xTickLineStyles: { stroke: "black" },
306
- xAxisLineStyles: { stroke: "#DCDCDE", strokeWidth: 1 },
307
- legend: {
308
- labelStyles: {
309
- color: "var(--jp-gray-80, #2c3338)"
310
- },
311
- containerStyles: {},
312
- shapeStyles: []
313
- },
314
- seriesLineStyles: [],
315
- glyphs: [],
316
- svgLabelSmall: { fill: "var(--jp-gray-80, #2c3338)" },
317
- annotationStyles: {
318
- label: {
319
- anchorLineStroke: "var(--jp-gray-80, #2c3338)",
320
- backgroundFill: "#fff"
321
- },
322
- connector: {
323
- stroke: "var(--jp-gray-80, #2c3338)"
324
- },
325
- circleSubject: {
326
- stroke: "transparent",
327
- fill: "var(--jp-gray-80, #2c3338)",
328
- radius: 5
329
- }
330
- },
331
- geoChart: {
332
- featureFillColor: "var(--jp-gray-0, #f6f7f7)"
333
- },
334
- leaderboardChart: {
335
- rowGap: 12,
336
- columnGap: 4,
337
- labelSpacing: 1.5,
338
- deltaColors: ["#FF8C8F", "#757575", "#1F9828"]
339
- // [negative, neutral, positive]
340
- },
341
- conversionFunnelChart: {
342
- backgroundColor: "#F3F4F6",
343
- positiveChangeColor: "#1F9828",
344
- negativeChangeColor: "#FF8C8F"
345
- },
346
- lineChart: {
347
- lineStyles: {
348
- comparison: {
349
- strokeDasharray: "4 4",
350
- strokeLinecap: "square"
351
- }
352
- }
353
- },
354
- sparkline: {
355
- margin: { top: 2, right: 2, bottom: 2, left: 2 },
356
- strokeWidth: 1.5
357
- }
358
- };
359
-
360
- // src/providers/chart-context/global-charts-provider.tsx
361
- import { jsx as _jsx } from "react/jsx-runtime";
362
- var GlobalChartsContext = /* @__PURE__ */ createContext(null);
363
- var GlobalChartsProvider = ({
364
- children,
365
- theme,
366
- portalContainer
367
- }) => {
368
- const [charts, setCharts] = useState(() => /* @__PURE__ */ new Map());
369
- const [hiddenSeries, setHiddenSeries] = useState(() => /* @__PURE__ */ new Map());
370
- const wrapperRef = useRef2(null);
371
- useTooltipPortalRelocator(portalContainer ?? wrapperRef);
372
- const providerTheme = useMemo(() => {
373
- return theme ? mergeThemes(defaultTheme, theme) : defaultTheme;
374
- }, [theme]);
375
- const [colorCache, setColorCache] = useState(() => ({
376
- colors: [],
377
- hues: [],
378
- existingHslColors: [],
379
- minHue: 360,
380
- maxHue: 0
381
- }));
382
- useLayoutEffect(() => {
383
- const {
384
- colors
385
- } = providerTheme;
386
- const resolvedColors = [];
387
- const hues = [];
388
- const existingHslColors = [];
389
- let minHue = 360;
390
- let maxHue = 0;
391
- if (Array.isArray(colors)) {
392
- for (const color of colors) {
393
- if (color && typeof color === "string") {
394
- let colorValue = color;
395
- if (color.startsWith("--") || color.startsWith("var(")) {
396
- const resolved = resolveCssVariable(color, wrapperRef.current);
397
- if (resolved === null || resolved === "") {
398
- continue;
399
- }
400
- colorValue = resolved;
401
- }
402
- if (colorValue.startsWith("#")) {
403
- resolvedColors.push(colorValue);
404
- const hslColor = d3Hsl2(colorValue);
405
- if (!isNaN(hslColor.h)) {
406
- const hslTuple = [hslColor.h, hslColor.s * 100, hslColor.l * 100];
407
- hues.push(hslTuple[0]);
408
- existingHslColors.push(hslTuple);
409
- minHue = Math.min(minHue, hslTuple[0]);
410
- maxHue = Math.max(maxHue, hslTuple[0]);
411
- }
412
- }
413
- }
414
- }
415
- }
416
- setColorCache({
417
- colors: resolvedColors,
418
- hues,
419
- existingHslColors,
420
- minHue,
421
- maxHue
422
- });
423
- }, [providerTheme]);
424
- const [groupToColorMap, setGroupToColorMap] = useState(() => /* @__PURE__ */ new Map());
425
- useEffect2(() => {
426
- setGroupToColorMap(/* @__PURE__ */ new Map());
427
- }, [providerTheme.colors]);
428
- const registerChart = useCallback2((id, data) => {
429
- setCharts((prev) => new Map(prev).set(id, data));
430
- }, []);
431
- const unregisterChart = useCallback2((id) => {
432
- setCharts((prev) => {
433
- const newMap = new Map(prev);
434
- newMap.delete(id);
435
- return newMap;
436
- });
437
- }, []);
438
- const getChartData = useCallback2((id) => {
439
- return charts.get(id);
440
- }, [charts]);
441
- const resolveColor = useCallback2(({
442
- group,
443
- index,
444
- overrideColor
445
- }) => {
446
- if (overrideColor) {
447
- return normalizeColorToHex(overrideColor, wrapperRef.current, resolveCssVariable);
448
- }
449
- if (group) {
450
- const existing = groupToColorMap.get(group);
451
- if (existing) {
452
- return existing;
453
- }
454
- const assignedCount = groupToColorMap.size;
455
- const color = getChartColor(assignedCount, colorCache);
456
- groupToColorMap.set(group, color);
457
- return color;
458
- }
459
- return getChartColor(index, colorCache);
460
- }, [colorCache, groupToColorMap]);
461
- const getElementStyles = useCallback2(({
462
- data,
463
- index,
464
- overrideColor,
465
- legendShape
466
- }) => {
467
- const isSeriesData = data && typeof data === "object" && "data" in data && "options" in data;
468
- const isPointPercentageData = data && typeof data === "object" && "percentage" in data;
469
- return {
470
- color: resolveColor({
471
- group: data?.group,
472
- index,
473
- overrideColor: overrideColor || isSeriesData && data?.options?.stroke || isPointPercentageData && data?.color
474
- }),
475
- lineStyles: isSeriesData ? getSeriesLineStyles(data, index, providerTheme) : {},
476
- glyph: providerTheme.glyphs?.[index],
477
- shapeStyles: isSeriesData ? getItemShapeStyles(data, index, providerTheme, legendShape) : {}
478
- };
479
- }, [providerTheme, resolveColor]);
480
- const toggleSeriesVisibility = useCallback2((chartId, seriesLabel) => {
481
- setHiddenSeries((prev) => {
482
- const newMap = new Map(prev);
483
- const chartHidden = newMap.get(chartId) || /* @__PURE__ */ new Set();
484
- const newSet = new Set(chartHidden);
485
- if (newSet.has(seriesLabel)) {
486
- newSet.delete(seriesLabel);
487
- } else {
488
- newSet.add(seriesLabel);
489
- }
490
- if (newSet.size === 0) {
491
- newMap.delete(chartId);
492
- } else {
493
- newMap.set(chartId, newSet);
494
- }
495
- return newMap;
496
- });
497
- }, []);
498
- const isSeriesVisible = useCallback2((chartId, seriesLabel) => {
499
- const chartHidden = hiddenSeries.get(chartId);
500
- return !chartHidden || !chartHidden.has(seriesLabel);
501
- }, [hiddenSeries]);
502
- const getHiddenSeries = useCallback2((chartId) => {
503
- const set = hiddenSeries.get(chartId);
504
- return set ? new Set(set) : /* @__PURE__ */ new Set();
505
- }, [hiddenSeries]);
506
- const value = useMemo(() => ({
507
- charts,
508
- registerChart,
509
- unregisterChart,
510
- getChartData,
511
- theme: providerTheme,
512
- getElementStyles,
513
- toggleSeriesVisibility,
514
- isSeriesVisible,
515
- getHiddenSeries
516
- }), [charts, registerChart, unregisterChart, getChartData, providerTheme, getElementStyles, toggleSeriesVisibility, isSeriesVisible, getHiddenSeries]);
517
- return /* @__PURE__ */ _jsx(GlobalChartsContext.Provider, {
518
- value,
519
- children: /* @__PURE__ */ _jsx("div", {
520
- ref: wrapperRef,
521
- style: {
522
- display: "contents"
523
- },
524
- children
525
- })
526
- });
527
- };
528
-
529
- // src/providers/chart-context/hooks/use-global-charts-context.ts
530
- import { useContext } from "react";
531
- var useGlobalChartsContext = () => {
532
- const context = useContext(GlobalChartsContext);
533
- if (!context) {
534
- throw new Error("useGlobalChartsContext must be used within a GlobalChartsProvider");
535
- }
536
- return context;
537
- };
538
-
539
- // src/providers/chart-context/hooks/use-chart-id.ts
540
- import { useId } from "react";
541
- var useChartId = (providedId) => {
542
- const generatedId = useId();
543
- return providedId || generatedId;
544
- };
545
-
546
- // src/providers/chart-context/hooks/use-chart-registration.ts
547
- import { useEffect as useEffect3, useMemo as useMemo2 } from "react";
548
- var useChartRegistration = ({
549
- chartId,
550
- legendItems,
551
- chartType,
552
- isDataValid,
553
- metadata
554
- }) => {
555
- const { registerChart, unregisterChart } = useGlobalChartsContext();
556
- const stableLegendItems = useDeepMemo(legendItems);
557
- const memoizedMetadata = useMemo2(() => metadata, [metadata]);
558
- useEffect3(() => {
559
- if (isDataValid) {
560
- registerChart(chartId, {
561
- legendItems: stableLegendItems,
562
- chartType,
563
- metadata: memoizedMetadata
564
- });
565
- }
566
- return () => {
567
- unregisterChart(chartId);
568
- };
569
- }, [
570
- chartId,
571
- stableLegendItems,
572
- chartType,
573
- memoizedMetadata,
574
- isDataValid
575
- // Removed registerChart and unregisterChart from dependencies
576
- // They are stable functions created with useCallback and empty deps
577
- ]);
578
- };
579
-
580
- // src/providers/chart-context/hooks/use-global-charts-theme.ts
581
- import { useContext as useContext2 } from "react";
582
- var useGlobalChartsTheme = () => {
583
- const context = useContext2(GlobalChartsContext);
584
- const globalTheme = context?.theme;
585
- return globalTheme ?? defaultTheme;
586
- };
587
-
588
- // src/hooks/use-xychart-theme.ts
589
- var useXYChartTheme = (data) => {
590
- const theme = useGlobalChartsTheme();
591
- return useMemo3(() => {
592
- const seriesColors = (data ?? []).map((series) => series.options?.stroke).filter((color) => Boolean(color));
593
- return buildChartTheme({
594
- ...theme,
595
- colors: [...seriesColors, ...theme.colors ?? []]
596
- });
597
- }, [theme, data]);
598
- };
599
-
600
- // src/hooks/use-chart-data-transform.ts
601
- import { useMemo as useMemo4 } from "react";
602
- var useChartDataTransform = (data) => {
603
- return useMemo4(() => {
604
- const firstPoint = data?.[0]?.data?.[0];
605
- const hasDateProperties = firstPoint && ("date" in firstPoint || "dateString" in firstPoint);
606
- if (!hasDateProperties) {
607
- return data;
608
- }
609
- return data.map((series) => ({
610
- ...series,
611
- data: series.data.map((point) => {
612
- let date;
613
- if ("date" in point && point.date) {
614
- date = point.date;
615
- } else if ("dateString" in point && point.dateString) {
616
- date = parseAsLocalDate(point.dateString);
617
- }
618
- return {
619
- ...point,
620
- date
621
- };
622
- }).sort((a, b) => {
623
- if (!a.date || !b.date) return 0;
624
- return a.date.getTime() - b.date.getTime();
625
- })
626
- }));
627
- }, [data]);
628
- };
629
-
630
- // src/hooks/use-chart-margin.tsx
631
- import { createScale, getTicks } from "@visx/scale";
632
- import { useMemo as useMemo5 } from "react";
633
- var DEFAULT_MARGIN_TOP = 10;
634
- var DEFAULT_MARGIN_RIGHT = 20;
635
- var DEFAULT_MARGIN_BOTTOM = 20;
636
- var DEFAULT_MARGIN_LEFT = 20;
637
- var DEFAULT_BOTTOM_FOR_TOP_AXIS = 10;
638
- var DEFAULT_FONT_SIZE = 12;
639
- var DEFAULT_TICK_LENGTH = 8;
640
- var DEFAULT_Y_TICK_WIDTH = 40;
641
- var resolveFontSize = (val) => {
642
- if (typeof val === "number" && !isNaN(val)) {
643
- return val;
644
- }
645
- if (typeof val === "string") {
646
- const parsed = parseFloat(val);
647
- return isNaN(parsed) ? void 0 : parsed;
648
- }
649
- return void 0;
650
- };
651
- var getXAxisLabelMetrics = (theme, orientation) => {
652
- const xAxisStyles = orientation === "top" ? theme.axisStyles?.x?.top : theme.axisStyles?.x?.bottom;
653
- const fontSize = resolveFontSize(xAxisStyles?.axisLabel?.fontSize) || resolveFontSize(theme.svgLabelSmall?.fontSize) || DEFAULT_FONT_SIZE;
654
- const tickLength = xAxisStyles?.tickLength ?? DEFAULT_TICK_LENGTH;
655
- return {
656
- fontSize,
657
- tickLength
658
- };
659
- };
660
- var useChartMargin = (height, options, data, theme, horizontal = false) => {
661
- const yTicks = useMemo5(() => {
662
- const allDataPoints = data.flatMap((series) => series.data);
663
- if (horizontal) {
664
- return allDataPoints.map((d) => d.label || options.axis?.y?.tickFormat(d.date.getTime(), 0, []));
665
- }
666
- const minY = Math.min(...allDataPoints.map((d) => d.value));
667
- const maxY = Math.max(...allDataPoints.map((d) => d.value));
668
- const yScale = createScale({
669
- ...options.yScale,
670
- domain: [minY, maxY],
671
- range: [height, 0]
672
- });
673
- return getTicks(yScale, options.axis?.y?.numTicks);
674
- }, [options, data, height, horizontal]);
675
- return useMemo5(() => {
676
- const defaultMargin = {
677
- top: DEFAULT_MARGIN_TOP,
678
- right: DEFAULT_MARGIN_RIGHT,
679
- bottom: DEFAULT_MARGIN_BOTTOM,
680
- left: DEFAULT_MARGIN_LEFT
681
- };
682
- const yAxisOrientation = options.axis?.y?.orientation;
683
- const yAxisStyles = yAxisOrientation === "right" ? theme.axisStyles.y.right : theme.axisStyles.y.left;
684
- const yTickWidth = getLongestTickWidth(yTicks, options.axis?.y?.tickFormat, yAxisStyles.axisLabel);
685
- const yMarginValue = (yTickWidth ?? DEFAULT_Y_TICK_WIDTH) + (yAxisStyles?.tickLength ?? 0);
686
- if (yAxisOrientation === "right") {
687
- defaultMargin.right = yMarginValue;
688
- } else {
689
- defaultMargin.left = yMarginValue;
690
- }
691
- const xOrientation = options.axis?.x?.orientation === "top" ? "top" : "bottom";
692
- const {
693
- fontSize,
694
- tickLength
695
- } = getXAxisLabelMetrics(theme, xOrientation);
696
- const computedXMargin = fontSize + tickLength;
697
- if (xOrientation === "top") {
698
- defaultMargin.top = Math.max(defaultMargin.top, computedXMargin);
699
- defaultMargin.bottom = DEFAULT_BOTTOM_FOR_TOP_AXIS;
700
- } else {
701
- defaultMargin.bottom = Math.max(defaultMargin.bottom, computedXMargin);
702
- }
703
- return defaultMargin;
704
- }, [options, theme, yTicks]);
705
- };
706
-
707
- // src/hooks/use-element-size.ts
708
- import { useState as useState2, useCallback as useCallback3, useRef as useRef3 } from "react";
709
- function useElementSize({
710
- initialWidth = 0,
711
- initialHeight = 0
712
- } = {}) {
713
- const [width, setWidth] = useState2(initialWidth);
714
- const [height, setHeight] = useState2(initialHeight);
715
- const observerRef = useRef3(null);
716
- const refCallback = useCallback3((node) => {
717
- if (observerRef.current) {
718
- observerRef.current.disconnect();
719
- observerRef.current = null;
720
- }
721
- if (node) {
722
- const handleResize = () => {
723
- const rect = node.getBoundingClientRect();
724
- setWidth(rect.width || 0);
725
- setHeight(rect.height || 0);
726
- };
727
- handleResize();
728
- const resizeObserver = new ResizeObserver(handleResize);
729
- resizeObserver.observe(node);
730
- observerRef.current = resizeObserver;
731
- }
732
- }, []);
733
- return [refCallback, width, height];
734
- }
735
-
736
- // src/hooks/use-text-truncation.ts
737
- import { useCallback as useCallback4, useRef as useRef4, useState as useState3 } from "react";
738
- function useTextTruncation(enabled = true) {
739
- const [isTruncated, setIsTruncated] = useState3(false);
740
- const observerRef = useRef4(null);
741
- const refCallback = useCallback4(
742
- (node) => {
743
- if (observerRef.current) {
744
- observerRef.current.disconnect();
745
- observerRef.current = null;
746
- }
747
- if (node && enabled) {
748
- const checkTruncation = () => {
749
- const truncated = node.scrollWidth > node.clientWidth;
750
- setIsTruncated(truncated);
751
- };
752
- checkTruncation();
753
- const resizeObserver = new ResizeObserver(checkTruncation);
754
- resizeObserver.observe(node);
755
- observerRef.current = resizeObserver;
756
- } else {
757
- setIsTruncated(false);
758
- }
759
- },
760
- [enabled]
761
- );
762
- return [refCallback, isTruncated];
763
- }
764
-
765
- // src/hooks/use-zero-value-display.ts
766
- import { useMemo as useMemo6 } from "react";
767
- var MIN_PIXEL_SIZE = 3;
768
- var ZERO_PIXEL_SIZE = MIN_PIXEL_SIZE - 1;
769
- var useZeroValueDisplay = (data, options = { enabled: false }) => {
770
- const { enabled, valueAxisLength } = options;
771
- return useMemo6(() => {
772
- if (!enabled || !valueAxisLength || valueAxisLength <= 0) return data;
773
- let maxAbsoluteValue = 0;
774
- for (const series of data) {
775
- for (const point of series.data) {
776
- if (point.value !== null && point.value !== 0) {
777
- maxAbsoluteValue = Math.max(maxAbsoluteValue, Math.abs(point.value));
778
- }
779
- }
780
- }
781
- if (maxAbsoluteValue === 0) return data;
782
- const minNonZeroValue = Math.min(
783
- MIN_PIXEL_SIZE / valueAxisLength * maxAbsoluteValue,
784
- maxAbsoluteValue
785
- );
786
- const zeroVisualValue = Math.min(
787
- ZERO_PIXEL_SIZE / valueAxisLength * maxAbsoluteValue,
788
- maxAbsoluteValue
789
- );
790
- return data.map((series) => ({
791
- ...series,
792
- data: series.data.map((point) => {
793
- if (point.value === 0) {
794
- return {
795
- ...point,
796
- visualValue: zeroVisualValue
797
- };
798
- }
799
- if (point.value === null) {
800
- return point;
801
- }
802
- const absValue = Math.abs(point.value);
803
- if (absValue < minNonZeroValue) {
804
- return {
805
- ...point,
806
- visualValue: Math.sign(point.value) * minNonZeroValue
807
- };
808
- }
809
- return point;
810
- })
811
- }));
812
- }, [data, enabled, valueAxisLength]);
813
- };
814
-
815
- // src/hooks/use-interactive-legend-data.ts
816
- import { useMemo as useMemo7 } from "react";
817
- var useInteractiveLegendData = ({
818
- data,
819
- chartId,
820
- legendInteractive,
821
- isSeriesVisible
822
- }) => {
823
- const visibleData = useMemo7(() => {
824
- if (!chartId || !legendInteractive) {
825
- return data;
826
- }
827
- const filtered = data.filter((segment) => isSeriesVisible(chartId, segment.label));
828
- if (filtered.length === 0) {
829
- return [];
830
- }
831
- const totalValue = filtered.reduce((sum, segment) => sum + segment.value, 0);
832
- return filtered.map((segment) => ({
833
- ...segment,
834
- percentage: totalValue > 0 ? segment.value / totalValue * 100 : 0
835
- }));
836
- }, [data, chartId, isSeriesVisible, legendInteractive]);
837
- const allSegmentsHidden = useMemo7(() => {
838
- return legendInteractive && visibleData.length === 0;
839
- }, [legendInteractive, visibleData]);
840
- const legendData = useMemo7(() => {
841
- if (!legendInteractive || !chartId) {
842
- return data;
843
- }
844
- return data.map((segment) => {
845
- const isVisible = isSeriesVisible(chartId, segment.label);
846
- if (!isVisible) {
847
- return segment;
848
- }
849
- const recalculated = visibleData.find((d) => d.label === segment.label);
850
- return recalculated || segment;
851
- });
852
- }, [data, visibleData, legendInteractive, chartId, isSeriesVisible]);
853
- return { visibleData, allSegmentsHidden, legendData };
854
- };
855
-
856
- // src/hooks/use-prefers-reduced-motion.ts
857
- import { useState as useState4, useEffect as useEffect4 } from "react";
858
- var QUERY = "(prefers-reduced-motion: no-preference)";
859
- var getInitialState = () => !window.matchMedia(QUERY).matches;
860
- function usePrefersReducedMotion() {
861
- const [prefersReducedMotion, setPrefersReducedMotion] = useState4(getInitialState);
862
- useEffect4(() => {
863
- const mediaQueryList = window.matchMedia(QUERY);
864
- const listener = (event) => {
865
- setPrefersReducedMotion(!event.matches);
866
- };
867
- mediaQueryList.addEventListener("change", listener);
868
- return () => {
869
- mediaQueryList.removeEventListener("change", listener);
870
- };
871
- }, []);
872
- return prefersReducedMotion;
873
- }
874
-
875
- export {
876
- useTooltipPortalRelocator,
877
- defaultTheme,
878
- GlobalChartsContext,
879
- GlobalChartsProvider,
880
- useGlobalChartsContext,
881
- useChartId,
882
- useDeepMemo,
883
- useChartMouseHandler,
884
- useXYChartTheme,
885
- useChartDataTransform,
886
- useChartMargin,
887
- useElementSize,
888
- useTextTruncation,
889
- useZeroValueDisplay,
890
- useInteractiveLegendData,
891
- usePrefersReducedMotion,
892
- useChartRegistration,
893
- useGlobalChartsTheme
894
- };
895
- //# sourceMappingURL=chunk-2I67QUIV.js.map