@automattic/charts 0.56.2 → 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 +14 -0
  2. package/dist/charts/bar-chart/index.cjs +5 -5
  3. package/dist/charts/bar-chart/index.css +12 -0
  4. package/dist/charts/bar-chart/index.css.map +1 -1
  5. package/dist/charts/bar-chart/index.js +4 -4
  6. package/dist/charts/bar-list-chart/index.cjs +6 -6
  7. package/dist/charts/bar-list-chart/index.css +12 -0
  8. package/dist/charts/bar-list-chart/index.css.map +1 -1
  9. package/dist/charts/bar-list-chart/index.js +5 -5
  10. package/dist/charts/conversion-funnel-chart/index.cjs +5 -3
  11. package/dist/charts/conversion-funnel-chart/index.cjs.map +1 -1
  12. package/dist/charts/conversion-funnel-chart/index.css +14 -1
  13. package/dist/charts/conversion-funnel-chart/index.css.map +1 -1
  14. package/dist/charts/conversion-funnel-chart/index.d.cts +2 -0
  15. package/dist/charts/conversion-funnel-chart/index.d.ts +2 -0
  16. package/dist/charts/conversion-funnel-chart/index.js +4 -2
  17. package/dist/charts/geo-chart/index.cjs +4 -4
  18. package/dist/charts/geo-chart/index.css +12 -0
  19. package/dist/charts/geo-chart/index.css.map +1 -1
  20. package/dist/charts/geo-chart/index.js +3 -3
  21. package/dist/charts/leaderboard-chart/index.cjs +5 -5
  22. package/dist/charts/leaderboard-chart/index.css +12 -0
  23. package/dist/charts/leaderboard-chart/index.css.map +1 -1
  24. package/dist/charts/leaderboard-chart/index.js +4 -4
  25. package/dist/charts/line-chart/index.cjs +5 -5
  26. package/dist/charts/line-chart/index.css +12 -0
  27. package/dist/charts/line-chart/index.css.map +1 -1
  28. package/dist/charts/line-chart/index.js +4 -4
  29. package/dist/charts/pie-chart/index.cjs +7 -7
  30. package/dist/charts/pie-chart/index.css +12 -0
  31. package/dist/charts/pie-chart/index.css.map +1 -1
  32. package/dist/charts/pie-chart/index.js +6 -6
  33. package/dist/charts/pie-semi-circle-chart/index.cjs +7 -7
  34. package/dist/charts/pie-semi-circle-chart/index.css +12 -0
  35. package/dist/charts/pie-semi-circle-chart/index.css.map +1 -1
  36. package/dist/charts/pie-semi-circle-chart/index.js +6 -6
  37. package/dist/charts/sparkline/index.cjs +6 -6
  38. package/dist/charts/sparkline/index.css +12 -0
  39. package/dist/charts/sparkline/index.css.map +1 -1
  40. package/dist/charts/sparkline/index.js +5 -5
  41. package/dist/{chunk-OTZT3MC2.cjs → chunk-2A34OA5O.cjs} +19 -20
  42. package/dist/chunk-2A34OA5O.cjs.map +1 -0
  43. package/dist/chunk-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 +7 -4
  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
