@automattic/charts 0.56.7 → 0.58.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 (223) hide show
  1. package/AGENTS.md +28 -98
  2. package/CHANGELOG.md +30 -0
  3. package/dist/charts/bar-chart/index.cjs +7 -6
  4. package/dist/charts/bar-chart/index.cjs.map +1 -1
  5. package/dist/charts/bar-chart/index.css +12 -24
  6. package/dist/charts/bar-chart/index.css.map +1 -1
  7. package/dist/charts/bar-chart/index.d.cts +3 -4
  8. package/dist/charts/bar-chart/index.d.ts +3 -4
  9. package/dist/charts/bar-chart/index.js +6 -5
  10. package/dist/charts/bar-list-chart/index.cjs +8 -7
  11. package/dist/charts/bar-list-chart/index.cjs.map +1 -1
  12. package/dist/charts/bar-list-chart/index.css +12 -24
  13. package/dist/charts/bar-list-chart/index.css.map +1 -1
  14. package/dist/charts/bar-list-chart/index.d.cts +3 -3
  15. package/dist/charts/bar-list-chart/index.d.ts +3 -3
  16. package/dist/charts/bar-list-chart/index.js +7 -6
  17. package/dist/charts/conversion-funnel-chart/index.cjs +5 -6
  18. package/dist/charts/conversion-funnel-chart/index.cjs.map +1 -1
  19. package/dist/charts/conversion-funnel-chart/index.css +0 -94
  20. package/dist/charts/conversion-funnel-chart/index.css.map +1 -1
  21. package/dist/charts/conversion-funnel-chart/index.d.cts +1 -1
  22. package/dist/charts/conversion-funnel-chart/index.d.ts +1 -1
  23. package/dist/charts/conversion-funnel-chart/index.js +4 -5
  24. package/dist/charts/geo-chart/index.cjs +4 -4
  25. package/dist/charts/geo-chart/index.css +0 -94
  26. package/dist/charts/geo-chart/index.css.map +1 -1
  27. package/dist/charts/geo-chart/index.d.cts +1 -1
  28. package/dist/charts/geo-chart/index.d.ts +1 -1
  29. package/dist/charts/geo-chart/index.js +3 -3
  30. package/dist/charts/leaderboard-chart/index.cjs +7 -6
  31. package/dist/charts/leaderboard-chart/index.cjs.map +1 -1
  32. package/dist/charts/leaderboard-chart/index.css +20 -33
  33. package/dist/charts/leaderboard-chart/index.css.map +1 -1
  34. package/dist/charts/leaderboard-chart/index.d.cts +3 -3
  35. package/dist/charts/leaderboard-chart/index.d.ts +3 -3
  36. package/dist/charts/leaderboard-chart/index.js +6 -5
  37. package/dist/charts/line-chart/index.cjs +7 -6
  38. package/dist/charts/line-chart/index.cjs.map +1 -1
  39. package/dist/charts/line-chart/index.css +12 -24
  40. package/dist/charts/line-chart/index.css.map +1 -1
  41. package/dist/charts/line-chart/index.d.cts +3 -4
  42. package/dist/charts/line-chart/index.d.ts +3 -4
  43. package/dist/charts/line-chart/index.js +6 -5
  44. package/dist/charts/pie-chart/index.cjs +7 -7
  45. package/dist/charts/pie-chart/index.css +12 -24
  46. package/dist/charts/pie-chart/index.css.map +1 -1
  47. package/dist/charts/pie-chart/index.d.cts +7 -13
  48. package/dist/charts/pie-chart/index.d.ts +7 -13
  49. package/dist/charts/pie-chart/index.js +6 -6
  50. package/dist/charts/pie-semi-circle-chart/index.cjs +7 -7
  51. package/dist/charts/pie-semi-circle-chart/index.css +12 -24
  52. package/dist/charts/pie-semi-circle-chart/index.css.map +1 -1
  53. package/dist/charts/pie-semi-circle-chart/index.d.cts +7 -13
  54. package/dist/charts/pie-semi-circle-chart/index.d.ts +7 -13
  55. package/dist/charts/pie-semi-circle-chart/index.js +6 -6
  56. package/dist/charts/sparkline/index.cjs +8 -7
  57. package/dist/charts/sparkline/index.cjs.map +1 -1
  58. package/dist/charts/sparkline/index.css +12 -24
  59. package/dist/charts/sparkline/index.css.map +1 -1
  60. package/dist/charts/sparkline/index.js +7 -6
  61. package/dist/{chunk-RFSHE3HL.js → chunk-2I67QUIV.js} +84 -431
  62. package/dist/chunk-2I67QUIV.js.map +1 -0
  63. package/dist/{chunk-OMS5QIJN.js → chunk-2ICEEQOC.js} +31 -25
  64. package/dist/chunk-2ICEEQOC.js.map +1 -0
  65. package/dist/{chunk-GWBS65VC.js → chunk-4B7BL2DD.js} +3 -3
  66. package/dist/{chunk-7FDQGBY7.js → chunk-4OXMTKAL.js} +24 -24
  67. package/dist/chunk-4OXMTKAL.js.map +1 -0
  68. package/dist/{chunk-SSFFCBCF.js → chunk-B6NLZFRW.js} +32 -26
  69. package/dist/chunk-B6NLZFRW.js.map +1 -0
  70. package/dist/{chunk-3EXJP67N.cjs → chunk-BBAUQOW6.cjs} +9 -9
  71. package/dist/{chunk-3EXJP67N.cjs.map → chunk-BBAUQOW6.cjs.map} +1 -1
  72. package/dist/{chunk-NQJE2CC7.cjs → chunk-CMMHCTBX.cjs} +45 -45
  73. package/dist/chunk-CMMHCTBX.cjs.map +1 -0
  74. package/dist/{chunk-O2JIANHK.cjs → chunk-CPPXJATQ.cjs} +51 -45
  75. package/dist/chunk-CPPXJATQ.cjs.map +1 -0
  76. package/dist/{chunk-MDRCAGKZ.js → chunk-DKU775VC.js} +3 -3
  77. package/dist/{chunk-BXFD7JIG.cjs → chunk-GRA7Y2ZG.cjs} +46 -46
  78. package/dist/chunk-GRA7Y2ZG.cjs.map +1 -0
  79. package/dist/{chunk-TE63Y5PX.js → chunk-JJIMABHT.js} +10 -3
  80. package/dist/chunk-JJIMABHT.js.map +1 -0
  81. package/dist/{chunk-KHQPN77E.js → chunk-KJHWXOCZ.js} +4 -4
  82. package/dist/{chunk-6CCZL2JJ.js → chunk-KRWGSOJ2.js} +30 -2
  83. package/dist/chunk-KRWGSOJ2.js.map +1 -0
  84. package/dist/{chunk-VPAEBI2F.js → chunk-LTFH7SEG.js} +24 -24
  85. package/dist/chunk-LTFH7SEG.js.map +1 -0
  86. package/dist/{chunk-E62LCBGD.js → chunk-MUNOKLLE.js} +3 -3
  87. package/dist/{chunk-ZVGEDXDP.cjs → chunk-MXGLYWVP.cjs} +10 -3
  88. package/dist/chunk-MXGLYWVP.cjs.map +1 -0
  89. package/dist/{chunk-55ZCOYDF.cjs → chunk-OYC34VTO.cjs} +252 -827
  90. package/dist/chunk-OYC34VTO.cjs.map +1 -0
  91. package/dist/{chunk-CAFJRZPZ.cjs → chunk-PQL5I3F6.cjs} +17 -17
  92. package/dist/{chunk-CAFJRZPZ.cjs.map → chunk-PQL5I3F6.cjs.map} +1 -1
  93. package/dist/{chunk-UFRBUT2D.cjs → chunk-REZTQ4PH.cjs} +87 -24
  94. package/dist/chunk-REZTQ4PH.cjs.map +1 -0
  95. package/dist/{chunk-RCY6XLGU.cjs → chunk-TZRUHQOH.cjs} +36 -8
  96. package/dist/chunk-TZRUHQOH.cjs.map +1 -0
  97. package/dist/{chunk-XD2HV7M5.js → chunk-UTYVIOWZ.js} +226 -801
  98. package/dist/chunk-UTYVIOWZ.js.map +1 -0
  99. package/dist/{chunk-YAXY5L7I.cjs → chunk-W2LDIX26.cjs} +5 -5
  100. package/dist/{chunk-YAXY5L7I.cjs.map → chunk-W2LDIX26.cjs.map} +1 -1
  101. package/dist/{chunk-K6TGILHX.cjs → chunk-WSG64BVN.cjs} +6 -6
  102. package/dist/{chunk-K6TGILHX.cjs.map → chunk-WSG64BVN.cjs.map} +1 -1
  103. package/dist/chunk-WTQYGUNF.js +400 -0
  104. package/dist/chunk-WTQYGUNF.js.map +1 -0
  105. package/dist/{chunk-YDVHT7GS.cjs → chunk-WYK7EL5R.cjs} +100 -447
  106. package/dist/chunk-WYK7EL5R.cjs.map +1 -0
  107. package/dist/{chunk-X7JL2NYJ.cjs → chunk-XC4KHJYX.cjs} +51 -45
  108. package/dist/chunk-XC4KHJYX.cjs.map +1 -0
  109. package/dist/chunk-XVBH5XHE.cjs +400 -0
  110. package/dist/chunk-XVBH5XHE.cjs.map +1 -0
  111. package/dist/{chunk-IS5YYLTV.js → chunk-YAFQVVDI.js} +85 -22
  112. package/dist/chunk-YAFQVVDI.js.map +1 -0
  113. package/dist/components/legend/index.cjs +4 -3
  114. package/dist/components/legend/index.cjs.map +1 -1
  115. package/dist/components/legend/index.css +12 -24
  116. package/dist/components/legend/index.css.map +1 -1
  117. package/dist/components/legend/index.d.cts +4 -4
  118. package/dist/components/legend/index.d.ts +4 -4
  119. package/dist/components/legend/index.js +3 -2
  120. package/dist/components/tooltip/index.d.cts +1 -1
  121. package/dist/components/tooltip/index.d.ts +1 -1
  122. package/dist/hooks/index.cjs +3 -5
  123. package/dist/hooks/index.cjs.map +1 -1
  124. package/dist/hooks/index.css +0 -94
  125. package/dist/hooks/index.css.map +1 -1
  126. package/dist/hooks/index.d.cts +9 -13
  127. package/dist/hooks/index.d.ts +9 -13
  128. package/dist/hooks/index.js +2 -4
  129. package/dist/index.cjs +18 -17
  130. package/dist/index.cjs.map +1 -1
  131. package/dist/index.css +20 -33
  132. package/dist/index.css.map +1 -1
  133. package/dist/index.d.cts +6 -6
  134. package/dist/index.d.ts +6 -6
  135. package/dist/index.js +17 -16
  136. package/dist/{leaderboard-chart-COtgamhe.d.cts → leaderboard-chart-BSbg0ufV.d.cts} +3 -11
  137. package/dist/{leaderboard-chart-BSgEw_Um.d.ts → leaderboard-chart-odEYxxEC.d.ts} +3 -11
  138. package/dist/{legend-C9ahiwOt.d.cts → legend-DFkosEvC.d.cts} +1 -1
  139. package/dist/{legend-jjMmhSg3.d.ts → legend-DLswHhOk.d.ts} +1 -1
  140. package/dist/providers/index.cjs +3 -3
  141. package/dist/providers/index.css +0 -94
  142. package/dist/providers/index.css.map +1 -1
  143. package/dist/providers/index.d.cts +3 -3
  144. package/dist/providers/index.d.ts +3 -3
  145. package/dist/providers/index.js +2 -2
  146. package/dist/{themes-CVR5rmIs.d.cts → themes-D0qc5JaW.d.cts} +2 -2
  147. package/dist/{themes-DQzmaSze.d.ts → themes-itO4Ht5g.d.ts} +2 -2
  148. package/dist/{types-BBwg4Evw.d.cts → types-B5f6XQ7Q.d.cts} +1 -1
  149. package/dist/{types-DQNnq5Fr.d.ts → types-BsHooDbM.d.ts} +1 -1
  150. package/dist/{types-C05PdDJa.d.cts → types-BuSrRM4p.d.ts} +15 -23
  151. package/dist/{types-CzdN7rUe.d.cts → types-ChOUI9-N.d.cts} +90 -46
  152. package/dist/{types-CzdN7rUe.d.ts → types-ChOUI9-N.d.ts} +90 -46
  153. package/dist/{types-C05PdDJa.d.ts → types-Dfw9VOKI.d.cts} +15 -23
  154. package/dist/utils/index.cjs +2 -2
  155. package/dist/utils/index.d.cts +1 -1
  156. package/dist/utils/index.d.ts +1 -1
  157. package/dist/utils/index.js +1 -1
  158. package/package.json +10 -8
  159. package/src/charts/bar-chart/bar-chart.tsx +19 -19
  160. package/src/charts/bar-chart/test/bar-chart.test.tsx +78 -31
  161. package/src/charts/conversion-funnel-chart/test/conversion-funnel-chart.test.tsx +2 -2
  162. package/src/charts/leaderboard-chart/hooks/use-leaderboard-legend-items.ts +0 -2
  163. package/src/charts/leaderboard-chart/leaderboard-chart.module.scss +9 -10
  164. package/src/charts/leaderboard-chart/leaderboard-chart.tsx +124 -102
  165. package/src/charts/leaderboard-chart/test/leaderboard-chart.test.tsx +61 -33
  166. package/src/charts/leaderboard-chart/test/use-leaderboard-legend-items.test.tsx +2 -5
  167. package/src/charts/leaderboard-chart/types.ts +2 -15
  168. package/src/charts/line-chart/line-chart.tsx +18 -17
  169. package/src/charts/line-chart/test/line-chart.test.tsx +49 -27
  170. package/src/charts/line-chart/types.ts +0 -1
  171. package/src/charts/pie-chart/pie-chart.tsx +23 -23
  172. package/src/charts/pie-chart/test/composition-api.test.tsx +41 -0
  173. package/src/charts/pie-chart/test/pie-chart.test.tsx +9 -9
  174. package/src/charts/pie-semi-circle-chart/pie-semi-circle-chart.tsx +21 -24
  175. package/src/charts/pie-semi-circle-chart/test/pie-semi-circle-chart.test.tsx +33 -5
  176. package/src/charts/private/chart-composition/index.ts +2 -0
  177. package/src/charts/private/chart-composition/render-legend-slot.ts +22 -0
  178. package/src/charts/private/chart-composition/test/render-legend-slot.test.tsx +60 -0
  179. package/src/charts/private/chart-composition/test/use-chart-children.test.tsx +91 -0
  180. package/src/charts/private/chart-composition/use-chart-children.ts +34 -2
  181. package/src/components/legend/private/base-legend.module.scss +19 -37
  182. package/src/components/legend/private/base-legend.tsx +32 -24
  183. package/src/components/legend/test/legend.test.tsx +148 -52
  184. package/src/components/legend/types.ts +23 -24
  185. package/src/hooks/index.ts +0 -1
  186. package/src/hooks/test/use-zero-value-display.test.tsx +206 -0
  187. package/src/hooks/use-zero-value-display.ts +52 -23
  188. package/src/providers/chart-context/test/chart-context.test.tsx +12 -6
  189. package/src/providers/chart-context/themes.ts +6 -4
  190. package/src/types.ts +93 -44
  191. package/src/utils/date-parsing.ts +10 -1
  192. package/src/utils/get-styles.ts +1 -1
  193. package/src/utils/test/date-parsing.test.ts +12 -0
  194. package/src/utils/test/get-styles.test.ts +12 -10
  195. package/src/utils/test/resolve-css-var.test.ts +2 -2
  196. package/tsup.config.ts +1 -1
  197. package/dist/chunk-55ZCOYDF.cjs.map +0 -1
  198. package/dist/chunk-6CCZL2JJ.js.map +0 -1
  199. package/dist/chunk-7FDQGBY7.js.map +0 -1
  200. package/dist/chunk-BXFD7JIG.cjs.map +0 -1
  201. package/dist/chunk-IS5YYLTV.js.map +0 -1
  202. package/dist/chunk-KNIMXN6Z.js +0 -51
  203. package/dist/chunk-KNIMXN6Z.js.map +0 -1
  204. package/dist/chunk-NQJE2CC7.cjs.map +0 -1
  205. package/dist/chunk-O2JIANHK.cjs.map +0 -1
  206. package/dist/chunk-OMS5QIJN.js.map +0 -1
  207. package/dist/chunk-RCY6XLGU.cjs.map +0 -1
  208. package/dist/chunk-RFSHE3HL.js.map +0 -1
  209. package/dist/chunk-SSFFCBCF.js.map +0 -1
  210. package/dist/chunk-SUDERBUA.cjs +0 -51
  211. package/dist/chunk-SUDERBUA.cjs.map +0 -1
  212. package/dist/chunk-TE63Y5PX.js.map +0 -1
  213. package/dist/chunk-UFRBUT2D.cjs.map +0 -1
  214. package/dist/chunk-VPAEBI2F.js.map +0 -1
  215. package/dist/chunk-X7JL2NYJ.cjs.map +0 -1
  216. package/dist/chunk-XD2HV7M5.js.map +0 -1
  217. package/dist/chunk-YDVHT7GS.cjs.map +0 -1
  218. package/dist/chunk-ZVGEDXDP.cjs.map +0 -1
  219. package/src/hooks/use-has-legend-child.ts +0 -22
  220. /package/dist/{chunk-GWBS65VC.js.map → chunk-4B7BL2DD.js.map} +0 -0
  221. /package/dist/{chunk-MDRCAGKZ.js.map → chunk-DKU775VC.js.map} +0 -0
  222. /package/dist/{chunk-KHQPN77E.js.map → chunk-KJHWXOCZ.js.map} +0 -0
  223. /package/dist/{chunk-E62LCBGD.js.map → chunk-MUNOKLLE.js.map} +0 -0
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
2
 
