@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,45 +1,43 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
|
|
3
|
-
import {
|
|
2
|
+
// src/charts/candlestick-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 { formatNumber, estimateTextWidth } from "../../core/format";
|
|
7
12
|
import { linePath } from "../../core/shape";
|
|
8
13
|
import { withAlpha, colorAt } from "../../theme";
|
|
9
14
|
import { useChartTheme } from "../../hooks/useChartTheme";
|
|
10
15
|
import { useElementSize } from "../../hooks/useElementSize";
|
|
11
16
|
import { useChartTransition } from "../../hooks/useChartTransition";
|
|
12
|
-
import {
|
|
17
|
+
import {
|
|
18
|
+
resolveAnimation,
|
|
19
|
+
staggerProgress
|
|
20
|
+
} from "../../core/animation";
|
|
13
21
|
import { Tooltip } from "../../components/Tooltip";
|
|
14
|
-
import { jsx
|
|
15
|
-
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
16
|
-
/** 简单移动平均;不足周期的位置返回 null(不能拿 0 顶替,否则线会拉到轴上) */
|
|
22
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
17
23
|
function movingAverage(values, period) {
|
|
18
24
|
const result = [];
|
|
19
25
|
let sum = 0;
|
|
20
26
|
for (let index = 0; index < values.length; index += 1) {
|
|
21
27
|
sum += values[index];
|
|
22
|
-
if (index >= period)
|
|
28
|
+
if (index >= period)
|
|
29
|
+
sum -= values[index - period];
|
|
23
30
|
result.push(index >= period - 1 ? sum / period : null);
|
|
24
31
|
}
|
|
25
32
|
return result;
|
|
26
33
|
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* K 线图。
|
|
30
|
-
*
|
|
31
|
-
* 一根蜡烛编码四个价格:开盘、收盘、最高、最低。
|
|
32
|
-
* 实体(开收之间的矩形)表达当期多空结果,上下影线表达盘中波动范围。
|
|
33
|
-
*
|
|
34
|
-
* 配色遵循国内习惯:**红涨绿跌**,与国际市场相反。
|
|
35
|
-
*/
|
|
36
|
-
export function CandlestickChart({
|
|
34
|
+
function CandlestickChart({
|
|
37
35
|
data = [],
|
|
38
36
|
ma = [5, 10, 20],
|
|
39
37
|
showVolume = true,
|
|
40
|
-
upColor =
|
|
41
|
-
downColor =
|
|
42
|
-
width =
|
|
38
|
+
upColor = "#ef4444",
|
|
39
|
+
downColor = "#22c55e",
|
|
40
|
+
width = "100%",
|
|
43
41
|
height = 360,
|
|
44
42
|
theme: themeInput,
|
|
45
43
|
palette,
|
|
@@ -48,44 +46,62 @@ export function CandlestickChart({
|
|
|
48
46
|
className,
|
|
49
47
|
style,
|
|
50
48
|
ariaLabel,
|
|
51
|
-
emptyText =
|
|
49
|
+
emptyText = "暂无数据"
|
|
52
50
|
}) {
|
|
51
|
+
var _a;
|
|
53
52
|
const theme = useChartTheme(themeInput, palette);
|
|
54
|
-
const {
|
|
55
|
-
ref,
|
|
56
|
-
size
|
|
57
|
-
} = useElementSize();
|
|
53
|
+
const { ref, size } = useElementSize();
|
|
58
54
|
const [activeIndex, setActiveIndex] = useState(null);
|
|
59
|
-
const animKey = typeof animation ===
|
|
60
|
-
const animConfig = useMemo(
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
const matrix = useMemo(
|
|
55
|
+
const animKey = typeof animation === "object" ? JSON.stringify(animation) : String(animation);
|
|
56
|
+
const animConfig = useMemo(
|
|
57
|
+
() => resolveAnimation(animation),
|
|
58
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
59
|
+
[animKey]
|
|
60
|
+
);
|
|
61
|
+
const dates = useMemo(() => data.map((item) => item.date), [data]);
|
|
62
|
+
const hasVolume = showVolume && data.some((item) => Number.isFinite(item.volume));
|
|
63
|
+
const matrix = useMemo(
|
|
64
|
+
() => data.map((item) => [
|
|
65
|
+
item.open,
|
|
66
|
+
item.high,
|
|
67
|
+
item.low,
|
|
68
|
+
item.close,
|
|
69
|
+
item.volume ?? 0
|
|
70
|
+
]),
|
|
71
|
+
[data]
|
|
72
|
+
);
|
|
68
73
|
const transition = useChartTransition(matrix, animConfig);
|
|
69
74
|
const progress = transition.progress;
|
|
70
75
|
const priceRange = useMemo(() => {
|
|
71
|
-
if (!data.length)
|
|
72
|
-
|
|
73
|
-
const
|
|
76
|
+
if (!data.length)
|
|
77
|
+
return [0, 1];
|
|
78
|
+
const lows = data.map((item) => item.low);
|
|
79
|
+
const highs = data.map((item) => item.high);
|
|
74
80
|
const min = Math.min(...lows);
|
|
75
81
|
const max = Math.max(...highs);
|
|
76
|
-
if (min === max)
|
|
82
|
+
if (min === max)
|
|
83
|
+
return [min * 0.98, max * 1.02];
|
|
77
84
|
const pad = (max - min) * 0.06;
|
|
78
85
|
return [min - pad, max + pad];
|
|
79
86
|
}, [data]);
|
|
80
|
-
const volumeMax = useMemo(
|
|
87
|
+
const volumeMax = useMemo(
|
|
88
|
+
() => Math.max(1, ...data.map((item) => item.volume ?? 0)),
|
|
89
|
+
[data]
|
|
90
|
+
);
|
|
81
91
|
const tickCount = Math.max(3, Math.min(6, Math.round(height * 0.6 / 54)));
|
|
82
|
-
const yTicks = useMemo(
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
92
|
+
const yTicks = useMemo(
|
|
93
|
+
() => linearTicks(priceRange[0], priceRange[1], tickCount),
|
|
94
|
+
[priceRange, tickCount]
|
|
95
|
+
);
|
|
96
|
+
const yLabels = useMemo(
|
|
97
|
+
() => yTicks.map((tick) => formatNumber(tick, { compact: true, decimals: 2 })),
|
|
98
|
+
[yTicks]
|
|
99
|
+
);
|
|
87
100
|
const geometry = useMemo(() => {
|
|
88
|
-
const labelWidth = Math.max(
|
|
101
|
+
const labelWidth = Math.max(
|
|
102
|
+
0,
|
|
103
|
+
...yLabels.map((label) => estimateTextWidth(label, theme.font.size))
|
|
104
|
+
);
|
|
89
105
|
const left = Math.ceil(labelWidth) + 8;
|
|
90
106
|
const top = 10;
|
|
91
107
|
const bottom = theme.font.size + 12;
|
|
@@ -102,34 +118,43 @@ export function CandlestickChart({
|
|
|
102
118
|
volumeHeight: Math.max(0, plotHeight - mainHeight - 12)
|
|
103
119
|
};
|
|
104
120
|
}, [yLabels, size.width, size.height, theme.font.size, hasVolume]);
|
|
105
|
-
const xScale = useMemo(
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
121
|
+
const xScale = useMemo(
|
|
122
|
+
() => createBandScale({
|
|
123
|
+
domain: dates,
|
|
124
|
+
range: [geometry.left, geometry.left + geometry.plotWidth],
|
|
125
|
+
paddingInner: 0.34,
|
|
126
|
+
paddingOuter: 0.16
|
|
127
|
+
}),
|
|
128
|
+
[dates, geometry.left, geometry.plotWidth]
|
|
129
|
+
);
|
|
130
|
+
const yScale = useMemo(
|
|
131
|
+
() => createLinearScale({
|
|
132
|
+
domain: priceRange,
|
|
133
|
+
range: [geometry.top + geometry.mainHeight, geometry.top]
|
|
134
|
+
}),
|
|
135
|
+
[priceRange, geometry.top, geometry.mainHeight]
|
|
136
|
+
);
|
|
115
137
|
const maSeries = useMemo(() => {
|
|
116
|
-
if (!ma.length || !data.length)
|
|
138
|
+
if (!ma.length || !data.length)
|
|
139
|
+
return [];
|
|
117
140
|
return ma.map((period, index) => ({
|
|
118
141
|
period,
|
|
119
142
|
color: colorAt(theme, index + 2),
|
|
120
|
-
values: movingAverage(
|
|
143
|
+
values: movingAverage(
|
|
144
|
+
data.map((item) => item.close),
|
|
145
|
+
period
|
|
146
|
+
)
|
|
121
147
|
}));
|
|
122
148
|
}, [ma, data, theme]);
|
|
123
149
|
const scene = useMemo(() => {
|
|
124
|
-
if (!data.length || geometry.plotWidth <= 0)
|
|
150
|
+
if (!data.length || geometry.plotWidth <= 0)
|
|
151
|
+
return [];
|
|
125
152
|
const nodes = [];
|
|
126
153
|
const bodyWidth = Math.max(1, xScale.step * 0.62);
|
|
127
|
-
|
|
128
|
-
// 水平网格 + 价格刻度
|
|
129
154
|
yTicks.forEach((tick, index) => {
|
|
130
155
|
const y = yScale.scale(tick);
|
|
131
156
|
nodes.push({
|
|
132
|
-
kind:
|
|
157
|
+
kind: "line",
|
|
133
158
|
key: `grid-${index}`,
|
|
134
159
|
x1: geometry.left,
|
|
135
160
|
y1: y,
|
|
@@ -137,33 +162,43 @@ export function CandlestickChart({
|
|
|
137
162
|
y2: y,
|
|
138
163
|
stroke: theme.grid.line,
|
|
139
164
|
strokeWidth: theme.grid.lineWidth,
|
|
140
|
-
strokeDasharray: theme.grid.dash.join(
|
|
165
|
+
strokeDasharray: theme.grid.dash.join(" ") || void 0
|
|
141
166
|
});
|
|
142
167
|
nodes.push({
|
|
143
|
-
kind:
|
|
168
|
+
kind: "text",
|
|
144
169
|
key: `yl-${index}`,
|
|
145
170
|
x: geometry.left - 6,
|
|
146
171
|
y,
|
|
147
172
|
text: yLabels[index],
|
|
148
173
|
fill: theme.axis.label,
|
|
149
174
|
fontSize: theme.font.size,
|
|
150
|
-
anchor:
|
|
151
|
-
baseline:
|
|
175
|
+
anchor: "end",
|
|
176
|
+
baseline: "middle",
|
|
152
177
|
fontFamily: theme.font.family
|
|
153
178
|
});
|
|
154
179
|
});
|
|
155
180
|
data.forEach((item, index) => {
|
|
156
181
|
const cx = xScale.center(item.date);
|
|
157
|
-
if (cx ===
|
|
158
|
-
|
|
182
|
+
if (cx === void 0)
|
|
183
|
+
return;
|
|
184
|
+
const row = transition.values[index] ?? [
|
|
185
|
+
item.open,
|
|
186
|
+
item.high,
|
|
187
|
+
item.low,
|
|
188
|
+
item.close,
|
|
189
|
+
item.volume ?? 0
|
|
190
|
+
];
|
|
159
191
|
const [open, high, low, close] = row;
|
|
160
192
|
const rising = close >= open;
|
|
161
193
|
const color = rising ? upColor : downColor;
|
|
162
|
-
const local = staggerProgress(
|
|
163
|
-
|
|
164
|
-
|
|
194
|
+
const local = staggerProgress(
|
|
195
|
+
progress,
|
|
196
|
+
index,
|
|
197
|
+
data.length,
|
|
198
|
+
animConfig.stagger
|
|
199
|
+
);
|
|
165
200
|
const anchorY = yScale.scale(close);
|
|
166
|
-
const project = value => anchorY + (yScale.scale(value) - anchorY) * local;
|
|
201
|
+
const project = (value) => anchorY + (yScale.scale(value) - anchorY) * local;
|
|
167
202
|
const yHigh = project(high);
|
|
168
203
|
const yLow = project(low);
|
|
169
204
|
const yOpen = project(open);
|
|
@@ -171,7 +206,7 @@ export function CandlestickChart({
|
|
|
171
206
|
const bodyTop = Math.min(yOpen, yClose);
|
|
172
207
|
const bodyHeight = Math.max(1, Math.abs(yClose - yOpen));
|
|
173
208
|
nodes.push({
|
|
174
|
-
kind:
|
|
209
|
+
kind: "line",
|
|
175
210
|
key: `wick-${index}`,
|
|
176
211
|
x1: cx,
|
|
177
212
|
y1: yHigh,
|
|
@@ -179,10 +214,10 @@ export function CandlestickChart({
|
|
|
179
214
|
y2: yLow,
|
|
180
215
|
stroke: color,
|
|
181
216
|
strokeWidth: 1,
|
|
182
|
-
pointerEvents:
|
|
217
|
+
pointerEvents: "none"
|
|
183
218
|
});
|
|
184
219
|
nodes.push({
|
|
185
|
-
kind:
|
|
220
|
+
kind: "rect",
|
|
186
221
|
key: `body-${index}`,
|
|
187
222
|
x: cx - bodyWidth / 2,
|
|
188
223
|
y: bodyTop,
|
|
@@ -191,15 +226,16 @@ export function CandlestickChart({
|
|
|
191
226
|
radius: 1,
|
|
192
227
|
fill: color,
|
|
193
228
|
opacity: activeIndex === null || activeIndex === index ? 1 : 0.55,
|
|
194
|
-
pointerEvents:
|
|
229
|
+
pointerEvents: "none"
|
|
195
230
|
});
|
|
196
|
-
|
|
197
|
-
// 成交量副图
|
|
198
231
|
if (hasVolume && geometry.volumeHeight > 0) {
|
|
199
232
|
const volume = row[4] ?? 0;
|
|
200
|
-
const barHeight = Math.max(
|
|
233
|
+
const barHeight = Math.max(
|
|
234
|
+
1,
|
|
235
|
+
volume / volumeMax * geometry.volumeHeight * local
|
|
236
|
+
);
|
|
201
237
|
nodes.push({
|
|
202
|
-
kind:
|
|
238
|
+
kind: "rect",
|
|
203
239
|
key: `volume-${index}`,
|
|
204
240
|
x: cx - bodyWidth / 2,
|
|
205
241
|
y: geometry.volumeTop + geometry.volumeHeight - barHeight,
|
|
@@ -207,61 +243,76 @@ export function CandlestickChart({
|
|
|
207
243
|
height: barHeight,
|
|
208
244
|
radius: 1,
|
|
209
245
|
fill: withAlpha(color, 0.55),
|
|
210
|
-
pointerEvents:
|
|
246
|
+
pointerEvents: "none"
|
|
211
247
|
});
|
|
212
248
|
}
|
|
213
|
-
|
|
214
|
-
// x 轴标签:密集时抽样,避免压字
|
|
215
249
|
const labelStep = Math.max(1, Math.ceil(data.length / 8));
|
|
216
250
|
if (index % labelStep === 0 || index === data.length - 1) {
|
|
217
251
|
nodes.push({
|
|
218
|
-
kind:
|
|
252
|
+
kind: "text",
|
|
219
253
|
key: `xl-${index}`,
|
|
220
254
|
x: cx,
|
|
221
255
|
y: geometry.top + geometry.plotHeight + theme.font.size + 4,
|
|
222
256
|
text: item.date,
|
|
223
257
|
fill: theme.axis.label,
|
|
224
258
|
fontSize: theme.font.size,
|
|
225
|
-
anchor:
|
|
259
|
+
anchor: "middle",
|
|
226
260
|
fontFamily: theme.font.family
|
|
227
261
|
});
|
|
228
262
|
}
|
|
229
263
|
});
|
|
230
|
-
|
|
231
|
-
// 均线
|
|
232
|
-
maSeries.forEach(item => {
|
|
264
|
+
maSeries.forEach((item) => {
|
|
233
265
|
const points = item.values.map((value, index) => {
|
|
234
|
-
if (value === null)
|
|
266
|
+
if (value === null)
|
|
267
|
+
return null;
|
|
235
268
|
const cx = xScale.center(data[index].date);
|
|
236
|
-
if (cx ===
|
|
269
|
+
if (cx === void 0)
|
|
270
|
+
return null;
|
|
237
271
|
const target = yScale.scale(value);
|
|
238
272
|
const anchor = yScale.scale(data[index].close);
|
|
239
|
-
return {
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
const d = linePath(points, 'linear');
|
|
245
|
-
if (!d) return;
|
|
273
|
+
return { x: cx, y: anchor + (target - anchor) * progress };
|
|
274
|
+
}).filter((point) => point !== null);
|
|
275
|
+
const d = linePath(points, "linear");
|
|
276
|
+
if (!d)
|
|
277
|
+
return;
|
|
246
278
|
nodes.push({
|
|
247
|
-
kind:
|
|
279
|
+
kind: "path",
|
|
248
280
|
key: `ma-${item.period}`,
|
|
249
281
|
d,
|
|
250
|
-
fill:
|
|
282
|
+
fill: "none",
|
|
251
283
|
stroke: item.color,
|
|
252
284
|
strokeWidth: 1.4,
|
|
253
|
-
linejoin:
|
|
254
|
-
pointerEvents:
|
|
285
|
+
linejoin: "round",
|
|
286
|
+
pointerEvents: "none"
|
|
255
287
|
});
|
|
256
288
|
});
|
|
257
289
|
return nodes;
|
|
258
|
-
}, [
|
|
259
|
-
|
|
290
|
+
}, [
|
|
291
|
+
data,
|
|
292
|
+
geometry,
|
|
293
|
+
xScale,
|
|
294
|
+
yScale,
|
|
295
|
+
yTicks,
|
|
296
|
+
yLabels,
|
|
297
|
+
theme,
|
|
298
|
+
transition.values,
|
|
299
|
+
progress,
|
|
300
|
+
animConfig.stagger,
|
|
301
|
+
upColor,
|
|
302
|
+
downColor,
|
|
303
|
+
hasVolume,
|
|
304
|
+
volumeMax,
|
|
305
|
+
maSeries,
|
|
306
|
+
activeIndex
|
|
307
|
+
]);
|
|
308
|
+
const indexFromPointer = (clientX) => {
|
|
260
309
|
const element = ref.current;
|
|
261
|
-
if (!element || xScale.step <= 0)
|
|
310
|
+
if (!element || xScale.step <= 0)
|
|
311
|
+
return null;
|
|
262
312
|
const rect = element.getBoundingClientRect();
|
|
263
313
|
const localX = clientX - rect.left - geometry.left;
|
|
264
|
-
if (localX < 0)
|
|
314
|
+
if (localX < 0)
|
|
315
|
+
return null;
|
|
265
316
|
const index = Math.floor(localX / xScale.step);
|
|
266
317
|
return index >= 0 && index < data.length ? index : null;
|
|
267
318
|
};
|
|
@@ -269,79 +320,90 @@ export function CandlestickChart({
|
|
|
269
320
|
const tooltipPayload = active ? {
|
|
270
321
|
label: active.date,
|
|
271
322
|
row: null,
|
|
272
|
-
series: [
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
decimals: 2
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
323
|
+
series: [
|
|
324
|
+
{
|
|
325
|
+
key: "open",
|
|
326
|
+
name: "开盘",
|
|
327
|
+
color: upColor,
|
|
328
|
+
value: active.open,
|
|
329
|
+
formatted: formatNumber(active.open, { decimals: 2 })
|
|
330
|
+
},
|
|
331
|
+
{
|
|
332
|
+
key: "high",
|
|
333
|
+
name: "最高",
|
|
334
|
+
color: theme.text.secondary,
|
|
335
|
+
value: active.high,
|
|
336
|
+
formatted: formatNumber(active.high, { decimals: 2 })
|
|
337
|
+
},
|
|
338
|
+
{
|
|
339
|
+
key: "low",
|
|
340
|
+
name: "最低",
|
|
341
|
+
color: theme.text.secondary,
|
|
342
|
+
value: active.low,
|
|
343
|
+
formatted: formatNumber(active.low, { decimals: 2 })
|
|
344
|
+
},
|
|
345
|
+
{
|
|
346
|
+
key: "close",
|
|
347
|
+
name: "收盘",
|
|
348
|
+
color: downColor,
|
|
349
|
+
value: active.close,
|
|
350
|
+
formatted: formatNumber(active.close, { decimals: 2 })
|
|
351
|
+
},
|
|
352
|
+
...Number.isFinite(active.volume) ? [
|
|
353
|
+
{
|
|
354
|
+
key: "volume",
|
|
355
|
+
name: "成交量",
|
|
356
|
+
color: theme.text.secondary,
|
|
357
|
+
value: active.volume ?? null,
|
|
358
|
+
formatted: formatNumber(active.volume ?? 0, {
|
|
359
|
+
compact: true
|
|
360
|
+
})
|
|
361
|
+
}
|
|
362
|
+
] : []
|
|
363
|
+
]
|
|
313
364
|
} : null;
|
|
314
|
-
const autoAriaLabel = ariaLabel ?? `K 线图:${data.length} 个交易日,最新收盘 ${data[data.length - 1]
|
|
315
|
-
return
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
height,
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
365
|
+
const autoAriaLabel = ariaLabel ?? `K 线图:${data.length} 个交易日,最新收盘 ${((_a = data[data.length - 1]) == null ? void 0 : _a.close) ?? "—"}`;
|
|
366
|
+
return /* @__PURE__ */ jsx(
|
|
367
|
+
"div",
|
|
368
|
+
{
|
|
369
|
+
className: classNames(prefixCls("chart"), className),
|
|
370
|
+
style: { width, height, ...style },
|
|
371
|
+
"data-aura-chart": "candlestick",
|
|
372
|
+
children: /* @__PURE__ */ jsxs(
|
|
373
|
+
"div",
|
|
374
|
+
{
|
|
375
|
+
ref,
|
|
376
|
+
className: prefixCls("chart__plot"),
|
|
377
|
+
onPointerMove: (event) => setActiveIndex(indexFromPointer(event.clientX)),
|
|
378
|
+
onPointerLeave: () => setActiveIndex(null),
|
|
379
|
+
children: [
|
|
380
|
+
data.length === 0 || size.width === 0 ? /* @__PURE__ */ jsx("div", { className: prefixCls("chart__empty"), children: emptyText }) : /* @__PURE__ */ jsx(
|
|
381
|
+
SvgScene,
|
|
382
|
+
{
|
|
383
|
+
nodes: scene,
|
|
384
|
+
width: size.width,
|
|
385
|
+
height: size.height,
|
|
386
|
+
ariaLabel: autoAriaLabel
|
|
387
|
+
}
|
|
388
|
+
),
|
|
389
|
+
/* @__PURE__ */ jsx(
|
|
390
|
+
Tooltip,
|
|
391
|
+
{
|
|
392
|
+
payload: tooltipPayload,
|
|
393
|
+
x: activeIndex !== null ? xScale.center(data[activeIndex].date) ?? 0 : 0,
|
|
394
|
+
y: geometry.top + 12,
|
|
395
|
+
containerWidth: size.width,
|
|
396
|
+
containerHeight: size.height,
|
|
397
|
+
theme,
|
|
398
|
+
config: tooltip
|
|
399
|
+
}
|
|
400
|
+
)
|
|
401
|
+
]
|
|
402
|
+
}
|
|
403
|
+
)
|
|
404
|
+
}
|
|
405
|
+
);
|
|
406
|
+
}
|
|
407
|
+
export {
|
|
408
|
+
CandlestickChart
|
|
409
|
+
};
|
|
@@ -1,26 +1,14 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
|
|
2
|
+
// src/charts/combo-chart/index.tsx
|
|
3
3
|
import { CartesianChart } from "../../internal/CartesianChart";
|
|
4
|
-
import { jsx
|
|
5
|
-
|
|
6
|
-
* 折柱混合图。
|
|
7
|
-
*
|
|
8
|
-
* 没有独立实现:直接复用直角坐标系内核,由每个 series 的 type 决定画法。
|
|
9
|
-
* 之所以单独导出,是因为「收入用柱、转化率用线」这类双轴需求在业务里极常见,
|
|
10
|
-
* 给个语义化的名字比让使用者记 defaultType 更友好。
|
|
11
|
-
*
|
|
12
|
-
* 双轴:给系列加 `yAxisIndex: 1`,并开启 `yAxisRight`,即可让该系列读右侧轴。
|
|
13
|
-
* 仍是那句话——双轴只在量纲差一个数量级以上时使用,且两根轴都要写标题。
|
|
14
|
-
*/
|
|
15
|
-
export function ComboChart({
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
function ComboChart({
|
|
16
6
|
stack = false,
|
|
17
7
|
series,
|
|
18
8
|
...rest
|
|
19
9
|
}) {
|
|
20
|
-
return
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
});
|
|
26
|
-
}
|
|
10
|
+
return /* @__PURE__ */ jsx(CartesianChart, { ...rest, series, defaultType: "bar", stack });
|
|
11
|
+
}
|
|
12
|
+
export {
|
|
13
|
+
ComboChart
|
|
14
|
+
};
|