@x-plat/design-system 0.5.11 → 0.5.13
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 +67 -48
- package/dist/components/Chart/index.js +68 -49
- package/dist/components/DatePicker/index.cjs +398 -380
- package/dist/components/DatePicker/index.js +384 -366
- package/dist/components/Dropdown/index.cjs +34 -17
- package/dist/components/Dropdown/index.css +9 -9
- package/dist/components/Dropdown/index.js +33 -16
- package/dist/components/Modal/index.cjs +25 -9
- package/dist/components/Modal/index.d.cts +0 -3
- package/dist/components/Modal/index.d.ts +0 -3
- package/dist/components/Modal/index.js +24 -8
- package/dist/components/PopOver/index.cjs +29 -12
- package/dist/components/PopOver/index.css +6 -9
- package/dist/components/PopOver/index.js +28 -11
- package/dist/components/Select/index.cjs +348 -331
- package/dist/components/Select/index.css +12 -19
- package/dist/components/Select/index.js +346 -329
- package/dist/components/index.cjs +480 -439
- package/dist/components/index.css +27 -37
- package/dist/components/index.js +436 -395
- package/dist/index.cjs +504 -463
- package/dist/index.css +27 -37
- package/dist/index.js +458 -417
- package/package.json +1 -1
|
@@ -85,14 +85,23 @@ var useChartSize = (ref) => {
|
|
|
85
85
|
import_react.default.useEffect(() => {
|
|
86
86
|
const el = ref.current;
|
|
87
87
|
if (!el) return;
|
|
88
|
+
let rafId = 0;
|
|
88
89
|
const observer = new ResizeObserver((entries) => {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
90
|
+
cancelAnimationFrame(rafId);
|
|
91
|
+
rafId = requestAnimationFrame(() => {
|
|
92
|
+
const entry = entries[0];
|
|
93
|
+
if (!entry) return;
|
|
94
|
+
const { width, height } = entry.contentRect;
|
|
95
|
+
const w = Math.floor(width);
|
|
96
|
+
const h = Math.floor(height);
|
|
97
|
+
setSize((prev) => prev.width === w && prev.height === h ? prev : { width: w, height: h });
|
|
98
|
+
});
|
|
93
99
|
});
|
|
94
100
|
observer.observe(el);
|
|
95
|
-
return () =>
|
|
101
|
+
return () => {
|
|
102
|
+
cancelAnimationFrame(rafId);
|
|
103
|
+
observer.disconnect();
|
|
104
|
+
};
|
|
96
105
|
}, [ref]);
|
|
97
106
|
return size;
|
|
98
107
|
};
|
|
@@ -104,15 +113,21 @@ var useChartTooltip = (enabled) => {
|
|
|
104
113
|
content: ""
|
|
105
114
|
});
|
|
106
115
|
const containerRef = import_react.default.useRef(null);
|
|
116
|
+
const rafRef = import_react.default.useRef(0);
|
|
107
117
|
const move = import_react.default.useCallback((e) => {
|
|
108
118
|
if (!enabled) return;
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
119
|
+
const clientX = e.clientX;
|
|
120
|
+
const clientY = e.clientY;
|
|
121
|
+
cancelAnimationFrame(rafRef.current);
|
|
122
|
+
rafRef.current = requestAnimationFrame(() => {
|
|
123
|
+
const rect = containerRef.current?.getBoundingClientRect();
|
|
124
|
+
if (!rect) return;
|
|
125
|
+
setTooltip((prev) => ({
|
|
126
|
+
...prev,
|
|
127
|
+
x: clientX - rect.left,
|
|
128
|
+
y: clientY - rect.top - 12
|
|
129
|
+
}));
|
|
130
|
+
});
|
|
116
131
|
}, [enabled]);
|
|
117
132
|
const show = import_react.default.useCallback((e, content) => {
|
|
118
133
|
if (!enabled) return;
|
|
@@ -126,10 +141,35 @@ var useChartTooltip = (enabled) => {
|
|
|
126
141
|
});
|
|
127
142
|
}, [enabled]);
|
|
128
143
|
const hide = import_react.default.useCallback(() => {
|
|
144
|
+
cancelAnimationFrame(rafRef.current);
|
|
129
145
|
setTooltip((prev) => ({ ...prev, visible: false }));
|
|
130
146
|
}, []);
|
|
131
147
|
return { tooltip, show, hide, move, containerRef };
|
|
132
148
|
};
|
|
149
|
+
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) => {
|
|
150
|
+
const y = PADDING.top + (1 - ratio) * chartH;
|
|
151
|
+
const val = Math.round(maxVal * ratio);
|
|
152
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("g", { children: [
|
|
153
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("line", { x1: PADDING.left, y1: y, x2: width - PADDING.right, y2: y, className: "chart-grid" }),
|
|
154
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("text", { x: PADDING.left - 8, y: y + 4, className: "chart-axis-label", textAnchor: "end", children: val })
|
|
155
|
+
] }, ratio);
|
|
156
|
+
}) }));
|
|
157
|
+
GridLines.displayName = "GridLines";
|
|
158
|
+
var getLabelStep = (count, chartW) => {
|
|
159
|
+
const minLabelWidth = 40;
|
|
160
|
+
const maxLabels = Math.floor(chartW / minLabelWidth);
|
|
161
|
+
if (count <= maxLabels) return 1;
|
|
162
|
+
return Math.ceil(count / maxLabels);
|
|
163
|
+
};
|
|
164
|
+
var AxisLabels = import_react.default.memo(({ labels, count, chartW, height }) => {
|
|
165
|
+
const step = getLabelStep(count, chartW);
|
|
166
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: labels.map((label, i) => {
|
|
167
|
+
if (i % step !== 0) return null;
|
|
168
|
+
const x = PADDING.left + i / (count - 1 || 1) * chartW;
|
|
169
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("text", { x, y: height - 8, className: "chart-axis-label", textAnchor: "middle", children: label }, i);
|
|
170
|
+
}) });
|
|
171
|
+
});
|
|
172
|
+
AxisLabels.displayName = "AxisLabels";
|
|
133
173
|
var LineChart = import_react.default.memo(({ data, labels, width, height, onHover, onMove, onLeave }) => {
|
|
134
174
|
const entries = import_react.default.useMemo(() => Object.entries(data), [data]);
|
|
135
175
|
const maxVal = import_react.default.useMemo(() => {
|
|
@@ -149,19 +189,10 @@ var LineChart = import_react.default.memo(({ data, labels, width, height, onHove
|
|
|
149
189
|
),
|
|
150
190
|
[entries, count, chartW, chartH, maxVal]
|
|
151
191
|
);
|
|
192
|
+
const showPoints = count <= 100;
|
|
152
193
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("svg", { viewBox: `0 0 ${width} ${height}`, className: "chart-svg", children: [
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
const val = Math.round(maxVal * ratio);
|
|
156
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("g", { children: [
|
|
157
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("line", { x1: PADDING.left, y1: y, x2: width - PADDING.right, y2: y, className: "chart-grid" }),
|
|
158
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("text", { x: PADDING.left - 8, y: y + 4, className: "chart-axis-label", textAnchor: "end", children: val })
|
|
159
|
-
] }, ratio);
|
|
160
|
-
}),
|
|
161
|
-
labels.map((label, i) => {
|
|
162
|
-
const x = PADDING.left + i / (count - 1 || 1) * chartW;
|
|
163
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("text", { x, y: height - 8, className: "chart-axis-label", textAnchor: "middle", children: label }, i);
|
|
164
|
-
}),
|
|
194
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(GridLines, { width, height, chartH, maxVal }),
|
|
195
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(AxisLabels, { labels, count, chartW, height }),
|
|
165
196
|
entries.map(([key], di) => {
|
|
166
197
|
const palette = getPalette(LINE_BAR_PALETTES, di, key);
|
|
167
198
|
const color = palette[2];
|
|
@@ -176,7 +207,7 @@ var LineChart = import_react.default.memo(({ data, labels, width, height, onHove
|
|
|
176
207
|
strokeWidth: "2"
|
|
177
208
|
}
|
|
178
209
|
),
|
|
179
|
-
points.map((p, i) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
210
|
+
showPoints && points.map((p, i) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
180
211
|
"circle",
|
|
181
212
|
{
|
|
182
213
|
cx: p.x,
|
|
@@ -214,19 +245,10 @@ var CurveChart = import_react.default.memo(({ data, labels, width, height, onHov
|
|
|
214
245
|
),
|
|
215
246
|
[entries, count, chartW, chartH, maxVal]
|
|
216
247
|
);
|
|
248
|
+
const showPoints = count <= 100;
|
|
217
249
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("svg", { viewBox: `0 0 ${width} ${height}`, className: "chart-svg", children: [
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
const val = Math.round(maxVal * ratio);
|
|
221
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("g", { children: [
|
|
222
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("line", { x1: PADDING.left, y1: y, x2: width - PADDING.right, y2: y, className: "chart-grid" }),
|
|
223
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("text", { x: PADDING.left - 8, y: y + 4, className: "chart-axis-label", textAnchor: "end", children: val })
|
|
224
|
-
] }, ratio);
|
|
225
|
-
}),
|
|
226
|
-
labels.map((label, i) => {
|
|
227
|
-
const x = PADDING.left + i / (count - 1 || 1) * chartW;
|
|
228
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("text", { x, y: height - 8, className: "chart-axis-label", textAnchor: "middle", children: label }, i);
|
|
229
|
-
}),
|
|
250
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(GridLines, { width, height, chartH, maxVal }),
|
|
251
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(AxisLabels, { labels, count, chartW, height }),
|
|
230
252
|
entries.map(([key], di) => {
|
|
231
253
|
const palette = getPalette(LINE_BAR_PALETTES, di, key);
|
|
232
254
|
const color = palette[2];
|
|
@@ -242,7 +264,7 @@ var CurveChart = import_react.default.memo(({ data, labels, width, height, onHov
|
|
|
242
264
|
] }) }),
|
|
243
265
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: areaPath, fill: `url(#${gradientId})` }),
|
|
244
266
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: linePath, fill: "none", stroke: color, strokeWidth: "2" }),
|
|
245
|
-
points.map((p, i) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
267
|
+
showPoints && points.map((p, i) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
246
268
|
"circle",
|
|
247
269
|
{
|
|
248
270
|
cx: p.x,
|
|
@@ -272,11 +294,11 @@ var BarChart = import_react.default.memo(({ data, labels, width, height, onHover
|
|
|
272
294
|
const chartW = width - PADDING.left - PADDING.right;
|
|
273
295
|
const chartH = height - PADDING.top - PADDING.bottom;
|
|
274
296
|
const groupW = chartW / count;
|
|
275
|
-
const barW = Math.min(32, groupW * 0.7 / groupCount);
|
|
297
|
+
const barW = Math.max(1, Math.min(32, groupW * 0.7 / groupCount));
|
|
276
298
|
const bars = import_react.default.useMemo(
|
|
277
299
|
() => entries.map(
|
|
278
300
|
([, values], di) => values.map((v, i) => {
|
|
279
|
-
const h = v / maxVal * chartH;
|
|
301
|
+
const h = Math.max(0, v / maxVal * chartH);
|
|
280
302
|
const x = PADDING.left + groupW * i + (groupW - barW * groupCount) / 2 + barW * di;
|
|
281
303
|
const y = PADDING.top + chartH - h;
|
|
282
304
|
return { x, y, w: barW, h, v };
|
|
@@ -284,16 +306,13 @@ var BarChart = import_react.default.memo(({ data, labels, width, height, onHover
|
|
|
284
306
|
),
|
|
285
307
|
[entries, maxVal, chartH, groupW, barW, groupCount]
|
|
286
308
|
);
|
|
309
|
+
const barLabelStep = getLabelStep(count, chartW);
|
|
287
310
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("svg", { viewBox: `0 0 ${width} ${height}`, className: "chart-svg", children: [
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.
|
|
292
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("line", { x1: PADDING.left, y1: y, x2: width - PADDING.right, y2: y, className: "chart-grid" }),
|
|
293
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("text", { x: PADDING.left - 8, y: y + 4, className: "chart-axis-label", textAnchor: "end", children: val })
|
|
294
|
-
] }, ratio);
|
|
311
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(GridLines, { width, height, chartH, maxVal }),
|
|
312
|
+
labels.map((label, i) => {
|
|
313
|
+
if (i % barLabelStep !== 0) return null;
|
|
314
|
+
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);
|
|
295
315
|
}),
|
|
296
|
-
labels.map((label, i) => /* @__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)),
|
|
297
316
|
entries.map(([key], di) => {
|
|
298
317
|
const palette = getPalette(LINE_BAR_PALETTES, di, key);
|
|
299
318
|
const color = palette[2];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/components/Chart/Chart.tsx
|
|
2
2
|
import React from "react";
|
|
3
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
4
4
|
var CATEGORICAL_COUNT = 8;
|
|
5
5
|
var LINE_BAR_PALETTES = Array.from({ length: CATEGORICAL_COUNT }, (_, i) => {
|
|
6
6
|
const n = i + 1;
|
|
@@ -49,14 +49,23 @@ var useChartSize = (ref) => {
|
|
|
49
49
|
React.useEffect(() => {
|
|
50
50
|
const el = ref.current;
|
|
51
51
|
if (!el) return;
|
|
52
|
+
let rafId = 0;
|
|
52
53
|
const observer = new ResizeObserver((entries) => {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
cancelAnimationFrame(rafId);
|
|
55
|
+
rafId = requestAnimationFrame(() => {
|
|
56
|
+
const entry = entries[0];
|
|
57
|
+
if (!entry) return;
|
|
58
|
+
const { width, height } = entry.contentRect;
|
|
59
|
+
const w = Math.floor(width);
|
|
60
|
+
const h = Math.floor(height);
|
|
61
|
+
setSize((prev) => prev.width === w && prev.height === h ? prev : { width: w, height: h });
|
|
62
|
+
});
|
|
57
63
|
});
|
|
58
64
|
observer.observe(el);
|
|
59
|
-
return () =>
|
|
65
|
+
return () => {
|
|
66
|
+
cancelAnimationFrame(rafId);
|
|
67
|
+
observer.disconnect();
|
|
68
|
+
};
|
|
60
69
|
}, [ref]);
|
|
61
70
|
return size;
|
|
62
71
|
};
|
|
@@ -68,15 +77,21 @@ var useChartTooltip = (enabled) => {
|
|
|
68
77
|
content: ""
|
|
69
78
|
});
|
|
70
79
|
const containerRef = React.useRef(null);
|
|
80
|
+
const rafRef = React.useRef(0);
|
|
71
81
|
const move = React.useCallback((e) => {
|
|
72
82
|
if (!enabled) return;
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
83
|
+
const clientX = e.clientX;
|
|
84
|
+
const clientY = e.clientY;
|
|
85
|
+
cancelAnimationFrame(rafRef.current);
|
|
86
|
+
rafRef.current = requestAnimationFrame(() => {
|
|
87
|
+
const rect = containerRef.current?.getBoundingClientRect();
|
|
88
|
+
if (!rect) return;
|
|
89
|
+
setTooltip((prev) => ({
|
|
90
|
+
...prev,
|
|
91
|
+
x: clientX - rect.left,
|
|
92
|
+
y: clientY - rect.top - 12
|
|
93
|
+
}));
|
|
94
|
+
});
|
|
80
95
|
}, [enabled]);
|
|
81
96
|
const show = React.useCallback((e, content) => {
|
|
82
97
|
if (!enabled) return;
|
|
@@ -90,10 +105,35 @@ var useChartTooltip = (enabled) => {
|
|
|
90
105
|
});
|
|
91
106
|
}, [enabled]);
|
|
92
107
|
const hide = React.useCallback(() => {
|
|
108
|
+
cancelAnimationFrame(rafRef.current);
|
|
93
109
|
setTooltip((prev) => ({ ...prev, visible: false }));
|
|
94
110
|
}, []);
|
|
95
111
|
return { tooltip, show, hide, move, containerRef };
|
|
96
112
|
};
|
|
113
|
+
var GridLines = React.memo(({ width, height, chartH, maxVal }) => /* @__PURE__ */ jsx(Fragment, { children: [0, 0.25, 0.5, 0.75, 1].map((ratio) => {
|
|
114
|
+
const y = PADDING.top + (1 - ratio) * chartH;
|
|
115
|
+
const val = Math.round(maxVal * ratio);
|
|
116
|
+
return /* @__PURE__ */ jsxs("g", { children: [
|
|
117
|
+
/* @__PURE__ */ jsx("line", { x1: PADDING.left, y1: y, x2: width - PADDING.right, y2: y, className: "chart-grid" }),
|
|
118
|
+
/* @__PURE__ */ jsx("text", { x: PADDING.left - 8, y: y + 4, className: "chart-axis-label", textAnchor: "end", children: val })
|
|
119
|
+
] }, ratio);
|
|
120
|
+
}) }));
|
|
121
|
+
GridLines.displayName = "GridLines";
|
|
122
|
+
var getLabelStep = (count, chartW) => {
|
|
123
|
+
const minLabelWidth = 40;
|
|
124
|
+
const maxLabels = Math.floor(chartW / minLabelWidth);
|
|
125
|
+
if (count <= maxLabels) return 1;
|
|
126
|
+
return Math.ceil(count / maxLabels);
|
|
127
|
+
};
|
|
128
|
+
var AxisLabels = React.memo(({ labels, count, chartW, height }) => {
|
|
129
|
+
const step = getLabelStep(count, chartW);
|
|
130
|
+
return /* @__PURE__ */ jsx(Fragment, { children: labels.map((label, i) => {
|
|
131
|
+
if (i % step !== 0) return null;
|
|
132
|
+
const x = PADDING.left + i / (count - 1 || 1) * chartW;
|
|
133
|
+
return /* @__PURE__ */ jsx("text", { x, y: height - 8, className: "chart-axis-label", textAnchor: "middle", children: label }, i);
|
|
134
|
+
}) });
|
|
135
|
+
});
|
|
136
|
+
AxisLabels.displayName = "AxisLabels";
|
|
97
137
|
var LineChart = React.memo(({ data, labels, width, height, onHover, onMove, onLeave }) => {
|
|
98
138
|
const entries = React.useMemo(() => Object.entries(data), [data]);
|
|
99
139
|
const maxVal = React.useMemo(() => {
|
|
@@ -113,19 +153,10 @@ var LineChart = React.memo(({ data, labels, width, height, onHover, onMove, onLe
|
|
|
113
153
|
),
|
|
114
154
|
[entries, count, chartW, chartH, maxVal]
|
|
115
155
|
);
|
|
156
|
+
const showPoints = count <= 100;
|
|
116
157
|
return /* @__PURE__ */ jsxs("svg", { viewBox: `0 0 ${width} ${height}`, className: "chart-svg", children: [
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
const val = Math.round(maxVal * ratio);
|
|
120
|
-
return /* @__PURE__ */ jsxs("g", { children: [
|
|
121
|
-
/* @__PURE__ */ jsx("line", { x1: PADDING.left, y1: y, x2: width - PADDING.right, y2: y, className: "chart-grid" }),
|
|
122
|
-
/* @__PURE__ */ jsx("text", { x: PADDING.left - 8, y: y + 4, className: "chart-axis-label", textAnchor: "end", children: val })
|
|
123
|
-
] }, ratio);
|
|
124
|
-
}),
|
|
125
|
-
labels.map((label, i) => {
|
|
126
|
-
const x = PADDING.left + i / (count - 1 || 1) * chartW;
|
|
127
|
-
return /* @__PURE__ */ jsx("text", { x, y: height - 8, className: "chart-axis-label", textAnchor: "middle", children: label }, i);
|
|
128
|
-
}),
|
|
158
|
+
/* @__PURE__ */ jsx(GridLines, { width, height, chartH, maxVal }),
|
|
159
|
+
/* @__PURE__ */ jsx(AxisLabels, { labels, count, chartW, height }),
|
|
129
160
|
entries.map(([key], di) => {
|
|
130
161
|
const palette = getPalette(LINE_BAR_PALETTES, di, key);
|
|
131
162
|
const color = palette[2];
|
|
@@ -140,7 +171,7 @@ var LineChart = React.memo(({ data, labels, width, height, onHover, onMove, onLe
|
|
|
140
171
|
strokeWidth: "2"
|
|
141
172
|
}
|
|
142
173
|
),
|
|
143
|
-
points.map((p, i) => /* @__PURE__ */ jsx(
|
|
174
|
+
showPoints && points.map((p, i) => /* @__PURE__ */ jsx(
|
|
144
175
|
"circle",
|
|
145
176
|
{
|
|
146
177
|
cx: p.x,
|
|
@@ -178,19 +209,10 @@ var CurveChart = React.memo(({ data, labels, width, height, onHover, onMove, onL
|
|
|
178
209
|
),
|
|
179
210
|
[entries, count, chartW, chartH, maxVal]
|
|
180
211
|
);
|
|
212
|
+
const showPoints = count <= 100;
|
|
181
213
|
return /* @__PURE__ */ jsxs("svg", { viewBox: `0 0 ${width} ${height}`, className: "chart-svg", children: [
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
const val = Math.round(maxVal * ratio);
|
|
185
|
-
return /* @__PURE__ */ jsxs("g", { children: [
|
|
186
|
-
/* @__PURE__ */ jsx("line", { x1: PADDING.left, y1: y, x2: width - PADDING.right, y2: y, className: "chart-grid" }),
|
|
187
|
-
/* @__PURE__ */ jsx("text", { x: PADDING.left - 8, y: y + 4, className: "chart-axis-label", textAnchor: "end", children: val })
|
|
188
|
-
] }, ratio);
|
|
189
|
-
}),
|
|
190
|
-
labels.map((label, i) => {
|
|
191
|
-
const x = PADDING.left + i / (count - 1 || 1) * chartW;
|
|
192
|
-
return /* @__PURE__ */ jsx("text", { x, y: height - 8, className: "chart-axis-label", textAnchor: "middle", children: label }, i);
|
|
193
|
-
}),
|
|
214
|
+
/* @__PURE__ */ jsx(GridLines, { width, height, chartH, maxVal }),
|
|
215
|
+
/* @__PURE__ */ jsx(AxisLabels, { labels, count, chartW, height }),
|
|
194
216
|
entries.map(([key], di) => {
|
|
195
217
|
const palette = getPalette(LINE_BAR_PALETTES, di, key);
|
|
196
218
|
const color = palette[2];
|
|
@@ -206,7 +228,7 @@ var CurveChart = React.memo(({ data, labels, width, height, onHover, onMove, onL
|
|
|
206
228
|
] }) }),
|
|
207
229
|
/* @__PURE__ */ jsx("path", { d: areaPath, fill: `url(#${gradientId})` }),
|
|
208
230
|
/* @__PURE__ */ jsx("path", { d: linePath, fill: "none", stroke: color, strokeWidth: "2" }),
|
|
209
|
-
points.map((p, i) => /* @__PURE__ */ jsx(
|
|
231
|
+
showPoints && points.map((p, i) => /* @__PURE__ */ jsx(
|
|
210
232
|
"circle",
|
|
211
233
|
{
|
|
212
234
|
cx: p.x,
|
|
@@ -236,11 +258,11 @@ var BarChart = React.memo(({ data, labels, width, height, onHover, onMove, onLea
|
|
|
236
258
|
const chartW = width - PADDING.left - PADDING.right;
|
|
237
259
|
const chartH = height - PADDING.top - PADDING.bottom;
|
|
238
260
|
const groupW = chartW / count;
|
|
239
|
-
const barW = Math.min(32, groupW * 0.7 / groupCount);
|
|
261
|
+
const barW = Math.max(1, Math.min(32, groupW * 0.7 / groupCount));
|
|
240
262
|
const bars = React.useMemo(
|
|
241
263
|
() => entries.map(
|
|
242
264
|
([, values], di) => values.map((v, i) => {
|
|
243
|
-
const h = v / maxVal * chartH;
|
|
265
|
+
const h = Math.max(0, v / maxVal * chartH);
|
|
244
266
|
const x = PADDING.left + groupW * i + (groupW - barW * groupCount) / 2 + barW * di;
|
|
245
267
|
const y = PADDING.top + chartH - h;
|
|
246
268
|
return { x, y, w: barW, h, v };
|
|
@@ -248,16 +270,13 @@ var BarChart = React.memo(({ data, labels, width, height, onHover, onMove, onLea
|
|
|
248
270
|
),
|
|
249
271
|
[entries, maxVal, chartH, groupW, barW, groupCount]
|
|
250
272
|
);
|
|
273
|
+
const barLabelStep = getLabelStep(count, chartW);
|
|
251
274
|
return /* @__PURE__ */ jsxs("svg", { viewBox: `0 0 ${width} ${height}`, className: "chart-svg", children: [
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
return /* @__PURE__ */
|
|
256
|
-
/* @__PURE__ */ jsx("line", { x1: PADDING.left, y1: y, x2: width - PADDING.right, y2: y, className: "chart-grid" }),
|
|
257
|
-
/* @__PURE__ */ jsx("text", { x: PADDING.left - 8, y: y + 4, className: "chart-axis-label", textAnchor: "end", children: val })
|
|
258
|
-
] }, ratio);
|
|
275
|
+
/* @__PURE__ */ jsx(GridLines, { width, height, chartH, maxVal }),
|
|
276
|
+
labels.map((label, i) => {
|
|
277
|
+
if (i % barLabelStep !== 0) return null;
|
|
278
|
+
return /* @__PURE__ */ jsx("text", { x: PADDING.left + groupW * i + groupW / 2, y: height - 8, className: "chart-axis-label", textAnchor: "middle", children: label }, i);
|
|
259
279
|
}),
|
|
260
|
-
labels.map((label, i) => /* @__PURE__ */ jsx("text", { x: PADDING.left + groupW * i + groupW / 2, y: height - 8, className: "chart-axis-label", textAnchor: "middle", children: label }, i)),
|
|
261
280
|
entries.map(([key], di) => {
|
|
262
281
|
const palette = getPalette(LINE_BAR_PALETTES, di, key);
|
|
263
282
|
const color = palette[2];
|