@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.
Files changed (98) hide show
  1. package/esm/charts/area-chart/index.d.ts +2 -2
  2. package/esm/charts/area-chart/index.js +28 -23
  3. package/esm/charts/bar-chart/index.d.ts +1 -1
  4. package/esm/charts/bar-chart/index.js +18 -21
  5. package/esm/charts/candlestick-chart/index.d.ts +2 -2
  6. package/esm/charts/candlestick-chart/index.js +243 -180
  7. package/esm/charts/combo-chart/index.d.ts +1 -1
  8. package/esm/charts/combo-chart/index.js +9 -20
  9. package/esm/charts/funnel-chart/index.d.ts +2 -2
  10. package/esm/charts/funnel-chart/index.js +134 -108
  11. package/esm/charts/gauge-chart/index.d.ts +1 -1
  12. package/esm/charts/gauge-chart/index.js +103 -105
  13. package/esm/charts/graph-chart/index.d.ts +3 -3
  14. package/esm/charts/graph-chart/index.js +155 -114
  15. package/esm/charts/heatmap-chart/index.d.ts +2 -2
  16. package/esm/charts/heatmap-chart/index.js +180 -135
  17. package/esm/charts/line-chart/index.d.ts +2 -2
  18. package/esm/charts/line-chart/index.js +29 -24
  19. package/esm/charts/pie-chart/index.d.ts +2 -2
  20. package/esm/charts/pie-chart/index.d.ts.map +1 -1
  21. package/esm/charts/pie-chart/index.js +199 -139
  22. package/esm/charts/radar-chart/index.d.ts +2 -2
  23. package/esm/charts/radar-chart/index.d.ts.map +1 -1
  24. package/esm/charts/radar-chart/index.js +155 -128
  25. package/esm/charts/ring-progress/index.d.ts +1 -1
  26. package/esm/charts/ring-progress/index.js +82 -82
  27. package/esm/charts/sankey-chart/index.d.ts +3 -3
  28. package/esm/charts/sankey-chart/index.js +172 -141
  29. package/esm/charts/scatter-chart/index.d.ts +3 -3
  30. package/esm/charts/scatter-chart/index.d.ts.map +1 -1
  31. package/esm/charts/scatter-chart/index.js +226 -159
  32. package/esm/charts/sparkline/index.d.ts +1 -1
  33. package/esm/charts/sparkline/index.js +82 -66
  34. package/esm/charts/tree-chart/index.d.ts +3 -3
  35. package/esm/charts/tree-chart/index.js +129 -102
  36. package/esm/charts/treemap-chart/index.d.ts +3 -3
  37. package/esm/charts/treemap-chart/index.js +163 -141
  38. package/esm/charts/waterfall-chart/index.d.ts +2 -2
  39. package/esm/charts/waterfall-chart/index.js +166 -121
  40. package/esm/components/Legend.d.ts +5 -4
  41. package/esm/components/Legend.d.ts.map +1 -1
  42. package/esm/components/Legend.js +80 -48
  43. package/esm/components/Tooltip.d.ts +2 -2
  44. package/esm/components/Tooltip.js +63 -71
  45. package/esm/components/chart/index.d.ts +5 -2
  46. package/esm/components/chart/index.d.ts.map +1 -1
  47. package/esm/components/chart/index.js +81 -102
  48. package/esm/components/chart.less +13 -0
  49. package/esm/core/animation.js +32 -43
  50. package/esm/core/export.d.ts +34 -0
  51. package/esm/core/export.d.ts.map +1 -0
  52. package/esm/core/export.js +390 -0
  53. package/esm/core/force.js +23 -45
  54. package/esm/core/format.js +49 -52
  55. package/esm/core/hierarchy.d.ts +1 -1
  56. package/esm/core/hierarchy.js +61 -92
  57. package/esm/core/layout.d.ts +1 -1
  58. package/esm/core/layout.js +33 -50
  59. package/esm/core/sampling.js +31 -53
  60. package/esm/core/sankey.js +36 -55
  61. package/esm/core/scale.js +73 -86
  62. package/esm/core/shape.js +102 -133
  63. package/esm/core/sync.d.ts +41 -0
  64. package/esm/core/sync.d.ts.map +1 -0
  65. package/esm/core/sync.js +120 -0
  66. package/esm/hooks/useChartExport.d.ts +19 -0
  67. package/esm/hooks/useChartExport.d.ts.map +1 -0
  68. package/esm/hooks/useChartExport.js +35 -0
  69. package/esm/hooks/useChartTheme.d.ts +6 -5
  70. package/esm/hooks/useChartTheme.d.ts.map +1 -1
  71. package/esm/hooks/useChartTheme.js +18 -18
  72. package/esm/hooks/useChartTransition.d.ts +1 -1
  73. package/esm/hooks/useChartTransition.js +59 -73
  74. package/esm/hooks/useElementSize.js +20 -28
  75. package/esm/hooks/usePlotPointer.d.ts +23 -0
  76. package/esm/hooks/usePlotPointer.d.ts.map +1 -0
  77. package/esm/hooks/usePlotPointer.js +94 -0
  78. package/esm/index.d.ts +56 -50
  79. package/esm/index.d.ts.map +1 -1
  80. package/esm/index.js +137 -47
  81. package/esm/internal/CartesianChart.d.ts +1 -1
  82. package/esm/internal/CartesianChart.d.ts.map +1 -1
  83. package/esm/internal/CartesianChart.js +667 -485
  84. package/esm/internal/model.d.ts +2 -2
  85. package/esm/internal/model.js +45 -60
  86. package/esm/scene/canvas.d.ts +1 -1
  87. package/esm/scene/canvas.js +101 -107
  88. package/esm/scene/svg.d.ts +1 -1
  89. package/esm/scene/svg.js +107 -99
  90. package/esm/scene/types.js +9 -15
  91. package/esm/style.css +10 -0
  92. package/esm/theme/index.d.ts +2 -2
  93. package/esm/theme/index.d.ts.map +1 -1
  94. package/esm/theme/index.js +145 -170
  95. package/esm/types.d.ts +7 -3
  96. package/esm/types.d.ts.map +1 -1
  97. package/esm/types.js +1 -1
  98. package/package.json +2 -2
