@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,5 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
// src/charts/heatmap-chart/index.tsx
|
|
3
|
+
import { useCallback, useMemo, useState } from "react";
|
|
4
|
+
import { classNames, prefixCls } from "@aura-react-comp/shared";
|
|
3
5
|
import { SvgScene } from "../../scene/svg";
|
|
4
6
|
import { createBandScale } from "../../core/scale";
|
|
5
7
|
import { formatNumber, estimateTextWidth } from "../../core/format";
|
|
@@ -10,32 +12,21 @@ import { useElementSize } from "../../hooks/useElementSize";
|
|
|
10
12
|
import { useChartTransition } from "../../hooks/useChartTransition";
|
|
11
13
|
import { resolveAnimation, staggerProgress } from "../../core/animation";
|
|
12
14
|
import { Tooltip } from "../../components/Tooltip";
|
|
13
|
-
import { jsx
|
|
14
|
-
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
15
|
-
/** 把数值映射到 0~1 的位置;全等值时统一给 0.6,避免整片同色看不清边界 */
|
|
15
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
16
16
|
function normalize(value, min, max) {
|
|
17
|
-
if (max === min)
|
|
17
|
+
if (max === min)
|
|
18
|
+
return 0.6;
|
|
18
19
|
return (value - min) / (max - min);
|
|
19
20
|
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* 热力图。
|
|
23
|
-
*
|
|
24
|
-
* 用颜色深浅编码二维矩阵里的数值,密度远高于逐格标数字,
|
|
25
|
-
* 适合「一眼看出哪块热」——访问时段分布、地域 × 品类销量、相关性矩阵。
|
|
26
|
-
*
|
|
27
|
-
* 注意:颜色编码的精度低于长度/位置(这是视觉感知的固有限制),
|
|
28
|
-
* 需要读出准确数值时必须配合 tooltip 或数字。
|
|
29
|
-
*/
|
|
30
|
-
export function HeatmapChart({
|
|
21
|
+
function HeatmapChart({
|
|
31
22
|
data = [],
|
|
32
23
|
xLabels: xLabelsProp,
|
|
33
24
|
yLabels: yLabelsProp,
|
|
34
25
|
colorRange,
|
|
35
|
-
showValue =
|
|
26
|
+
showValue = "auto",
|
|
36
27
|
cellGap = 3,
|
|
37
28
|
cellRadius = 3,
|
|
38
|
-
width =
|
|
29
|
+
width = "100%",
|
|
39
30
|
height = 320,
|
|
40
31
|
theme: themeInput,
|
|
41
32
|
palette,
|
|
@@ -44,33 +35,31 @@ export function HeatmapChart({
|
|
|
44
35
|
className,
|
|
45
36
|
style,
|
|
46
37
|
ariaLabel,
|
|
47
|
-
emptyText =
|
|
38
|
+
emptyText = "暂无数据"
|
|
48
39
|
}) {
|
|
49
40
|
const theme = useChartTheme(themeInput, palette);
|
|
50
|
-
const {
|
|
51
|
-
ref,
|
|
52
|
-
size
|
|
53
|
-
} = useElementSize();
|
|
41
|
+
const { ref, size } = useElementSize();
|
|
54
42
|
const [activeCell, setActiveCell] = useState(null);
|
|
55
|
-
const animKey = typeof animation ===
|
|
56
|
-
const animConfig = useMemo(
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
} = useMemo(() => {
|
|
65
|
-
const xs = xLabelsProp?.length ? xLabelsProp : [];
|
|
66
|
-
const ys = yLabelsProp?.length ? yLabelsProp : [];
|
|
43
|
+
const animKey = typeof animation === "object" ? JSON.stringify(animation) : String(animation);
|
|
44
|
+
const animConfig = useMemo(
|
|
45
|
+
() => resolveAnimation(animation),
|
|
46
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
47
|
+
[animKey]
|
|
48
|
+
);
|
|
49
|
+
const { xLabels, yLabels, lookup, range } = useMemo(() => {
|
|
50
|
+
const xs = (xLabelsProp == null ? void 0 : xLabelsProp.length) ? xLabelsProp : [];
|
|
51
|
+
const ys = (yLabelsProp == null ? void 0 : yLabelsProp.length) ? yLabelsProp : [];
|
|
67
52
|
if (!xs.length) {
|
|
68
|
-
for (const cell of data)
|
|
53
|
+
for (const cell of data)
|
|
54
|
+
if (!xs.includes(cell.x))
|
|
55
|
+
xs.push(cell.x);
|
|
69
56
|
}
|
|
70
57
|
if (!ys.length) {
|
|
71
|
-
for (const cell of data)
|
|
58
|
+
for (const cell of data)
|
|
59
|
+
if (!ys.includes(cell.y))
|
|
60
|
+
ys.push(cell.y);
|
|
72
61
|
}
|
|
73
|
-
const map = new Map();
|
|
62
|
+
const map = /* @__PURE__ */ new Map();
|
|
74
63
|
let min = Number.POSITIVE_INFINITY;
|
|
75
64
|
let max = Number.NEGATIVE_INFINITY;
|
|
76
65
|
for (const cell of data) {
|
|
@@ -84,19 +73,28 @@ export function HeatmapChart({
|
|
|
84
73
|
xLabels: xs,
|
|
85
74
|
yLabels: ys,
|
|
86
75
|
lookup: map,
|
|
87
|
-
range: [
|
|
76
|
+
range: [
|
|
77
|
+
Number.isFinite(min) ? min : 0,
|
|
78
|
+
Number.isFinite(max) ? max : 1
|
|
79
|
+
]
|
|
88
80
|
};
|
|
89
81
|
}, [data, xLabelsProp, yLabelsProp]);
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
82
|
+
const matrix = useMemo(
|
|
83
|
+
() => yLabels.map(
|
|
84
|
+
(y) => xLabels.map((x) => {
|
|
85
|
+
const value = lookup.get(`${x}__${y}`);
|
|
86
|
+
return value === void 0 ? null : value;
|
|
87
|
+
})
|
|
88
|
+
),
|
|
89
|
+
[xLabels, yLabels, lookup]
|
|
90
|
+
);
|
|
96
91
|
const transition = useChartTransition(matrix, animConfig);
|
|
97
92
|
const progress = transition.progress;
|
|
98
93
|
const geometry = useMemo(() => {
|
|
99
|
-
const labelWidth = Math.max(
|
|
94
|
+
const labelWidth = Math.max(
|
|
95
|
+
0,
|
|
96
|
+
...yLabels.map((label) => estimateTextWidth(label, theme.font.size))
|
|
97
|
+
);
|
|
100
98
|
const left = Math.ceil(labelWidth) + 8;
|
|
101
99
|
const top = 8;
|
|
102
100
|
const bottom = theme.font.size + 12;
|
|
@@ -110,48 +108,61 @@ export function HeatmapChart({
|
|
|
110
108
|
plotHeight: Math.max(0, size.height - top - bottom)
|
|
111
109
|
};
|
|
112
110
|
}, [yLabels, size.width, size.height, theme.font.size]);
|
|
113
|
-
const xScale = useMemo(
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
111
|
+
const xScale = useMemo(
|
|
112
|
+
() => createBandScale({
|
|
113
|
+
domain: xLabels,
|
|
114
|
+
range: [geometry.left, geometry.left + geometry.plotWidth],
|
|
115
|
+
paddingInner: 0,
|
|
116
|
+
paddingOuter: 0
|
|
117
|
+
}),
|
|
118
|
+
[xLabels, geometry.left, geometry.plotWidth]
|
|
119
|
+
);
|
|
119
120
|
const rowHeight = yLabels.length > 0 ? geometry.plotHeight / yLabels.length : 0;
|
|
120
|
-
const colorAt = useCallback(
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
121
|
+
const colorAt = useCallback(
|
|
122
|
+
(value) => {
|
|
123
|
+
const from = (colorRange == null ? void 0 : colorRange[0]) ?? withAlpha(theme.emphasis, 0.08);
|
|
124
|
+
const to = (colorRange == null ? void 0 : colorRange[1]) ?? theme.emphasis;
|
|
125
|
+
return mixColor(from, to, normalize(value, range[0], range[1]));
|
|
126
|
+
},
|
|
127
|
+
[colorRange, theme.emphasis, range]
|
|
128
|
+
);
|
|
125
129
|
const cellSize = Math.max(0, xScale.step - cellGap);
|
|
126
|
-
const showNumbers = showValue === true || showValue ===
|
|
130
|
+
const showNumbers = showValue === true || showValue === "auto" && cellSize >= 42 && rowHeight >= 24;
|
|
127
131
|
const scene = useMemo(() => {
|
|
128
|
-
if (!xLabels.length || !yLabels.length || geometry.plotWidth <= 0)
|
|
132
|
+
if (!xLabels.length || !yLabels.length || geometry.plotWidth <= 0)
|
|
133
|
+
return [];
|
|
129
134
|
const nodes = [];
|
|
130
135
|
const total = yLabels.length * xLabels.length;
|
|
131
136
|
yLabels.forEach((yLabel, rowIndex) => {
|
|
132
137
|
const y = geometry.top + rowIndex * rowHeight;
|
|
133
138
|
nodes.push({
|
|
134
|
-
kind:
|
|
139
|
+
kind: "text",
|
|
135
140
|
key: `yl-${yLabel}`,
|
|
136
141
|
x: geometry.left - 8,
|
|
137
142
|
y: y + rowHeight / 2,
|
|
138
143
|
text: yLabel,
|
|
139
144
|
fill: theme.axis.label,
|
|
140
145
|
fontSize: theme.font.size,
|
|
141
|
-
anchor:
|
|
142
|
-
baseline:
|
|
146
|
+
anchor: "end",
|
|
147
|
+
baseline: "middle",
|
|
143
148
|
fontFamily: theme.font.family
|
|
144
149
|
});
|
|
145
150
|
xLabels.forEach((xLabel, columnIndex) => {
|
|
151
|
+
var _a;
|
|
146
152
|
const x = xScale.scale(xLabel);
|
|
147
|
-
if (x ===
|
|
148
|
-
|
|
153
|
+
if (x === void 0)
|
|
154
|
+
return;
|
|
155
|
+
const raw = ((_a = transition.values[rowIndex]) == null ? void 0 : _a[columnIndex]) ?? null;
|
|
149
156
|
const flatIndex = rowIndex * xLabels.length + columnIndex;
|
|
150
|
-
const local = staggerProgress(
|
|
157
|
+
const local = staggerProgress(
|
|
158
|
+
progress,
|
|
159
|
+
flatIndex,
|
|
160
|
+
total,
|
|
161
|
+
animConfig.stagger
|
|
162
|
+
);
|
|
151
163
|
if (raw === null) {
|
|
152
|
-
// 缺失格:画一个极浅的底,让矩阵结构仍然完整
|
|
153
164
|
nodes.push({
|
|
154
|
-
kind:
|
|
165
|
+
kind: "rect",
|
|
155
166
|
key: `empty-${xLabel}-${yLabel}`,
|
|
156
167
|
x: x + cellGap / 2,
|
|
157
168
|
y: y + cellGap / 2,
|
|
@@ -160,121 +171,155 @@ export function HeatmapChart({
|
|
|
160
171
|
radius: cellRadius,
|
|
161
172
|
fill: withAlpha(theme.axis.line, 0.35),
|
|
162
173
|
opacity: local,
|
|
163
|
-
pointerEvents:
|
|
174
|
+
pointerEvents: "none"
|
|
164
175
|
});
|
|
165
176
|
return;
|
|
166
177
|
}
|
|
167
|
-
const isActive = activeCell
|
|
178
|
+
const isActive = (activeCell == null ? void 0 : activeCell.x) === xLabel && (activeCell == null ? void 0 : activeCell.y) === yLabel;
|
|
168
179
|
nodes.push({
|
|
169
|
-
kind:
|
|
180
|
+
kind: "path",
|
|
170
181
|
key: `cell-${xLabel}-${yLabel}`,
|
|
171
|
-
d: roundedRectPath(
|
|
182
|
+
d: roundedRectPath(
|
|
183
|
+
x + cellGap / 2,
|
|
184
|
+
y + cellGap / 2,
|
|
185
|
+
cellSize,
|
|
186
|
+
Math.max(0, rowHeight - cellGap),
|
|
187
|
+
cellRadius
|
|
188
|
+
),
|
|
172
189
|
fill: colorAt(raw),
|
|
173
|
-
stroke: isActive ? theme.text.primary :
|
|
190
|
+
stroke: isActive ? theme.text.primary : void 0,
|
|
174
191
|
strokeWidth: isActive ? 1.5 : 0,
|
|
175
192
|
opacity: local,
|
|
176
|
-
pointerEvents:
|
|
193
|
+
pointerEvents: "none"
|
|
177
194
|
});
|
|
178
195
|
if (showNumbers) {
|
|
179
|
-
// 深色格子用白字,浅色用深字,保证可读
|
|
180
196
|
const ratio = normalize(raw, range[0], range[1]);
|
|
181
197
|
nodes.push({
|
|
182
|
-
kind:
|
|
198
|
+
kind: "text",
|
|
183
199
|
key: `cell-value-${xLabel}-${yLabel}`,
|
|
184
200
|
x: x + xScale.step / 2,
|
|
185
201
|
y: y + rowHeight / 2,
|
|
186
202
|
text: formatNumber(raw),
|
|
187
|
-
fill: ratio > 0.55 ?
|
|
203
|
+
fill: ratio > 0.55 ? "#fff" : theme.text.primary,
|
|
188
204
|
fontSize: theme.font.sizeSmall,
|
|
189
|
-
anchor:
|
|
190
|
-
baseline:
|
|
205
|
+
anchor: "middle",
|
|
206
|
+
baseline: "middle",
|
|
191
207
|
opacity: local,
|
|
192
208
|
fontFamily: theme.font.family
|
|
193
209
|
});
|
|
194
210
|
}
|
|
195
211
|
});
|
|
196
212
|
});
|
|
197
|
-
|
|
198
|
-
// 横轴标签
|
|
199
|
-
xLabels.forEach(xLabel => {
|
|
213
|
+
xLabels.forEach((xLabel) => {
|
|
200
214
|
const x = xScale.scale(xLabel);
|
|
201
|
-
if (x ===
|
|
215
|
+
if (x === void 0)
|
|
216
|
+
return;
|
|
202
217
|
nodes.push({
|
|
203
|
-
kind:
|
|
218
|
+
kind: "text",
|
|
204
219
|
key: `xl-${xLabel}`,
|
|
205
220
|
x: x + xScale.step / 2,
|
|
206
221
|
y: geometry.top + geometry.plotHeight + theme.font.size + 4,
|
|
207
222
|
text: xLabel,
|
|
208
223
|
fill: theme.axis.label,
|
|
209
224
|
fontSize: theme.font.size,
|
|
210
|
-
anchor:
|
|
225
|
+
anchor: "middle",
|
|
211
226
|
fontFamily: theme.font.family
|
|
212
227
|
});
|
|
213
228
|
});
|
|
214
229
|
return nodes;
|
|
215
|
-
}, [
|
|
230
|
+
}, [
|
|
231
|
+
xLabels,
|
|
232
|
+
yLabels,
|
|
233
|
+
geometry,
|
|
234
|
+
rowHeight,
|
|
235
|
+
xScale,
|
|
236
|
+
cellSize,
|
|
237
|
+
cellGap,
|
|
238
|
+
cellRadius,
|
|
239
|
+
theme,
|
|
240
|
+
transition.values,
|
|
241
|
+
progress,
|
|
242
|
+
animConfig.stagger,
|
|
243
|
+
range,
|
|
244
|
+
showNumbers,
|
|
245
|
+
activeCell,
|
|
246
|
+
colorAt
|
|
247
|
+
]);
|
|
216
248
|
const cellFromPointer = (clientX, clientY) => {
|
|
217
249
|
const element = ref.current;
|
|
218
|
-
if (!element || xScale.step <= 0 || rowHeight <= 0)
|
|
250
|
+
if (!element || xScale.step <= 0 || rowHeight <= 0)
|
|
251
|
+
return null;
|
|
219
252
|
const rect = element.getBoundingClientRect();
|
|
220
253
|
const localX = clientX - rect.left - geometry.left;
|
|
221
254
|
const localY = clientY - rect.top - geometry.top;
|
|
222
|
-
if (localX < 0 || localY < 0)
|
|
255
|
+
if (localX < 0 || localY < 0)
|
|
256
|
+
return null;
|
|
223
257
|
const column = Math.floor(localX / xScale.step);
|
|
224
258
|
const row = Math.floor(localY / rowHeight);
|
|
225
259
|
const x = xLabels[column];
|
|
226
260
|
const y = yLabels[row];
|
|
227
|
-
if (x ===
|
|
261
|
+
if (x === void 0 || y === void 0)
|
|
262
|
+
return null;
|
|
228
263
|
const value = lookup.get(`${x}__${y}`);
|
|
229
|
-
if (value ===
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
y,
|
|
233
|
-
value
|
|
234
|
-
};
|
|
264
|
+
if (value === void 0)
|
|
265
|
+
return null;
|
|
266
|
+
return { x, y, value };
|
|
235
267
|
};
|
|
236
268
|
const tooltipPayload = activeCell ? {
|
|
237
269
|
label: `${activeCell.y} · ${activeCell.x}`,
|
|
238
270
|
row: null,
|
|
239
|
-
series: [
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
271
|
+
series: [
|
|
272
|
+
{
|
|
273
|
+
key: activeCell.x,
|
|
274
|
+
name: "数值",
|
|
275
|
+
color: activeCell.value === null ? theme.text.secondary : colorAt(activeCell.value),
|
|
276
|
+
value: activeCell.value,
|
|
277
|
+
formatted: activeCell.value === null ? "无数据" : formatNumber(activeCell.value)
|
|
278
|
+
}
|
|
279
|
+
]
|
|
246
280
|
} : null;
|
|
247
281
|
const autoAriaLabel = ariaLabel ?? `热力图:${yLabels.length} 行 × ${xLabels.length} 列`;
|
|
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
|
-
|
|
282
|
+
return /* @__PURE__ */ jsx(
|
|
283
|
+
"div",
|
|
284
|
+
{
|
|
285
|
+
className: classNames(prefixCls("chart"), className),
|
|
286
|
+
style: { width, height, ...style },
|
|
287
|
+
"data-aura-chart": "heatmap",
|
|
288
|
+
children: /* @__PURE__ */ jsxs(
|
|
289
|
+
"div",
|
|
290
|
+
{
|
|
291
|
+
ref,
|
|
292
|
+
className: prefixCls("chart__plot"),
|
|
293
|
+
onPointerMove: (event) => setActiveCell(cellFromPointer(event.clientX, event.clientY)),
|
|
294
|
+
onPointerLeave: () => setActiveCell(null),
|
|
295
|
+
children: [
|
|
296
|
+
data.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: size.width / 2,
|
|
310
|
+
y: 16,
|
|
311
|
+
containerWidth: size.width,
|
|
312
|
+
containerHeight: size.height,
|
|
313
|
+
theme,
|
|
314
|
+
config: tooltip
|
|
315
|
+
}
|
|
316
|
+
)
|
|
317
|
+
]
|
|
318
|
+
}
|
|
319
|
+
)
|
|
320
|
+
}
|
|
321
|
+
);
|
|
322
|
+
}
|
|
323
|
+
export {
|
|
324
|
+
HeatmapChart
|
|
325
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import type { BaseChartProps } from '../../types';
|
|
3
|
-
import type { CurveType } from '../../core/shape';
|
|
2
|
+
import type { BaseChartProps } from '../../types.js';
|
|
3
|
+
import type { CurveType } from '../../core/shape.js';
|
|
4
4
|
export interface LineChartProps extends BaseChartProps {
|
|
5
5
|
/** 曲线插值方式,默认 monotone(平滑但不越界) */
|
|
6
6
|
curve?: CurveType;
|
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
// src/charts/line-chart/index.tsx
|
|
3
|
+
import { useMemo } from "react";
|
|
2
4
|
import { CartesianChart } from "../../internal/CartesianChart";
|
|
3
|
-
import { jsx
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
*
|
|
7
|
-
* 默认曲线为 monotone 而非普通样条:普通样条在极值处会「冲出」数据范围,
|
|
8
|
-
* 折线图一旦画出超过真实最大值的高度,读者会基于错误信息做判断。
|
|
9
|
-
*/
|
|
10
|
-
export function LineChart({
|
|
11
|
-
curve = 'monotone',
|
|
5
|
+
import { jsx } from "react/jsx-runtime";
|
|
6
|
+
function LineChart({
|
|
7
|
+
curve = "monotone",
|
|
12
8
|
smooth = false,
|
|
13
9
|
area = false,
|
|
14
10
|
showSymbol,
|
|
@@ -16,17 +12,26 @@ export function LineChart({
|
|
|
16
12
|
series,
|
|
17
13
|
...rest
|
|
18
14
|
}) {
|
|
19
|
-
const merged = useMemo(
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
15
|
+
const merged = useMemo(
|
|
16
|
+
() => (series ?? []).map((item) => ({
|
|
17
|
+
type: "line",
|
|
18
|
+
curve: smooth ? "smooth" : curve,
|
|
19
|
+
area,
|
|
20
|
+
showSymbol,
|
|
21
|
+
...item
|
|
22
|
+
})),
|
|
23
|
+
[series, smooth, curve, area, showSymbol]
|
|
24
|
+
);
|
|
25
|
+
return /* @__PURE__ */ jsx(
|
|
26
|
+
CartesianChart,
|
|
27
|
+
{
|
|
28
|
+
...rest,
|
|
29
|
+
series: merged,
|
|
30
|
+
defaultType: "line",
|
|
31
|
+
stack
|
|
32
|
+
}
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
export {
|
|
36
|
+
LineChart
|
|
37
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import type { ChartThemeInput } from '../../theme';
|
|
3
|
-
import type { LegendConfig, TooltipConfig } from '../../types';
|
|
2
|
+
import type { ChartThemeInput } from '../../theme/index.js';
|
|
3
|
+
import type { LegendConfig, TooltipConfig } from '../../types.js';
|
|
4
4
|
export interface PieDataItem {
|
|
5
5
|
name: string;
|
|
6
6
|
value: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAyC,MAAM,OAAO,CAAC;AAM9D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAyC,MAAM,OAAO,CAAC;AAM9D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAQnD,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC/D,OAAO,6BAA6B,CAAC;AAErC,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,WAAW,EAAE,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,MAAM,CAAC,EAAE,OAAO,GAAG,YAAY,CAAC;IAChC,OAAO,CAAC,EAAE,OAAO,GAAG,aAAa,CAAC;IAClC,6BAA6B;IAC7B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,yBAAyB;IACzB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,iDAAiD;IACjD,KAAK,CAAC,EAAE,SAAS,GAAG,QAAQ,GAAG,KAAK,CAAC;IACrC,uBAAuB;IACvB,aAAa,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAChC,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;AAUD;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,EACvB,IAAS,EACT,KAAc,EACd,MAAY,EACZ,KAAK,EAAE,UAAU,EACjB,OAAO,EACP,MAAa,EACb,OAAc,EACd,WAAiB,EACjB,QAAe,EACf,KAAiB,EACjB,aAAa,EACb,SAAgB,EAChB,SAAS,EACT,KAAK,EACL,SAAS,EACT,SAAkB,GACnB,EAAE,aAAa,qBA6Uf"}
|