@aura-react-comp/charts 0.0.0-stage → 0.2.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 (129) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +90 -2
  3. package/esm/charts/area-chart/index.d.ts +19 -0
  4. package/esm/charts/area-chart/index.d.ts.map +1 -0
  5. package/esm/charts/area-chart/index.js +30 -0
  6. package/esm/charts/bar-chart/index.d.ts +16 -0
  7. package/esm/charts/bar-chart/index.d.ts.map +1 -0
  8. package/esm/charts/bar-chart/index.js +27 -0
  9. package/esm/charts/candlestick-chart/index.d.ts +47 -0
  10. package/esm/charts/candlestick-chart/index.d.ts.map +1 -0
  11. package/esm/charts/candlestick-chart/index.js +346 -0
  12. package/esm/charts/combo-chart/index.d.ts +17 -0
  13. package/esm/charts/combo-chart/index.d.ts.map +1 -0
  14. package/esm/charts/combo-chart/index.js +25 -0
  15. package/esm/charts/funnel-chart/index.d.ts +35 -0
  16. package/esm/charts/funnel-chart/index.d.ts.map +1 -0
  17. package/esm/charts/funnel-chart/index.js +199 -0
  18. package/esm/charts/gauge-chart/index.d.ts +41 -0
  19. package/esm/charts/gauge-chart/index.d.ts.map +1 -0
  20. package/esm/charts/gauge-chart/index.js +216 -0
  21. package/esm/charts/graph-chart/index.d.ts +35 -0
  22. package/esm/charts/graph-chart/index.d.ts.map +1 -0
  23. package/esm/charts/graph-chart/index.js +223 -0
  24. package/esm/charts/heatmap-chart/index.d.ts +47 -0
  25. package/esm/charts/heatmap-chart/index.d.ts.map +1 -0
  26. package/esm/charts/heatmap-chart/index.js +280 -0
  27. package/esm/charts/line-chart/index.d.ts +23 -0
  28. package/esm/charts/line-chart/index.d.ts.map +1 -0
  29. package/esm/charts/line-chart/index.js +32 -0
  30. package/esm/charts/pie-chart/index.d.ts +38 -0
  31. package/esm/charts/pie-chart/index.d.ts.map +1 -0
  32. package/esm/charts/pie-chart/index.js +271 -0
  33. package/esm/charts/radar-chart/index.d.ts +44 -0
  34. package/esm/charts/radar-chart/index.d.ts.map +1 -0
  35. package/esm/charts/radar-chart/index.js +262 -0
  36. package/esm/charts/ring-progress/index.d.ts +38 -0
  37. package/esm/charts/ring-progress/index.d.ts.map +1 -0
  38. package/esm/charts/ring-progress/index.js +136 -0
  39. package/esm/charts/sankey-chart/index.d.ts +34 -0
  40. package/esm/charts/sankey-chart/index.d.ts.map +1 -0
  41. package/esm/charts/sankey-chart/index.js +247 -0
  42. package/esm/charts/scatter-chart/index.d.ts +34 -0
  43. package/esm/charts/scatter-chart/index.d.ts.map +1 -0
  44. package/esm/charts/scatter-chart/index.js +304 -0
  45. package/esm/charts/sparkline/index.d.ts +31 -0
  46. package/esm/charts/sparkline/index.d.ts.map +1 -0
  47. package/esm/charts/sparkline/index.js +151 -0
  48. package/esm/charts/tree-chart/index.d.ts +34 -0
  49. package/esm/charts/tree-chart/index.d.ts.map +1 -0
  50. package/esm/charts/tree-chart/index.js +199 -0
  51. package/esm/charts/treemap-chart/index.d.ts +35 -0
  52. package/esm/charts/treemap-chart/index.d.ts.map +1 -0
  53. package/esm/charts/treemap-chart/index.js +238 -0
  54. package/esm/charts/waterfall-chart/index.d.ts +41 -0
  55. package/esm/charts/waterfall-chart/index.d.ts.map +1 -0
  56. package/esm/charts/waterfall-chart/index.js +280 -0
  57. package/esm/components/Legend.d.ts +24 -0
  58. package/esm/components/Legend.d.ts.map +1 -0
  59. package/esm/components/Legend.js +49 -0
  60. package/esm/components/Tooltip.d.ts +24 -0
  61. package/esm/components/Tooltip.d.ts.map +1 -0
  62. package/esm/components/Tooltip.js +84 -0
  63. package/esm/components/chart/index.d.ts +71 -0
  64. package/esm/components/chart/index.d.ts.map +1 -0
  65. package/esm/components/chart/index.js +141 -0
  66. package/esm/components/chart.less +223 -0
  67. package/esm/core/animation.d.ts +49 -0
  68. package/esm/core/animation.d.ts.map +1 -0
  69. package/esm/core/animation.js +92 -0
  70. package/esm/core/force.d.ts +43 -0
  71. package/esm/core/force.d.ts.map +1 -0
  72. package/esm/core/force.js +133 -0
  73. package/esm/core/format.d.ts +34 -0
  74. package/esm/core/format.d.ts.map +1 -0
  75. package/esm/core/format.js +80 -0
  76. package/esm/core/hierarchy.d.ts +77 -0
  77. package/esm/core/hierarchy.d.ts.map +1 -0
  78. package/esm/core/hierarchy.js +232 -0
  79. package/esm/core/layout.d.ts +67 -0
  80. package/esm/core/layout.d.ts.map +1 -0
  81. package/esm/core/layout.js +120 -0
  82. package/esm/core/sampling.d.ts +32 -0
  83. package/esm/core/sampling.d.ts.map +1 -0
  84. package/esm/core/sampling.js +123 -0
  85. package/esm/core/sankey.d.ts +67 -0
  86. package/esm/core/sankey.d.ts.map +1 -0
  87. package/esm/core/sankey.js +135 -0
  88. package/esm/core/scale.d.ts +98 -0
  89. package/esm/core/scale.d.ts.map +1 -0
  90. package/esm/core/scale.js +206 -0
  91. package/esm/core/shape.d.ts +60 -0
  92. package/esm/core/shape.d.ts.map +1 -0
  93. package/esm/core/shape.js +245 -0
  94. package/esm/global.d.ts +6 -0
  95. package/esm/hooks/useChartTheme.d.ts +10 -0
  96. package/esm/hooks/useChartTheme.d.ts.map +1 -0
  97. package/esm/hooks/useChartTheme.js +33 -0
  98. package/esm/hooks/useChartTransition.d.ts +20 -0
  99. package/esm/hooks/useChartTransition.d.ts.map +1 -0
  100. package/esm/hooks/useChartTransition.js +119 -0
  101. package/esm/hooks/useElementSize.d.ts +17 -0
  102. package/esm/hooks/useElementSize.d.ts.map +1 -0
  103. package/esm/hooks/useElementSize.js +46 -0
  104. package/esm/index.d.ts +62 -0
  105. package/esm/index.d.ts.map +1 -0
  106. package/esm/index.js +47 -0
  107. package/esm/internal/CartesianChart.d.ts +16 -0
  108. package/esm/internal/CartesianChart.d.ts.map +1 -0
  109. package/esm/internal/CartesianChart.js +810 -0
  110. package/esm/internal/model.d.ts +67 -0
  111. package/esm/internal/model.d.ts.map +1 -0
  112. package/esm/internal/model.js +145 -0
  113. package/esm/scene/canvas.d.ts +18 -0
  114. package/esm/scene/canvas.d.ts.map +1 -0
  115. package/esm/scene/canvas.js +137 -0
  116. package/esm/scene/svg.d.ts +12 -0
  117. package/esm/scene/svg.d.ts.map +1 -0
  118. package/esm/scene/svg.js +115 -0
  119. package/esm/scene/types.d.ts +89 -0
  120. package/esm/scene/types.d.ts.map +1 -0
  121. package/esm/scene/types.js +20 -0
  122. package/esm/style.css +196 -0
  123. package/esm/theme/index.d.ts +127 -0
  124. package/esm/theme/index.d.ts.map +1 -0
  125. package/esm/theme/index.js +297 -0
  126. package/esm/types.d.ts +168 -0
  127. package/esm/types.d.ts.map +1 -0
  128. package/esm/types.js +1 -0
  129. package/package.json +64 -3