@@ -1,44 +1,43 @@
1
- import React, { useMemo, useState } from 'react';
2
- import { classNames, prefixCls } from '@aura-react-comp/shared';
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 { createBandScale, createLinearScale, linearTicks } from "../../core/scale";
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 { resolveAnimation, staggerProgress } from "../../core/animation";
17
+ import {
18
+ resolveAnimation,
19
+ staggerProgress
20
+ } from "../../core/animation";
12
21
  import { Tooltip } from "../../components/Tooltip";
13
- import { jsx as _jsx } from "react/jsx-runtime";
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) sum -= values[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 = '#ef4444',
40
- downColor = '#22c55e',
41
- width = '100%',
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 === 'object' ? JSON.stringify(animation) : String(animation);
59
- const animConfig = useMemo(() => resolveAnimation(animation),
60
- // eslint-disable-next-line react-hooks/exhaustive-deps
61
- [animKey]);
62
- const dates = useMemo(() => data.map(item => item.date), [data]);
63
- const hasVolume = showVolume && data.some(item => Number.isFinite(item.volume));
64
-
65
- // 每行 [open, high, low, close, volume],更新时逐项插值
66
- const matrix = useMemo(() => data.map(item => [item.open, item.high, item.low, item.close, item.volume ?? 0]), [data]);
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) return [0, 1];
71
- const lows = data.map(item => item.low);
72
- const highs = data.map(item => item.high);
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) return [min * 0.98, max * 1.02];
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(() => Math.max(1, ...data.map(item => item.volume ?? 0)), [data]);
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(() => linearTicks(priceRange[0], priceRange[1], tickCount), [priceRange, tickCount]);
82
- const yLabels = useMemo(() => yTicks.map(tick => formatNumber(tick, {
83
- compact: true,
84
- decimals: 2
85
- })), [yTicks]);
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(0, ...yLabels.map(label => estimateTextWidth(label, theme.font.size)));
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(() => createBandScale({
105
- domain: dates,
106
- range: [geometry.left, geometry.left + geometry.plotWidth],
107
- paddingInner: 0.34,
108
- paddingOuter: 0.16
109
- }), [dates, geometry.left, geometry.plotWidth]);
110
- const yScale = useMemo(() => createLinearScale({
111
- domain: priceRange,
112
- range: [geometry.top + geometry.mainHeight, geometry.top]
113
- }), [priceRange, geometry.top, geometry.mainHeight]);
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) return [];
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(data.map(item => item.close), period)
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) return [];
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: 'line',
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(' ') || undefined
165
+ strokeDasharray: theme.grid.dash.join(" ") || void 0
140
166
  });
141
167
  nodes.push({
142
- kind: 'text',
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: 'end',
150
- baseline: 'middle',
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 === undefined) return;
157
- const row = transition.values[index] ?? [item.open, item.high, item.low, item.close, item.volume ?? 0];
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(progress, index, data.length, animConfig.stagger);
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: 'line',
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: 'none'
217
+ pointerEvents: "none"
182
218
  });
