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