@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.
Files changed (98) hide show
  1. package/esm/charts/area-chart/index.d.ts +2 -2
  2. package/esm/charts/area-chart/index.js +28 -23
  3. package/esm/charts/bar-chart/index.d.ts +1 -1
  4. package/esm/charts/bar-chart/index.js +18 -21
  5. package/esm/charts/candlestick-chart/index.d.ts +2 -2
  6. package/esm/charts/candlestick-chart/index.js +243 -180
  7. package/esm/charts/combo-chart/index.d.ts +1 -1
  8. package/esm/charts/combo-chart/index.js +9 -20
  9. package/esm/charts/funnel-chart/index.d.ts +2 -2
  10. package/esm/charts/funnel-chart/index.js +134 -108
  11. package/esm/charts/gauge-chart/index.d.ts +1 -1
  12. package/esm/charts/gauge-chart/index.js +103 -105
  13. package/esm/charts/graph-chart/index.d.ts +3 -3
  14. package/esm/charts/graph-chart/index.js +155 -114
  15. package/esm/charts/heatmap-chart/index.d.ts +2 -2
  16. package/esm/charts/heatmap-chart/index.js +180 -135
  17. package/esm/charts/line-chart/index.d.ts +2 -2
  18. package/esm/charts/line-chart/index.js +29 -24
  19. package/esm/charts/pie-chart/index.d.ts +2 -2
  20. package/esm/charts/pie-chart/index.d.ts.map +1 -1
  21. package/esm/charts/pie-chart/index.js +199 -139
  22. package/esm/charts/radar-chart/index.d.ts +2 -2
  23. package/esm/charts/radar-chart/index.d.ts.map +1 -1
  24. package/esm/charts/radar-chart/index.js +155 -128
  25. package/esm/charts/ring-progress/index.d.ts +1 -1
  26. package/esm/charts/ring-progress/index.js +82 -82
  27. package/esm/charts/sankey-chart/index.d.ts +3 -3
  28. package/esm/charts/sankey-chart/index.js +172 -141
  29. package/esm/charts/scatter-chart/index.d.ts +3 -3
  30. package/esm/charts/scatter-chart/index.d.ts.map +1 -1
  31. package/esm/charts/scatter-chart/index.js +226 -159
  32. package/esm/charts/sparkline/index.d.ts +1 -1
  33. package/esm/charts/sparkline/index.js +82 -66
  34. package/esm/charts/tree-chart/index.d.ts +3 -3
  35. package/esm/charts/tree-chart/index.js +129 -102
  36. package/esm/charts/treemap-chart/index.d.ts +3 -3
  37. package/esm/charts/treemap-chart/index.js +163 -141
  38. package/esm/charts/waterfall-chart/index.d.ts +2 -2
  39. package/esm/charts/waterfall-chart/index.js +166 -121
  40. package/esm/components/Legend.d.ts +5 -4
  41. package/esm/components/Legend.d.ts.map +1 -1
  42. package/esm/components/Legend.js +80 -48
  43. package/esm/components/Tooltip.d.ts +2 -2
  44. package/esm/components/Tooltip.js +63 -71
  45. package/esm/components/chart/index.d.ts +5 -2
  46. package/esm/components/chart/index.d.ts.map +1 -1
  47. package/esm/components/chart/index.js +81 -102
  48. package/esm/components/chart.less +13 -0
  49. package/esm/core/animation.js +32 -43
  50. package/esm/core/export.d.ts +34 -0
  51. package/esm/core/export.d.ts.map +1 -0
  52. package/esm/core/export.js +390 -0
  53. package/esm/core/force.js +23 -45
  54. package/esm/core/format.js +49 -52
  55. package/esm/core/hierarchy.d.ts +1 -1
  56. package/esm/core/hierarchy.js +61 -92
  57. package/esm/core/layout.d.ts +1 -1
  58. package/esm/core/layout.js +33 -50
  59. package/esm/core/sampling.js +31 -53
  60. package/esm/core/sankey.js +36 -55
  61. package/esm/core/scale.js +73 -86
  62. package/esm/core/shape.js +102 -133
  63. package/esm/core/sync.d.ts +41 -0
  64. package/esm/core/sync.d.ts.map +1 -0
  65. package/esm/core/sync.js +120 -0
  66. package/esm/hooks/useChartExport.d.ts +19 -0
  67. package/esm/hooks/useChartExport.d.ts.map +1 -0
  68. package/esm/hooks/useChartExport.js +35 -0
  69. package/esm/hooks/useChartTheme.d.ts +6 -5
  70. package/esm/hooks/useChartTheme.d.ts.map +1 -1
  71. package/esm/hooks/useChartTheme.js +18 -18
  72. package/esm/hooks/useChartTransition.d.ts +1 -1
  73. package/esm/hooks/useChartTransition.js +59 -73
  74. package/esm/hooks/useElementSize.js +20 -28
  75. package/esm/hooks/usePlotPointer.d.ts +23 -0
  76. package/esm/hooks/usePlotPointer.d.ts.map +1 -0
  77. package/esm/hooks/usePlotPointer.js +94 -0
  78. package/esm/index.d.ts +56 -50
  79. package/esm/index.d.ts.map +1 -1
  80. package/esm/index.js +137 -47
  81. package/esm/internal/CartesianChart.d.ts +1 -1
  82. package/esm/internal/CartesianChart.d.ts.map +1 -1
  83. package/esm/internal/CartesianChart.js +667 -485
  84. package/esm/internal/model.d.ts +2 -2
  85. package/esm/internal/model.js +45 -60
  86. package/esm/scene/canvas.d.ts +1 -1
  87. package/esm/scene/canvas.js +101 -107
  88. package/esm/scene/svg.d.ts +1 -1
  89. package/esm/scene/svg.js +107 -99
  90. package/esm/scene/types.js +9 -15
  91. package/esm/style.css +10 -0
  92. package/esm/theme/index.d.ts +2 -2
  93. package/esm/theme/index.d.ts.map +1 -1
  94. package/esm/theme/index.js +145 -170
  95. package/esm/types.d.ts +7 -3
  96. package/esm/types.d.ts.map +1 -1
  97. package/esm/types.js +1 -1
  98. package/package.json +2 -2