3
3
 
4
4
 
@@ -7,15 +7,53 @@
7
7
 
8
8
 
9
9
 
10
+ var _chunkMXGLYWVPcjs = require('./chunk-MXGLYWVP.cjs');
10
11
 
11
- var _chunkZVGEDXDPcjs = require('./chunk-ZVGEDXDP.cjs');
12
+
13
+
14
+ var _chunkEMMSS5I5cjs = require('./chunk-EMMSS5I5.cjs');
15
+
16
+ // ../../../node_modules/.pnpm/fast-deep-equal@3.1.3/node_modules/fast-deep-equal/index.js
17
+ var require_fast_deep_equal = _chunkEMMSS5I5cjs.__commonJS.call(void 0, {
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
+ });
12
50
 
13
51
  // src/hooks/use-deep-memo.ts
14
- var _fastdeepequal = require('fast-deep-equal'); var _fastdeepequal2 = _interopRequireDefault(_fastdeepequal);
52
+ var import_fast_deep_equal = _chunkEMMSS5I5cjs.__toESM.call(void 0, require_fast_deep_equal(), 1);
15
53
  var _react = require('react');
16
54
  var useDeepMemo = (value) => {
17
55
  const ref = _react.useRef.call(void 0, value);
18
- if (!_fastdeepequal2.default.call(void 0, ref.current, value)) {
56
+ if (!(0, import_fast_deep_equal.default)(ref.current, value)) {
19
57
  ref.current = value;
20
58
  }
21
59
  return ref.current;
@@ -96,7 +134,7 @@ function installRemoveChildPatch() {
96
134
  patchedRemoveChild = function(child) {
97
135
  if (relocatedNodes.has(child) && child.parentNode !== this) {
98
136
  relocatedNodes.delete(child);
99
- _optionalChain([child, 'access', _2 => _2.parentNode, 'optionalAccess', _3 => _3.removeChild, 'call', _4 => _4(child)]);
137
+ _optionalChain([child, 'access', _ => _.parentNode, 'optionalAccess', _2 => _2.removeChild, 'call', _3 => _3(child)]);
100
138
  return child;
101
139
  }
102
140
  return origRemoveChild.call(this, child);
@@ -115,7 +153,7 @@ function uninstallRemoveChildPatch() {
115
153
  }
116
154
  function useTooltipPortalRelocator(containerRef) {
117
155
  _react.useEffect.call(void 0, () => {
118
- const container = _optionalChain([containerRef, 'optionalAccess', _5 => _5.current]);
156
+ const container = _optionalChain([containerRef, 'optionalAccess', _4 => _4.current]);
119
157
  if (!container) {
120
158
  return;
121
159
  }
@@ -229,7 +267,7 @@ var getChartColor = (index, colorCache) => {
229
267
  const candidateHsl = [hue, saturation, lightness];
230
268
  let isSufficientlyDifferent = true;
231
269
  for (const existingHsl of existingHslColors) {
232
- if (_chunkZVGEDXDPcjs.getColorDistance.call(void 0, candidateHsl, existingHsl) < MIN_COLOR_DISTANCE) {
270
+ if (_chunkMXGLYWVPcjs.getColorDistance.call(void 0, candidateHsl, existingHsl) < MIN_COLOR_DISTANCE) {
233
271
  isSufficientlyDifferent = false;
234
272
  break;
235
273
  }
@@ -266,12 +304,14 @@ var defaultTheme = {
266
304
  gridColorDark: "",
267
305
  xTickLineStyles: { stroke: "black" },
268
306
  xAxisLineStyles: { stroke: "#DCDCDE", strokeWidth: 1 },
269
- legendLabelStyles: {
270
- color: "var(--jp-gray-80, #2c3338)"
307
+ legend: {
308
+ labelStyles: {
309
+ color: "var(--jp-gray-80, #2c3338)"
310
+ },
311
+ containerStyles: {},
312
+ shapeStyles: []
271
313
  },
272
- legendContainerStyles: {},
273
314
  seriesLineStyles: [],
274
- legendShapeStyles: [],
275
315
  glyphs: [],
276
316
  svgLabelSmall: { fill: "var(--jp-gray-80, #2c3338)" },
277
317
  annotationStyles: {
@@ -330,7 +370,7 @@ var GlobalChartsProvider = ({
330
370
  const wrapperRef = _react.useRef.call(void 0, null);
331
371
  useTooltipPortalRelocator(_nullishCoalesce(portalContainer, () => ( wrapperRef)));
332
372
  const providerTheme = _react.useMemo.call(void 0, () => {
333
- return theme ? _chunkZVGEDXDPcjs.mergeThemes.call(void 0, defaultTheme, theme) : defaultTheme;
373
+ return theme ? _chunkMXGLYWVPcjs.mergeThemes.call(void 0, defaultTheme, theme) : defaultTheme;
334
374
  }, [theme]);
335
375
  const [colorCache, setColorCache] = _react.useState.call(void 0, () => ({
336
376
  colors: [],
@@ -353,7 +393,7 @@ var GlobalChartsProvider = ({
353
393
  if (color && typeof color === "string") {
354
394
  let colorValue = color;
355
395
  if (color.startsWith("--") || color.startsWith("var(")) {
356
- const resolved = _chunkZVGEDXDPcjs.resolveCssVariable.call(void 0, color, wrapperRef.current);
396
+ const resolved = _chunkMXGLYWVPcjs.resolveCssVariable.call(void 0, color, wrapperRef.current);
357
397
  if (resolved === null || resolved === "") {
358
398
  continue;
359
399
  }
@@ -404,7 +444,7 @@ var GlobalChartsProvider = ({
404
444
  overrideColor
405
445
  }) => {
406
446
  if (overrideColor) {
407
- return _chunkZVGEDXDPcjs.normalizeColorToHex.call(void 0, overrideColor, wrapperRef.current, _chunkZVGEDXDPcjs.resolveCssVariable);
447
+ return _chunkMXGLYWVPcjs.normalizeColorToHex.call(void 0, overrideColor, wrapperRef.current, _chunkMXGLYWVPcjs.resolveCssVariable);
408
448
  }
409
449
  if (group) {
410
450
  const existing = groupToColorMap.get(group);
@@ -428,13 +468,13 @@ var GlobalChartsProvider = ({
428
468
  const isPointPercentageData = data && typeof data === "object" && "percentage" in data;
429
469
  return {
430
470
  color: resolveColor({
431
- group: _optionalChain([data, 'optionalAccess', _6 => _6.group]),
471
+ group: _optionalChain([data, 'optionalAccess', _5 => _5.group]),
432
472
  index,
433
- overrideColor: overrideColor || isSeriesData && _optionalChain([data, 'optionalAccess', _7 => _7.options, 'optionalAccess', _8 => _8.stroke]) || isPointPercentageData && _optionalChain([data, 'optionalAccess', _9 => _9.color])
473
+ overrideColor: overrideColor || isSeriesData && _optionalChain([data, 'optionalAccess', _6 => _6.options, 'optionalAccess', _7 => _7.stroke]) || isPointPercentageData && _optionalChain([data, 'optionalAccess', _8 => _8.color])
434
474
  }),
435
- lineStyles: isSeriesData ? _chunkZVGEDXDPcjs.getSeriesLineStyles.call(void 0, data, index, providerTheme) : {},
436
- glyph: _optionalChain([providerTheme, 'access', _10 => _10.glyphs, 'optionalAccess', _11 => _11[index]]),
437
- shapeStyles: isSeriesData ? _chunkZVGEDXDPcjs.getItemShapeStyles.call(void 0, data, index, providerTheme, legendShape) : {}
475
+ lineStyles: isSeriesData ? _chunkMXGLYWVPcjs.getSeriesLineStyles.call(void 0, data, index, providerTheme) : {},
476
+ glyph: _optionalChain([providerTheme, 'access', _9 => _9.glyphs, 'optionalAccess', _10 => _10[index]]),
477
+ shapeStyles: isSeriesData ? _chunkMXGLYWVPcjs.getItemShapeStyles.call(void 0, data, index, providerTheme, legendShape) : {}
438
478
  };
439
479
  }, [providerTheme, resolveColor]);
440
480
  const toggleSeriesVisibility = _react.useCallback.call(void 0, (chartId, seriesLabel) => {
@@ -541,7 +581,7 @@ var useChartRegistration = ({
541
581
 
542
582
  var useGlobalChartsTheme = () => {
543
583
  const context = _react.useContext.call(void 0, GlobalChartsContext);
544
- const globalTheme = _optionalChain([context, 'optionalAccess', _12 => _12.theme]);
584
+ const globalTheme = _optionalChain([context, 'optionalAccess', _11 => _11.theme]);
545
585
  return _nullishCoalesce(globalTheme, () => ( defaultTheme));
546
586
  };
547
587
 
@@ -549,7 +589,7 @@ var useGlobalChartsTheme = () => {
549
589
  var useXYChartTheme = (data) => {
550
590
  const theme = useGlobalChartsTheme();
551
591
  return _react.useMemo.call(void 0, () => {
552
- const seriesColors = (_nullishCoalesce(data, () => ( []))).map((series) => _optionalChain([series, 'access', _13 => _13.options, 'optionalAccess', _14 => _14.stroke])).filter((color) => Boolean(color));
592
+ const seriesColors = (_nullishCoalesce(data, () => ( []))).map((series) => _optionalChain([series, 'access', _12 => _12.options, 'optionalAccess', _13 => _13.stroke])).filter((color) => Boolean(color));
553
593
  return _xychart.buildChartTheme.call(void 0, {
554
594
  ...theme,
555
595
  colors: [...seriesColors, ..._nullishCoalesce(theme.colors, () => ( []))]
@@ -561,7 +601,7 @@ var useXYChartTheme = (data) => {
561
601
 
562
602
  var useChartDataTransform = (data) => {
563
603
  return _react.useMemo.call(void 0, () => {
564
- const firstPoint = _optionalChain([data, 'optionalAccess', _15 => _15[0], 'optionalAccess', _16 => _16.data, 'optionalAccess', _17 => _17[0]]);
604
+ const firstPoint = _optionalChain([data, 'optionalAccess', _14 => _14[0], 'optionalAccess', _15 => _15.data, 'optionalAccess', _16 => _16[0]]);
565
605
  const hasDateProperties = firstPoint && ("date" in firstPoint || "dateString" in firstPoint);
566
606
  if (!hasDateProperties) {
567
607
  return data;
@@ -573,7 +613,7 @@ var useChartDataTransform = (data) => {
573
613
  if ("date" in point && point.date) {
574
614
  date = point.date;
575
615
  } else if ("dateString" in point && point.dateString) {
576
- date = _chunkZVGEDXDPcjs.parseAsLocalDate.call(void 0, point.dateString);
616
+ date = _chunkMXGLYWVPcjs.parseAsLocalDate.call(void 0, point.dateString);
577
617
  }
578
618
  return {
579
619
  ...point,
@@ -609,9 +649,9 @@ var resolveFontSize = (val) => {
609
649
  return void 0;
610
650
  };
611
651
  var getXAxisLabelMetrics = (theme, orientation) => {
612
- const xAxisStyles = orientation === "top" ? _optionalChain([theme, 'access', _18 => _18.axisStyles, 'optionalAccess', _19 => _19.x, 'optionalAccess', _20 => _20.top]) : _optionalChain([theme, 'access', _21 => _21.axisStyles, 'optionalAccess', _22 => _22.x, 'optionalAccess', _23 => _23.bottom]);
613
- const fontSize = resolveFontSize(_optionalChain([xAxisStyles, 'optionalAccess', _24 => _24.axisLabel, 'optionalAccess', _25 => _25.fontSize])) || resolveFontSize(_optionalChain([theme, 'access', _26 => _26.svgLabelSmall, 'optionalAccess', _27 => _27.fontSize])) || DEFAULT_FONT_SIZE;
614
- const tickLength = _nullishCoalesce(_optionalChain([xAxisStyles, 'optionalAccess', _28 => _28.tickLength]), () => ( DEFAULT_TICK_LENGTH));
652
+ const xAxisStyles = orientation === "top" ? _optionalChain([theme, 'access', _17 => _17.axisStyles, 'optionalAccess', _18 => _18.x, 'optionalAccess', _19 => _19.top]) : _optionalChain([theme, 'access', _20 => _20.axisStyles, 'optionalAccess', _21 => _21.x, 'optionalAccess', _22 => _22.bottom]);
653
+ const fontSize = resolveFontSize(_optionalChain([xAxisStyles, 'optionalAccess', _23 => _23.axisLabel, 'optionalAccess', _24 => _24.fontSize])) || resolveFontSize(_optionalChain([theme, 'access', _25 => _25.svgLabelSmall, 'optionalAccess', _26 => _26.fontSize])) || DEFAULT_FONT_SIZE;
654
+ const tickLength = _nullishCoalesce(_optionalChain([xAxisStyles, 'optionalAccess', _27 => _27.tickLength]), () => ( DEFAULT_TICK_LENGTH));
615
655
  return {
616
656
  fontSize,
617
657
  tickLength
@@ -621,7 +661,7 @@ var useChartMargin = (height, options, data, theme, horizontal = false) => {
621
661
  const yTicks = _react.useMemo.call(void 0, () => {
622
662
  const allDataPoints = data.flatMap((series) => series.data);
623
663
  if (horizontal) {
624
- return allDataPoints.map((d) => d.label || _optionalChain([options, 'access', _29 => _29.axis, 'optionalAccess', _30 => _30.y, 'optionalAccess', _31 => _31.tickFormat, 'call', _32 => _32(d.date.getTime(), 0, [])]));
664
+ return allDataPoints.map((d) => d.label || _optionalChain([options, 'access', _28 => _28.axis, 'optionalAccess', _29 => _29.y, 'optionalAccess', _30 => _30.tickFormat, 'call', _31 => _31(d.date.getTime(), 0, [])]));
625
665
  }
626
666
  const minY = Math.min(...allDataPoints.map((d) => d.value));
627
667
  const maxY = Math.max(...allDataPoints.map((d) => d.value));
@@ -630,7 +670,7 @@ var useChartMargin = (height, options, data, theme, horizontal = false) => {
630
670
  domain: [minY, maxY],
631
671
  range: [height, 0]
632
672
  });
633
- return _scale.getTicks.call(void 0, yScale, _optionalChain([options, 'access', _33 => _33.axis, 'optionalAccess', _34 => _34.y, 'optionalAccess', _35 => _35.numTicks]));
673
+ return _scale.getTicks.call(void 0, yScale, _optionalChain([options, 'access', _32 => _32.axis, 'optionalAccess', _33 => _33.y, 'optionalAccess', _34 => _34.numTicks]));
634
674
  }, [options, data, height, horizontal]);
635
675
  return _react.useMemo.call(void 0, () => {
636
676
  const defaultMargin = {
@@ -639,16 +679,16 @@ var useChartMargin = (height, options, data, theme, horizontal = false) => {
639
679
  bottom: DEFAULT_MARGIN_BOTTOM,
640
680
  left: DEFAULT_MARGIN_LEFT
641
681
  };
642
- const yAxisOrientation = _optionalChain([options, 'access', _36 => _36.axis, 'optionalAccess', _37 => _37.y, 'optionalAccess', _38 => _38.orientation]);
682
+ const yAxisOrientation = _optionalChain([options, 'access', _35 => _35.axis, 'optionalAccess', _36 => _36.y, 'optionalAccess', _37 => _37.orientation]);
643
683
  const yAxisStyles = yAxisOrientation === "right" ? theme.axisStyles.y.right : theme.axisStyles.y.left;
644
- const yTickWidth = _chunkZVGEDXDPcjs.getLongestTickWidth.call(void 0, yTicks, _optionalChain([options, 'access', _39 => _39.axis, 'optionalAccess', _40 => _40.y, 'optionalAccess', _41 => _41.tickFormat]), yAxisStyles.axisLabel);
645
- const yMarginValue = (_nullishCoalesce(yTickWidth, () => ( DEFAULT_Y_TICK_WIDTH))) + (_nullishCoalesce(_optionalChain([yAxisStyles, 'optionalAccess', _42 => _42.tickLength]), () => ( 0)));
684
+ const yTickWidth = _chunkMXGLYWVPcjs.getLongestTickWidth.call(void 0, yTicks, _optionalChain([options, 'access', _38 => _38.axis, 'optionalAccess', _39 => _39.y, 'optionalAccess', _40 => _40.tickFormat]), yAxisStyles.axisLabel);
685
+ const yMarginValue = (_nullishCoalesce(yTickWidth, () => ( DEFAULT_Y_TICK_WIDTH))) + (_nullishCoalesce(_optionalChain([yAxisStyles, 'optionalAccess', _41 => _41.tickLength]), () => ( 0)));
646
686
  if (yAxisOrientation === "right") {
647
687
  defaultMargin.right = yMarginValue;
648
688
  } else {
649
689
  defaultMargin.left = yMarginValue;
650
690
  }
651
- const xOrientation = _optionalChain([options, 'access', _43 => _43.axis, 'optionalAccess', _44 => _44.x, 'optionalAccess', _45 => _45.orientation]) === "top" ? "top" : "bottom";
691
+ const xOrientation = _optionalChain([options, 'access', _42 => _42.axis, 'optionalAccess', _43 => _43.x, 'optionalAccess', _44 => _44.orientation]) === "top" ? "top" : "bottom";
652
692
  const {
653
693
  fontSize,
654
694
  tickLength
@@ -693,401 +733,6 @@ function useElementSize({
693
733
  return [refCallback, width, height];
694
734
  }
695
735
 
696
- // src/hooks/use-has-legend-child.ts
697
-
698
-
699
- // src/components/legend/legend.tsx
700
-
701
-
702
- // src/charts/private/single-chart-context/single-chart-context.tsx
703
-
704
- var ChartInstanceContext = /* @__PURE__ */ _react.createContext.call(void 0, null);
705
- var SingleChartContext = ChartInstanceContext;
706
-
707
- // src/charts/private/single-chart-context/use-single-chart-context.ts
708
-
709
- var useChartInstanceContext = () => {
710
- const context = _react.useContext.call(void 0, ChartInstanceContext);
711
- if (!context) {
712
- throw new Error("useChartInstanceContext must be used within a Chart component");
713
- }
714
- return context;
715
- };
716
- var useSingleChartContext = useChartInstanceContext;
717
-
718
- // src/components/legend/private/base-legend.tsx
719
- var _group = require('@visx/group');
720
- var _legend = require('@visx/legend');
721
-
722
- var _clsx = require('clsx'); var _clsx2 = _interopRequireDefault(_clsx);
723
-
724
-
725
- // src/components/legend/utils/value-or-identity.ts
726
- function valueOrIdentity(_) {
727
- if (_ && typeof _ === "object" && "value" in _ && typeof _.value !== "undefined")
728
- return _.value;
729
- return _;
730
- }
731
- function valueOrIdentityString(_) {
732
- return String(valueOrIdentity(_));
733
- }
734
-
735
- // src/components/legend/utils/label-transform-factory.ts
736
- function labelTransformFactory({
737
- scale,
738
- labelFormat
739
- }) {
740
- return (d, i) => ({
741
- datum: d,
742
- index: i,
743
- text: `${labelFormat(d, i)}`,
744
- value: scale(d)
745
- });
746
- }
747
-
748
- // src/components/legend/private/base-legend.module.scss
749
- var base_legend_module_default = {
750
- "legend--horizontal": "a8ccharts-AELBvX",
751
- "legend--vertical": "a8ccharts-fX8uQe",
752
- "legend--alignment-start": "a8ccharts-DEe0wg",
753
- "legend--alignment-center": "a8ccharts-WBKF9I",
754
- "legend--alignment-end": "a8ccharts-JfwMng",
755
- "legend--position-top": "a8ccharts-8Y73Kh",
756
- "legend--position-bottom": "a8ccharts-TVM-IY",
757
- "legend-item": "a8ccharts-Vflwq8",
758
- "legend-item--interactive": "a8ccharts-qGsavM",
759
- "legend-item--inactive": "a8ccharts-ZtDY-Q",
760
- "legend-item-label": "a8ccharts-2H65Kr",
761
- "legend-item-text--wrap": "a8ccharts-faSDBI",
762
- "legend-item-text--ellipsis": "a8ccharts-FISUIO",
763
- "legend-item-value": "a8ccharts-DTZlT-"
764
- };
765
-
766
- // src/components/legend/private/base-legend.tsx
767
-
768
- var orientationToFlexDirection = {
769
- horizontal: "row",
770
- vertical: "column"
771
- };
772
- var LegendText = ({
773
- text,
774
- textOverflow,
775
- maxWidth
776
- }) => {
777
- const isEllipsis = maxWidth != null && textOverflow === "ellipsis";
778
- const [textRef, isTruncated] = useTextTruncation(Boolean(isEllipsis));
779
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", {
780
- ref: textRef,
781
- className: _clsx2.default.call(void 0, base_legend_module_default["legend-item-text"], maxWidth != null && base_legend_module_default[`legend-item-text--${textOverflow}`]),
782
- style: {
783
- ...maxWidth != null && {
784
- maxWidth,
785
- minWidth: 0
786
- }
787
- },
788
- title: isEllipsis && isTruncated ? text : void 0,
789
- children: text
790
- });
791
- };
792
- var BaseLegend = /* @__PURE__ */ _react.forwardRef.call(void 0, ({
793
- items,
794
- className,
795
- orientation = "horizontal",
796
- position = "bottom",
797
- alignment = "center",
798
- maxWidth,
799
- textOverflow = "wrap",
800
- shape = "rect",
801
- fill = valueOrIdentityString,
802
- size = valueOrIdentityString,
803
- labelFormat = valueOrIdentity,
804
- labelTransform = labelTransformFactory,
805
- shapeWidth = 16,
806
- shapeHeight = 16,
807
- shapeMargin = "2px 4px 2px 0",
808
- labelAlign = "left",
809
- labelFlex = "0 0 auto",
810
- // Use natural width instead of expanding to fill space
811
- labelMargin = "0 4px",
812
- itemMargin = "0",
813
- itemDirection = "row",
814
- legendLabelProps,
815
- legendItemClassName,
816
- render,
817
- interactive = false,
818
- chartId,
819
- ...legendItemProps
820
- }, ref) => {
821
- const theme = useGlobalChartsTheme();
822
- const context = _react.useContext.call(void 0, GlobalChartsContext);
823
- const legendScale = _scale.scaleOrdinal.call(void 0, {
824
- domain: items.map((item) => item.label),
825
- range: items.map((item) => item.color)
826
- });
827
- const domain = legendScale.domain();
828
- const getShapeStyle = _react.useCallback.call(void 0, ({
829
- index
830
- }) => _optionalChain([items, 'access', _46 => _46[index], 'optionalAccess', _47 => _47.shapeStyle]), [items]);
831
- const handleLegendClick = _react.useCallback.call(void 0, (seriesLabel) => {
832
- if (interactive && chartId && context) {
833
- context.toggleSeriesVisibility(chartId, seriesLabel);
834
- }
835
- }, [interactive, chartId, context]);
836
- const isSeriesVisible = _react.useCallback.call(void 0, (seriesLabel) => {
837
- if (!interactive || !chartId || !context) {
838
- return true;
839
- }
840
- return context.isSeriesVisible(chartId, seriesLabel);
841
- }, [interactive, chartId, context]);
842
- const createClickHandler = _react.useCallback.call(void 0, (labelText) => {
843
- if (!interactive) {
844
- return void 0;
845
- }
846
- return () => handleLegendClick(labelText);
847
- }, [interactive, handleLegendClick]);
848
- const createKeyDownHandler = _react.useCallback.call(void 0, (labelText) => {
849
- if (!interactive) {
850
- return void 0;
851
- }
852
- return (event) => {
853
- if (event.key === "Enter" || event.key === " ") {
854
- event.preventDefault();
855
- handleLegendClick(labelText);
856
- }
857
- };
858
- }, [interactive, handleLegendClick]);
859
- return render ? render(items) : /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _legend.LegendOrdinal, {
860
- scale: legendScale,
861
- labelFormat,
862
- labelTransform,
863
- children: (labels) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", {
864
- ref,
865
- role: "list",
866
- className: _clsx2.default.call(void 0, 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),
867
- style: {
868
- flexDirection: orientationToFlexDirection[orientation],
869
- ...theme.legendContainerStyles
870
- },
871
- children: labels.map((label, i) => {
872
- const visible = isSeriesVisible(label.text);
873
- const handleClick = createClickHandler(label.text);
874
- const handleKeyDown = createKeyDownHandler(label.text);
875
- return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _legend.LegendItem, {
876
- className: _clsx2.default.call(void 0, "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),
877
- margin: itemMargin,
878
- flexDirection: orientation === "vertical" && alignment === "end" ? "row-reverse" : itemDirection,
879
- onClick: handleClick,
880
- onKeyDown: handleKeyDown,
881
- role: interactive ? "button" : void 0,
882
- tabIndex: interactive ? 0 : void 0,
883
- "aria-pressed": interactive ? visible : void 0,
884
- "aria-label": interactive ? `${label.text}: ${visible ? "visible" : "hidden"}. Toggle visibility.` : void 0,
885
- ...legendItemProps,
886
- children: [_optionalChain([items, 'access', _48 => _48[i], 'optionalAccess', _49 => _49.renderGlyph]) ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "svg", {
887
- width: _optionalChain([items, 'access', _50 => _50[i], 'optionalAccess', _51 => _51.glyphSize]) * 2,
888
- height: _optionalChain([items, 'access', _52 => _52[i], 'optionalAccess', _53 => _53.glyphSize]) * 2,
889
- children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _group.Group, {
890
- children: _optionalChain([items, 'access', _54 => _54[i], 'optionalAccess', _55 => _55.renderGlyph, 'call', _56 => _56({
891
- key: `legend-glyph-${label.text}`,
892
- datum: {},
893
- index: i,
894
- color: fill(label),
895
- size: _optionalChain([items, 'access', _57 => _57[i], 'optionalAccess', _58 => _58.glyphSize]),
896
- x: _optionalChain([items, 'access', _59 => _59[i], 'optionalAccess', _60 => _60.glyphSize]),
897
- y: _optionalChain([items, 'access', _61 => _61[i], 'optionalAccess', _62 => _62.glyphSize])
898
- })])
899
- })
900
- }) : /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _legend.LegendShape, {
901
- shape,
902
- height: shapeHeight,
903
- width: shapeWidth,
904
- margin: shapeMargin,
905
- item: domain[i],
906
- itemIndex: i,
907
- label,
908
- fill,
909
- size,
910
- shapeStyle: getShapeStyle
911
- }), /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _legend.LegendLabel, {
912
- className: _clsx2.default.call(void 0, "visx-legend-label", base_legend_module_default["legend-item-label"]),
913
- style: {
914
- justifyContent: labelAlign,
915
- flex: labelFlex,
916
- margin: labelMargin,
917
- ...theme.legendLabelStyles
918
- },
919
- ...legendLabelProps,
920
- children: [/* @__PURE__ */ _jsxruntime.jsx.call(void 0, LegendText, {
921
- text: label.text,
922
- textOverflow,
923
- maxWidth
924
- }), _optionalChain([items, 'access', _63 => _63.find, 'call', _64 => _64((item) => item.label === label.text), 'optionalAccess', _65 => _65.value]) && /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "span", {
925
- className: base_legend_module_default["legend-item-value"],
926
- children: ["\xA0", _optionalChain([items, 'access', _66 => _66.find, 'call', _67 => _67((item) => item.label === label.text), 'optionalAccess', _68 => _68.value])]
927
- })]
928
- })]
929
- }, `legend-${label.text}-${i}`);
930
- })
931
- })
932
- });
933
- });
934
-
935
- // src/components/legend/legend.tsx
936
-
937
- var Legend = /* @__PURE__ */ _react.forwardRef.call(void 0, ({
938
- chartId,
939
- items,
940
- ...props
941
- }, ref) => {
942
- const context = _react.useContext.call(void 0, GlobalChartsContext);
943
- const singleChartContext = _react.useContext.call(void 0, SingleChartContext);
944
- const contextChartId = _nullishCoalesce(chartId, () => ( _optionalChain([singleChartContext, 'optionalAccess', _69 => _69.chartId])));
945
- const contextItems = _react.useMemo.call(void 0, () => {
946
- return contextChartId && context ? _optionalChain([context, 'access', _70 => _70.getChartData, 'call', _71 => _71(contextChartId), 'optionalAccess', _72 => _72.legendItems]) : void 0;
947
- }, [contextChartId, context]);
948
- const legendItems = items || contextItems;
949
- if (!legendItems) {
950
- return null;
951
- }
952
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, BaseLegend, {
953
- ref,
954
- items: legendItems,
955
- ...props,
956
- chartId: contextChartId
957
- });
958
- });
959
-
960
- // src/components/legend/hooks/use-chart-legend-items.ts
961
- var _numberformatters = require('@automattic/number-formatters');
962
-
963
- function formatPointValue(point, showValues, legendValueDisplay = "percentage") {
964
- if (!showValues || legendValueDisplay === "none") {
965
- return "";
966
- }
967
- if ("percentage" in point) {
968
- const percentagePoint = point;
969
- switch (legendValueDisplay) {
970
- case "percentage":
971
- return _chunkZVGEDXDPcjs.formatPercentage.call(void 0, percentagePoint.percentage);
972
- case "value":
973
- return _numberformatters.formatNumber.call(void 0, percentagePoint.value);
974
- case "valueDisplay":
975
- return percentagePoint.valueDisplay || _numberformatters.formatNumber.call(void 0, percentagePoint.value);
976
- default:
977
- return "";
978
- }
979
- }
980
- if ("value" in point) {
981
- return point.value !== null ? _numberformatters.formatNumber.call(void 0, point.value) : "";
982
- }
983
- return "";
984
- }
985
- function applyGlyphToLegendItem(baseItem, withGlyph, glyph, renderGlyph, glyphSize) {
986
- if (withGlyph) {
987
- const glyphToUse = glyph || renderGlyph;
988
- if (glyphToUse) {
989
- return {
990
- ...baseItem,
991
- glyphSize,
992
- renderGlyph: glyphToUse
993
- };
994
- }
995
- }
996
- return baseItem;
997
- }
998
- function processSeriesData(seriesData, getElementStyles, showValues, withGlyph, glyphSize, renderGlyph, legendShape) {
999
- const mapper = (series, index) => {
1000
- const { color, glyph, shapeStyles } = getElementStyles({
1001
- data: series,
1002
- index,
1003
- legendShape
1004
- });
1005
- const baseItem = {
1006
- label: series.label,
1007
- value: showValues ? _optionalChain([series, 'access', _73 => _73.data, 'optionalAccess', _74 => _74.length, 'optionalAccess', _75 => _75.toString, 'call', _76 => _76()]) || "0" : "",
1008
- color,
1009
- shapeStyle: shapeStyles
1010
- };
1011
- return applyGlyphToLegendItem(baseItem, withGlyph, glyph, renderGlyph, glyphSize);
1012
- };
1013
- return seriesData.map(mapper);
1014
- }
1015
- function processPointData(pointData, getElementStyles, showValues, legendValueDisplay, withGlyph, glyphSize, renderGlyph, legendShape) {
1016
- const mapper = (point, index) => {
1017
- const { color, glyph, shapeStyles } = getElementStyles({
1018
- data: point,
1019
- index,
1020
- legendShape
1021
- });
1022
- const baseItem = {
1023
- label: point.label,
1024
- value: formatPointValue(point, showValues, legendValueDisplay),
1025
- color,
1026
- shapeStyle: shapeStyles
1027
- };
1028
- return applyGlyphToLegendItem(baseItem, withGlyph, glyph, renderGlyph, glyphSize);
1029
- };
1030
- return pointData.map(mapper);
1031
- }
1032
- function useChartLegendItems(data, options = {}, legendShape) {
1033
- const {
1034
- showValues = false,
1035
- legendValueDisplay = "percentage",
1036
- withGlyph = false,
1037
- glyphSize = 8,
1038
- renderGlyph
1039
- } = options;
1040
- const { getElementStyles } = useGlobalChartsContext();
1041
- return _react.useMemo.call(void 0, () => {
1042
- if (!data || !Array.isArray(data) || data.length === 0) {
1043
- return [];
1044
- }
1045
- if ("data" in data[0]) {
1046
- return processSeriesData(
1047
- data,
1048
- getElementStyles,
1049
- showValues,
1050
- withGlyph,
1051
- glyphSize,
1052
- renderGlyph,
1053
- legendShape
1054
- );
1055
- }
1056
- return processPointData(
1057
- data,
1058
- getElementStyles,
1059
- showValues,
1060
- legendValueDisplay,
1061
- withGlyph,
1062
- glyphSize,
1063
- renderGlyph,
1064
- legendShape
1065
- );
1066
- }, [
1067
- data,
1068
- getElementStyles,
1069
- showValues,
1070
- legendValueDisplay,
1071
- withGlyph,
1072
- glyphSize,
1073
- renderGlyph,
1074
- legendShape
1075
- ]);
1076
- }
1077
-
1078
- // src/hooks/use-has-legend-child.ts
1079
- function useHasLegendChild(children) {
1080
- return _react.useMemo.call(void 0, () => {
1081
- let found = false;
1082
- _react.Children.forEach(children, (child) => {
1083
- if (_react.isValidElement.call(void 0, child) && child.type === Legend) {
1084
- found = true;
1085
- }
1086
- });
1087
- return found;
1088
- }, [children]);
1089
- }
1090
-
1091
736
  // src/hooks/use-text-truncation.ts
1092
737
 
1093
738
  function useTextTruncation(enabled = true) {
@@ -1119,25 +764,28 @@ function useTextTruncation(enabled = true) {
1119
764
 
1120
765
  // src/hooks/use-zero-value-display.ts
1121
766
 
767
+ var MIN_PIXEL_SIZE = 3;
768
+ var ZERO_PIXEL_SIZE = MIN_PIXEL_SIZE - 1;
1122
769
  var useZeroValueDisplay = (data, options = { enabled: false }) => {
1123
- const { enabled, minValueRatio = 0.6, maxValueRatio = 8e-3 } = options;
770
+ const { enabled, valueAxisLength } = options;
1124
771
  return _react.useMemo.call(void 0, () => {
1125
- if (!enabled) return data;
1126
- const nonZeroValues = [];
772
+ if (!enabled || !valueAxisLength || valueAxisLength <= 0) return data;
773
+ let maxAbsoluteValue = 0;
1127
774
  for (const series of data) {
1128
775
  for (const point of series.data) {
1129
776
  if (point.value !== null && point.value !== 0) {
1130
- nonZeroValues.push(point.value);
777
+ maxAbsoluteValue = Math.max(maxAbsoluteValue, Math.abs(point.value));
1131
778
  }
1132
779
  }
1133
780
  }
1134
- if (nonZeroValues.length === 0) return data;
1135
- const absoluteValues = nonZeroValues.map(Math.abs);
1136
- const minAbsoluteValue = Math.min(...absoluteValues);
1137
- const maxAbsoluteValue = Math.max(...absoluteValues);
1138
- const minVisibleValue = Math.min(
1139
- minAbsoluteValue * minValueRatio,
1140
- maxAbsoluteValue * maxValueRatio
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
1141
789
  );
1142
790
  return data.map((series) => ({
1143
791
  ...series,
@@ -1145,13 +793,23 @@ var useZeroValueDisplay = (data, options = { enabled: false }) => {
1145
793
  if (point.value === 0) {
1146
794
  return {
1147
795
  ...point,
1148
- visualValue: minVisibleValue
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
1149
807
  };
1150
808
  }
1151
809
  return point;
1152
810
  })
1153
811
  }));
1154
- }, [data, enabled, minValueRatio, maxValueRatio]);
812
+ }, [data, enabled, valueAxisLength]);
1155
813
  };
1156
814
 
1157
815
  // src/hooks/use-interactive-legend-data.ts
@@ -1233,10 +891,5 @@ function usePrefersReducedMotion() {
1233
891
 
1234
892
 
1235
893
 
1236
-
1237
-
1238
-
1239
-
1240
-
1241
- exports.SingleChartContext = SingleChartContext; exports.useSingleChartContext = useSingleChartContext; exports.useTooltipPortalRelocator = useTooltipPortalRelocator; exports.defaultTheme = defaultTheme; exports.GlobalChartsContext = GlobalChartsContext; exports.GlobalChartsProvider = GlobalChartsProvider; exports.useGlobalChartsContext = useGlobalChartsContext; exports.useChartId = useChartId; exports.useDeepMemo = useDeepMemo; exports.useChartMouseHandler = useChartMouseHandler; exports.useXYChartTheme = useXYChartTheme; exports.useChartDataTransform = useChartDataTransform; exports.useChartMargin = useChartMargin; exports.useElementSize = useElementSize; exports.useHasLegendChild = useHasLegendChild; exports.useTextTruncation = useTextTruncation; exports.useZeroValueDisplay = useZeroValueDisplay; exports.useInteractiveLegendData = useInteractiveLegendData; exports.usePrefersReducedMotion = usePrefersReducedMotion; exports.useChartRegistration = useChartRegistration; exports.useGlobalChartsTheme = useGlobalChartsTheme; exports.Legend = Legend; exports.useChartLegendItems = useChartLegendItems;
1242
- //# sourceMappingURL=chunk-YDVHT7GS.cjs.map
894
+ exports.useTooltipPortalRelocator = useTooltipPortalRelocator; exports.defaultTheme = defaultTheme; exports.GlobalChartsContext = GlobalChartsContext; exports.GlobalChartsProvider = GlobalChartsProvider; exports.useGlobalChartsContext = useGlobalChartsContext; exports.useChartId = useChartId; exports.useDeepMemo = useDeepMemo; exports.useChartMouseHandler = useChartMouseHandler; exports.useXYChartTheme = useXYChartTheme; exports.useChartDataTransform = useChartDataTransform; exports.useChartMargin = useChartMargin; exports.useElementSize = useElementSize; exports.useTextTruncation = useTextTruncation; exports.useZeroValueDisplay = useZeroValueDisplay; exports.useInteractiveLegendData = useInteractiveLegendData; exports.usePrefersReducedMotion = usePrefersReducedMotion; exports.useChartRegistration = useChartRegistration; exports.useGlobalChartsTheme = useGlobalChartsTheme;
895
+ //# sourceMappingURL=chunk-WYK7EL5R.cjs.map