@aura-react-comp/charts 0.3.1 → 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 (68) hide show
  1. package/esm/charts/area-chart/index.js +27 -23
  2. package/esm/charts/bar-chart/index.js +17 -21
  3. package/esm/charts/candlestick-chart/index.js +242 -180
  4. package/esm/charts/combo-chart/index.js +8 -20
  5. package/esm/charts/funnel-chart/index.js +133 -108
  6. package/esm/charts/gauge-chart/index.js +102 -105
  7. package/esm/charts/graph-chart/index.js +154 -114
  8. package/esm/charts/heatmap-chart/index.js +179 -135
  9. package/esm/charts/line-chart/index.js +28 -24
  10. package/esm/charts/pie-chart/index.d.ts.map +1 -1
  11. package/esm/charts/pie-chart/index.js +198 -139
  12. package/esm/charts/radar-chart/index.d.ts.map +1 -1
  13. package/esm/charts/radar-chart/index.js +154 -128
  14. package/esm/charts/ring-progress/index.js +81 -82
  15. package/esm/charts/sankey-chart/index.js +171 -141
  16. package/esm/charts/scatter-chart/index.d.ts.map +1 -1
  17. package/esm/charts/scatter-chart/index.js +225 -159
  18. package/esm/charts/sparkline/index.js +81 -66
  19. package/esm/charts/tree-chart/index.js +128 -102
  20. package/esm/charts/treemap-chart/index.js +162 -141
  21. package/esm/charts/waterfall-chart/index.js +165 -121
  22. package/esm/components/Legend.d.ts +3 -2
  23. package/esm/components/Legend.d.ts.map +1 -1
  24. package/esm/components/Legend.js +79 -48
  25. package/esm/components/Tooltip.js +62 -71
  26. package/esm/components/chart/index.d.ts +4 -1
  27. package/esm/components/chart/index.d.ts.map +1 -1
  28. package/esm/components/chart/index.js +80 -102
  29. package/esm/components/chart.less +13 -0
  30. package/esm/core/animation.js +31 -43
  31. package/esm/core/export.d.ts +34 -0
  32. package/esm/core/export.d.ts.map +1 -0
  33. package/esm/core/export.js +390 -0
  34. package/esm/core/force.js +22 -45
  35. package/esm/core/format.js +48 -52
  36. package/esm/core/hierarchy.js +60 -92
  37. package/esm/core/layout.js +32 -50
  38. package/esm/core/sampling.js +30 -53
  39. package/esm/core/sankey.js +35 -55
  40. package/esm/core/scale.js +72 -86
  41. package/esm/core/shape.js +101 -133
  42. package/esm/core/sync.d.ts +41 -0
  43. package/esm/core/sync.d.ts.map +1 -0
  44. package/esm/core/sync.js +120 -0
  45. package/esm/hooks/useChartExport.d.ts +19 -0
  46. package/esm/hooks/useChartExport.d.ts.map +1 -0
  47. package/esm/hooks/useChartExport.js +35 -0
  48. package/esm/hooks/useChartTheme.js +17 -19
  49. package/esm/hooks/useChartTransition.js +58 -73
  50. package/esm/hooks/useElementSize.js +19 -28
  51. package/esm/hooks/usePlotPointer.d.ts +23 -0
  52. package/esm/hooks/usePlotPointer.d.ts.map +1 -0
  53. package/esm/hooks/usePlotPointer.js +94 -0
  54. package/esm/index.d.ts +6 -0
  55. package/esm/index.d.ts.map +1 -1
  56. package/esm/index.js +136 -47
  57. package/esm/internal/CartesianChart.d.ts.map +1 -1
  58. package/esm/internal/CartesianChart.js +666 -485
  59. package/esm/internal/model.js +44 -60
  60. package/esm/scene/canvas.js +100 -107
  61. package/esm/scene/svg.js +106 -99
  62. package/esm/scene/types.js +8 -15
  63. package/esm/style.css +10 -0
  64. package/esm/theme/index.js +143 -171
  65. package/esm/types.d.ts +4 -0
  66. package/esm/types.d.ts.map +1 -1
  67. package/esm/types.js +0 -1
  68. package/package.json +1 -1
