@x-plat/design-system 0.5.35 → 0.5.36
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.
- package/dist/components/Chart/index.cjs +146 -200
- package/dist/components/Chart/index.css +12 -25
- package/dist/components/Chart/index.js +132 -186
- package/dist/components/index.cjs +193 -231
- package/dist/components/index.css +12 -25
- package/dist/components/index.js +173 -211
- package/dist/index.cjs +193 -231
- package/dist/index.css +12 -25
- package/dist/index.js +173 -211
- package/package.json +1 -1
|
@@ -35,24 +35,8 @@ __export(Chart_exports, {
|
|
|
35
35
|
module.exports = __toCommonJS(Chart_exports);
|
|
36
36
|
|
|
37
37
|
// src/components/Chart/Chart.tsx
|
|
38
|
-
var import_react2 = __toESM(require("react"), 1);
|
|
39
|
-
|
|
40
|
-
// src/tokens/hooks/Portal.tsx
|
|
41
38
|
var import_react = __toESM(require("react"), 1);
|
|
42
|
-
var import_react_dom = __toESM(require("react-dom"), 1);
|
|
43
39
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
44
|
-
var PortalContainerContext = import_react.default.createContext(null);
|
|
45
|
-
var Portal = ({ children }) => {
|
|
46
|
-
const contextContainer = import_react.default.useContext(PortalContainerContext);
|
|
47
|
-
if (typeof document === "undefined") return null;
|
|
48
|
-
const container = contextContainer ?? document.body;
|
|
49
|
-
return import_react_dom.default.createPortal(children, container);
|
|
50
|
-
};
|
|
51
|
-
Portal.displayName = "Portal";
|
|
52
|
-
var Portal_default = Portal;
|
|
53
|
-
|
|
54
|
-
// src/components/Chart/Chart.tsx
|
|
55
|
-
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
56
40
|
var CATEGORICAL_COUNT = 8;
|
|
57
41
|
var LINE_BAR_PALETTES = Array.from({ length: CATEGORICAL_COUNT }, (_, i) => {
|
|
58
42
|
const n = i + 1;
|
|
@@ -98,11 +82,11 @@ var toSmoothPath = (points) => {
|
|
|
98
82
|
};
|
|
99
83
|
var RESIZE_SETTLE_MS = 150;
|
|
100
84
|
var useChartSize = (ref) => {
|
|
101
|
-
const [size, setSize] =
|
|
102
|
-
const settleTimer =
|
|
103
|
-
const committedSize =
|
|
104
|
-
const initialRef =
|
|
105
|
-
|
|
85
|
+
const [size, setSize] = import_react.default.useState({ width: 0, height: 0 });
|
|
86
|
+
const settleTimer = import_react.default.useRef(0);
|
|
87
|
+
const committedSize = import_react.default.useRef({ width: 0, height: 0 });
|
|
88
|
+
const initialRef = import_react.default.useRef(true);
|
|
89
|
+
import_react.default.useEffect(() => {
|
|
106
90
|
const el = ref.current;
|
|
107
91
|
if (!el) return;
|
|
108
92
|
const observer = new ResizeObserver((entries) => {
|
|
@@ -144,10 +128,10 @@ var useChartSize = (ref) => {
|
|
|
144
128
|
};
|
|
145
129
|
var prefersReducedMotion = () => typeof window !== "undefined" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
146
130
|
var useChartAnimation = (containerRef, dataKey) => {
|
|
147
|
-
const [animate, setAnimate] =
|
|
148
|
-
const prevDataKey =
|
|
149
|
-
const hasAnimated =
|
|
150
|
-
|
|
131
|
+
const [animate, setAnimate] = import_react.default.useState(false);
|
|
132
|
+
const prevDataKey = import_react.default.useRef(dataKey);
|
|
133
|
+
const hasAnimated = import_react.default.useRef(false);
|
|
134
|
+
import_react.default.useEffect(() => {
|
|
151
135
|
if (prefersReducedMotion()) return;
|
|
152
136
|
const el = containerRef.current;
|
|
153
137
|
if (!el) return;
|
|
@@ -163,7 +147,7 @@ var useChartAnimation = (containerRef, dataKey) => {
|
|
|
163
147
|
observer.observe(el);
|
|
164
148
|
return () => observer.disconnect();
|
|
165
149
|
}, [containerRef]);
|
|
166
|
-
|
|
150
|
+
import_react.default.useEffect(() => {
|
|
167
151
|
if (dataKey !== prevDataKey.current) {
|
|
168
152
|
prevDataKey.current = dataKey;
|
|
169
153
|
if (prefersReducedMotion()) return;
|
|
@@ -177,39 +161,47 @@ var useChartAnimation = (containerRef, dataKey) => {
|
|
|
177
161
|
};
|
|
178
162
|
var TOOLTIP_OFFSET = 12;
|
|
179
163
|
var useChartTooltip = (enabled) => {
|
|
180
|
-
const [tooltip, setTooltip] =
|
|
164
|
+
const [tooltip, setTooltip] = import_react.default.useState({
|
|
181
165
|
visible: false,
|
|
182
|
-
|
|
183
|
-
|
|
166
|
+
x: 0,
|
|
167
|
+
y: 0,
|
|
184
168
|
content: ""
|
|
185
169
|
});
|
|
186
|
-
const containerRef =
|
|
187
|
-
const rafRef =
|
|
188
|
-
const move =
|
|
170
|
+
const containerRef = import_react.default.useRef(null);
|
|
171
|
+
const rafRef = import_react.default.useRef(0);
|
|
172
|
+
const move = import_react.default.useCallback((e) => {
|
|
189
173
|
if (!enabled) return;
|
|
190
174
|
const cx = e.clientX;
|
|
191
175
|
const cy = e.clientY;
|
|
192
176
|
cancelAnimationFrame(rafRef.current);
|
|
193
177
|
rafRef.current = requestAnimationFrame(() => {
|
|
194
|
-
|
|
178
|
+
const rect = containerRef.current?.getBoundingClientRect();
|
|
179
|
+
if (!rect) return;
|
|
180
|
+
setTooltip((prev) => ({ ...prev, x: cx - rect.left, y: cy - rect.top }));
|
|
195
181
|
});
|
|
196
182
|
}, [enabled]);
|
|
197
|
-
const show =
|
|
183
|
+
const show = import_react.default.useCallback((e, content) => {
|
|
184
|
+
if (!enabled) return;
|
|
185
|
+
const rect = containerRef.current?.getBoundingClientRect();
|
|
186
|
+
if (!rect) return;
|
|
187
|
+
setTooltip({ visible: true, x: e.clientX - rect.left, y: e.clientY - rect.top, content });
|
|
188
|
+
}, [enabled]);
|
|
189
|
+
const showAt = import_react.default.useCallback((x, y, content) => {
|
|
198
190
|
if (!enabled) return;
|
|
199
|
-
setTooltip({ visible: true,
|
|
191
|
+
setTooltip({ visible: true, x, y, content });
|
|
200
192
|
}, [enabled]);
|
|
201
|
-
const hide =
|
|
193
|
+
const hide = import_react.default.useCallback(() => {
|
|
202
194
|
cancelAnimationFrame(rafRef.current);
|
|
203
195
|
setTooltip((prev) => ({ ...prev, visible: false }));
|
|
204
196
|
}, []);
|
|
205
|
-
return { tooltip, show, hide, move, containerRef };
|
|
197
|
+
return { tooltip, show, showAt, hide, move, containerRef };
|
|
206
198
|
};
|
|
207
|
-
var GridLines =
|
|
199
|
+
var GridLines = import_react.default.memo(({ width, height, chartH, maxVal }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: [0, 0.25, 0.5, 0.75, 1].map((ratio) => {
|
|
208
200
|
const y = PADDING.top + (1 - ratio) * chartH;
|
|
209
201
|
const val = Math.round(maxVal * ratio);
|
|
210
|
-
return /* @__PURE__ */ (0,
|
|
211
|
-
/* @__PURE__ */ (0,
|
|
212
|
-
/* @__PURE__ */ (0,
|
|
202
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("g", { children: [
|
|
203
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("line", { x1: PADDING.left, y1: y, x2: width - PADDING.right, y2: y, className: "chart-grid" }),
|
|
204
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("text", { x: PADDING.left - 8, y: y + 4, className: "chart-axis-label", textAnchor: "end", children: val })
|
|
213
205
|
] }, ratio);
|
|
214
206
|
}) }));
|
|
215
207
|
GridLines.displayName = "GridLines";
|
|
@@ -219,18 +211,18 @@ var getLabelStep = (count, chartW) => {
|
|
|
219
211
|
if (count <= maxLabels) return 1;
|
|
220
212
|
return Math.ceil(count / maxLabels);
|
|
221
213
|
};
|
|
222
|
-
var AxisLabels =
|
|
214
|
+
var AxisLabels = import_react.default.memo(({ labels, count, chartW, height }) => {
|
|
223
215
|
const step = getLabelStep(count, chartW);
|
|
224
|
-
return /* @__PURE__ */ (0,
|
|
216
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: labels.map((label, i) => {
|
|
225
217
|
if (i % step !== 0) return null;
|
|
226
218
|
const x = PADDING.left + i / (count - 1 || 1) * chartW;
|
|
227
|
-
return /* @__PURE__ */ (0,
|
|
219
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("text", { x, y: height - 8, className: "chart-axis-label", textAnchor: "middle", children: label }, i);
|
|
228
220
|
}) });
|
|
229
221
|
});
|
|
230
222
|
AxisLabels.displayName = "AxisLabels";
|
|
231
223
|
var useCrosshair = (seriesPoints, entries, labels, chartH) => {
|
|
232
|
-
const [activeIndex, setActiveIndex] =
|
|
233
|
-
const handleMouseMove =
|
|
224
|
+
const [activeIndex, setActiveIndex] = import_react.default.useState(null);
|
|
225
|
+
const handleMouseMove = import_react.default.useCallback((e) => {
|
|
234
226
|
const svg = e.currentTarget;
|
|
235
227
|
const rect = svg.getBoundingClientRect();
|
|
236
228
|
const mx = (e.clientX - rect.left) / rect.width * svg.viewBox.baseVal.width;
|
|
@@ -249,17 +241,17 @@ var useCrosshair = (seriesPoints, entries, labels, chartH) => {
|
|
|
249
241
|
}
|
|
250
242
|
setActiveIndex(minDist <= threshold ? closest : null);
|
|
251
243
|
}, [seriesPoints]);
|
|
252
|
-
const handleMouseLeave =
|
|
244
|
+
const handleMouseLeave = import_react.default.useCallback(() => {
|
|
253
245
|
setActiveIndex(null);
|
|
254
246
|
}, []);
|
|
255
|
-
const tooltipContent =
|
|
247
|
+
const tooltipContent = import_react.default.useMemo(() => {
|
|
256
248
|
if (activeIndex === null) return "";
|
|
257
249
|
return entries.map(([key], di) => {
|
|
258
250
|
const p = seriesPoints[di]?.[activeIndex];
|
|
259
251
|
return p ? `${key}: ${p.v}` : "";
|
|
260
252
|
}).filter(Boolean).join(" / ");
|
|
261
253
|
}, [activeIndex, entries, seriesPoints]);
|
|
262
|
-
const getTooltipAt =
|
|
254
|
+
const getTooltipAt = import_react.default.useCallback((idx) => {
|
|
263
255
|
return entries.map(([key], di) => {
|
|
264
256
|
const p = seriesPoints[di]?.[idx];
|
|
265
257
|
return p ? `${key}: ${p.v}` : "";
|
|
@@ -267,16 +259,16 @@ var useCrosshair = (seriesPoints, entries, labels, chartH) => {
|
|
|
267
259
|
}, [entries, seriesPoints]);
|
|
268
260
|
return { activeIndex, handleMouseMove, handleMouseLeave, tooltipContent, getTooltipAt };
|
|
269
261
|
};
|
|
270
|
-
var LineChart =
|
|
271
|
-
const entries =
|
|
272
|
-
const maxVal =
|
|
262
|
+
var LineChart = import_react.default.memo(({ data, labels, width, height, animate, onHover, onShowAt, onMove, onLeave }) => {
|
|
263
|
+
const entries = import_react.default.useMemo(() => Object.entries(data), [data]);
|
|
264
|
+
const maxVal = import_react.default.useMemo(() => {
|
|
273
265
|
const allValues = entries.flatMap(([, v]) => v);
|
|
274
266
|
return Math.max(...allValues) * 1.2 || 1;
|
|
275
267
|
}, [entries]);
|
|
276
268
|
const count = labels.length;
|
|
277
269
|
const chartW = width - PADDING.left - PADDING.right;
|
|
278
270
|
const chartH = height - PADDING.top - PADDING.bottom;
|
|
279
|
-
const seriesPoints =
|
|
271
|
+
const seriesPoints = import_react.default.useMemo(
|
|
280
272
|
() => entries.map(
|
|
281
273
|
([, values]) => values.map((v, i) => ({
|
|
282
274
|
x: PADDING.left + i / (count - 1 || 1) * chartW,
|
|
@@ -286,9 +278,9 @@ var LineChart = import_react2.default.memo(({ data, labels, width, height, anima
|
|
|
286
278
|
),
|
|
287
279
|
[entries, count, chartW, chartH, maxVal]
|
|
288
280
|
);
|
|
289
|
-
const clipRef =
|
|
281
|
+
const clipRef = import_react.default.useRef(null);
|
|
290
282
|
const { activeIndex, handleMouseMove, handleMouseLeave, getTooltipAt } = useCrosshair(seriesPoints, entries, labels, chartH);
|
|
291
|
-
|
|
283
|
+
import_react.default.useEffect(() => {
|
|
292
284
|
if (!animate || !clipRef.current) return;
|
|
293
285
|
clipRef.current.setAttribute("width", "0");
|
|
294
286
|
requestAnimationFrame(() => {
|
|
@@ -300,30 +292,16 @@ var LineChart = import_react2.default.memo(({ data, labels, width, height, anima
|
|
|
300
292
|
}, [animate, width]);
|
|
301
293
|
const activeX = activeIndex !== null ? seriesPoints[0]?.[activeIndex]?.x ?? null : null;
|
|
302
294
|
const lineClipId = "line-area-clip";
|
|
303
|
-
return /* @__PURE__ */ (0,
|
|
295
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
304
296
|
"svg",
|
|
305
297
|
{
|
|
306
298
|
viewBox: `0 0 ${width} ${height}`,
|
|
307
299
|
className: "chart-svg",
|
|
308
300
|
onMouseMove: (e) => {
|
|
309
301
|
handleMouseMove(e);
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
const points = seriesPoints[0];
|
|
314
|
-
if (!points || points.length === 0) return;
|
|
315
|
-
const step = points.length > 1 ? Math.abs(points[1].x - points[0].x) : 20;
|
|
316
|
-
let closest = 0;
|
|
317
|
-
let minDist = Math.abs(points[0].x - mx);
|
|
318
|
-
for (let i = 1; i < points.length; i++) {
|
|
319
|
-
const dist = Math.abs(points[i].x - mx);
|
|
320
|
-
if (dist < minDist) {
|
|
321
|
-
minDist = dist;
|
|
322
|
-
closest = i;
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
if (minDist <= step / 2) {
|
|
326
|
-
onHover(e, `${labels[closest]} \u2014 ${getTooltipAt(closest)}`);
|
|
302
|
+
if (activeIndex !== null && seriesPoints[0]?.[activeIndex]) {
|
|
303
|
+
const p = seriesPoints[0][activeIndex];
|
|
304
|
+
onShowAt(p.x, p.y, `${labels[activeIndex]} \u2014 ${getTooltipAt(activeIndex)}`);
|
|
327
305
|
} else {
|
|
328
306
|
onLeave();
|
|
329
307
|
}
|
|
@@ -333,9 +311,9 @@ var LineChart = import_react2.default.memo(({ data, labels, width, height, anima
|
|
|
333
311
|
onLeave();
|
|
334
312
|
},
|
|
335
313
|
children: [
|
|
336
|
-
animate && /* @__PURE__ */ (0,
|
|
337
|
-
/* @__PURE__ */ (0,
|
|
338
|
-
/* @__PURE__ */ (0,
|
|
314
|
+
animate && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("defs", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("clipPath", { id: lineClipId, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("rect", { ref: clipRef, x: "0", y: "0", width: animate ? 0 : width, height }) }) }),
|
|
315
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(GridLines, { width, height, chartH, maxVal }),
|
|
316
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(AxisLabels, { labels, count, chartW, height }),
|
|
339
317
|
entries.map(([key], di) => {
|
|
340
318
|
const palette = getPalette(LINE_BAR_PALETTES, di, key);
|
|
341
319
|
const color = palette[2];
|
|
@@ -344,16 +322,16 @@ var LineChart = import_react2.default.memo(({ data, labels, width, height, anima
|
|
|
344
322
|
const gradientId = `line-gradient-${di}`;
|
|
345
323
|
const polyPoints = points.map((p) => `${p.x},${p.y}`).join(" ");
|
|
346
324
|
const areaD = `M ${points[0].x},${points[0].y} ${points.map((p) => `L ${p.x},${p.y}`).join(" ")} L ${points[points.length - 1].x},${PADDING.top + chartH} L ${points[0].x},${PADDING.top + chartH} Z`;
|
|
347
|
-
return /* @__PURE__ */ (0,
|
|
348
|
-
/* @__PURE__ */ (0,
|
|
349
|
-
/* @__PURE__ */ (0,
|
|
350
|
-
/* @__PURE__ */ (0,
|
|
325
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("g", { children: [
|
|
326
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("defs", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("linearGradient", { id: gradientId, x1: "0", y1: "0", x2: "0", y2: "1", children: [
|
|
327
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("stop", { offset: "0%", stopColor: areaColor, stopOpacity: "0.2" }),
|
|
328
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("stop", { offset: "100%", stopColor: areaColor, stopOpacity: "0" })
|
|
351
329
|
] }) }),
|
|
352
|
-
/* @__PURE__ */ (0,
|
|
353
|
-
/* @__PURE__ */ (0,
|
|
354
|
-
/* @__PURE__ */ (0,
|
|
330
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("g", { clipPath: animate ? `url(#${lineClipId})` : void 0, children: [
|
|
331
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: areaD, fill: `url(#${gradientId})` }),
|
|
332
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("polyline", { points: polyPoints, fill: "none", stroke: color, strokeWidth: "2" })
|
|
355
333
|
] }),
|
|
356
|
-
activeIndex !== null && points[activeIndex] && /* @__PURE__ */ (0,
|
|
334
|
+
activeIndex !== null && points[activeIndex] && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
357
335
|
"circle",
|
|
358
336
|
{
|
|
359
337
|
cx: points[activeIndex].x,
|
|
@@ -365,7 +343,7 @@ var LineChart = import_react2.default.memo(({ data, labels, width, height, anima
|
|
|
365
343
|
)
|
|
366
344
|
] }, di);
|
|
367
345
|
}),
|
|
368
|
-
activeX !== null && /* @__PURE__ */ (0,
|
|
346
|
+
activeX !== null && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
369
347
|
"line",
|
|
370
348
|
{
|
|
371
349
|
x1: activeX,
|
|
@@ -375,7 +353,7 @@ var LineChart = import_react2.default.memo(({ data, labels, width, height, anima
|
|
|
375
353
|
className: "chart-crosshair"
|
|
376
354
|
}
|
|
377
355
|
),
|
|
378
|
-
/* @__PURE__ */ (0,
|
|
356
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
379
357
|
"rect",
|
|
380
358
|
{
|
|
381
359
|
x: PADDING.left,
|
|
@@ -391,16 +369,16 @@ var LineChart = import_react2.default.memo(({ data, labels, width, height, anima
|
|
|
391
369
|
);
|
|
392
370
|
});
|
|
393
371
|
LineChart.displayName = "LineChart";
|
|
394
|
-
var CurveChart =
|
|
395
|
-
const entries =
|
|
396
|
-
const maxVal =
|
|
372
|
+
var CurveChart = import_react.default.memo(({ data, labels, width, height, animate, onHover, onShowAt, onMove, onLeave }) => {
|
|
373
|
+
const entries = import_react.default.useMemo(() => Object.entries(data), [data]);
|
|
374
|
+
const maxVal = import_react.default.useMemo(() => {
|
|
397
375
|
const allValues = entries.flatMap(([, v]) => v);
|
|
398
376
|
return Math.max(...allValues) * 1.2 || 1;
|
|
399
377
|
}, [entries]);
|
|
400
378
|
const count = labels.length;
|
|
401
379
|
const chartW = width - PADDING.left - PADDING.right;
|
|
402
380
|
const chartH = height - PADDING.top - PADDING.bottom;
|
|
403
|
-
const seriesPoints =
|
|
381
|
+
const seriesPoints = import_react.default.useMemo(
|
|
404
382
|
() => entries.map(
|
|
405
383
|
([, values]) => values.map((v, i) => ({
|
|
406
384
|
x: PADDING.left + i / (count - 1 || 1) * chartW,
|
|
@@ -410,9 +388,9 @@ var CurveChart = import_react2.default.memo(({ data, labels, width, height, anim
|
|
|
410
388
|
),
|
|
411
389
|
[entries, count, chartW, chartH, maxVal]
|
|
412
390
|
);
|
|
413
|
-
const curveClipRef =
|
|
391
|
+
const curveClipRef = import_react.default.useRef(null);
|
|
414
392
|
const { activeIndex, handleMouseMove, handleMouseLeave, getTooltipAt } = useCrosshair(seriesPoints, entries, labels, chartH);
|
|
415
|
-
|
|
393
|
+
import_react.default.useEffect(() => {
|
|
416
394
|
if (!animate || !curveClipRef.current) return;
|
|
417
395
|
curveClipRef.current.setAttribute("width", "0");
|
|
418
396
|
requestAnimationFrame(() => {
|
|
@@ -424,30 +402,16 @@ var CurveChart = import_react2.default.memo(({ data, labels, width, height, anim
|
|
|
424
402
|
}, [animate, width]);
|
|
425
403
|
const activeX = activeIndex !== null ? seriesPoints[0]?.[activeIndex]?.x ?? null : null;
|
|
426
404
|
const curveClipId = "curve-area-clip";
|
|
427
|
-
return /* @__PURE__ */ (0,
|
|
405
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
428
406
|
"svg",
|
|
429
407
|
{
|
|
430
408
|
viewBox: `0 0 ${width} ${height}`,
|
|
431
409
|
className: "chart-svg",
|
|
432
410
|
onMouseMove: (e) => {
|
|
433
411
|
handleMouseMove(e);
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
const points = seriesPoints[0];
|
|
438
|
-
if (!points || points.length === 0) return;
|
|
439
|
-
const step = points.length > 1 ? Math.abs(points[1].x - points[0].x) : 20;
|
|
440
|
-
let closest = 0;
|
|
441
|
-
let minDist = Math.abs(points[0].x - mx);
|
|
442
|
-
for (let i = 1; i < points.length; i++) {
|
|
443
|
-
const dist = Math.abs(points[i].x - mx);
|
|
444
|
-
if (dist < minDist) {
|
|
445
|
-
minDist = dist;
|
|
446
|
-
closest = i;
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
if (minDist <= step / 2) {
|
|
450
|
-
onHover(e, `${labels[closest]} \u2014 ${getTooltipAt(closest)}`);
|
|
412
|
+
if (activeIndex !== null && seriesPoints[0]?.[activeIndex]) {
|
|
413
|
+
const p = seriesPoints[0][activeIndex];
|
|
414
|
+
onShowAt(p.x, p.y, `${labels[activeIndex]} \u2014 ${getTooltipAt(activeIndex)}`);
|
|
451
415
|
} else {
|
|
452
416
|
onLeave();
|
|
453
417
|
}
|
|
@@ -457,9 +421,9 @@ var CurveChart = import_react2.default.memo(({ data, labels, width, height, anim
|
|
|
457
421
|
onLeave();
|
|
458
422
|
},
|
|
459
423
|
children: [
|
|
460
|
-
animate && /* @__PURE__ */ (0,
|
|
461
|
-
/* @__PURE__ */ (0,
|
|
462
|
-
/* @__PURE__ */ (0,
|
|
424
|
+
animate && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("defs", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("clipPath", { id: curveClipId, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("rect", { ref: curveClipRef, x: "0", y: "0", width: animate ? 0 : width, height }) }) }),
|
|
425
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(GridLines, { width, height, chartH, maxVal }),
|
|
426
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(AxisLabels, { labels, count, chartW, height }),
|
|
463
427
|
entries.map(([key], di) => {
|
|
464
428
|
const palette = getPalette(LINE_BAR_PALETTES, di, key);
|
|
465
429
|
const color = palette[2];
|
|
@@ -468,16 +432,16 @@ var CurveChart = import_react2.default.memo(({ data, labels, width, height, anim
|
|
|
468
432
|
const gradientId = `curve-gradient-${di}`;
|
|
469
433
|
const linePath = toSmoothPath(points);
|
|
470
434
|
const areaPath = linePath + ` L ${points[points.length - 1].x} ${PADDING.top + chartH} L ${points[0].x} ${PADDING.top + chartH} Z`;
|
|
471
|
-
return /* @__PURE__ */ (0,
|
|
472
|
-
/* @__PURE__ */ (0,
|
|
473
|
-
/* @__PURE__ */ (0,
|
|
474
|
-
/* @__PURE__ */ (0,
|
|
435
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("g", { children: [
|
|
436
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("defs", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("linearGradient", { id: gradientId, x1: "0", y1: "0", x2: "0", y2: "1", children: [
|
|
437
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("stop", { offset: "0%", stopColor: areaColor, stopOpacity: "0.4" }),
|
|
438
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("stop", { offset: "100%", stopColor: areaColor, stopOpacity: "0.02" })
|
|
475
439
|
] }) }),
|
|
476
|
-
/* @__PURE__ */ (0,
|
|
477
|
-
/* @__PURE__ */ (0,
|
|
478
|
-
/* @__PURE__ */ (0,
|
|
440
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("g", { clipPath: animate ? `url(#${curveClipId})` : void 0, children: [
|
|
441
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: areaPath, fill: `url(#${gradientId})` }),
|
|
442
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: linePath, fill: "none", stroke: color, strokeWidth: "2" })
|
|
479
443
|
] }),
|
|
480
|
-
activeIndex !== null && points[activeIndex] && /* @__PURE__ */ (0,
|
|
444
|
+
activeIndex !== null && points[activeIndex] && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
481
445
|
"circle",
|
|
482
446
|
{
|
|
483
447
|
cx: points[activeIndex].x,
|
|
@@ -489,7 +453,7 @@ var CurveChart = import_react2.default.memo(({ data, labels, width, height, anim
|
|
|
489
453
|
)
|
|
490
454
|
] }, di);
|
|
491
455
|
}),
|
|
492
|
-
activeX !== null && /* @__PURE__ */ (0,
|
|
456
|
+
activeX !== null && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
493
457
|
"line",
|
|
494
458
|
{
|
|
495
459
|
x1: activeX,
|
|
@@ -499,7 +463,7 @@ var CurveChart = import_react2.default.memo(({ data, labels, width, height, anim
|
|
|
499
463
|
className: "chart-crosshair"
|
|
500
464
|
}
|
|
501
465
|
),
|
|
502
|
-
/* @__PURE__ */ (0,
|
|
466
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
503
467
|
"rect",
|
|
504
468
|
{
|
|
505
469
|
x: PADDING.left,
|
|
@@ -515,9 +479,9 @@ var CurveChart = import_react2.default.memo(({ data, labels, width, height, anim
|
|
|
515
479
|
);
|
|
516
480
|
});
|
|
517
481
|
CurveChart.displayName = "CurveChart";
|
|
518
|
-
var BarChart =
|
|
519
|
-
const entries =
|
|
520
|
-
const maxVal =
|
|
482
|
+
var BarChart = import_react.default.memo(({ data, labels, width, height, animate, onHover, onShowAt, onMove, onLeave }) => {
|
|
483
|
+
const entries = import_react.default.useMemo(() => Object.entries(data), [data]);
|
|
484
|
+
const maxVal = import_react.default.useMemo(() => {
|
|
521
485
|
const allValues = entries.flatMap(([, v]) => v);
|
|
522
486
|
return Math.max(...allValues) * 1.2 || 1;
|
|
523
487
|
}, [entries]);
|
|
@@ -529,7 +493,7 @@ var BarChart = import_react2.default.memo(({ data, labels, width, height, animat
|
|
|
529
493
|
const barGap = groupCount > 1 ? 2 : 0;
|
|
530
494
|
const barW = Math.max(1, Math.min(32, (groupW * 0.7 - barGap * (groupCount - 1)) / groupCount));
|
|
531
495
|
const baseline = PADDING.top + chartH;
|
|
532
|
-
const bars =
|
|
496
|
+
const bars = import_react.default.useMemo(
|
|
533
497
|
() => entries.map(
|
|
534
498
|
([, values], di) => values.map((v, i) => {
|
|
535
499
|
const totalBarsW = barW * groupCount + barGap * (groupCount - 1);
|
|
@@ -542,11 +506,11 @@ var BarChart = import_react2.default.memo(({ data, labels, width, height, animat
|
|
|
542
506
|
[entries, maxVal, chartH, groupW, barW, barGap, groupCount]
|
|
543
507
|
);
|
|
544
508
|
const barLabelStep = getLabelStep(count, chartW);
|
|
545
|
-
return /* @__PURE__ */ (0,
|
|
546
|
-
/* @__PURE__ */ (0,
|
|
509
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("svg", { viewBox: `0 0 ${width} ${height}`, className: "chart-svg", children: [
|
|
510
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(GridLines, { width, height, chartH, maxVal }),
|
|
547
511
|
labels.map((label, i) => {
|
|
548
512
|
if (i % barLabelStep !== 0) return null;
|
|
549
|
-
return /* @__PURE__ */ (0,
|
|
513
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("text", { x: PADDING.left + groupW * i + groupW / 2, y: height - 8, className: "chart-axis-label", textAnchor: "middle", children: label }, i);
|
|
550
514
|
}),
|
|
551
515
|
entries.map(([key], di) => {
|
|
552
516
|
const palette = getPalette(LINE_BAR_PALETTES, di, key);
|
|
@@ -555,7 +519,7 @@ var BarChart = import_react2.default.memo(({ data, labels, width, height, animat
|
|
|
555
519
|
const r = Math.min(4, b.w / 2);
|
|
556
520
|
const d = b.h <= r ? `M ${b.x} ${b.y + b.h} V ${b.y} H ${b.x + b.w} V ${b.y + b.h} Z` : `M ${b.x} ${b.y + b.h} V ${b.y + r} Q ${b.x} ${b.y} ${b.x + r} ${b.y} H ${b.x + b.w - r} Q ${b.x + b.w} ${b.y} ${b.x + b.w} ${b.y + r} V ${b.y + b.h} Z`;
|
|
557
521
|
const delay = 100 + i * 80;
|
|
558
|
-
return /* @__PURE__ */ (0,
|
|
522
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
559
523
|
"path",
|
|
560
524
|
{
|
|
561
525
|
d,
|
|
@@ -565,8 +529,7 @@ var BarChart = import_react2.default.memo(({ data, labels, width, height, animat
|
|
|
565
529
|
transformOrigin: `${b.x + b.w / 2}px ${baseline}px`,
|
|
566
530
|
animationDelay: `${delay}ms`
|
|
567
531
|
} : void 0,
|
|
568
|
-
onMouseEnter: (
|
|
569
|
-
onMouseMove: onMove,
|
|
532
|
+
onMouseEnter: () => onShowAt(b.x + b.w / 2, b.y, `${key}: ${labels[i]} \u2014 ${b.v}`),
|
|
570
533
|
onMouseLeave: onLeave
|
|
571
534
|
},
|
|
572
535
|
`${di}-${i}`
|
|
@@ -576,11 +539,11 @@ var BarChart = import_react2.default.memo(({ data, labels, width, height, animat
|
|
|
576
539
|
] });
|
|
577
540
|
});
|
|
578
541
|
BarChart.displayName = "BarChart";
|
|
579
|
-
var PieDonutChart =
|
|
542
|
+
var PieDonutChart = import_react.default.memo(
|
|
580
543
|
({ data, labels, width, height, animate, isDoughnut, onHover, onMove, onLeave }) => {
|
|
581
|
-
const entries =
|
|
582
|
-
const values =
|
|
583
|
-
const total =
|
|
544
|
+
const entries = import_react.default.useMemo(() => Object.entries(data), [data]);
|
|
545
|
+
const values = import_react.default.useMemo(() => entries.flatMap(([, v]) => v), [entries]);
|
|
546
|
+
const total = import_react.default.useMemo(() => values.reduce((a, b) => a + b, 0) || 1, [values]);
|
|
584
547
|
const size = Math.min(width, height);
|
|
585
548
|
const cx = size / 2;
|
|
586
549
|
const cy = size / 2;
|
|
@@ -588,10 +551,10 @@ var PieDonutChart = import_react2.default.memo(
|
|
|
588
551
|
const innerR = isDoughnut ? r * 0.5 : 0;
|
|
589
552
|
const firstKey = entries[0]?.[0] ?? "";
|
|
590
553
|
const colorOffset = hashString(firstKey);
|
|
591
|
-
const maskRef =
|
|
554
|
+
const maskRef = import_react.default.useRef(null);
|
|
592
555
|
const maskR = r + 10;
|
|
593
556
|
const maskCircumference = 2 * Math.PI * maskR;
|
|
594
|
-
|
|
557
|
+
import_react.default.useEffect(() => {
|
|
595
558
|
if (!animate || !maskRef.current) return;
|
|
596
559
|
const el = maskRef.current;
|
|
597
560
|
el.style.strokeDasharray = `${maskCircumference}`;
|
|
@@ -601,7 +564,7 @@ var PieDonutChart = import_react2.default.memo(
|
|
|
601
564
|
el.style.strokeDashoffset = "0";
|
|
602
565
|
});
|
|
603
566
|
}, [animate, maskCircumference]);
|
|
604
|
-
const sliceData =
|
|
567
|
+
const sliceData = import_react.default.useMemo(() => {
|
|
605
568
|
let angle0 = -Math.PI / 2;
|
|
606
569
|
let cumulativeAngle = 0;
|
|
607
570
|
return values.map((v, i) => {
|
|
@@ -635,8 +598,8 @@ var PieDonutChart = import_react2.default.memo(
|
|
|
635
598
|
});
|
|
636
599
|
}, [values, total, cx, cy, r, innerR, labels]);
|
|
637
600
|
const maskId = `pie-mask-${isDoughnut ? "d" : "p"}`;
|
|
638
|
-
return /* @__PURE__ */ (0,
|
|
639
|
-
animate && /* @__PURE__ */ (0,
|
|
601
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("svg", { viewBox: `0 0 ${size} ${size}`, className: "chart-svg chart-pie", children: [
|
|
602
|
+
animate && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("defs", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("mask", { id: maskId, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
640
603
|
"circle",
|
|
641
604
|
{
|
|
642
605
|
ref: maskRef,
|
|
@@ -649,56 +612,39 @@ var PieDonutChart = import_react2.default.memo(
|
|
|
649
612
|
transform: `rotate(-90 ${cx} ${cy})`
|
|
650
613
|
}
|
|
651
614
|
) }) }),
|
|
652
|
-
/* @__PURE__ */ (0,
|
|
615
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("g", { mask: animate ? `url(#${maskId})` : void 0, children: sliceData.map((s, i) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("g", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
653
616
|
"path",
|
|
654
617
|
{
|
|
655
618
|
d: s.d,
|
|
656
619
|
fill: PIE_COLORS[(i + colorOffset) % PIE_COLORS.length],
|
|
657
|
-
className: "chart-slice"
|
|
658
|
-
onMouseEnter: (e) => onHover(e, `${s.label}: ${s.v} (${s.pct}%)`),
|
|
659
|
-
onMouseMove: onMove,
|
|
660
|
-
onMouseLeave: onLeave
|
|
620
|
+
className: "chart-slice"
|
|
661
621
|
}
|
|
662
|
-
) }, i)) })
|
|
663
|
-
sliceData.map((s, i) => s.angle > 0.2 && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
664
|
-
"text",
|
|
665
|
-
{
|
|
666
|
-
x: s.lx,
|
|
667
|
-
y: s.ly,
|
|
668
|
-
className: `chart-pie-label ${animate ? "chart-pie-label-animate" : ""}`,
|
|
669
|
-
style: animate ? { animationDelay: `${s.labelDelay}ms` } : void 0,
|
|
670
|
-
textAnchor: "middle",
|
|
671
|
-
dominantBaseline: "central",
|
|
672
|
-
children: s.v
|
|
673
|
-
},
|
|
674
|
-
`label-${i}`
|
|
675
|
-
))
|
|
622
|
+
) }, i)) })
|
|
676
623
|
] });
|
|
677
624
|
}
|
|
678
625
|
);
|
|
679
626
|
PieDonutChart.displayName = "PieDonutChart";
|
|
680
|
-
var
|
|
681
|
-
const ref =
|
|
682
|
-
const [pos, setPos] =
|
|
683
|
-
|
|
627
|
+
var ChartTooltip = ({ x, y, containerWidth, containerHeight, children }) => {
|
|
628
|
+
const ref = import_react.default.useRef(null);
|
|
629
|
+
const [pos, setPos] = import_react.default.useState({ left: 0, top: 0 });
|
|
630
|
+
import_react.default.useLayoutEffect(() => {
|
|
684
631
|
const el = ref.current;
|
|
685
632
|
if (!el) return;
|
|
686
633
|
const w = el.offsetWidth;
|
|
687
634
|
const h = el.offsetHeight;
|
|
688
|
-
|
|
689
|
-
let
|
|
690
|
-
|
|
691
|
-
if (
|
|
692
|
-
if (
|
|
693
|
-
if (left < 8) left = 8;
|
|
635
|
+
let left = x + TOOLTIP_OFFSET;
|
|
636
|
+
let top = y - h - TOOLTIP_OFFSET;
|
|
637
|
+
if (left + w > containerWidth) left = x - w - TOOLTIP_OFFSET;
|
|
638
|
+
if (top < 0) top = y + TOOLTIP_OFFSET;
|
|
639
|
+
if (left < 0) left = 0;
|
|
694
640
|
setPos({ left, top });
|
|
695
|
-
}, [
|
|
696
|
-
return /* @__PURE__ */ (0,
|
|
641
|
+
}, [x, y, containerWidth, containerHeight]);
|
|
642
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
697
643
|
"div",
|
|
698
644
|
{
|
|
699
645
|
ref,
|
|
700
|
-
className:
|
|
701
|
-
style: {
|
|
646
|
+
className: "chart-tooltip chart-tooltip-show",
|
|
647
|
+
style: { left: pos.left, top: pos.top },
|
|
702
648
|
children
|
|
703
649
|
}
|
|
704
650
|
);
|
|
@@ -710,14 +656,14 @@ var ChartLegend = ({ data, labels, type }) => {
|
|
|
710
656
|
const total = values.reduce((a, b) => a + b, 0) || 1;
|
|
711
657
|
const firstKey = entries[0]?.[0] ?? "";
|
|
712
658
|
const colorOffset = hashString(firstKey);
|
|
713
|
-
return /* @__PURE__ */ (0,
|
|
659
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "chart-legend", children: values.map((v, i) => {
|
|
714
660
|
const pct = Math.round(v / total * 100);
|
|
715
661
|
const color = PIE_COLORS[(i + colorOffset) % PIE_COLORS.length];
|
|
716
|
-
return /* @__PURE__ */ (0,
|
|
717
|
-
/* @__PURE__ */ (0,
|
|
718
|
-
/* @__PURE__ */ (0,
|
|
719
|
-
/* @__PURE__ */ (0,
|
|
720
|
-
/* @__PURE__ */ (0,
|
|
662
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "chart-legend-item", children: [
|
|
663
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "chart-legend-dot", style: { backgroundColor: color } }),
|
|
664
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "chart-legend-text", children: [
|
|
665
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "chart-legend-label", children: labels[i] || `${i + 1}` }),
|
|
666
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: "chart-legend-value", children: [
|
|
721
667
|
v.toLocaleString(),
|
|
722
668
|
"(",
|
|
723
669
|
pct,
|
|
@@ -727,37 +673,37 @@ var ChartLegend = ({ data, labels, type }) => {
|
|
|
727
673
|
] }, i);
|
|
728
674
|
}) });
|
|
729
675
|
}
|
|
730
|
-
return /* @__PURE__ */ (0,
|
|
676
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "chart-legend", children: entries.map(([key], di) => {
|
|
731
677
|
const palette = getPalette(LINE_BAR_PALETTES, di, key);
|
|
732
678
|
const color = palette[2];
|
|
733
679
|
const values = entries[di][1];
|
|
734
680
|
const sum = values.reduce((a, b) => a + b, 0);
|
|
735
|
-
return /* @__PURE__ */ (0,
|
|
736
|
-
/* @__PURE__ */ (0,
|
|
737
|
-
/* @__PURE__ */ (0,
|
|
738
|
-
/* @__PURE__ */ (0,
|
|
739
|
-
/* @__PURE__ */ (0,
|
|
681
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "chart-legend-item", children: [
|
|
682
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "chart-legend-dot", style: { backgroundColor: color } }),
|
|
683
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "chart-legend-text", children: [
|
|
684
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "chart-legend-label", children: key }),
|
|
685
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "chart-legend-value", children: sum.toLocaleString() })
|
|
740
686
|
] })
|
|
741
687
|
] }, di);
|
|
742
688
|
}) });
|
|
743
689
|
};
|
|
744
|
-
var Chart =
|
|
690
|
+
var Chart = import_react.default.memo((props) => {
|
|
745
691
|
const { type, data, labels, tooltip: showTooltip = true } = props;
|
|
746
|
-
const { tooltip, show, hide, move, containerRef } = useChartTooltip(showTooltip);
|
|
692
|
+
const { tooltip, show, showAt, hide, move, containerRef } = useChartTooltip(showTooltip);
|
|
747
693
|
const { width, height } = useChartSize(containerRef);
|
|
748
|
-
const stableData =
|
|
749
|
-
const stableLabels =
|
|
750
|
-
const dataKey =
|
|
694
|
+
const stableData = import_react.default.useMemo(() => data, [JSON.stringify(data)]);
|
|
695
|
+
const stableLabels = import_react.default.useMemo(() => labels, [JSON.stringify(labels)]);
|
|
696
|
+
const dataKey = import_react.default.useMemo(() => JSON.stringify(labels), [labels]);
|
|
751
697
|
const animate = useChartAnimation(containerRef, dataKey);
|
|
752
698
|
const ready = width > 0 && height > 0;
|
|
753
|
-
return /* @__PURE__ */ (0,
|
|
754
|
-
ready && type === "line" && /* @__PURE__ */ (0,
|
|
755
|
-
ready && type === "curve" && /* @__PURE__ */ (0,
|
|
756
|
-
ready && type === "bar" && /* @__PURE__ */ (0,
|
|
757
|
-
ready && type === "pie" && /* @__PURE__ */ (0,
|
|
758
|
-
ready && type === "doughnut" && /* @__PURE__ */ (0,
|
|
759
|
-
ready && (type === "bar" || type === "pie" || type === "doughnut") && /* @__PURE__ */ (0,
|
|
760
|
-
tooltip.content && /* @__PURE__ */ (0,
|
|
699
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "lib-xplat-chart", ref: containerRef, children: [
|
|
700
|
+
ready && type === "line" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LineChart, { data: stableData, labels: stableLabels, width, height, animate, onHover: show, onShowAt: showAt, onMove: move, onLeave: hide }),
|
|
701
|
+
ready && type === "curve" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CurveChart, { data: stableData, labels: stableLabels, width, height, animate, onHover: show, onShowAt: showAt, onMove: move, onLeave: hide }),
|
|
702
|
+
ready && type === "bar" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(BarChart, { data: stableData, labels: stableLabels, width, height, animate, onHover: show, onShowAt: showAt, onMove: move, onLeave: hide }),
|
|
703
|
+
ready && type === "pie" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PieDonutChart, { data: stableData, labels: stableLabels, width, height, animate, onHover: show, onShowAt: showAt, onMove: move, onLeave: hide }),
|
|
704
|
+
ready && type === "doughnut" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PieDonutChart, { data: stableData, labels: stableLabels, width, height, animate, isDoughnut: true, onHover: show, onShowAt: showAt, onMove: move, onLeave: hide }),
|
|
705
|
+
ready && (type === "bar" || type === "pie" || type === "doughnut") && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ChartLegend, { data: stableData, labels: stableLabels, type }),
|
|
706
|
+
tooltip.visible && tooltip.content && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ChartTooltip, { x: tooltip.x, y: tooltip.y, containerWidth: width, containerHeight: height, children: tooltip.content })
|
|
761
707
|
] });
|
|
762
708
|
});
|
|
763
709
|
Chart.displayName = "Chart";
|