@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,31 +1,23 @@
1
- import React, { useCallback, useMemo, useState } from 'react';
2
- import { classNames, prefixCls } from '@aura-react-comp/shared';
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 as _jsx } from "react/jsx-runtime";
13
- import { jsxs as _jsxs } from "react/jsx-runtime";
14
- const GRID_LABEL_GAP = 10;
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 = '100%',
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(() => series.filter(item => !hiddenKeys.includes(item.key)), [series, hiddenKeys]);
49
- const colors = useMemo(() => series.map((item, index) => item.color ?? theme.palette[index % theme.palette.length]), [series, theme.palette]);
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
- const maxLabel = indicators.reduce((max, item) => Math.max(max, estimateTextWidth(item.name, theme.font.size)), 0);
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(index => -Math.PI / 2 + index * Math.PI * 2 / geometry.count, [geometry.count]);
64
- const animKey = typeof animation === 'object' ? JSON.stringify(animation) : String(animation);
65
- const animConfig = useMemo(() => resolveAnimation(animation),
66
- // eslint-disable-next-line react-hooks/exhaustive-deps
67
- [animKey]);
68
- const valueMatrix = useMemo(() => series.map(item => item.values), [series]);
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
- cx,
74
- cy,
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('L');
83
+ }).join("L");
87
84
  nodes.push({
88
- kind: 'path',
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) : 'none',
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 ? undefined : theme.grid.dash.join(' '),
95
- pointerEvents: 'none'
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: 'line',
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: 'none'
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: 'text',
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 ? 'middle' : cos > 0 ? 'start' : 'end',
130
- baseline: 'middle',
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
- const local = staggerProgress(progress, seriesIndex, visible.length, animConfig.stagger);
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: 'path',
149
+ kind: "path",
156
150
  key: `area-${item.key}`,
157
- d: `M${points.map(p => `${p.x},${p.y}`).join('L')}Z`,
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: 'round',
155
+ linejoin: "round",
162
156
  opacity: activeKey === null || isActive ? 1 : 0.5,
163
- pointerEvents: 'none'
157
+ pointerEvents: "none"
164
158
  });
165
159
  points.forEach((point, index) => {
166
160
  nodes.push({
167
- kind: 'circle',
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: 'none'
170
+ pointerEvents: "none"
177
171
  });
178
172
  });
179
173
  });
180
174
  return nodes;
181
- }, [geometry, indicators, levels, angleAt, theme, visible, colors, series, activeKey, progress, transition.values, animConfig.stagger]);
182
-
183
- /** 指针 → 最近的多边形(按包围盒近似,够用且不引入额外几何计算) */
184
- const findNearest = useCallback((clientX, clientY) => {
185
- const element = ref.current;
186
- if (!element || visible.length === 0) return null;
187
- const rect = element.getBoundingClientRect();
188
- const localX = clientX - rect.left;
189
- const localY = clientY - rect.top;
190
- const distance = Math.hypot(localX - geometry.cx, localY - geometry.cy);
191
- if (distance > geometry.radius + 12) return null;
192
- return visible[0].key;
193
- }, [ref, visible, geometry]);
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) return null;
196
- const item = series.find(entry => entry.key === activeKey);
197
- if (!item) return null;
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(prev => prev.includes(key) ? prev.filter(item => item !== key) : [...prev, key]);
233
+ const toggle = useCallback((key) => {
234
+ setHiddenKeys(
235
+ (prev) => prev.includes(key) ? prev.filter((item) => item !== key) : [...prev, key]
236
+ );
223
237
  }, []);
224
- const autoAriaLabel = ariaLabel ?? `雷达图:${indicators.map(item => item.name).join('、')}`;
225
- return /*#__PURE__*/_jsxs("div", {
226
- className: classNames(prefixCls('chart'), className),
227
- style: {
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,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 RingProgressProps {
4
4
  /** 当前值 */
5
5
  value: number;
@@ -1,5 +1,7 @@
1
- import React, { useMemo } from 'react';
2
- import { classNames, prefixCls } from '@aura-react-comp/shared';
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 as _jsx } from "react/jsx-runtime";
11
- import { jsxs as _jsxs } from "react/jsx-runtime";
12
- const DEG = Math.PI / 180;
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 === 'object' ? JSON.stringify(animation) : String(animation);
40
- const animConfig = useMemo(() => resolveAnimation(animation),
41
- // eslint-disable-next-line react-hooks/exhaustive-deps
42
- [animKey]);
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]?.[0] ?? value;
42
+ const animatedValue = ((_a = transition.values[0]) == null ? void 0 : _a[0]) ?? value;
46
43
  const ratio = useMemo(() => {
47
- if (max === 0) return 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
- cx,
67
- cy,
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: 'path',
74
- key: 'track',
63
+ kind: "path",
64
+ key: "track",
75
65
  d: arcLinePath(cx, cy, radius, 0, Math.PI * 2),
76
- fill: 'none',
66
+ fill: "none",
77
67
  stroke: track,
78
68
  strokeWidth: thickness,
79
- pointerEvents: 'none'
69
+ pointerEvents: "none"
80
70
  });
81
- if (end > start + 0.0001) {
71
+ if (end > start + 1e-4) {
82
72
  nodes.push({
83
- kind: 'path',
84
- key: 'value',
73
+ kind: "path",
74
+ key: "value",
85
75
  d: arcLinePath(cx, cy, radius, start, end),
86
- fill: 'none',
76
+ fill: "none",
87
77
  stroke: accent,
88
78
  strokeWidth: thickness,
89
- linecap: round ? 'round' : 'butt',
90
- pointerEvents: 'none'
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 /*#__PURE__*/_jsxs("div", {
97
- className: classNames(prefixCls('chart'), className),
98
- style: {
99
- width: size,
100
- height: size,
101
- position: 'relative',
102
- ...style
103
- },
104
- "data-aura-chart": "ring-progress",
105
- role: "img",
106
- "aria-label": autoAriaLabel,
107
- children: [/*#__PURE__*/_jsx("div", {
108
- className: prefixCls('chart__plot'),
109
- children: /*#__PURE__*/_jsx(SvgScene, {
110
- nodes: scene,
111
- width: size,
112
- height: size,
113
- ariaLabel: autoAriaLabel
114
- })
115
- }), /*#__PURE__*/_jsx("div", {
116
- style: {
117
- position: 'absolute',
118
- inset: 0,
119
- display: 'flex',
120
- flexDirection: 'column',
121
- alignItems: 'center',
122
- justifyContent: 'center',
123
- pointerEvents: 'none'
124
- },
125
- children: children ?? (showPercent ? /*#__PURE__*/_jsx("span", {
126
- style: {
127
- fontSize: Math.max(14, size * 0.16),
128
- fontWeight: theme.font.weightMedium,
129
- color: theme.text.primary,
130
- fontVariantNumeric: 'tabular-nums'
131
- },
132
- children: formatPercent(value, max || 1, 0)
133
- }) : null)
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[];