@@ -1,5 +1,7 @@
1
- import React, { useCallback, useMemo, useState } from 'react';
2
- import { classNames, prefixCls } from '@aura-react-comp/shared';
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 as _jsx } from "react/jsx-runtime";
16
- import { jsxs as _jsxs } from "react/jsx-runtime";
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 = 'x',
21
+ xKey = "x",
27
22
  series = [],
28
- width = '100%',
23
+ width = "100%",
29
24
  height = 320,
30
25
  theme: themeInput,
31
26
  palette,
32
27
  legend = true,
33
28
  tooltip = true,
34
- symbol = 'circle',
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(() => data.map(row => {
50
- const raw = row[xKey];
51
- const num = typeof raw === 'number' ? raw : Number(raw);
52
- return Number.isFinite(num) ? num : null;
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
- visible: !config.hidden && !hiddenKeys.includes(config.key)
65
- })), [series, data, theme, hiddenKeys]);
66
- const animKey = typeof animation === 'object' ? JSON.stringify(animation) : String(animation);
67
- const animConfig = useMemo(() => resolveAnimation(animation),
68
- // eslint-disable-next-line react-hooks/exhaustive-deps
69
- [animKey]);
70
-
71
- // 每个系列一行数值,更新时在旧值之间插值
72
- const valueMatrix = useMemo(() => seriesList.map(item => item.values), [seriesList]);
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) continue;
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 === undefined) return;
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) return [min - 1, max + 1];
100
- // 两端留 4% 余量,避免点被裁在轴线上
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) return [min - 1, max + 1];
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(() => linearTicks(yDomain[0], yDomain[1], tickCount), [yDomain, tickCount]);
113
- const xTicks = useMemo(() => linearTicks(xDomain[0], xDomain[1], Math.round(tickCount * 1.3)), [xDomain, tickCount]);
114
- const yLabels = useMemo(() => yTicks.map(tick => formatNumber(tick)), [yTicks]);
115
- const xLabels = useMemo(() => xTicks.map(tick => formatNumber(tick)), [xTicks]);
116
- const layout = useMemo(() => computeLayout({
117
- width: Math.max(size.width, 0),
118
- height: Math.max(size.height, 0),
119
- yLabels,
120
- xLabels,
121
- theme
122
- }), [size.width, size.height, yLabels, xLabels, theme]);
123
- const {
124
- plot
125
- } = layout;
126
- const xScale = useMemo(() => createLinearScale({
127
- domain: xDomain,
128
- range: [plot.x, plot.x + plot.width]
129
- }), [xDomain, plot.x, plot.width]);
130
- const yScale = useMemo(() => createLinearScale({
131
- domain: yDomain,
132
- range: [plot.y + plot.height, plot.y]
133
- }), [yDomain, plot.y, plot.height]);
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) return [];
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: 'line',
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(' ') || undefined
172
+ strokeDasharray: theme.grid.dash.join(" ") || void 0
149
173
  });