@@ -1,6 +1,7 @@
1
1
  'use client';
2
- import React, { useCallback, useMemo, useState } from 'react';
3
- import { classNames, prefixCls } from '@aura-react-comp/shared';
2
+ // src/charts/funnel-chart/index.tsx
3
+ import { useCallback, useMemo, useState } from "react";
4
+ import { classNames, prefixCls } from "@aura-react-comp/shared";
4
5
  import { SvgScene } from "../../scene/svg";
5
6
  import { formatNumber, formatPercent } from "../../core/format";
6
7
  import { withAlpha } from "../../theme";
@@ -9,21 +10,12 @@ import { useElementSize } from "../../hooks/useElementSize";
9
10
  import { useChartTransition } from "../../hooks/useChartTransition";
10
11
  import { resolveAnimation, staggerProgress } from "../../core/animation";
11
12
  import { Tooltip } from "../../components/Tooltip";
12
- import { jsx as _jsx } from "react/jsx-runtime";
13
- import { jsxs as _jsxs } from "react/jsx-runtime";
14
- /**
15
- * 漏斗图。
16
- *
17
- * 每一项的宽度按数值比例决定,因此它能直观表达「逐层流失」。
18
- *
19
- * 注意:漏斗图的面积编码是**非线性的**(梯形面积 ∝ 上下宽之和 × 高),
20
- * 所以不要用它做精确的比例判断——它擅长的是「看出哪一层掉得最狠」。
21
- */
22
- export function FunnelChart({
13
+ import { jsx, jsxs } from "react/jsx-runtime";
14
+ function FunnelChart({
23
15
  data = [],
24
- width = '100%',
16
+ width = "100%",
25
17
  height = 320,
26
- label = 'inside',
18
+ label = "inside",
27
19
  gap = 4,
28
20
  theme: themeInput,
29
21
  palette,
@@ -32,46 +24,50 @@ export function FunnelChart({
32
24
  className,
33
25
  style,
34
26
  ariaLabel,
35
- emptyText = '暂无数据'
27
+ emptyText = "暂无数据"
36
28
  }) {
29
+ var _a;
37
30
  const theme = useChartTheme(themeInput, palette);
38
- const {
39
- ref,
40
- size
41
- } = useElementSize();
31
+ const { ref, size } = useElementSize();
42
32
  const [activeIndex, setActiveIndex] = useState(null);
43
- const items = useMemo(() => data.map((item, index) => ({
44
- ...item,
45
- color: item.color ?? theme.palette[index % theme.palette.length],
46
- index
47
- })), [data, theme.palette]);
48
- const maxValue = useMemo(() => Math.max(...items.map(item => item.value), 1), [items]);
49
- const baseValue = items[0]?.value ?? 1;
50
- const animKey = typeof animation === 'object' ? JSON.stringify(animation) : String(animation);
51
- const animConfig = useMemo(() => resolveAnimation(animation),
52
- // eslint-disable-next-line react-hooks/exhaustive-deps
53
- [animKey]);
54
- const valueMatrix = useMemo(() => [items.map(item => item.value)], [items]);
33
+ const items = useMemo(
34
+ () => data.map((item, index) => ({
35
+ ...item,
36
+ color: item.color ?? theme.palette[index % theme.palette.length],
37
+ index
38
+ })),
39
+ [data, theme.palette]
40
+ );
41
+ const maxValue = useMemo(
42
+ () => Math.max(...items.map((item) => item.value), 1),
43
+ [items]
44
+ );
45
+ const baseValue = ((_a = items[0]) == null ? void 0 : _a.value) ?? 1;
46
+ const animKey = typeof animation === "object" ? JSON.stringify(animation) : String(animation);
47
+ const animConfig = useMemo(
48
+ () => resolveAnimation(animation),
49
+ // eslint-disable-next-line react-hooks/exhaustive-deps
50
+ [animKey]
51
+ );
52
+ const valueMatrix = useMemo(() => [items.map((item) => item.value)], [items]);
55
53
  const transition = useChartTransition(valueMatrix, animConfig);
56
54
  const progress = transition.progress;
57
55
  const scene = useMemo(() => {
58
- if (!items.length || size.width <= 0 || size.height <= 0) return [];
56
+ if (!items.length || size.width <= 0 || size.height <= 0)
57
+ return [];
59
58
  const nodes = [];
60
59
  const count = items.length;
61
60
  const slot = (size.height - gap * (count - 1)) / count;
62
- // 右侧要留给标签
63
- const labelSpace = label === 'right' ? Math.min(160, size.width * 0.32) : 0;
61
+ const labelSpace = label === "right" ? Math.min(160, size.width * 0.32) : 0;
64
62
  const maxWidth = Math.max(40, (size.width - labelSpace) * 0.82);
65
63
  const cx = (size.width - labelSpace) / 2;
66
-
67
- // 每层按自己的局部进度展开,整体呈「从上往下倾泻」的节奏
68
64
  const widthOf = (value, local) => Math.max(4, value / maxValue * maxWidth * local);
69
65
  items.forEach((item, index) => {
66
+ var _a2, _b, _c;
70
67
  const local = staggerProgress(progress, index, count, animConfig.stagger);
71
- const animatedValue = transition.values[0]?.[index] ?? item.value;
68
+ const animatedValue = ((_a2 = transition.values[0]) == null ? void 0 : _a2[index]) ?? item.value;
72
69
  const topWidth = widthOf(animatedValue, local);
73
- // 最后一项收口,形成漏斗的尖底;其余项以「下一项的宽度」为底边
74
- const nextValue = transition.values[0]?.[index + 1] ?? items[index + 1]?.value ?? 0;
70
+ const nextValue = ((_b = transition.values[0]) == null ? void 0 : _b[index + 1]) ?? ((_c = items[index + 1]) == null ? void 0 : _c.value) ?? 0;
75
71
  const nextWidth = index < count - 1 ? widthOf(nextValue, local) : topWidth * 0.6;
76
72
  const y = index * (slot + gap);
77
73
  const isActive = activeIndex === index;
@@ -80,34 +76,33 @@ export function FunnelChart({
80
76
  const x3 = cx + nextWidth / 2;
81
77
  const x4 = cx - nextWidth / 2;
82
78
  nodes.push({
83
- kind: 'path',
79
+ kind: "path",
84
80
  key: `funnel-${index}`,
85
81
  d: `M${x1},${y}L${x2},${y}L${x3},${y + slot}L${x4},${y + slot}Z`,
86
82
  fill: item.color,
87
83
  opacity: activeIndex === null || isActive ? 0.92 : 0.5,
88
- pointerEvents: 'none'
84
+ pointerEvents: "none"
89
85
  });
90
- if (label === 'inside') {
91
- // 文字放在梯形上沿,宽度不足时跳过,避免文字溢出图形
86
+ if (label === "inside") {
92
87
  if (topWidth > 90 && slot > 26) {
93
88
  nodes.push({
94
- kind: 'text',
89
+ kind: "text",
95
90
  key: `inside-${index}`,
96
91
  x: cx,
97
92
  y: y + slot / 2,
98
93
  text: `${item.name} ${formatNumber(item.value)}`,
99
- fill: '#fff',
94
+ fill: "#fff",
100
95
  fontSize: theme.font.size,
101
96
  fontWeight: theme.font.weightMedium,
102
- anchor: 'middle',
103
- baseline: 'middle',
97
+ anchor: "middle",
98
+ baseline: "middle",
104
99
  opacity: progress
105
100
  });
106
101
  }
107
102
  }
108
- if (label === 'right') {
103
+ if (label === "right") {
109
104
  nodes.push({
110
- kind: 'line',
105
+ kind: "line",
111
106
  key: `leader-${index}`,
112
107
  x1: cx + topWidth / 2,
113
108
  y1: y + slot / 2,
@@ -115,86 +110,116 @@ export function FunnelChart({
115
110
  y2: y + slot / 2,
116
111
  stroke: withAlpha(theme.axis.line, 0.9),
117
112
  strokeWidth: 1,
118
- pointerEvents: 'none'
113
+ pointerEvents: "none"
119
114
  });
120
115
  nodes.push({
121
- kind: 'text',
116
+ kind: "text",
122
117
  key: `label-${index}`,
123
118
  x: cx + maxWidth / 2 + 14,
124
119
  y: y + slot / 2,
125
120
  text: `${item.name}`,
126
121
  fill: theme.text.primary,
127
122
  fontSize: theme.font.size,
128
- anchor: 'start',
129
- baseline: 'middle'
123
+ anchor: "start",
124
+ baseline: "middle"
130
125
  });
131
126
  nodes.push({
132
- kind: 'text',
127
+ kind: "text",
133
128
  key: `value-${index}`,
134
129
  x: cx + maxWidth / 2 + 14,
135
130
  y: y + slot / 2 + theme.font.size + 2,
136
131
  text: `${formatNumber(item.value)} · ${formatPercent(item.value, baseValue, 1)}`,
137
132
  fill: theme.text.secondary,
138
133
  fontSize: theme.font.sizeSmall,
139
- anchor: 'start',
140
- baseline: 'middle'
134
+ anchor: "start",
135
+ baseline: "middle"
141
136
  });
142
137
  }
143
138
  });
144
139
  return nodes;
145
- }, [items, size.width, size.height, gap, label, maxValue, baseValue, progress, theme, activeIndex, transition.values, animConfig.stagger]);
146
- const indexFromPointer = useCallback(clientY => {
147
- const element = ref.current;
148
- if (!element || !items.length) return null;
149
- const rect = element.getBoundingClientRect();
150
- const localY = clientY - rect.top;
151
- const slot = (size.height - gap * (items.length - 1)) / items.length;
152
- const index = Math.floor(localY / (slot + gap));
153
- return index >= 0 && index < items.length ? index : null;
154
- }, [ref, items.length, size.height, gap]);
140
+ }, [
141
+ items,
142
+ size.width,
143
+ size.height,
144
+ gap,
145
+ label,
146
+ maxValue,
147
+ baseValue,
148
+ progress,
149
+ theme,
150
+ activeIndex,
151
+ transition.values,
152
+ animConfig.stagger
153
+ ]);
154
+ const indexFromPointer = useCallback(
155
+ (clientY) => {
156
+ const element = ref.current;
157
+ if (!element || !items.length)
158
+ return null;
159
+ const rect = element.getBoundingClientRect();
160
+ const localY = clientY - rect.top;
161
+ const slot = (size.height - gap * (items.length - 1)) / items.length;
162
+ const index = Math.floor(localY / (slot + gap));
163
+ return index >= 0 && index < items.length ? index : null;
164
+ },
165
+ [ref, items.length, size.height, gap]
166
+ );
155
167
  const active = activeIndex !== null ? items[activeIndex] : null;
156
168
  const tooltipPayload = active ? {
157
169
  label: active.name,
158
170
  row: null,
159
- series: [{
160
- key: active.name,
161
- name: active.name,
162
- color: active.color,
163
- value: active.value,
164
- formatted: `${formatNumber(active.value)}(${formatPercent(active.value, baseValue, 1)})`
165
- }]
171
+ series: [
172
+ {
173
+ key: active.name,
174
+ name: active.name,
175
+ color: active.color,
176
+ value: active.value,
177
+ formatted: `${formatNumber(active.value)}(${formatPercent(active.value, baseValue, 1)})`
178
+ }
179
+ ]
166
180
  } : null;
167
- const autoAriaLabel = ariaLabel ?? `漏斗图:${items.map(item => item.name).join('、')}`;
168
- return /*#__PURE__*/_jsx("div", {
169
- className: classNames(prefixCls('chart'), className),
170
- style: {
171
- width,
172
- height,
173
- ...style
174
- },
175
- "data-aura-chart": "funnel",
176
- children: /*#__PURE__*/_jsxs("div", {
177
- ref: ref,
178
- className: prefixCls('chart__plot'),
179
- onPointerMove: event => setActiveIndex(indexFromPointer(event.clientY)),
180
- onPointerLeave: () => setActiveIndex(null),
181
- children: [items.length === 0 || size.width === 0 ? /*#__PURE__*/_jsx("div", {
182
- className: prefixCls('chart__empty'),
183
- children: emptyText
184
- }) : /*#__PURE__*/_jsx(SvgScene, {
185
- nodes: scene,
186
- width: size.width,
187
- height: size.height,
188
- ariaLabel: autoAriaLabel
189
- }), /*#__PURE__*/_jsx(Tooltip, {
190
- payload: tooltipPayload,
191
- x: size.width / 2,
192
- y: activeIndex !== null ? size.height / items.length * activeIndex + 4 : 0,
193
- containerWidth: size.width,
194
- containerHeight: size.height,
195
- theme: theme,
196
- config: tooltip
197
- })]
198
- })
199
- });
200
- }
181
+ const autoAriaLabel = ariaLabel ?? `漏斗图:${items.map((item) => item.name).join("、")}`;
182
+ return /* @__PURE__ */ jsx(
183
+ "div",
184
+ {
185
+ className: classNames(prefixCls("chart"), className),
186
+ style: { width, height, ...style },
187
+ "data-aura-chart": "funnel",
188
+ children: /* @__PURE__ */ jsxs(
189
+ "div",
190
+ {
191
+ ref,
192
+ className: prefixCls("chart__plot"),
193
+ onPointerMove: (event) => setActiveIndex(indexFromPointer(event.clientY)),
194
+ onPointerLeave: () => setActiveIndex(null),
195
+ children: [
196
+ items.length === 0 || size.width === 0 ? /* @__PURE__ */ jsx("div", { className: prefixCls("chart__empty"), children: emptyText }) : /* @__PURE__ */ jsx(
197
+ SvgScene,
198
+ {
199
+ nodes: scene,
200
+ width: size.width,
201
+ height: size.height,
202
+ ariaLabel: autoAriaLabel
203
+ }
204
+ ),
205
+ /* @__PURE__ */ jsx(
206
+ Tooltip,
207
+ {
208
+ payload: tooltipPayload,
209
+ x: size.width / 2,
210
+ y: activeIndex !== null ? size.height / items.length * activeIndex + 4 : 0,
211
+ containerWidth: size.width,
212
+ containerHeight: size.height,
213
+ theme,
214
+ config: tooltip
215
+ }
216
+ )
217
+ ]
218
+ }
219
+ )
220
+ }
221
+ );
222
+ }
223
+ export {
224
+ FunnelChart
225
+ };
@@ -1,6 +1,7 @@
1
1
  'use client';
2
- import React, { useMemo } from 'react';
3
- import { classNames, prefixCls } from '@aura-react-comp/shared';
2
+ // src/charts/gauge-chart/index.tsx
3
+ import { useMemo } from "react";
4
+ import { classNames, prefixCls } from "@aura-react-comp/shared";
4
5
  import { SvgScene } from "../../scene/svg";
5
6
  import { arcLinePath } from "../../core/shape";
6
7
  import { formatNumber } from "../../core/format";
@@ -9,27 +10,19 @@ import { useChartTheme } from "../../hooks/useChartTheme";
9
10
  import { useElementSize } from "../../hooks/useElementSize";
10
11
  import { useChartTransition } from "../../hooks/useChartTransition";
11
12
  import { resolveAnimation } from "../../core/animation";
12
- import { jsx as _jsx } from "react/jsx-runtime";
13
- const DEG = Math.PI / 180;
14
-
15
- /**
16
- * 仪表盘。
17
- *
18
- * 只表达「一个值在量程中的位置」,不承载多指标比较。
19
- * 数值以外不加指针:现代仪表盘用填充弧表达进度,指针图形的可读性反而更差
20
- * (细长指针在 240° 弧上要判断角度,误差远大于判断弧长)。
21
- */
22
- export function GaugeChart({
13
+ import { jsx } from "react/jsx-runtime";
14
+ var DEG = Math.PI / 180;
15
+ function GaugeChart({
23
16
  value,
24
17
  min = 0,
25
18
  max = 100,
26
- unit = '',
19
+ unit = "",
27
20
  label,
28
21
  ranges,
29
22
  thickness = 0.14,
30
23
  startAngle = 150,
31
24
  sweepAngle = 240,
32
- width = '100%',
25
+ width = "100%",
33
26
  height = 260,
34
27
  theme: themeInput,
35
28
  palette,
@@ -38,34 +31,33 @@ export function GaugeChart({
38
31
  style,
39
32
  ariaLabel
40
33
  }) {
34
+ var _a;
41
35
  const theme = useChartTheme(themeInput, palette);
42
- const {
43
- ref,
44
- size
45
- } = useElementSize();
46
- const animKey = typeof animation === 'object' ? JSON.stringify(animation) : String(animation);
47
- const animConfig = useMemo(() => resolveAnimation(animation),
48
- // eslint-disable-next-line react-hooks/exhaustive-deps
49
- [animKey]);
50
-
51
- // 数值做插值:更新时弧长平滑滑到新位置,中心数字同时滚动
36
+ const { ref, size } = useElementSize();
37
+ const animKey = typeof animation === "object" ? JSON.stringify(animation) : String(animation);
38
+ const animConfig = useMemo(
39
+ () => resolveAnimation(animation),
40
+ // eslint-disable-next-line react-hooks/exhaustive-deps
41
+ [animKey]
42
+ );
52
43
  const transition = useChartTransition([[value]], animConfig);
53
44
  const progress = transition.progress;
54
- const animatedValue = transition.values[0]?.[0] ?? value;
45
+ const animatedValue = ((_a = transition.values[0]) == null ? void 0 : _a[0]) ?? value;
55
46
  const ratio = useMemo(() => {
56
- if (max === min) return 0;
47
+ if (max === min)
48
+ return 0;
57
49
  return Math.min(1, Math.max(0, (animatedValue - min) / (max - min)));
58
50
  }, [animatedValue, min, max]);
59
51
  const color = useMemo(() => {
60
- if (ranges?.length) {
61
- const hit = ranges.find(range => value <= range.to);
62
- if (hit) return hit.color;
52
+ if (ranges == null ? void 0 : ranges.length) {
53
+ const hit = ranges.find((range) => value <= range.to);
54
+ if (hit)
55
+ return hit.color;
63
56
  return ranges[ranges.length - 1].color;
64
57
  }
65
58
  return theme.emphasis;
66
59
  }, [ranges, value, theme.emphasis]);
67
60
  const geometry = useMemo(() => {
68
- // 240° 弧在竖直方向的占用约为 0.87R,据此反推半径,避免上下裁切
69
61
  const outer = Math.max(0, Math.min(size.width / 2, size.height / 1.72)) - 6;
70
62
  const ring = Math.max(6, outer * thickness);
71
63
  return {
@@ -79,51 +71,39 @@ export function GaugeChart({
79
71
  const start = startAngle * DEG;
80
72
  const sweep = sweepAngle * DEG;
81
73
  const scene = useMemo(() => {
82
- const {
83
- cx,
84
- cy,
85
- outer,
86
- inner,
87
- thickness: ring
88
- } = geometry;
89
- if (outer <= 0) return [];
74
+ const { cx, cy, outer, inner, thickness: ring } = geometry;
75
+ if (outer <= 0)
76
+ return [];
90
77
  const nodes = [];
91
-
92
- // 轨道
93
78
  nodes.push({
94
- kind: 'path',
95
- key: 'track',
79
+ kind: "path",
80
+ key: "track",
96
81
  d: arcLinePath(cx, cy, (inner + outer) / 2, start, start + sweep),
97
- fill: 'none',
82
+ fill: "none",
98
83
  stroke: withAlpha(theme.axis.line, 0.55),
99
84
  strokeWidth: ring,
100
- linecap: 'round',
101
- pointerEvents: 'none'
85
+ linecap: "round",
86
+ pointerEvents: "none"
102
87
  });
103
-
104
- // 进度弧
105
88
  const end = start + sweep * ratio * progress;
106
- if (end > start + 0.001) {
89
+ if (end > start + 1e-3) {
107
90
  nodes.push({
108
- kind: 'path',
109
- key: 'value-arc',
91
+ kind: "path",
92
+ key: "value-arc",
110
93
  d: arcLinePath(cx, cy, (inner + outer) / 2, start, end),
111
- fill: 'none',
94
+ fill: "none",
112
95
  stroke: color,
113
96
  strokeWidth: ring,
114
- linecap: 'round',
115
- pointerEvents: 'none'
97
+ linecap: "round",
98
+ pointerEvents: "none"
116
99
  });
117
100
  }
118
-
119
- // 刻度:11 条短线,每 10% 一条
120
- // 刻度落在环外侧,长度取环宽的 45%,太短会淹没在环的边缘里
121
101
  const tickOuter = outer + ring * 1.05;
122
102
  const tickInner = outer + ring * 0.6;
123
103
  for (let index = 0; index <= 10; index += 1) {
124
104
  const angle = start + sweep * index / 10;
125
105
  nodes.push({
126
- kind: 'line',
106
+ kind: "line",
127
107
  key: `tick-${index}`,
128
108
  x1: cx + Math.cos(angle) * tickInner,
129
109
  y1: cy + Math.sin(angle) * tickInner,
@@ -132,86 +112,103 @@ export function GaugeChart({
132
112
  stroke: index / 10 <= ratio ? color : theme.axis.tick,
133
113
  strokeWidth: index % 5 === 0 ? 2 : 1,
134
114
  opacity: index / 10 <= ratio ? 0.9 : 0.5,
135
- pointerEvents: 'none'
115
+ pointerEvents: "none"
136
116
  });
137
117
  }
138
-
139
- // 量程端点数值
140
- // 端点标签按容器边界收敛:小卡片里「100」这类标签溢出会被裁成「10C」
141
- const clampToCard = (value, max) => Math.min(Math.max(value, 10), Math.max(10, max - 10));
118
+ const clampToCard = (value2, max2) => Math.min(Math.max(value2, 10), Math.max(10, max2 - 10));
142
119
  nodes.push({
143
- kind: 'text',
144
- key: 'min-label',
120
+ kind: "text",
121
+ key: "min-label",
145
122
  x: clampToCard(cx + Math.cos(start) * (outer + ring * 0.9), size.width),
146
123
  y: clampToCard(cy + Math.sin(start) * (outer + ring * 0.9), size.height),
147
124
  text: formatNumber(min),
148
125
  fill: theme.text.secondary,
149
126
  fontSize: theme.font.sizeSmall,
150
- anchor: 'middle',
151
- baseline: 'middle',
127
+ anchor: "middle",
128
+ baseline: "middle",
152
129
  fontFamily: theme.font.family
153
130
  });
154
131
  nodes.push({
155
- kind: 'text',
156
- key: 'max-label',
157
- x: clampToCard(cx + Math.cos(start + sweep) * (outer + ring * 0.9), size.width),
158
- y: clampToCard(cy + Math.sin(start + sweep) * (outer + ring * 0.9), size.height),
132
+ kind: "text",
133
+ key: "max-label",
134
+ x: clampToCard(
135
+ cx + Math.cos(start + sweep) * (outer + ring * 0.9),
136
+ size.width
137
+ ),
138
+ y: clampToCard(
139
+ cy + Math.sin(start + sweep) * (outer + ring * 0.9),
140
+ size.height
141
+ ),
159
142
  text: formatNumber(max),
160
143
  fill: theme.text.secondary,
161
144
  fontSize: theme.font.sizeSmall,
162
- anchor: 'middle',
163
- baseline: 'middle',
145
+ anchor: "middle",
146
+ baseline: "middle",
164
147
  fontFamily: theme.font.family
165
148
  });
166
-
167
- // 中心数值
168
149
  nodes.push({
169
- kind: 'text',
170
- key: 'value',
150
+ kind: "text",
151
+ key: "value",
171
152
  x: cx,
172
153
  y: cy - 6,
173
154
  text: `${formatNumber(Math.round(animatedValue * 10) / 10)}${unit}`,
174
155
  fill: theme.text.primary,
175
156
  fontSize: Math.max(20, Math.min(34, outer * 0.3)),
176
157
  fontWeight: theme.font.weightMedium,
177
- anchor: 'middle',
178
- baseline: 'middle',
158
+ anchor: "middle",
159
+ baseline: "middle",
179
160
  fontFamily: theme.font.family
180
161
  });
181
162
  if (label) {
182
163
  nodes.push({
183
- kind: 'text',
184
- key: 'label',
164
+ kind: "text",
165
+ key: "label",
185
166
  x: cx,
186
167
  y: cy + Math.max(20, outer * 0.16),
187
168
  text: label,
188
169
  fill: theme.text.secondary,
189
170
  fontSize: theme.font.size,
190
- anchor: 'middle',
191
- baseline: 'middle',
171
+ anchor: "middle",
172
+ baseline: "middle",
192
173
  fontFamily: theme.font.family
193
174
  });
194
175
  }
195
176
  return nodes;
196
- }, [geometry, start, sweep, ratio, progress, color, theme, animatedValue, unit, size.width, size.height, label, min, max]);
197
- const autoAriaLabel = ariaLabel ?? `${label ?? '仪表盘'}:${value}${unit},量程 ${min}~${max}`;
198
- return /*#__PURE__*/_jsx("div", {
199
- className: classNames(prefixCls('chart'), className),
200
- style: {
201
- width,
202
- height,
203
- ...style
204
- },
205
- "data-aura-chart": "gauge",
206
- children: /*#__PURE__*/_jsx("div", {
207
- ref: ref,
208
- className: prefixCls('chart__plot'),
209
- children: size.width > 0 ? /*#__PURE__*/_jsx(SvgScene, {
210
- nodes: scene,
211
- width: size.width,
212
- height: size.height,
213
- ariaLabel: autoAriaLabel
214
- }) : null
215
- })
216
- });
217
- }
177
+ }, [
178
+ geometry,
179
+ start,
180
+ sweep,
181
+ ratio,
182
+ progress,
183
+ color,
184
+ theme,
185
+ animatedValue,
186
+ unit,
187
+ size.width,
188
+ size.height,
189
+ label,
190
+ min,
191
+ max
192
+ ]);
193
+ const autoAriaLabel = ariaLabel ?? `${label ?? "仪表盘"}:${value}${unit},量程 ${min}~${max}`;
194
+ return /* @__PURE__ */ jsx(
195
+ "div",
196
+ {
197
+ className: classNames(prefixCls("chart"), className),
198
+ style: { width, height, ...style },
199
+ "data-aura-chart": "gauge",
200
+ children: /* @__PURE__ */ jsx("div", { ref, className: prefixCls("chart__plot"), children: size.width > 0 ? /* @__PURE__ */ jsx(
201
+ SvgScene,
202
+ {
203
+ nodes: scene,
204
+ width: size.width,
205
+ height: size.height,
206
+ ariaLabel: autoAriaLabel
207
+ }
208
+ ) : null })
209
+ }
210
+ );
211
+ }
212
+ export {
213
+ GaugeChart
214
+ };