@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,5 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
// src/charts/scatter-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 { createLinearScale, extentOf, linearTicks } from "../../core/scale";
|
|
5
7
|
import { computeLayout, suggestTickCount } from "../../core/layout";
|
|
@@ -9,67 +11,66 @@ import { colorAt } from "../../theme";
|
|
|
9
11
|
import { useChartTheme } from "../../hooks/useChartTheme";
|
|
10
12
|
import { useElementSize } from "../../hooks/useElementSize";
|
|
11
13
|
import { useChartTransition } from "../../hooks/useChartTransition";
|
|
14
|
+
import { usePlotPointer } from "../../hooks/usePlotPointer";
|
|
12
15
|
import { resolveAnimation, staggerProgress } from "../../core/animation";
|
|
13
16
|
import { Legend } from "../../components/Legend";
|
|
14
17
|
import { Tooltip } from "../../components/Tooltip";
|
|
15
|
-
import { jsx
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* 散点图。
|
|
19
|
-
*
|
|
20
|
-
* 与折线/柱状不同,散点的 x 是**连续的数值轴**而非分类轴:
|
|
21
|
-
* 分类轴会把 [1, 2, 100] 摆成等间距,严重扭曲相关性判断。
|
|
22
|
-
* 因此这里不复用 CartesianChart 的 band 坐标,改为线性 x 轴。
|
|
23
|
-
*/
|
|
24
|
-
export function ScatterChart({
|
|
18
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
19
|
+
function ScatterChart({
|
|
25
20
|
data = [],
|
|
26
|
-
xKey =
|
|
21
|
+
xKey = "x",
|
|
27
22
|
series = [],
|
|
28
|
-
width =
|
|
23
|
+
width = "100%",
|
|
29
24
|
height = 320,
|
|
30
25
|
theme: themeInput,
|
|
31
26
|
palette,
|
|
32
27
|
legend = true,
|
|
33
28
|
tooltip = true,
|
|
34
|
-
symbol =
|
|
29
|
+
symbol = "circle",
|
|
35
30
|
symbolSize = 8,
|
|
36
31
|
animation = true,
|
|
37
32
|
className,
|
|
38
33
|
style,
|
|
39
34
|
ariaLabel,
|
|
40
|
-
emptyText =
|
|
35
|
+
emptyText = "暂无数据"
|
|
41
36
|
}) {
|
|
42
37
|
const theme = useChartTheme(themeInput, palette);
|
|
43
|
-
const {
|
|
44
|
-
ref,
|
|
45
|
-
size
|
|
46
|
-
} = useElementSize();
|
|
38
|
+
const { ref, size } = useElementSize();
|
|
47
39
|
const [hiddenKeys, setHiddenKeys] = useState([]);
|
|
48
40
|
const [activeKey, setActiveKey] = useState(null);
|
|
49
|
-
const xValues = useMemo(
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}), [data, xKey]);
|
|
54
|
-
const seriesList = useMemo(() => series.map((config, index) => ({
|
|
55
|
-
config,
|
|
56
|
-
key: config.key,
|
|
57
|
-
name: config.name ?? config.key,
|
|
58
|
-
color: config.color ?? colorAt(theme, index),
|
|
59
|
-
values: data.map((row, rowIndex) => {
|
|
60
|
-
const raw = config.data ? config.data[rowIndex] : row[config.key];
|
|
61
|
-
const num = typeof raw === 'number' ? raw : Number(raw);
|
|
41
|
+
const xValues = useMemo(
|
|
42
|
+
() => data.map((row) => {
|
|
43
|
+
const raw = row[xKey];
|
|
44
|
+
const num = typeof raw === "number" ? raw : Number(raw);
|
|
62
45
|
return Number.isFinite(num) ? num : null;
|
|
63
46
|
}),
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
47
|
+
[data, xKey]
|
|
48
|
+
);
|
|
49
|
+
const seriesList = useMemo(
|
|
50
|
+
() => series.map((config, index) => ({
|
|
51
|
+
config,
|
|
52
|
+
key: config.key,
|
|
53
|
+
name: config.name ?? config.key,
|
|
54
|
+
color: config.color ?? colorAt(theme, index),
|
|
55
|
+
values: data.map((row, rowIndex) => {
|
|
56
|
+
const raw = config.data ? config.data[rowIndex] : row[config.key];
|
|
57
|
+
const num = typeof raw === "number" ? raw : Number(raw);
|
|
58
|
+
return Number.isFinite(num) ? num : null;
|
|
59
|
+
}),
|
|
60
|
+
visible: !config.hidden && !hiddenKeys.includes(config.key)
|
|
61
|
+
})),
|
|
62
|
+
[series, data, theme, hiddenKeys]
|
|
63
|
+
);
|
|
64
|
+
const animKey = typeof animation === "object" ? JSON.stringify(animation) : String(animation);
|
|
65
|
+
const animConfig = useMemo(
|
|
66
|
+
() => resolveAnimation(animation),
|
|
67
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
68
|
+
[animKey]
|
|
69
|
+
);
|
|
70
|
+
const valueMatrix = useMemo(
|
|
71
|
+
() => seriesList.map((item) => item.values),
|
|
72
|
+
[seriesList]
|
|
73
|
+
);
|
|
73
74
|
const transition = useChartTransition(valueMatrix, animConfig);
|
|
74
75
|
const progress = transition.progress;
|
|
75
76
|
const points = useMemo(() => {
|
|
@@ -77,11 +78,13 @@ export function ScatterChart({
|
|
|
77
78
|
let seriesIndex = -1;
|
|
78
79
|
for (const item of seriesList) {
|
|
79
80
|
seriesIndex += 1;
|
|
80
|
-
if (!item.visible)
|
|
81
|
+
if (!item.visible)
|
|
82
|
+
continue;
|
|
81
83
|
const row = transition.values[seriesIndex] ?? item.values;
|
|
82
84
|
row.forEach((value, index) => {
|
|
83
85
|
const x = xValues[index];
|
|
84
|
-
if (value === null || x === null || x ===
|
|
86
|
+
if (value === null || x === null || x === void 0)
|
|
87
|
+
return;
|
|
85
88
|
list.push({
|
|
86
89
|
seriesKey: item.key,
|
|
87
90
|
seriesName: item.name,
|
|
@@ -96,48 +99,69 @@ export function ScatterChart({
|
|
|
96
99
|
}, [seriesList, xValues, transition.values]);
|
|
97
100
|
const xDomain = useMemo(() => {
|
|
98
101
|
const [min, max] = extentOf(xValues);
|
|
99
|
-
if (min === max)
|
|
100
|
-
|
|
102
|
+
if (min === max)
|
|
103
|
+
return [min - 1, max + 1];
|
|
101
104
|
const pad = (max - min) * 0.04;
|
|
102
105
|
return [min - pad, max + pad];
|
|
103
106
|
}, [xValues]);
|
|
104
107
|
const yDomain = useMemo(() => {
|
|
105
|
-
const [min, max] = extentOf(points.map(point => point.y));
|
|
106
|
-
if (min === max)
|
|
108
|
+
const [min, max] = extentOf(points.map((point) => point.y));
|
|
109
|
+
if (min === max)
|
|
110
|
+
return [min - 1, max + 1];
|
|
107
111
|
const pad = (max - min) * 0.08;
|
|
108
112
|
return [min - pad, max + pad];
|
|
109
113
|
}, [points]);
|
|
110
114
|
const estimatedPlotHeight = Math.max(60, height - 48);
|
|
111
115
|
const tickCount = suggestTickCount(estimatedPlotHeight);
|
|
112
|
-
const yTicks = useMemo(
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
116
|
+
const yTicks = useMemo(
|
|
117
|
+
() => linearTicks(yDomain[0], yDomain[1], tickCount),
|
|
118
|
+
[yDomain, tickCount]
|
|
119
|
+
);
|
|
120
|
+
const xTicks = useMemo(
|
|
121
|
+
() => linearTicks(xDomain[0], xDomain[1], Math.round(tickCount * 1.3)),
|
|
122
|
+
[xDomain, tickCount]
|
|
123
|
+
);
|
|
124
|
+
const yLabels = useMemo(
|
|
125
|
+
() => yTicks.map((tick) => formatNumber(tick)),
|
|
126
|
+
[yTicks]
|
|
127
|
+
);
|
|
128
|
+
const xLabels = useMemo(
|
|
129
|
+
() => xTicks.map((tick) => formatNumber(tick)),
|
|
130
|
+
[xTicks]
|
|
131
|
+
);
|
|
132
|
+
const layout = useMemo(
|
|
133
|
+
() => computeLayout({
|
|
134
|
+
width: Math.max(size.width, 0),
|
|
135
|
+
height: Math.max(size.height, 0),
|
|
136
|
+
yLabels,
|
|
137
|
+
xLabels,
|
|
138
|
+
theme
|
|
139
|
+
}),
|
|
140
|
+
[size.width, size.height, yLabels, xLabels, theme]
|
|
141
|
+
);
|
|
142
|
+
const { plot } = layout;
|
|
143
|
+
const xScale = useMemo(
|
|
144
|
+
() => createLinearScale({
|
|
145
|
+
domain: xDomain,
|
|
146
|
+
range: [plot.x, plot.x + plot.width]
|
|
147
|
+
}),
|
|
148
|
+
[xDomain, plot.x, plot.width]
|
|
149
|
+
);
|
|
150
|
+
const yScale = useMemo(
|
|
151
|
+
() => createLinearScale({
|
|
152
|
+
domain: yDomain,
|
|
153
|
+
range: [plot.y + plot.height, plot.y]
|
|
154
|
+
}),
|
|
155
|
+
[yDomain, plot.y, plot.height]
|
|
156
|
+
);
|
|
134
157
|
const animBaseY = plot.y + plot.height;
|
|
135
158
|
const scene = useMemo(() => {
|
|
136
|
-
if (plot.width <= 0 || plot.height <= 0)
|
|
159
|
+
if (plot.width <= 0 || plot.height <= 0)
|
|
160
|
+
return [];
|
|
137
161
|
const nodes = [];
|
|
138
162
|
for (const tick of yTicks) {
|
|
139
163
|
nodes.push({
|
|
140
|
-
kind:
|
|
164
|
+
kind: "line",
|
|
141
165
|
key: `gy-${tick}`,
|
|
142
166
|
x1: plot.x,
|
|
143
167
|
y1: yScale.scale(tick),
|
|
@@ -145,41 +169,42 @@ export function ScatterChart({
|
|
|
145
169
|
y2: yScale.scale(tick),
|
|
146
170
|
stroke: theme.grid.line,
|
|
147
171
|
strokeWidth: theme.grid.lineWidth,
|
|
148
|
-
strokeDasharray: theme.grid.dash.join(
|
|
172
|
+
strokeDasharray: theme.grid.dash.join(" ") || void 0
|
|
149
173
|
});
|
|
150
174
|
}
|
|
151
175
|
yTicks.forEach((tick, index) => {
|
|
152
176
|
nodes.push({
|
|
153
|
-
kind:
|
|
177
|
+
kind: "text",
|
|
154
178
|
key: `yl-${index}`,
|
|
155
179
|
x: plot.x - theme.axis.tickSize - 4,
|
|
156
180
|
y: yScale.scale(tick),
|
|
157
181
|
text: yLabels[index],
|
|
158
182
|
fill: theme.axis.label,
|
|
159
183
|
fontSize: theme.font.size,
|
|
160
|
-
anchor:
|
|
161
|
-
baseline:
|
|
184
|
+
anchor: "end",
|
|
185
|
+
baseline: "middle",
|
|
162
186
|
fontFamily: theme.font.family
|
|
163
187
|
});
|
|
164
188
|
});
|
|
165
189
|
xTicks.forEach((tick, index) => {
|
|
166
190
|
const x = xScale.scale(tick);
|
|
167
|
-
if (x < plot.x - 1 || x > plot.x + plot.width + 1)
|
|
191
|
+
if (x < plot.x - 1 || x > plot.x + plot.width + 1)
|
|
192
|
+
return;
|
|
168
193
|
nodes.push({
|
|
169
|
-
kind:
|
|
194
|
+
kind: "text",
|
|
170
195
|
key: `xl-${index}`,
|
|
171
196
|
x,
|
|
172
197
|
y: plot.y + plot.height + theme.axis.tickSize + theme.font.size,
|
|
173
198
|
text: xLabels[index],
|
|
174
199
|
fill: theme.axis.label,
|
|
175
200
|
fontSize: theme.font.size,
|
|
176
|
-
anchor:
|
|
201
|
+
anchor: "middle",
|
|
177
202
|
fontFamily: theme.font.family
|
|
178
203
|
});
|
|
179
204
|
});
|
|
180
205
|
nodes.push({
|
|
181
|
-
kind:
|
|
182
|
-
key:
|
|
206
|
+
kind: "line",
|
|
207
|
+
key: "x-axis",
|
|
183
208
|
x1: plot.x,
|
|
184
209
|
y1: plot.y + plot.height,
|
|
185
210
|
x2: plot.x + plot.width,
|
|
@@ -188,8 +213,8 @@ export function ScatterChart({
|
|
|
188
213
|
strokeWidth: theme.axis.lineWidth
|
|
189
214
|
});
|
|
190
215
|
nodes.push({
|
|
191
|
-
kind:
|
|
192
|
-
key:
|
|
216
|
+
kind: "line",
|
|
217
|
+
key: "y-axis",
|
|
193
218
|
x1: plot.x,
|
|
194
219
|
y1: plot.y,
|
|
195
220
|
x2: plot.x,
|
|
@@ -200,105 +225,147 @@ export function ScatterChart({
|
|
|
200
225
|
points.forEach((point, pointIndex) => {
|
|
201
226
|
const cx = xScale.scale(point.x);
|
|
202
227
|
const targetY = yScale.scale(point.y);
|
|
203
|
-
|
|
204
|
-
|
|
228
|
+
const local = staggerProgress(
|
|
229
|
+
progress,
|
|
230
|
+
pointIndex,
|
|
231
|
+
points.length,
|
|
232
|
+
animConfig.stagger
|
|
233
|
+
);
|
|
205
234
|
const cy = animBaseY + (targetY - animBaseY) * local;
|
|
206
235
|
const isActive = activeKey === `${point.seriesKey}-${point.xIndex}`;
|
|
207
236
|
const radius = isActive ? symbolSize * 0.75 : symbolSize * 0.55;
|
|
208
237
|
nodes.push({
|
|
209
|
-
kind:
|
|
238
|
+
kind: "path",
|
|
210
239
|
key: `pt-${point.seriesKey}-${point.xIndex}`,
|
|
211
240
|
d: symbolPath(symbol, cx, cy, radius * 2),
|
|
212
241
|
fill: point.color,
|
|
213
242
|
opacity: (activeKey === null || isActive ? 0.85 : 0.35) * local,
|
|
214
|
-
pointerEvents:
|
|
243
|
+
pointerEvents: "none"
|
|
215
244
|
});
|
|
216
245
|
});
|
|
217
246
|
return nodes;
|
|
218
|
-
}, [
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
247
|
+
}, [
|
|
248
|
+
plot,
|
|
249
|
+
yTicks,
|
|
250
|
+
xTicks,
|
|
251
|
+
yLabels,
|
|
252
|
+
xLabels,
|
|
253
|
+
yScale,
|
|
254
|
+
xScale,
|
|
255
|
+
points,
|
|
256
|
+
theme,
|
|
257
|
+
progress,
|
|
258
|
+
animBaseY,
|
|
259
|
+
activeKey,
|
|
260
|
+
symbol,
|
|
261
|
+
symbolSize,
|
|
262
|
+
animConfig.stagger
|
|
263
|
+
]);
|
|
264
|
+
const findNearest = useCallback(
|
|
265
|
+
(clientX, clientY) => {
|
|
266
|
+
const element = ref.current;
|
|
267
|
+
if (!element || !points.length)
|
|
268
|
+
return null;
|
|
269
|
+
const rect = element.getBoundingClientRect();
|
|
270
|
+
const localX = clientX - rect.left;
|
|
271
|
+
const localY = clientY - rect.top;
|
|
272
|
+
let best = null;
|
|
273
|
+
let minDistance = 28;
|
|
274
|
+
for (const point of points) {
|
|
275
|
+
const px = xScale.scale(point.x);
|
|
276
|
+
const py = yScale.scale(point.y);
|
|
277
|
+
const distance = Math.hypot(px - localX, py - localY);
|
|
278
|
+
if (distance < minDistance) {
|
|
279
|
+
minDistance = distance;
|
|
280
|
+
best = point;
|
|
281
|
+
}
|
|
236
282
|
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
283
|
+
return best;
|
|
284
|
+
},
|
|
285
|
+
[ref, points, xScale, yScale]
|
|
286
|
+
);
|
|
240
287
|
const activePoint = useMemo(() => {
|
|
241
|
-
if (!activeKey)
|
|
242
|
-
|
|
288
|
+
if (!activeKey)
|
|
289
|
+
return null;
|
|
290
|
+
return points.find(
|
|
291
|
+
(point) => `${point.seriesKey}-${point.xIndex}` === activeKey
|
|
292
|
+
) ?? null;
|
|
243
293
|
}, [activeKey, points]);
|
|
244
294
|
const tooltipPayload = activePoint ? {
|
|
245
295
|
label: `${xKey}: ${formatNumber(activePoint.x)}`,
|
|
246
296
|
row: data[activePoint.xIndex] ?? null,
|
|
247
|
-
series: [
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
297
|
+
series: [
|
|
298
|
+
{
|
|
299
|
+
key: activePoint.seriesKey,
|
|
300
|
+
name: activePoint.seriesName,
|
|
301
|
+
color: activePoint.color,
|
|
302
|
+
value: activePoint.y,
|
|
303
|
+
formatted: formatNumber(activePoint.y)
|
|
304
|
+
}
|
|
305
|
+
]
|
|
254
306
|
} : null;
|
|
255
|
-
const legendItems = seriesList.map(item => ({
|
|
307
|
+
const legendItems = seriesList.map((item) => ({
|
|
256
308
|
key: item.key,
|
|
257
309
|
name: item.name,
|
|
258
310
|
color: item.color,
|
|
259
311
|
visible: item.visible
|
|
260
312
|
}));
|
|
261
|
-
const toggle = useCallback(key => {
|
|
262
|
-
setHiddenKeys(
|
|
313
|
+
const toggle = useCallback((key) => {
|
|
314
|
+
setHiddenKeys(
|
|
315
|
+
(prev) => prev.includes(key) ? prev.filter((item) => item !== key) : [...prev, key]
|
|
316
|
+
);
|
|
263
317
|
}, []);
|
|
264
|
-
const
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
height,
|
|
270
|
-
...style
|
|
318
|
+
const pointerHandlers = usePlotPointer({
|
|
319
|
+
disabled: tooltip === false || points.length === 0,
|
|
320
|
+
onMove: (clientX, clientY) => {
|
|
321
|
+
const nearest = findNearest(clientX, clientY);
|
|
322
|
+
setActiveKey(nearest ? `${nearest.seriesKey}-${nearest.xIndex}` : null);
|
|
271
323
|
},
|
|
272
|
-
|
|
273
|
-
children: [/*#__PURE__*/_jsx(Legend, {
|
|
274
|
-
items: legendItems,
|
|
275
|
-
theme: theme,
|
|
276
|
-
config: legend,
|
|
277
|
-
onToggle: toggle
|
|
278
|
-
}), /*#__PURE__*/_jsxs("div", {
|
|
279
|
-
ref: ref,
|
|
280
|
-
className: prefixCls('chart__plot'),
|
|
281
|
-
onPointerMove: event => {
|
|
282
|
-
const nearest = findNearest(event.clientX, event.clientY);
|
|
283
|
-
setActiveKey(nearest ? `${nearest.seriesKey}-${nearest.xIndex}` : null);
|
|
284
|
-
},
|
|
285
|
-
onPointerLeave: () => setActiveKey(null),
|
|
286
|
-
children: [points.length === 0 ? /*#__PURE__*/_jsx("div", {
|
|
287
|
-
className: prefixCls('chart__empty'),
|
|
288
|
-
children: emptyText
|
|
289
|
-
}) : /*#__PURE__*/_jsx(SvgScene, {
|
|
290
|
-
nodes: scene,
|
|
291
|
-
width: size.width,
|
|
292
|
-
height: size.height,
|
|
293
|
-
ariaLabel: autoAriaLabel
|
|
294
|
-
}), /*#__PURE__*/_jsx(Tooltip, {
|
|
295
|
-
payload: tooltipPayload,
|
|
296
|
-
x: activePoint ? xScale.scale(activePoint.x) : 0,
|
|
297
|
-
y: activePoint ? yScale.scale(activePoint.y) : 0,
|
|
298
|
-
containerWidth: size.width,
|
|
299
|
-
theme: theme,
|
|
300
|
-
config: tooltip
|
|
301
|
-
})]
|
|
302
|
-
})]
|
|
324
|
+
onLeave: () => setActiveKey(null)
|
|
303
325
|
});
|
|
304
|
-
}
|
|
326
|
+
const autoAriaLabel = ariaLabel ?? `散点图:${seriesList.map((item) => item.name).join("、")}`;
|
|
327
|
+
return /* @__PURE__ */ jsxs(
|
|
328
|
+
"div",
|
|
329
|
+
{
|
|
330
|
+
className: classNames(prefixCls("chart"), className),
|
|
331
|
+
style: { width, height, ...style },
|
|
332
|
+
"data-aura-chart": "scatter",
|
|
333
|
+
children: [
|
|
334
|
+
/* @__PURE__ */ jsx(
|
|
335
|
+
Legend,
|
|
336
|
+
{
|
|
337
|
+
items: legendItems,
|
|
338
|
+
theme,
|
|
339
|
+
config: legend,
|
|
340
|
+
onToggle: toggle
|
|
341
|
+
}
|
|
342
|
+
),
|
|
343
|
+
/* @__PURE__ */ jsxs("div", { ref, className: prefixCls("chart__plot"), ...pointerHandlers, children: [
|
|
344
|
+
points.length === 0 ? /* @__PURE__ */ jsx("div", { className: prefixCls("chart__empty"), children: emptyText }) : /* @__PURE__ */ jsx(
|
|
345
|
+
SvgScene,
|
|
346
|
+
{
|
|
347
|
+
nodes: scene,
|
|
348
|
+
width: size.width,
|
|
349
|
+
height: size.height,
|
|
350
|
+
ariaLabel: autoAriaLabel
|
|
351
|
+
}
|
|
352
|
+
),
|
|
353
|
+
/* @__PURE__ */ jsx(
|
|
354
|
+
Tooltip,
|
|
355
|
+
{
|
|
356
|
+
payload: tooltipPayload,
|
|
357
|
+
x: activePoint ? xScale.scale(activePoint.x) : 0,
|
|
358
|
+
y: activePoint ? yScale.scale(activePoint.y) : 0,
|
|
359
|
+
containerWidth: size.width,
|
|
360
|
+
theme,
|
|
361
|
+
config: tooltip
|
|
362
|
+
}
|
|
363
|
+
)
|
|
364
|
+
] })
|
|
365
|
+
]
|
|
366
|
+
}
|
|
367
|
+
);
|
|
368
|
+
}
|
|
369
|
+
export {
|
|
370
|
+
ScatterChart
|
|
371
|
+
};
|