@aura-react-comp/charts 0.3.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/charts/area-chart/index.js +27 -23
- package/esm/charts/bar-chart/index.js +17 -21
- package/esm/charts/candlestick-chart/index.js +242 -180
- package/esm/charts/combo-chart/index.js +8 -20
- package/esm/charts/funnel-chart/index.js +133 -108
- package/esm/charts/gauge-chart/index.js +102 -105
- package/esm/charts/graph-chart/index.js +154 -114
- package/esm/charts/heatmap-chart/index.js +179 -135
- package/esm/charts/line-chart/index.js +28 -24
- package/esm/charts/pie-chart/index.d.ts.map +1 -1
- package/esm/charts/pie-chart/index.js +198 -139
- package/esm/charts/radar-chart/index.d.ts.map +1 -1
- package/esm/charts/radar-chart/index.js +154 -128
- package/esm/charts/ring-progress/index.js +81 -82
- package/esm/charts/sankey-chart/index.js +171 -141
- package/esm/charts/scatter-chart/index.d.ts.map +1 -1
- package/esm/charts/scatter-chart/index.js +225 -159
- package/esm/charts/sparkline/index.js +81 -66
- package/esm/charts/tree-chart/index.js +128 -102
- package/esm/charts/treemap-chart/index.js +162 -141
- package/esm/charts/waterfall-chart/index.js +165 -121
- package/esm/components/Legend.d.ts +3 -2
- package/esm/components/Legend.d.ts.map +1 -1
- package/esm/components/Legend.js +79 -48
- package/esm/components/Tooltip.js +62 -71
- package/esm/components/chart/index.d.ts +4 -1
- package/esm/components/chart/index.d.ts.map +1 -1
- package/esm/components/chart/index.js +80 -102
- package/esm/components/chart.less +13 -0
- package/esm/core/animation.js +31 -43
- package/esm/core/export.d.ts +34 -0
- package/esm/core/export.d.ts.map +1 -0
- package/esm/core/export.js +390 -0
- package/esm/core/force.js +22 -45
- package/esm/core/format.js +48 -52
- package/esm/core/hierarchy.js +60 -92
- package/esm/core/layout.js +32 -50
- package/esm/core/sampling.js +30 -53
- package/esm/core/sankey.js +35 -55
- package/esm/core/scale.js +72 -86
- package/esm/core/shape.js +101 -133
- package/esm/core/sync.d.ts +41 -0
- package/esm/core/sync.d.ts.map +1 -0
- package/esm/core/sync.js +120 -0
- package/esm/hooks/useChartExport.d.ts +19 -0
- package/esm/hooks/useChartExport.d.ts.map +1 -0
- package/esm/hooks/useChartExport.js +35 -0
- package/esm/hooks/useChartTheme.js +17 -19
- package/esm/hooks/useChartTransition.js +58 -73
- package/esm/hooks/useElementSize.js +19 -28
- package/esm/hooks/usePlotPointer.d.ts +23 -0
- package/esm/hooks/usePlotPointer.d.ts.map +1 -0
- package/esm/hooks/usePlotPointer.js +94 -0
- package/esm/index.d.ts +6 -0
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +136 -47
- package/esm/internal/CartesianChart.d.ts.map +1 -1
- package/esm/internal/CartesianChart.js +666 -485
- package/esm/internal/model.js +44 -60
- package/esm/scene/canvas.js +100 -107
- package/esm/scene/svg.js +106 -99
- package/esm/scene/types.js +8 -15
- package/esm/style.css +10 -0
- package/esm/theme/index.js +143 -171
- package/esm/types.d.ts +4 -0
- package/esm/types.d.ts.map +1 -1
- package/esm/types.js +0 -1
- package/package.json +1 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
|
|
3
|
-
import {
|
|
2
|
+
// src/charts/sparkline/index.tsx
|
|
3
|
+
import { useMemo } from "react";
|
|
4
|
+
import { classNames, prefixCls } from "@aura-react-comp/shared";
|
|
4
5
|
import { SvgScene } from "../../scene/svg";
|
|
5
6
|
import { areaPath, linePath } from "../../core/shape";
|
|
6
7
|
import { extentOf } from "../../core/scale";
|
|
@@ -8,18 +9,10 @@ import { withAlpha } from "../../theme";
|
|
|
8
9
|
import { useChartTheme } from "../../hooks/useChartTheme";
|
|
9
10
|
import { useChartTransition } from "../../hooks/useChartTransition";
|
|
10
11
|
import { resolveAnimation, staggerProgress } from "../../core/animation";
|
|
11
|
-
import { jsx
|
|
12
|
-
|
|
13
|
-
* 迷你图(Sparkline)。
|
|
14
|
-
*
|
|
15
|
-
* 没有坐标轴、没有图例、没有 tooltip —— 它的唯一职责是让读者在扫视表格时
|
|
16
|
-
* 立刻看出「这条数据是在涨还是在跌」。任何额外装饰都会削弱这个目的。
|
|
17
|
-
*
|
|
18
|
-
* 因此它也刻意不提供数值精度:需要读数请用折线图。
|
|
19
|
-
*/
|
|
20
|
-
export function Sparkline({
|
|
12
|
+
import { jsx } from "react/jsx-runtime";
|
|
13
|
+
function Sparkline({
|
|
21
14
|
data = [],
|
|
22
|
-
type =
|
|
15
|
+
type = "line",
|
|
23
16
|
width = 120,
|
|
24
17
|
height = 32,
|
|
25
18
|
color,
|
|
@@ -35,15 +28,18 @@ export function Sparkline({
|
|
|
35
28
|
}) {
|
|
36
29
|
const theme = useChartTheme(themeInput, palette);
|
|
37
30
|
const accent = color ?? theme.emphasis;
|
|
38
|
-
const animKey = typeof animation ===
|
|
39
|
-
const animConfig = useMemo(
|
|
40
|
-
|
|
41
|
-
|
|
31
|
+
const animKey = typeof animation === "object" ? JSON.stringify(animation) : String(animation);
|
|
32
|
+
const animConfig = useMemo(
|
|
33
|
+
() => resolveAnimation(animation),
|
|
34
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
35
|
+
[animKey]
|
|
36
|
+
);
|
|
42
37
|
const transition = useChartTransition([data], animConfig);
|
|
43
38
|
const progress = transition.progress;
|
|
44
39
|
const values = transition.values[0] ?? data;
|
|
45
40
|
const points = useMemo(() => {
|
|
46
|
-
if (!values.length)
|
|
41
|
+
if (!values.length)
|
|
42
|
+
return [];
|
|
47
43
|
const [min, max] = extentOf(values);
|
|
48
44
|
const span = max - min || 1;
|
|
49
45
|
const pad = strokeWidth;
|
|
@@ -60,18 +56,24 @@ export function Sparkline({
|
|
|
60
56
|
});
|
|
61
57
|
}, [values, width, height, strokeWidth]);
|
|
62
58
|
const scene = useMemo(() => {
|
|
63
|
-
if (!points.length)
|
|
59
|
+
if (!points.length)
|
|
60
|
+
return [];
|
|
64
61
|
const nodes = [];
|
|
65
|
-
const curve = smooth ?
|
|
66
|
-
if (type ===
|
|
62
|
+
const curve = smooth ? "smooth" : "linear";
|
|
63
|
+
if (type === "bar") {
|
|
67
64
|
const slot = width / Math.max(points.length, 1);
|
|
68
65
|
const barWidth = Math.max(1, slot * 0.6);
|
|
69
66
|
const bottom = height - strokeWidth / 2;
|
|
70
67
|
points.forEach((point, index) => {
|
|
71
|
-
const local = staggerProgress(
|
|
68
|
+
const local = staggerProgress(
|
|
69
|
+
progress,
|
|
70
|
+
index,
|
|
71
|
+
points.length,
|
|
72
|
+
animConfig.stagger
|
|
73
|
+
);
|
|
72
74
|
const barHeight = Math.max(1, (bottom - point.y) * local);
|
|
73
75
|
nodes.push({
|
|
74
|
-
kind:
|
|
76
|
+
kind: "rect",
|
|
75
77
|
key: `bar-${index}`,
|
|
76
78
|
x: point.x - barWidth / 2,
|
|
77
79
|
y: bottom - barHeight,
|
|
@@ -80,73 +82,86 @@ export function Sparkline({
|
|
|
80
82
|
radius: 1,
|
|
81
83
|
fill: accent,
|
|
82
84
|
opacity: 0.85,
|
|
83
|
-
pointerEvents:
|
|
85
|
+
pointerEvents: "none"
|
|
84
86
|
});
|
|
85
87
|
});
|
|
86
88
|
return nodes;
|
|
87
89
|
}
|
|
88
|
-
|
|
89
|
-
// 动画:进场时按 progress 从底部抬升
|
|
90
|
-
// 逐点错峰:线条像被画出,而不是整体从底部抬起
|
|
91
90
|
const animated = points.map((point, index) => {
|
|
92
|
-
const local = staggerProgress(
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
91
|
+
const local = staggerProgress(
|
|
92
|
+
progress,
|
|
93
|
+
index,
|
|
94
|
+
points.length,
|
|
95
|
+
animConfig.stagger
|
|
96
|
+
);
|
|
97
|
+
return { x: point.x, y: height + (point.y - height) * local };
|
|
97
98
|
});
|
|
98
|
-
if (type ===
|
|
99
|
+
if (type === "area") {
|
|
99
100
|
nodes.push({
|
|
100
|
-
kind:
|
|
101
|
-
key:
|
|
101
|
+
kind: "path",
|
|
102
|
+
key: "area",
|
|
102
103
|
d: areaPath(animated, height, curve),
|
|
103
104
|
fill: withAlpha(accent, 0.16),
|
|
104
|
-
pointerEvents:
|
|
105
|
+
pointerEvents: "none"
|
|
105
106
|
});
|
|
106
107
|
}
|
|
107
108
|
nodes.push({
|
|
108
|
-
kind:
|
|
109
|
-
key:
|
|
109
|
+
kind: "path",
|
|
110
|
+
key: "line",
|
|
110
111
|
d: linePath(animated, curve),
|
|
111
|
-
fill:
|
|
112
|
+
fill: "none",
|
|
112
113
|
stroke: accent,
|
|
113
114
|
strokeWidth,
|
|
114
|
-
linecap:
|
|
115
|
-
linejoin:
|
|
116
|
-
pointerEvents:
|
|
115
|
+
linecap: "round",
|
|
116
|
+
linejoin: "round",
|
|
117
|
+
pointerEvents: "none"
|
|
117
118
|
});
|
|
118
119
|
if (showLast) {
|
|
119
120
|
const last = animated[animated.length - 1];
|
|
120
121
|
nodes.push({
|
|
121
|
-
kind:
|
|
122
|
-
key:
|
|
122
|
+
kind: "circle",
|
|
123
|
+
key: "last",
|
|
123
124
|
cx: last.x,
|
|
124
125
|
cy: last.y,
|
|
125
126
|
r: strokeWidth + 1.2,
|
|
126
127
|
fill: accent,
|
|
127
128
|
strokeWidth: 0,
|
|
128
|
-
pointerEvents:
|
|
129
|
+
pointerEvents: "none"
|
|
129
130
|
});
|
|
130
131
|
}
|
|
131
132
|
return nodes;
|
|
132
|
-
}, [
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
133
|
+
}, [
|
|
134
|
+
points,
|
|
135
|
+
type,
|
|
136
|
+
width,
|
|
137
|
+
height,
|
|
138
|
+
accent,
|
|
139
|
+
strokeWidth,
|
|
140
|
+
progress,
|
|
141
|
+
showLast,
|
|
142
|
+
smooth,
|
|
143
|
+
animConfig.stagger
|
|
144
|
+
]);
|
|
145
|
+
if (!data.length)
|
|
146
|
+
return null;
|
|
147
|
+
return /* @__PURE__ */ jsx(
|
|
148
|
+
"div",
|
|
149
|
+
{
|
|
150
|
+
className: classNames(prefixCls("chart"), className),
|
|
151
|
+
style: { width, height, ...style },
|
|
152
|
+
"data-aura-chart": "sparkline",
|
|
153
|
+
children: /* @__PURE__ */ jsx("div", { className: prefixCls("chart__plot"), children: /* @__PURE__ */ jsx(
|
|
154
|
+
SvgScene,
|
|
155
|
+
{
|
|
156
|
+
nodes: scene,
|
|
157
|
+
width,
|
|
158
|
+
height,
|
|
159
|
+
ariaLabel: ariaLabel ?? `迷你趋势图,共 ${data.length} 个数据点`
|
|
160
|
+
}
|
|
161
|
+
) })
|
|
162
|
+
}
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
export {
|
|
166
|
+
Sparkline
|
|
167
|
+
};
|
|
@@ -1,32 +1,28 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
|
|
3
|
-
import {
|
|
2
|
+
// src/charts/tree-chart/index.tsx
|
|
3
|
+
import { useMemo, useState } from "react";
|
|
4
|
+
import { classNames, prefixCls } from "@aura-react-comp/shared";
|
|
4
5
|
import { SvgScene } from "../../scene/svg";
|
|
5
6
|
import { formatNumber } from "../../core/format";
|
|
6
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
layoutTree,
|
|
9
|
+
maxDepth,
|
|
10
|
+
sumValues,
|
|
11
|
+
treeLinkPath
|
|
12
|
+
} from "../../core/hierarchy";
|
|
7
13
|
import { withAlpha } from "../../theme";
|
|
8
14
|
import { useChartTheme } from "../../hooks/useChartTheme";
|
|
9
15
|
import { useElementSize } from "../../hooks/useElementSize";
|
|
10
16
|
import { useChartTransition } from "../../hooks/useChartTransition";
|
|
11
17
|
import { resolveAnimation, staggerProgress } from "../../core/animation";
|
|
12
18
|
import { Tooltip } from "../../components/Tooltip";
|
|
13
|
-
import { jsx
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* 树图(横向展开)。
|
|
17
|
-
*
|
|
18
|
-
* 与矩形树图的分工:矩形树图用面积编码数值、回答「谁占得多」;
|
|
19
|
-
* 树图只表达层级结构与从属关系,节点大小恒定。
|
|
20
|
-
*
|
|
21
|
-
* 纵向位置按叶子顺序均分,父节点取子节点均值 —— 这样连线不交叉,
|
|
22
|
-
* 同一父节点下的兄弟会自然聚成一簇。
|
|
23
|
-
*/
|
|
24
|
-
export function TreeChart({
|
|
19
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
20
|
+
function TreeChart({
|
|
25
21
|
data,
|
|
26
22
|
nodeSize = 4,
|
|
27
23
|
showValue = false,
|
|
28
24
|
labelSpace = 96,
|
|
29
|
-
width =
|
|
25
|
+
width = "100%",
|
|
30
26
|
height = 360,
|
|
31
27
|
theme: themeInput,
|
|
32
28
|
palette,
|
|
@@ -35,23 +31,21 @@ export function TreeChart({
|
|
|
35
31
|
className,
|
|
36
32
|
style,
|
|
37
33
|
ariaLabel,
|
|
38
|
-
emptyText =
|
|
34
|
+
emptyText = "暂无数据"
|
|
39
35
|
}) {
|
|
36
|
+
var _a;
|
|
40
37
|
const theme = useChartTheme(themeInput, palette);
|
|
41
|
-
const {
|
|
42
|
-
ref,
|
|
43
|
-
size
|
|
44
|
-
} = useElementSize();
|
|
38
|
+
const { ref, size } = useElementSize();
|
|
45
39
|
const [activeIndex, setActiveIndex] = useState(null);
|
|
46
|
-
const animKey = typeof animation ===
|
|
47
|
-
const animConfig = useMemo(
|
|
48
|
-
|
|
49
|
-
|
|
40
|
+
const animKey = typeof animation === "object" ? JSON.stringify(animation) : String(animation);
|
|
41
|
+
const animConfig = useMemo(
|
|
42
|
+
() => resolveAnimation(animation),
|
|
43
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
44
|
+
[animKey]
|
|
45
|
+
);
|
|
50
46
|
const layout = useMemo(() => {
|
|
51
|
-
if (!data)
|
|
52
|
-
nodes: [],
|
|
53
|
-
depth: 0
|
|
54
|
-
};
|
|
47
|
+
if (!data)
|
|
48
|
+
return { nodes: [], depth: 0 };
|
|
55
49
|
return layoutTree(data, {
|
|
56
50
|
x: 12,
|
|
57
51
|
y: 16,
|
|
@@ -60,50 +54,61 @@ export function TreeChart({
|
|
|
60
54
|
height: Math.max(0, size.height - 32)
|
|
61
55
|
});
|
|
62
56
|
}, [data, size.width, size.height, labelSpace]);
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
57
|
+
const matrix = useMemo(
|
|
58
|
+
() => [layout.nodes.map((item) => Math.round(item.y))],
|
|
59
|
+
[layout.nodes]
|
|
60
|
+
);
|
|
66
61
|
const transition = useChartTransition(matrix, animConfig);
|
|
67
62
|
const progress = transition.progress;
|
|
68
63
|
const scene = useMemo(() => {
|
|
69
|
-
if (!layout.nodes.length || size.width <= 0)
|
|
64
|
+
if (!layout.nodes.length || size.width <= 0)
|
|
65
|
+
return [];
|
|
70
66
|
const nodes = [];
|
|
71
|
-
const depthTotal = Math.max(1, maxDepth(data ?? {
|
|
72
|
-
name: ''
|
|
73
|
-
}));
|
|
74
|
-
|
|
75
|
-
// 先画连线,保证节点压在线上
|
|
67
|
+
const depthTotal = Math.max(1, maxDepth(data ?? { name: "" }));
|
|
76
68
|
layout.nodes.forEach((item, index) => {
|
|
77
|
-
|
|
69
|
+
var _a2, _b;
|
|
70
|
+
if (item.parent < 0)
|
|
71
|
+
return;
|
|
78
72
|
const parent = layout.nodes[item.parent];
|
|
79
|
-
const local = staggerProgress(
|
|
73
|
+
const local = staggerProgress(
|
|
74
|
+
progress,
|
|
75
|
+
item.depth,
|
|
76
|
+
depthTotal,
|
|
77
|
+
animConfig.stagger
|
|
78
|
+
);
|
|
80
79
|
const animatedParent = {
|
|
81
80
|
...parent,
|
|
82
|
-
y: transition.values[0]
|
|
81
|
+
y: ((_a2 = transition.values[0]) == null ? void 0 : _a2[item.parent]) ?? parent.y
|
|
83
82
|
};
|
|
84
83
|
const animatedChild = {
|
|
85
84
|
...item,
|
|
86
|
-
y: transition.values[0]
|
|
85
|
+
y: ((_b = transition.values[0]) == null ? void 0 : _b[index]) ?? item.y
|
|
87
86
|
};
|
|
88
87
|
nodes.push({
|
|
89
|
-
kind:
|
|
88
|
+
kind: "path",
|
|
90
89
|
key: `link-${index}`,
|
|
91
90
|
d: treeLinkPath(animatedParent, animatedChild, nodeSize),
|
|
92
|
-
fill:
|
|
91
|
+
fill: "none",
|
|
93
92
|
stroke: withAlpha(theme.axis.line, 0.9),
|
|
94
93
|
strokeWidth: 1.2,
|
|
95
94
|
opacity: local,
|
|
96
|
-
pointerEvents:
|
|
95
|
+
pointerEvents: "none"
|
|
97
96
|
});
|
|
98
97
|
});
|
|
99
98
|
layout.nodes.forEach((item, index) => {
|
|
100
|
-
|
|
99
|
+
var _a2, _b;
|
|
100
|
+
const y = ((_a2 = transition.values[0]) == null ? void 0 : _a2[index]) ?? item.y;
|
|
101
101
|
const isActive = activeIndex === index;
|
|
102
|
-
const hasChildren = Boolean(item.node.children
|
|
103
|
-
const local = staggerProgress(
|
|
102
|
+
const hasChildren = Boolean((_b = item.node.children) == null ? void 0 : _b.length);
|
|
103
|
+
const local = staggerProgress(
|
|
104
|
+
progress,
|
|
105
|
+
item.depth,
|
|
106
|
+
depthTotal,
|
|
107
|
+
animConfig.stagger
|
|
108
|
+
);
|
|
104
109
|
const color = hasChildren ? theme.emphasis : item.node.color ?? theme.palette[item.depth % theme.palette.length];
|
|
105
110
|
nodes.push({
|
|
106
|
-
kind:
|
|
111
|
+
kind: "circle",
|
|
107
112
|
key: `node-${index}`,
|
|
108
113
|
cx: item.x,
|
|
109
114
|
cy: y,
|
|
@@ -112,35 +117,45 @@ export function TreeChart({
|
|
|
112
117
|
stroke: color,
|
|
113
118
|
strokeWidth: hasChildren ? 2 : 0,
|
|
114
119
|
opacity: local,
|
|
115
|
-
pointerEvents:
|
|
120
|
+
pointerEvents: "none"
|
|
116
121
|
});
|
|
117
122
|
nodes.push({
|
|
118
|
-
kind:
|
|
123
|
+
kind: "text",
|
|
119
124
|
key: `label-${index}`,
|
|
120
125
|
x: item.x + nodeSize + 8,
|
|
121
126
|
y,
|
|
122
|
-
text: showValue && item.node.value !==
|
|
123
|
-
compact: true
|
|
124
|
-
})}` : item.node.name,
|
|
127
|
+
text: showValue && item.node.value !== void 0 ? `${item.node.name} ${formatNumber(item.node.value, { compact: true })}` : item.node.name,
|
|
125
128
|
fill: hasChildren ? theme.text.primary : theme.text.secondary,
|
|
126
129
|
fontSize: theme.font.size,
|
|
127
|
-
fontWeight: hasChildren ? theme.font.weightMedium :
|
|
128
|
-
anchor:
|
|
129
|
-
baseline:
|
|
130
|
+
fontWeight: hasChildren ? theme.font.weightMedium : void 0,
|
|
131
|
+
anchor: "start",
|
|
132
|
+
baseline: "middle",
|
|
130
133
|
opacity: local,
|
|
131
134
|
fontFamily: theme.font.family
|
|
132
135
|
});
|
|
133
136
|
});
|
|
134
137
|
return nodes;
|
|
135
|
-
}, [
|
|
138
|
+
}, [
|
|
139
|
+
layout,
|
|
140
|
+
size.width,
|
|
141
|
+
data,
|
|
142
|
+
theme,
|
|
143
|
+
progress,
|
|
144
|
+
animConfig.stagger,
|
|
145
|
+
activeIndex,
|
|
146
|
+
nodeSize,
|
|
147
|
+
showValue,
|
|
148
|
+
transition.values
|
|
149
|
+
]);
|
|
136
150
|
const nodeFromPointer = (clientX, clientY) => {
|
|
137
151
|
const element = ref.current;
|
|
138
|
-
if (!element)
|
|
152
|
+
if (!element)
|
|
153
|
+
return null;
|
|
139
154
|
const rect = element.getBoundingClientRect();
|
|
140
155
|
const x = clientX - rect.left;
|
|
141
156
|
const y = clientY - rect.top;
|
|
142
157
|
let nearest = null;
|
|
143
|
-
let min = 18;
|
|
158
|
+
let min = 18;
|
|
144
159
|
layout.nodes.forEach((item, index) => {
|
|
145
160
|
const distance = Math.hypot(item.x - x, item.y - y);
|
|
146
161
|
if (distance < min) {
|
|
@@ -154,47 +169,58 @@ export function TreeChart({
|
|
|
154
169
|
const tooltipPayload = active ? {
|
|
155
170
|
label: active.node.name,
|
|
156
171
|
row: null,
|
|
157
|
-
series: [
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
compact: true
|
|
164
|
-
}
|
|
165
|
-
|
|
172
|
+
series: [
|
|
173
|
+
{
|
|
174
|
+
key: "value",
|
|
175
|
+
name: ((_a = active.node.children) == null ? void 0 : _a.length) ? "合计" : "数值",
|
|
176
|
+
color: theme.emphasis,
|
|
177
|
+
value: sumValues(active.node),
|
|
178
|
+
formatted: formatNumber(sumValues(active.node), { compact: true })
|
|
179
|
+
}
|
|
180
|
+
]
|
|
166
181
|
} : null;
|
|
167
182
|
const autoAriaLabel = ariaLabel ?? `树图:${layout.nodes.length} 个节点`;
|
|
168
|
-
return
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
height,
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
183
|
+
return /* @__PURE__ */ jsx(
|
|
184
|
+
"div",
|
|
185
|
+
{
|
|
186
|
+
className: classNames(prefixCls("chart"), className),
|
|
187
|
+
style: { width, height, ...style },
|
|
188
|
+
"data-aura-chart": "tree",
|
|
189
|
+
children: /* @__PURE__ */ jsxs(
|
|
190
|
+
"div",
|
|
191
|
+
{
|
|
192
|
+
ref,
|
|
193
|
+
className: prefixCls("chart__plot"),
|
|
194
|
+
onPointerMove: (event) => setActiveIndex(nodeFromPointer(event.clientX, event.clientY)),
|
|
195
|
+
onPointerLeave: () => setActiveIndex(null),
|
|
196
|
+
children: [
|
|
197
|
+
!layout.nodes.length || size.width === 0 ? /* @__PURE__ */ jsx("div", { className: prefixCls("chart__empty"), children: emptyText }) : /* @__PURE__ */ jsx(
|
|
198
|
+
SvgScene,
|
|
199
|
+
{
|
|
200
|
+
nodes: scene,
|
|
201
|
+
width: size.width,
|
|
202
|
+
height: size.height,
|
|
203
|
+
ariaLabel: autoAriaLabel
|
|
204
|
+
}
|
|
205
|
+
),
|
|
206
|
+
/* @__PURE__ */ jsx(
|
|
207
|
+
Tooltip,
|
|
208
|
+
{
|
|
209
|
+
payload: tooltipPayload,
|
|
210
|
+
x: active ? active.x : 0,
|
|
211
|
+
y: active ? active.y - 12 : 0,
|
|
212
|
+
containerWidth: size.width,
|
|
213
|
+
containerHeight: size.height,
|
|
214
|
+
theme,
|
|
215
|
+
config: tooltip
|
|
216
|
+
}
|
|
217
|
+
)
|
|
218
|
+
]
|
|
219
|
+
}
|
|
220
|
+
)
|
|
221
|
+
}
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
export {
|
|
225
|
+
TreeChart
|
|
226
|
+
};
|