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