@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,304 @@
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 { createLinearScale, extentOf, linearTicks } from "../../core/scale";
5
+ import { computeLayout, suggestTickCount } from "../../core/layout";
6
+ import { formatNumber } from "../../core/format";
7
+ import { symbolPath } from "../../core/shape";
8
+ import { colorAt } from "../../theme";
9
+ import { useChartTheme } from "../../hooks/useChartTheme";
10
+ import { useElementSize } from "../../hooks/useElementSize";
11
+ import { useChartTransition } from "../../hooks/useChartTransition";
12
+ import { resolveAnimation, staggerProgress } from "../../core/animation";
13
+ import { Legend } from "../../components/Legend";
14
+ import { Tooltip } from "../../components/Tooltip";
15
+ import { jsx as _jsx } from "react/jsx-runtime";
16
+ import { jsxs as _jsxs } from "react/jsx-runtime";
17
+ /**
18
+ * 散点图。
19
+ *
20
+ * 与折线/柱状不同,散点的 x 是**连续的数值轴**而非分类轴:
21
+ * 分类轴会把 [1, 2, 100] 摆成等间距,严重扭曲相关性判断。
22
+ * 因此这里不复用 CartesianChart 的 band 坐标,改为线性 x 轴。
23
+ */
24
+ export function ScatterChart({
25
+ data = [],
26
+ xKey = 'x',
27
+ series = [],
28
+ width = '100%',
29
+ height = 320,
30
+ theme: themeInput,
31
+ palette,
32
+ legend = true,
33
+ tooltip = true,
34
+ symbol = 'circle',
35
+ symbolSize = 8,
36
+ animation = true,
37
+ className,
38
+ style,
39
+ ariaLabel,
40
+ emptyText = '暂无数据'
41
+ }) {
42
+ const theme = useChartTheme(themeInput, palette);
43
+ const {
44
+ ref,
45
+ size
46
+ } = useElementSize();
47
+ const [hiddenKeys, setHiddenKeys] = useState([]);
48
+ const [activeKey, setActiveKey] = useState(null);
49
+ const xValues = useMemo(() => data.map(row => {
50
+ const raw = row[xKey];
51
+ const num = typeof raw === 'number' ? raw : Number(raw);
52
+ return Number.isFinite(num) ? num : null;
53
+ }), [data, xKey]);
54
+ const seriesList = useMemo(() => series.map((config, index) => ({
55
+ config,
56
+ key: config.key,
57
+ name: config.name ?? config.key,
58
+ color: config.color ?? colorAt(theme, index),
59
+ values: data.map((row, rowIndex) => {
60
+ const raw = config.data ? config.data[rowIndex] : row[config.key];
61
+ const num = typeof raw === 'number' ? raw : Number(raw);
62
+ return Number.isFinite(num) ? num : null;
63
+ }),
64
+ visible: !config.hidden && !hiddenKeys.includes(config.key)
65
+ })), [series, data, theme, hiddenKeys]);
66
+ const animKey = typeof animation === 'object' ? JSON.stringify(animation) : String(animation);
67
+ const animConfig = useMemo(() => resolveAnimation(animation),
68
+ // eslint-disable-next-line react-hooks/exhaustive-deps
69
+ [animKey]);
70
+
71
+ // 每个系列一行数值,更新时在旧值之间插值
72
+ const valueMatrix = useMemo(() => seriesList.map(item => item.values), [seriesList]);
73
+ const transition = useChartTransition(valueMatrix, animConfig);
74
+ const progress = transition.progress;
75
+ const points = useMemo(() => {
76
+ const list = [];
77
+ let seriesIndex = -1;
78
+ for (const item of seriesList) {
79
+ seriesIndex += 1;
80
+ if (!item.visible) continue;
81
+ const row = transition.values[seriesIndex] ?? item.values;
82
+ row.forEach((value, index) => {
83
+ const x = xValues[index];
84
+ if (value === null || x === null || x === undefined) return;
85
+ list.push({
86
+ seriesKey: item.key,
87
+ seriesName: item.name,
88
+ color: item.color,
89
+ x,
90
+ y: value,
91
+ xIndex: index
92
+ });
93
+ });
94
+ }
95
+ return list;
96
+ }, [seriesList, xValues, transition.values]);
97
+ const xDomain = useMemo(() => {
98
+ const [min, max] = extentOf(xValues);
99
+ if (min === max) return [min - 1, max + 1];
100
+ // 两端留 4% 余量,避免点被裁在轴线上
101
+ const pad = (max - min) * 0.04;
102
+ return [min - pad, max + pad];
103
+ }, [xValues]);
104
+ const yDomain = useMemo(() => {
105
+ const [min, max] = extentOf(points.map(point => point.y));
106
+ if (min === max) return [min - 1, max + 1];
107
+ const pad = (max - min) * 0.08;
108
+ return [min - pad, max + pad];
109
+ }, [points]);
110
+ const estimatedPlotHeight = Math.max(60, height - 48);
111
+ const tickCount = suggestTickCount(estimatedPlotHeight);
112
+ const yTicks = useMemo(() => linearTicks(yDomain[0], yDomain[1], tickCount), [yDomain, tickCount]);
113
+ const xTicks = useMemo(() => linearTicks(xDomain[0], xDomain[1], Math.round(tickCount * 1.3)), [xDomain, tickCount]);
114
+ const yLabels = useMemo(() => yTicks.map(tick => formatNumber(tick)), [yTicks]);
115
+ const xLabels = useMemo(() => xTicks.map(tick => formatNumber(tick)), [xTicks]);
116
+ const layout = useMemo(() => computeLayout({
117
+ width: Math.max(size.width, 0),
118
+ height: Math.max(size.height, 0),
119
+ yLabels,
120
+ xLabels,
121
+ theme
122
+ }), [size.width, size.height, yLabels, xLabels, theme]);
123
+ const {
124
+ plot
125
+ } = layout;
126
+ const xScale = useMemo(() => createLinearScale({
127
+ domain: xDomain,
128
+ range: [plot.x, plot.x + plot.width]
129
+ }), [xDomain, plot.x, plot.width]);
130
+ const yScale = useMemo(() => createLinearScale({
131
+ domain: yDomain,
132
+ range: [plot.y + plot.height, plot.y]
133
+ }), [yDomain, plot.y, plot.height]);
134
+ const animBaseY = plot.y + plot.height;
135
+ const scene = useMemo(() => {
136
+ if (plot.width <= 0 || plot.height <= 0) return [];
137
+ const nodes = [];
138
+ for (const tick of yTicks) {
139
+ nodes.push({
140
+ kind: 'line',
141
+ key: `gy-${tick}`,
142
+ x1: plot.x,
143
+ y1: yScale.scale(tick),
144
+ x2: plot.x + plot.width,
145
+ y2: yScale.scale(tick),
146
+ stroke: theme.grid.line,
147
+ strokeWidth: theme.grid.lineWidth,
148
+ strokeDasharray: theme.grid.dash.join(' ') || undefined
149
+ });
150
+ }
151
+ yTicks.forEach((tick, index) => {
152
+ nodes.push({
153
+ kind: 'text',
154
+ key: `yl-${index}`,
155
+ x: plot.x - theme.axis.tickSize - 4,
156
+ y: yScale.scale(tick),
157
+ text: yLabels[index],
158
+ fill: theme.axis.label,
159
+ fontSize: theme.font.size,
160
+ anchor: 'end',
161
+ baseline: 'middle',
162
+ fontFamily: theme.font.family
163
+ });
164
+ });
165
+ xTicks.forEach((tick, index) => {
166
+ const x = xScale.scale(tick);
167
+ if (x < plot.x - 1 || x > plot.x + plot.width + 1) return;
168
+ nodes.push({
169
+ kind: 'text',
170
+ key: `xl-${index}`,
171
+ x,
172
+ y: plot.y + plot.height + theme.axis.tickSize + theme.font.size,
173
+ text: xLabels[index],
174
+ fill: theme.axis.label,
175
+ fontSize: theme.font.size,
176
+ anchor: 'middle',
177
+ fontFamily: theme.font.family
178
+ });
179
+ });
180
+ nodes.push({
181
+ kind: 'line',
182
+ key: 'x-axis',
183
+ x1: plot.x,
184
+ y1: plot.y + plot.height,
185
+ x2: plot.x + plot.width,
186
+ y2: plot.y + plot.height,
187
+ stroke: theme.axis.line,
188
+ strokeWidth: theme.axis.lineWidth
189
+ });
190
+ nodes.push({
191
+ kind: 'line',
192
+ key: 'y-axis',
193
+ x1: plot.x,
194
+ y1: plot.y,
195
+ x2: plot.x,
196
+ y2: plot.y + plot.height,
197
+ stroke: theme.axis.line,
198
+ strokeWidth: theme.axis.lineWidth
199
+ });
200
+ points.forEach((point, pointIndex) => {
201
+ const cx = xScale.scale(point.x);
202
+ const targetY = yScale.scale(point.y);
203
+ // 逐点错峰 + 透明度淡入,避免整片点同时「砸」在基线上
204
+ const local = staggerProgress(progress, pointIndex, points.length, animConfig.stagger);
205
+ const cy = animBaseY + (targetY - animBaseY) * local;
206
+ const isActive = activeKey === `${point.seriesKey}-${point.xIndex}`;
207
+ const radius = isActive ? symbolSize * 0.75 : symbolSize * 0.55;
208
+ nodes.push({
209
+ kind: 'path',
210
+ key: `pt-${point.seriesKey}-${point.xIndex}`,
211
+ d: symbolPath(symbol, cx, cy, radius * 2),
212
+ fill: point.color,
213
+ opacity: (activeKey === null || isActive ? 0.85 : 0.35) * local,
214
+ pointerEvents: 'none'
215
+ });
216
+ });
217
+ return nodes;
218
+ }, [plot, yTicks, xTicks, yLabels, xLabels, yScale, xScale, points, theme, progress, animBaseY, activeKey, symbol, symbolSize, animConfig.stagger]);
219
+
220
+ /** 指针 → 最近的点(限定 28px 内,避免远处空白也触发) */
221
+ const findNearest = useCallback((clientX, clientY) => {
222
+ const element = ref.current;
223
+ if (!element || !points.length) return null;
224
+ const rect = element.getBoundingClientRect();
225
+ const localX = clientX - rect.left;
226
+ const localY = clientY - rect.top;
227
+ let best = null;
228
+ let minDistance = 28;
229
+ for (const point of points) {
230
+ const px = xScale.scale(point.x);
231
+ const py = yScale.scale(point.y);
232
+ const distance = Math.hypot(px - localX, py - localY);
233
+ if (distance < minDistance) {
234
+ minDistance = distance;
235
+ best = point;
236
+ }
237
+ }
238
+ return best;
239
+ }, [ref, points, xScale, yScale]);
240
+ const activePoint = useMemo(() => {
241
+ if (!activeKey) return null;
242
+ return points.find(point => `${point.seriesKey}-${point.xIndex}` === activeKey) ?? null;
243
+ }, [activeKey, points]);
244
+ const tooltipPayload = activePoint ? {
245
+ label: `${xKey}: ${formatNumber(activePoint.x)}`,
246
+ row: data[activePoint.xIndex] ?? null,
247
+ series: [{
248
+ key: activePoint.seriesKey,
249
+ name: activePoint.seriesName,
250
+ color: activePoint.color,
251
+ value: activePoint.y,
252
+ formatted: formatNumber(activePoint.y)
253
+ }]
254
+ } : null;
255
+ const legendItems = seriesList.map(item => ({
256
+ key: item.key,
257
+ name: item.name,
258
+ color: item.color,
259
+ visible: item.visible
260
+ }));
261
+ const toggle = useCallback(key => {
262
+ setHiddenKeys(prev => prev.includes(key) ? prev.filter(item => item !== key) : [...prev, key]);
263
+ }, []);
264
+ const autoAriaLabel = ariaLabel ?? `散点图:${seriesList.map(item => item.name).join('、')}`;
265
+ return /*#__PURE__*/_jsxs("div", {
266
+ className: classNames(prefixCls('chart'), className),
267
+ style: {
268
+ width,
269
+ height,
270
+ ...style
271
+ },
272
+ "data-aura-chart": "scatter",
273
+ children: [/*#__PURE__*/_jsx(Legend, {
274
+ items: legendItems,
275
+ theme: theme,
276
+ config: legend,
277
+ onToggle: toggle
278
+ }), /*#__PURE__*/_jsxs("div", {
279
+ ref: ref,
280
+ className: prefixCls('chart__plot'),
281
+ onPointerMove: event => {
282
+ const nearest = findNearest(event.clientX, event.clientY);
283
+ setActiveKey(nearest ? `${nearest.seriesKey}-${nearest.xIndex}` : null);
284
+ },
285
+ onPointerLeave: () => setActiveKey(null),
286
+ children: [points.length === 0 ? /*#__PURE__*/_jsx("div", {
287
+ className: prefixCls('chart__empty'),
288
+ children: emptyText
289
+ }) : /*#__PURE__*/_jsx(SvgScene, {
290
+ nodes: scene,
291
+ width: size.width,
292
+ height: size.height,
293
+ ariaLabel: autoAriaLabel
294
+ }), /*#__PURE__*/_jsx(Tooltip, {
295
+ payload: tooltipPayload,
296
+ x: activePoint ? xScale.scale(activePoint.x) : 0,
297
+ y: activePoint ? yScale.scale(activePoint.y) : 0,
298
+ containerWidth: size.width,
299
+ theme: theme,
300
+ config: tooltip
301
+ })]
302
+ })]
303
+ });
304
+ }
@@ -0,0 +1,31 @@
1
+ import React from 'react';
2
+ import { type ChartThemeInput } from '../../theme';
3
+ export interface SparklineProps {
4
+ data: number[];
5
+ type?: 'line' | 'area' | 'bar';
6
+ width?: number;
7
+ height?: number;
8
+ /** 线条 / 柱子颜色,默认主题强调色 */
9
+ color?: string;
10
+ /** 曲线是否平滑 */
11
+ smooth?: boolean;
12
+ /** 是否高亮最后一个数据点 */
13
+ showLast?: boolean;
14
+ strokeWidth?: number;
15
+ theme?: ChartThemeInput;
16
+ palette?: string[];
17
+ animation?: boolean;
18
+ className?: string;
19
+ style?: React.CSSProperties;
20
+ ariaLabel?: string;
21
+ }
22
+ /**
23
+ * 迷你图(Sparkline)。
24
+ *
25
+ * 没有坐标轴、没有图例、没有 tooltip —— 它的唯一职责是让读者在扫视表格时
26
+ * 立刻看出「这条数据是在涨还是在跌」。任何额外装饰都会削弱这个目的。
27
+ *
28
+ * 因此它也刻意不提供数值精度:需要读数请用折线图。
29
+ */
30
+ export declare function Sparkline({ data, type, width, height, color, smooth, showLast, strokeWidth, theme: themeInput, palette, animation, className, style, ariaLabel, }: SparklineProps): React.JSX.Element | null;
31
+ //# 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;AAI9D,OAAO,6BAA6B,CAAC;AAErC,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,KAAK,CAAC;IAC/B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,wBAAwB;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,aAAa;IACb,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,kBAAkB;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,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;AAED;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,EACxB,IAAS,EACT,IAAa,EACb,KAAW,EACX,MAAW,EACX,KAAK,EACL,MAAc,EACd,QAAgB,EAChB,WAAiB,EACjB,KAAK,EAAE,UAAU,EACjB,OAAO,EACP,SAAgB,EAChB,SAAS,EACT,KAAK,EACL,SAAS,GACV,EAAE,cAAc,4BAwJhB"}
@@ -0,0 +1,151 @@
1
+ import React, { useMemo } from 'react';
2
+ import { classNames, prefixCls } from '@aura-react-comp/shared';
3
+ import { SvgScene } from "../../scene/svg";
4
+ import { areaPath, linePath } from "../../core/shape";
5
+ import { extentOf } from "../../core/scale";
6
+ import { withAlpha } from "../../theme";
7
+ import { useChartTheme } from "../../hooks/useChartTheme";
8
+ import { useChartTransition } from "../../hooks/useChartTransition";
9
+ import { resolveAnimation, staggerProgress } from "../../core/animation";
10
+ import { jsx as _jsx } from "react/jsx-runtime";
11
+ /**
12
+ * 迷你图(Sparkline)。
13
+ *
14
+ * 没有坐标轴、没有图例、没有 tooltip —— 它的唯一职责是让读者在扫视表格时
15
+ * 立刻看出「这条数据是在涨还是在跌」。任何额外装饰都会削弱这个目的。
16
+ *
17
+ * 因此它也刻意不提供数值精度:需要读数请用折线图。
18
+ */
19
+ export function Sparkline({
20
+ data = [],
21
+ type = 'line',
22
+ width = 120,
23
+ height = 32,
24
+ color,
25
+ smooth = false,
26
+ showLast = false,
27
+ strokeWidth = 1.6,
28
+ theme: themeInput,
29
+ palette,
30
+ animation = true,
31
+ className,
32
+ style,
33
+ ariaLabel
34
+ }) {
35
+ const theme = useChartTheme(themeInput, palette);
36
+ const accent = color ?? theme.emphasis;
37
+ const animKey = typeof animation === 'object' ? JSON.stringify(animation) : String(animation);
38
+ const animConfig = useMemo(() => resolveAnimation(animation),
39
+ // eslint-disable-next-line react-hooks/exhaustive-deps
40
+ [animKey]);
41
+ const transition = useChartTransition([data], animConfig);
42
+ const progress = transition.progress;
43
+ const values = transition.values[0] ?? data;
44
+ const points = useMemo(() => {
45
+ if (!values.length) return [];
46
+ const [min, max] = extentOf(values);
47
+ const span = max - min || 1;
48
+ const pad = strokeWidth;
49
+ const innerWidth = Math.max(1, width - pad);
50
+ const innerHeight = Math.max(1, height - pad * 2);
51
+ return values.map((raw, index) => {
52
+ const value = raw ?? 0;
53
+ return {
54
+ x: values.length === 1 ? width / 2 : pad / 2 + index / (values.length - 1) * innerWidth,
55
+ // y 轴翻转:数值越大越靠上
56
+ y: pad + innerHeight - (value - min) / span * innerHeight,
57
+ value
58
+ };
59
+ });
60
+ }, [values, width, height, strokeWidth]);
61
+ const scene = useMemo(() => {
62
+ if (!points.length) return [];
63
+ const nodes = [];
64
+ const curve = smooth ? 'smooth' : 'linear';
65
+ if (type === 'bar') {
66
+ const slot = width / Math.max(points.length, 1);
67
+ const barWidth = Math.max(1, slot * 0.6);
68
+ const bottom = height - strokeWidth / 2;
69
+ points.forEach((point, index) => {
70
+ const local = staggerProgress(progress, index, points.length, animConfig.stagger);
71
+ const barHeight = Math.max(1, (bottom - point.y) * local);
72
+ nodes.push({
73
+ kind: 'rect',
74
+ key: `bar-${index}`,
75
+ x: point.x - barWidth / 2,
76
+ y: bottom - barHeight,
77
+ width: barWidth,
78
+ height: barHeight,
79
+ radius: 1,
80
+ fill: accent,
81
+ opacity: 0.85,
82
+ pointerEvents: 'none'
83
+ });
84
+ });
85
+ return nodes;
86
+ }
87
+
88
+ // 动画:进场时按 progress 从底部抬升
89
+ // 逐点错峰:线条像被画出,而不是整体从底部抬起
90
+ const animated = points.map((point, index) => {
91
+ const local = staggerProgress(progress, index, points.length, animConfig.stagger);
92
+ return {
93
+ x: point.x,
94
+ y: height + (point.y - height) * local
95
+ };
96
+ });
97
+ if (type === 'area') {
98
+ nodes.push({
99
+ kind: 'path',
100
+ key: 'area',
101
+ d: areaPath(animated, height, curve),
102
+ fill: withAlpha(accent, 0.16),
103
+ pointerEvents: 'none'
104
+ });
105
+ }
106
+ nodes.push({
107
+ kind: 'path',
108
+ key: 'line',
109
+ d: linePath(animated, curve),
110
+ fill: 'none',
111
+ stroke: accent,
112
+ strokeWidth,
113
+ linecap: 'round',
114
+ linejoin: 'round',
115
+ pointerEvents: 'none'
116
+ });
117
+ if (showLast) {
118
+ const last = animated[animated.length - 1];
119
+ nodes.push({
120
+ kind: 'circle',
121
+ key: 'last',
122
+ cx: last.x,
123
+ cy: last.y,
124
+ r: strokeWidth + 1.2,
125
+ fill: accent,
126
+ strokeWidth: 0,
127
+ pointerEvents: 'none'
128
+ });
129
+ }
130
+ return nodes;
131
+ }, [points, type, width, height, accent, strokeWidth, progress, showLast, smooth, animConfig.stagger]);
132
+ if (!data.length) return null;
133
+ return /*#__PURE__*/_jsx("div", {
134
+ className: classNames(prefixCls('chart'), className),
135
+ style: {
136
+ width,
137
+ height,
138
+ ...style
139
+ },
140
+ "data-aura-chart": "sparkline",
141
+ children: /*#__PURE__*/_jsx("div", {
142
+ className: prefixCls('chart__plot'),
143
+ children: /*#__PURE__*/_jsx(SvgScene, {
144
+ nodes: scene,
145
+ width: width,
146
+ height: height,
147
+ ariaLabel: ariaLabel ?? `迷你趋势图,共 ${data.length} 个数据点`
148
+ })
149
+ })
150
+ });
151
+ }
@@ -0,0 +1,34 @@
1
+ import React from 'react';
2
+ import { type HierarchyNode } from '../../core/hierarchy';
3
+ import { type ChartThemeInput } from '../../theme';
4
+ import type { ChartAnimationInput, TooltipConfig } from '../../types';
5
+ export interface TreeChartProps {
6
+ data?: HierarchyNode;
7
+ /** 节点圆点半径 */
8
+ nodeSize?: number;
9
+ /** 是否显示节点数值 */
10
+ showValue?: boolean;
11
+ /** 叶子到右边界预留的标签宽度 */
12
+ labelSpace?: number;
13
+ width?: number | string;
14
+ height?: number;
15
+ theme?: ChartThemeInput;
16
+ palette?: string[];
17
+ tooltip?: boolean | TooltipConfig;
18
+ animation?: ChartAnimationInput;
19
+ className?: string;
20
+ style?: React.CSSProperties;
21
+ ariaLabel?: string;
22
+ emptyText?: string;
23
+ }
24
+ /**
25
+ * 树图(横向展开)。
26
+ *
27
+ * 与矩形树图的分工:矩形树图用面积编码数值、回答「谁占得多」;
28
+ * 树图只表达层级结构与从属关系,节点大小恒定。
29
+ *
30
+ * 纵向位置按叶子顺序均分,父节点取子节点均值 —— 这样连线不交叉,
31
+ * 同一父节点下的兄弟会自然聚成一簇。
32
+ */
33
+ export declare function TreeChart({ data, nodeSize, showValue, labelSpace, width, height, theme: themeInput, palette, tooltip, animation, className, style, ariaLabel, emptyText, }: TreeChartProps): React.JSX.Element;
34
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA4B,MAAM,OAAO,CAAC;AAKjD,OAAO,EAKL,KAAK,aAAa,EAEnB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAa,KAAK,eAAe,EAAE,MAAM,aAAa,CAAC;AAM9D,OAAO,KAAK,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACtE,OAAO,6BAA6B,CAAC;AAErC,MAAM,WAAW,cAAc;IAC7B,IAAI,CAAC,EAAE,aAAa,CAAC;IACrB,aAAa;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,eAAe;IACf,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,oBAAoB;IACpB,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,OAAO,CAAC,EAAE,OAAO,GAAG,aAAa,CAAC;IAClC,SAAS,CAAC,EAAE,mBAAmB,CAAC;IAChC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;IAC5B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;GAQG;AACH,wBAAgB,SAAS,CAAC,EACxB,IAAI,EACJ,QAAY,EACZ,SAAiB,EACjB,UAAe,EACf,KAAc,EACd,MAAY,EACZ,KAAK,EAAE,UAAU,EACjB,OAAO,EACP,OAAc,EACd,SAAgB,EAChB,SAAS,EACT,KAAK,EACL,SAAS,EACT,SAAkB,GACnB,EAAE,cAAc,qBA4MhB"}