@363045841yyt/klinechart 0.5.0-alpha.2 → 0.5.1
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/README.md +126 -259
- package/dist/index.cjs +9 -9
- package/dist/index.js +1841 -1624
- package/dist/klinechart.css +1 -1
- package/dist/src/components/LeftToolbar.vue.d.ts +4 -0
- package/dist/src/core/chart-store.d.ts +74 -0
- package/dist/src/core/chart.d.ts +17 -2
- package/dist/src/core/controller/interaction.d.ts +9 -0
- package/dist/src/core/drawing/interaction.d.ts +2 -1
- package/dist/src/plugin/types.d.ts +2 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,259 +1,126 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
[
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
-
|
|
30
|
-
-
|
|
31
|
-
-
|
|
32
|
-
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
},
|
|
128
|
-
indicators: {
|
|
129
|
-
main: [{ type: 'MA', enabled: true, params: { periods: [5, 10, 20] } }],
|
|
130
|
-
sub: [{ type: 'MACD', enabled: true }],
|
|
131
|
-
},
|
|
132
|
-
chart: {
|
|
133
|
-
kWidth: 10,
|
|
134
|
-
kGap: 2,
|
|
135
|
-
autoScrollToRight: true,
|
|
136
|
-
},
|
|
137
|
-
})
|
|
138
|
-
</script>
|
|
139
|
-
```
|
|
140
|
-
|
|
141
|
-
### 语义化 JSON 控制(Agent 模式)
|
|
142
|
-
|
|
143
|
-
通过 `semanticConfig` prop,AI Agent 可以用 JSON 配置完整控制图表渲染:
|
|
144
|
-
|
|
145
|
-
```vue
|
|
146
|
-
<template>
|
|
147
|
-
<KLineChart :semanticConfig="config" />
|
|
148
|
-
</template>
|
|
149
|
-
|
|
150
|
-
<script setup lang="ts">
|
|
151
|
-
import { ref } from 'vue'
|
|
152
|
-
import type { SemanticChartConfig } from '@363045841yyt/klinechart'
|
|
153
|
-
|
|
154
|
-
const config = ref<SemanticChartConfig>({
|
|
155
|
-
version: '1.0.0',
|
|
156
|
-
data: {
|
|
157
|
-
source: 'baostock',
|
|
158
|
-
symbol: '600519',
|
|
159
|
-
exchange: 'SH',
|
|
160
|
-
startDate: '2025-01-01',
|
|
161
|
-
endDate: '2025-04-18',
|
|
162
|
-
period: 'daily',
|
|
163
|
-
adjust: 'qfq',
|
|
164
|
-
},
|
|
165
|
-
indicators: {
|
|
166
|
-
main: [{ type: 'MA', enabled: true, params: { periods: [5, 10, 20] } }],
|
|
167
|
-
sub: [{ type: 'MACD', enabled: true }],
|
|
168
|
-
},
|
|
169
|
-
markers: {
|
|
170
|
-
customMarkers: [
|
|
171
|
-
{
|
|
172
|
-
id: 'buy_001',
|
|
173
|
-
date: '2025-02-15',
|
|
174
|
-
shape: 'arrow_up',
|
|
175
|
-
label: { text: '买入' },
|
|
176
|
-
style: { fillColor: '#52c41a' },
|
|
177
|
-
},
|
|
178
|
-
],
|
|
179
|
-
},
|
|
180
|
-
})
|
|
181
|
-
</script>
|
|
182
|
-
```
|
|
183
|
-
|
|
184
|
-
详细配置说明请参阅 [语义化配置文档](./docs/semantic-config.md)。
|
|
185
|
-
|
|
186
|
-
## 数据源配置
|
|
187
|
-
|
|
188
|
-
### BaoStock(推荐)
|
|
189
|
-
|
|
190
|
-
免费开源的 Python 证券数据接口,每日支持十万次 API 调用。
|
|
191
|
-
|
|
192
|
-
```bash
|
|
193
|
-
# 方式一:手动安装并启动
|
|
194
|
-
uv pip install baostock
|
|
195
|
-
git clone https://github.com/363045841/stockbao.git
|
|
196
|
-
cd stockbao
|
|
197
|
-
uv run python ./server.py
|
|
198
|
-
|
|
199
|
-
# 方式二:使用项目内置脚本(需将 stockbao 克隆到父目录)
|
|
200
|
-
pnpm stockbao
|
|
201
|
-
```
|
|
202
|
-
|
|
203
|
-
### AKTools
|
|
204
|
-
|
|
205
|
-
基于 Python 的开源财经数据接口,数据来源于东方财富等公开渠道。
|
|
206
|
-
|
|
207
|
-
```bash
|
|
208
|
-
uv pip install aktools
|
|
209
|
-
uv run python -m aktools # 启动服务
|
|
210
|
-
```
|
|
211
|
-
|
|
212
|
-
> ⚠️ 注意:AKTools 采取直连 API,频繁请求可能触发反爬机制
|
|
213
|
-
|
|
214
|
-
### 组件属性
|
|
215
|
-
|
|
216
|
-
| 属性 | 类型 | 默认值 | 说明 |
|
|
217
|
-
|------|------|--------|------|
|
|
218
|
-
| semanticConfig | SemanticChartConfig | - | **必需**。语义化配置(唯一控制源) |
|
|
219
|
-
| yPaddingPx | number | 0 | Y 轴上下留白像素 |
|
|
220
|
-
| minKWidth | number | 2 | K 线最小宽度 |
|
|
221
|
-
| maxKWidth | number | 50 | K 线最大宽度 |
|
|
222
|
-
| rightAxisWidth | number | 0 | 右侧价格轴宽度 |
|
|
223
|
-
| bottomAxisHeight | number | 24 | 底部时间轴高度 |
|
|
224
|
-
| priceLabelWidth | number | 60 | 价格标签额外宽度(用于显示涨跌幅) |
|
|
225
|
-
| zoomLevels | number | 20 | 缩放级别数量 |
|
|
226
|
-
| initialZoomLevel | number | 3 | 初始缩放级别(1 ~ zoomLevels) |
|
|
227
|
-
|
|
228
|
-
## 环境要求
|
|
229
|
-
|
|
230
|
-
- Node.js: ^20.19.0 || >=22.12.0
|
|
231
|
-
- pnpm: 包管理器
|
|
232
|
-
- Python: 用于运行数据源服务(可选)
|
|
233
|
-
- uv: Python 包管理器
|
|
234
|
-
|
|
235
|
-
## 构建与部署
|
|
236
|
-
|
|
237
|
-
```bash
|
|
238
|
-
pnpm build # 生产环境构建
|
|
239
|
-
pnpm preview # 预览生产包
|
|
240
|
-
```
|
|
241
|
-
|
|
242
|
-
## 相关链接
|
|
243
|
-
|
|
244
|
-
- [NPM 包地址](https://www.npmjs.com/package/@363045841yyt/klinechart)
|
|
245
|
-
- [GitHub 仓库](https://github.com/363045841/KLineChartQuant)
|
|
246
|
-
- [Vue.js 官方文档](https://vuejs.org/guide/introduction.html)
|
|
247
|
-
- [Vite 官方文档](https://vite.dev/guide/)
|
|
248
|
-
- [BaoStock 官方文档](http://baostock.com/)
|
|
249
|
-
- [AKTools 官方文档](https://github.com/akfamily/aktools)
|
|
250
|
-
- [Canvas API MDN 文档](https://developer.mozilla.org/zh-CN/docs/Web/API/Canvas_API)
|
|
251
|
-
- [Vitest 官方文档](https://vitest.dev/)
|
|
252
|
-
- [语义化配置文档](./docs/semantic-config.md) - Agent JSON 配置说明
|
|
253
|
-
- [架构文档(ResizeObserver 重构版)](./docs/architecture.md)
|
|
254
|
-
- [系统架构综述](./docs/system-architecture-overview.md)
|
|
255
|
-
- [渲染器开发指南](./docs/renderer-development-guide.md)
|
|
256
|
-
|
|
257
|
-
## 许可证
|
|
258
|
-
|
|
259
|
-
本项目采用 MIT 许可证,详情请见 [LICENSE](./LICENSE) 文件。
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
English | [简体中文](README_CN.md)
|
|
4
|
+
|
|
5
|
+
# 📈 KLineChartQuant
|
|
6
|
+
|
|
7
|
+
**Crisp Rendering · High Performance · Optimized Interaction**
|
|
8
|
+
|
|
9
|
+
[](https://www.npmjs.com/package/@363045841yyt/klinechart) [](https://www.npmjs.com/package/@363045841yyt/klinechart) [](https://github.com/363045841/klinechart/blob/main/LICENSE) [](http://8.130.98.164/)
|
|
10
|
+
|
|
11
|
+
[](https://qm.qq.com/q/672011965) [](https://t.me/+1o-6B-wVRTU2MjQ9)
|
|
12
|
+
|
|
13
|
+
</div>
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
A lightweight financial K-line charting library focused on quantitative trading scenarios. **Agent is a first-class citizen** — supports AI Agent direct control of chart operations, providing TradingView-level interaction experience.
|
|
18
|
+
|
|
19
|
+
<div align="center">
|
|
20
|
+
<img src="https://files.seeusercontent.com/2026/05/13/vF8x/pasted-image-1778672929115.webp" width="400" style="border-radius: 12px; margin: 8px;" />
|
|
21
|
+
<img src="https://files.seeusercontent.com/2026/05/13/J8xd/pasted-image-1778672926979.webp" width="400" style="border-radius: 12px; margin: 8px;" />
|
|
22
|
+
<br/>
|
|
23
|
+
<img src="https://files.seeusercontent.com/2026/05/13/vV4u/pasted-image-1778672925611.webp" width="400" style="border-radius: 12px; margin: 8px;" />
|
|
24
|
+
<img src="https://files.seeusercontent.com/2026/05/13/Vyy8/pasted-image-1778672923956.webp" width="400" style="border-radius: 12px; margin: 8px;" />
|
|
25
|
+
</div>
|
|
26
|
+
|
|
27
|
+
## ✨ Core Features
|
|
28
|
+
|
|
29
|
+
- **Agent First** - Supports AI Agent direct control of charts, zoom, pan, and draw operations can all be called programmatically
|
|
30
|
+
- **Crisp Rendering** - Full-chain ResizeObserver driven, physical pixel alignment, K-lines, wicks, and lines are sharp and clear on all DPR screens
|
|
31
|
+
- **Plugin Architecture** - Renderer plugin-based design, supporting dynamic registration, configuration, and lifecycle management
|
|
32
|
+
- **Custom Markers** - Supports semantic configuration of custom markers and custom information
|
|
33
|
+
- **High Performance** - Smoothly handles tens of thousands of data points, no lag during zoom or pan
|
|
34
|
+
- **Optimized Interaction** - Stable zoom anchor, precise crosshair cursor, smooth drag
|
|
35
|
+
|
|
36
|
+
## 🚀 Quick Start
|
|
37
|
+
|
|
38
|
+
### Prerequisites
|
|
39
|
+
|
|
40
|
+
KLineChart requires a stock data backend. Please ensure `kmap` and `stockbao` are in the same directory:
|
|
41
|
+
|
|
42
|
+
```
|
|
43
|
+
workspace/
|
|
44
|
+
├── kmap/ # This repository
|
|
45
|
+
└── stockbao/ # Data backend repository
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### 1. Clone Repositories
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
git clone https://github.com/363045841/kmap.git
|
|
52
|
+
git clone https://github.com/363045841/stockbao.git
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### 2. Start Data Backend
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
cd kmap
|
|
59
|
+
npm run stockbao
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
After startup, the API is available at `http://localhost:8000`
|
|
63
|
+
|
|
64
|
+
### 3. Install and Use
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
npm install @363045841yyt/klinechart
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
```vue
|
|
71
|
+
<script setup lang="ts">
|
|
72
|
+
import KLineChart from '@363045841yyt/klinechart';
|
|
73
|
+
import type { SemanticChartConfig } from '@363045841yyt/klinechart';
|
|
74
|
+
|
|
75
|
+
const config: SemanticChartConfig = {
|
|
76
|
+
version: '1.0.0',
|
|
77
|
+
data: {
|
|
78
|
+
source: 'baostock',
|
|
79
|
+
code: 'sh.000001',
|
|
80
|
+
startDate: '2024-01-01',
|
|
81
|
+
endDate: '2024-12-31',
|
|
82
|
+
frequency: 'day'
|
|
83
|
+
},
|
|
84
|
+
indicators: {
|
|
85
|
+
main: [{ type: 'MA', params: [5, 10, 20] }],
|
|
86
|
+
sub: [{ type: 'MACD' }]
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
</script>
|
|
90
|
+
|
|
91
|
+
<template>
|
|
92
|
+
<KLineChart
|
|
93
|
+
:semanticConfig="config"
|
|
94
|
+
:kWidth="7"
|
|
95
|
+
:kGap="3"
|
|
96
|
+
:yPaddingPx="24"
|
|
97
|
+
/>
|
|
98
|
+
</template>
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## 📖 More Documentation
|
|
102
|
+
|
|
103
|
+
- [Rendering Engine Architecture](./docs/rendering-engine-architecture.md) - Core rendering pipeline and physical pixel alignment mechanism
|
|
104
|
+
- [Plugin System](./docs/PLUGIN_SYSTEM.md) - Extension mechanism and custom development
|
|
105
|
+
- [Renderer Development Guide](./docs/renderer-development-guide.md) - Custom renderer development
|
|
106
|
+
|
|
107
|
+
## 🗺️ Roadmap
|
|
108
|
+
|
|
109
|
+
- [x] K-line zoom anchor stability, improved zoom feel
|
|
110
|
+
- [x] Right axis detached from scroll container, completely solving clipping issues
|
|
111
|
+
- [x] Blank area drawing support
|
|
112
|
+
- [x] Limit vertical pan range to prevent viewport from leaving data
|
|
113
|
+
- [x] Drawing system
|
|
114
|
+
- [x] Right axis zoom
|
|
115
|
+
- [x] Latest price line and right axis label style optimization
|
|
116
|
+
- [ ] Area primitive tools and rendering
|
|
117
|
+
- [ ] More advanced drawing tools
|
|
118
|
+
|
|
119
|
+
## 🚀 What's New
|
|
120
|
+
|
|
121
|
+
- **v0.5.0** Complete drawing tool system, supporting line, rectangle, text drawing and style editing
|
|
122
|
+
- **v0.4** Modern UI, left toolbar, right axis optimization, TradingView-style zoom feel
|
|
123
|
+
|
|
124
|
+
## 📄 License
|
|
125
|
+
|
|
126
|
+
[MIT](LICENSE)
|