@automattic/charts 0.56.3 → 0.56.4

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 (184) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/charts/bar-chart/index.cjs +5 -5
  3. package/dist/charts/bar-chart/index.css +12 -0
  4. package/dist/charts/bar-chart/index.css.map +1 -1
  5. package/dist/charts/bar-chart/index.js +4 -4
  6. package/dist/charts/bar-list-chart/index.cjs +6 -6
  7. package/dist/charts/bar-list-chart/index.css +12 -0
  8. package/dist/charts/bar-list-chart/index.css.map +1 -1
  9. package/dist/charts/bar-list-chart/index.js +5 -5
  10. package/dist/charts/conversion-funnel-chart/index.cjs +5 -3
  11. package/dist/charts/conversion-funnel-chart/index.cjs.map +1 -1
  12. package/dist/charts/conversion-funnel-chart/index.css +14 -1
  13. package/dist/charts/conversion-funnel-chart/index.css.map +1 -1
  14. package/dist/charts/conversion-funnel-chart/index.d.cts +2 -0
  15. package/dist/charts/conversion-funnel-chart/index.d.ts +2 -0
  16. package/dist/charts/conversion-funnel-chart/index.js +4 -2
  17. package/dist/charts/geo-chart/index.cjs +4 -4
  18. package/dist/charts/geo-chart/index.css +12 -0
  19. package/dist/charts/geo-chart/index.css.map +1 -1
  20. package/dist/charts/geo-chart/index.js +3 -3
  21. package/dist/charts/leaderboard-chart/index.cjs +5 -5
  22. package/dist/charts/leaderboard-chart/index.css +12 -0
  23. package/dist/charts/leaderboard-chart/index.css.map +1 -1
  24. package/dist/charts/leaderboard-chart/index.js +4 -4
  25. package/dist/charts/line-chart/index.cjs +5 -5
  26. package/dist/charts/line-chart/index.css +12 -0
  27. package/dist/charts/line-chart/index.css.map +1 -1
  28. package/dist/charts/line-chart/index.js +4 -4
  29. package/dist/charts/pie-chart/index.cjs +7 -7
  30. package/dist/charts/pie-chart/index.css +12 -0
  31. package/dist/charts/pie-chart/index.css.map +1 -1
  32. package/dist/charts/pie-chart/index.js +6 -6
  33. package/dist/charts/pie-semi-circle-chart/index.cjs +7 -7
  34. package/dist/charts/pie-semi-circle-chart/index.css +12 -0
  35. package/dist/charts/pie-semi-circle-chart/index.css.map +1 -1
  36. package/dist/charts/pie-semi-circle-chart/index.js +6 -6
  37. package/dist/charts/sparkline/index.cjs +6 -6
  38. package/dist/charts/sparkline/index.css +12 -0
  39. package/dist/charts/sparkline/index.css.map +1 -1
  40. package/dist/charts/sparkline/index.js +5 -5
  41. package/dist/{chunk-OTZT3MC2.cjs → chunk-2A34OA5O.cjs} +19 -20
  42. package/dist/chunk-2A34OA5O.cjs.map +1 -0
  43. package/dist/chunk-4YYROZDJ.cjs +375 -0
  44. package/dist/chunk-4YYROZDJ.cjs.map +1 -0
  45. package/dist/{chunk-YYQ4IK5V.cjs → chunk-5N77S5N3.cjs} +103 -80
  46. package/dist/chunk-5N77S5N3.cjs.map +1 -0
  47. package/dist/chunk-66BXSWMW.cjs +1065 -0
  48. package/dist/chunk-66BXSWMW.cjs.map +1 -0
  49. package/dist/{chunk-CEZGL6YP.js → chunk-6CCZL2JJ.js} +15 -7
  50. package/dist/chunk-6CCZL2JJ.js.map +1 -0
  51. package/dist/{chunk-NW3RUYK2.cjs → chunk-7QDEU3KN.cjs} +15 -22
  52. package/dist/chunk-7QDEU3KN.cjs.map +1 -0
  53. package/dist/{chunk-H34CJSR6.js → chunk-AWNCAKZY.js} +367 -358
  54. package/dist/chunk-AWNCAKZY.js.map +1 -0
  55. package/dist/{chunk-5XI443YP.js → chunk-BPYKWMI7.js} +72 -64
  56. package/dist/chunk-BPYKWMI7.js.map +1 -0
  57. package/dist/{chunk-7UJPVCMB.cjs → chunk-CERFRCXD.cjs} +265 -262
  58. package/dist/chunk-CERFRCXD.cjs.map +1 -0
  59. package/dist/chunk-CMHPXSCI.js +351 -0
  60. package/dist/chunk-CMHPXSCI.js.map +1 -0
  61. package/dist/chunk-EBDUXL5K.js +421 -0
  62. package/dist/chunk-EBDUXL5K.js.map +1 -0
  63. package/dist/{chunk-2VPPTJS2.js → chunk-FZYJM5PN.js} +256 -253
  64. package/dist/chunk-FZYJM5PN.js.map +1 -0
  65. package/dist/chunk-GBDFC74U.cjs +165 -0
  66. package/dist/chunk-GBDFC74U.cjs.map +1 -0
  67. package/dist/{chunk-ODF5O5PV.cjs → chunk-HNEG3EFJ.cjs} +154 -170
  68. package/dist/chunk-HNEG3EFJ.cjs.map +1 -0
  69. package/dist/{chunk-SRXJLAKG.cjs → chunk-I2276W3I.cjs} +28 -37
  70. package/dist/chunk-I2276W3I.cjs.map +1 -0
  71. package/dist/chunk-KKPZ4MVF.js +375 -0
  72. package/dist/chunk-KKPZ4MVF.js.map +1 -0
  73. package/dist/chunk-KMYJJTSR.cjs +421 -0
  74. package/dist/chunk-KMYJJTSR.cjs.map +1 -0
  75. package/dist/{chunk-A3AEEGKR.js → chunk-KXRWNFQJ.js} +20 -21
  76. package/dist/chunk-KXRWNFQJ.js.map +1 -0
  77. package/dist/{chunk-TVV7ZI7C.cjs → chunk-LSV7F26B.cjs} +362 -353
  78. package/dist/chunk-LSV7F26B.cjs.map +1 -0
  79. package/dist/{chunk-T4J6TI55.js → chunk-M7PRGJFE.js} +102 -79
  80. package/dist/chunk-M7PRGJFE.js.map +1 -0
  81. package/dist/{chunk-TNRKEBTA.js → chunk-PGJAZN2H.js} +148 -164
  82. package/dist/{chunk-TNRKEBTA.js.map → chunk-PGJAZN2H.js.map} +1 -1
  83. package/dist/chunk-R23BFDIW.js +1065 -0
  84. package/dist/chunk-R23BFDIW.js.map +1 -0
  85. package/dist/{chunk-HIWNB5PK.cjs → chunk-RCY6XLGU.cjs} +13 -5
  86. package/dist/chunk-RCY6XLGU.cjs.map +1 -0
  87. package/dist/chunk-RSYD434G.cjs +351 -0
  88. package/dist/chunk-RSYD434G.cjs.map +1 -0
  89. package/dist/{chunk-C33AQZEC.js → chunk-TYIH5LMV.js} +16 -23
  90. package/dist/chunk-TYIH5LMV.js.map +1 -0
  91. package/dist/chunk-WMWAUOQ4.js +165 -0
  92. package/dist/chunk-WMWAUOQ4.js.map +1 -0
  93. package/dist/chunk-XWYZIFZW.js +66 -0
  94. package/dist/chunk-XWYZIFZW.js.map +1 -0
  95. package/dist/{chunk-7HROSZRS.cjs → chunk-Y3NNQMAX.cjs} +70 -62
  96. package/dist/chunk-Y3NNQMAX.cjs.map +1 -0
  97. package/dist/chunk-ZXEFMKVP.cjs +120 -0
  98. package/dist/chunk-ZXEFMKVP.cjs.map +1 -0
  99. package/dist/chunk-ZY4FXLMM.js +120 -0
  100. package/dist/chunk-ZY4FXLMM.js.map +1 -0
  101. package/dist/components/legend/index.cjs +2 -2
  102. package/dist/components/legend/index.css +12 -0
  103. package/dist/components/legend/index.css.map +1 -1
  104. package/dist/components/legend/index.js +1 -1
  105. package/dist/components/tooltip/index.cjs +2 -2
  106. package/dist/components/tooltip/index.js +1 -1
  107. package/dist/components/trend-indicator/index.cjs +2 -2
  108. package/dist/components/trend-indicator/index.js +1 -1
  109. package/dist/hooks/index.cjs +4 -2
  110. package/dist/hooks/index.cjs.map +1 -1
  111. package/dist/hooks/index.css +12 -0
  112. package/dist/hooks/index.css.map +1 -1
  113. package/dist/hooks/index.d.cts +28 -2
  114. package/dist/hooks/index.d.ts +28 -2
  115. package/dist/hooks/index.js +3 -1
  116. package/dist/index.cjs +18 -18
  117. package/dist/index.cjs.map +1 -1
  118. package/dist/index.css +14 -1
  119. package/dist/index.css.map +1 -1
  120. package/dist/index.d.cts +1 -1
  121. package/dist/index.d.ts +1 -1
  122. package/dist/index.js +17 -17
  123. package/dist/providers/index.cjs +2 -2
  124. package/dist/providers/index.css +12 -0
  125. package/dist/providers/index.css.map +1 -1
  126. package/dist/providers/index.d.cts +1 -1
  127. package/dist/providers/index.d.ts +1 -1
  128. package/dist/providers/index.js +1 -1
  129. package/dist/{themes-DQs9rbN5.d.cts → themes-BDVaIfBz.d.cts} +9 -0
  130. package/dist/{themes-CRV5fVzJ.d.ts → themes-mcS8QNkQ.d.ts} +9 -0
  131. package/package.json +5 -1
  132. package/src/charts/conversion-funnel-chart/conversion-funnel-chart.module.scss +2 -1
  133. package/src/charts/conversion-funnel-chart/conversion-funnel-chart.tsx +16 -6
  134. package/src/charts/conversion-funnel-chart/test/conversion-funnel-chart.test.tsx +34 -0
  135. package/src/charts/conversion-funnel-chart/types.ts +2 -0
  136. package/src/charts/pie-chart/pie-chart.tsx +2 -3
  137. package/src/hooks/index.ts +1 -0
  138. package/src/hooks/test/use-tooltip-portal-relocator.test.ts +216 -0
  139. package/src/hooks/use-tooltip-portal-relocator.module.scss +10 -0
  140. package/src/hooks/use-tooltip-portal-relocator.ts +177 -0
  141. package/src/providers/chart-context/global-charts-provider.tsx +18 -1
  142. package/tsup.config.ts +11 -0
  143. package/dist/chunk-2VPPTJS2.js.map +0 -1
  144. package/dist/chunk-5XI443YP.js.map +0 -1
  145. package/dist/chunk-7HROSZRS.cjs.map +0 -1
  146. package/dist/chunk-7UJPVCMB.cjs.map +0 -1
  147. package/dist/chunk-A3AEEGKR.js.map +0 -1
  148. package/dist/chunk-C33AQZEC.js.map +0 -1
  149. package/dist/chunk-CEZGL6YP.js.map +0 -1
  150. package/dist/chunk-COOC2TVQ.js +0 -167
  151. package/dist/chunk-COOC2TVQ.js.map +0 -1
  152. package/dist/chunk-EJHLLXBV.js +0 -362
  153. package/dist/chunk-EJHLLXBV.js.map +0 -1
  154. package/dist/chunk-FWMJ2FR2.js +0 -121
  155. package/dist/chunk-FWMJ2FR2.js.map +0 -1
  156. package/dist/chunk-GRYNIPWH.cjs +0 -385
  157. package/dist/chunk-GRYNIPWH.cjs.map +0 -1
  158. package/dist/chunk-H34CJSR6.js.map +0 -1
  159. package/dist/chunk-HIWNB5PK.cjs.map +0 -1
  160. package/dist/chunk-IZWC33YN.cjs +0 -357
  161. package/dist/chunk-IZWC33YN.cjs.map +0 -1
  162. package/dist/chunk-KOF32DBL.cjs +0 -1058
  163. package/dist/chunk-KOF32DBL.cjs.map +0 -1
  164. package/dist/chunk-LHWRZMF7.cjs +0 -362
  165. package/dist/chunk-LHWRZMF7.cjs.map +0 -1
  166. package/dist/chunk-MFRS2PEY.cjs +0 -121
  167. package/dist/chunk-MFRS2PEY.cjs.map +0 -1
  168. package/dist/chunk-MMDLXS6O.js +0 -75
  169. package/dist/chunk-MMDLXS6O.js.map +0 -1
  170. package/dist/chunk-NW3RUYK2.cjs.map +0 -1
  171. package/dist/chunk-ODF5O5PV.cjs.map +0 -1
  172. package/dist/chunk-OTZT3MC2.cjs.map +0 -1
  173. package/dist/chunk-SBRMWDWM.js +0 -357
  174. package/dist/chunk-SBRMWDWM.js.map +0 -1
  175. package/dist/chunk-SRXJLAKG.cjs.map +0 -1
  176. package/dist/chunk-T4J6TI55.js.map +0 -1
  177. package/dist/chunk-TVV7ZI7C.cjs.map +0 -1
  178. package/dist/chunk-XVMXWV3C.cjs +0 -167
  179. package/dist/chunk-XVMXWV3C.cjs.map +0 -1
  180. package/dist/chunk-YYQ4IK5V.cjs.map +0 -1
  181. package/dist/chunk-ZDNCF642.js +0 -1058
  182. package/dist/chunk-ZDNCF642.js.map +0 -1
  183. package/dist/chunk-ZWBUEHKF.js +0 -385
  184. package/dist/chunk-ZWBUEHKF.js.map +0 -1