183
219
  nodes.push({
184
- kind: 'rect',
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: 'none'
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(1, volume / volumeMax * geometry.volumeHeight * local);
233
+ const barHeight = Math.max(
234
+ 1,
235
+ volume / volumeMax * geometry.volumeHeight * local
236
+ );
200
237
  nodes.push({
201
- kind: 'rect',
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: 'none'
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: 'text',
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: 'middle',
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) return null;
266
+ if (value === null)
267
+ return null;
234
268
  const cx = xScale.center(data[index].date);
235
- if (cx === undefined) return null;
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
- x: cx,
240
- y: anchor + (target - anchor) * progress
241
- };
242
- }).filter(point => point !== null);
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: 'path',
279
+ kind: "path",
247
280
  key: `ma-${item.period}`,
248
281
  d,
249
- fill: 'none',
282
+ fill: "none",
250
283
  stroke: item.color,
251
284
  strokeWidth: 1.4,
252
- linejoin: 'round',
253
- pointerEvents: 'none'
285
+ linejoin: "round",
286
+ pointerEvents: "none"
254
287
  });
255
288
  });
256
289
  return nodes;
257
- }, [data, geometry, xScale, yScale, yTicks, yLabels, theme, transition.values, progress, animConfig.stagger, upColor, downColor, hasVolume, volumeMax, maSeries, activeIndex]);
258
- const indexFromPointer = clientX => {
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) return null;
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) return null;
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
- key: 'open',
273
- name: '开盘',
274
- color: upColor,
275
- value: active.open,
276
- formatted: formatNumber(active.open, {
277
- decimals: 2
278
- })
279
- }, {
280
- key: 'high',
281
- name: '最高',
282
- color: theme.text.secondary,
283
- value: active.high,
284
- formatted: formatNumber(active.high, {
285
- decimals: 2
286
- })
287
- }, {
288
- key: 'low',
289
- name: '最低',
290
- color: theme.text.secondary,
291
- value: active.low,
292
- formatted: formatNumber(active.low, {
293
- decimals: 2
294
- })
295
- }, {
296
- key: 'close',
297
- name: '收盘',
298
- color: downColor,
299
- value: active.close,
300
- formatted: formatNumber(active.close, {
301
- decimals: 2
302
- })
303
- }, ...(Number.isFinite(active.volume) ? [{
304
- key: 'volume',
305
- name: '成交量',
306
- color: theme.text.secondary,
307
- value: active.volume ?? null,
308
- formatted: formatNumber(active.volume ?? 0, {
309
- compact: true
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]?.close ?? '—'}`;
314
- return /*#__PURE__*/_jsx("div", {
315
- className: classNames(prefixCls('chart'), className),
316
- style: {
317
- width,
318
- height,
319
- ...style
320
- },
321
- "data-aura-chart": "candlestick",
322
- children: /*#__PURE__*/_jsxs("div", {
323
- ref: ref,
324
- className: prefixCls('chart__plot'),
325
- onPointerMove: event => setActiveIndex(indexFromPointer(event.clientX)),
326
- onPointerLeave: () => setActiveIndex(null),
327
- children: [data.length === 0 || size.width === 0 ? /*#__PURE__*/_jsx("div", {
328
- className: prefixCls('chart__empty'),
329
- children: emptyText
330
- }) : /*#__PURE__*/_jsx(SvgScene, {
331
- nodes: scene,
332
- width: size.width,
333
- height: size.height,
334
- ariaLabel: autoAriaLabel
335
- }), /*#__PURE__*/_jsx(Tooltip, {
336
- payload: tooltipPayload,
337
- x: activeIndex !== null ? xScale.center(data[activeIndex].date) ?? 0 : 0,
338
- y: geometry.top + 12,
339
- containerWidth: size.width,
340
- containerHeight: size.height,
341
- theme: theme,
342
- config: tooltip
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,5 +1,5 @@
1
1
  import React from 'react';
2
- import type { BaseChartProps } from '../../types';
2
+ import type { BaseChartProps } from '../../types.js';
3
3
  export interface ComboChartProps extends BaseChartProps {
4
4
  stack?: boolean;
5
5
  }
@@ -1,25 +1,14 @@
1
- import React from 'react';
1
+ 'use client';
2
+ // src/charts/combo-chart/index.tsx
2
3
  import { CartesianChart } from "../../internal/CartesianChart";
3
- import { jsx as _jsx } from "react/jsx-runtime";
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 /*#__PURE__*/_jsx(CartesianChart, {
20
- ...rest,
21
- series: series,
22
- defaultType: "bar",
23
- stack: stack
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;