150
174
  }
151
175
  yTicks.forEach((tick, index) => {
152
176
  nodes.push({
153
- kind: 'text',
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: 'end',
161
- baseline: 'middle',
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) return;
191
+ if (x < plot.x - 1 || x > plot.x + plot.width + 1)
192
+ return;
168
193
  nodes.push({
169
- kind: 'text',
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: 'middle',
201
+ anchor: "middle",
177
202
  fontFamily: theme.font.family
178
203
  });
179
204
  });
180
205
  nodes.push({
181
- kind: 'line',
182
- key: 'x-axis',
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: 'line',
192
- key: 'y-axis',
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
- const local = staggerProgress(progress, pointIndex, points.length, animConfig.stagger);
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: 'path',
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: 'none'
243
+ pointerEvents: "none"
215
244
  });
216
245
  });
217
246
  return nodes;
218
- }, [plot, yTicks, xTicks, yLabels, xLabels, yScale, xScale, points, theme, progress, animBaseY, activeKey, symbol, symbolSize, animConfig.stagger]);
219
-
220
- /** 指针 → 最近的点(限定 28px 内,避免远处空白也触发) */
221
- const findNearest = useCallback((clientX, clientY) => {
222
- const element = ref.current;
223
- if (!element || !points.length) return null;
224
- const rect = element.getBoundingClientRect();
225
- const localX = clientX - rect.left;
226
- const localY = clientY - rect.top;
227
- let best = null;
228
- let minDistance = 28;
229
- for (const point of points) {
230
- const px = xScale.scale(point.x);
231
- const py = yScale.scale(point.y);
232
- const distance = Math.hypot(px - localX, py - localY);
233
- if (distance < minDistance) {
234
- minDistance = distance;
235
- best = point;
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
- return best;
239
- }, [ref, points, xScale, yScale]);
283
+ return best;
284
+ },
285
+ [ref, points, xScale, yScale]
286
+ );
240
287
  const activePoint = useMemo(() => {
241
- if (!activeKey) return null;
242
- return points.find(point => `${point.seriesKey}-${point.xIndex}` === activeKey) ?? null;
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
- key: activePoint.seriesKey,
249
- name: activePoint.seriesName,
250
- color: activePoint.color,
251
- value: activePoint.y,
252
- formatted: formatNumber(activePoint.y)
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(prev => prev.includes(key) ? prev.filter(item => item !== key) : [...prev, key]);
313
+ const toggle = useCallback((key) => {
314
+ setHiddenKeys(
315
+ (prev) => prev.includes(key) ? prev.filter((item) => item !== key) : [...prev, key]
316
+ );
263
317
  }, []);
264
- const autoAriaLabel = ariaLabel ?? `散点图:${seriesList.map(item => item.name).join('、')}`;
265
- return /*#__PURE__*/_jsxs("div", {
266
- className: classNames(prefixCls('chart'), className),
267
- style: {
268
- width,
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
- "data-aura-chart": "scatter",
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
+ };
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { type ChartThemeInput } from '../../theme';
2
+ import { type ChartThemeInput } from '../../theme/index.js';
3
3
  export interface SparklineProps {
4
4
  data: number[];
5
5
  type?: 'line' | 'area' | 'bar';