@aura-react-comp/charts 0.2.0 → 0.4.0
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/esm/charts/area-chart/index.d.ts +2 -2
- package/esm/charts/area-chart/index.js +28 -23
- package/esm/charts/bar-chart/index.d.ts +1 -1
- package/esm/charts/bar-chart/index.js +18 -21
- package/esm/charts/candlestick-chart/index.d.ts +2 -2
- package/esm/charts/candlestick-chart/index.js +243 -180
- package/esm/charts/combo-chart/index.d.ts +1 -1
- package/esm/charts/combo-chart/index.js +9 -20
- package/esm/charts/funnel-chart/index.d.ts +2 -2
- package/esm/charts/funnel-chart/index.js +134 -108
- package/esm/charts/gauge-chart/index.d.ts +1 -1
- package/esm/charts/gauge-chart/index.js +103 -105
- package/esm/charts/graph-chart/index.d.ts +3 -3
- package/esm/charts/graph-chart/index.js +155 -114
- package/esm/charts/heatmap-chart/index.d.ts +2 -2
- package/esm/charts/heatmap-chart/index.js +180 -135
- package/esm/charts/line-chart/index.d.ts +2 -2
- package/esm/charts/line-chart/index.js +29 -24
- package/esm/charts/pie-chart/index.d.ts +2 -2
- package/esm/charts/pie-chart/index.d.ts.map +1 -1
- package/esm/charts/pie-chart/index.js +199 -139
- package/esm/charts/radar-chart/index.d.ts +2 -2
- package/esm/charts/radar-chart/index.d.ts.map +1 -1
- package/esm/charts/radar-chart/index.js +155 -128
- package/esm/charts/ring-progress/index.d.ts +1 -1
- package/esm/charts/ring-progress/index.js +82 -82
- package/esm/charts/sankey-chart/index.d.ts +3 -3
- package/esm/charts/sankey-chart/index.js +172 -141
- package/esm/charts/scatter-chart/index.d.ts +3 -3
- package/esm/charts/scatter-chart/index.d.ts.map +1 -1
- package/esm/charts/scatter-chart/index.js +226 -159
- package/esm/charts/sparkline/index.d.ts +1 -1
- package/esm/charts/sparkline/index.js +82 -66
- package/esm/charts/tree-chart/index.d.ts +3 -3
- package/esm/charts/tree-chart/index.js +129 -102
- package/esm/charts/treemap-chart/index.d.ts +3 -3
- package/esm/charts/treemap-chart/index.js +163 -141
- package/esm/charts/waterfall-chart/index.d.ts +2 -2
- package/esm/charts/waterfall-chart/index.js +166 -121
- package/esm/components/Legend.d.ts +5 -4
- package/esm/components/Legend.d.ts.map +1 -1
- package/esm/components/Legend.js +80 -48
- package/esm/components/Tooltip.d.ts +2 -2
- package/esm/components/Tooltip.js +63 -71
- package/esm/components/chart/index.d.ts +5 -2
- package/esm/components/chart/index.d.ts.map +1 -1
- package/esm/components/chart/index.js +81 -102
- package/esm/components/chart.less +13 -0
- package/esm/core/animation.js +32 -43
- package/esm/core/export.d.ts +34 -0
- package/esm/core/export.d.ts.map +1 -0
- package/esm/core/export.js +390 -0
- package/esm/core/force.js +23 -45
- package/esm/core/format.js +49 -52
- package/esm/core/hierarchy.d.ts +1 -1
- package/esm/core/hierarchy.js +61 -92
- package/esm/core/layout.d.ts +1 -1
- package/esm/core/layout.js +33 -50
- package/esm/core/sampling.js +31 -53
- package/esm/core/sankey.js +36 -55
- package/esm/core/scale.js +73 -86
- package/esm/core/shape.js +102 -133
- package/esm/core/sync.d.ts +41 -0
- package/esm/core/sync.d.ts.map +1 -0
- package/esm/core/sync.js +120 -0
- package/esm/hooks/useChartExport.d.ts +19 -0
- package/esm/hooks/useChartExport.d.ts.map +1 -0
- package/esm/hooks/useChartExport.js +35 -0
- package/esm/hooks/useChartTheme.d.ts +6 -5
- package/esm/hooks/useChartTheme.d.ts.map +1 -1
- package/esm/hooks/useChartTheme.js +18 -18
- package/esm/hooks/useChartTransition.d.ts +1 -1
- package/esm/hooks/useChartTransition.js +59 -73
- package/esm/hooks/useElementSize.js +20 -28
- package/esm/hooks/usePlotPointer.d.ts +23 -0
- package/esm/hooks/usePlotPointer.d.ts.map +1 -0
- package/esm/hooks/usePlotPointer.js +94 -0
- package/esm/index.d.ts +56 -50
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +137 -47
- package/esm/internal/CartesianChart.d.ts +1 -1
- package/esm/internal/CartesianChart.d.ts.map +1 -1
- package/esm/internal/CartesianChart.js +667 -485
- package/esm/internal/model.d.ts +2 -2
- package/esm/internal/model.js +45 -60
- package/esm/scene/canvas.d.ts +1 -1
- package/esm/scene/canvas.js +101 -107
- package/esm/scene/svg.d.ts +1 -1
- package/esm/scene/svg.js +107 -99
- package/esm/scene/types.js +9 -15
- package/esm/style.css +10 -0
- package/esm/theme/index.d.ts +2 -2
- package/esm/theme/index.d.ts.map +1 -1
- package/esm/theme/index.js +145 -170
- package/esm/types.d.ts +7 -3
- package/esm/types.d.ts.map +1 -1
- package/esm/types.js +1 -1
- package/package.json +2 -2
|
@@ -1,31 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
// src/charts/radar-chart/index.tsx
|
|
3
|
+
import { useCallback, useMemo, useState } from "react";
|
|
4
|
+
import { classNames, prefixCls } from "@aura-react-comp/shared";
|
|
3
5
|
import { SvgScene } from "../../scene/svg";
|
|
4
6
|
import { withAlpha } from "../../theme";
|
|
5
7
|
import { useChartTheme } from "../../hooks/useChartTheme";
|
|
6
8
|
import { useElementSize } from "../../hooks/useElementSize";
|
|
7
9
|
import { useChartTransition } from "../../hooks/useChartTransition";
|
|
10
|
+
import { usePlotPointer } from "../../hooks/usePlotPointer";
|
|
8
11
|
import { resolveAnimation, staggerProgress } from "../../core/animation";
|
|
9
12
|
import { Legend } from "../../components/Legend";
|
|
10
13
|
import { Tooltip } from "../../components/Tooltip";
|
|
11
14
|
import { estimateTextWidth } from "../../core/format";
|
|
12
|
-
import { jsx
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* 雷达图。
|
|
18
|
-
*
|
|
19
|
-
* 几何本质是极坐标:n 个指标把圆周等分,每个指标一条轴,
|
|
20
|
-
* 数值映射为「沿轴距圆心的距离」。
|
|
21
|
-
*
|
|
22
|
-
* 与饼图相反,雷达图不编码总量,它编码的是**形状**——多指标的综合轮廓。
|
|
23
|
-
* 因此各指标的 max 必须由使用者显式给出:自动取最大值会让「谁更好」失去参照。
|
|
24
|
-
*/
|
|
25
|
-
export function RadarChart({
|
|
15
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
16
|
+
var GRID_LABEL_GAP = 10;
|
|
17
|
+
function RadarChart({
|
|
26
18
|
indicators = [],
|
|
27
19
|
series = [],
|
|
28
|
-
width =
|
|
20
|
+
width = "100%",
|
|
29
21
|
height = 320,
|
|
30
22
|
theme: themeInput,
|
|
31
23
|
palette,
|
|
@@ -36,71 +28,74 @@ export function RadarChart({
|
|
|
36
28
|
className,
|
|
37
29
|
style,
|
|
38
30
|
ariaLabel,
|
|
39
|
-
emptyText =
|
|
31
|
+
emptyText = "暂无数据"
|
|
40
32
|
}) {
|
|
41
33
|
const theme = useChartTheme(themeInput, palette);
|
|
42
|
-
const {
|
|
43
|
-
ref,
|
|
44
|
-
size
|
|
45
|
-
} = useElementSize();
|
|
34
|
+
const { ref, size } = useElementSize();
|
|
46
35
|
const [hiddenKeys, setHiddenKeys] = useState([]);
|
|
47
36
|
const [activeKey, setActiveKey] = useState(null);
|
|
48
|
-
const visible = useMemo(
|
|
49
|
-
|
|
37
|
+
const visible = useMemo(
|
|
38
|
+
() => series.filter((item) => !hiddenKeys.includes(item.key)),
|
|
39
|
+
[series, hiddenKeys]
|
|
40
|
+
);
|
|
41
|
+
const colors = useMemo(
|
|
42
|
+
() => series.map(
|
|
43
|
+
(item, index) => item.color ?? theme.palette[index % theme.palette.length]
|
|
44
|
+
),
|
|
45
|
+
[series, theme.palette]
|
|
46
|
+
);
|
|
50
47
|
const geometry = useMemo(() => {
|
|
51
48
|
const count = Math.max(indicators.length, 3);
|
|
52
|
-
|
|
53
|
-
|
|
49
|
+
const maxLabel = indicators.reduce(
|
|
50
|
+
(max, item) => Math.max(max, estimateTextWidth(item.name, theme.font.size)),
|
|
51
|
+
0
|
|
52
|
+
);
|
|
54
53
|
const padding = Math.min(64, maxLabel / 2 + GRID_LABEL_GAP + 6);
|
|
55
54
|
const radius = Math.max(0, Math.min(size.width, size.height) / 2 - padding);
|
|
56
|
-
return {
|
|
57
|
-
cx: size.width / 2,
|
|
58
|
-
cy: size.height / 2,
|
|
59
|
-
radius,
|
|
60
|
-
count
|
|
61
|
-
};
|
|
55
|
+
return { cx: size.width / 2, cy: size.height / 2, radius, count };
|
|
62
56
|
}, [indicators, size.width, size.height, theme.font.size]);
|
|
63
|
-
const angleAt = useCallback(
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
const
|
|
57
|
+
const angleAt = useCallback(
|
|
58
|
+
(index) => -Math.PI / 2 + index * Math.PI * 2 / geometry.count,
|
|
59
|
+
[geometry.count]
|
|
60
|
+
);
|
|
61
|
+
const animKey = typeof animation === "object" ? JSON.stringify(animation) : String(animation);
|
|
62
|
+
const animConfig = useMemo(
|
|
63
|
+
() => resolveAnimation(animation),
|
|
64
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
65
|
+
[animKey]
|
|
66
|
+
);
|
|
67
|
+
const valueMatrix = useMemo(
|
|
68
|
+
() => series.map((item) => item.values),
|
|
69
|
+
[series]
|
|
70
|
+
);
|
|
69
71
|
const transition = useChartTransition(valueMatrix, animConfig);
|
|
70
72
|
const progress = transition.progress;
|
|
71
73
|
const scene = useMemo(() => {
|
|
72
|
-
const {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
radius
|
|
76
|
-
} = geometry;
|
|
77
|
-
if (radius <= 0 || indicators.length < 3) return [];
|
|
74
|
+
const { cx, cy, radius } = geometry;
|
|
75
|
+
if (radius <= 0 || indicators.length < 3)
|
|
76
|
+
return [];
|
|
78
77
|
const nodes = [];
|
|
79
|
-
|
|
80
|
-
// 同心多边形网格
|
|
81
78
|
for (let level = 1; level <= levels; level += 1) {
|
|
82
79
|
const ratio = level / levels;
|
|
83
80
|
const points = indicators.map((_, index) => {
|
|
84
81
|
const angle = angleAt(index);
|
|
85
82
|
return `${cx + Math.cos(angle) * radius * ratio},${cy + Math.sin(angle) * radius * ratio}`;
|
|
86
|
-
}).join(
|
|
83
|
+
}).join("L");
|
|
87
84
|
nodes.push({
|
|
88
|
-
kind:
|
|
85
|
+
kind: "path",
|
|
89
86
|
key: `grid-${level}`,
|
|
90
87
|
d: `M${points}Z`,
|
|
91
|
-
fill: level % 2 === 0 ? withAlpha(theme.grid.line, 0.05) :
|
|
88
|
+
fill: level % 2 === 0 ? withAlpha(theme.grid.line, 0.05) : "none",
|
|
92
89
|
stroke: theme.grid.line,
|
|
93
90
|
strokeWidth: theme.grid.lineWidth,
|
|
94
|
-
strokeDasharray: level === levels ?
|
|
95
|
-
pointerEvents:
|
|
91
|
+
strokeDasharray: level === levels ? void 0 : theme.grid.dash.join(" "),
|
|
92
|
+
pointerEvents: "none"
|
|
96
93
|
});
|
|
97
94
|
}
|
|
98
|
-
|
|
99
|
-
// 轴线
|
|
100
95
|
indicators.forEach((_, index) => {
|
|
101
96
|
const angle = angleAt(index);
|
|
102
97
|
nodes.push({
|
|
103
|
-
kind:
|
|
98
|
+
kind: "line",
|
|
104
99
|
key: `axis-${index}`,
|
|
105
100
|
x1: cx,
|
|
106
101
|
y1: cy,
|
|
@@ -108,42 +103,41 @@ export function RadarChart({
|
|
|
108
103
|
y2: cy + Math.sin(angle) * radius,
|
|
109
104
|
stroke: theme.axis.line,
|
|
110
105
|
strokeWidth: 1,
|
|
111
|
-
pointerEvents:
|
|
106
|
+
pointerEvents: "none"
|
|
112
107
|
});
|
|
113
108
|
});
|
|
114
|
-
|
|
115
|
-
// 指标名
|
|
116
109
|
indicators.forEach((indicator, index) => {
|
|
117
110
|
const angle = angleAt(index);
|
|
118
111
|
const x = cx + Math.cos(angle) * (radius + GRID_LABEL_GAP);
|
|
119
112
|
const y = cy + Math.sin(angle) * (radius + GRID_LABEL_GAP);
|
|
120
113
|
const cos = Math.cos(angle);
|
|
121
114
|
nodes.push({
|
|
122
|
-
kind:
|
|
115
|
+
kind: "text",
|
|
123
116
|
key: `label-${index}`,
|
|
124
117
|
x,
|
|
125
118
|
y,
|
|
126
119
|
text: indicator.name,
|
|
127
120
|
fill: theme.text.secondary,
|
|
128
121
|
fontSize: theme.font.size,
|
|
129
|
-
anchor: Math.abs(cos) < 0.2 ?
|
|
130
|
-
baseline:
|
|
122
|
+
anchor: Math.abs(cos) < 0.2 ? "middle" : cos > 0 ? "start" : "end",
|
|
123
|
+
baseline: "middle",
|
|
131
124
|
fontFamily: theme.font.family
|
|
132
125
|
});
|
|
133
126
|
});
|
|
134
|
-
|
|
135
|
-
// 数据多边形
|
|
136
|
-
visible.forEach(item => {
|
|
127
|
+
visible.forEach((item) => {
|
|
137
128
|
const seriesIndex = series.indexOf(item);
|
|
138
129
|
const color = colors[seriesIndex] ?? theme.palette[0];
|
|
139
130
|
const isActive = activeKey === item.key;
|
|
140
|
-
|
|
141
|
-
|
|
131
|
+
const local = staggerProgress(
|
|
132
|
+
progress,
|
|
133
|
+
seriesIndex,
|
|
134
|
+
visible.length,
|
|
135
|
+
animConfig.stagger
|
|
136
|
+
);
|
|
142
137
|
const row = transition.values[seriesIndex] ?? item.values;
|
|
143
138
|
const points = indicators.map((indicator, index) => {
|
|
144
139
|
const raw = row[index] ?? 0;
|
|
145
140
|
const max = indicator.max || 1;
|
|
146
|
-
// 超出 max 的数值会画到网格外,视觉上必须夹紧而不是溢出画布
|
|
147
141
|
const ratio = Math.min(1.2, Math.max(0, raw / max)) * local;
|
|
148
142
|
const angle = angleAt(index);
|
|
149
143
|
return {
|
|
@@ -152,19 +146,19 @@ export function RadarChart({
|
|
|
152
146
|
};
|
|
153
147
|
});
|
|
154
148
|
nodes.push({
|
|
155
|
-
kind:
|
|
149
|
+
kind: "path",
|
|
156
150
|
key: `area-${item.key}`,
|
|
157
|
-
d: `M${points.map(p => `${p.x},${p.y}`).join(
|
|
151
|
+
d: `M${points.map((p) => `${p.x},${p.y}`).join("L")}Z`,
|
|
158
152
|
fill: withAlpha(color, isActive ? 0.28 : 0.16),
|
|
159
153
|
stroke: color,
|
|
160
154
|
strokeWidth: isActive ? theme.series.emphasisWidth : theme.series.lineWidth,
|
|
161
|
-
linejoin:
|
|
155
|
+
linejoin: "round",
|
|
162
156
|
opacity: activeKey === null || isActive ? 1 : 0.5,
|
|
163
|
-
pointerEvents:
|
|
157
|
+
pointerEvents: "none"
|
|
164
158
|
});
|
|
165
159
|
points.forEach((point, index) => {
|
|
166
160
|
nodes.push({
|
|
167
|
-
kind:
|
|
161
|
+
kind: "circle",
|
|
168
162
|
key: `dot-${item.key}-${index}`,
|
|
169
163
|
cx: point.x,
|
|
170
164
|
cy: point.y,
|
|
@@ -173,28 +167,46 @@ export function RadarChart({
|
|
|
173
167
|
stroke: color,
|
|
174
168
|
strokeWidth: 2,
|
|
175
169
|
opacity: activeKey === null || isActive ? 1 : 0.5,
|
|
176
|
-
pointerEvents:
|
|
170
|
+
pointerEvents: "none"
|
|
177
171
|
});
|
|
178
172
|
});
|
|
179
173
|
});
|
|
180
174
|
return nodes;
|
|
181
|
-
}, [
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
175
|
+
}, [
|
|
176
|
+
geometry,
|
|
177
|
+
indicators,
|
|
178
|
+
levels,
|
|
179
|
+
angleAt,
|
|
180
|
+
theme,
|
|
181
|
+
visible,
|
|
182
|
+
colors,
|
|
183
|
+
series,
|
|
184
|
+
activeKey,
|
|
185
|
+
progress,
|
|
186
|
+
transition.values,
|
|
187
|
+
animConfig.stagger
|
|
188
|
+
]);
|
|
189
|
+
const findNearest = useCallback(
|
|
190
|
+
(clientX, clientY) => {
|
|
191
|
+
const element = ref.current;
|
|
192
|
+
if (!element || visible.length === 0)
|
|
193
|
+
return null;
|
|
194
|
+
const rect = element.getBoundingClientRect();
|
|
195
|
+
const localX = clientX - rect.left;
|
|
196
|
+
const localY = clientY - rect.top;
|
|
197
|
+
const distance = Math.hypot(localX - geometry.cx, localY - geometry.cy);
|
|
198
|
+
if (distance > geometry.radius + 12)
|
|
199
|
+
return null;
|
|
200
|
+
return visible[0].key;
|
|
201
|
+
},
|
|
202
|
+
[ref, visible, geometry]
|
|
203
|
+
);
|
|
194
204
|
const active = useMemo(() => {
|
|
195
|
-
if (!activeKey)
|
|
196
|
-
|
|
197
|
-
|
|
205
|
+
if (!activeKey)
|
|
206
|
+
return null;
|
|
207
|
+
const item = series.find((entry) => entry.key === activeKey);
|
|
208
|
+
if (!item)
|
|
209
|
+
return null;
|
|
198
210
|
const color = colors[series.indexOf(item)] ?? theme.palette[0];
|
|
199
211
|
return {
|
|
200
212
|
item,
|
|
@@ -218,45 +230,60 @@ export function RadarChart({
|
|
|
218
230
|
color: colors[index],
|
|
219
231
|
visible: !hiddenKeys.includes(item.key)
|
|
220
232
|
}));
|
|
221
|
-
const toggle = useCallback(key => {
|
|
222
|
-
setHiddenKeys(
|
|
233
|
+
const toggle = useCallback((key) => {
|
|
234
|
+
setHiddenKeys(
|
|
235
|
+
(prev) => prev.includes(key) ? prev.filter((item) => item !== key) : [...prev, key]
|
|
236
|
+
);
|
|
223
237
|
}, []);
|
|
224
|
-
const
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
width,
|
|
229
|
-
height,
|
|
230
|
-
...style
|
|
231
|
-
},
|
|
232
|
-
"data-aura-chart": "radar",
|
|
233
|
-
children: [/*#__PURE__*/_jsx(Legend, {
|
|
234
|
-
items: legendItems,
|
|
235
|
-
theme: theme,
|
|
236
|
-
config: legend,
|
|
237
|
-
onToggle: toggle
|
|
238
|
-
}), /*#__PURE__*/_jsxs("div", {
|
|
239
|
-
ref: ref,
|
|
240
|
-
className: prefixCls('chart__plot'),
|
|
241
|
-
onPointerMove: event => setActiveKey(findNearest(event.clientX, event.clientY)),
|
|
242
|
-
onPointerLeave: () => setActiveKey(null),
|
|
243
|
-
children: [indicators.length < 3 || visible.length === 0 ? /*#__PURE__*/_jsx("div", {
|
|
244
|
-
className: prefixCls('chart__empty'),
|
|
245
|
-
children: emptyText
|
|
246
|
-
}) : /*#__PURE__*/_jsx(SvgScene, {
|
|
247
|
-
nodes: scene,
|
|
248
|
-
width: size.width,
|
|
249
|
-
height: size.height,
|
|
250
|
-
ariaLabel: autoAriaLabel
|
|
251
|
-
}), /*#__PURE__*/_jsx(Tooltip, {
|
|
252
|
-
payload: active?.payload ?? null,
|
|
253
|
-
x: geometry.cx,
|
|
254
|
-
y: geometry.cy - geometry.radius * 0.6,
|
|
255
|
-
containerWidth: size.width,
|
|
256
|
-
containerHeight: size.height,
|
|
257
|
-
theme: theme,
|
|
258
|
-
config: tooltip
|
|
259
|
-
})]
|
|
260
|
-
})]
|
|
238
|
+
const pointerHandlers = usePlotPointer({
|
|
239
|
+
disabled: tooltip === false || visible.length === 0,
|
|
240
|
+
onMove: (clientX, clientY) => setActiveKey(findNearest(clientX, clientY)),
|
|
241
|
+
onLeave: () => setActiveKey(null)
|
|
261
242
|
});
|
|
262
|
-
}
|
|
243
|
+
const autoAriaLabel = ariaLabel ?? `雷达图:${indicators.map((item) => item.name).join("、")}`;
|
|
244
|
+
return /* @__PURE__ */ jsxs(
|
|
245
|
+
"div",
|
|
246
|
+
{
|
|
247
|
+
className: classNames(prefixCls("chart"), className),
|
|
248
|
+
style: { width, height, ...style },
|
|
249
|
+
"data-aura-chart": "radar",
|
|
250
|
+
children: [
|
|
251
|
+
/* @__PURE__ */ jsx(
|
|
252
|
+
Legend,
|
|
253
|
+
{
|
|
254
|
+
items: legendItems,
|
|
255
|
+
theme,
|
|
256
|
+
config: legend,
|
|
257
|
+
onToggle: toggle
|
|
258
|
+
}
|
|
259
|
+
),
|
|
260
|
+
/* @__PURE__ */ jsxs("div", { ref, className: prefixCls("chart__plot"), ...pointerHandlers, children: [
|
|
261
|
+
indicators.length < 3 || visible.length === 0 ? /* @__PURE__ */ jsx("div", { className: prefixCls("chart__empty"), children: emptyText }) : /* @__PURE__ */ jsx(
|
|
262
|
+
SvgScene,
|
|
263
|
+
{
|
|
264
|
+
nodes: scene,
|
|
265
|
+
width: size.width,
|
|
266
|
+
height: size.height,
|
|
267
|
+
ariaLabel: autoAriaLabel
|
|
268
|
+
}
|
|
269
|
+
),
|
|
270
|
+
/* @__PURE__ */ jsx(
|
|
271
|
+
Tooltip,
|
|
272
|
+
{
|
|
273
|
+
payload: (active == null ? void 0 : active.payload) ?? null,
|
|
274
|
+
x: geometry.cx,
|
|
275
|
+
y: geometry.cy - geometry.radius * 0.6,
|
|
276
|
+
containerWidth: size.width,
|
|
277
|
+
containerHeight: size.height,
|
|
278
|
+
theme,
|
|
279
|
+
config: tooltip
|
|
280
|
+
}
|
|
281
|
+
)
|
|
282
|
+
] })
|
|
283
|
+
]
|
|
284
|
+
}
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
export {
|
|
288
|
+
RadarChart
|
|
289
|
+
};
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
// src/charts/ring-progress/index.tsx
|
|
3
|
+
import { useMemo } from "react";
|
|
4
|
+
import { classNames, prefixCls } from "@aura-react-comp/shared";
|
|
3
5
|
import { SvgScene } from "../../scene/svg";
|
|
4
6
|
import { arcLinePath } from "../../core/shape";
|
|
5
7
|
import { formatPercent } from "../../core/format";
|
|
@@ -7,17 +9,9 @@ import { withAlpha } from "../../theme";
|
|
|
7
9
|
import { useChartTheme } from "../../hooks/useChartTheme";
|
|
8
10
|
import { useChartTransition } from "../../hooks/useChartTransition";
|
|
9
11
|
import { resolveAnimation } from "../../core/animation";
|
|
10
|
-
import { jsx
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* 环形进度。
|
|
16
|
-
*
|
|
17
|
-
* 与 GaugeChart 的分工:仪表盘强调「在量程中的位置」(带刻度与端点),
|
|
18
|
-
* 环形进度强调「完成度」(无刻度、更紧凑),常用于表格单元格与卡片角落。
|
|
19
|
-
*/
|
|
20
|
-
export function RingProgress({
|
|
12
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
13
|
+
var DEG = Math.PI / 180;
|
|
14
|
+
function RingProgress({
|
|
21
15
|
value,
|
|
22
16
|
max = 100,
|
|
23
17
|
size = 160,
|
|
@@ -35,16 +29,20 @@ export function RingProgress({
|
|
|
35
29
|
style,
|
|
36
30
|
ariaLabel
|
|
37
31
|
}) {
|
|
32
|
+
var _a;
|
|
38
33
|
const theme = useChartTheme(themeInput, palette);
|
|
39
|
-
const animKey = typeof animation ===
|
|
40
|
-
const animConfig = useMemo(
|
|
41
|
-
|
|
42
|
-
|
|
34
|
+
const animKey = typeof animation === "object" ? JSON.stringify(animation) : String(animation);
|
|
35
|
+
const animConfig = useMemo(
|
|
36
|
+
() => resolveAnimation(animation),
|
|
37
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
38
|
+
[animKey]
|
|
39
|
+
);
|
|
43
40
|
const transition = useChartTransition([[value]], animConfig);
|
|
44
41
|
const progress = transition.progress;
|
|
45
|
-
const animatedValue = transition.values[0]
|
|
42
|
+
const animatedValue = ((_a = transition.values[0]) == null ? void 0 : _a[0]) ?? value;
|
|
46
43
|
const ratio = useMemo(() => {
|
|
47
|
-
if (max === 0)
|
|
44
|
+
if (max === 0)
|
|
45
|
+
return 0;
|
|
48
46
|
return Math.min(1, Math.max(0, animatedValue / max));
|
|
49
47
|
}, [animatedValue, max]);
|
|
50
48
|
const accent = color ?? theme.emphasis;
|
|
@@ -52,85 +50,87 @@ export function RingProgress({
|
|
|
52
50
|
const geometry = useMemo(() => {
|
|
53
51
|
const center = size / 2;
|
|
54
52
|
const radius = Math.max(0, center - thickness / 2 - 1);
|
|
55
|
-
return {
|
|
56
|
-
cx: center,
|
|
57
|
-
cy: center,
|
|
58
|
-
radius,
|
|
59
|
-
arc: radius * 2 * Math.PI
|
|
60
|
-
};
|
|
53
|
+
return { cx: center, cy: center, radius, arc: radius * 2 * Math.PI };
|
|
61
54
|
}, [size, thickness]);
|
|
62
55
|
const start = startAngle * DEG;
|
|
63
56
|
const end = start + Math.PI * 2 * ratio * progress;
|
|
64
57
|
const scene = useMemo(() => {
|
|
65
|
-
const {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
radius
|
|
69
|
-
} = geometry;
|
|
70
|
-
if (radius <= 0) return [];
|
|
58
|
+
const { cx, cy, radius } = geometry;
|
|
59
|
+
if (radius <= 0)
|
|
60
|
+
return [];
|
|
71
61
|
const nodes = [];
|
|
72
62
|
nodes.push({
|
|
73
|
-
kind:
|
|
74
|
-
key:
|
|
63
|
+
kind: "path",
|
|
64
|
+
key: "track",
|
|
75
65
|
d: arcLinePath(cx, cy, radius, 0, Math.PI * 2),
|
|
76
|
-
fill:
|
|
66
|
+
fill: "none",
|
|
77
67
|
stroke: track,
|
|
78
68
|
strokeWidth: thickness,
|
|
79
|
-
pointerEvents:
|
|
69
|
+
pointerEvents: "none"
|
|
80
70
|
});
|
|
81
|
-
if (end > start +
|
|
71
|
+
if (end > start + 1e-4) {
|
|
82
72
|
nodes.push({
|
|
83
|
-
kind:
|
|
84
|
-
key:
|
|
73
|
+
kind: "path",
|
|
74
|
+
key: "value",
|
|
85
75
|
d: arcLinePath(cx, cy, radius, start, end),
|
|
86
|
-
fill:
|
|
76
|
+
fill: "none",
|
|
87
77
|
stroke: accent,
|
|
88
78
|
strokeWidth: thickness,
|
|
89
|
-
linecap: round ?
|
|
90
|
-
pointerEvents:
|
|
79
|
+
linecap: round ? "round" : "butt",
|
|
80
|
+
pointerEvents: "none"
|
|
91
81
|
});
|
|
92
82
|
}
|
|
93
83
|
return nodes;
|
|
94
84
|
}, [geometry, start, end, track, accent, thickness, round]);
|
|
95
85
|
const autoAriaLabel = ariaLabel ?? `进度:${Math.round(ratio * 100)}%`;
|
|
96
|
-
return
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
height: size,
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
}
|
|
86
|
+
return /* @__PURE__ */ jsxs(
|
|
87
|
+
"div",
|
|
88
|
+
{
|
|
89
|
+
className: classNames(prefixCls("chart"), className),
|
|
90
|
+
style: { width: size, height: size, position: "relative", ...style },
|
|
91
|
+
"data-aura-chart": "ring-progress",
|
|
92
|
+
role: "img",
|
|
93
|
+
"aria-label": autoAriaLabel,
|
|
94
|
+
children: [
|
|
95
|
+
/* @__PURE__ */ jsx("div", { className: prefixCls("chart__plot"), children: /* @__PURE__ */ jsx(
|
|
96
|
+
SvgScene,
|
|
97
|
+
{
|
|
98
|
+
nodes: scene,
|
|
99
|
+
width: size,
|
|
100
|
+
height: size,
|
|
101
|
+
ariaLabel: autoAriaLabel
|
|
102
|
+
}
|
|
103
|
+
) }),
|
|
104
|
+
/* @__PURE__ */ jsx(
|
|
105
|
+
"div",
|
|
106
|
+
{
|
|
107
|
+
style: {
|
|
108
|
+
position: "absolute",
|
|
109
|
+
inset: 0,
|
|
110
|
+
display: "flex",
|
|
111
|
+
flexDirection: "column",
|
|
112
|
+
alignItems: "center",
|
|
113
|
+
justifyContent: "center",
|
|
114
|
+
pointerEvents: "none"
|
|
115
|
+
},
|
|
116
|
+
children: children ?? (showPercent ? /* @__PURE__ */ jsx(
|
|
117
|
+
"span",
|
|
118
|
+
{
|
|
119
|
+
style: {
|
|
120
|
+
fontSize: Math.max(14, size * 0.16),
|
|
121
|
+
fontWeight: theme.font.weightMedium,
|
|
122
|
+
color: theme.text.primary,
|
|
123
|
+
fontVariantNumeric: "tabular-nums"
|
|
124
|
+
},
|
|
125
|
+
children: formatPercent(value, max || 1, 0)
|
|
126
|
+
}
|
|
127
|
+
) : null)
|
|
128
|
+
}
|
|
129
|
+
)
|
|
130
|
+
]
|
|
131
|
+
}
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
export {
|
|
135
|
+
RingProgress
|
|
136
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { type ChartThemeInput } from '../../theme';
|
|
3
|
-
import { type SankeyLinkInput, type SankeyNode } from '../../core/sankey';
|
|
4
|
-
import type { ChartAnimationInput, TooltipConfig } from '../../types';
|
|
2
|
+
import { type ChartThemeInput } from '../../theme/index.js';
|
|
3
|
+
import { type SankeyLinkInput, type SankeyNode } from '../../core/sankey.js';
|
|
4
|
+
import type { ChartAnimationInput, TooltipConfig } from '../../types.js';
|
|
5
5
|
export interface SankeyChartProps {
|
|
6
6
|
/** 节点列表;只传 links 时会自动从 links 推导 */
|
|
7
7
|
nodes?: SankeyNode[];
|