@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,8 +1,13 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
|
|
3
|
-
import {
|
|
2
|
+
// src/charts/waterfall-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
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
createBandScale,
|
|
8
|
+
createLinearScale,
|
|
9
|
+
linearTicks
|
|
10
|
+
} from "../../core/scale";
|
|
6
11
|
import { computeLayout, suggestTickCount } from "../../core/layout";
|
|
7
12
|
import { formatNumber } from "../../core/format";
|
|
8
13
|
import { roundedRectPath } from "../../core/shape";
|
|
@@ -12,21 +17,13 @@ import { useElementSize } from "../../hooks/useElementSize";
|
|
|
12
17
|
import { useChartTransition } from "../../hooks/useChartTransition";
|
|
13
18
|
import { resolveAnimation, staggerProgress } from "../../core/animation";
|
|
14
19
|
import { Tooltip } from "../../components/Tooltip";
|
|
15
|
-
import { jsx
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* 瀑布图。
|
|
19
|
-
*
|
|
20
|
-
* 用柱子的「起点 + 终点」表达增减过程,最后落到总计。
|
|
21
|
-
* 与堆叠柱的区别:堆叠柱的每段都从 0 起算的相对量,瀑布图的每一段都是**增量**,
|
|
22
|
-
* 位置取决于此前所有项的累计。
|
|
23
|
-
*/
|
|
24
|
-
export function WaterfallChart({
|
|
20
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
21
|
+
function WaterfallChart({
|
|
25
22
|
data = [],
|
|
26
|
-
width =
|
|
23
|
+
width = "100%",
|
|
27
24
|
height = 320,
|
|
28
25
|
positiveColor,
|
|
29
|
-
negativeColor =
|
|
26
|
+
negativeColor = "#ef4444",
|
|
30
27
|
totalColor,
|
|
31
28
|
connector = true,
|
|
32
29
|
theme: themeInput,
|
|
@@ -36,19 +33,16 @@ export function WaterfallChart({
|
|
|
36
33
|
className,
|
|
37
34
|
style,
|
|
38
35
|
ariaLabel,
|
|
39
|
-
emptyText =
|
|
36
|
+
emptyText = "暂无数据"
|
|
40
37
|
}) {
|
|
41
38
|
const theme = useChartTheme(themeInput, palette);
|
|
42
|
-
const {
|
|
43
|
-
ref,
|
|
44
|
-
size
|
|
45
|
-
} = useElementSize();
|
|
39
|
+
const { ref, size } = useElementSize();
|
|
46
40
|
const [activeIndex, setActiveIndex] = useState(null);
|
|
47
41
|
const rows = useMemo(() => {
|
|
48
42
|
const up = positiveColor ?? colorAt(theme, 0);
|
|
49
43
|
const total = totalColor ?? colorAt(theme, 1);
|
|
50
44
|
let running = 0;
|
|
51
|
-
return data.map(item => {
|
|
45
|
+
return data.map((item) => {
|
|
52
46
|
if (item.isTotal) {
|
|
53
47
|
const row = {
|
|
54
48
|
name: item.name,
|
|
@@ -73,7 +67,8 @@ export function WaterfallChart({
|
|
|
73
67
|
});
|
|
74
68
|
}, [data, positiveColor, negativeColor, totalColor, theme]);
|
|
75
69
|
const domain = useMemo(() => {
|
|
76
|
-
if (!rows.length)
|
|
70
|
+
if (!rows.length)
|
|
71
|
+
return [0, 1];
|
|
77
72
|
let min = 0;
|
|
78
73
|
let max = 0;
|
|
79
74
|
for (const row of rows) {
|
|
@@ -82,43 +77,61 @@ export function WaterfallChart({
|
|
|
82
77
|
}
|
|
83
78
|
return min === max ? [0, max + 1] : [min, max];
|
|
84
79
|
}, [rows]);
|
|
85
|
-
const yTicks = useMemo(
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
const
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
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
|
+
);
|
|
114
126
|
const transition = useChartTransition(valueMatrix, animConfig);
|
|
115
127
|
const progress = transition.progress;
|
|
116
128
|
const scene = useMemo(() => {
|
|
117
|
-
if (!rows.length || plot.width <= 0)
|
|
129
|
+
if (!rows.length || plot.width <= 0)
|
|
130
|
+
return [];
|
|
118
131
|
const nodes = [];
|
|
119
132
|
yTicks.forEach((tick, index) => {
|
|
120
133
|
nodes.push({
|
|
121
|
-
kind:
|
|
134
|
+
kind: "line",
|
|
122
135
|
key: `grid-${index}`,
|
|
123
136
|
x1: plot.x,
|
|
124
137
|
y1: yScale.scale(tick),
|
|
@@ -126,27 +139,25 @@ export function WaterfallChart({
|
|
|
126
139
|
y2: yScale.scale(tick),
|
|
127
140
|
stroke: theme.grid.line,
|
|
128
141
|
strokeWidth: theme.grid.lineWidth,
|
|
129
|
-
strokeDasharray: theme.grid.dash.join(
|
|
142
|
+
strokeDasharray: theme.grid.dash.join(" ") || void 0
|
|
130
143
|
});
|
|
131
144
|
nodes.push({
|
|
132
|
-
kind:
|
|
145
|
+
kind: "text",
|
|
133
146
|
key: `yl-${index}`,
|
|
134
147
|
x: plot.x - theme.axis.tickSize - 4,
|
|
135
148
|
y: yScale.scale(tick),
|
|
136
149
|
text: yLabels[index],
|
|
137
150
|
fill: theme.axis.label,
|
|
138
151
|
fontSize: theme.font.size,
|
|
139
|
-
anchor:
|
|
140
|
-
baseline:
|
|
152
|
+
anchor: "end",
|
|
153
|
+
baseline: "middle",
|
|
141
154
|
fontFamily: theme.font.family
|
|
142
155
|
});
|
|
143
156
|
});
|
|
144
|
-
|
|
145
|
-
// 零基线(负值场景下必须显式画出)
|
|
146
157
|
if (domain[0] < 0) {
|
|
147
158
|
nodes.push({
|
|
148
|
-
kind:
|
|
149
|
-
key:
|
|
159
|
+
kind: "line",
|
|
160
|
+
key: "zero",
|
|
150
161
|
x1: plot.x,
|
|
151
162
|
y1: yScale.scale(0),
|
|
152
163
|
x2: plot.x + plot.width,
|
|
@@ -157,12 +168,18 @@ export function WaterfallChart({
|
|
|
157
168
|
}
|
|
158
169
|
const barWidth = Math.min(xScale.bandWidth, 56);
|
|
159
170
|
rows.forEach((row, index) => {
|
|
171
|
+
var _a, _b;
|
|
160
172
|
const cx = xScale.center(row.name);
|
|
161
|
-
if (cx ===
|
|
162
|
-
|
|
163
|
-
const local = staggerProgress(
|
|
164
|
-
|
|
165
|
-
|
|
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;
|
|
166
183
|
const drawnEnd = animatedStart + (animatedEnd - animatedStart) * local;
|
|
167
184
|
const top = yScale.scale(drawnEnd);
|
|
168
185
|
const bottom = yScale.scale(animatedStart);
|
|
@@ -170,7 +187,7 @@ export function WaterfallChart({
|
|
|
170
187
|
const h = Math.max(2, Math.abs(bottom - top));
|
|
171
188
|
const isActive = activeIndex === index;
|
|
172
189
|
nodes.push({
|
|
173
|
-
kind:
|
|
190
|
+
kind: "path",
|
|
174
191
|
key: `bar-${index}`,
|
|
175
192
|
d: roundedRectPath(cx - barWidth / 2, y, barWidth, h, 3, {
|
|
176
193
|
tl: true,
|
|
@@ -178,17 +195,15 @@ export function WaterfallChart({
|
|
|
178
195
|
}),
|
|
179
196
|
fill: row.color,
|
|
180
197
|
opacity: activeIndex === null || isActive ? 1 : 0.55,
|
|
181
|
-
pointerEvents:
|
|
198
|
+
pointerEvents: "none"
|
|
182
199
|
});
|
|
183
|
-
|
|
184
|
-
// 连接线:从前一根柱的终点水平引到本柱起点
|
|
185
200
|
if (connector && index > 0) {
|
|
186
201
|
const prev = rows[index - 1];
|
|
187
202
|
const prevCx = xScale.center(prev.name);
|
|
188
|
-
if (prevCx !==
|
|
203
|
+
if (prevCx !== void 0) {
|
|
189
204
|
const linkY = yScale.scale(prev.end);
|
|
190
205
|
nodes.push({
|
|
191
|
-
kind:
|
|
206
|
+
kind: "line",
|
|
192
207
|
key: `link-${index}`,
|
|
193
208
|
x1: prevCx + barWidth / 2,
|
|
194
209
|
y1: linkY,
|
|
@@ -196,35 +211,51 @@ export function WaterfallChart({
|
|
|
196
211
|
y2: linkY,
|
|
197
212
|
stroke: theme.axis.line,
|
|
198
213
|
strokeWidth: 1,
|
|
199
|
-
strokeDasharray:
|
|
200
|
-
pointerEvents:
|
|
214
|
+
strokeDasharray: "3 3",
|
|
215
|
+
pointerEvents: "none"
|
|
201
216
|
});
|
|
202
217
|
}
|
|
203
218
|
}
|
|
204
219
|
nodes.push({
|
|
205
|
-
kind:
|
|
220
|
+
kind: "text",
|
|
206
221
|
key: `xlabel-${index}`,
|
|
207
222
|
x: cx,
|
|
208
223
|
y: plot.y + plot.height + theme.axis.tickSize + theme.font.size,
|
|
209
224
|
text: row.name,
|
|
210
225
|
fill: theme.axis.label,
|
|
211
226
|
fontSize: theme.font.size,
|
|
212
|
-
anchor:
|
|
227
|
+
anchor: "middle",
|
|
213
228
|
fontFamily: theme.font.family
|
|
214
229
|
});
|
|
215
230
|
});
|
|
216
231
|
return nodes;
|
|
217
|
-
}, [
|
|
218
|
-
|
|
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) => {
|
|
219
248
|
const element = ref.current;
|
|
220
|
-
if (!element || !rows.length)
|
|
249
|
+
if (!element || !rows.length)
|
|
250
|
+
return null;
|
|
221
251
|
const rect = element.getBoundingClientRect();
|
|
222
252
|
const localX = clientX - rect.left;
|
|
223
253
|
let nearest = null;
|
|
224
254
|
let min = Infinity;
|
|
225
255
|
rows.forEach((row, index) => {
|
|
226
256
|
const cx = xScale.center(row.name);
|
|
227
|
-
if (cx ===
|
|
257
|
+
if (cx === void 0)
|
|
258
|
+
return;
|
|
228
259
|
const distance = Math.abs(cx - localX);
|
|
229
260
|
if (distance < min) {
|
|
230
261
|
min = distance;
|
|
@@ -237,45 +268,58 @@ export function WaterfallChart({
|
|
|
237
268
|
const tooltipPayload = active ? {
|
|
238
269
|
label: active.name,
|
|
239
270
|
row: null,
|
|
240
|
-
series: [
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
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
|
+
]
|
|
247
280
|
} : null;
|
|
248
|
-
const autoAriaLabel = ariaLabel ?? `瀑布图:${rows.map(row => row.name).join(
|
|
249
|
-
return
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
height,
|
|
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
|
-
|
|
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
|
+
};
|
|
@@ -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,50 +1,81 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
|
|
3
|
-
import { classNames, prefixCls } from
|
|
4
|
-
import { jsx
|
|
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
|
-
|
|
40
|
-
|
|
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
|
+
);
|
|
41
59
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
+
};
|