- import {
2
- Stack
3
- } from "./chunk-MEIVKY4K.js";
4
- import {
5
- AccessibleTooltip,
6
- useKeyboardNavigation
7
- } from "./chunk-5XI443YP.js";
8
- import {
9
- withResponsive
10
- } from "./chunk-C33AQZEC.js";
11
- import {
12
- GlobalChartsContext,
13
- GlobalChartsProvider,
14
- Legend,
15
- SingleChartContext,
16
- useChartDataTransform,
17
- useChartId,
18
- useChartLegendItems,
19
- useChartMargin,
20
- useChartRegistration,
21
- useElementHeight,
22
- useGlobalChartsContext,
23
- useGlobalChartsTheme,
24
- useHasLegendChild,
25
- usePrefersReducedMotion,
26
- useSingleChartContext,
27
- useXYChartTheme
28
- } from "./chunk-H34CJSR6.js";
29
- import {
30
- attachSubComponents,
31
- isSafari
32
- } from "./chunk-TE63Y5PX.js";
33
-
34
- // src/charts/line-chart/line-chart.tsx
35
- import { formatNumberCompact, formatNumber } from "@automattic/number-formatters";
36
- import { curveCatmullRom, curveLinear, curveMonotoneX } from "@visx/curve";
37
- import { LinearGradient } from "@visx/gradient";
38
- import { scaleTime } from "@visx/scale";
39
- import { XYChart, AreaSeries, Grid, Axis, DataContext as DataContext5 } from "@visx/xychart";
40
- import { __ as __2 } from "@wordpress/i18n";
41
- import clsx2 from "clsx";
42
- import { differenceInHours, differenceInYears } from "date-fns";
43
- import { useMemo as useMemo2, useContext as useContext4, forwardRef, useImperativeHandle, useState as useState4, useRef as useRef3 } from "react";
44
-
45
- // src/charts/private/default-glyph/default-glyph.tsx
46
- import { DataContext } from "@visx/xychart";
47
- import { useContext } from "react";
48
- import { jsx } from "react/jsx-runtime";
49
- var DefaultGlyph = (props) => {
50
- const { theme } = useContext(DataContext) || {};
51
- const position = props.position || "start";
52
- return /* @__PURE__ */ jsx(
53
- "circle",
54
- {
55
- cx: props.x,
56
- cy: props.y,
57
- r: props.size,
58
- fill: props.color,
59
- stroke: theme?.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
- import { __ } from "@wordpress/i18n";
91
- import clsx from "clsx";
92
- import Gridicon from "gridicons";
93
- import { useEffect, useId, useRef, useState } from "react";
94
- import { jsx as jsx2, jsxs } from "react/jsx-runtime";
95
- var POPOVER_BUTTON_SIZE = 44;
96
- var LineChartAnnotationLabelWithPopover = ({
97
- title,
98
- subtitle,
99
- renderLabel,
100
- renderLabelPopover
101
- }) => {
102
- const popoverId = useId();
103
- const buttonRef = useRef(null);
104
- const popoverRef = useRef(null);
105
- const [isPositioned, setIsPositioned] = useState(false);
106
- const isBrowserSafari = isSafari();
107
- useEffect(() => {
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 {
129
- }
130
- }, [isBrowserSafari]);
131
- return /* @__PURE__ */ jsxs("div", { className: line_chart_module_default["line-chart__annotation-label"], children: [
132
- /* @__PURE__ */ jsx2(
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 || __("View details", "jetpack-charts"),
144
- children: renderLabel({ title, subtitle })
145
- }
146
- ),
147
- /* @__PURE__ */ jsx2(
148
- "div",
149
- {
150
- ref: popoverRef,
151
- id: popoverId,
152
- ...{ popover: "auto" },
153
- className: clsx(
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__ */ jsxs("div", { className: line_chart_module_default["line-chart__annotation-label-popover-header"], children: [
160
- /* @__PURE__ */ jsx2("div", { className: line_chart_module_default["line-chart__annotation-label-popover-content"], children: renderLabelPopover({ title, subtitle }) }),
161
- /* @__PURE__ */ jsx2(
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": __("Close", "jetpack-charts"),
170
- children: /* @__PURE__ */ jsx2(Gridicon, { 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
- import { DataContext as DataContext2 } from "@visx/xychart";
182
- import { useEffect as useEffect2, useState as useState2, useCallback } from "react";
183
- import { jsx as jsx3 } from "react/jsx-runtime";
184
- var LineChartAnnotationsOverlay = ({ children }) => {
185
- const { chartRef, chartWidth, chartHeight } = useSingleChartContext();
186
- const [scales, setScales] = useState2(null);
187
- const [scalesStable, setScalesStable] = useState2(false);
188
- const createScaleSignature = useCallback((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 = useCallback(() => {
198
- if (chartRef?.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
- useEffect2(() => {
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__ */ jsx3(DataContext2.Provider, { value: dataContextValue, children: /* @__PURE__ */ jsx3(
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
- import {
271
- Annotation,
272
- CircleSubject,
273
- Connector,
274
- HtmlLabel,
275
- Label,
276
- LineSubject
277
- } from "@visx/annotation";
278
- import { DataContext as DataContext3 } from "@visx/xychart";
279
- import merge from "deepmerge";
280
- import { useContext as useContext2, useRef as useRef2, useEffect as useEffect3, useState as useState3, useMemo } from "react";
281
- import { jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
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 = maxWidth ?? ANNOTATION_MAX_WIDTH;
295
- const annotationHeight = 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 = useGlobalChartsTheme();
365
- const { xScale, yScale } = useContext2(DataContext3) || {};
366
- const labelRef = useRef2(null);
367
- const [height, setHeight] = useState3(null);
368
- const styles = merge(providerTheme.annotationStyles ?? {}, datumStyles ?? {});
369
- useEffect3(() => {
370
- if (labelRef.current?.getBBox) {
371
- const bbox = labelRef.current.getBBox();
372
- setHeight(bbox.height);
373
- }
374
- }, []);
375
- const positionData = useMemo(() => {
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: styles?.label?.maxWidth,
404
- height
405
- });
406
- return { x: x2, y: y2, yMin: yMin2, yMax: yMax2, xMin: xMin2, xMax: xMax2, ...position };
407
- }, [datum, xScale, yScale, subjectType, styles?.label?.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 = styles?.label?.y;
412
- if (labelY === "start") return yMax;
413
- if (labelY === "end") return yMin;
414
- return labelY;
415
- };
416
- const getLabelX = () => {
417
- const labelX = styles?.label?.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 isSafari() ? {
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__ */ jsx4("g", { "data-testid": testId, children: /* @__PURE__ */ jsxs2(Annotation, { x, y, dx, dy, children: [
436
- /* @__PURE__ */ jsx4(Connector, { ...styles?.connector }),
437
- subjectType === "circle" && /* @__PURE__ */ jsx4(CircleSubject, { ...styles?.circleSubject }),
438
- subjectType === "line-vertical" && /* @__PURE__ */ jsx4(
439
- LineSubject,
440
- {
441
- min: yMax,
442
- max: yMin,
443
- ...{ ...styles?.lineSubject, orientation: "vertical" }
444
- }
445
- ),
446
- subjectType === "line-horizontal" && /* @__PURE__ */ jsx4(
447
- LineSubject,
448
- {
449
- min: xMin,
450
- max: xMax,
451
- ...{ ...styles?.lineSubject, orientation: "horizontal" }
452
- }
453
- ),
454
- renderLabel ? /* @__PURE__ */ jsx4(HtmlLabel, { ...styles?.label, ...labelPosition, children: /* @__PURE__ */ jsx4("div", { style: getSafariHTMLLabelPosition(), children: renderLabelPopover ? /* @__PURE__ */ jsx4(
455
- line_chart_annotation_label_popover_default,
456
- {
457
- title,
458
- subtitle,
459
- renderLabel,
460
- renderLabelPopover
461
- }
462
- ) : renderLabel({ title, subtitle }) }) }) : /* @__PURE__ */ jsx4("g", { ref: labelRef, children: /* @__PURE__ */ jsx4(
463
- Label,
464
- {
465
- title,
466
- subtitle,
467
- ...styles?.label,
468
- ...labelPosition,
469
- horizontalAnchor: getHorizontalAnchor(subjectType, isFlippedHorizontally),
470
- verticalAnchor: getVerticalAnchor(
471
- subjectType,
472
- isFlippedVertically,
473
- y,
474
- yMax,
475
- 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
- import { DataContext as DataContext4 } from "@visx/xychart";
485
- import { useContext as useContext3 } from "react";
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 } = useContext3(DataContext4) || {};
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, toNumber(glyphStyle?.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
- import { jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
523
- import { createElement } from "react";
524
- var X_TICK_WIDTH = 60;
525
- var defaultRenderGlyph = (props) => {
526
- return /* @__PURE__ */ createElement(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 ? curveCatmullRom : curveLinear;
535
- }
536
- switch (type) {
537
- case "smooth":
538
- return curveCatmullRom;
539
- case "monotone":
540
- return curveMonotoneX;
541
- case "linear":
542
- return curveLinear;
543
- default:
544
- return curveLinear;
545
- }
546
- };
547
- var renderDefaultTooltip = (params) => {
548
- const { tooltipData } = params;
549
- const nearestDatum = tooltipData?.nearestDatum?.datum;
550
- if (!nearestDatum) return null;
551
- const tooltipPoints = Object.entries(tooltipData?.datumByKey || {}).map(([key, { datum }]) => ({
552
- key,
553
- value: datum.value
554
- })).sort((a, b) => b.value - a.value);
555
- return /* @__PURE__ */ jsxs3("div", { className: line_chart_module_default["line-chart__tooltip"], children: [
556
- /* @__PURE__ */ jsx5("div", { className: line_chart_module_default["line-chart__tooltip-date"], children: nearestDatum.date?.toLocaleDateString() }),
557
- tooltipPoints.map((point) => /* @__PURE__ */ jsxs3("div", { className: line_chart_module_default["line-chart__tooltip-row"], children: [
558
- /* @__PURE__ */ jsxs3("span", { className: line_chart_module_default["line-chart__tooltip-label"], children: [
559
- point.key,
560
- ":"
561
- ] }),
562
- /* @__PURE__ */ jsx5("span", { className: line_chart_module_default["line-chart__tooltip-value"], children: formatNumber(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) => datom.data.at(0)?.date));
588
- const maxX = Math.max(...sortedData.map((datom) => datom.data.at(-1)?.date));
589
- const diffInHours = Math.abs(differenceInHours(maxX, minX));
590
- if (diffInHours <= 24) {
591
- return formatHourTick;
592
- }
593
- const diffInYears = Math.abs(differenceInYears(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) => datom.data.at(0)?.date));
601
- const maxX = Math.max(...data.map((datom) => datom.data.at(-1)?.date));
602
- const xScale = scaleTime({ domain: [minX, maxX] });
603
- const upperBound = Math.min(
604
- data[0]?.data.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 (!data?.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 = useContext4(DataContext5);
641
- useImperativeHandle(
642
- chartRef,
643
- () => ({
644
- getScales: () => {
645
- if (!context?.xScale || !context?.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 = forwardRef(
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 = useGlobalChartsTheme();
702
- const theme = useXYChartTheme(data);
703
- const chartId = useChartId(providedChartId);
704
- const [svgWrapperRef, svgWrapperHeight] = useElementHeight();
705
- const chartRef = useRef3(null);
706
- const [selectedIndex, setSelectedIndex] = useState4(void 0);
707
- const [isNavigating, setIsNavigating] = useState4(false);
708
- const internalChartRef = useRef3(null);
709
- const hasLegendChild = useHasLegendChild(children);
710
- const chartHeight = svgWrapperHeight > 0 ? svgWrapperHeight : height;
711
- const hasLegend = showLegend || hasLegendChild;
712
- const isWaitingForMeasurement = hasLegend ? svgWrapperHeight === 0 : !chartHeight;
713
- useImperativeHandle(
714
- ref,
715
- () => ({
716
- getScales: () => internalChartRef.current?.getScales() || null,
717
- getChartDimensions: () => internalChartRef.current?.getChartDimensions() || { width: 0, height: 0, margin: {} }
718
- }),
719
- [internalChartRef]
720
- );
721
- const dataSorted = useChartDataTransform(data);
722
- const { getElementStyles, isSeriesVisible } = useGlobalChartsContext();
723
- const seriesWithVisibility = useMemo2(() => {
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 = useMemo2(() => {
734
- return seriesWithVisibility.every(({ isVisible }) => !isVisible);
735
- }, [seriesWithVisibility]);
736
- const { tooltipRef, onChartFocus, onChartBlur, onChartKeyDown } = useKeyboardNavigation({
737
- selectedIndex,
738
- setSelectedIndex,
739
- isNavigating,
740
- setIsNavigating,
741
- chartRef,
742
- totalPoints: dataSorted[0]?.data.length || 0
743
- });
744
- const chartOptions = useMemo2(() => {
745
- const formatter = options?.axis?.x?.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
- ...options?.axis?.x
754
- },
755
- y: {
756
- orientation: "left",
757
- numTicks: 4,
758
- tickFormat: formatNumberCompact,
759
- display: true,
760
- ...options?.axis?.y
761
- }
762
- },
763
- xScale: {
764
- type: "time",
765
- ...options?.xScale
766
- },
767
- yScale: {
768
- type: "linear",
769
- nice: true,
770
- zero: false,
771
- ...options?.yScale
772
- }
773
- };
774
- }, [options, dataSorted, width]);
775
- const tooltipRenderGlyph = useMemo2(() => {
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 = useChartMargin(height, chartOptions, dataSorted, theme);
790
- const error = validateData(dataSorted);
791
- const isDataValid = !error;
792
- const legendOptions = useMemo2(
793
- () => ({
794
- withGlyph: withLegendGlyph,
795
- glyphSize: Math.max(0, toNumber2(glyphStyle?.radius) ?? 4),
796
- renderGlyph
797
- }),
798
- [withLegendGlyph, glyphStyle?.radius, renderGlyph]
799
- );
800
- const legendItems = useChartLegendItems(dataSorted, legendOptions, legendShape);
801
- const chartMetadata = useMemo2(
802
- () => ({
803
- withGradientFill,
804
- smoothing,
805
- curveType,
806
- withStartGlyphs,
807
- withEndGlyphs,
808
- withLegendGlyph
809
- }),
810
- [withGradientFill, smoothing, curveType, withStartGlyphs, withEndGlyphs, withLegendGlyph]
811
- );
812
- useChartRegistration({
813
- chartId,
814
- legendItems,
815
- chartType: "line",
816
- isDataValid,
817
- metadata: chartMetadata
818
- });
819
- const prefersReducedMotion = usePrefersReducedMotion();
820
- const accessors = {
821
- xAccessor: (d) => d?.date,
822
- yAccessor: (d) => d?.value
823
- };
824
- if (error) {
825
- return /* @__PURE__ */ jsx5("div", { className: clsx2("line-chart", line_chart_module_default["line-chart"]), children: error });
826
- }
827
- const legendElement = showLegend && /* @__PURE__ */ jsx5(
828
- 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__ */ jsx5(
843
- SingleChartContext.Provider,
844
- {
845
- value: {
846
- chartId,
847
- chartRef: internalChartRef,
848
- chartWidth: width,
849
- chartHeight
850
- },
851
- children: /* @__PURE__ */ jsxs3(
852
- Stack,
853
- {
854
- direction: "column",
855
- gap,
856
- className: clsx2(
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__ */ jsx5(
871
- "div",
872
- {
873
- className: line_chart_module_default["line-chart__svg-wrapper"],
874
- ref: svgWrapperRef,
875
- role: "grid",
876
- "aria-label": __2("Line chart", "jetpack-charts"),
877
- tabIndex: 0,
878
- onKeyDown: onChartKeyDown,
879
- onFocus: onChartFocus,
880
- onBlur: onChartBlur,
881
- children: !isWaitingForMeasurement && /* @__PURE__ */ jsx5("div", { ref: chartRef, children: /* @__PURE__ */ jsxs3(
882
- 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__ */ jsx5(Grid, { columns: false, numTicks: 4 }),
900
- chartOptions.axis.x.display && /* @__PURE__ */ jsx5(Axis, { ...chartOptions.axis.x }),
901
- chartOptions.axis.y.display && /* @__PURE__ */ jsx5(Axis, { ...chartOptions.axis.y }),
902
- allSeriesHidden ? /* @__PURE__ */ jsx5(
903
- "text",
904
- {
905
- x: width / 2,
906
- y: chartHeight / 2,
907
- textAnchor: "middle",
908
- fill: providerTheme.gridStyles?.stroke || "#ccc",
909
- fontSize: "14",
910
- fontFamily: "-apple-system,BlinkMacSystemFont,Roboto,Helvetica Neue,sans-serif",
911
- children: __2(
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__ */ jsxs3("g", { children: [
930
- withGradientFill && /* @__PURE__ */ jsx5(
931
- 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
- ...seriesData.options?.gradient,
939
- "data-testid": "line-gradient",
940
- children: seriesData.options?.gradient?.stops?.map((stop, stopIndex) => /* @__PURE__ */ jsx5(
941
- "stop",
942
- {
943
- offset: stop.offset,
944
- stopColor: stop.color || color,
945
- stopOpacity: stop.opacity ?? 1,
946
- "data-testid": `line-gradient-stop-${chartId}-${index}-${stopIndex}`
947
- },
948
- `${stop.offset}-${stop.color || color}`
949
- ))
950
- }
951
- ),
952
- /* @__PURE__ */ jsx5(
953
- AreaSeries,
954
- {
955
- dataKey: seriesData?.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
- seriesData?.label
964
- ),
965
- withStartGlyphs && /* @__PURE__ */ jsx5(
966
- line_chart_glyph_default,
967
- {
968
- index,
969
- data: seriesData,
970
- color,
971
- renderGlyph: glyph ?? renderGlyph,
972
- accessors,
973
- glyphStyle,
974
- position: "start"
975
- }
976
- ),
977
- withEndGlyphs && /* @__PURE__ */ jsx5(
978
- line_chart_glyph_default,
979
- {
980
- index,
981
- data: seriesData,
982
- color,
983
- renderGlyph: glyph ?? renderGlyph,
984
- accessors,
985
- glyphStyle,
986
- position: "end"
987
- }
988
- )
989
- ] }, seriesData?.label || index);
990
- }),
991
- withTooltips && /* @__PURE__ */ jsx5(
992
- AccessibleTooltip,
993
- {
994
- detectBounds: true,
995
- snapTooltipToDatumX: true,
996
- snapTooltipToDatumY: true,
997
- showSeriesGlyphs: true,
998
- renderTooltip,
999
- renderGlyph: tooltipRenderGlyph,
1000
- glyphStyle,
1001
- showVerticalCrosshair: withTooltipCrosshairs?.showVertical,
1002
- showHorizontalCrosshair: withTooltipCrosshairs?.showHorizontal,
1003
- selectedIndex,
1004
- tooltipRef,
1005
- keyboardFocusedClassName: line_chart_module_default["line-chart__tooltip--keyboard-focused"],
1006
- series: dataSorted
1007
- }
1008
- ),
1009
- /* @__PURE__ */ jsx5(
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 = forwardRef((props, ref) => {
1033
- const existingContext = useContext4(GlobalChartsContext);
1034
- if (existingContext) {
1035
- return /* @__PURE__ */ jsx5(LineChartInternal, { ...props, ref });
1036
- }
1037
- return /* @__PURE__ */ jsx5(GlobalChartsProvider, { children: /* @__PURE__ */ jsx5(LineChartInternal, { ...props, ref }) });
1038
- });
1039
- LineChartWithProvider.displayName = "LineChart";
1040
- var LineChart = attachSubComponents(LineChartWithProvider, {
1041
- Legend,
1042
- AnnotationsOverlay: line_chart_annotations_overlay_default,
1043
- Annotation: line_chart_annotation_default
1044
- });
1045
- var LineChartResponsive = attachSubComponents(
1046
- withResponsive(LineChartWithProvider),
1047
- {
1048
- Legend,
1049
- AnnotationsOverlay: line_chart_annotations_overlay_default,
1050
- Annotation: line_chart_annotation_default
1051
- }
1052
- );
1053
-
1054
- export {
1055
- LineChart,
1056
- LineChartResponsive
1057
- };
1058
- //# sourceMappingURL=chunk-ZDNCF642.js.map