@@ -0,0 +1,35 @@
1
+ import React from 'react';
2
+ import { type ChartThemeInput } from '../../theme';
3
+ import type { TooltipConfig } from '../../types';
4
+ export interface FunnelDataItem {
5
+ name: string;
6
+ value: number;
7
+ color?: string;
8
+ }
9
+ export interface FunnelChartProps {
10
+ data: FunnelDataItem[];
11
+ width?: number | string;
12
+ height?: number;
13
+ /** 标签位置:堆叠在图元内 / 右侧外部 */
14
+ label?: 'inside' | 'right' | false;
15
+ /** 项之间的间隙(像素) */
16
+ gap?: number;
17
+ theme?: ChartThemeInput;
18
+ palette?: string[];
19
+ tooltip?: boolean | TooltipConfig;
20
+ animation?: boolean;
21
+ className?: string;
22
+ style?: React.CSSProperties;
23
+ ariaLabel?: string;
24
+ emptyText?: string;
25
+ }
26
+ /**
27
+ * 漏斗图。
28
+ *
29
+ * 每一项的宽度按数值比例决定,因此它能直观表达「逐层流失」。
30
+ *
31
+ * 注意:漏斗图的面积编码是**非线性的**(梯形面积 ∝ 上下宽之和 × 高),
32
+ * 所以不要用它做精确的比例判断——它擅长的是「看出哪一层掉得最狠」。
33
+ */
34
+ export declare function FunnelChart({ data, width, height, label, gap, theme: themeInput, palette, tooltip, animation, className, style, ariaLabel, emptyText, }: FunnelChartProps): React.JSX.Element;
35
+ //# sourceMappingURL=index.d.ts.map
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@@
1
+ import React, { useCallback, useMemo, useState } from 'react';
2
+ import { classNames, prefixCls } from '@aura-react-comp/shared';
3
+ import { SvgScene } from "../../scene/svg";
4
+ import { formatNumber, formatPercent } from "../../core/format";
5
+ import { withAlpha } from "../../theme";
6
+ import { useChartTheme } from "../../hooks/useChartTheme";
7
+ import { useElementSize } from "../../hooks/useElementSize";
8
+ import { useChartTransition } from "../../hooks/useChartTransition";
9
+ import { resolveAnimation, staggerProgress } from "../../core/animation";
10
+ 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({
22
+ data = [],
23
+ width = '100%',
24
+ height = 320,
25
+ label = 'inside',
26
+ gap = 4,
27
+ theme: themeInput,
28
+ palette,
29
+ tooltip = true,
30
+ animation = true,
31
+ className,
32
+ style,
33
+ ariaLabel,
34
+ emptyText = '暂无数据'
35
+ }) {
36
+ const theme = useChartTheme(themeInput, palette);
37
+ const {
38
+ ref,
39
+ size
40
+ } = useElementSize();
41
+ 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]);
54
+ const transition = useChartTransition(valueMatrix, animConfig);
55
+ const progress = transition.progress;
56
+ const scene = useMemo(() => {
57
+ if (!items.length || size.width <= 0 || size.height <= 0) return [];
58
+ const nodes = [];
59
+ const count = items.length;
60
+ const slot = (size.height - gap * (count - 1)) / count;
61
+ // 右侧要留给标签
62
+ const labelSpace = label === 'right' ? Math.min(160, size.width * 0.32) : 0;
63
+ const maxWidth = Math.max(40, (size.width - labelSpace) * 0.82);
64
+ const cx = (size.width - labelSpace) / 2;
65
+
66
+ // 每层按自己的局部进度展开,整体呈「从上往下倾泻」的节奏
67
+ const widthOf = (value, local) => Math.max(4, value / maxValue * maxWidth * local);
68
+ items.forEach((item, index) => {
69
+ const local = staggerProgress(progress, index, count, animConfig.stagger);
70
+ const animatedValue = transition.values[0]?.[index] ?? item.value;
71
+ const topWidth = widthOf(animatedValue, local);
72
+ // 最后一项收口,形成漏斗的尖底;其余项以「下一项的宽度」为底边
73
+ const nextValue = transition.values[0]?.[index + 1] ?? items[index + 1]?.value ?? 0;
74
+ const nextWidth = index < count - 1 ? widthOf(nextValue, local) : topWidth * 0.6;
75
+ const y = index * (slot + gap);
76
+ const isActive = activeIndex === index;
77
+ const x1 = cx - topWidth / 2;
78
+ const x2 = cx + topWidth / 2;
79
+ const x3 = cx + nextWidth / 2;
80
+ const x4 = cx - nextWidth / 2;
81
+ nodes.push({
82
+ kind: 'path',
83
+ key: `funnel-${index}`,
84
+ d: `M${x1},${y}L${x2},${y}L${x3},${y + slot}L${x4},${y + slot}Z`,
85
+ fill: item.color,
86
+ opacity: activeIndex === null || isActive ? 0.92 : 0.5,
87
+ pointerEvents: 'none'
88
+ });
89
+ if (label === 'inside') {
90
+ // 文字放在梯形上沿,宽度不足时跳过,避免文字溢出图形
91
+ if (topWidth > 90 && slot > 26) {
92
+ nodes.push({
93
+ kind: 'text',
94
+ key: `inside-${index}`,
95
+ x: cx,
96
+ y: y + slot / 2,
97
+ text: `${item.name} ${formatNumber(item.value)}`,
98
+ fill: '#fff',
99
+ fontSize: theme.font.size,
100
+ fontWeight: theme.font.weightMedium,
101
+ anchor: 'middle',
102
+ baseline: 'middle',
103
+ opacity: progress
104
+ });
105
+ }
106
+ }
107
+ if (label === 'right') {
108
+ nodes.push({
109
+ kind: 'line',
110
+ key: `leader-${index}`,
111
+ x1: cx + topWidth / 2,
112
+ y1: y + slot / 2,
113
+ x2: cx + maxWidth / 2 + 10,
114
+ y2: y + slot / 2,
115
+ stroke: withAlpha(theme.axis.line, 0.9),
116
+ strokeWidth: 1,
117
+ pointerEvents: 'none'
118
+ });
119
+ nodes.push({
120
+ kind: 'text',
121
+ key: `label-${index}`,
122
+ x: cx + maxWidth / 2 + 14,
123
+ y: y + slot / 2,
124
+ text: `${item.name}`,
125
+ fill: theme.text.primary,
126
+ fontSize: theme.font.size,
127
+ anchor: 'start',
128
+ baseline: 'middle'
129
+ });
130
+ nodes.push({
131
+ kind: 'text',
132
+ key: `value-${index}`,
133
+ x: cx + maxWidth / 2 + 14,
134
+ y: y + slot / 2 + theme.font.size + 2,
135
+ text: `${formatNumber(item.value)} · ${formatPercent(item.value, baseValue, 1)}`,
136
+ fill: theme.text.secondary,
137
+ fontSize: theme.font.sizeSmall,
138
+ anchor: 'start',
139
+ baseline: 'middle'
140
+ });
141
+ }
142
+ });
143
+ 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]);
154
+ const active = activeIndex !== null ? items[activeIndex] : null;
155
+ const tooltipPayload = active ? {
156
+ label: active.name,
157
+ 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
+ }]
165
+ } : 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
+ }
@@ -0,0 +1,41 @@
1
+ import React from 'react';
2
+ import { type ChartThemeInput } from '../../theme';
3
+ export interface GaugeRange {
4
+ /** 该分段的终点值 */
5
+ to: number;
6
+ color: string;
7
+ }
8
+ export interface GaugeChartProps {
9
+ value: number;
10
+ min?: number;
11
+ max?: number;
12
+ /** 单位,显示在数值右侧 */
13
+ unit?: string;
14
+ /** 数值下方的说明文字 */
15
+ label?: string;
16
+ /** 分段配色,按区间端点匹配 */
17
+ ranges?: GaugeRange[];
18
+ /** 环宽占半径的比例 */
19
+ thickness?: number;
20
+ /** 弧的起始角度(度),默认 150(左下) */
21
+ startAngle?: number;
22
+ /** 弧的总扫过角度(度),默认 240 */
23
+ sweepAngle?: number;
24
+ width?: number | string;
25
+ height?: number;
26
+ theme?: ChartThemeInput;
27
+ palette?: string[];
28
+ animation?: boolean;
29
+ className?: string;
30
+ style?: React.CSSProperties;
31
+ ariaLabel?: string;
32
+ }
33
+ /**
34
+ * 仪表盘。
35
+ *
36
+ * 只表达「一个值在量程中的位置」,不承载多指标比较。
37
+ * 数值以外不加指针:现代仪表盘用填充弧表达进度,指针图形的可读性反而更差
38
+ * (细长指针在 240° 弧上要判断角度,误差远大于判断弧长)。
39
+ */
40
+ export declare function GaugeChart({ value, min, max, unit, label, ranges, thickness, startAngle, sweepAngle, width, height, theme: themeInput, palette, animation, className, style, ariaLabel, }: GaugeChartProps): React.JSX.Element;
41
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAkB,MAAM,OAAO,CAAC;AAMvC,OAAO,EAAa,KAAK,eAAe,EAAE,MAAM,aAAa,CAAC;AAK9D,OAAO,6BAA6B,CAAC;AAErC,MAAM,WAAW,UAAU;IACzB,cAAc;IACd,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,iBAAiB;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,gBAAgB;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,mBAAmB;IACnB,MAAM,CAAC,EAAE,UAAU,EAAE,CAAC;IACtB,eAAe;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,2BAA2B;IAC3B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,wBAAwB;IACxB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,eAAe,CAAC;IACxB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;IAC5B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAID;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,EACzB,KAAK,EACL,GAAO,EACP,GAAS,EACT,IAAS,EACT,KAAK,EACL,MAAM,EACN,SAAgB,EAChB,UAAgB,EAChB,UAAgB,EAChB,KAAc,EACd,MAAY,EACZ,KAAK,EAAE,UAAU,EACjB,OAAO,EACP,SAAgB,EAChB,SAAS,EACT,KAAK,EACL,SAAS,GACV,EAAE,eAAe,qBA8MjB"}
@@ -0,0 +1,216 @@
1
+ import React, { useMemo } from 'react';
2
+ import { classNames, prefixCls } from '@aura-react-comp/shared';
3
+ import { SvgScene } from "../../scene/svg";
4
+ import { arcLinePath } from "../../core/shape";
5
+ import { formatNumber } from "../../core/format";
6
+ import { withAlpha } from "../../theme";
7
+ import { useChartTheme } from "../../hooks/useChartTheme";
8
+ import { useElementSize } from "../../hooks/useElementSize";
9
+ import { useChartTransition } from "../../hooks/useChartTransition";
10
+ 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({
22
+ value,
23
+ min = 0,
24
+ max = 100,
25
+ unit = '',
26
+ label,
27
+ ranges,
28
+ thickness = 0.14,
29
+ startAngle = 150,
30
+ sweepAngle = 240,
31
+ width = '100%',
32
+ height = 260,
33
+ theme: themeInput,
34
+ palette,
35
+ animation = true,
36
+ className,
37
+ style,
38
+ ariaLabel
39
+ }) {
40
+ 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
+ // 数值做插值:更新时弧长平滑滑到新位置,中心数字同时滚动
51
+ const transition = useChartTransition([[value]], animConfig);
52
+ const progress = transition.progress;
53
+ const animatedValue = transition.values[0]?.[0] ?? value;
54
+ const ratio = useMemo(() => {
55
+ if (max === min) return 0;
56
+ return Math.min(1, Math.max(0, (animatedValue - min) / (max - min)));
57
+ }, [animatedValue, min, max]);
58
+ const color = useMemo(() => {
59
+ if (ranges?.length) {
60
+ const hit = ranges.find(range => value <= range.to);
61
+ if (hit) return hit.color;
62
+ return ranges[ranges.length - 1].color;
63
+ }
64
+ return theme.emphasis;
65
+ }, [ranges, value, theme.emphasis]);
66
+ const geometry = useMemo(() => {
67
+ // 240° 弧在竖直方向的占用约为 0.87R,据此反推半径,避免上下裁切
68
+ const outer = Math.max(0, Math.min(size.width / 2, size.height / 1.72)) - 6;
69
+ const ring = Math.max(6, outer * thickness);
70
+ return {
71
+ cx: size.width / 2,
72
+ cy: size.height / 2 + outer * 0.28,
73
+ outer,
74
+ inner: outer - ring,
75
+ thickness: ring
76
+ };
77
+ }, [size.width, size.height, thickness]);
78
+ const start = startAngle * DEG;
79
+ const sweep = sweepAngle * DEG;
80
+ const scene = useMemo(() => {
81
+ const {
82
+ cx,
83
+ cy,
84
+ outer,
85
+ inner,
86
+ thickness: ring
87
+ } = geometry;
88
+ if (outer <= 0) return [];
89
+ const nodes = [];
90
+
91
+ // 轨道
92
+ nodes.push({
93
+ kind: 'path',
94
+ key: 'track',
95
+ d: arcLinePath(cx, cy, (inner + outer) / 2, start, start + sweep),
96
+ fill: 'none',
97
+ stroke: withAlpha(theme.axis.line, 0.55),
98
+ strokeWidth: ring,
99
+ linecap: 'round',
100
+ pointerEvents: 'none'
101
+ });
102
+
103
+ // 进度弧
104
+ const end = start + sweep * ratio * progress;
105
+ if (end > start + 0.001) {
106
+ nodes.push({
107
+ kind: 'path',
108
+ key: 'value-arc',
109
+ d: arcLinePath(cx, cy, (inner + outer) / 2, start, end),
110
+ fill: 'none',
111
+ stroke: color,
112
+ strokeWidth: ring,
113
+ linecap: 'round',
114
+ pointerEvents: 'none'
115
+ });
116
+ }
117
+
118
+ // 刻度:11 条短线,每 10% 一条
119
+ // 刻度落在环外侧,长度取环宽的 45%,太短会淹没在环的边缘里
120
+ const tickOuter = outer + ring * 1.05;
121
+ const tickInner = outer + ring * 0.6;
122
+ for (let index = 0; index <= 10; index += 1) {
123
+ const angle = start + sweep * index / 10;
124
+ nodes.push({
125
+ kind: 'line',
126
+ key: `tick-${index}`,
127
+ x1: cx + Math.cos(angle) * tickInner,
128
+ y1: cy + Math.sin(angle) * tickInner,
129
+ x2: cx + Math.cos(angle) * tickOuter,
130
+ y2: cy + Math.sin(angle) * tickOuter,
131
+ stroke: index / 10 <= ratio ? color : theme.axis.tick,
132
+ strokeWidth: index % 5 === 0 ? 2 : 1,
133
+ opacity: index / 10 <= ratio ? 0.9 : 0.5,
134
+ pointerEvents: 'none'
135
+ });
136
+ }
137
+
138
+ // 量程端点数值
139
+ // 端点标签按容器边界收敛:小卡片里「100」这类标签溢出会被裁成「10C」
140
+ const clampToCard = (value, max) => Math.min(Math.max(value, 10), Math.max(10, max - 10));
141
+ nodes.push({
142
+ kind: 'text',
143
+ key: 'min-label',
144
+ x: clampToCard(cx + Math.cos(start) * (outer + ring * 0.9), size.width),
145
+ y: clampToCard(cy + Math.sin(start) * (outer + ring * 0.9), size.height),
146
+ text: formatNumber(min),
147
+ fill: theme.text.secondary,
148
+ fontSize: theme.font.sizeSmall,
149
+ anchor: 'middle',
150
+ baseline: 'middle',
151
+ fontFamily: theme.font.family
152
+ });
153
+ 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),
158
+ text: formatNumber(max),
159
+ fill: theme.text.secondary,
160
+ fontSize: theme.font.sizeSmall,
161
+ anchor: 'middle',
162
+ baseline: 'middle',
163
+ fontFamily: theme.font.family
164
+ });
165
+
166
+ // 中心数值
167
+ nodes.push({
168
+ kind: 'text',
169
+ key: 'value',
170
+ x: cx,
171
+ y: cy - 6,
172
+ text: `${formatNumber(Math.round(animatedValue * 10) / 10)}${unit}`,
173
+ fill: theme.text.primary,
174
+ fontSize: Math.max(20, Math.min(34, outer * 0.3)),
175
+ fontWeight: theme.font.weightMedium,
176
+ anchor: 'middle',
177
+ baseline: 'middle',
178
+ fontFamily: theme.font.family
179
+ });
180
+ if (label) {
181
+ nodes.push({
182
+ kind: 'text',
183
+ key: 'label',
184
+ x: cx,
185
+ y: cy + Math.max(20, outer * 0.16),
186
+ text: label,
187
+ fill: theme.text.secondary,
188
+ fontSize: theme.font.size,
189
+ anchor: 'middle',
190
+ baseline: 'middle',
191
+ fontFamily: theme.font.family
192
+ });
193
+ }
194
+ 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
+ }
@@ -0,0 +1,35 @@
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';
5
+ export interface GraphChartProps {
6
+ nodes?: ForceNode[];
7
+ links?: ForceLink[];
8
+ /** 力导向迭代次数,节点多时适当调低 */
9
+ iterations?: number;
10
+ /** 基础半径 */
11
+ nodeSize?: number;
12
+ /** 是否显示节点名称(节点少时才建议开) */
13
+ showLabel?: boolean;
14
+ /** 是否按连接数放大节点 */
15
+ scaleByDegree?: boolean;
16
+ width?: number | string;
17
+ height?: number;
18
+ theme?: ChartThemeInput;
19
+ palette?: string[];
20
+ tooltip?: boolean | TooltipConfig;
21
+ animation?: ChartAnimationInput;
22
+ className?: string;
23
+ style?: React.CSSProperties;
24
+ ariaLabel?: string;
25
+ emptyText?: string;
26
+ }
27
+ /**
28
+ * 关系图(力导向)。
29
+ *
30
+ * 节点两两相斥、有连边的相互吸引,最终收敛成「抱团」的形状:
31
+ * 连得紧的聚成一簇,孤立的被推到边缘。这是一种**探索**型图表——
32
+ * 它的价值是让你看到结构,而不是读出精确数值。
33
+ */
34
+ export declare function GraphChart({ nodes, links, iterations, nodeSize, showLabel, scaleByDegree, width, height, theme: themeInput, palette, tooltip, animation, className, style, ariaLabel, emptyText, }: GraphChartProps): React.JSX.Element;
35
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAyC,MAAM,OAAO,CAAC;AAK9D,OAAO,EAAa,KAAK,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9D,OAAO,EAE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