@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,136 @@
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 { formatPercent } from "../../core/format";
6
+ import { withAlpha } from "../../theme";
7
+ import { useChartTheme } from "../../hooks/useChartTheme";
8
+ import { useChartTransition } from "../../hooks/useChartTransition";
9
+ import { resolveAnimation } from "../../core/animation";
10
+ import { jsx as _jsx } from "react/jsx-runtime";
11
+ import { jsxs as _jsxs } from "react/jsx-runtime";
12
+ const DEG = Math.PI / 180;
13
+
14
+ /**
15
+ * 环形进度。
16
+ *
17
+ * 与 GaugeChart 的分工:仪表盘强调「在量程中的位置」(带刻度与端点),
18
+ * 环形进度强调「完成度」(无刻度、更紧凑),常用于表格单元格与卡片角落。
19
+ */
20
+ export function RingProgress({
21
+ value,
22
+ max = 100,
23
+ size = 160,
24
+ thickness = 12,
25
+ color,
26
+ trackColor,
27
+ startAngle = -90,
28
+ round = true,
29
+ showPercent = true,
30
+ children,
31
+ theme: themeInput,
32
+ palette,
33
+ animation = true,
34
+ className,
35
+ style,
36
+ ariaLabel
37
+ }) {
38
+ const theme = useChartTheme(themeInput, palette);
39
+ const animKey = typeof animation === 'object' ? JSON.stringify(animation) : String(animation);
40
+ const animConfig = useMemo(() => resolveAnimation(animation),
41
+ // eslint-disable-next-line react-hooks/exhaustive-deps
42
+ [animKey]);
43
+ const transition = useChartTransition([[value]], animConfig);
44
+ const progress = transition.progress;
45
+ const animatedValue = transition.values[0]?.[0] ?? value;
46
+ const ratio = useMemo(() => {
47
+ if (max === 0) return 0;
48
+ return Math.min(1, Math.max(0, animatedValue / max));
49
+ }, [animatedValue, max]);
50
+ const accent = color ?? theme.emphasis;
51
+ const track = trackColor ?? withAlpha(theme.axis.line, 0.6);
52
+ const geometry = useMemo(() => {
53
+ const center = size / 2;
54
+ const radius = Math.max(0, center - thickness / 2 - 1);
55
+ return {
56
+ cx: center,
57
+ cy: center,
58
+ radius,
59
+ arc: radius * 2 * Math.PI
60
+ };
61
+ }, [size, thickness]);
62
+ const start = startAngle * DEG;
63
+ const end = start + Math.PI * 2 * ratio * progress;
64
+ const scene = useMemo(() => {
65
+ const {
66
+ cx,
67
+ cy,
68
+ radius
69
+ } = geometry;
70
+ if (radius <= 0) return [];
71
+ const nodes = [];
72
+ nodes.push({
73
+ kind: 'path',
74
+ key: 'track',
75
+ d: arcLinePath(cx, cy, radius, 0, Math.PI * 2),
76
+ fill: 'none',
77
+ stroke: track,
78
+ strokeWidth: thickness,
79
+ pointerEvents: 'none'
80
+ });
81
+ if (end > start + 0.0001) {
82
+ nodes.push({
83
+ kind: 'path',
84
+ key: 'value',
85
+ d: arcLinePath(cx, cy, radius, start, end),
86
+ fill: 'none',
87
+ stroke: accent,
88
+ strokeWidth: thickness,
89
+ linecap: round ? 'round' : 'butt',
90
+ pointerEvents: 'none'
91
+ });
92
+ }
93
+ return nodes;
94
+ }, [geometry, start, end, track, accent, thickness, round]);
95
+ const autoAriaLabel = ariaLabel ?? `进度:${Math.round(ratio * 100)}%`;
96
+ return /*#__PURE__*/_jsxs("div", {
97
+ className: classNames(prefixCls('chart'), className),
98
+ style: {
99
+ width: size,
100
+ height: size,
101
+ position: 'relative',
102
+ ...style
103
+ },
104
+ "data-aura-chart": "ring-progress",
105
+ role: "img",
106
+ "aria-label": autoAriaLabel,
107
+ children: [/*#__PURE__*/_jsx("div", {
108
+ className: prefixCls('chart__plot'),
109
+ children: /*#__PURE__*/_jsx(SvgScene, {
110
+ nodes: scene,
111
+ width: size,
112
+ height: size,
113
+ ariaLabel: autoAriaLabel
114
+ })
115
+ }), /*#__PURE__*/_jsx("div", {
116
+ style: {
117
+ position: 'absolute',
118
+ inset: 0,
119
+ display: 'flex',
120
+ flexDirection: 'column',
121
+ alignItems: 'center',
122
+ justifyContent: 'center',
123
+ pointerEvents: 'none'
124
+ },
125
+ children: children ?? (showPercent ? /*#__PURE__*/_jsx("span", {
126
+ style: {
127
+ fontSize: Math.max(14, size * 0.16),
128
+ fontWeight: theme.font.weightMedium,
129
+ color: theme.text.primary,
130
+ fontVariantNumeric: 'tabular-nums'
131
+ },
132
+ children: formatPercent(value, max || 1, 0)
133
+ }) : null)
134
+ })]
135
+ });
136
+ }
@@ -0,0 +1,34 @@
1
+ import React from 'react';
2
+ import { type ChartThemeInput } from '../../theme';
3
+ import { type SankeyLinkInput, type SankeyNode } from '../../core/sankey';
4
+ import type { ChartAnimationInput, TooltipConfig } from '../../types';
5
+ export interface SankeyChartProps {
6
+ /** 节点列表;只传 links 时会自动从 links 推导 */
7
+ nodes?: SankeyNode[];
8
+ links?: SankeyLinkInput[];
9
+ /** 节点矩形宽度 */
10
+ nodeWidth?: number;
11
+ /** 同层节点竖向间隙 */
12
+ nodeGap?: number;
13
+ /** 是否在节点旁显示流量数值 */
14
+ showValue?: boolean;
15
+ width?: number | string;
16
+ height?: number;
17
+ theme?: ChartThemeInput;
18
+ palette?: string[];
19
+ tooltip?: boolean | TooltipConfig;
20
+ animation?: ChartAnimationInput;
21
+ className?: string;
22
+ style?: React.CSSProperties;
23
+ ariaLabel?: string;
24
+ emptyText?: string;
25
+ }
26
+ /**
27
+ * 桑基图。
28
+ *
29
+ * 用带宽编码流量,用节点位置编码阶段,一眼能看出「东西从哪来、到哪去、路上漏了多少」。
30
+ *
31
+ * 与漏斗图的区别:漏斗只能表达单链路层层递减,桑基能表达分流与合流。
32
+ */
33
+ export declare function SankeyChart({ nodes: nodesProp, links, nodeWidth, nodeGap, showValue, width, height, theme: themeInput, palette, tooltip, animation, className, style, ariaLabel, emptyText, }: SankeyChartProps): 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;AASjD,OAAO,EAAa,KAAK,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9D,OAAO,EAEL,KAAK,eAAe,EAEpB,KAAK,UAAU,EAChB,MAAM,mBAAmB,CAAC;AAM3B,OAAO,KAAK,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACtE,OAAO,6BAA6B,CAAC;AAErC,MAAM,WAAW,gBAAgB;IAC/B,mCAAmC;IACnC,KAAK,CAAC,EAAE,UAAU,EAAE,CAAC;IACrB,KAAK,CAAC,EAAE,eAAe,EAAE,CAAC;IAC1B,aAAa;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,eAAe;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,mBAAmB;IACnB,SAAS,CAAC,EAAE,OAAO,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;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,EAC1B,KAAK,EAAE,SAAS,EAChB,KAAU,EACV,SAAc,EACd,OAAY,EACZ,SAAgB,EAChB,KAAc,EACd,MAAY,EACZ,KAAK,EAAE,UAAU,EACjB,OAAO,EACP,OAAc,EACd,SAAgB,EAChB,SAAS,EACT,KAAK,EACL,SAAS,EACT,SAAkB,GACnB,EAAE,gBAAgB,qBA8RlB"}
@@ -0,0 +1,247 @@
1
+ import React, { useMemo, useState } from 'react';
2
+ import { classNames, prefixCls } from '@aura-react-comp/shared';
3
+ import { SvgScene } from "../../scene/svg";
4
+ import { formatNumber, formatPercent, estimateTextWidth } from "../../core/format";
5
+ import { withAlpha } from "../../theme";
6
+ import { layoutSankey } from "../../core/sankey";
7
+ import { useChartTheme } from "../../hooks/useChartTheme";
8
+ import { useElementSize } from "../../hooks/useElementSize";
9
+ import { useChartTransition } from "../../hooks/useChartTransition";
10
+ import { resolveAnimation, staggerProgress } from "../../core/animation";
11
+ 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
+ export function SankeyChart({
22
+ nodes: nodesProp,
23
+ links = [],
24
+ nodeWidth = 12,
25
+ nodeGap = 10,
26
+ showValue = true,
27
+ width = '100%',
28
+ height = 360,
29
+ theme: themeInput,
30
+ palette,
31
+ tooltip = true,
32
+ animation = true,
33
+ className,
34
+ style,
35
+ ariaLabel,
36
+ emptyText = '暂无数据'
37
+ }) {
38
+ const theme = useChartTheme(themeInput, palette);
39
+ const {
40
+ ref,
41
+ size
42
+ } = useElementSize();
43
+ const [activeLink, setActiveLink] = useState(null);
44
+ const [activeNode, setActiveNode] = useState(null);
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
+ /** 只给 links 时,按出现顺序补出节点 */
51
+ const nodes = useMemo(() => {
52
+ if (nodesProp?.length) return nodesProp;
53
+ const seen = new Set();
54
+ const derived = [];
55
+ for (const link of links) {
56
+ if (!seen.has(link.source)) {
57
+ seen.add(link.source);
58
+ derived.push({
59
+ name: link.source
60
+ });
61
+ }
62
+ if (!seen.has(link.target)) {
63
+ seen.add(link.target);
64
+ derived.push({
65
+ name: link.target
66
+ });
67
+ }
68
+ }
69
+ return derived;
70
+ }, [nodesProp, links]);
71
+ const total = useMemo(() => links.reduce((sum, link) => sum + (link.value || 0), 0) || 1, [links]);
72
+
73
+ // 左右各留出标签空间
74
+ const labelSpace = 92;
75
+ const layout = useMemo(() => layoutSankey(nodes, links, {
76
+ x: labelSpace,
77
+ y: 12,
78
+ width: Math.max(0, size.width - labelSpace * 2),
79
+ height: Math.max(0, size.height - 24)
80
+ }, {
81
+ nodeWidth,
82
+ nodeGap,
83
+ colorOf: (layer, index) => theme.palette[(layer * 2 + index) % theme.palette.length]
84
+ }), [nodes, links, size.width, size.height, nodeWidth, nodeGap, theme.palette]);
85
+ const valueMatrix = useMemo(() => [layout.links.map(link => Math.round(link.value))], [layout.links]);
86
+ const progress = useChartTransition(valueMatrix, animConfig).progress;
87
+ const scene = useMemo(() => {
88
+ if (!layout.nodes.length || size.width <= 0) return [];
89
+ const nodes = [];
90
+
91
+ // 链接先画,节点压在上面
92
+ layout.links.forEach((link, index) => {
93
+ const local = staggerProgress(progress, link.source.layer, layout.layers, animConfig.stagger);
94
+ const isActive = activeLink?.source.name === link.source.name && activeLink?.target.name === link.target.name && activeLink.value === link.value;
95
+ nodes.push({
96
+ kind: 'path',
97
+ key: `link-${index}`,
98
+ d: link.d,
99
+ fill: withAlpha(link.color, isActive ? 0.55 : 0.26),
100
+ opacity: local,
101
+ pointerEvents: 'none'
102
+ });
103
+ });
104
+ layout.nodes.forEach((node, index) => {
105
+ const local = staggerProgress(progress, node.layer, layout.layers, animConfig.stagger);
106
+ const isActive = activeNode === node.name;
107
+ nodes.push({
108
+ kind: 'rect',
109
+ key: `node-${node.name}`,
110
+ x: node.x,
111
+ y: node.y,
112
+ width: node.width,
113
+ height: Math.max(2, node.height * local),
114
+ radius: 2,
115
+ fill: node.color,
116
+ stroke: isActive ? theme.text.primary : undefined,
117
+ strokeWidth: isActive ? 2 : 0,
118
+ pointerEvents: 'none'
119
+ });
120
+
121
+ // 首尾两列标签放节点外侧,中间列放内侧;内侧会被色带压住,
122
+ // 所以文字统一带白色光晕
123
+ const isLastLayer = node.layer === layout.layers - 1;
124
+ const onLeft = node.layer === 0 || isLastLayer;
125
+ const labelX = onLeft ? node.x - 8 : node.x + node.width + 8;
126
+ const maxLabelWidth = onLeft ? labelX - 4 : size.width - labelX - 4;
127
+ if (maxLabelWidth < 24) return;
128
+ const label = showValue && node.layer === layout.layers - 1 ? `${node.name} ${formatNumber(node.value, {
129
+ compact: true
130
+ })}` : node.name;
131
+ const text = estimateTextWidth(label, theme.font.size) > maxLabelWidth ? `${label.slice(0, Math.max(2, Math.floor(maxLabelWidth / theme.font.size)))}…` : label;
132
+ nodes.push({
133
+ kind: 'text',
134
+ key: `node-label-${node.name}-${index}`,
135
+ x: labelX,
136
+ y: node.y + node.height / 2,
137
+ text,
138
+ fill: isActive ? theme.text.primary : theme.text.secondary,
139
+ fontSize: theme.font.size,
140
+ anchor: onLeft ? 'end' : 'start',
141
+ baseline: 'middle',
142
+ opacity: local,
143
+ fontFamily: theme.font.family,
144
+ // 光晕:文字压在色带上也读得清
145
+ stroke: theme.tooltip.background,
146
+ strokeWidth: 3
147
+ });
148
+ });
149
+ return nodes;
150
+ }, [layout, size.width, theme, progress, animConfig.stagger, activeLink, activeNode, showValue]);
151
+ const linkFromPointer = (clientX, clientY) => {
152
+ const element = ref.current;
153
+ if (!element) return null;
154
+ const rect = element.getBoundingClientRect();
155
+ const x = clientX - rect.left;
156
+ const y = clientY - rect.top;
157
+
158
+ // 节点优先
159
+ for (const node of layout.nodes) {
160
+ if (x >= node.x - 2 && x <= node.x + node.width + 2 && y >= node.y && y <= node.y + node.height) {
161
+ setActiveNode(node.name);
162
+ return null;
163
+ }
164
+ }
165
+ setActiveNode(null);
166
+
167
+ // 链接:按 x 在两端之间做线性插值,得到该处的带状区间
168
+ for (const link of layout.links) {
169
+ const x0 = link.source.x + link.source.width;
170
+ const x1 = link.target.x;
171
+ if (x < x0 || x > x1 || x1 <= x0) continue;
172
+ const ratio = (x - x0) / (x1 - x0);
173
+ const top = link.sourceY + (link.targetY - link.sourceY) * ratio;
174
+ const thickness = link.sourceThickness + (link.targetThickness - link.sourceThickness) * ratio;
175
+ if (y >= top && y <= top + thickness) return link;
176
+ }
177
+ return null;
178
+ };
179
+ const tooltipPayload = activeLink ? {
180
+ label: `${activeLink.source.name} → ${activeLink.target.name}`,
181
+ row: null,
182
+ series: [{
183
+ key: 'value',
184
+ name: '流量',
185
+ color: activeLink.color,
186
+ value: activeLink.value,
187
+ formatted: `${formatNumber(activeLink.value, {
188
+ compact: true
189
+ })}(${formatPercent(activeLink.value, total, 1)})`
190
+ }]
191
+ } : activeNode ? (() => {
192
+ const node = layout.nodes.find(item => item.name === activeNode);
193
+ if (!node) return null;
194
+ return {
195
+ label: node.name,
196
+ row: null,
197
+ series: [{
198
+ key: 'value',
199
+ name: '流量',
200
+ color: node.color,
201
+ value: node.value,
202
+ formatted: formatNumber(node.value, {
203
+ compact: true
204
+ })
205
+ }]
206
+ };
207
+ })() : null;
208
+ const autoAriaLabel = ariaLabel ?? `桑基图:${layout.nodes.length} 个节点,${layout.links.length} 条流向`;
209
+ return /*#__PURE__*/_jsx("div", {
210
+ className: classNames(prefixCls('chart'), className),
211
+ style: {
212
+ width,
213
+ height,
214
+ ...style
215
+ },
216
+ "data-aura-chart": "sankey",
217
+ children: /*#__PURE__*/_jsxs("div", {
218
+ ref: ref,
219
+ className: prefixCls('chart__plot'),
220
+ onPointerMove: event => {
221
+ const link = linkFromPointer(event.clientX, event.clientY);
222
+ setActiveLink(link);
223
+ },
224
+ onPointerLeave: () => {
225
+ setActiveLink(null);
226
+ setActiveNode(null);
227
+ },
228
+ children: [!layout.nodes.length || size.width === 0 ? /*#__PURE__*/_jsx("div", {
229
+ className: prefixCls('chart__empty'),
230
+ children: emptyText
231
+ }) : /*#__PURE__*/_jsx(SvgScene, {
232
+ nodes: scene,
233
+ width: size.width,
234
+ height: size.height,
235
+ ariaLabel: autoAriaLabel
236
+ }), /*#__PURE__*/_jsx(Tooltip, {
237
+ payload: tooltipPayload,
238
+ x: activeLink ? (activeLink.source.x + activeLink.target.x) / 2 : size.width / 2,
239
+ y: 12,
240
+ containerWidth: size.width,
241
+ containerHeight: size.height,
242
+ theme: theme,
243
+ config: tooltip
244
+ })]
245
+ })
246
+ });
247
+ }
@@ -0,0 +1,34 @@
1
+ import React from 'react';
2
+ import type { ChartDataRow, SeriesConfig } from '../../types';
3
+ import { type ChartThemeInput } from '../../theme';
4
+ import type { LegendConfig, TooltipConfig } from '../../types';
5
+ export interface ScatterChartProps {
6
+ data?: ChartDataRow[];
7
+ /** 数值型 x 字段 */
8
+ xKey?: string;
9
+ series?: SeriesConfig[];
10
+ width?: number | string;
11
+ height?: number;
12
+ theme?: ChartThemeInput;
13
+ palette?: string[];
14
+ legend?: boolean | LegendConfig;
15
+ tooltip?: boolean | TooltipConfig;
16
+ /** 点形状 */
17
+ symbol?: 'circle' | 'square' | 'diamond' | 'triangle' | 'star' | 'cross';
18
+ /** 点大小 */
19
+ symbolSize?: number;
20
+ animation?: boolean;
21
+ className?: string;
22
+ style?: React.CSSProperties;
23
+ ariaLabel?: string;
24
+ emptyText?: string;
25
+ }
26
+ /**
27
+ * 散点图。
28
+ *
29
+ * 与折线/柱状不同,散点的 x 是**连续的数值轴**而非分类轴:
30
+ * 分类轴会把 [1, 2, 100] 摆成等间距,严重扭曲相关性判断。
31
+ * 因此这里不复用 CartesianChart 的 band 坐标,改为线性 x 轴。
32
+ */
33
+ export declare function ScatterChart({ data, xKey, series, width, height, theme: themeInput, palette, legend, tooltip, symbol, symbolSize, animation, className, style, ariaLabel, emptyText, }: ScatterChartProps): 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,KAAyC,MAAM,OAAO,CAAC;AAE9D,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAkB,MAAM,aAAa,CAAC;AAO9E,OAAO,EAAW,KAAK,eAAe,EAAE,MAAM,aAAa,CAAC;AAO5D,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC/D,OAAO,6BAA6B,CAAC;AAErC,MAAM,WAAW,iBAAiB;IAChC,IAAI,CAAC,EAAE,YAAY,EAAE,CAAC;IACtB,eAAe;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,YAAY,EAAE,CAAC;IACxB,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,MAAM,CAAC,EAAE,OAAO,GAAG,YAAY,CAAC;IAChC,OAAO,CAAC,EAAE,OAAO,GAAG,aAAa,CAAC;IAClC,UAAU;IACV,MAAM,CAAC,EAAE,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,UAAU,GAAG,MAAM,GAAG,OAAO,CAAC;IACzE,UAAU;IACV,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,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;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAWD;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,EAC3B,IAAS,EACT,IAAU,EACV,MAAW,EACX,KAAc,EACd,MAAY,EACZ,KAAK,EAAE,UAAU,EACjB,OAAO,EACP,MAAa,EACb,OAAc,EACd,MAAiB,EACjB,UAAc,EACd,SAAgB,EAChB,SAAS,EACT,KAAK,EACL,SAAS,EACT,SAAkB,GACnB,EAAE,iBAAiB,qBA+WnB"}