@@ -1,1058 +0,0 @@
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; }
2
-
3
- var _chunkSH32YSZOcjs = require('./chunk-SH32YSZO.cjs');
4
-
5
-
6
-
7
- var _chunk7HROSZRScjs = require('./chunk-7HROSZRS.cjs');
8
-
9
-
10
- var _chunkNW3RUYK2cjs = require('./chunk-NW3RUYK2.cjs');
11
-
12
-
13
-
14
-
15
-
16
-
17
-
18
-
19
-
20
-
21
-
22
-
23
-
24
-
25
-
26
-
27
-
28
- var _chunkTVV7ZI7Ccjs = require('./chunk-TVV7ZI7C.cjs');
29
-
30
-
31
-
32
- var _chunkZVGEDXDPcjs = require('./chunk-ZVGEDXDP.cjs');
33
-
34
- // src/charts/line-chart/line-chart.tsx
35
- var _numberformatters = require('@automattic/number-formatters');
36
- var _curve = require('@visx/curve');
37
- var _gradient = require('@visx/gradient');
38
- var _scale = require('@visx/scale');
39
- var _xychart = require('@visx/xychart');
40
- var _i18n = require('@wordpress/i18n');
41
- var _clsx = require('clsx'); var _clsx2 = _interopRequireDefault(_clsx);
42
- var _datefns = require('date-fns');
43
- var _react = require('react');
44
-
45
- // src/charts/private/default-glyph/default-glyph.tsx
46
-
47
-
48
- var _jsxruntime = require('react/jsx-runtime');
49
- var DefaultGlyph = (props) => {
50
- const { theme } = _react.useContext.call(void 0, _xychart.DataContext) || {};
51
- const position = props.position || "start";
52
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
53
- "circle",
54
- {
55
- cx: props.x,
56
- cy: props.y,
57
- r: props.size,
58
- fill: props.color,
59
- stroke: _optionalChain([theme, 'optionalAccess', _ => _.backgroundColor]),
60
- strokeWidth: 1.5,
61
- paintOrder: "fill",
62
- "data-testid": `${position}-glyph-${props.index}`,
63
- ...props.glyphStyle
64
- }
65
- );
66
- };
67
-
68
- // src/charts/line-chart/line-chart.module.scss
69
- var line_chart_module_default = {
70
- "line-chart": "a8ccharts-v-oO8E",
71
- "line-chart__svg-wrapper": "a8ccharts-cpMNjj",
72
- "line-chart--animated": "a8ccharts-QrkuTW",
73
- "rise": "a8ccharts--rxDU3",
74
- "line-chart__tooltip": "a8ccharts-Tu0rR-",
75
- "line-chart__annotation-label-popover": "a8ccharts--RSWXi",
76
- "line-chart__tooltip-date": "a8ccharts-Q-b5A1",
77
- "line-chart__tooltip-row": "a8ccharts-19N7T9",
78
- "line-chart__tooltip-label": "a8ccharts-HOAXrD",
79
- "line-chart__annotations-overlay": "a8ccharts-rQiY8O",
80
- "line-chart__annotation-label": "a8ccharts-8AKWOe",
81
- "line-chart__annotation-label-trigger-button": "a8ccharts-7mh3Cl",
82
- "line-chart__annotation-label-popover--visible": "a8ccharts-VAeVuJ",
83
- "line-chart__annotation-label-popover--safari": "a8ccharts-TEe-iV",
84
- "line-chart__annotation-label-popover-header": "a8ccharts-LAUpx7",
85
- "line-chart__annotation-label-popover-content": "a8ccharts-b76gEu",
86
- "line-chart__annotation-label-popover-close-button": "a8ccharts-LIpFoS"
87
- };
88
-
89
- // src/charts/line-chart/private/line-chart-annotation-label-popover.tsx
90
-
91
-
92
- var _gridicons = require('gridicons'); var _gridicons2 = _interopRequireDefault(_gridicons);
93
-
94
-
95
- var POPOVER_BUTTON_SIZE = 44;
96
- var LineChartAnnotationLabelWithPopover = ({
97
- title,
98
- subtitle,
99
- renderLabel,
100
- renderLabelPopover
101
- }) => {
102
- const popoverId = _react.useId.call(void 0, );
103
- const buttonRef = _react.useRef.call(void 0, null);
104
- const popoverRef = _react.useRef.call(void 0, null);
105
- const [isPositioned, setIsPositioned] = _react.useState.call(void 0, false);
106
- const isBrowserSafari = _chunkZVGEDXDPcjs.isSafari.call(void 0, );
107
- _react.useEffect.call(void 0, () => {
108
- const button = buttonRef.current;
109
- const popover = popoverRef.current;
110
- if (!button || !popover) return;
111
- const positionPopover = () => {
112
- if (!isBrowserSafari) {
113
- const buttonRect = button.getBoundingClientRect();
114
- popover.style.left = `${buttonRect.right}px`;
115
- popover.style.top = `${buttonRect.top}px`;
116
- }
117
- setIsPositioned(true);
118
- };
119
- popover.addEventListener("toggle", (e) => {
120
- if (e.newState === "open") {
121
- positionPopover();
122
- }
123
- });
124
- try {
125
- if (popover.matches(":popover-open")) {
126
- positionPopover();
127
- }
128
- } catch (e2) {
129
- }
130
- }, [isBrowserSafari]);
131
- return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: line_chart_module_default["line-chart__annotation-label"], children: [
132
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
133
- "button",
134
- {
135
- ref: buttonRef,
136
- ...{ popovertarget: popoverId },
137
- className: line_chart_module_default["line-chart__annotation-label-trigger-button"],
138
- style: {
139
- width: `${POPOVER_BUTTON_SIZE}px`,
140
- height: `${POPOVER_BUTTON_SIZE}px`,
141
- transform: `translate(${POPOVER_BUTTON_SIZE / 2}px, 0)`
142
- },
143
- "aria-label": title || _i18n.__.call(void 0, "View details", "jetpack-charts"),
144
- children: renderLabel({ title, subtitle })
145
- }
146
- ),
147
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
148
- "div",
149
- {
150
- ref: popoverRef,
151
- id: popoverId,
152
- ...{ popover: "auto" },
153
- className: _clsx2.default.call(void 0,
154
- line_chart_module_default["line-chart__annotation-label-popover"],
155
- isPositioned && line_chart_module_default["line-chart__annotation-label-popover--visible"],
156
- isBrowserSafari && line_chart_module_default["line-chart__annotation-label-popover--safari"]
157
- ),
158
- "data-testid": "line-chart-annotation-label-popover",
159
- children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: line_chart_module_default["line-chart__annotation-label-popover-header"], children: [
160
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: line_chart_module_default["line-chart__annotation-label-popover-content"], children: renderLabelPopover({ title, subtitle }) }),
161
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
162
- "button",
163
- {
164
- ...{
165
- popovertarget: popoverId,
166
- popovertargetaction: "hide"
167
- },
168
- className: line_chart_module_default["line-chart__annotation-label-popover-close-button"],
169
- "aria-label": _i18n.__.call(void 0, "Close", "jetpack-charts"),
170
- children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _gridicons2.default, { icon: "cross", size: 16 })
171
- }
172
- )
173
- ] })
174
- }
175
- )
176
- ] });
177
- };
178
- var line_chart_annotation_label_popover_default = LineChartAnnotationLabelWithPopover;
179
-
180
- // src/charts/line-chart/private/line-chart-annotations-overlay.tsx
181
-
182
-
183
-
184
- var LineChartAnnotationsOverlay = ({ children }) => {
185
- const { chartRef, chartWidth, chartHeight } = _chunkTVV7ZI7Ccjs.useSingleChartContext.call(void 0, );
186
- const [scales, setScales] = _react.useState.call(void 0, null);
187
- const [scalesStable, setScalesStable] = _react.useState.call(void 0, false);
188
- const createScaleSignature = _react.useCallback.call(void 0, (scaleData) => {
189
- const xDomain = scaleData.xScale.domain();
190
- const yDomain = scaleData.yScale.domain();
191
- const xRange = scaleData.xScale.range();
192
- const yRange = scaleData.yScale.range();
193
- return `${xDomain.join(",")}-${yDomain.join(",")}-${xRange.join(
194
- ","
195
- )}-${yRange.join(",")}`;
196
- }, []);
197
- const getScalesData = _react.useCallback.call(void 0, () => {
198
- if (_optionalChain([chartRef, 'optionalAccess', _2 => _2.current])) {
199
- const scaleData = chartRef.current.getScales();
200
- if (scaleData) {
201
- const scaleInfo = {
202
- xScale: scaleData.xScale,
203
- yScale: scaleData.yScale
204
- };
205
- return {
206
- scales: scaleInfo,
207
- signature: createScaleSignature(scaleInfo)
208
- };
209
- }
210
- }
211
- return null;
212
- }, [chartRef, createScaleSignature]);
213
- _react.useEffect.call(void 0, () => {
214
- let timeoutId = null;
215
- let lastSignature = null;
216
- let retryCount = 0;
217
- const maxRetries = 20;
218
- const checkInterval = 50;
219
- setScalesStable(false);
220
- const monitorScales = () => {
221
- const currentScaleData = getScalesData();
222
- if (currentScaleData) {
223
- const scalesSettled = lastSignature && currentScaleData.signature === lastSignature;
224
- if (scalesSettled) {
225
- setScalesStable(true);
226
- return;
227
- }
228
- setScales(currentScaleData.scales);
229
- lastSignature = currentScaleData.signature;
230
- }
231
- if (retryCount < maxRetries) {
232
- retryCount++;
233
- timeoutId = setTimeout(monitorScales, checkInterval);
234
- }
235
- };
236
- monitorScales();
237
- return () => {
238
- if (timeoutId) {
239
- clearTimeout(timeoutId);
240
- }
241
- };
242
- }, [getScalesData, chartWidth, chartHeight]);
243
- if (!chartRef || !children) {
244
- return null;
245
- }
246
- if (!scales || !scalesStable) {
247
- return null;
248
- }
249
- const dataContextValue = {
250
- xScale: scales.xScale,
251
- yScale: scales.yScale,
252
- margin: { top: 0, right: 0, bottom: 0, left: 0 },
253
- width: chartWidth,
254
- height: chartHeight
255
- };
256
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _xychart.DataContext.Provider, { value: dataContextValue, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
257
- "svg",
258
- {
259
- width: chartWidth,
260
- height: chartHeight,
261
- className: line_chart_module_default["line-chart__annotations-overlay"],
262
- "data-testid": "line-chart-annotations-overlay",
263
- children
264
- }
265
- ) });
266
- };
267
- var line_chart_annotations_overlay_default = LineChartAnnotationsOverlay;
268
-
269
- // src/charts/line-chart/private/line-chart-annotation.tsx
270
-
271
-
272
-
273
-
274
-
275
-
276
-
277
- var _annotation = require('@visx/annotation');
278
-
279
- var _deepmerge = require('deepmerge'); var _deepmerge2 = _interopRequireDefault(_deepmerge);
280
-
281
-
282
- var ANNOTATION_MAX_WIDTH = 125;
283
- var ANNOTATION_INIT_HEIGHT = 100;
284
- var getLabelPosition = ({
285
- subjectType,
286
- x,
287
- xMax,
288
- y,
289
- yMin,
290
- yMax,
291
- maxWidth,
292
- height
293
- }) => {
294
- const annotationMaxWidth = _nullishCoalesce(maxWidth, () => ( ANNOTATION_MAX_WIDTH));
295
- const annotationHeight = _nullishCoalesce(height, () => ( ANNOTATION_INIT_HEIGHT));
296
- let dx = 15;
297
- let dy = 15;
298
- let isFlippedHorizontally = false;
299
- let isFlippedVertically = false;
300
- if (subjectType === "line-horizontal") {
301
- dx = 0;
302
- dy = 20;
303
- }
304
- if (subjectType === "line-vertical") {
305
- dx = 20;
306
- dy = 0;
307
- }
308
- const effectiveX = x + dx;
309
- if (effectiveX + annotationMaxWidth > xMax) {
310
- isFlippedHorizontally = true;
311
- if (subjectType === "circle") {
312
- dx = -dx;
313
- } else if (subjectType === "line-vertical") {
314
- dx = -20;
315
- }
316
- }
317
- if (subjectType === "circle") {
318
- if (y + dy + annotationHeight > yMin) {
319
- isFlippedVertically = true;
320
- dy = -Math.abs(dy);
321
- }
322
- } else if (y - annotationHeight < yMax) {
323
- if (subjectType === "line-horizontal") {
324
- isFlippedVertically = true;
325
- dy = Math.abs(dy);
326
- } else if (subjectType === "line-vertical") {
327
- isFlippedVertically = true;
328
- }
329
- } else if (y + annotationHeight > yMin) {
330
- if (subjectType === "line-horizontal") {
331
- isFlippedVertically = true;
332
- dy = -Math.abs(dy);
333
- } else if (subjectType === "line-vertical") {
334
- isFlippedVertically = true;
335
- }
336
- }
337
- return { dx, dy, isFlippedHorizontally, isFlippedVertically };
338
- };
339
- var getHorizontalAnchor = (subjectType, isFlippedHorizontally) => {
340
- if (subjectType === "line-horizontal") {
341
- return isFlippedHorizontally ? "end" : "start";
342
- }
343
- return void 0;
344
- };
345
- var getVerticalAnchor = (subjectType, isFlippedVertically, y, yMax, height) => {
346
- if (subjectType === "line-vertical") {
347
- if (isFlippedVertically) {
348
- return y - height < yMax ? "start" : "end";
349
- }
350
- return "start";
351
- }
352
- return void 0;
353
- };
354
- var LineChartAnnotation = ({
355
- datum,
356
- title,
357
- subtitle,
358
- subjectType = "circle",
359
- styles: datumStyles,
360
- testId,
361
- renderLabel,
362
- renderLabelPopover
363
- }) => {
364
- const providerTheme = _chunkTVV7ZI7Ccjs.useGlobalChartsTheme.call(void 0, );
365
- const { xScale, yScale } = _react.useContext.call(void 0, _xychart.DataContext) || {};
366
- const labelRef = _react.useRef.call(void 0, null);
367
- const [height, setHeight] = _react.useState.call(void 0, null);
368
- const styles = _deepmerge2.default.call(void 0, _nullishCoalesce(providerTheme.annotationStyles, () => ( {})), _nullishCoalesce(datumStyles, () => ( {})));
369
- _react.useEffect.call(void 0, () => {
370
- if (_optionalChain([labelRef, 'access', _3 => _3.current, 'optionalAccess', _4 => _4.getBBox])) {
371
- const bbox = labelRef.current.getBBox();
372
- setHeight(bbox.height);
373
- }
374
- }, []);
375
- const positionData = _react.useMemo.call(void 0, () => {
376
- if (!datum || !datum.date || datum.value == null || !xScale || !yScale) return null;
377
- const x2 = xScale(datum.date);
378
- const y2 = yScale(datum.value);
379
- if (typeof x2 !== "number" || typeof y2 !== "number") return null;
380
- const [yMin2, yMax2] = yScale.range().map(Number);
381
- const [xMin2, xMax2] = xScale.range().map(Number);
382
- if (renderLabel) {
383
- return {
384
- x: x2,
385
- dx: 0,
386
- y: y2,
387
- dy: 0,
388
- yMin: yMin2,
389
- yMax: yMax2,
390
- xMin: xMin2,
391
- xMax: xMax2,
392
- isFlippedHorizontally: false,
393
- isFlippedVertically: false
394
- };
395
- }
396
- const position = getLabelPosition({
397
- subjectType,
398
- x: x2,
399
- xMax: xMax2,
400
- y: y2,
401
- yMin: yMin2,
402
- yMax: yMax2,
403
- maxWidth: _optionalChain([styles, 'optionalAccess', _5 => _5.label, 'optionalAccess', _6 => _6.maxWidth]),
404
- height
405
- });
406
- return { x: x2, y: y2, yMin: yMin2, yMax: yMax2, xMin: xMin2, xMax: xMax2, ...position };
407
- }, [datum, xScale, yScale, subjectType, _optionalChain([styles, 'optionalAccess', _7 => _7.label, 'optionalAccess', _8 => _8.maxWidth]), height, renderLabel]);
408
- if (!positionData) return null;
409
- const { x, y, yMin, yMax, xMin, xMax, dx, dy, isFlippedHorizontally, isFlippedVertically } = positionData;
410
- const getLabelY = () => {
411
- const labelY = _optionalChain([styles, 'optionalAccess', _9 => _9.label, 'optionalAccess', _10 => _10.y]);
412
- if (labelY === "start") return yMax;
413
- if (labelY === "end") return yMin;
414
- return labelY;
415
- };
416
- const getLabelX = () => {
417
- const labelX = _optionalChain([styles, 'optionalAccess', _11 => _11.label, 'optionalAccess', _12 => _12.x]);
418
- if (labelX === "start") return xMin;
419
- if (labelX === "end") return xMax;
420
- return labelX;
421
- };
422
- const labelPosition = {
423
- x: getLabelX(),
424
- y: getLabelY()
425
- };
426
- const getSafariHTMLLabelPosition = () => {
427
- const labelWidth = POPOVER_BUTTON_SIZE;
428
- const labelHeight = POPOVER_BUTTON_SIZE;
429
- return _chunkZVGEDXDPcjs.isSafari.call(void 0, ) ? {
430
- transform: `translate(${x + (dx || 0) + (typeof labelPosition.x === "number" ? labelPosition.x - x : 0) - labelWidth}px, ${y + (dy || 0) + (typeof labelPosition.y === "number" ? labelPosition.y - y : 0) - labelHeight}px)`,
431
- width: labelWidth,
432
- height: labelHeight
433
- } : void 0;
434
- };
435
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "g", { "data-testid": testId, children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _annotation.Annotation, { x, y, dx, dy, children: [
436
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _annotation.Connector, { ..._optionalChain([styles, 'optionalAccess', _13 => _13.connector]) }),
437
- subjectType === "circle" && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _annotation.CircleSubject, { ..._optionalChain([styles, 'optionalAccess', _14 => _14.circleSubject]) }),
438
- subjectType === "line-vertical" && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
439
- _annotation.LineSubject,
440
- {
441
- min: yMax,
442
- max: yMin,
443
- ...{ ..._optionalChain([styles, 'optionalAccess', _15 => _15.lineSubject]), orientation: "vertical" }
444
- }
445
- ),
446
- subjectType === "line-horizontal" && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
447
- _annotation.LineSubject,
448
- {
449
- min: xMin,
450
- max: xMax,
451
- ...{ ..._optionalChain([styles, 'optionalAccess', _16 => _16.lineSubject]), orientation: "horizontal" }
452
- }
453
- ),
454
- renderLabel ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _annotation.HtmlLabel, { ..._optionalChain([styles, 'optionalAccess', _17 => _17.label]), ...labelPosition, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { style: getSafariHTMLLabelPosition(), children: renderLabelPopover ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
455
- line_chart_annotation_label_popover_default,
456
- {
457
- title,
458
- subtitle,
459
- renderLabel,
460
- renderLabelPopover
461
- }
462
- ) : renderLabel({ title, subtitle }) }) }) : /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "g", { ref: labelRef, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
463
- _annotation.Label,
464
- {
465
- title,
466
- subtitle,
467
- ..._optionalChain([styles, 'optionalAccess', _18 => _18.label]),
468
- ...labelPosition,
469
- horizontalAnchor: getHorizontalAnchor(subjectType, isFlippedHorizontally),
470
- verticalAnchor: getVerticalAnchor(
471
- subjectType,
472
- isFlippedVertically,
473
- y,
474
- yMax,
475
- _nullishCoalesce(height, () => ( ANNOTATION_INIT_HEIGHT))
476
- )
477
- }
478
- ) })
479
- ] }) });
480
- };
481
- var line_chart_annotation_default = LineChartAnnotation;
482
-
483
- // src/charts/line-chart/private/line-chart-glyph.tsx
484
-
485
-
486
- var toNumber = (val) => {
487
- const num = typeof val === "number" ? val : parseFloat(val);
488
- return isNaN(num) ? void 0 : num;
489
- };
490
- var LineChartGlyph = ({
491
- data,
492
- index,
493
- color,
494
- glyphStyle,
495
- renderGlyph,
496
- accessors,
497
- position
498
- }) => {
499
- const { xScale, yScale } = _react.useContext.call(void 0, _xychart.DataContext) || {};
500
- if (!xScale || !yScale) return null;
501
- if (data.data.length === 0) return null;
502
- const point = position === "start" ? data.data[0] : data.data[data.data.length - 1];
503
- const x = xScale(accessors.xAccessor(point));
504
- const y = yScale(accessors.yAccessor(point));
505
- if (typeof x !== "number" || typeof y !== "number") return null;
506
- const size = Math.max(0, _nullishCoalesce(toNumber(_optionalChain([glyphStyle, 'optionalAccess', _19 => _19.radius])), () => ( 4)));
507
- return renderGlyph({
508
- key: `${position}-glyph-${data.label}`,
509
- index,
510
- datum: point,
511
- color,
512
- size,
513
- x,
514
- y,
515
- glyphStyle,
516
- position
517
- });
518
- };
519
- var line_chart_glyph_default = LineChartGlyph;
520
-
521
- // src/charts/line-chart/line-chart.tsx
522
-
523
-
524
- var X_TICK_WIDTH = 60;
525
- var defaultRenderGlyph = (props) => {
526
- return /* @__PURE__ */ _react.createElement.call(void 0, DefaultGlyph, { ...props, key: props.key });
527
- };
528
- var toNumber2 = (val) => {
529
- const num = typeof val === "number" ? val : parseFloat(val);
530
- return isNaN(num) ? void 0 : num;
531
- };
532
- var getCurveType = (type, smoothing) => {
533
- if (!type) {
534
- return smoothing ? _curve.curveCatmullRom : _curve.curveLinear;
535
- }
536
- switch (type) {
537
- case "smooth":
538
- return _curve.curveCatmullRom;
539
- case "monotone":
540
- return _curve.curveMonotoneX;
541
- case "linear":
542
- return _curve.curveLinear;
543
- default:
544
- return _curve.curveLinear;
545
- }
546
- };
547
- var renderDefaultTooltip = (params) => {
548
- const { tooltipData } = params;
549
- const nearestDatum = _optionalChain([tooltipData, 'optionalAccess', _20 => _20.nearestDatum, 'optionalAccess', _21 => _21.datum]);
550
- if (!nearestDatum) return null;
551
- const tooltipPoints = Object.entries(_optionalChain([tooltipData, 'optionalAccess', _22 => _22.datumByKey]) || {}).map(([key, { datum }]) => ({
552
- key,
553
- value: datum.value
554
- })).sort((a, b) => b.value - a.value);
555
- return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: line_chart_module_default["line-chart__tooltip"], children: [
556
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: line_chart_module_default["line-chart__tooltip-date"], children: _optionalChain([nearestDatum, 'access', _23 => _23.date, 'optionalAccess', _24 => _24.toLocaleDateString, 'call', _25 => _25()]) }),
557
- tooltipPoints.map((point) => /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: line_chart_module_default["line-chart__tooltip-row"], children: [
558
- /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "span", { className: line_chart_module_default["line-chart__tooltip-label"], children: [
559
- point.key,
560
- ":"
561
- ] }),
562
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: line_chart_module_default["line-chart__tooltip-value"], children: _numberformatters.formatNumber.call(void 0, point.value) })
563
- ] }, point.key))
564
- ] });
565
- };
566
- var formatYearTick = (timestamp) => {
567
- const date = new Date(timestamp);
568
- return date.toLocaleDateString(void 0, {
569
- year: "numeric"
570
- });
571
- };
572
- var formatDateTick = (timestamp) => {
573
- const date = new Date(timestamp);
574
- return date.toLocaleDateString(void 0, {
575
- month: "short",
576
- day: "numeric"
577
- });
578
- };
579
- var formatHourTick = (timestamp) => {
580
- const date = new Date(timestamp);
581
- return date.toLocaleTimeString(void 0, {
582
- hour: "numeric",
583
- hour12: true
584
- });
585
- };
586
- var getFormatter = (sortedData) => {
587
- const minX = Math.min(...sortedData.map((datom) => _optionalChain([datom, 'access', _26 => _26.data, 'access', _27 => _27.at, 'call', _28 => _28(0), 'optionalAccess', _29 => _29.date])));
588
- const maxX = Math.max(...sortedData.map((datom) => _optionalChain([datom, 'access', _30 => _30.data, 'access', _31 => _31.at, 'call', _32 => _32(-1), 'optionalAccess', _33 => _33.date])));
589
- const diffInHours = Math.abs(_datefns.differenceInHours.call(void 0, maxX, minX));
590
- if (diffInHours <= 24) {
591
- return formatHourTick;
592
- }
593
- const diffInYears = Math.abs(_datefns.differenceInYears.call(void 0, maxX, minX));
594
- if (diffInYears <= 1) {
595
- return formatDateTick;
596
- }
597
- return formatYearTick;
598
- };
599
- var guessOptimalNumTicks = (data, chartWidth, tickFormatter) => {
600
- const minX = Math.min(...data.map((datom) => _optionalChain([datom, 'access', _34 => _34.data, 'access', _35 => _35.at, 'call', _36 => _36(0), 'optionalAccess', _37 => _37.date])));
601
- const maxX = Math.max(...data.map((datom) => _optionalChain([datom, 'access', _38 => _38.data, 'access', _39 => _39.at, 'call', _40 => _40(-1), 'optionalAccess', _41 => _41.date])));
602
- const xScale = _scale.scaleTime.call(void 0, { domain: [minX, maxX] });
603
- const upperBound = Math.min(
604
- _optionalChain([data, 'access', _42 => _42[0], 'optionalAccess', _43 => _43.data, 'access', _44 => _44.length]) || 3,
605
- // A sane fallback to avoid NaN when no data is present
606
- Math.ceil(chartWidth / X_TICK_WIDTH)
607
- );
608
- let secondBestGuess = 1;
609
- for (let numTicks = upperBound; numTicks > 1; --numTicks) {
610
- const ticks = xScale.ticks(numTicks).map((d) => tickFormatter(d.getTime()));
611
- if (ticks.length > upperBound) {
612
- continue;
613
- }
614
- secondBestGuess = Math.max(secondBestGuess, ticks.length);
615
- const uniqueTicks = Array.from(new Set(ticks));
616
- if (uniqueTicks.length === 1) {
617
- return 1;
618
- }
619
- const hasConsecutiveDuplicate = ticks.some(
620
- (tick, idx) => idx > 0 && tick === ticks[idx - 1]
621
- );
622
- if (hasConsecutiveDuplicate) {
623
- continue;
624
- }
625
- return ticks.length;
626
- }
627
- return secondBestGuess;
628
- };
629
- var validateData = (data) => {
630
- if (!_optionalChain([data, 'optionalAccess', _45 => _45.length])) return "No data available";
631
- const hasInvalidData = data.some(
632
- (series) => series.data.some(
633
- (point) => isNaN(point.value) || point.value === null || point.value === void 0 || "date" in point && point.date && isNaN(point.date.getTime())
634
- )
635
- );
636
- if (hasInvalidData) return "Invalid data";
637
- return null;
638
- };
639
- var LineChartScalesRef = ({ chartRef, width, height, margin }) => {
640
- const context = _react.useContext.call(void 0, _xychart.DataContext);
641
- _react.useImperativeHandle.call(void 0,
642
- chartRef,
643
- () => ({
644
- getScales: () => {
645
- if (!_optionalChain([context, 'optionalAccess', _46 => _46.xScale]) || !_optionalChain([context, 'optionalAccess', _47 => _47.yScale])) {
646
- return null;
647
- }
648
- return {
649
- xScale: context.xScale,
650
- yScale: context.yScale
651
- };
652
- },
653
- getChartDimensions: () => ({
654
- width,
655
- height,
656
- margin: margin || {}
657
- })
658
- }),
659
- [context, width, height, margin]
660
- );
661
- return null;
662
- };
663
- var LineChartInternal = _react.forwardRef.call(void 0,
664
- ({
665
- data,
666
- chartId: providedChartId,
667
- width,
668
- height,
669
- className,
670
- margin,
671
- withTooltips = true,
672
- withTooltipCrosshairs,
673
- showLegend = false,
674
- legendOrientation = "horizontal",
675
- legendAlignment = "center",
676
- legendPosition = "bottom",
677
- legendMaxWidth,
678
- legendTextOverflow = "wrap",
679
- legendItemClassName,
680
- renderGlyph = defaultRenderGlyph,
681
- glyphStyle = {},
682
- legendShape = "line",
683
- withLegendGlyph = false,
684
- withGradientFill = false,
685
- smoothing = true,
686
- curveType,
687
- renderTooltip = renderDefaultTooltip,
688
- withStartGlyphs = false,
689
- withEndGlyphs = false,
690
- legendInteractive = false,
691
- animation,
692
- options = {},
693
- onPointerDown = void 0,
694
- onPointerUp = void 0,
695
- onPointerMove = void 0,
696
- onPointerOut = void 0,
697
- children,
698
- gridVisibility,
699
- gap = "md"
700
- }, ref) => {
701
- const providerTheme = _chunkTVV7ZI7Ccjs.useGlobalChartsTheme.call(void 0, );
702
- const theme = _chunkTVV7ZI7Ccjs.useXYChartTheme.call(void 0, data);
703
- const chartId = _chunkTVV7ZI7Ccjs.useChartId.call(void 0, providedChartId);
704
- const [svgWrapperRef, svgWrapperHeight] = _chunkTVV7ZI7Ccjs.useElementHeight.call(void 0, );
705
- const chartRef = _react.useRef.call(void 0, null);
706
- const [selectedIndex, setSelectedIndex] = _react.useState.call(void 0, void 0);
707
- const [isNavigating, setIsNavigating] = _react.useState.call(void 0, false);
708
- const internalChartRef = _react.useRef.call(void 0, null);
709
- const hasLegendChild = _chunkTVV7ZI7Ccjs.useHasLegendChild.call(void 0, children);
710
- const chartHeight = svgWrapperHeight > 0 ? svgWrapperHeight : height;
711
- const hasLegend = showLegend || hasLegendChild;
712
- const isWaitingForMeasurement = hasLegend ? svgWrapperHeight === 0 : !chartHeight;
713
- _react.useImperativeHandle.call(void 0,
714
- ref,
715
- () => ({
716
- getScales: () => _optionalChain([internalChartRef, 'access', _48 => _48.current, 'optionalAccess', _49 => _49.getScales, 'call', _50 => _50()]) || null,
717
- getChartDimensions: () => _optionalChain([internalChartRef, 'access', _51 => _51.current, 'optionalAccess', _52 => _52.getChartDimensions, 'call', _53 => _53()]) || { width: 0, height: 0, margin: {} }
718
- }),
719
- [internalChartRef]
720
- );
721
- const dataSorted = _chunkTVV7ZI7Ccjs.useChartDataTransform.call(void 0, data);
722
- const { getElementStyles, isSeriesVisible } = _chunkTVV7ZI7Ccjs.useGlobalChartsContext.call(void 0, );
723
- const seriesWithVisibility = _react.useMemo.call(void 0, () => {
724
- if (!chartId || !legendInteractive) {
725
- return dataSorted.map((series, index) => ({ series, index, isVisible: true }));
726
- }
727
- return dataSorted.map((series, index) => ({
728
- series,
729
- index,
730
- isVisible: isSeriesVisible(chartId, series.label)
731
- }));
732
- }, [dataSorted, chartId, isSeriesVisible, legendInteractive]);
733
- const allSeriesHidden = _react.useMemo.call(void 0, () => {
734
- return seriesWithVisibility.every(({ isVisible }) => !isVisible);
735
- }, [seriesWithVisibility]);
736
- const { tooltipRef, onChartFocus, onChartBlur, onChartKeyDown } = _chunk7HROSZRScjs.useKeyboardNavigation.call(void 0, {
737
- selectedIndex,
738
- setSelectedIndex,
739
- isNavigating,
740
- setIsNavigating,
741
- chartRef,
742
- totalPoints: _optionalChain([dataSorted, 'access', _54 => _54[0], 'optionalAccess', _55 => _55.data, 'access', _56 => _56.length]) || 0
743
- });
744
- const chartOptions = _react.useMemo.call(void 0, () => {
745
- const formatter = _optionalChain([options, 'optionalAccess', _57 => _57.axis, 'optionalAccess', _58 => _58.x, 'optionalAccess', _59 => _59.tickFormat]) || getFormatter(dataSorted);
746
- return {
747
- axis: {
748
- x: {
749
- orientation: "bottom",
750
- numTicks: guessOptimalNumTicks(dataSorted, width, formatter),
751
- tickFormat: formatter,
752
- display: true,
753
- ..._optionalChain([options, 'optionalAccess', _60 => _60.axis, 'optionalAccess', _61 => _61.x])
754
- },
755
- y: {
756
- orientation: "left",
757
- numTicks: 4,
758
- tickFormat: _numberformatters.formatNumberCompact,
759
- display: true,
760
- ..._optionalChain([options, 'optionalAccess', _62 => _62.axis, 'optionalAccess', _63 => _63.y])
761
- }
762
- },
763
- xScale: {
764
- type: "time",
765
- ..._optionalChain([options, 'optionalAccess', _64 => _64.xScale])
766
- },
767
- yScale: {
768
- type: "linear",
769
- nice: true,
770
- zero: false,
771
- ..._optionalChain([options, 'optionalAccess', _65 => _65.yScale])
772
- }
773
- };
774
- }, [options, dataSorted, width]);
775
- const tooltipRenderGlyph = _react.useMemo.call(void 0, () => {
776
- return (props) => {
777
- const seriesIndex = dataSorted.findIndex(
778
- (series) => series.label === props.key || series.data.includes(props.datum)
779
- );
780
- const seriesData = dataSorted[seriesIndex];
781
- const { color, glyph: themeGlyph } = getElementStyles({
782
- data: seriesData,
783
- index: seriesIndex
784
- });
785
- const propsWithResolvedColor = { ...props, color };
786
- return themeGlyph ? themeGlyph(propsWithResolvedColor) : renderGlyph(propsWithResolvedColor);
787
- };
788
- }, [dataSorted, renderGlyph, getElementStyles]);
789
- const defaultMargin = _chunkTVV7ZI7Ccjs.useChartMargin.call(void 0, height, chartOptions, dataSorted, theme);
790
- const error = validateData(dataSorted);
791
- const isDataValid = !error;
792
- const legendOptions = _react.useMemo.call(void 0,
793
- () => ({
794
- withGlyph: withLegendGlyph,
795
- glyphSize: Math.max(0, _nullishCoalesce(toNumber2(_optionalChain([glyphStyle, 'optionalAccess', _66 => _66.radius])), () => ( 4))),
796
- renderGlyph
797
- }),
798
- [withLegendGlyph, _optionalChain([glyphStyle, 'optionalAccess', _67 => _67.radius]), renderGlyph]
799
- );
800
- const legendItems = _chunkTVV7ZI7Ccjs.useChartLegendItems.call(void 0, dataSorted, legendOptions, legendShape);
801
- const chartMetadata = _react.useMemo.call(void 0,
802
- () => ({
803
- withGradientFill,
804
- smoothing,
805
- curveType,
806
- withStartGlyphs,
807
- withEndGlyphs,
808
- withLegendGlyph
809
- }),
810
- [withGradientFill, smoothing, curveType, withStartGlyphs, withEndGlyphs, withLegendGlyph]
811
- );
812
- _chunkTVV7ZI7Ccjs.useChartRegistration.call(void 0, {
813
- chartId,
814
- legendItems,
815
- chartType: "line",
816
- isDataValid,
817
- metadata: chartMetadata
818
- });
819
- const prefersReducedMotion = _chunkTVV7ZI7Ccjs.usePrefersReducedMotion.call(void 0, );
820
- const accessors = {
821
- xAccessor: (d) => _optionalChain([d, 'optionalAccess', _68 => _68.date]),
822
- yAccessor: (d) => _optionalChain([d, 'optionalAccess', _69 => _69.value])
823
- };
824
- if (error) {
825
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: _clsx2.default.call(void 0, "line-chart", line_chart_module_default["line-chart"]), children: error });
826
- }
827
- const legendElement = showLegend && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
828
- _chunkTVV7ZI7Ccjs.Legend,
829
- {
830
- orientation: legendOrientation,
831
- alignment: legendAlignment,
832
- position: legendPosition,
833
- maxWidth: legendMaxWidth,
834
- textOverflow: legendTextOverflow,
835
- legendItemClassName,
836
- className: line_chart_module_default["line-chart__legend"],
837
- shape: legendShape,
838
- chartId,
839
- interactive: legendInteractive
840
- }
841
- );
842
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
843
- _chunkTVV7ZI7Ccjs.SingleChartContext.Provider,
844
- {
845
- value: {
846
- chartId,
847
- chartRef: internalChartRef,
848
- chartWidth: width,
849
- chartHeight
850
- },
851
- children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
852
- _chunkSH32YSZOcjs.Stack,
853
- {
854
- direction: "column",
855
- gap,
856
- className: _clsx2.default.call(void 0,
857
- "line-chart",
858
- line_chart_module_default["line-chart"],
859
- { [line_chart_module_default["line-chart--animated"]]: animation && !prefersReducedMotion },
860
- className
861
- ),
862
- "data-testid": "line-chart",
863
- style: {
864
- width,
865
- height,
866
- visibility: isWaitingForMeasurement ? "hidden" : "visible"
867
- },
868
- children: [
869
- legendPosition === "top" && legendElement,
870
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
871
- "div",
872
- {
873
- className: line_chart_module_default["line-chart__svg-wrapper"],
874
- ref: svgWrapperRef,
875
- role: "grid",
876
- "aria-label": _i18n.__.call(void 0, "Line chart", "jetpack-charts"),
877
- tabIndex: 0,
878
- onKeyDown: onChartKeyDown,
879
- onFocus: onChartFocus,
880
- onBlur: onChartBlur,
881
- children: !isWaitingForMeasurement && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { ref: chartRef, children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
882
- _xychart.XYChart,
883
- {
884
- theme,
885
- width,
886
- height: chartHeight,
887
- margin: {
888
- ...defaultMargin,
889
- ...margin
890
- },
891
- xScale: chartOptions.xScale,
892
- yScale: chartOptions.yScale,
893
- onPointerDown,
894
- onPointerUp,
895
- onPointerMove,
896
- onPointerOut,
897
- pointerEventsDataKey: "nearest",
898
- children: [
899
- gridVisibility !== "none" && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _xychart.Grid, { columns: false, numTicks: 4 }),
900
- chartOptions.axis.x.display && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _xychart.Axis, { ...chartOptions.axis.x }),
901
- chartOptions.axis.y.display && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _xychart.Axis, { ...chartOptions.axis.y }),
902
- allSeriesHidden ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
903
- "text",
904
- {
905
- x: width / 2,
906
- y: chartHeight / 2,
907
- textAnchor: "middle",
908
- fill: _optionalChain([providerTheme, 'access', _70 => _70.gridStyles, 'optionalAccess', _71 => _71.stroke]) || "#ccc",
909
- fontSize: "14",
910
- fontFamily: "-apple-system,BlinkMacSystemFont,Roboto,Helvetica Neue,sans-serif",
911
- children: _i18n.__.call(void 0,
912
- "All series are hidden. Click legend items to show data.",
913
- "jetpack-charts"
914
- )
915
- }
916
- ) : null,
917
- seriesWithVisibility.map(({ series: seriesData, index, isVisible }) => {
918
- if (!isVisible) {
919
- return null;
920
- }
921
- const { color, lineStyles, glyph } = getElementStyles({
922
- data: seriesData,
923
- index
924
- });
925
- const lineProps = {
926
- stroke: color,
927
- ...lineStyles
928
- };
929
- return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "g", { children: [
930
- withGradientFill && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
931
- _gradient.LinearGradient,
932
- {
933
- id: `area-gradient-${chartId}-${index + 1}`,
934
- from: color,
935
- fromOpacity: 0.4,
936
- toOpacity: 0.1,
937
- to: providerTheme.backgroundColor,
938
- ..._optionalChain([seriesData, 'access', _72 => _72.options, 'optionalAccess', _73 => _73.gradient]),
939
- "data-testid": "line-gradient",
940
- children: _optionalChain([seriesData, 'access', _74 => _74.options, 'optionalAccess', _75 => _75.gradient, 'optionalAccess', _76 => _76.stops, 'optionalAccess', _77 => _77.map, 'call', _78 => _78((stop, stopIndex) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
941
- "stop",
942
- {
943
- offset: stop.offset,
944
- stopColor: stop.color || color,
945
- stopOpacity: _nullishCoalesce(stop.opacity, () => ( 1)),
946
- "data-testid": `line-gradient-stop-${chartId}-${index}-${stopIndex}`
947
- },
948
- `${stop.offset}-${stop.color || color}`
949
- ))])
950
- }
951
- ),
952
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
953
- _xychart.AreaSeries,
954
- {
955
- dataKey: _optionalChain([seriesData, 'optionalAccess', _79 => _79.label]),
956
- data: seriesData.data,
957
- ...accessors,
958
- fill: withGradientFill ? `url(#area-gradient-${chartId}-${index + 1})` : "transparent",
959
- renderLine: true,
960
- curve: getCurveType(curveType, smoothing),
961
- lineProps
962
- },
963
- _optionalChain([seriesData, 'optionalAccess', _80 => _80.label])
964
- ),
965
- withStartGlyphs && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
966
- line_chart_glyph_default,
967
- {
968
- index,
969
- data: seriesData,
970
- color,
971
- renderGlyph: _nullishCoalesce(glyph, () => ( renderGlyph)),
972
- accessors,
973
- glyphStyle,
974
- position: "start"
975
- }
976
- ),
977
- withEndGlyphs && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
978
- line_chart_glyph_default,
979
- {
980
- index,
981
- data: seriesData,
982
- color,
983
- renderGlyph: _nullishCoalesce(glyph, () => ( renderGlyph)),
984
- accessors,
985
- glyphStyle,
986
- position: "end"
987
- }
988
- )
989
- ] }, _optionalChain([seriesData, 'optionalAccess', _81 => _81.label]) || index);
990
- }),
991
- withTooltips && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
992
- _chunk7HROSZRScjs.AccessibleTooltip,
993
- {
994
- detectBounds: true,
995
- snapTooltipToDatumX: true,
996
- snapTooltipToDatumY: true,
997
- showSeriesGlyphs: true,
998
- renderTooltip,
999
- renderGlyph: tooltipRenderGlyph,
1000
- glyphStyle,
1001
- showVerticalCrosshair: _optionalChain([withTooltipCrosshairs, 'optionalAccess', _82 => _82.showVertical]),
1002
- showHorizontalCrosshair: _optionalChain([withTooltipCrosshairs, 'optionalAccess', _83 => _83.showHorizontal]),
1003
- selectedIndex,
1004
- tooltipRef,
1005
- keyboardFocusedClassName: line_chart_module_default["line-chart__tooltip--keyboard-focused"],
1006
- series: dataSorted
1007
- }
1008
- ),
1009
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
1010
- LineChartScalesRef,
1011
- {
1012
- chartRef: internalChartRef,
1013
- width,
1014
- height,
1015
- margin
1016
- }
1017
- )
1018
- ]
1019
- }
1020
- ) })
1021
- }
1022
- ),
1023
- legendPosition === "bottom" && legendElement,
1024
- children
1025
- ]
1026
- }
1027
- )
1028
- }
1029
- );
1030
- }
1031
- );
1032
- var LineChartWithProvider = _react.forwardRef.call(void 0, (props, ref) => {
1033
- const existingContext = _react.useContext.call(void 0, _chunkTVV7ZI7Ccjs.GlobalChartsContext);
1034
- if (existingContext) {
1035
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, LineChartInternal, { ...props, ref });
1036
- }
1037
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkTVV7ZI7Ccjs.GlobalChartsProvider, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, LineChartInternal, { ...props, ref }) });
1038
- });
1039
- LineChartWithProvider.displayName = "LineChart";
1040
- var LineChart = _chunkZVGEDXDPcjs.attachSubComponents.call(void 0, LineChartWithProvider, {
1041
- Legend: _chunkTVV7ZI7Ccjs.Legend,
1042
- AnnotationsOverlay: line_chart_annotations_overlay_default,
1043
- Annotation: line_chart_annotation_default
1044
- });
1045
- var LineChartResponsive = _chunkZVGEDXDPcjs.attachSubComponents.call(void 0,
1046
- _chunkNW3RUYK2cjs.withResponsive.call(void 0, LineChartWithProvider),
1047
- {
1048
- Legend: _chunkTVV7ZI7Ccjs.Legend,
1049
- AnnotationsOverlay: line_chart_annotations_overlay_default,
1050
- Annotation: line_chart_annotation_default
1051
- }
1052
- );
1053
-
1054
-
1055
-
1056
-
1057
- exports.LineChart = LineChart; exports.LineChartResponsive = LineChartResponsive;
1058
- //# sourceMappingURL=chunk-KOF32DBL.cjs.map