@aura-react-comp/charts 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/charts/area-chart/index.d.ts +2 -2
- package/esm/charts/area-chart/index.js +28 -23
- package/esm/charts/bar-chart/index.d.ts +1 -1
- package/esm/charts/bar-chart/index.js +18 -21
- package/esm/charts/candlestick-chart/index.d.ts +2 -2
- package/esm/charts/candlestick-chart/index.js +243 -180
- package/esm/charts/combo-chart/index.d.ts +1 -1
- package/esm/charts/combo-chart/index.js +9 -20
- package/esm/charts/funnel-chart/index.d.ts +2 -2
- package/esm/charts/funnel-chart/index.js +134 -108
- package/esm/charts/gauge-chart/index.d.ts +1 -1
- package/esm/charts/gauge-chart/index.js +103 -105
- package/esm/charts/graph-chart/index.d.ts +3 -3
- package/esm/charts/graph-chart/index.js +155 -114
- package/esm/charts/heatmap-chart/index.d.ts +2 -2
- package/esm/charts/heatmap-chart/index.js +180 -135
- package/esm/charts/line-chart/index.d.ts +2 -2
- package/esm/charts/line-chart/index.js +29 -24
- package/esm/charts/pie-chart/index.d.ts +2 -2
- package/esm/charts/pie-chart/index.d.ts.map +1 -1
- package/esm/charts/pie-chart/index.js +199 -139
- package/esm/charts/radar-chart/index.d.ts +2 -2
- package/esm/charts/radar-chart/index.d.ts.map +1 -1
- package/esm/charts/radar-chart/index.js +155 -128
- package/esm/charts/ring-progress/index.d.ts +1 -1
- package/esm/charts/ring-progress/index.js +82 -82
- package/esm/charts/sankey-chart/index.d.ts +3 -3
- package/esm/charts/sankey-chart/index.js +172 -141
- package/esm/charts/scatter-chart/index.d.ts +3 -3
- package/esm/charts/scatter-chart/index.d.ts.map +1 -1
- package/esm/charts/scatter-chart/index.js +226 -159
- package/esm/charts/sparkline/index.d.ts +1 -1
- package/esm/charts/sparkline/index.js +82 -66
- package/esm/charts/tree-chart/index.d.ts +3 -3
- package/esm/charts/tree-chart/index.js +129 -102
- package/esm/charts/treemap-chart/index.d.ts +3 -3
- package/esm/charts/treemap-chart/index.js +163 -141
- package/esm/charts/waterfall-chart/index.d.ts +2 -2
- package/esm/charts/waterfall-chart/index.js +166 -121
- package/esm/components/Legend.d.ts +5 -4
- package/esm/components/Legend.d.ts.map +1 -1
- package/esm/components/Legend.js +80 -48
- package/esm/components/Tooltip.d.ts +2 -2
- package/esm/components/Tooltip.js +63 -71
- package/esm/components/chart/index.d.ts +5 -2
- package/esm/components/chart/index.d.ts.map +1 -1
- package/esm/components/chart/index.js +81 -102
- package/esm/components/chart.less +13 -0
- package/esm/core/animation.js +32 -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 +23 -45
- package/esm/core/format.js +49 -52
- package/esm/core/hierarchy.d.ts +1 -1
- package/esm/core/hierarchy.js +61 -92
- package/esm/core/layout.d.ts +1 -1
- package/esm/core/layout.js +33 -50
- package/esm/core/sampling.js +31 -53
- package/esm/core/sankey.js +36 -55
- package/esm/core/scale.js +73 -86
- package/esm/core/shape.js +102 -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.d.ts +6 -5
- package/esm/hooks/useChartTheme.d.ts.map +1 -1
- package/esm/hooks/useChartTheme.js +18 -18
- package/esm/hooks/useChartTransition.d.ts +1 -1
- package/esm/hooks/useChartTransition.js +59 -73
- package/esm/hooks/useElementSize.js +20 -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 +56 -50
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +137 -47
- package/esm/internal/CartesianChart.d.ts +1 -1
- package/esm/internal/CartesianChart.d.ts.map +1 -1
- package/esm/internal/CartesianChart.js +667 -485
- package/esm/internal/model.d.ts +2 -2
- package/esm/internal/model.js +45 -60
- package/esm/scene/canvas.d.ts +1 -1
- package/esm/scene/canvas.js +101 -107
- package/esm/scene/svg.d.ts +1 -1
- package/esm/scene/svg.js +107 -99
- package/esm/scene/types.js +9 -15
- package/esm/style.css +10 -0
- package/esm/theme/index.d.ts +2 -2
- package/esm/theme/index.d.ts.map +1 -1
- package/esm/theme/index.js +145 -170
- package/esm/types.d.ts +7 -3
- package/esm/types.d.ts.map +1 -1
- package/esm/types.js +1 -1
- package/package.json +2 -2
|
@@ -1,7 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
// src/charts/waterfall-chart/index.tsx
|
|
3
|
+
import { useMemo, useState } from "react";
|
|
4
|
+
import { classNames, prefixCls } from "@aura-react-comp/shared";
|
|
3
5
|
import { SvgScene } from "../../scene/svg";
|
|
4
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
createBandScale,
|
|
8
|
+
createLinearScale,
|
|
9
|
+
linearTicks
|
|
10
|
+
} from "../../core/scale";
|
|
5
11
|
import { computeLayout, suggestTickCount } from "../../core/layout";
|
|
6
12
|
import { formatNumber } from "../../core/format";
|
|
7
13
|
import { roundedRectPath } from "../../core/shape";
|
|
@@ -11,21 +17,13 @@ import { useElementSize } from "../../hooks/useElementSize";
|
|
|
11
17
|
import { useChartTransition } from "../../hooks/useChartTransition";
|
|
12
18
|
import { resolveAnimation, staggerProgress } from "../../core/animation";
|
|
13
19
|
import { Tooltip } from "../../components/Tooltip";
|
|
14
|
-
import { jsx
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* 瀑布图。
|
|
18
|
-
*
|
|
19
|
-
* 用柱子的「起点 + 终点」表达增减过程,最后落到总计。
|
|
20
|
-
* 与堆叠柱的区别:堆叠柱的每段都从 0 起算的相对量,瀑布图的每一段都是**增量**,
|
|
21
|
-
* 位置取决于此前所有项的累计。
|
|
22
|
-
*/
|
|
23
|
-
export function WaterfallChart({
|
|
20
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
21
|
+
function WaterfallChart({
|
|
24
22
|
data = [],
|
|
25
|
-
width =
|
|
23
|
+
width = "100%",
|
|
26
24
|
height = 320,
|
|
27
25
|
positiveColor,
|
|
28
|
-
negativeColor =
|
|
26
|
+
negativeColor = "#ef4444",
|
|
29
27
|
totalColor,
|
|
30
28
|
connector = true,
|
|
31
29
|
theme: themeInput,
|
|
@@ -35,19 +33,16 @@ export function WaterfallChart({
|
|
|
35
33
|
className,
|
|
36
34
|
style,
|
|
37
35
|
ariaLabel,
|
|
38
|
-
emptyText =
|
|
36
|
+
emptyText = "暂无数据"
|
|
39
37
|
}) {
|
|
40
38
|
const theme = useChartTheme(themeInput, palette);
|
|
41
|
-
const {
|
|
42
|
-
ref,
|
|
43
|
-
size
|
|
44
|
-
} = useElementSize();
|
|
39
|
+
const { ref, size } = useElementSize();
|
|
45
40
|
const [activeIndex, setActiveIndex] = useState(null);
|
|
46
41
|
const rows = useMemo(() => {
|
|
47
42
|
const up = positiveColor ?? colorAt(theme, 0);
|
|
48
43
|
const total = totalColor ?? colorAt(theme, 1);
|
|
49
44
|
let running = 0;
|
|
50
|
-
return data.map(item => {
|
|
45
|
+
return data.map((item) => {
|
|
51
46
|
if (item.isTotal) {
|
|
52
47
|
const row = {
|
|
53
48
|
name: item.name,
|
|
@@ -72,7 +67,8 @@ export function WaterfallChart({
|
|
|
72
67
|
});
|
|
73
68
|
}, [data, positiveColor, negativeColor, totalColor, theme]);
|
|
74
69
|
const domain = useMemo(() => {
|
|
75
|
-
if (!rows.length)
|
|
70
|
+
if (!rows.length)
|
|
71
|
+
return [0, 1];
|
|
76
72
|
let min = 0;
|
|
77
73
|
let max = 0;
|
|
78
74
|
for (const row of rows) {
|
|
@@ -81,43 +77,61 @@ export function WaterfallChart({
|
|
|
81
77
|
}
|
|
82
78
|
return min === max ? [0, max + 1] : [min, max];
|
|
83
79
|
}, [rows]);
|
|
84
|
-
const yTicks = useMemo(
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
const
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
80
|
+
const yTicks = useMemo(
|
|
81
|
+
() => linearTicks(
|
|
82
|
+
domain[0],
|
|
83
|
+
domain[1],
|
|
84
|
+
suggestTickCount(Math.max(60, height - 48))
|
|
85
|
+
),
|
|
86
|
+
[domain, height]
|
|
87
|
+
);
|
|
88
|
+
const yLabels = useMemo(
|
|
89
|
+
() => yTicks.map((tick) => formatNumber(tick)),
|
|
90
|
+
[yTicks]
|
|
91
|
+
);
|
|
92
|
+
const layout = useMemo(
|
|
93
|
+
() => computeLayout({
|
|
94
|
+
width: Math.max(size.width, 0),
|
|
95
|
+
height: Math.max(size.height, 0),
|
|
96
|
+
yLabels,
|
|
97
|
+
xLabels: rows.map((row) => row.name),
|
|
98
|
+
theme
|
|
99
|
+
}),
|
|
100
|
+
[size.width, size.height, yLabels, rows, theme]
|
|
101
|
+
);
|
|
102
|
+
const { plot } = layout;
|
|
103
|
+
const xScale = useMemo(
|
|
104
|
+
() => createBandScale({
|
|
105
|
+
domain: rows.map((row) => row.name),
|
|
106
|
+
range: [plot.x, plot.x + plot.width],
|
|
107
|
+
paddingInner: 0.36,
|
|
108
|
+
paddingOuter: 0.12
|
|
109
|
+
}),
|
|
110
|
+
[rows, plot.x, plot.width]
|
|
111
|
+
);
|
|
112
|
+
const yScale = useMemo(
|
|
113
|
+
() => createLinearScale({ domain, range: [plot.y + plot.height, plot.y] }),
|
|
114
|
+
[domain, plot.y, plot.height]
|
|
115
|
+
);
|
|
116
|
+
const animKey = typeof animation === "object" ? JSON.stringify(animation) : String(animation);
|
|
117
|
+
const animConfig = useMemo(
|
|
118
|
+
() => resolveAnimation(animation),
|
|
119
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
120
|
+
[animKey]
|
|
121
|
+
);
|
|
122
|
+
const valueMatrix = useMemo(
|
|
123
|
+
() => rows.map((row) => [row.start, row.end]),
|
|
124
|
+
[rows]
|
|
125
|
+
);
|
|
113
126
|
const transition = useChartTransition(valueMatrix, animConfig);
|
|
114
127
|
const progress = transition.progress;
|
|
115
128
|
const scene = useMemo(() => {
|
|
116
|
-
if (!rows.length || plot.width <= 0)
|
|
129
|
+
if (!rows.length || plot.width <= 0)
|
|
130
|
+
return [];
|
|
117
131
|
const nodes = [];
|
|
118
132
|
yTicks.forEach((tick, index) => {
|
|
119
133
|
nodes.push({
|
|
120
|
-
kind:
|
|
134
|
+
kind: "line",
|
|
121
135
|
key: `grid-${index}`,
|
|
122
136
|
x1: plot.x,
|
|
123
137
|
y1: yScale.scale(tick),
|
|
@@ -125,27 +139,25 @@ export function WaterfallChart({
|
|
|
125
139
|
y2: yScale.scale(tick),
|
|
126
140
|
stroke: theme.grid.line,
|
|
127
141
|
strokeWidth: theme.grid.lineWidth,
|
|
128
|
-
strokeDasharray: theme.grid.dash.join(
|
|
142
|
+
strokeDasharray: theme.grid.dash.join(" ") || void 0
|
|
129
143
|
});
|
|
130
144
|
nodes.push({
|
|
131
|
-
kind:
|
|
145
|
+
kind: "text",
|
|
132
146
|
key: `yl-${index}`,
|
|
133
147
|
x: plot.x - theme.axis.tickSize - 4,
|
|
134
148
|
y: yScale.scale(tick),
|
|
135
149
|
text: yLabels[index],
|
|
136
150
|
fill: theme.axis.label,
|
|
137
151
|
fontSize: theme.font.size,
|
|
138
|
-
anchor:
|
|
139
|
-
baseline:
|
|
152
|
+
anchor: "end",
|
|
153
|
+
baseline: "middle",
|
|
140
154
|
fontFamily: theme.font.family
|
|
141
155
|
});
|
|
142
156
|
});
|
|
143
|
-
|
|
144
|
-
// 零基线(负值场景下必须显式画出)
|
|
145
157
|
if (domain[0] < 0) {
|
|
146
158
|
nodes.push({
|
|
147
|
-
kind:
|
|
148
|
-
key:
|
|
159
|
+
kind: "line",
|
|
160
|
+
key: "zero",
|
|
149
161
|
x1: plot.x,
|
|
150
162
|
y1: yScale.scale(0),
|
|
151
163
|
x2: plot.x + plot.width,
|
|
@@ -156,12 +168,18 @@ export function WaterfallChart({
|
|
|
156
168
|
}
|
|
157
169
|
const barWidth = Math.min(xScale.bandWidth, 56);
|
|
158
170
|
rows.forEach((row, index) => {
|
|
171
|
+
var _a, _b;
|
|
159
172
|
const cx = xScale.center(row.name);
|
|
160
|
-
if (cx ===
|
|
161
|
-
|
|
162
|
-
const local = staggerProgress(
|
|
163
|
-
|
|
164
|
-
|
|
173
|
+
if (cx === void 0)
|
|
174
|
+
return;
|
|
175
|
+
const local = staggerProgress(
|
|
176
|
+
progress,
|
|
177
|
+
index,
|
|
178
|
+
rows.length,
|
|
179
|
+
animConfig.stagger
|
|
180
|
+
);
|
|
181
|
+
const animatedStart = ((_a = transition.values[index]) == null ? void 0 : _a[0]) ?? row.start;
|
|
182
|
+
const animatedEnd = ((_b = transition.values[index]) == null ? void 0 : _b[1]) ?? row.end;
|
|
165
183
|
const drawnEnd = animatedStart + (animatedEnd - animatedStart) * local;
|
|
166
184
|
const top = yScale.scale(drawnEnd);
|
|
167
185
|
const bottom = yScale.scale(animatedStart);
|
|
@@ -169,7 +187,7 @@ export function WaterfallChart({
|
|
|
169
187
|
const h = Math.max(2, Math.abs(bottom - top));
|
|
170
188
|
const isActive = activeIndex === index;
|
|
171
189
|
nodes.push({
|
|
172
|
-
kind:
|
|
190
|
+
kind: "path",
|
|
173
191
|
key: `bar-${index}`,
|
|
174
192
|
d: roundedRectPath(cx - barWidth / 2, y, barWidth, h, 3, {
|
|
175
193
|
tl: true,
|
|
@@ -177,17 +195,15 @@ export function WaterfallChart({
|
|
|
177
195
|
}),
|
|
178
196
|
fill: row.color,
|
|
179
197
|
opacity: activeIndex === null || isActive ? 1 : 0.55,
|
|
180
|
-
pointerEvents:
|
|
198
|
+
pointerEvents: "none"
|
|
181
199
|
});
|
|
182
|
-
|
|
183
|
-
// 连接线:从前一根柱的终点水平引到本柱起点
|
|
184
200
|
if (connector && index > 0) {
|
|
185
201
|
const prev = rows[index - 1];
|
|
186
202
|
const prevCx = xScale.center(prev.name);
|
|
187
|
-
if (prevCx !==
|
|
203
|
+
if (prevCx !== void 0) {
|
|
188
204
|
const linkY = yScale.scale(prev.end);
|
|
189
205
|
nodes.push({
|
|
190
|
-
kind:
|
|
206
|
+
kind: "line",
|
|
191
207
|
key: `link-${index}`,
|
|
192
208
|
x1: prevCx + barWidth / 2,
|
|
193
209
|
y1: linkY,
|
|
@@ -195,35 +211,51 @@ export function WaterfallChart({
|
|
|
195
211
|
y2: linkY,
|
|
196
212
|
stroke: theme.axis.line,
|
|
197
213
|
strokeWidth: 1,
|
|
198
|
-
strokeDasharray:
|
|
199
|
-
pointerEvents:
|
|
214
|
+
strokeDasharray: "3 3",
|
|
215
|
+
pointerEvents: "none"
|
|
200
216
|
});
|
|
201
217
|
}
|
|
202
218
|
}
|
|
203
219
|
nodes.push({
|
|
204
|
-
kind:
|
|
220
|
+
kind: "text",
|
|
205
221
|
key: `xlabel-${index}`,
|
|
206
222
|
x: cx,
|
|
207
223
|
y: plot.y + plot.height + theme.axis.tickSize + theme.font.size,
|
|
208
224
|
text: row.name,
|
|
209
225
|
fill: theme.axis.label,
|
|
210
226
|
fontSize: theme.font.size,
|
|
211
|
-
anchor:
|
|
227
|
+
anchor: "middle",
|
|
212
228
|
fontFamily: theme.font.family
|
|
213
229
|
});
|
|
214
230
|
});
|
|
215
231
|
return nodes;
|
|
216
|
-
}, [
|
|
217
|
-
|
|
232
|
+
}, [
|
|
233
|
+
rows,
|
|
234
|
+
plot,
|
|
235
|
+
yTicks,
|
|
236
|
+
yLabels,
|
|
237
|
+
yScale,
|
|
238
|
+
xScale,
|
|
239
|
+
theme,
|
|
240
|
+
progress,
|
|
241
|
+
activeIndex,
|
|
242
|
+
domain,
|
|
243
|
+
connector,
|
|
244
|
+
transition.values,
|
|
245
|
+
animConfig.stagger
|
|
246
|
+
]);
|
|
247
|
+
const indexFromPointer = (clientX) => {
|
|
218
248
|
const element = ref.current;
|
|
219
|
-
if (!element || !rows.length)
|
|
249
|
+
if (!element || !rows.length)
|
|
250
|
+
return null;
|
|
220
251
|
const rect = element.getBoundingClientRect();
|
|
221
252
|
const localX = clientX - rect.left;
|
|
222
253
|
let nearest = null;
|
|
223
254
|
let min = Infinity;
|
|
224
255
|
rows.forEach((row, index) => {
|
|
225
256
|
const cx = xScale.center(row.name);
|
|
226
|
-
if (cx ===
|
|
257
|
+
if (cx === void 0)
|
|
258
|
+
return;
|
|
227
259
|
const distance = Math.abs(cx - localX);
|
|
228
260
|
if (distance < min) {
|
|
229
261
|
min = distance;
|
|
@@ -236,45 +268,58 @@ export function WaterfallChart({
|
|
|
236
268
|
const tooltipPayload = active ? {
|
|
237
269
|
label: active.name,
|
|
238
270
|
row: null,
|
|
239
|
-
series: [
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
271
|
+
series: [
|
|
272
|
+
{
|
|
273
|
+
key: active.name,
|
|
274
|
+
name: active.isTotal ? "累计" : "增减",
|
|
275
|
+
color: active.color,
|
|
276
|
+
value: active.isTotal ? active.end : active.value,
|
|
277
|
+
formatted: formatNumber(active.isTotal ? active.end : active.value)
|
|
278
|
+
}
|
|
279
|
+
]
|
|
246
280
|
} : null;
|
|
247
|
-
const autoAriaLabel = ariaLabel ?? `瀑布图:${rows.map(row => row.name).join(
|
|
248
|
-
return
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
height,
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
+
const autoAriaLabel = ariaLabel ?? `瀑布图:${rows.map((row) => row.name).join("、")}`;
|
|
282
|
+
return /* @__PURE__ */ jsx(
|
|
283
|
+
"div",
|
|
284
|
+
{
|
|
285
|
+
className: classNames(prefixCls("chart"), className),
|
|
286
|
+
style: { width, height, ...style },
|
|
287
|
+
"data-aura-chart": "waterfall",
|
|
288
|
+
children: /* @__PURE__ */ jsxs(
|
|
289
|
+
"div",
|
|
290
|
+
{
|
|
291
|
+
ref,
|
|
292
|
+
className: prefixCls("chart__plot"),
|
|
293
|
+
onPointerMove: (event) => setActiveIndex(indexFromPointer(event.clientX)),
|
|
294
|
+
onPointerLeave: () => setActiveIndex(null),
|
|
295
|
+
children: [
|
|
296
|
+
rows.length === 0 || size.width === 0 ? /* @__PURE__ */ jsx("div", { className: prefixCls("chart__empty"), children: emptyText }) : /* @__PURE__ */ jsx(
|
|
297
|
+
SvgScene,
|
|
298
|
+
{
|
|
299
|
+
nodes: scene,
|
|
300
|
+
width: size.width,
|
|
301
|
+
height: size.height,
|
|
302
|
+
ariaLabel: autoAriaLabel
|
|
303
|
+
}
|
|
304
|
+
),
|
|
305
|
+
/* @__PURE__ */ jsx(
|
|
306
|
+
Tooltip,
|
|
307
|
+
{
|
|
308
|
+
payload: tooltipPayload,
|
|
309
|
+
x: active ? xScale.center(active.name) ?? 0 : 0,
|
|
310
|
+
y: active ? yScale.scale(Math.max(active.start, active.end)) - 10 : 0,
|
|
311
|
+
containerWidth: size.width,
|
|
312
|
+
containerHeight: size.height,
|
|
313
|
+
theme,
|
|
314
|
+
config: tooltip
|
|
315
|
+
}
|
|
316
|
+
)
|
|
317
|
+
]
|
|
318
|
+
}
|
|
319
|
+
)
|
|
320
|
+
}
|
|
321
|
+
);
|
|
322
|
+
}
|
|
323
|
+
export {
|
|
324
|
+
WaterfallChart
|
|
325
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import type { ChartTheme } from '../theme';
|
|
3
|
-
import type { LegendConfig } from '../types';
|
|
2
|
+
import type { ChartTheme } from '../theme/index.js';
|
|
3
|
+
import type { LegendConfig } from '../types.js';
|
|
4
4
|
export interface LegendItem {
|
|
5
5
|
key: string;
|
|
6
6
|
name: string;
|
|
@@ -11,13 +11,14 @@ export interface LegendProps {
|
|
|
11
11
|
items: LegendItem[];
|
|
12
12
|
theme: ChartTheme;
|
|
13
13
|
config?: boolean | LegendConfig;
|
|
14
|
-
|
|
14
|
+
/** 点击切换系列显隐回调;未传或 selectable=false 时仅作静态展示 */
|
|
15
|
+
onToggle?: (key: string) => void;
|
|
15
16
|
}
|
|
16
17
|
/**
|
|
17
18
|
* 图例。
|
|
18
19
|
*
|
|
19
20
|
* 刻意用 DOM 而不是画进 SVG:
|
|
20
|
-
* ·
|
|
21
|
+
* · 可筛选时用原生 button,键盘可达、可聚焦,天然符合无障碍要求;
|
|
21
22
|
* · 换行、省略号交给 CSS,省去手写文本换行计算。
|
|
22
23
|
*/
|
|
23
24
|
export declare function Legend({ items, theme, config, onToggle }: LegendProps): React.JSX.Element | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Legend.d.ts","sourceRoot":"","sources":["Legend.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAE7C,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,UAAU,EAAE,CAAC;IACpB,KAAK,EAAE,UAAU,CAAC;IAClB,MAAM,CAAC,EAAE,OAAO,GAAG,YAAY,CAAC;IAChC,QAAQ,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"Legend.d.ts","sourceRoot":"","sources":["Legend.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAE7C,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,UAAU,EAAE,CAAC;IACpB,KAAK,EAAE,UAAU,CAAC;IAClB,MAAM,CAAC,EAAE,OAAO,GAAG,YAAY,CAAC;IAChC,8CAA8C;IAC9C,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;CAClC;AAED;;;;;;GAMG;AACH,wBAAgB,MAAM,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,WAAW,4BA2ErE"}
|
package/esm/components/Legend.js
CHANGED
|
@@ -1,49 +1,81 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
// src/components/Legend.tsx
|
|
3
|
+
import { classNames, prefixCls } from "@aura-react-comp/shared";
|
|
4
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
function Legend({ items, theme, config, onToggle }) {
|
|
6
|
+
if (config === false || items.length === 0)
|
|
7
|
+
return null;
|
|
8
|
+
const options = typeof config === "object" ? config : {};
|
|
9
|
+
const { position = "top", align = "left", selectable = true } = options;
|
|
10
|
+
if (options.show === false)
|
|
11
|
+
return null;
|
|
12
|
+
const interactive = selectable !== false && Boolean(onToggle);
|
|
13
|
+
return /* @__PURE__ */ jsx(
|
|
14
|
+
"div",
|
|
15
|
+
{
|
|
16
|
+
className: classNames(
|
|
17
|
+
prefixCls("chart__legend"),
|
|
18
|
+
position === "bottom" && prefixCls("chart__legend--bottom"),
|
|
19
|
+
align !== "left" && prefixCls(`chart__legend--${align}`)
|
|
20
|
+
),
|
|
21
|
+
role: "group",
|
|
22
|
+
"aria-label": "图例",
|
|
23
|
+
children: items.map((item) => {
|
|
24
|
+
const content = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
25
|
+
/* @__PURE__ */ jsx(
|
|
26
|
+
"span",
|
|
27
|
+
{
|
|
28
|
+
className: prefixCls("chart__legend-dot"),
|
|
29
|
+
style: {
|
|
30
|
+
background: item.color,
|
|
31
|
+
opacity: item.visible ? 1 : 0.45
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
),
|
|
35
|
+
/* @__PURE__ */ jsx(
|
|
36
|
+
"span",
|
|
37
|
+
{
|
|
38
|
+
className: prefixCls("chart__legend-text"),
|
|
39
|
+
style: {
|
|
40
|
+
color: item.visible ? theme.legend.text : theme.legend.textInactive
|
|
41
|
+
},
|
|
42
|
+
children: item.name
|
|
43
|
+
}
|
|
44
|
+
)
|
|
45
|
+
] });
|
|
46
|
+
if (!interactive) {
|
|
47
|
+
return /* @__PURE__ */ jsx(
|
|
48
|
+
"span",
|
|
49
|
+
{
|
|
50
|
+
className: classNames(
|
|
51
|
+
prefixCls("chart__legend-item"),
|
|
52
|
+
prefixCls("chart__legend-item--static"),
|
|
53
|
+
!item.visible && prefixCls("chart__legend-item--inactive")
|
|
54
|
+
),
|
|
55
|
+
children: content
|
|
56
|
+
},
|
|
57
|
+
item.key
|
|
58
|
+
);
|
|
40
59
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
60
|
+
return /* @__PURE__ */ jsx(
|
|
61
|
+
"button",
|
|
62
|
+
{
|
|
63
|
+
type: "button",
|
|
64
|
+
className: classNames(
|
|
65
|
+
prefixCls("chart__legend-item"),
|
|
66
|
+
!item.visible && prefixCls("chart__legend-item--inactive")
|
|
67
|
+
),
|
|
68
|
+
"aria-pressed": item.visible,
|
|
69
|
+
title: `${item.visible ? "隐藏" : "显示"} ${item.name}`,
|
|
70
|
+
onClick: () => onToggle == null ? void 0 : onToggle(item.key),
|
|
71
|
+
children: content
|
|
72
|
+
},
|
|
73
|
+
item.key
|
|
74
|
+
);
|
|
75
|
+
})
|
|
76
|
+
}
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
export {
|
|
80
|
+
Legend
|
|
81
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import type { ChartTheme } from '../theme';
|
|
3
|
-
import type { TooltipConfig, TooltipPayload } from '../types';
|
|
2
|
+
import type { ChartTheme } from '../theme/index.js';
|
|
3
|
+
import type { TooltipConfig, TooltipPayload } from '../types.js';
|
|
4
4
|
export interface TooltipProps {
|
|
5
5
|
payload: TooltipPayload | null;
|
|
6
6
|
/** 相对容器的像素位置 */
|