@aura-react-comp/charts 0.0.0-stage → 0.2.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 (129) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +90 -2
  3. package/esm/charts/area-chart/index.d.ts +19 -0
  4. package/esm/charts/area-chart/index.d.ts.map +1 -0
  5. package/esm/charts/area-chart/index.js +30 -0
  6. package/esm/charts/bar-chart/index.d.ts +16 -0
  7. package/esm/charts/bar-chart/index.d.ts.map +1 -0
  8. package/esm/charts/bar-chart/index.js +27 -0
  9. package/esm/charts/candlestick-chart/index.d.ts +47 -0
  10. package/esm/charts/candlestick-chart/index.d.ts.map +1 -0
  11. package/esm/charts/candlestick-chart/index.js +346 -0
  12. package/esm/charts/combo-chart/index.d.ts +17 -0
  13. package/esm/charts/combo-chart/index.d.ts.map +1 -0
  14. package/esm/charts/combo-chart/index.js +25 -0
  15. package/esm/charts/funnel-chart/index.d.ts +35 -0
  16. package/esm/charts/funnel-chart/index.d.ts.map +1 -0
  17. package/esm/charts/funnel-chart/index.js +199 -0
  18. package/esm/charts/gauge-chart/index.d.ts +41 -0
  19. package/esm/charts/gauge-chart/index.d.ts.map +1 -0
  20. package/esm/charts/gauge-chart/index.js +216 -0
  21. package/esm/charts/graph-chart/index.d.ts +35 -0
  22. package/esm/charts/graph-chart/index.d.ts.map +1 -0
  23. package/esm/charts/graph-chart/index.js +223 -0
  24. package/esm/charts/heatmap-chart/index.d.ts +47 -0
  25. package/esm/charts/heatmap-chart/index.d.ts.map +1 -0
  26. package/esm/charts/heatmap-chart/index.js +280 -0
  27. package/esm/charts/line-chart/index.d.ts +23 -0
  28. package/esm/charts/line-chart/index.d.ts.map +1 -0
  29. package/esm/charts/line-chart/index.js +32 -0
  30. package/esm/charts/pie-chart/index.d.ts +38 -0
  31. package/esm/charts/pie-chart/index.d.ts.map +1 -0
  32. package/esm/charts/pie-chart/index.js +271 -0
  33. package/esm/charts/radar-chart/index.d.ts +44 -0
  34. package/esm/charts/radar-chart/index.d.ts.map +1 -0
  35. package/esm/charts/radar-chart/index.js +262 -0
  36. package/esm/charts/ring-progress/index.d.ts +38 -0
  37. package/esm/charts/ring-progress/index.d.ts.map +1 -0
  38. package/esm/charts/ring-progress/index.js +136 -0
  39. package/esm/charts/sankey-chart/index.d.ts +34 -0
  40. package/esm/charts/sankey-chart/index.d.ts.map +1 -0
  41. package/esm/charts/sankey-chart/index.js +247 -0
  42. package/esm/charts/scatter-chart/index.d.ts +34 -0
  43. package/esm/charts/scatter-chart/index.d.ts.map +1 -0
  44. package/esm/charts/scatter-chart/index.js +304 -0
  45. package/esm/charts/sparkline/index.d.ts +31 -0
  46. package/esm/charts/sparkline/index.d.ts.map +1 -0
  47. package/esm/charts/sparkline/index.js +151 -0
  48. package/esm/charts/tree-chart/index.d.ts +34 -0
  49. package/esm/charts/tree-chart/index.d.ts.map +1 -0
  50. package/esm/charts/tree-chart/index.js +199 -0
  51. package/esm/charts/treemap-chart/index.d.ts +35 -0
  52. package/esm/charts/treemap-chart/index.d.ts.map +1 -0
  53. package/esm/charts/treemap-chart/index.js +238 -0
  54. package/esm/charts/waterfall-chart/index.d.ts +41 -0
  55. package/esm/charts/waterfall-chart/index.d.ts.map +1 -0
  56. package/esm/charts/waterfall-chart/index.js +280 -0
  57. package/esm/components/Legend.d.ts +24 -0
  58. package/esm/components/Legend.d.ts.map +1 -0
  59. package/esm/components/Legend.js +49 -0
  60. package/esm/components/Tooltip.d.ts +24 -0
  61. package/esm/components/Tooltip.d.ts.map +1 -0
  62. package/esm/components/Tooltip.js +84 -0
  63. package/esm/components/chart/index.d.ts +71 -0
  64. package/esm/components/chart/index.d.ts.map +1 -0
  65. package/esm/components/chart/index.js +141 -0
  66. package/esm/components/chart.less +223 -0
  67. package/esm/core/animation.d.ts +49 -0
  68. package/esm/core/animation.d.ts.map +1 -0
  69. package/esm/core/animation.js +92 -0
  70. package/esm/core/force.d.ts +43 -0
  71. package/esm/core/force.d.ts.map +1 -0
  72. package/esm/core/force.js +133 -0
  73. package/esm/core/format.d.ts +34 -0
  74. package/esm/core/format.d.ts.map +1 -0
  75. package/esm/core/format.js +80 -0
  76. package/esm/core/hierarchy.d.ts +77 -0
  77. package/esm/core/hierarchy.d.ts.map +1 -0
  78. package/esm/core/hierarchy.js +232 -0
  79. package/esm/core/layout.d.ts +67 -0
  80. package/esm/core/layout.d.ts.map +1 -0
  81. package/esm/core/layout.js +120 -0
  82. package/esm/core/sampling.d.ts +32 -0
  83. package/esm/core/sampling.d.ts.map +1 -0
  84. package/esm/core/sampling.js +123 -0
  85. package/esm/core/sankey.d.ts +67 -0
  86. package/esm/core/sankey.d.ts.map +1 -0
  87. package/esm/core/sankey.js +135 -0
  88. package/esm/core/scale.d.ts +98 -0
  89. package/esm/core/scale.d.ts.map +1 -0
  90. package/esm/core/scale.js +206 -0
  91. package/esm/core/shape.d.ts +60 -0
  92. package/esm/core/shape.d.ts.map +1 -0
  93. package/esm/core/shape.js +245 -0
  94. package/esm/global.d.ts +6 -0
  95. package/esm/hooks/useChartTheme.d.ts +10 -0
  96. package/esm/hooks/useChartTheme.d.ts.map +1 -0
  97. package/esm/hooks/useChartTheme.js +33 -0
  98. package/esm/hooks/useChartTransition.d.ts +20 -0
  99. package/esm/hooks/useChartTransition.d.ts.map +1 -0
  100. package/esm/hooks/useChartTransition.js +119 -0
  101. package/esm/hooks/useElementSize.d.ts +17 -0
  102. package/esm/hooks/useElementSize.d.ts.map +1 -0
  103. package/esm/hooks/useElementSize.js +46 -0
  104. package/esm/index.d.ts +62 -0
  105. package/esm/index.d.ts.map +1 -0
  106. package/esm/index.js +47 -0
  107. package/esm/internal/CartesianChart.d.ts +16 -0
  108. package/esm/internal/CartesianChart.d.ts.map +1 -0
  109. package/esm/internal/CartesianChart.js +810 -0
  110. package/esm/internal/model.d.ts +67 -0
  111. package/esm/internal/model.d.ts.map +1 -0
  112. package/esm/internal/model.js +145 -0
  113. package/esm/scene/canvas.d.ts +18 -0
  114. package/esm/scene/canvas.d.ts.map +1 -0
  115. package/esm/scene/canvas.js +137 -0
  116. package/esm/scene/svg.d.ts +12 -0
  117. package/esm/scene/svg.d.ts.map +1 -0
  118. package/esm/scene/svg.js +115 -0
  119. package/esm/scene/types.d.ts +89 -0
  120. package/esm/scene/types.d.ts.map +1 -0
  121. package/esm/scene/types.js +20 -0
  122. package/esm/style.css +196 -0
  123. package/esm/theme/index.d.ts +127 -0
  124. package/esm/theme/index.d.ts.map +1 -0
  125. package/esm/theme/index.js +297 -0
  126. package/esm/types.d.ts +168 -0
  127. package/esm/types.d.ts.map +1 -0
  128. package/esm/types.js +1 -0
  129. package/package.json +64 -3
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026-present Aura Team
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,91 @@
1
- # Temporary Holding Version
1
+ # @aura-react-comp/charts
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Aura 图表库:18 个图表组件,自研 SVG / Canvas 双渲染内核,不依赖任何第三方图表引擎。
4
+
5
+ ## 安装
6
+
7
+ ```bash
8
+ pnpm add @aura-react-comp/charts
9
+ ```
10
+
11
+ `react` / `react-dom` 为 peerDependencies,需由使用方提供(>=18)。
12
+
13
+ ## 使用
14
+
15
+ ```tsx
16
+ import { LineChart } from '@aura-react-comp/charts';
17
+
18
+ const data = [
19
+ { month: '1月', orders: 1240 },
20
+ { month: '2月', orders: 1560 },
21
+ { month: '3月', orders: 1890 },
22
+ ];
23
+
24
+ const App = () => (
25
+ <LineChart
26
+ data={data}
27
+ xKey="month"
28
+ series={[{ key: 'orders', name: '订单量' }]}
29
+ height={320}
30
+ />
31
+ );
32
+ ```
33
+
34
+ 样式随入口自动引入,无需单独 `import`。源码路径(`@aura-react-comp/charts/src/...`)不可用 —— 发布包只包含 `esm/` 产物。
35
+
36
+ ## 组件总览(18 个)
37
+
38
+ | 分类 | 组件 |
39
+ | ---------- | ------------------------------------------------------------------------------------------------------------------ |
40
+ | **基础** | LineChart、BarChart、AreaChart、PieChart、FunnelChart、WaterfallChart |
41
+ | **进阶** | ComboChart(折柱混合 + 双 Y 轴)、ScatterChart、RadarChart、HeatmapChart、CandlestickChart(K 线 + 均线 + 成交量) |
42
+ | **层级** | TreemapChart(矩形树图)、TreeChart(树图) |
43
+ | **关系** | SankeyChart(桑基图)、GraphChart(力导向关系图) |
44
+ | **指标** | GaugeChart、RingProgress、Sparkline |
45
+ | **配置式** | Chart(用一份 option 描述整张图) |
46
+
47
+ ## 关键能力
48
+
49
+ **双渲染内核**:默认 SVG(可被读屏器读取、可打印为矢量),图元超过 2000 时自动切 Canvas。两种渲染器消费同一份场景数据,因此视觉与动效完全一致。
50
+
51
+ **主题**:运行时读取 `--aura-*` CSS 变量,`data-theme` 切换后自动跟随,无需重渲染。
52
+
53
+ **动画**:入场阶段逐图元错峰生长,数据更新走值插值——改一个数字不会让整张图重播。命中 `prefers-reduced-motion` 时自动跳过。
54
+
55
+ ```tsx
56
+ <LineChart
57
+ animation={{ duration: 620, easing: 'easeOutQuint', stagger: 0.35 }}
58
+ />
59
+ ```
60
+
61
+ **双 Y 轴**:量纲差一个数量级以上时使用,两根轴都要写标题。
62
+
63
+ ```tsx
64
+ <ComboChart
65
+ yAxisRight={{ formatter: (v) => `${v}%` }}
66
+ series={[
67
+ { key: 'revenue', name: '营收', type: 'bar' },
68
+ { key: 'rate', name: '增长率', type: 'line', yAxisIndex: 1 },
69
+ ]}
70
+ />
71
+ ```
72
+
73
+ **大数据**:默认按 LTTB 保形降采样到 800 点(保住尖峰),并支持底部缩略轴缩放。
74
+
75
+ ```tsx
76
+ <LineChart data={bigData} dataZoom sampling={800} />
77
+ ```
78
+
79
+ **无障碍**:每张图都渲染一份视觉隐藏的数据表,屏幕阅读器能读到真实数值。
80
+
81
+ ## 体积
82
+
83
+ 全量引入约 78 kB(brotli,18 个图表 + 内核)。按需 import 时 tree-shaking 后单个图表通常 3~6 kB,内核是共享的。
84
+
85
+ ## 文档
86
+
87
+ 完整文档与可运行示例:https://asbeforelandy.github.io/aura/charts
88
+
89
+ ## 许可证
90
+
91
+ MIT
@@ -0,0 +1,19 @@
1
+ import React from 'react';
2
+ import type { BaseChartProps } from '../../types';
3
+ import type { CurveType } from '../../core/shape';
4
+ export interface AreaChartProps extends BaseChartProps {
5
+ curve?: CurveType;
6
+ smooth?: boolean;
7
+ /** 堆叠面积图 */
8
+ stack?: boolean;
9
+ /** 填充不透明度,默认取主题值 */
10
+ areaOpacity?: number;
11
+ }
12
+ /**
13
+ * 面积图。
14
+ *
15
+ * 单系列面积图用来强调「量级」,多系列时**必须**开 stack,
16
+ * 否则后画的系列会遮住前面的 —— 这是面积图最常见的误用。
17
+ */
18
+ export declare function AreaChart({ curve, smooth, stack, areaOpacity, series, ...rest }: AreaChartProps): React.JSX.Element;
19
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAkB,MAAM,OAAO,CAAC;AACvC,OAAO,KAAK,EAAE,cAAc,EAAgB,MAAM,aAAa,CAAC;AAChE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAGlD,MAAM,WAAW,cAAe,SAAQ,cAAc;IACpD,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,YAAY;IACZ,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,oBAAoB;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,EACxB,KAAkB,EAClB,MAAc,EACd,KAAa,EACb,WAAW,EACX,MAAM,EACN,GAAG,IAAI,EACR,EAAE,cAAc,qBAoBhB"}
@@ -0,0 +1,30 @@
1
+ import React, { useMemo } from 'react';
2
+ import { CartesianChart } from "../../internal/CartesianChart";
3
+ import { jsx as _jsx } from "react/jsx-runtime";
4
+ /**
5
+ * 面积图。
6
+ *
7
+ * 单系列面积图用来强调「量级」,多系列时**必须**开 stack,
8
+ * 否则后画的系列会遮住前面的 —— 这是面积图最常见的误用。
9
+ */
10
+ export function AreaChart({
11
+ curve = 'monotone',
12
+ smooth = false,
13
+ stack = false,
14
+ areaOpacity,
15
+ series,
16
+ ...rest
17
+ }) {
18
+ const merged = useMemo(() => (series ?? []).map(item => ({
19
+ type: 'area',
20
+ curve: smooth ? 'smooth' : curve,
21
+ areaOpacity,
22
+ ...item
23
+ })), [series, smooth, curve, areaOpacity]);
24
+ return /*#__PURE__*/_jsx(CartesianChart, {
25
+ ...rest,
26
+ series: merged,
27
+ defaultType: "area",
28
+ stack: stack
29
+ });
30
+ }
@@ -0,0 +1,16 @@
1
+ import React from 'react';
2
+ import type { BaseChartProps } from '../../types';
3
+ export interface BarChartProps extends BaseChartProps {
4
+ /** 堆叠:同一 x 下的系列累加 */
5
+ stack?: boolean;
6
+ /** 柱子最大宽度,默认 48 */
7
+ barMaxWidth?: number;
8
+ }
9
+ /**
10
+ * 柱状图。
11
+ *
12
+ * y 轴默认从 0 起(startFromZero),这是柱状图的硬性要求:
13
+ * 柱子用「长度」编码数值,基线不在 0 会让长度比例失真。
14
+ */
15
+ export declare function BarChart({ stack, barMaxWidth, series, ...rest }: BarChartProps): React.JSX.Element;
16
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAkB,MAAM,OAAO,CAAC;AACvC,OAAO,KAAK,EAAE,cAAc,EAAgB,MAAM,aAAa,CAAC;AAGhE,MAAM,WAAW,aAAc,SAAQ,cAAc;IACnD,qBAAqB;IACrB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,mBAAmB;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,EACvB,KAAa,EACb,WAAW,EACX,MAAM,EACN,GAAG,IAAI,EACR,EAAE,aAAa,qBAcf"}
@@ -0,0 +1,27 @@
1
+ import React, { useMemo } from 'react';
2
+ import { CartesianChart } from "../../internal/CartesianChart";
3
+ import { jsx as _jsx } from "react/jsx-runtime";
4
+ /**
5
+ * 柱状图。
6
+ *
7
+ * y 轴默认从 0 起(startFromZero),这是柱状图的硬性要求:
8
+ * 柱子用「长度」编码数值,基线不在 0 会让长度比例失真。
9
+ */
10
+ export function BarChart({
11
+ stack = false,
12
+ barMaxWidth,
13
+ series,
14
+ ...rest
15
+ }) {
16
+ const merged = useMemo(() => (series ?? []).map(item => ({
17
+ type: 'bar',
18
+ barMaxWidth,
19
+ ...item
20
+ })), [series, barMaxWidth]);
21
+ return /*#__PURE__*/_jsx(CartesianChart, {
22
+ ...rest,
23
+ series: merged,
24
+ defaultType: "bar",
25
+ stack: stack
26
+ });
27
+ }
@@ -0,0 +1,47 @@
1
+ import React from 'react';
2
+ import { type ChartThemeInput } from '../../theme';
3
+ import type { ChartAnimationInput, TooltipConfig } from '../../types';
4
+ export interface CandlestickItem {
5
+ /** 时间标签(交易日、周、月) */
6
+ date: string;
7
+ open: number;
8
+ high: number;
9
+ low: number;
10
+ close: number;
11
+ /** 成交量;不传时不画副图 */
12
+ volume?: number;
13
+ }
14
+ export interface CandlestickChartProps {
15
+ data?: CandlestickItem[];
16
+ /** 均线周期,默认 [5, 10, 20];传空数组关闭 */
17
+ ma?: number[];
18
+ /** 是否显示成交量副图(需要数据里有 volume) */
19
+ showVolume?: boolean;
20
+ /**
21
+ * 上涨颜色。默认红色 —— 遵循 A 股/港股「红涨绿跌」,
22
+ * 与欧美市场相反;如需国际市场惯例请自行对调。
23
+ */
24
+ upColor?: string;
25
+ /** 下跌颜色 */
26
+ downColor?: string;
27
+ width?: number | string;
28
+ height?: number;
29
+ theme?: ChartThemeInput;
30
+ palette?: string[];
31
+ tooltip?: boolean | TooltipConfig;
32
+ animation?: ChartAnimationInput;
33
+ className?: string;
34
+ style?: React.CSSProperties;
35
+ ariaLabel?: string;
36
+ emptyText?: string;
37
+ }
38
+ /**
39
+ * K 线图。
40
+ *
41
+ * 一根蜡烛编码四个价格:开盘、收盘、最高、最低。
42
+ * 实体(开收之间的矩形)表达当期多空结果,上下影线表达盘中波动范围。
43
+ *
44
+ * 配色遵循国内习惯:**红涨绿跌**,与国际市场相反。
45
+ */
46
+ export declare function CandlestickChart({ data, ma, showVolume, upColor, downColor, width, height, theme: themeInput, palette, tooltip, animation, className, style, ariaLabel, emptyText, }: CandlestickChartProps): React.JSX.Element;
47
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA4B,MAAM,OAAO,CAAC;AAWjD,OAAO,EAAsB,KAAK,eAAe,EAAE,MAAM,aAAa,CAAC;AAUvE,OAAO,KAAK,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACtE,OAAO,6BAA6B,CAAC;AAErC,MAAM,WAAW,eAAe;IAC9B,oBAAoB;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,kBAAkB;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,qBAAqB;IACpC,IAAI,CAAC,EAAE,eAAe,EAAE,CAAC;IACzB,iCAAiC;IACjC,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC;IACd,+BAA+B;IAC/B,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW;IACX,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,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,OAAO,CAAC,EAAE,OAAO,GAAG,aAAa,CAAC;IAClC,SAAS,CAAC,EAAE,mBAAmB,CAAC;IAChC,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;AAcD;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,EAC/B,IAAS,EACT,EAAgB,EAChB,UAAiB,EACjB,OAAmB,EACnB,SAAqB,EACrB,KAAc,EACd,MAAY,EACZ,KAAK,EAAE,UAAU,EACjB,OAAO,EACP,OAAc,EACd,SAAgB,EAChB,SAAS,EACT,KAAK,EACL,SAAS,EACT,SAAkB,GACnB,EAAE,qBAAqB,qBA4YvB"}
@@ -0,0 +1,346 @@
1
+ import React, { useMemo, useState } from 'react';
2
+ import { classNames, prefixCls } from '@aura-react-comp/shared';
3
+ import { SvgScene } from "../../scene/svg";
4
+ import { createBandScale, createLinearScale, linearTicks } from "../../core/scale";
5
+ import { formatNumber, estimateTextWidth } from "../../core/format";
6
+ import { linePath } from "../../core/shape";
7
+ import { withAlpha, colorAt } from "../../theme";
8
+ import { useChartTheme } from "../../hooks/useChartTheme";
9
+ import { useElementSize } from "../../hooks/useElementSize";
10
+ import { useChartTransition } from "../../hooks/useChartTransition";
11
+ import { resolveAnimation, staggerProgress } from "../../core/animation";
12
+ 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 顶替,否则线会拉到轴上) */
16
+ function movingAverage(values, period) {
17
+ const result = [];
18
+ let sum = 0;
19
+ for (let index = 0; index < values.length; index += 1) {
20
+ sum += values[index];
21
+ if (index >= period) sum -= values[index - period];
22
+ result.push(index >= period - 1 ? sum / period : null);
23
+ }
24
+ return result;
25
+ }
26
+
27
+ /**
28
+ * K 线图。
29
+ *
30
+ * 一根蜡烛编码四个价格:开盘、收盘、最高、最低。
31
+ * 实体(开收之间的矩形)表达当期多空结果,上下影线表达盘中波动范围。
32
+ *
33
+ * 配色遵循国内习惯:**红涨绿跌**,与国际市场相反。
34
+ */
35
+ export function CandlestickChart({
36
+ data = [],
37
+ ma = [5, 10, 20],
38
+ showVolume = true,
39
+ upColor = '#ef4444',
40
+ downColor = '#22c55e',
41
+ width = '100%',
42
+ height = 360,
43
+ theme: themeInput,
44
+ palette,
45
+ tooltip = true,
46
+ animation = true,
47
+ className,
48
+ style,
49
+ ariaLabel,
50
+ emptyText = '暂无数据'
51
+ }) {
52
+ const theme = useChartTheme(themeInput, palette);
53
+ const {
54
+ ref,
55
+ size
56
+ } = useElementSize();
57
+ 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]);
67
+ const transition = useChartTransition(matrix, animConfig);
68
+ const progress = transition.progress;
69
+ 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);
73
+ const min = Math.min(...lows);
74
+ const max = Math.max(...highs);
75
+ if (min === max) return [min * 0.98, max * 1.02];
76
+ const pad = (max - min) * 0.06;
77
+ return [min - pad, max + pad];
78
+ }, [data]);
79
+ const volumeMax = useMemo(() => Math.max(1, ...data.map(item => item.volume ?? 0)), [data]);
80
+ 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]);
86
+ const geometry = useMemo(() => {
87
+ const labelWidth = Math.max(0, ...yLabels.map(label => estimateTextWidth(label, theme.font.size)));
88
+ const left = Math.ceil(labelWidth) + 8;
89
+ const top = 10;
90
+ const bottom = theme.font.size + 12;
91
+ const plotWidth = Math.max(0, size.width - left - 12);
92
+ const plotHeight = Math.max(0, size.height - top - bottom);
93
+ const mainHeight = hasVolume ? plotHeight * 0.74 : plotHeight;
94
+ return {
95
+ left,
96
+ top,
97
+ plotWidth,
98
+ plotHeight,
99
+ mainHeight,
100
+ volumeTop: top + mainHeight + 12,
101
+ volumeHeight: Math.max(0, plotHeight - mainHeight - 12)
102
+ };
103
+ }, [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]);
114
+ const maSeries = useMemo(() => {
115
+ if (!ma.length || !data.length) return [];
116
+ return ma.map((period, index) => ({
117
+ period,
118
+ color: colorAt(theme, index + 2),
119
+ values: movingAverage(data.map(item => item.close), period)
120
+ }));
121
+ }, [ma, data, theme]);
122
+ const scene = useMemo(() => {
123
+ if (!data.length || geometry.plotWidth <= 0) return [];
124
+ const nodes = [];
125
+ const bodyWidth = Math.max(1, xScale.step * 0.62);
126
+
127
+ // 水平网格 + 价格刻度
128
+ yTicks.forEach((tick, index) => {
129
+ const y = yScale.scale(tick);
130
+ nodes.push({
131
+ kind: 'line',
132
+ key: `grid-${index}`,
133
+ x1: geometry.left,
134
+ y1: y,
135
+ x2: geometry.left + geometry.plotWidth,
136
+ y2: y,
137
+ stroke: theme.grid.line,
138
+ strokeWidth: theme.grid.lineWidth,
139
+ strokeDasharray: theme.grid.dash.join(' ') || undefined
140
+ });
141
+ nodes.push({
142
+ kind: 'text',
143
+ key: `yl-${index}`,
144
+ x: geometry.left - 6,
145
+ y,
146
+ text: yLabels[index],
147
+ fill: theme.axis.label,
148
+ fontSize: theme.font.size,
149
+ anchor: 'end',
150
+ baseline: 'middle',
151
+ fontFamily: theme.font.family
152
+ });
153
+ });
154
+ data.forEach((item, index) => {
155
+ 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];
158
+ const [open, high, low, close] = row;
159
+ const rising = close >= open;
160
+ const color = rising ? upColor : downColor;
161
+ const local = staggerProgress(progress, index, data.length, animConfig.stagger);
162
+
163
+ // 入场时以收盘价为锚点向两端展开,视觉上像「长出一根蜡烛」
164
+ const anchorY = yScale.scale(close);
165
+ const project = value => anchorY + (yScale.scale(value) - anchorY) * local;
166
+ const yHigh = project(high);
167
+ const yLow = project(low);
168
+ const yOpen = project(open);
169
+ const yClose = project(close);
170
+ const bodyTop = Math.min(yOpen, yClose);
171
+ const bodyHeight = Math.max(1, Math.abs(yClose - yOpen));
172
+ nodes.push({
173
+ kind: 'line',
174
+ key: `wick-${index}`,
175
+ x1: cx,
176
+ y1: yHigh,
177
+ x2: cx,
178
+ y2: yLow,
179
+ stroke: color,
180
+ strokeWidth: 1,
181
+ pointerEvents: 'none'
182
+ });
183
+ nodes.push({
184
+ kind: 'rect',
185
+ key: `body-${index}`,
186
+ x: cx - bodyWidth / 2,
187
+ y: bodyTop,
188
+ width: bodyWidth,
189
+ height: bodyHeight,
190
+ radius: 1,
191
+ fill: color,
192
+ opacity: activeIndex === null || activeIndex === index ? 1 : 0.55,
193
+ pointerEvents: 'none'
194
+ });
195
+
196
+ // 成交量副图
197
+ if (hasVolume && geometry.volumeHeight > 0) {
198
+ const volume = row[4] ?? 0;
199
+ const barHeight = Math.max(1, volume / volumeMax * geometry.volumeHeight * local);
200
+ nodes.push({
201
+ kind: 'rect',
202
+ key: `volume-${index}`,
203
+ x: cx - bodyWidth / 2,
204
+ y: geometry.volumeTop + geometry.volumeHeight - barHeight,
205
+ width: bodyWidth,
206
+ height: barHeight,
207
+ radius: 1,
208
+ fill: withAlpha(color, 0.55),
209
+ pointerEvents: 'none'
210
+ });
211
+ }
212
+
213
+ // x 轴标签:密集时抽样,避免压字
214
+ const labelStep = Math.max(1, Math.ceil(data.length / 8));
215
+ if (index % labelStep === 0 || index === data.length - 1) {
216
+ nodes.push({
217
+ kind: 'text',
218
+ key: `xl-${index}`,
219
+ x: cx,
220
+ y: geometry.top + geometry.plotHeight + theme.font.size + 4,
221
+ text: item.date,
222
+ fill: theme.axis.label,
223
+ fontSize: theme.font.size,
224
+ anchor: 'middle',
225
+ fontFamily: theme.font.family
226
+ });
227
+ }
228
+ });
229
+
230
+ // 均线
231
+ maSeries.forEach(item => {
232
+ const points = item.values.map((value, index) => {
233
+ if (value === null) return null;
234
+ const cx = xScale.center(data[index].date);
235
+ if (cx === undefined) return null;
236
+ const target = yScale.scale(value);
237
+ 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;
245
+ nodes.push({
246
+ kind: 'path',
247
+ key: `ma-${item.period}`,
248
+ d,
249
+ fill: 'none',
250
+ stroke: item.color,
251
+ strokeWidth: 1.4,
252
+ linejoin: 'round',
253
+ pointerEvents: 'none'
254
+ });
255
+ });
256
+ 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 => {
259
+ const element = ref.current;
260
+ if (!element || xScale.step <= 0) return null;
261
+ const rect = element.getBoundingClientRect();
262
+ const localX = clientX - rect.left - geometry.left;
263
+ if (localX < 0) return null;
264
+ const index = Math.floor(localX / xScale.step);
265
+ return index >= 0 && index < data.length ? index : null;
266
+ };
267
+ const active = activeIndex !== null ? data[activeIndex] : null;
268
+ const tooltipPayload = active ? {
269
+ label: active.date,
270
+ 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
+ }] : [])]
312
+ } : 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
+ }
@@ -0,0 +1,17 @@
1
+ import React from 'react';
2
+ import type { BaseChartProps } from '../../types';
3
+ export interface ComboChartProps extends BaseChartProps {
4
+ stack?: boolean;
5
+ }
6
+ /**
7
+ * 折柱混合图。
8
+ *
9
+ * 没有独立实现:直接复用直角坐标系内核,由每个 series 的 type 决定画法。
10
+ * 之所以单独导出,是因为「收入用柱、转化率用线」这类双轴需求在业务里极常见,
11
+ * 给个语义化的名字比让使用者记 defaultType 更友好。
12
+ *
13
+ * 双轴:给系列加 `yAxisIndex: 1`,并开启 `yAxisRight`,即可让该系列读右侧轴。
14
+ * 仍是那句话——双轴只在量纲差一个数量级以上时使用,且两根轴都要写标题。
15
+ */
16
+ export declare function ComboChart({ stack, series, ...rest }: ComboChartProps): React.JSX.Element;
17
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAGlD,MAAM,WAAW,eAAgB,SAAQ,cAAc;IACrD,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CAAC,EACzB,KAAa,EACb,MAAM,EACN,GAAG,IAAI,EACR,EAAE,eAAe,qBAIjB"}
@@ -0,0 +1,25 @@
1
+ import React from 'react';
2
+ 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({
15
+ stack = false,
16
+ series,
17
+ ...rest
18
+ }) {
19
+ return /*#__PURE__*/_jsx(CartesianChart, {
20
+ ...rest,
21
+ series: series,
22
+ defaultType: "bar",
23
+ stack: stack
24
+ });
25
+ }