@x-plat/design-system 0.5.32 → 0.5.34
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 +148 -144
- package/dist/components/Chart/index.css +54 -10
- package/dist/components/Chart/index.js +148 -144
- package/dist/components/index.cjs +148 -144
- package/dist/components/index.css +54 -10
- package/dist/components/index.js +148 -144
- package/dist/index.cjs +148 -144
- package/dist/index.css +54 -10
- package/dist/index.js +148 -144
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -6346,45 +6346,35 @@ var useChartAnimation = (containerRef, dataKey) => {
|
|
|
6346
6346
|
prevDataKey.current = dataKey;
|
|
6347
6347
|
if (prefersReducedMotion()) return;
|
|
6348
6348
|
setAnimate(false);
|
|
6349
|
-
requestAnimationFrame(() =>
|
|
6349
|
+
requestAnimationFrame(() => {
|
|
6350
|
+
requestAnimationFrame(() => setAnimate(true));
|
|
6351
|
+
});
|
|
6350
6352
|
}
|
|
6351
6353
|
}, [dataKey]);
|
|
6352
6354
|
return animate || prefersReducedMotion();
|
|
6353
6355
|
};
|
|
6356
|
+
var TOOLTIP_OFFSET = 12;
|
|
6354
6357
|
var useChartTooltip = (enabled) => {
|
|
6355
6358
|
const [tooltip, setTooltip] = React6.useState({
|
|
6356
6359
|
visible: false,
|
|
6357
|
-
|
|
6358
|
-
|
|
6360
|
+
clientX: 0,
|
|
6361
|
+
clientY: 0,
|
|
6359
6362
|
content: ""
|
|
6360
6363
|
});
|
|
6361
6364
|
const containerRef = React6.useRef(null);
|
|
6362
6365
|
const rafRef = React6.useRef(0);
|
|
6363
6366
|
const move = React6.useCallback((e) => {
|
|
6364
6367
|
if (!enabled) return;
|
|
6365
|
-
const
|
|
6366
|
-
const
|
|
6368
|
+
const cx = e.clientX;
|
|
6369
|
+
const cy = e.clientY;
|
|
6367
6370
|
cancelAnimationFrame(rafRef.current);
|
|
6368
6371
|
rafRef.current = requestAnimationFrame(() => {
|
|
6369
|
-
|
|
6370
|
-
if (!rect) return;
|
|
6371
|
-
setTooltip((prev) => ({
|
|
6372
|
-
...prev,
|
|
6373
|
-
x: clientX - rect.left,
|
|
6374
|
-
y: clientY - rect.top - 12
|
|
6375
|
-
}));
|
|
6372
|
+
setTooltip((prev) => ({ ...prev, clientX: cx, clientY: cy }));
|
|
6376
6373
|
});
|
|
6377
6374
|
}, [enabled]);
|
|
6378
6375
|
const show = React6.useCallback((e, content) => {
|
|
6379
6376
|
if (!enabled) return;
|
|
6380
|
-
|
|
6381
|
-
if (!rect) return;
|
|
6382
|
-
setTooltip({
|
|
6383
|
-
visible: true,
|
|
6384
|
-
x: e.clientX - rect.left,
|
|
6385
|
-
y: e.clientY - rect.top - 12,
|
|
6386
|
-
content
|
|
6387
|
-
});
|
|
6377
|
+
setTooltip({ visible: true, clientX: e.clientX, clientY: e.clientY, content });
|
|
6388
6378
|
}, [enabled]);
|
|
6389
6379
|
const hide = React6.useCallback(() => {
|
|
6390
6380
|
cancelAnimationFrame(rafRef.current);
|
|
@@ -6418,14 +6408,14 @@ var AxisLabels = React6.memo(({ labels, count, chartW, height }) => {
|
|
|
6418
6408
|
AxisLabels.displayName = "AxisLabels";
|
|
6419
6409
|
var useCrosshair = (seriesPoints, entries, labels, chartH) => {
|
|
6420
6410
|
const [activeIndex, setActiveIndex] = React6.useState(null);
|
|
6421
|
-
const [mouseX, setMouseX] = React6.useState(null);
|
|
6422
6411
|
const handleMouseMove = React6.useCallback((e) => {
|
|
6423
6412
|
const svg = e.currentTarget;
|
|
6424
6413
|
const rect = svg.getBoundingClientRect();
|
|
6425
6414
|
const mx = (e.clientX - rect.left) / rect.width * svg.viewBox.baseVal.width;
|
|
6426
|
-
setMouseX(mx);
|
|
6427
6415
|
if (seriesPoints.length === 0 || seriesPoints[0].length === 0) return;
|
|
6428
6416
|
const points = seriesPoints[0];
|
|
6417
|
+
const step = points.length > 1 ? Math.abs(points[1].x - points[0].x) : 20;
|
|
6418
|
+
const threshold = step / 2;
|
|
6429
6419
|
let closest = 0;
|
|
6430
6420
|
let minDist = Math.abs(points[0].x - mx);
|
|
6431
6421
|
for (let i = 1; i < points.length; i++) {
|
|
@@ -6435,11 +6425,10 @@ var useCrosshair = (seriesPoints, entries, labels, chartH) => {
|
|
|
6435
6425
|
closest = i;
|
|
6436
6426
|
}
|
|
6437
6427
|
}
|
|
6438
|
-
setActiveIndex(closest);
|
|
6428
|
+
setActiveIndex(minDist <= threshold ? closest : null);
|
|
6439
6429
|
}, [seriesPoints]);
|
|
6440
6430
|
const handleMouseLeave = React6.useCallback(() => {
|
|
6441
6431
|
setActiveIndex(null);
|
|
6442
|
-
setMouseX(null);
|
|
6443
6432
|
}, []);
|
|
6444
6433
|
const tooltipContent = React6.useMemo(() => {
|
|
6445
6434
|
if (activeIndex === null) return "";
|
|
@@ -6448,7 +6437,13 @@ var useCrosshair = (seriesPoints, entries, labels, chartH) => {
|
|
|
6448
6437
|
return p ? `${key}: ${p.v}` : "";
|
|
6449
6438
|
}).filter(Boolean).join(" / ");
|
|
6450
6439
|
}, [activeIndex, entries, seriesPoints]);
|
|
6451
|
-
|
|
6440
|
+
const getTooltipAt = React6.useCallback((idx) => {
|
|
6441
|
+
return entries.map(([key], di) => {
|
|
6442
|
+
const p = seriesPoints[di]?.[idx];
|
|
6443
|
+
return p ? `${key}: ${p.v}` : "";
|
|
6444
|
+
}).filter(Boolean).join(" / ");
|
|
6445
|
+
}, [entries, seriesPoints]);
|
|
6446
|
+
return { activeIndex, handleMouseMove, handleMouseLeave, tooltipContent, getTooltipAt };
|
|
6452
6447
|
};
|
|
6453
6448
|
var LineChart = React6.memo(({ data, labels, width, height, animate, onHover, onMove, onLeave }) => {
|
|
6454
6449
|
const entries = React6.useMemo(() => Object.entries(data), [data]);
|
|
@@ -6469,33 +6464,19 @@ var LineChart = React6.memo(({ data, labels, width, height, animate, onHover, on
|
|
|
6469
6464
|
),
|
|
6470
6465
|
[entries, count, chartW, chartH, maxVal]
|
|
6471
6466
|
);
|
|
6472
|
-
const lineRefs = React6.useRef([]);
|
|
6473
6467
|
const clipRef = React6.useRef(null);
|
|
6474
|
-
const { activeIndex,
|
|
6468
|
+
const { activeIndex, handleMouseMove, handleMouseLeave, getTooltipAt } = useCrosshair(seriesPoints, entries, labels, chartH);
|
|
6475
6469
|
React6.useEffect(() => {
|
|
6476
|
-
if (!animate) return;
|
|
6477
|
-
|
|
6478
|
-
|
|
6479
|
-
|
|
6480
|
-
|
|
6481
|
-
|
|
6482
|
-
|
|
6483
|
-
el.style.transition = "stroke-dashoffset 1200ms ease-out 200ms";
|
|
6484
|
-
el.style.strokeDashoffset = "0";
|
|
6485
|
-
});
|
|
6470
|
+
if (!animate || !clipRef.current) return;
|
|
6471
|
+
clipRef.current.setAttribute("width", "0");
|
|
6472
|
+
requestAnimationFrame(() => {
|
|
6473
|
+
if (clipRef.current) {
|
|
6474
|
+
clipRef.current.style.transition = "width 1200ms ease-out 200ms";
|
|
6475
|
+
clipRef.current.setAttribute("width", `${width}`);
|
|
6476
|
+
}
|
|
6486
6477
|
});
|
|
6487
|
-
|
|
6488
|
-
|
|
6489
|
-
requestAnimationFrame(() => {
|
|
6490
|
-
if (clipRef.current) {
|
|
6491
|
-
clipRef.current.style.transition = "width 1200ms ease-out 200ms";
|
|
6492
|
-
clipRef.current.setAttribute("width", `${width}`);
|
|
6493
|
-
}
|
|
6494
|
-
});
|
|
6495
|
-
}
|
|
6496
|
-
}, [animate, seriesPoints, width]);
|
|
6497
|
-
const guideX = mouseX != null && mouseX >= PADDING.left && mouseX <= width - PADDING.right ? mouseX : null;
|
|
6498
|
-
const activeX = activeIndex !== null ? seriesPoints[0]?.[activeIndex]?.x : null;
|
|
6478
|
+
}, [animate, width]);
|
|
6479
|
+
const activeX = activeIndex !== null ? seriesPoints[0]?.[activeIndex]?.x ?? null : null;
|
|
6499
6480
|
const lineClipId = "line-area-clip";
|
|
6500
6481
|
return /* @__PURE__ */ jsxs197(
|
|
6501
6482
|
"svg",
|
|
@@ -6504,7 +6485,26 @@ var LineChart = React6.memo(({ data, labels, width, height, animate, onHover, on
|
|
|
6504
6485
|
className: "chart-svg",
|
|
6505
6486
|
onMouseMove: (e) => {
|
|
6506
6487
|
handleMouseMove(e);
|
|
6507
|
-
|
|
6488
|
+
const svg = e.currentTarget;
|
|
6489
|
+
const rect = svg.getBoundingClientRect();
|
|
6490
|
+
const mx = (e.clientX - rect.left) / rect.width * svg.viewBox.baseVal.width;
|
|
6491
|
+
const points = seriesPoints[0];
|
|
6492
|
+
if (!points || points.length === 0) return;
|
|
6493
|
+
const step = points.length > 1 ? Math.abs(points[1].x - points[0].x) : 20;
|
|
6494
|
+
let closest = 0;
|
|
6495
|
+
let minDist = Math.abs(points[0].x - mx);
|
|
6496
|
+
for (let i = 1; i < points.length; i++) {
|
|
6497
|
+
const dist = Math.abs(points[i].x - mx);
|
|
6498
|
+
if (dist < minDist) {
|
|
6499
|
+
minDist = dist;
|
|
6500
|
+
closest = i;
|
|
6501
|
+
}
|
|
6502
|
+
}
|
|
6503
|
+
if (minDist <= step / 2) {
|
|
6504
|
+
onHover(e, `${labels[closest]} \u2014 ${getTooltipAt(closest)}`);
|
|
6505
|
+
} else {
|
|
6506
|
+
onLeave();
|
|
6507
|
+
}
|
|
6508
6508
|
},
|
|
6509
6509
|
onMouseLeave: () => {
|
|
6510
6510
|
handleMouseLeave();
|
|
@@ -6527,26 +6527,10 @@ var LineChart = React6.memo(({ data, labels, width, height, animate, onHover, on
|
|
|
6527
6527
|
/* @__PURE__ */ jsx307("stop", { offset: "0%", stopColor: areaColor, stopOpacity: "0.2" }),
|
|
6528
6528
|
/* @__PURE__ */ jsx307("stop", { offset: "100%", stopColor: areaColor, stopOpacity: "0" })
|
|
6529
6529
|
] }) }),
|
|
6530
|
-
/* @__PURE__ */
|
|
6531
|
-
"path",
|
|
6532
|
-
{
|
|
6533
|
-
|
|
6534
|
-
fill: `url(#${gradientId})`,
|
|
6535
|
-
clipPath: animate ? `url(#${lineClipId})` : void 0
|
|
6536
|
-
}
|
|
6537
|
-
),
|
|
6538
|
-
/* @__PURE__ */ jsx307(
|
|
6539
|
-
"polyline",
|
|
6540
|
-
{
|
|
6541
|
-
ref: (el) => {
|
|
6542
|
-
lineRefs.current[di] = el;
|
|
6543
|
-
},
|
|
6544
|
-
points: polyPoints,
|
|
6545
|
-
fill: "none",
|
|
6546
|
-
stroke: color,
|
|
6547
|
-
strokeWidth: "2"
|
|
6548
|
-
}
|
|
6549
|
-
),
|
|
6530
|
+
/* @__PURE__ */ jsxs197("g", { clipPath: animate ? `url(#${lineClipId})` : void 0, children: [
|
|
6531
|
+
/* @__PURE__ */ jsx307("path", { d: areaD, fill: `url(#${gradientId})` }),
|
|
6532
|
+
/* @__PURE__ */ jsx307("polyline", { points: polyPoints, fill: "none", stroke: color, strokeWidth: "2" })
|
|
6533
|
+
] }),
|
|
6550
6534
|
activeIndex !== null && points[activeIndex] && /* @__PURE__ */ jsx307(
|
|
6551
6535
|
"circle",
|
|
6552
6536
|
{
|
|
@@ -6559,21 +6543,16 @@ var LineChart = React6.memo(({ data, labels, width, height, animate, onHover, on
|
|
|
6559
6543
|
)
|
|
6560
6544
|
] }, di);
|
|
6561
6545
|
}),
|
|
6562
|
-
|
|
6546
|
+
activeX !== null && /* @__PURE__ */ jsx307(
|
|
6563
6547
|
"line",
|
|
6564
6548
|
{
|
|
6565
|
-
x1:
|
|
6549
|
+
x1: activeX,
|
|
6566
6550
|
y1: PADDING.top,
|
|
6567
|
-
x2:
|
|
6551
|
+
x2: activeX,
|
|
6568
6552
|
y2: PADDING.top + chartH,
|
|
6569
6553
|
className: "chart-crosshair"
|
|
6570
6554
|
}
|
|
6571
6555
|
),
|
|
6572
|
-
activeIndex !== null && activeX !== null && /* @__PURE__ */ jsx307("foreignObject", { x: activeX - 100, y: 0, width: "200", height: PADDING.top, children: /* @__PURE__ */ jsxs197("div", { className: "chart-crosshair-label", children: [
|
|
6573
|
-
labels[activeIndex],
|
|
6574
|
-
" \u2014 ",
|
|
6575
|
-
tooltipContent
|
|
6576
|
-
] }) }),
|
|
6577
6556
|
/* @__PURE__ */ jsx307(
|
|
6578
6557
|
"rect",
|
|
6579
6558
|
{
|
|
@@ -6609,33 +6588,19 @@ var CurveChart = React6.memo(({ data, labels, width, height, animate, onHover, o
|
|
|
6609
6588
|
),
|
|
6610
6589
|
[entries, count, chartW, chartH, maxVal]
|
|
6611
6590
|
);
|
|
6612
|
-
const lineRefs = React6.useRef([]);
|
|
6613
6591
|
const curveClipRef = React6.useRef(null);
|
|
6614
|
-
const { activeIndex,
|
|
6592
|
+
const { activeIndex, handleMouseMove, handleMouseLeave, getTooltipAt } = useCrosshair(seriesPoints, entries, labels, chartH);
|
|
6615
6593
|
React6.useEffect(() => {
|
|
6616
|
-
if (!animate) return;
|
|
6617
|
-
|
|
6618
|
-
|
|
6619
|
-
|
|
6620
|
-
|
|
6621
|
-
|
|
6622
|
-
|
|
6623
|
-
el.style.transition = "stroke-dashoffset 1200ms ease-out 200ms";
|
|
6624
|
-
el.style.strokeDashoffset = "0";
|
|
6625
|
-
});
|
|
6594
|
+
if (!animate || !curveClipRef.current) return;
|
|
6595
|
+
curveClipRef.current.setAttribute("width", "0");
|
|
6596
|
+
requestAnimationFrame(() => {
|
|
6597
|
+
if (curveClipRef.current) {
|
|
6598
|
+
curveClipRef.current.style.transition = "width 1200ms ease-out 200ms";
|
|
6599
|
+
curveClipRef.current.setAttribute("width", `${width}`);
|
|
6600
|
+
}
|
|
6626
6601
|
});
|
|
6627
|
-
|
|
6628
|
-
|
|
6629
|
-
requestAnimationFrame(() => {
|
|
6630
|
-
if (curveClipRef.current) {
|
|
6631
|
-
curveClipRef.current.style.transition = "width 1200ms ease-out 200ms";
|
|
6632
|
-
curveClipRef.current.setAttribute("width", `${width}`);
|
|
6633
|
-
}
|
|
6634
|
-
});
|
|
6635
|
-
}
|
|
6636
|
-
}, [animate, seriesPoints, width]);
|
|
6637
|
-
const guideX = mouseX != null && mouseX >= PADDING.left && mouseX <= width - PADDING.right ? mouseX : null;
|
|
6638
|
-
const activeX = activeIndex !== null ? seriesPoints[0]?.[activeIndex]?.x : null;
|
|
6602
|
+
}, [animate, width]);
|
|
6603
|
+
const activeX = activeIndex !== null ? seriesPoints[0]?.[activeIndex]?.x ?? null : null;
|
|
6639
6604
|
const curveClipId = "curve-area-clip";
|
|
6640
6605
|
return /* @__PURE__ */ jsxs197(
|
|
6641
6606
|
"svg",
|
|
@@ -6644,7 +6609,26 @@ var CurveChart = React6.memo(({ data, labels, width, height, animate, onHover, o
|
|
|
6644
6609
|
className: "chart-svg",
|
|
6645
6610
|
onMouseMove: (e) => {
|
|
6646
6611
|
handleMouseMove(e);
|
|
6647
|
-
|
|
6612
|
+
const svg = e.currentTarget;
|
|
6613
|
+
const rect = svg.getBoundingClientRect();
|
|
6614
|
+
const mx = (e.clientX - rect.left) / rect.width * svg.viewBox.baseVal.width;
|
|
6615
|
+
const points = seriesPoints[0];
|
|
6616
|
+
if (!points || points.length === 0) return;
|
|
6617
|
+
const step = points.length > 1 ? Math.abs(points[1].x - points[0].x) : 20;
|
|
6618
|
+
let closest = 0;
|
|
6619
|
+
let minDist = Math.abs(points[0].x - mx);
|
|
6620
|
+
for (let i = 1; i < points.length; i++) {
|
|
6621
|
+
const dist = Math.abs(points[i].x - mx);
|
|
6622
|
+
if (dist < minDist) {
|
|
6623
|
+
minDist = dist;
|
|
6624
|
+
closest = i;
|
|
6625
|
+
}
|
|
6626
|
+
}
|
|
6627
|
+
if (minDist <= step / 2) {
|
|
6628
|
+
onHover(e, `${labels[closest]} \u2014 ${getTooltipAt(closest)}`);
|
|
6629
|
+
} else {
|
|
6630
|
+
onLeave();
|
|
6631
|
+
}
|
|
6648
6632
|
},
|
|
6649
6633
|
onMouseLeave: () => {
|
|
6650
6634
|
handleMouseLeave();
|
|
@@ -6667,26 +6651,10 @@ var CurveChart = React6.memo(({ data, labels, width, height, animate, onHover, o
|
|
|
6667
6651
|
/* @__PURE__ */ jsx307("stop", { offset: "0%", stopColor: areaColor, stopOpacity: "0.4" }),
|
|
6668
6652
|
/* @__PURE__ */ jsx307("stop", { offset: "100%", stopColor: areaColor, stopOpacity: "0.02" })
|
|
6669
6653
|
] }) }),
|
|
6670
|
-
/* @__PURE__ */
|
|
6671
|
-
"path",
|
|
6672
|
-
{
|
|
6673
|
-
|
|
6674
|
-
fill: `url(#${gradientId})`,
|
|
6675
|
-
clipPath: animate ? `url(#${curveClipId})` : void 0
|
|
6676
|
-
}
|
|
6677
|
-
),
|
|
6678
|
-
/* @__PURE__ */ jsx307(
|
|
6679
|
-
"path",
|
|
6680
|
-
{
|
|
6681
|
-
ref: (el) => {
|
|
6682
|
-
lineRefs.current[di] = el;
|
|
6683
|
-
},
|
|
6684
|
-
d: linePath,
|
|
6685
|
-
fill: "none",
|
|
6686
|
-
stroke: color,
|
|
6687
|
-
strokeWidth: "2"
|
|
6688
|
-
}
|
|
6689
|
-
),
|
|
6654
|
+
/* @__PURE__ */ jsxs197("g", { clipPath: animate ? `url(#${curveClipId})` : void 0, children: [
|
|
6655
|
+
/* @__PURE__ */ jsx307("path", { d: areaPath, fill: `url(#${gradientId})` }),
|
|
6656
|
+
/* @__PURE__ */ jsx307("path", { d: linePath, fill: "none", stroke: color, strokeWidth: "2" })
|
|
6657
|
+
] }),
|
|
6690
6658
|
activeIndex !== null && points[activeIndex] && /* @__PURE__ */ jsx307(
|
|
6691
6659
|
"circle",
|
|
6692
6660
|
{
|
|
@@ -6699,21 +6667,16 @@ var CurveChart = React6.memo(({ data, labels, width, height, animate, onHover, o
|
|
|
6699
6667
|
)
|
|
6700
6668
|
] }, di);
|
|
6701
6669
|
}),
|
|
6702
|
-
|
|
6670
|
+
activeX !== null && /* @__PURE__ */ jsx307(
|
|
6703
6671
|
"line",
|
|
6704
6672
|
{
|
|
6705
|
-
x1:
|
|
6673
|
+
x1: activeX,
|
|
6706
6674
|
y1: PADDING.top,
|
|
6707
|
-
x2:
|
|
6675
|
+
x2: activeX,
|
|
6708
6676
|
y2: PADDING.top + chartH,
|
|
6709
6677
|
className: "chart-crosshair"
|
|
6710
6678
|
}
|
|
6711
6679
|
),
|
|
6712
|
-
activeIndex !== null && activeX !== null && /* @__PURE__ */ jsx307("foreignObject", { x: activeX - 100, y: 0, width: "200", height: PADDING.top, children: /* @__PURE__ */ jsxs197("div", { className: "chart-crosshair-label", children: [
|
|
6713
|
-
labels[activeIndex],
|
|
6714
|
-
" \u2014 ",
|
|
6715
|
-
tooltipContent
|
|
6716
|
-
] }) }),
|
|
6717
6680
|
/* @__PURE__ */ jsx307(
|
|
6718
6681
|
"rect",
|
|
6719
6682
|
{
|
|
@@ -6892,30 +6855,70 @@ var PieDonutChart = React6.memo(
|
|
|
6892
6855
|
}
|
|
6893
6856
|
);
|
|
6894
6857
|
PieDonutChart.displayName = "PieDonutChart";
|
|
6895
|
-
var
|
|
6858
|
+
var ChartTooltipPortal = ({ clientX, clientY, visible, children }) => {
|
|
6896
6859
|
const ref = React6.useRef(null);
|
|
6897
|
-
const [
|
|
6898
|
-
React6.
|
|
6860
|
+
const [pos, setPos] = React6.useState({ left: 0, top: 0 });
|
|
6861
|
+
React6.useLayoutEffect(() => {
|
|
6899
6862
|
const el = ref.current;
|
|
6900
6863
|
if (!el) return;
|
|
6901
6864
|
const w = el.offsetWidth;
|
|
6902
|
-
const
|
|
6903
|
-
const
|
|
6904
|
-
let
|
|
6905
|
-
|
|
6906
|
-
|
|
6907
|
-
|
|
6908
|
-
|
|
6865
|
+
const h = el.offsetHeight;
|
|
6866
|
+
const vw = window.innerWidth;
|
|
6867
|
+
let left = clientX + TOOLTIP_OFFSET;
|
|
6868
|
+
let top = clientY - h - TOOLTIP_OFFSET;
|
|
6869
|
+
if (left + w > vw - 8) left = clientX - w - TOOLTIP_OFFSET;
|
|
6870
|
+
if (top < 8) top = clientY + TOOLTIP_OFFSET;
|
|
6871
|
+
if (left < 8) left = 8;
|
|
6872
|
+
setPos({ left, top });
|
|
6873
|
+
}, [clientX, clientY]);
|
|
6909
6874
|
return /* @__PURE__ */ jsx307(
|
|
6910
6875
|
"div",
|
|
6911
6876
|
{
|
|
6912
6877
|
ref,
|
|
6913
|
-
className: "chart-tooltip"
|
|
6914
|
-
style: { left:
|
|
6878
|
+
className: `chart-tooltip ${visible ? "chart-tooltip-show" : "chart-tooltip-hide"}`,
|
|
6879
|
+
style: { position: "fixed", left: pos.left, top: pos.top, zIndex: 1100 },
|
|
6915
6880
|
children
|
|
6916
6881
|
}
|
|
6917
6882
|
);
|
|
6918
6883
|
};
|
|
6884
|
+
var ChartLegend = ({ data, labels, type }) => {
|
|
6885
|
+
const entries = Object.entries(data);
|
|
6886
|
+
if (type === "pie" || type === "doughnut") {
|
|
6887
|
+
const values = entries.flatMap(([, v]) => v);
|
|
6888
|
+
const total = values.reduce((a, b) => a + b, 0) || 1;
|
|
6889
|
+
const firstKey = entries[0]?.[0] ?? "";
|
|
6890
|
+
const colorOffset = hashString(firstKey);
|
|
6891
|
+
return /* @__PURE__ */ jsx307("div", { className: "chart-legend", children: values.map((v, i) => {
|
|
6892
|
+
const pct = Math.round(v / total * 100);
|
|
6893
|
+
const color = PIE_COLORS[(i + colorOffset) % PIE_COLORS.length];
|
|
6894
|
+
return /* @__PURE__ */ jsxs197("div", { className: "chart-legend-item", children: [
|
|
6895
|
+
/* @__PURE__ */ jsx307("span", { className: "chart-legend-dot", style: { backgroundColor: color } }),
|
|
6896
|
+
/* @__PURE__ */ jsxs197("div", { className: "chart-legend-text", children: [
|
|
6897
|
+
/* @__PURE__ */ jsx307("span", { className: "chart-legend-label", children: labels[i] || `${i + 1}` }),
|
|
6898
|
+
/* @__PURE__ */ jsxs197("span", { className: "chart-legend-value", children: [
|
|
6899
|
+
v.toLocaleString(),
|
|
6900
|
+
"(",
|
|
6901
|
+
pct,
|
|
6902
|
+
"%)"
|
|
6903
|
+
] })
|
|
6904
|
+
] })
|
|
6905
|
+
] }, i);
|
|
6906
|
+
}) });
|
|
6907
|
+
}
|
|
6908
|
+
return /* @__PURE__ */ jsx307("div", { className: "chart-legend", children: entries.map(([key], di) => {
|
|
6909
|
+
const palette = getPalette(LINE_BAR_PALETTES, di, key);
|
|
6910
|
+
const color = palette[2];
|
|
6911
|
+
const values = entries[di][1];
|
|
6912
|
+
const sum = values.reduce((a, b) => a + b, 0);
|
|
6913
|
+
return /* @__PURE__ */ jsxs197("div", { className: "chart-legend-item", children: [
|
|
6914
|
+
/* @__PURE__ */ jsx307("span", { className: "chart-legend-dot", style: { backgroundColor: color } }),
|
|
6915
|
+
/* @__PURE__ */ jsxs197("div", { className: "chart-legend-text", children: [
|
|
6916
|
+
/* @__PURE__ */ jsx307("span", { className: "chart-legend-label", children: key }),
|
|
6917
|
+
/* @__PURE__ */ jsx307("span", { className: "chart-legend-value", children: sum.toLocaleString() })
|
|
6918
|
+
] })
|
|
6919
|
+
] }, di);
|
|
6920
|
+
}) });
|
|
6921
|
+
};
|
|
6919
6922
|
var Chart = React6.memo((props) => {
|
|
6920
6923
|
const { type, data, labels, tooltip: showTooltip = true } = props;
|
|
6921
6924
|
const { tooltip, show, hide, move, containerRef } = useChartTooltip(showTooltip);
|
|
@@ -6931,7 +6934,8 @@ var Chart = React6.memo((props) => {
|
|
|
6931
6934
|
ready && type === "bar" && /* @__PURE__ */ jsx307(BarChart, { data: stableData, labels: stableLabels, width, height, animate, onHover: show, onMove: move, onLeave: hide }),
|
|
6932
6935
|
ready && type === "pie" && /* @__PURE__ */ jsx307(PieDonutChart, { data: stableData, labels: stableLabels, width, height, animate, onHover: show, onMove: move, onLeave: hide }),
|
|
6933
6936
|
ready && type === "doughnut" && /* @__PURE__ */ jsx307(PieDonutChart, { data: stableData, labels: stableLabels, width, height, animate, isDoughnut: true, onHover: show, onMove: move, onLeave: hide }),
|
|
6934
|
-
|
|
6937
|
+
ready && (type === "bar" || type === "pie" || type === "doughnut") && /* @__PURE__ */ jsx307(ChartLegend, { data: stableData, labels: stableLabels, type }),
|
|
6938
|
+
tooltip.content && /* @__PURE__ */ jsx307(ChartTooltipPortal, { clientX: tooltip.clientX, clientY: tooltip.clientY, visible: tooltip.visible, children: tooltip.content })
|
|
6935
6939
|
] });
|
|
6936
6940
|
});
|
|
6937
6941
|
Chart.displayName = "Chart";
|