@x-plat/design-system 0.5.35 → 0.5.37
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 +164 -200
- package/dist/components/Chart/index.css +12 -25
- package/dist/components/Chart/index.js +151 -187
- package/dist/components/index.cjs +211 -231
- package/dist/components/index.css +12 -25
- package/dist/components/index.js +192 -212
- package/dist/index.cjs +211 -231
- package/dist/index.css +12 -25
- package/dist/index.js +192 -212
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -6628,25 +6628,8 @@ var CardTab = Object.assign(CardTabRoot, {
|
|
|
6628
6628
|
var CardTab_default = CardTab;
|
|
6629
6629
|
|
|
6630
6630
|
// src/components/Chart/Chart.tsx
|
|
6631
|
-
var import_react7 = __toESM(require("react"), 1);
|
|
6632
|
-
|
|
6633
|
-
// src/tokens/hooks/Portal.tsx
|
|
6634
6631
|
var import_react6 = __toESM(require("react"), 1);
|
|
6635
|
-
var import_react_dom = __toESM(require("react-dom"), 1);
|
|
6636
6632
|
var import_jsx_runtime307 = require("react/jsx-runtime");
|
|
6637
|
-
var PortalContainerContext = import_react6.default.createContext(null);
|
|
6638
|
-
var PortalProvider = ({ container, children }) => /* @__PURE__ */ (0, import_jsx_runtime307.jsx)(PortalContainerContext.Provider, { value: container, children });
|
|
6639
|
-
var Portal = ({ children }) => {
|
|
6640
|
-
const contextContainer = import_react6.default.useContext(PortalContainerContext);
|
|
6641
|
-
if (typeof document === "undefined") return null;
|
|
6642
|
-
const container = contextContainer ?? document.body;
|
|
6643
|
-
return import_react_dom.default.createPortal(children, container);
|
|
6644
|
-
};
|
|
6645
|
-
Portal.displayName = "Portal";
|
|
6646
|
-
var Portal_default = Portal;
|
|
6647
|
-
|
|
6648
|
-
// src/components/Chart/Chart.tsx
|
|
6649
|
-
var import_jsx_runtime308 = require("react/jsx-runtime");
|
|
6650
6633
|
var CATEGORICAL_COUNT2 = 8;
|
|
6651
6634
|
var LINE_BAR_PALETTES = Array.from({ length: CATEGORICAL_COUNT2 }, (_, i) => {
|
|
6652
6635
|
const n = i + 1;
|
|
@@ -6692,11 +6675,11 @@ var toSmoothPath = (points) => {
|
|
|
6692
6675
|
};
|
|
6693
6676
|
var RESIZE_SETTLE_MS = 150;
|
|
6694
6677
|
var useChartSize = (ref) => {
|
|
6695
|
-
const [size, setSize] =
|
|
6696
|
-
const settleTimer =
|
|
6697
|
-
const committedSize =
|
|
6698
|
-
const initialRef =
|
|
6699
|
-
|
|
6678
|
+
const [size, setSize] = import_react6.default.useState({ width: 0, height: 0 });
|
|
6679
|
+
const settleTimer = import_react6.default.useRef(0);
|
|
6680
|
+
const committedSize = import_react6.default.useRef({ width: 0, height: 0 });
|
|
6681
|
+
const initialRef = import_react6.default.useRef(true);
|
|
6682
|
+
import_react6.default.useEffect(() => {
|
|
6700
6683
|
const el = ref.current;
|
|
6701
6684
|
if (!el) return;
|
|
6702
6685
|
const observer = new ResizeObserver((entries) => {
|
|
@@ -6738,10 +6721,10 @@ var useChartSize = (ref) => {
|
|
|
6738
6721
|
};
|
|
6739
6722
|
var prefersReducedMotion = () => typeof window !== "undefined" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
6740
6723
|
var useChartAnimation = (containerRef, dataKey) => {
|
|
6741
|
-
const [animate, setAnimate] =
|
|
6742
|
-
const prevDataKey =
|
|
6743
|
-
const hasAnimated =
|
|
6744
|
-
|
|
6724
|
+
const [animate, setAnimate] = import_react6.default.useState(false);
|
|
6725
|
+
const prevDataKey = import_react6.default.useRef(dataKey);
|
|
6726
|
+
const hasAnimated = import_react6.default.useRef(false);
|
|
6727
|
+
import_react6.default.useEffect(() => {
|
|
6745
6728
|
if (prefersReducedMotion()) return;
|
|
6746
6729
|
const el = containerRef.current;
|
|
6747
6730
|
if (!el) return;
|
|
@@ -6757,7 +6740,7 @@ var useChartAnimation = (containerRef, dataKey) => {
|
|
|
6757
6740
|
observer.observe(el);
|
|
6758
6741
|
return () => observer.disconnect();
|
|
6759
6742
|
}, [containerRef]);
|
|
6760
|
-
|
|
6743
|
+
import_react6.default.useEffect(() => {
|
|
6761
6744
|
if (dataKey !== prevDataKey.current) {
|
|
6762
6745
|
prevDataKey.current = dataKey;
|
|
6763
6746
|
if (prefersReducedMotion()) return;
|
|
@@ -6771,39 +6754,60 @@ var useChartAnimation = (containerRef, dataKey) => {
|
|
|
6771
6754
|
};
|
|
6772
6755
|
var TOOLTIP_OFFSET = 12;
|
|
6773
6756
|
var useChartTooltip = (enabled) => {
|
|
6774
|
-
const [tooltip, setTooltip] =
|
|
6757
|
+
const [tooltip, setTooltip] = import_react6.default.useState({
|
|
6775
6758
|
visible: false,
|
|
6776
|
-
|
|
6777
|
-
|
|
6759
|
+
x: 0,
|
|
6760
|
+
y: 0,
|
|
6778
6761
|
content: ""
|
|
6779
6762
|
});
|
|
6780
|
-
const containerRef =
|
|
6781
|
-
const rafRef =
|
|
6782
|
-
const move =
|
|
6763
|
+
const containerRef = import_react6.default.useRef(null);
|
|
6764
|
+
const rafRef = import_react6.default.useRef(0);
|
|
6765
|
+
const move = import_react6.default.useCallback((e) => {
|
|
6783
6766
|
if (!enabled) return;
|
|
6784
6767
|
const cx = e.clientX;
|
|
6785
6768
|
const cy = e.clientY;
|
|
6786
6769
|
cancelAnimationFrame(rafRef.current);
|
|
6787
6770
|
rafRef.current = requestAnimationFrame(() => {
|
|
6788
|
-
|
|
6771
|
+
const rect = containerRef.current?.getBoundingClientRect();
|
|
6772
|
+
if (!rect) return;
|
|
6773
|
+
setTooltip((prev) => ({ ...prev, x: cx - rect.left, y: cy - rect.top }));
|
|
6789
6774
|
});
|
|
6790
6775
|
}, [enabled]);
|
|
6791
|
-
const show =
|
|
6776
|
+
const show = import_react6.default.useCallback((e, content) => {
|
|
6777
|
+
if (!enabled) return;
|
|
6778
|
+
const rect = containerRef.current?.getBoundingClientRect();
|
|
6779
|
+
if (!rect) return;
|
|
6780
|
+
setTooltip({ visible: true, x: e.clientX - rect.left, y: e.clientY - rect.top, content });
|
|
6781
|
+
}, [enabled]);
|
|
6782
|
+
const showAt = import_react6.default.useCallback((svgX, svgY, content, svgEl) => {
|
|
6792
6783
|
if (!enabled) return;
|
|
6793
|
-
|
|
6784
|
+
const container = containerRef.current;
|
|
6785
|
+
if (!container) return;
|
|
6786
|
+
let x = svgX;
|
|
6787
|
+
let y = svgY;
|
|
6788
|
+
if (svgEl) {
|
|
6789
|
+
const svgRect = svgEl.getBoundingClientRect();
|
|
6790
|
+
const containerRect = container.getBoundingClientRect();
|
|
6791
|
+
const vb = svgEl.viewBox.baseVal;
|
|
6792
|
+
const scaleX = svgRect.width / (vb.width || 1);
|
|
6793
|
+
const scaleY = svgRect.height / (vb.height || 1);
|
|
6794
|
+
x = svgX * scaleX + (svgRect.left - containerRect.left);
|
|
6795
|
+
y = svgY * scaleY + (svgRect.top - containerRect.top);
|
|
6796
|
+
}
|
|
6797
|
+
setTooltip({ visible: true, x, y, content });
|
|
6794
6798
|
}, [enabled]);
|
|
6795
|
-
const hide =
|
|
6799
|
+
const hide = import_react6.default.useCallback(() => {
|
|
6796
6800
|
cancelAnimationFrame(rafRef.current);
|
|
6797
6801
|
setTooltip((prev) => ({ ...prev, visible: false }));
|
|
6798
6802
|
}, []);
|
|
6799
|
-
return { tooltip, show, hide, move, containerRef };
|
|
6803
|
+
return { tooltip, show, showAt, hide, move, containerRef };
|
|
6800
6804
|
};
|
|
6801
|
-
var GridLines =
|
|
6805
|
+
var GridLines = import_react6.default.memo(({ width, height, chartH, maxVal }) => /* @__PURE__ */ (0, import_jsx_runtime307.jsx)(import_jsx_runtime307.Fragment, { children: [0, 0.25, 0.5, 0.75, 1].map((ratio) => {
|
|
6802
6806
|
const y = PADDING.top + (1 - ratio) * chartH;
|
|
6803
6807
|
const val = Math.round(maxVal * ratio);
|
|
6804
|
-
return /* @__PURE__ */ (0,
|
|
6805
|
-
/* @__PURE__ */ (0,
|
|
6806
|
-
/* @__PURE__ */ (0,
|
|
6808
|
+
return /* @__PURE__ */ (0, import_jsx_runtime307.jsxs)("g", { children: [
|
|
6809
|
+
/* @__PURE__ */ (0, import_jsx_runtime307.jsx)("line", { x1: PADDING.left, y1: y, x2: width - PADDING.right, y2: y, className: "chart-grid" }),
|
|
6810
|
+
/* @__PURE__ */ (0, import_jsx_runtime307.jsx)("text", { x: PADDING.left - 8, y: y + 4, className: "chart-axis-label", textAnchor: "end", children: val })
|
|
6807
6811
|
] }, ratio);
|
|
6808
6812
|
}) }));
|
|
6809
6813
|
GridLines.displayName = "GridLines";
|
|
@@ -6813,18 +6817,18 @@ var getLabelStep = (count, chartW) => {
|
|
|
6813
6817
|
if (count <= maxLabels) return 1;
|
|
6814
6818
|
return Math.ceil(count / maxLabels);
|
|
6815
6819
|
};
|
|
6816
|
-
var AxisLabels =
|
|
6820
|
+
var AxisLabels = import_react6.default.memo(({ labels, count, chartW, height }) => {
|
|
6817
6821
|
const step = getLabelStep(count, chartW);
|
|
6818
|
-
return /* @__PURE__ */ (0,
|
|
6822
|
+
return /* @__PURE__ */ (0, import_jsx_runtime307.jsx)(import_jsx_runtime307.Fragment, { children: labels.map((label, i) => {
|
|
6819
6823
|
if (i % step !== 0) return null;
|
|
6820
6824
|
const x = PADDING.left + i / (count - 1 || 1) * chartW;
|
|
6821
|
-
return /* @__PURE__ */ (0,
|
|
6825
|
+
return /* @__PURE__ */ (0, import_jsx_runtime307.jsx)("text", { x, y: height - 8, className: "chart-axis-label", textAnchor: "middle", children: label }, i);
|
|
6822
6826
|
}) });
|
|
6823
6827
|
});
|
|
6824
6828
|
AxisLabels.displayName = "AxisLabels";
|
|
6825
6829
|
var useCrosshair = (seriesPoints, entries, labels, chartH) => {
|
|
6826
|
-
const [activeIndex, setActiveIndex] =
|
|
6827
|
-
const handleMouseMove =
|
|
6830
|
+
const [activeIndex, setActiveIndex] = import_react6.default.useState(null);
|
|
6831
|
+
const handleMouseMove = import_react6.default.useCallback((e) => {
|
|
6828
6832
|
const svg = e.currentTarget;
|
|
6829
6833
|
const rect = svg.getBoundingClientRect();
|
|
6830
6834
|
const mx = (e.clientX - rect.left) / rect.width * svg.viewBox.baseVal.width;
|
|
@@ -6843,17 +6847,17 @@ var useCrosshair = (seriesPoints, entries, labels, chartH) => {
|
|
|
6843
6847
|
}
|
|
6844
6848
|
setActiveIndex(minDist <= threshold ? closest : null);
|
|
6845
6849
|
}, [seriesPoints]);
|
|
6846
|
-
const handleMouseLeave =
|
|
6850
|
+
const handleMouseLeave = import_react6.default.useCallback(() => {
|
|
6847
6851
|
setActiveIndex(null);
|
|
6848
6852
|
}, []);
|
|
6849
|
-
const tooltipContent =
|
|
6853
|
+
const tooltipContent = import_react6.default.useMemo(() => {
|
|
6850
6854
|
if (activeIndex === null) return "";
|
|
6851
6855
|
return entries.map(([key], di) => {
|
|
6852
6856
|
const p = seriesPoints[di]?.[activeIndex];
|
|
6853
6857
|
return p ? `${key}: ${p.v}` : "";
|
|
6854
6858
|
}).filter(Boolean).join(" / ");
|
|
6855
6859
|
}, [activeIndex, entries, seriesPoints]);
|
|
6856
|
-
const getTooltipAt =
|
|
6860
|
+
const getTooltipAt = import_react6.default.useCallback((idx) => {
|
|
6857
6861
|
return entries.map(([key], di) => {
|
|
6858
6862
|
const p = seriesPoints[di]?.[idx];
|
|
6859
6863
|
return p ? `${key}: ${p.v}` : "";
|
|
@@ -6861,16 +6865,16 @@ var useCrosshair = (seriesPoints, entries, labels, chartH) => {
|
|
|
6861
6865
|
}, [entries, seriesPoints]);
|
|
6862
6866
|
return { activeIndex, handleMouseMove, handleMouseLeave, tooltipContent, getTooltipAt };
|
|
6863
6867
|
};
|
|
6864
|
-
var LineChart =
|
|
6865
|
-
const entries =
|
|
6866
|
-
const maxVal =
|
|
6868
|
+
var LineChart = import_react6.default.memo(({ data, labels, width, height, animate, onHover, onShowAt, onMove, onLeave }) => {
|
|
6869
|
+
const entries = import_react6.default.useMemo(() => Object.entries(data), [data]);
|
|
6870
|
+
const maxVal = import_react6.default.useMemo(() => {
|
|
6867
6871
|
const allValues = entries.flatMap(([, v]) => v);
|
|
6868
6872
|
return Math.max(...allValues) * 1.2 || 1;
|
|
6869
6873
|
}, [entries]);
|
|
6870
6874
|
const count = labels.length;
|
|
6871
6875
|
const chartW = width - PADDING.left - PADDING.right;
|
|
6872
6876
|
const chartH = height - PADDING.top - PADDING.bottom;
|
|
6873
|
-
const seriesPoints =
|
|
6877
|
+
const seriesPoints = import_react6.default.useMemo(
|
|
6874
6878
|
() => entries.map(
|
|
6875
6879
|
([, values]) => values.map((v, i) => ({
|
|
6876
6880
|
x: PADDING.left + i / (count - 1 || 1) * chartW,
|
|
@@ -6880,9 +6884,10 @@ var LineChart = import_react7.default.memo(({ data, labels, width, height, anima
|
|
|
6880
6884
|
),
|
|
6881
6885
|
[entries, count, chartW, chartH, maxVal]
|
|
6882
6886
|
);
|
|
6883
|
-
const clipRef =
|
|
6887
|
+
const clipRef = import_react6.default.useRef(null);
|
|
6888
|
+
const svgRef = import_react6.default.useRef(null);
|
|
6884
6889
|
const { activeIndex, handleMouseMove, handleMouseLeave, getTooltipAt } = useCrosshair(seriesPoints, entries, labels, chartH);
|
|
6885
|
-
|
|
6890
|
+
import_react6.default.useEffect(() => {
|
|
6886
6891
|
if (!animate || !clipRef.current) return;
|
|
6887
6892
|
clipRef.current.setAttribute("width", "0");
|
|
6888
6893
|
requestAnimationFrame(() => {
|
|
@@ -6894,30 +6899,17 @@ var LineChart = import_react7.default.memo(({ data, labels, width, height, anima
|
|
|
6894
6899
|
}, [animate, width]);
|
|
6895
6900
|
const activeX = activeIndex !== null ? seriesPoints[0]?.[activeIndex]?.x ?? null : null;
|
|
6896
6901
|
const lineClipId = "line-area-clip";
|
|
6897
|
-
return /* @__PURE__ */ (0,
|
|
6902
|
+
return /* @__PURE__ */ (0, import_jsx_runtime307.jsxs)(
|
|
6898
6903
|
"svg",
|
|
6899
6904
|
{
|
|
6905
|
+
ref: svgRef,
|
|
6900
6906
|
viewBox: `0 0 ${width} ${height}`,
|
|
6901
6907
|
className: "chart-svg",
|
|
6902
6908
|
onMouseMove: (e) => {
|
|
6903
6909
|
handleMouseMove(e);
|
|
6904
|
-
|
|
6905
|
-
|
|
6906
|
-
|
|
6907
|
-
const points = seriesPoints[0];
|
|
6908
|
-
if (!points || points.length === 0) return;
|
|
6909
|
-
const step = points.length > 1 ? Math.abs(points[1].x - points[0].x) : 20;
|
|
6910
|
-
let closest = 0;
|
|
6911
|
-
let minDist = Math.abs(points[0].x - mx);
|
|
6912
|
-
for (let i = 1; i < points.length; i++) {
|
|
6913
|
-
const dist = Math.abs(points[i].x - mx);
|
|
6914
|
-
if (dist < minDist) {
|
|
6915
|
-
minDist = dist;
|
|
6916
|
-
closest = i;
|
|
6917
|
-
}
|
|
6918
|
-
}
|
|
6919
|
-
if (minDist <= step / 2) {
|
|
6920
|
-
onHover(e, `${labels[closest]} \u2014 ${getTooltipAt(closest)}`);
|
|
6910
|
+
if (activeIndex !== null && seriesPoints[0]?.[activeIndex]) {
|
|
6911
|
+
const p = seriesPoints[0][activeIndex];
|
|
6912
|
+
onShowAt(p.x, p.y, `${labels[activeIndex]} \u2014 ${getTooltipAt(activeIndex)}`, svgRef.current);
|
|
6921
6913
|
} else {
|
|
6922
6914
|
onLeave();
|
|
6923
6915
|
}
|
|
@@ -6927,9 +6919,9 @@ var LineChart = import_react7.default.memo(({ data, labels, width, height, anima
|
|
|
6927
6919
|
onLeave();
|
|
6928
6920
|
},
|
|
6929
6921
|
children: [
|
|
6930
|
-
animate && /* @__PURE__ */ (0,
|
|
6931
|
-
/* @__PURE__ */ (0,
|
|
6932
|
-
/* @__PURE__ */ (0,
|
|
6922
|
+
animate && /* @__PURE__ */ (0, import_jsx_runtime307.jsx)("defs", { children: /* @__PURE__ */ (0, import_jsx_runtime307.jsx)("clipPath", { id: lineClipId, children: /* @__PURE__ */ (0, import_jsx_runtime307.jsx)("rect", { ref: clipRef, x: "0", y: "0", width: animate ? 0 : width, height }) }) }),
|
|
6923
|
+
/* @__PURE__ */ (0, import_jsx_runtime307.jsx)(GridLines, { width, height, chartH, maxVal }),
|
|
6924
|
+
/* @__PURE__ */ (0, import_jsx_runtime307.jsx)(AxisLabels, { labels, count, chartW, height }),
|
|
6933
6925
|
entries.map(([key], di) => {
|
|
6934
6926
|
const palette = getPalette(LINE_BAR_PALETTES, di, key);
|
|
6935
6927
|
const color = palette[2];
|
|
@@ -6938,16 +6930,16 @@ var LineChart = import_react7.default.memo(({ data, labels, width, height, anima
|
|
|
6938
6930
|
const gradientId = `line-gradient-${di}`;
|
|
6939
6931
|
const polyPoints = points.map((p) => `${p.x},${p.y}`).join(" ");
|
|
6940
6932
|
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`;
|
|
6941
|
-
return /* @__PURE__ */ (0,
|
|
6942
|
-
/* @__PURE__ */ (0,
|
|
6943
|
-
/* @__PURE__ */ (0,
|
|
6944
|
-
/* @__PURE__ */ (0,
|
|
6933
|
+
return /* @__PURE__ */ (0, import_jsx_runtime307.jsxs)("g", { children: [
|
|
6934
|
+
/* @__PURE__ */ (0, import_jsx_runtime307.jsx)("defs", { children: /* @__PURE__ */ (0, import_jsx_runtime307.jsxs)("linearGradient", { id: gradientId, x1: "0", y1: "0", x2: "0", y2: "1", children: [
|
|
6935
|
+
/* @__PURE__ */ (0, import_jsx_runtime307.jsx)("stop", { offset: "0%", stopColor: areaColor, stopOpacity: "0.2" }),
|
|
6936
|
+
/* @__PURE__ */ (0, import_jsx_runtime307.jsx)("stop", { offset: "100%", stopColor: areaColor, stopOpacity: "0" })
|
|
6945
6937
|
] }) }),
|
|
6946
|
-
/* @__PURE__ */ (0,
|
|
6947
|
-
/* @__PURE__ */ (0,
|
|
6948
|
-
/* @__PURE__ */ (0,
|
|
6938
|
+
/* @__PURE__ */ (0, import_jsx_runtime307.jsxs)("g", { clipPath: animate ? `url(#${lineClipId})` : void 0, children: [
|
|
6939
|
+
/* @__PURE__ */ (0, import_jsx_runtime307.jsx)("path", { d: areaD, fill: `url(#${gradientId})` }),
|
|
6940
|
+
/* @__PURE__ */ (0, import_jsx_runtime307.jsx)("polyline", { points: polyPoints, fill: "none", stroke: color, strokeWidth: "2" })
|
|
6949
6941
|
] }),
|
|
6950
|
-
activeIndex !== null && points[activeIndex] && /* @__PURE__ */ (0,
|
|
6942
|
+
activeIndex !== null && points[activeIndex] && /* @__PURE__ */ (0, import_jsx_runtime307.jsx)(
|
|
6951
6943
|
"circle",
|
|
6952
6944
|
{
|
|
6953
6945
|
cx: points[activeIndex].x,
|
|
@@ -6959,7 +6951,7 @@ var LineChart = import_react7.default.memo(({ data, labels, width, height, anima
|
|
|
6959
6951
|
)
|
|
6960
6952
|
] }, di);
|
|
6961
6953
|
}),
|
|
6962
|
-
activeX !== null && /* @__PURE__ */ (0,
|
|
6954
|
+
activeX !== null && /* @__PURE__ */ (0, import_jsx_runtime307.jsx)(
|
|
6963
6955
|
"line",
|
|
6964
6956
|
{
|
|
6965
6957
|
x1: activeX,
|
|
@@ -6969,7 +6961,7 @@ var LineChart = import_react7.default.memo(({ data, labels, width, height, anima
|
|
|
6969
6961
|
className: "chart-crosshair"
|
|
6970
6962
|
}
|
|
6971
6963
|
),
|
|
6972
|
-
/* @__PURE__ */ (0,
|
|
6964
|
+
/* @__PURE__ */ (0, import_jsx_runtime307.jsx)(
|
|
6973
6965
|
"rect",
|
|
6974
6966
|
{
|
|
6975
6967
|
x: PADDING.left,
|
|
@@ -6985,16 +6977,16 @@ var LineChart = import_react7.default.memo(({ data, labels, width, height, anima
|
|
|
6985
6977
|
);
|
|
6986
6978
|
});
|
|
6987
6979
|
LineChart.displayName = "LineChart";
|
|
6988
|
-
var CurveChart =
|
|
6989
|
-
const entries =
|
|
6990
|
-
const maxVal =
|
|
6980
|
+
var CurveChart = import_react6.default.memo(({ data, labels, width, height, animate, onHover, onShowAt, onMove, onLeave }) => {
|
|
6981
|
+
const entries = import_react6.default.useMemo(() => Object.entries(data), [data]);
|
|
6982
|
+
const maxVal = import_react6.default.useMemo(() => {
|
|
6991
6983
|
const allValues = entries.flatMap(([, v]) => v);
|
|
6992
6984
|
return Math.max(...allValues) * 1.2 || 1;
|
|
6993
6985
|
}, [entries]);
|
|
6994
6986
|
const count = labels.length;
|
|
6995
6987
|
const chartW = width - PADDING.left - PADDING.right;
|
|
6996
6988
|
const chartH = height - PADDING.top - PADDING.bottom;
|
|
6997
|
-
const seriesPoints =
|
|
6989
|
+
const seriesPoints = import_react6.default.useMemo(
|
|
6998
6990
|
() => entries.map(
|
|
6999
6991
|
([, values]) => values.map((v, i) => ({
|
|
7000
6992
|
x: PADDING.left + i / (count - 1 || 1) * chartW,
|
|
@@ -7004,9 +6996,10 @@ var CurveChart = import_react7.default.memo(({ data, labels, width, height, anim
|
|
|
7004
6996
|
),
|
|
7005
6997
|
[entries, count, chartW, chartH, maxVal]
|
|
7006
6998
|
);
|
|
7007
|
-
const curveClipRef =
|
|
6999
|
+
const curveClipRef = import_react6.default.useRef(null);
|
|
7000
|
+
const curveSvgRef = import_react6.default.useRef(null);
|
|
7008
7001
|
const { activeIndex, handleMouseMove, handleMouseLeave, getTooltipAt } = useCrosshair(seriesPoints, entries, labels, chartH);
|
|
7009
|
-
|
|
7002
|
+
import_react6.default.useEffect(() => {
|
|
7010
7003
|
if (!animate || !curveClipRef.current) return;
|
|
7011
7004
|
curveClipRef.current.setAttribute("width", "0");
|
|
7012
7005
|
requestAnimationFrame(() => {
|
|
@@ -7018,30 +7011,17 @@ var CurveChart = import_react7.default.memo(({ data, labels, width, height, anim
|
|
|
7018
7011
|
}, [animate, width]);
|
|
7019
7012
|
const activeX = activeIndex !== null ? seriesPoints[0]?.[activeIndex]?.x ?? null : null;
|
|
7020
7013
|
const curveClipId = "curve-area-clip";
|
|
7021
|
-
return /* @__PURE__ */ (0,
|
|
7014
|
+
return /* @__PURE__ */ (0, import_jsx_runtime307.jsxs)(
|
|
7022
7015
|
"svg",
|
|
7023
7016
|
{
|
|
7017
|
+
ref: curveSvgRef,
|
|
7024
7018
|
viewBox: `0 0 ${width} ${height}`,
|
|
7025
7019
|
className: "chart-svg",
|
|
7026
7020
|
onMouseMove: (e) => {
|
|
7027
7021
|
handleMouseMove(e);
|
|
7028
|
-
|
|
7029
|
-
|
|
7030
|
-
|
|
7031
|
-
const points = seriesPoints[0];
|
|
7032
|
-
if (!points || points.length === 0) return;
|
|
7033
|
-
const step = points.length > 1 ? Math.abs(points[1].x - points[0].x) : 20;
|
|
7034
|
-
let closest = 0;
|
|
7035
|
-
let minDist = Math.abs(points[0].x - mx);
|
|
7036
|
-
for (let i = 1; i < points.length; i++) {
|
|
7037
|
-
const dist = Math.abs(points[i].x - mx);
|
|
7038
|
-
if (dist < minDist) {
|
|
7039
|
-
minDist = dist;
|
|
7040
|
-
closest = i;
|
|
7041
|
-
}
|
|
7042
|
-
}
|
|
7043
|
-
if (minDist <= step / 2) {
|
|
7044
|
-
onHover(e, `${labels[closest]} \u2014 ${getTooltipAt(closest)}`);
|
|
7022
|
+
if (activeIndex !== null && seriesPoints[0]?.[activeIndex]) {
|
|
7023
|
+
const p = seriesPoints[0][activeIndex];
|
|
7024
|
+
onShowAt(p.x, p.y, `${labels[activeIndex]} \u2014 ${getTooltipAt(activeIndex)}`, curveSvgRef.current);
|
|
7045
7025
|
} else {
|
|
7046
7026
|
onLeave();
|
|
7047
7027
|
}
|
|
@@ -7051,9 +7031,9 @@ var CurveChart = import_react7.default.memo(({ data, labels, width, height, anim
|
|
|
7051
7031
|
onLeave();
|
|
7052
7032
|
},
|
|
7053
7033
|
children: [
|
|
7054
|
-
animate && /* @__PURE__ */ (0,
|
|
7055
|
-
/* @__PURE__ */ (0,
|
|
7056
|
-
/* @__PURE__ */ (0,
|
|
7034
|
+
animate && /* @__PURE__ */ (0, import_jsx_runtime307.jsx)("defs", { children: /* @__PURE__ */ (0, import_jsx_runtime307.jsx)("clipPath", { id: curveClipId, children: /* @__PURE__ */ (0, import_jsx_runtime307.jsx)("rect", { ref: curveClipRef, x: "0", y: "0", width: animate ? 0 : width, height }) }) }),
|
|
7035
|
+
/* @__PURE__ */ (0, import_jsx_runtime307.jsx)(GridLines, { width, height, chartH, maxVal }),
|
|
7036
|
+
/* @__PURE__ */ (0, import_jsx_runtime307.jsx)(AxisLabels, { labels, count, chartW, height }),
|
|
7057
7037
|
entries.map(([key], di) => {
|
|
7058
7038
|
const palette = getPalette(LINE_BAR_PALETTES, di, key);
|
|
7059
7039
|
const color = palette[2];
|
|
@@ -7062,16 +7042,16 @@ var CurveChart = import_react7.default.memo(({ data, labels, width, height, anim
|
|
|
7062
7042
|
const gradientId = `curve-gradient-${di}`;
|
|
7063
7043
|
const linePath = toSmoothPath(points);
|
|
7064
7044
|
const areaPath = linePath + ` L ${points[points.length - 1].x} ${PADDING.top + chartH} L ${points[0].x} ${PADDING.top + chartH} Z`;
|
|
7065
|
-
return /* @__PURE__ */ (0,
|
|
7066
|
-
/* @__PURE__ */ (0,
|
|
7067
|
-
/* @__PURE__ */ (0,
|
|
7068
|
-
/* @__PURE__ */ (0,
|
|
7045
|
+
return /* @__PURE__ */ (0, import_jsx_runtime307.jsxs)("g", { children: [
|
|
7046
|
+
/* @__PURE__ */ (0, import_jsx_runtime307.jsx)("defs", { children: /* @__PURE__ */ (0, import_jsx_runtime307.jsxs)("linearGradient", { id: gradientId, x1: "0", y1: "0", x2: "0", y2: "1", children: [
|
|
7047
|
+
/* @__PURE__ */ (0, import_jsx_runtime307.jsx)("stop", { offset: "0%", stopColor: areaColor, stopOpacity: "0.4" }),
|
|
7048
|
+
/* @__PURE__ */ (0, import_jsx_runtime307.jsx)("stop", { offset: "100%", stopColor: areaColor, stopOpacity: "0.02" })
|
|
7069
7049
|
] }) }),
|
|
7070
|
-
/* @__PURE__ */ (0,
|
|
7071
|
-
/* @__PURE__ */ (0,
|
|
7072
|
-
/* @__PURE__ */ (0,
|
|
7050
|
+
/* @__PURE__ */ (0, import_jsx_runtime307.jsxs)("g", { clipPath: animate ? `url(#${curveClipId})` : void 0, children: [
|
|
7051
|
+
/* @__PURE__ */ (0, import_jsx_runtime307.jsx)("path", { d: areaPath, fill: `url(#${gradientId})` }),
|
|
7052
|
+
/* @__PURE__ */ (0, import_jsx_runtime307.jsx)("path", { d: linePath, fill: "none", stroke: color, strokeWidth: "2" })
|
|
7073
7053
|
] }),
|
|
7074
|
-
activeIndex !== null && points[activeIndex] && /* @__PURE__ */ (0,
|
|
7054
|
+
activeIndex !== null && points[activeIndex] && /* @__PURE__ */ (0, import_jsx_runtime307.jsx)(
|
|
7075
7055
|
"circle",
|
|
7076
7056
|
{
|
|
7077
7057
|
cx: points[activeIndex].x,
|
|
@@ -7083,7 +7063,7 @@ var CurveChart = import_react7.default.memo(({ data, labels, width, height, anim
|
|
|
7083
7063
|
)
|
|
7084
7064
|
] }, di);
|
|
7085
7065
|
}),
|
|
7086
|
-
activeX !== null && /* @__PURE__ */ (0,
|
|
7066
|
+
activeX !== null && /* @__PURE__ */ (0, import_jsx_runtime307.jsx)(
|
|
7087
7067
|
"line",
|
|
7088
7068
|
{
|
|
7089
7069
|
x1: activeX,
|
|
@@ -7093,7 +7073,7 @@ var CurveChart = import_react7.default.memo(({ data, labels, width, height, anim
|
|
|
7093
7073
|
className: "chart-crosshair"
|
|
7094
7074
|
}
|
|
7095
7075
|
),
|
|
7096
|
-
/* @__PURE__ */ (0,
|
|
7076
|
+
/* @__PURE__ */ (0, import_jsx_runtime307.jsx)(
|
|
7097
7077
|
"rect",
|
|
7098
7078
|
{
|
|
7099
7079
|
x: PADDING.left,
|
|
@@ -7109,9 +7089,10 @@ var CurveChart = import_react7.default.memo(({ data, labels, width, height, anim
|
|
|
7109
7089
|
);
|
|
7110
7090
|
});
|
|
7111
7091
|
CurveChart.displayName = "CurveChart";
|
|
7112
|
-
var BarChart =
|
|
7113
|
-
const
|
|
7114
|
-
const
|
|
7092
|
+
var BarChart = import_react6.default.memo(({ data, labels, width, height, animate, onHover, onShowAt, onMove, onLeave }) => {
|
|
7093
|
+
const barSvgRef = import_react6.default.useRef(null);
|
|
7094
|
+
const entries = import_react6.default.useMemo(() => Object.entries(data), [data]);
|
|
7095
|
+
const maxVal = import_react6.default.useMemo(() => {
|
|
7115
7096
|
const allValues = entries.flatMap(([, v]) => v);
|
|
7116
7097
|
return Math.max(...allValues) * 1.2 || 1;
|
|
7117
7098
|
}, [entries]);
|
|
@@ -7123,7 +7104,7 @@ var BarChart = import_react7.default.memo(({ data, labels, width, height, animat
|
|
|
7123
7104
|
const barGap = groupCount > 1 ? 2 : 0;
|
|
7124
7105
|
const barW = Math.max(1, Math.min(32, (groupW * 0.7 - barGap * (groupCount - 1)) / groupCount));
|
|
7125
7106
|
const baseline = PADDING.top + chartH;
|
|
7126
|
-
const bars =
|
|
7107
|
+
const bars = import_react6.default.useMemo(
|
|
7127
7108
|
() => entries.map(
|
|
7128
7109
|
([, values], di) => values.map((v, i) => {
|
|
7129
7110
|
const totalBarsW = barW * groupCount + barGap * (groupCount - 1);
|
|
@@ -7136,11 +7117,11 @@ var BarChart = import_react7.default.memo(({ data, labels, width, height, animat
|
|
|
7136
7117
|
[entries, maxVal, chartH, groupW, barW, barGap, groupCount]
|
|
7137
7118
|
);
|
|
7138
7119
|
const barLabelStep = getLabelStep(count, chartW);
|
|
7139
|
-
return /* @__PURE__ */ (0,
|
|
7140
|
-
/* @__PURE__ */ (0,
|
|
7120
|
+
return /* @__PURE__ */ (0, import_jsx_runtime307.jsxs)("svg", { ref: barSvgRef, viewBox: `0 0 ${width} ${height}`, className: "chart-svg", children: [
|
|
7121
|
+
/* @__PURE__ */ (0, import_jsx_runtime307.jsx)(GridLines, { width, height, chartH, maxVal }),
|
|
7141
7122
|
labels.map((label, i) => {
|
|
7142
7123
|
if (i % barLabelStep !== 0) return null;
|
|
7143
|
-
return /* @__PURE__ */ (0,
|
|
7124
|
+
return /* @__PURE__ */ (0, import_jsx_runtime307.jsx)("text", { x: PADDING.left + groupW * i + groupW / 2, y: height - 8, className: "chart-axis-label", textAnchor: "middle", children: label }, i);
|
|
7144
7125
|
}),
|
|
7145
7126
|
entries.map(([key], di) => {
|
|
7146
7127
|
const palette = getPalette(LINE_BAR_PALETTES, di, key);
|
|
@@ -7149,7 +7130,7 @@ var BarChart = import_react7.default.memo(({ data, labels, width, height, animat
|
|
|
7149
7130
|
const r2 = Math.min(4, b.w / 2);
|
|
7150
7131
|
const d = b.h <= r2 ? `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 + r2} Q ${b.x} ${b.y} ${b.x + r2} ${b.y} H ${b.x + b.w - r2} Q ${b.x + b.w} ${b.y} ${b.x + b.w} ${b.y + r2} V ${b.y + b.h} Z`;
|
|
7151
7132
|
const delay = 100 + i * 80;
|
|
7152
|
-
return /* @__PURE__ */ (0,
|
|
7133
|
+
return /* @__PURE__ */ (0, import_jsx_runtime307.jsx)(
|
|
7153
7134
|
"path",
|
|
7154
7135
|
{
|
|
7155
7136
|
d,
|
|
@@ -7159,8 +7140,7 @@ var BarChart = import_react7.default.memo(({ data, labels, width, height, animat
|
|
|
7159
7140
|
transformOrigin: `${b.x + b.w / 2}px ${baseline}px`,
|
|
7160
7141
|
animationDelay: `${delay}ms`
|
|
7161
7142
|
} : void 0,
|
|
7162
|
-
onMouseEnter: (
|
|
7163
|
-
onMouseMove: onMove,
|
|
7143
|
+
onMouseEnter: () => onShowAt(b.x + b.w / 2, b.y, `${key}: ${labels[i]} \u2014 ${b.v}`, barSvgRef.current),
|
|
7164
7144
|
onMouseLeave: onLeave
|
|
7165
7145
|
},
|
|
7166
7146
|
`${di}-${i}`
|
|
@@ -7170,11 +7150,11 @@ var BarChart = import_react7.default.memo(({ data, labels, width, height, animat
|
|
|
7170
7150
|
] });
|
|
7171
7151
|
});
|
|
7172
7152
|
BarChart.displayName = "BarChart";
|
|
7173
|
-
var PieDonutChart =
|
|
7153
|
+
var PieDonutChart = import_react6.default.memo(
|
|
7174
7154
|
({ data, labels, width, height, animate, isDoughnut, onHover, onMove, onLeave }) => {
|
|
7175
|
-
const entries =
|
|
7176
|
-
const values =
|
|
7177
|
-
const total =
|
|
7155
|
+
const entries = import_react6.default.useMemo(() => Object.entries(data), [data]);
|
|
7156
|
+
const values = import_react6.default.useMemo(() => entries.flatMap(([, v]) => v), [entries]);
|
|
7157
|
+
const total = import_react6.default.useMemo(() => values.reduce((a, b) => a + b, 0) || 1, [values]);
|
|
7178
7158
|
const size = Math.min(width, height);
|
|
7179
7159
|
const cx = size / 2;
|
|
7180
7160
|
const cy = size / 2;
|
|
@@ -7182,10 +7162,10 @@ var PieDonutChart = import_react7.default.memo(
|
|
|
7182
7162
|
const innerR = isDoughnut ? r2 * 0.5 : 0;
|
|
7183
7163
|
const firstKey = entries[0]?.[0] ?? "";
|
|
7184
7164
|
const colorOffset = hashString(firstKey);
|
|
7185
|
-
const maskRef =
|
|
7165
|
+
const maskRef = import_react6.default.useRef(null);
|
|
7186
7166
|
const maskR = r2 + 10;
|
|
7187
7167
|
const maskCircumference = 2 * Math.PI * maskR;
|
|
7188
|
-
|
|
7168
|
+
import_react6.default.useEffect(() => {
|
|
7189
7169
|
if (!animate || !maskRef.current) return;
|
|
7190
7170
|
const el = maskRef.current;
|
|
7191
7171
|
el.style.strokeDasharray = `${maskCircumference}`;
|
|
@@ -7195,7 +7175,7 @@ var PieDonutChart = import_react7.default.memo(
|
|
|
7195
7175
|
el.style.strokeDashoffset = "0";
|
|
7196
7176
|
});
|
|
7197
7177
|
}, [animate, maskCircumference]);
|
|
7198
|
-
const sliceData =
|
|
7178
|
+
const sliceData = import_react6.default.useMemo(() => {
|
|
7199
7179
|
let angle0 = -Math.PI / 2;
|
|
7200
7180
|
let cumulativeAngle = 0;
|
|
7201
7181
|
return values.map((v, i) => {
|
|
@@ -7229,8 +7209,8 @@ var PieDonutChart = import_react7.default.memo(
|
|
|
7229
7209
|
});
|
|
7230
7210
|
}, [values, total, cx, cy, r2, innerR, labels]);
|
|
7231
7211
|
const maskId = `pie-mask-${isDoughnut ? "d" : "p"}`;
|
|
7232
|
-
return /* @__PURE__ */ (0,
|
|
7233
|
-
animate && /* @__PURE__ */ (0,
|
|
7212
|
+
return /* @__PURE__ */ (0, import_jsx_runtime307.jsxs)("svg", { viewBox: `0 0 ${size} ${size}`, className: "chart-svg chart-pie", children: [
|
|
7213
|
+
animate && /* @__PURE__ */ (0, import_jsx_runtime307.jsx)("defs", { children: /* @__PURE__ */ (0, import_jsx_runtime307.jsx)("mask", { id: maskId, children: /* @__PURE__ */ (0, import_jsx_runtime307.jsx)(
|
|
7234
7214
|
"circle",
|
|
7235
7215
|
{
|
|
7236
7216
|
ref: maskRef,
|
|
@@ -7243,56 +7223,39 @@ var PieDonutChart = import_react7.default.memo(
|
|
|
7243
7223
|
transform: `rotate(-90 ${cx} ${cy})`
|
|
7244
7224
|
}
|
|
7245
7225
|
) }) }),
|
|
7246
|
-
/* @__PURE__ */ (0,
|
|
7226
|
+
/* @__PURE__ */ (0, import_jsx_runtime307.jsx)("g", { mask: animate ? `url(#${maskId})` : void 0, children: sliceData.map((s, i) => /* @__PURE__ */ (0, import_jsx_runtime307.jsx)("g", { children: /* @__PURE__ */ (0, import_jsx_runtime307.jsx)(
|
|
7247
7227
|
"path",
|
|
7248
7228
|
{
|
|
7249
7229
|
d: s.d,
|
|
7250
7230
|
fill: PIE_COLORS[(i + colorOffset) % PIE_COLORS.length],
|
|
7251
|
-
className: "chart-slice"
|
|
7252
|
-
onMouseEnter: (e) => onHover(e, `${s.label}: ${s.v} (${s.pct}%)`),
|
|
7253
|
-
onMouseMove: onMove,
|
|
7254
|
-
onMouseLeave: onLeave
|
|
7231
|
+
className: "chart-slice"
|
|
7255
7232
|
}
|
|
7256
|
-
) }, i)) })
|
|
7257
|
-
sliceData.map((s, i) => s.angle > 0.2 && /* @__PURE__ */ (0, import_jsx_runtime308.jsx)(
|
|
7258
|
-
"text",
|
|
7259
|
-
{
|
|
7260
|
-
x: s.lx,
|
|
7261
|
-
y: s.ly,
|
|
7262
|
-
className: `chart-pie-label ${animate ? "chart-pie-label-animate" : ""}`,
|
|
7263
|
-
style: animate ? { animationDelay: `${s.labelDelay}ms` } : void 0,
|
|
7264
|
-
textAnchor: "middle",
|
|
7265
|
-
dominantBaseline: "central",
|
|
7266
|
-
children: s.v
|
|
7267
|
-
},
|
|
7268
|
-
`label-${i}`
|
|
7269
|
-
))
|
|
7233
|
+
) }, i)) })
|
|
7270
7234
|
] });
|
|
7271
7235
|
}
|
|
7272
7236
|
);
|
|
7273
7237
|
PieDonutChart.displayName = "PieDonutChart";
|
|
7274
|
-
var
|
|
7275
|
-
const ref =
|
|
7276
|
-
const [pos, setPos] =
|
|
7277
|
-
|
|
7238
|
+
var ChartTooltip = ({ x, y, containerWidth, containerHeight, children }) => {
|
|
7239
|
+
const ref = import_react6.default.useRef(null);
|
|
7240
|
+
const [pos, setPos] = import_react6.default.useState({ left: 0, top: 0 });
|
|
7241
|
+
import_react6.default.useLayoutEffect(() => {
|
|
7278
7242
|
const el = ref.current;
|
|
7279
7243
|
if (!el) return;
|
|
7280
7244
|
const w = el.offsetWidth;
|
|
7281
7245
|
const h = el.offsetHeight;
|
|
7282
|
-
|
|
7283
|
-
let
|
|
7284
|
-
|
|
7285
|
-
if (
|
|
7286
|
-
if (
|
|
7287
|
-
if (left < 8) left = 8;
|
|
7246
|
+
let left = x + TOOLTIP_OFFSET;
|
|
7247
|
+
let top = y - h - TOOLTIP_OFFSET;
|
|
7248
|
+
if (left + w > containerWidth) left = x - w - TOOLTIP_OFFSET;
|
|
7249
|
+
if (top < 0) top = y + TOOLTIP_OFFSET;
|
|
7250
|
+
if (left < 0) left = 0;
|
|
7288
7251
|
setPos({ left, top });
|
|
7289
|
-
}, [
|
|
7290
|
-
return /* @__PURE__ */ (0,
|
|
7252
|
+
}, [x, y, containerWidth, containerHeight]);
|
|
7253
|
+
return /* @__PURE__ */ (0, import_jsx_runtime307.jsx)(
|
|
7291
7254
|
"div",
|
|
7292
7255
|
{
|
|
7293
7256
|
ref,
|
|
7294
|
-
className:
|
|
7295
|
-
style: {
|
|
7257
|
+
className: "chart-tooltip chart-tooltip-show",
|
|
7258
|
+
style: { left: pos.left, top: pos.top },
|
|
7296
7259
|
children
|
|
7297
7260
|
}
|
|
7298
7261
|
);
|
|
@@ -7304,14 +7267,14 @@ var ChartLegend = ({ data, labels, type }) => {
|
|
|
7304
7267
|
const total = values.reduce((a, b) => a + b, 0) || 1;
|
|
7305
7268
|
const firstKey = entries[0]?.[0] ?? "";
|
|
7306
7269
|
const colorOffset = hashString(firstKey);
|
|
7307
|
-
return /* @__PURE__ */ (0,
|
|
7270
|
+
return /* @__PURE__ */ (0, import_jsx_runtime307.jsx)("div", { className: "chart-legend", children: values.map((v, i) => {
|
|
7308
7271
|
const pct = Math.round(v / total * 100);
|
|
7309
7272
|
const color = PIE_COLORS[(i + colorOffset) % PIE_COLORS.length];
|
|
7310
|
-
return /* @__PURE__ */ (0,
|
|
7311
|
-
/* @__PURE__ */ (0,
|
|
7312
|
-
/* @__PURE__ */ (0,
|
|
7313
|
-
/* @__PURE__ */ (0,
|
|
7314
|
-
/* @__PURE__ */ (0,
|
|
7273
|
+
return /* @__PURE__ */ (0, import_jsx_runtime307.jsxs)("div", { className: "chart-legend-item", children: [
|
|
7274
|
+
/* @__PURE__ */ (0, import_jsx_runtime307.jsx)("span", { className: "chart-legend-dot", style: { backgroundColor: color } }),
|
|
7275
|
+
/* @__PURE__ */ (0, import_jsx_runtime307.jsxs)("div", { className: "chart-legend-text", children: [
|
|
7276
|
+
/* @__PURE__ */ (0, import_jsx_runtime307.jsx)("span", { className: "chart-legend-label", children: labels[i] || `${i + 1}` }),
|
|
7277
|
+
/* @__PURE__ */ (0, import_jsx_runtime307.jsxs)("span", { className: "chart-legend-value", children: [
|
|
7315
7278
|
v.toLocaleString(),
|
|
7316
7279
|
"(",
|
|
7317
7280
|
pct,
|
|
@@ -7321,37 +7284,37 @@ var ChartLegend = ({ data, labels, type }) => {
|
|
|
7321
7284
|
] }, i);
|
|
7322
7285
|
}) });
|
|
7323
7286
|
}
|
|
7324
|
-
return /* @__PURE__ */ (0,
|
|
7287
|
+
return /* @__PURE__ */ (0, import_jsx_runtime307.jsx)("div", { className: "chart-legend", children: entries.map(([key], di) => {
|
|
7325
7288
|
const palette = getPalette(LINE_BAR_PALETTES, di, key);
|
|
7326
7289
|
const color = palette[2];
|
|
7327
7290
|
const values = entries[di][1];
|
|
7328
7291
|
const sum = values.reduce((a, b) => a + b, 0);
|
|
7329
|
-
return /* @__PURE__ */ (0,
|
|
7330
|
-
/* @__PURE__ */ (0,
|
|
7331
|
-
/* @__PURE__ */ (0,
|
|
7332
|
-
/* @__PURE__ */ (0,
|
|
7333
|
-
/* @__PURE__ */ (0,
|
|
7292
|
+
return /* @__PURE__ */ (0, import_jsx_runtime307.jsxs)("div", { className: "chart-legend-item", children: [
|
|
7293
|
+
/* @__PURE__ */ (0, import_jsx_runtime307.jsx)("span", { className: "chart-legend-dot", style: { backgroundColor: color } }),
|
|
7294
|
+
/* @__PURE__ */ (0, import_jsx_runtime307.jsxs)("div", { className: "chart-legend-text", children: [
|
|
7295
|
+
/* @__PURE__ */ (0, import_jsx_runtime307.jsx)("span", { className: "chart-legend-label", children: key }),
|
|
7296
|
+
/* @__PURE__ */ (0, import_jsx_runtime307.jsx)("span", { className: "chart-legend-value", children: sum.toLocaleString() })
|
|
7334
7297
|
] })
|
|
7335
7298
|
] }, di);
|
|
7336
7299
|
}) });
|
|
7337
7300
|
};
|
|
7338
|
-
var Chart =
|
|
7301
|
+
var Chart = import_react6.default.memo((props) => {
|
|
7339
7302
|
const { type, data, labels, tooltip: showTooltip = true } = props;
|
|
7340
|
-
const { tooltip, show, hide, move, containerRef } = useChartTooltip(showTooltip);
|
|
7303
|
+
const { tooltip, show, showAt, hide, move, containerRef } = useChartTooltip(showTooltip);
|
|
7341
7304
|
const { width, height } = useChartSize(containerRef);
|
|
7342
|
-
const stableData =
|
|
7343
|
-
const stableLabels =
|
|
7344
|
-
const dataKey =
|
|
7305
|
+
const stableData = import_react6.default.useMemo(() => data, [JSON.stringify(data)]);
|
|
7306
|
+
const stableLabels = import_react6.default.useMemo(() => labels, [JSON.stringify(labels)]);
|
|
7307
|
+
const dataKey = import_react6.default.useMemo(() => JSON.stringify(labels), [labels]);
|
|
7345
7308
|
const animate = useChartAnimation(containerRef, dataKey);
|
|
7346
7309
|
const ready = width > 0 && height > 0;
|
|
7347
|
-
return /* @__PURE__ */ (0,
|
|
7348
|
-
ready && type === "line" && /* @__PURE__ */ (0,
|
|
7349
|
-
ready && type === "curve" && /* @__PURE__ */ (0,
|
|
7350
|
-
ready && type === "bar" && /* @__PURE__ */ (0,
|
|
7351
|
-
ready && type === "pie" && /* @__PURE__ */ (0,
|
|
7352
|
-
ready && type === "doughnut" && /* @__PURE__ */ (0,
|
|
7353
|
-
ready && (type === "
|
|
7354
|
-
tooltip.content && /* @__PURE__ */ (0,
|
|
7310
|
+
return /* @__PURE__ */ (0, import_jsx_runtime307.jsxs)("div", { className: "lib-xplat-chart", ref: containerRef, children: [
|
|
7311
|
+
ready && type === "line" && /* @__PURE__ */ (0, import_jsx_runtime307.jsx)(LineChart, { data: stableData, labels: stableLabels, width, height, animate, onHover: show, onShowAt: showAt, onMove: move, onLeave: hide }),
|
|
7312
|
+
ready && type === "curve" && /* @__PURE__ */ (0, import_jsx_runtime307.jsx)(CurveChart, { data: stableData, labels: stableLabels, width, height, animate, onHover: show, onShowAt: showAt, onMove: move, onLeave: hide }),
|
|
7313
|
+
ready && type === "bar" && /* @__PURE__ */ (0, import_jsx_runtime307.jsx)(BarChart, { data: stableData, labels: stableLabels, width, height, animate, onHover: show, onShowAt: showAt, onMove: move, onLeave: hide }),
|
|
7314
|
+
ready && type === "pie" && /* @__PURE__ */ (0, import_jsx_runtime307.jsx)(PieDonutChart, { data: stableData, labels: stableLabels, width, height, animate, onHover: show, onShowAt: showAt, onMove: move, onLeave: hide }),
|
|
7315
|
+
ready && type === "doughnut" && /* @__PURE__ */ (0, import_jsx_runtime307.jsx)(PieDonutChart, { data: stableData, labels: stableLabels, width, height, animate, isDoughnut: true, onHover: show, onShowAt: showAt, onMove: move, onLeave: hide }),
|
|
7316
|
+
ready && (type === "pie" || type === "doughnut") && /* @__PURE__ */ (0, import_jsx_runtime307.jsx)(ChartLegend, { data: stableData, labels: stableLabels, type }),
|
|
7317
|
+
tooltip.visible && tooltip.content && /* @__PURE__ */ (0, import_jsx_runtime307.jsx)(ChartTooltip, { x: tooltip.x, y: tooltip.y, containerWidth: width, containerHeight: height, children: tooltip.content })
|
|
7355
7318
|
] });
|
|
7356
7319
|
});
|
|
7357
7320
|
Chart.displayName = "Chart";
|
|
@@ -7377,7 +7340,7 @@ var import_tokens_core = require("@x-plat/tokens-core");
|
|
|
7377
7340
|
var import_tokens_core2 = require("@x-plat/tokens-core");
|
|
7378
7341
|
|
|
7379
7342
|
// src/components/CheckBox/CheckBox.tsx
|
|
7380
|
-
var
|
|
7343
|
+
var import_jsx_runtime308 = require("react/jsx-runtime");
|
|
7381
7344
|
var CheckBox = (props) => {
|
|
7382
7345
|
const {
|
|
7383
7346
|
checked,
|
|
@@ -7395,8 +7358,8 @@ var CheckBox = (props) => {
|
|
|
7395
7358
|
const checkedClasses = `checked`;
|
|
7396
7359
|
const disabledClasses = "disabled";
|
|
7397
7360
|
const boxClasses = disabled ? disabledClasses : checked ? checkedClasses : uncheckedClasses;
|
|
7398
|
-
return /* @__PURE__ */ (0,
|
|
7399
|
-
/* @__PURE__ */ (0,
|
|
7361
|
+
return /* @__PURE__ */ (0, import_jsx_runtime308.jsxs)("label", { className: clsx_default("lib-xplat-checkbox", size, type), children: [
|
|
7362
|
+
/* @__PURE__ */ (0, import_jsx_runtime308.jsx)(
|
|
7400
7363
|
"input",
|
|
7401
7364
|
{
|
|
7402
7365
|
type: "checkbox",
|
|
@@ -7406,22 +7369,22 @@ var CheckBox = (props) => {
|
|
|
7406
7369
|
...rest
|
|
7407
7370
|
}
|
|
7408
7371
|
),
|
|
7409
|
-
/* @__PURE__ */ (0,
|
|
7410
|
-
label && /* @__PURE__ */ (0,
|
|
7372
|
+
/* @__PURE__ */ (0, import_jsx_runtime308.jsx)("span", { className: clsx_default("checkbox", boxClasses), children: /* @__PURE__ */ (0, import_jsx_runtime308.jsx)("span", { className: clsx_default("check-icon", { visible: checked }), children: /* @__PURE__ */ (0, import_jsx_runtime308.jsx)(CheckIcon_default, {}) }) }),
|
|
7373
|
+
label && /* @__PURE__ */ (0, import_jsx_runtime308.jsx)("span", { className: "label", children: label })
|
|
7411
7374
|
] });
|
|
7412
7375
|
};
|
|
7413
7376
|
CheckBox.displayName = "CheckBox";
|
|
7414
7377
|
var CheckBox_default = CheckBox;
|
|
7415
7378
|
|
|
7416
7379
|
// src/components/Chip/Chip.tsx
|
|
7417
|
-
var
|
|
7380
|
+
var import_jsx_runtime309 = require("react/jsx-runtime");
|
|
7418
7381
|
var Chip = (props) => {
|
|
7419
7382
|
const {
|
|
7420
7383
|
children,
|
|
7421
7384
|
type = "primary",
|
|
7422
7385
|
size = "md"
|
|
7423
7386
|
} = props;
|
|
7424
|
-
return /* @__PURE__ */ (0,
|
|
7387
|
+
return /* @__PURE__ */ (0, import_jsx_runtime309.jsx)("div", { className: clsx_default("lib-xplat-chip", type, size), children });
|
|
7425
7388
|
};
|
|
7426
7389
|
Chip.displayName = "Chip";
|
|
7427
7390
|
var Chip_default = Chip;
|
|
@@ -7430,20 +7393,20 @@ var Chip_default = Chip;
|
|
|
7430
7393
|
var import_react13 = __toESM(require("react"), 1);
|
|
7431
7394
|
|
|
7432
7395
|
// src/components/Input/Input.tsx
|
|
7433
|
-
var
|
|
7396
|
+
var import_react7 = __toESM(require("react"), 1);
|
|
7434
7397
|
|
|
7435
7398
|
// src/components/Input/InputValidations.tsx
|
|
7436
|
-
var
|
|
7399
|
+
var import_jsx_runtime310 = require("react/jsx-runtime");
|
|
7437
7400
|
var InputValidations = (props) => {
|
|
7438
7401
|
const { message, status = "default" } = props;
|
|
7439
|
-
return /* @__PURE__ */ (0,
|
|
7440
|
-
/* @__PURE__ */ (0,
|
|
7441
|
-
status === "default" && /* @__PURE__ */ (0,
|
|
7442
|
-
status === "success" && /* @__PURE__ */ (0,
|
|
7443
|
-
status === "warning" && /* @__PURE__ */ (0,
|
|
7444
|
-
status === "error" && /* @__PURE__ */ (0,
|
|
7402
|
+
return /* @__PURE__ */ (0, import_jsx_runtime310.jsxs)("div", { className: clsx_default("lib-xplat-input-validation", status), children: [
|
|
7403
|
+
/* @__PURE__ */ (0, import_jsx_runtime310.jsxs)("div", { className: "icon", children: [
|
|
7404
|
+
status === "default" && /* @__PURE__ */ (0, import_jsx_runtime310.jsx)(InfoIcon_default, {}),
|
|
7405
|
+
status === "success" && /* @__PURE__ */ (0, import_jsx_runtime310.jsx)(SuccessIcon_default, {}),
|
|
7406
|
+
status === "warning" && /* @__PURE__ */ (0, import_jsx_runtime310.jsx)(InfoIcon_default, {}),
|
|
7407
|
+
status === "error" && /* @__PURE__ */ (0, import_jsx_runtime310.jsx)(ErrorIcon_default, {})
|
|
7445
7408
|
] }),
|
|
7446
|
-
/* @__PURE__ */ (0,
|
|
7409
|
+
/* @__PURE__ */ (0, import_jsx_runtime310.jsx)("div", { className: "message", children: message })
|
|
7447
7410
|
] });
|
|
7448
7411
|
};
|
|
7449
7412
|
InputValidations.displayName = "InputValidations";
|
|
@@ -7484,8 +7447,8 @@ var handleTelBackspace = (prevValue, currValue) => {
|
|
|
7484
7447
|
};
|
|
7485
7448
|
|
|
7486
7449
|
// src/components/Input/Input.tsx
|
|
7487
|
-
var
|
|
7488
|
-
var
|
|
7450
|
+
var import_jsx_runtime311 = require("react/jsx-runtime");
|
|
7451
|
+
var import_react8 = require("react");
|
|
7489
7452
|
var formatValue = (type, value) => {
|
|
7490
7453
|
if (value === null || value === void 0) return "";
|
|
7491
7454
|
const strValue = Array.isArray(value) ? String(value[0] ?? "") : String(value);
|
|
@@ -7533,7 +7496,7 @@ var parseValue = (type, value) => {
|
|
|
7533
7496
|
return value;
|
|
7534
7497
|
}
|
|
7535
7498
|
};
|
|
7536
|
-
var Input =
|
|
7499
|
+
var Input = import_react7.default.forwardRef((props, ref) => {
|
|
7537
7500
|
const {
|
|
7538
7501
|
value,
|
|
7539
7502
|
onChange,
|
|
@@ -7559,13 +7522,13 @@ var Input = import_react8.default.forwardRef((props, ref) => {
|
|
|
7559
7522
|
onChange(event);
|
|
7560
7523
|
}
|
|
7561
7524
|
};
|
|
7562
|
-
return /* @__PURE__ */ (0,
|
|
7563
|
-
/* @__PURE__ */ (0,
|
|
7525
|
+
return /* @__PURE__ */ (0, import_jsx_runtime311.jsxs)("div", { className: "lib-xplat-input-wrap", children: [
|
|
7526
|
+
/* @__PURE__ */ (0, import_jsx_runtime311.jsxs)(
|
|
7564
7527
|
"div",
|
|
7565
7528
|
{
|
|
7566
7529
|
className: clsx_default("lib-xplat-input", size, disabled ? "disabled" : void 0),
|
|
7567
7530
|
children: [
|
|
7568
|
-
/* @__PURE__ */ (0,
|
|
7531
|
+
/* @__PURE__ */ (0, import_jsx_runtime311.jsx)(
|
|
7569
7532
|
"input",
|
|
7570
7533
|
{
|
|
7571
7534
|
...inputProps,
|
|
@@ -7576,11 +7539,11 @@ var Input = import_react8.default.forwardRef((props, ref) => {
|
|
|
7576
7539
|
onChange: handleChange
|
|
7577
7540
|
}
|
|
7578
7541
|
),
|
|
7579
|
-
suffix && /* @__PURE__ */ (0,
|
|
7542
|
+
suffix && /* @__PURE__ */ (0, import_jsx_runtime311.jsx)("div", { className: "suffix", children: suffix })
|
|
7580
7543
|
]
|
|
7581
7544
|
}
|
|
7582
7545
|
),
|
|
7583
|
-
validations && /* @__PURE__ */ (0,
|
|
7546
|
+
validations && /* @__PURE__ */ (0, import_jsx_runtime311.jsx)("div", { className: "lib-xplat-input-validation-wrap", children: validations?.map((validation, idx) => /* @__PURE__ */ (0, import_react8.createElement)(
|
|
7584
7547
|
InputValidations_default,
|
|
7585
7548
|
{
|
|
7586
7549
|
...validation,
|
|
@@ -7593,20 +7556,20 @@ Input.displayName = "Input";
|
|
|
7593
7556
|
var Input_default = Input;
|
|
7594
7557
|
|
|
7595
7558
|
// src/components/Input/PasswordInput/PasswordInput.tsx
|
|
7596
|
-
var
|
|
7597
|
-
var
|
|
7598
|
-
var PasswordInput =
|
|
7559
|
+
var import_react9 = __toESM(require("react"), 1);
|
|
7560
|
+
var import_jsx_runtime312 = require("react/jsx-runtime");
|
|
7561
|
+
var PasswordInput = import_react9.default.forwardRef(
|
|
7599
7562
|
(props, ref) => {
|
|
7600
7563
|
const { reg: _reg, ...inputProps } = props;
|
|
7601
|
-
const [isView, setIsView] =
|
|
7564
|
+
const [isView, setIsView] = import_react9.default.useState(false);
|
|
7602
7565
|
const handleChangeView = () => {
|
|
7603
7566
|
setIsView((prev) => !prev);
|
|
7604
7567
|
};
|
|
7605
|
-
return /* @__PURE__ */ (0,
|
|
7568
|
+
return /* @__PURE__ */ (0, import_jsx_runtime312.jsx)(
|
|
7606
7569
|
Input_default,
|
|
7607
7570
|
{
|
|
7608
7571
|
...inputProps,
|
|
7609
|
-
suffix: /* @__PURE__ */ (0,
|
|
7572
|
+
suffix: /* @__PURE__ */ (0, import_jsx_runtime312.jsx)("div", { className: "wrapper pointer", onClick: handleChangeView, children: isView ? /* @__PURE__ */ (0, import_jsx_runtime312.jsx)(OpenEyeIcon_default, {}) : /* @__PURE__ */ (0, import_jsx_runtime312.jsx)(CloseEyeIcon_default, {}) }),
|
|
7610
7573
|
type: isView ? "text" : "password",
|
|
7611
7574
|
ref
|
|
7612
7575
|
}
|
|
@@ -7619,6 +7582,23 @@ var PasswordInput_default = PasswordInput;
|
|
|
7619
7582
|
// src/components/Modal/Modal.tsx
|
|
7620
7583
|
var import_react11 = __toESM(require("react"), 1);
|
|
7621
7584
|
var import_react_dom2 = require("react-dom");
|
|
7585
|
+
|
|
7586
|
+
// src/tokens/hooks/Portal.tsx
|
|
7587
|
+
var import_react10 = __toESM(require("react"), 1);
|
|
7588
|
+
var import_react_dom = __toESM(require("react-dom"), 1);
|
|
7589
|
+
var import_jsx_runtime313 = require("react/jsx-runtime");
|
|
7590
|
+
var PortalContainerContext = import_react10.default.createContext(null);
|
|
7591
|
+
var PortalProvider = ({ container, children }) => /* @__PURE__ */ (0, import_jsx_runtime313.jsx)(PortalContainerContext.Provider, { value: container, children });
|
|
7592
|
+
var Portal = ({ children }) => {
|
|
7593
|
+
const contextContainer = import_react10.default.useContext(PortalContainerContext);
|
|
7594
|
+
if (typeof document === "undefined") return null;
|
|
7595
|
+
const container = contextContainer ?? document.body;
|
|
7596
|
+
return import_react_dom.default.createPortal(children, container);
|
|
7597
|
+
};
|
|
7598
|
+
Portal.displayName = "Portal";
|
|
7599
|
+
var Portal_default = Portal;
|
|
7600
|
+
|
|
7601
|
+
// src/components/Modal/Modal.tsx
|
|
7622
7602
|
var import_jsx_runtime314 = require("react/jsx-runtime");
|
|
7623
7603
|
var ANIMATION_DURATION_MS = 200;
|
|
7624
7604
|
var Modal = (props) => {
|