@quantlife/qlchart 0.0.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.
Files changed (321) hide show
  1. package/.idea/QLChart.iml +12 -0
  2. package/.idea/modules.xml +8 -0
  3. package/.idea/vcs.xml +6 -0
  4. package/README.md +75 -0
  5. package/demo/App.css +213 -0
  6. package/demo/App.tsx +46 -0
  7. package/demo/components/ControlPanel.tsx +13 -0
  8. package/demo/components/DemoNav.tsx +27 -0
  9. package/demo/index.html +16 -0
  10. package/demo/main.tsx +10 -0
  11. package/demo/pages/BasicChartDemo.tsx +61 -0
  12. package/demo/pages/DrawingDemo.tsx +22 -0
  13. package/demo/pages/IndicatorDemo.tsx +22 -0
  14. package/demo/pages/LayoutDemo.tsx +35 -0
  15. package/demo/pages/MultiPeriodDemo.tsx +31 -0
  16. package/demo/pages/ReplayDemo.tsx +195 -0
  17. package/demo/pages/SaveDemo.tsx +27 -0
  18. package/demo/pages/ThemeDemo.tsx +29 -0
  19. package/demo/standalone-demo.html +597 -0
  20. package/demo/vite.config.demo.ts +17 -0
  21. package/dist/index.d.ts +1973 -0
  22. package/dist/qlchart.js +23169 -0
  23. package/dist/style.css +1 -0
  24. package/doc/api/indicator-data-processor.md +35 -0
  25. package/doc/api-reference/.nojekyll +1 -0
  26. package/doc/api-reference/assets/hierarchy.js +1 -0
  27. package/doc/api-reference/assets/highlight.css +43 -0
  28. package/doc/api-reference/assets/icons.js +18 -0
  29. package/doc/api-reference/assets/icons.svg +1 -0
  30. package/doc/api-reference/assets/main.js +60 -0
  31. package/doc/api-reference/assets/navigation.js +1 -0
  32. package/doc/api-reference/assets/search.js +1 -0
  33. package/doc/api-reference/assets/style.css +1611 -0
  34. package/doc/api-reference/classes/ChartManager.html +16 -0
  35. package/doc/api-reference/classes/DataManager.html +13 -0
  36. package/doc/api-reference/classes/DrawingAdapter.html +64 -0
  37. package/doc/api-reference/classes/DrawingPersistence.html +21 -0
  38. package/doc/api-reference/classes/EventManager.html +12 -0
  39. package/doc/api-reference/classes/HollowCandlestickSeries.html +22 -0
  40. package/doc/api-reference/classes/IndicatorRenderer.html +20 -0
  41. package/doc/api-reference/classes/KlineReplay.html +31 -0
  42. package/doc/api-reference/classes/MockDataService.html +13 -0
  43. package/doc/api-reference/classes/MockIndicatorService.html +4 -0
  44. package/doc/api-reference/classes/OverlayIndicator.html +11 -0
  45. package/doc/api-reference/classes/PaneIndicator.html +16 -0
  46. package/doc/api-reference/classes/PaneManager.html +24 -0
  47. package/doc/api-reference/classes/RealtimeDataFeed.html +22 -0
  48. package/doc/api-reference/classes/RenkoSeries.html +22 -0
  49. package/doc/api-reference/classes/ScreenshotUtil.html +10 -0
  50. package/doc/api-reference/classes/SeriesManager.html +30 -0
  51. package/doc/api-reference/classes/ThemeManager.html +18 -0
  52. package/doc/api-reference/enums/ChartEvent.html +12 -0
  53. package/doc/api-reference/enums/IndicatorType.html +4 -0
  54. package/doc/api-reference/enums/SeriesType.html +13 -0
  55. package/doc/api-reference/functions/ChartFunctionMenu.html +1 -0
  56. package/doc/api-reference/functions/DrawingModule.html +8 -0
  57. package/doc/api-reference/functions/IndicatorPanel.html +2 -0
  58. package/doc/api-reference/functions/IndicatorTag.html +2 -0
  59. package/doc/api-reference/functions/KlineTypeSelector.html +1 -0
  60. package/doc/api-reference/functions/LayoutSwitcher.html +1 -0
  61. package/doc/api-reference/functions/PeriodSelector.html +1 -0
  62. package/doc/api-reference/functions/QLChartLayout.html +1 -0
  63. package/doc/api-reference/functions/QLChartPanel.html +10 -0
  64. package/doc/api-reference/functions/QLChartProvider.html +2 -0
  65. package/doc/api-reference/functions/QLToolbar.html +1 -0
  66. package/doc/api-reference/functions/ReplayController.html +1 -0
  67. package/doc/api-reference/functions/TimeBarModule.html +4 -0
  68. package/doc/api-reference/functions/TimeRangeSelector.html +1 -0
  69. package/doc/api-reference/functions/createIndicatorConfig.html +2 -0
  70. package/doc/api-reference/functions/getToolConfig.html +2 -0
  71. package/doc/api-reference/functions/getToolsByCategory.html +2 -0
  72. package/doc/api-reference/functions/getToolsByPriority.html +2 -0
  73. package/doc/api-reference/functions/mapLibTypeToOurs.html +2 -0
  74. package/doc/api-reference/functions/mapToolTypeToLib.html +3 -0
  75. package/doc/api-reference/functions/transformCandlestickData.html +3 -0
  76. package/doc/api-reference/functions/transformIndicatorData.html +2 -0
  77. package/doc/api-reference/functions/transformVolumeData.html +3 -0
  78. package/doc/api-reference/functions/useChart.html +4 -0
  79. package/doc/api-reference/functions/useChartStore.html +8 -0
  80. package/doc/api-reference/functions/useCrosshairSync.html +8 -0
  81. package/doc/api-reference/functions/useDrawingModule.html +1 -0
  82. package/doc/api-reference/functions/useDrawingStore.html +8 -0
  83. package/doc/api-reference/functions/useIndicatorStore.html +8 -0
  84. package/doc/api-reference/functions/useQLChartConfig.html +2 -0
  85. package/doc/api-reference/functions/useReplayStore.html +8 -0
  86. package/doc/api-reference/functions/useTheme.html +2 -0
  87. package/doc/api-reference/functions/useTimeBarStore.html +8 -0
  88. package/doc/api-reference/index.html +1 -0
  89. package/doc/api-reference/interfaces/CandlestickData.html +7 -0
  90. package/doc/api-reference/interfaces/CandlestickRawData.html +8 -0
  91. package/doc/api-reference/interfaces/ChartFunctionMenuProps.html +2 -0
  92. package/doc/api-reference/interfaces/ChartManagerCreateOptions.html +4 -0
  93. package/doc/api-reference/interfaces/ChartOptions.html +8 -0
  94. package/doc/api-reference/interfaces/ChartRequestParams.html +8 -0
  95. package/doc/api-reference/interfaces/ChartResponse.html +5 -0
  96. package/doc/api-reference/interfaces/ChartState.html +24 -0
  97. package/doc/api-reference/interfaces/ChartThemeOptions.html +5 -0
  98. package/doc/api-reference/interfaces/CrosshairData.html +5 -0
  99. package/doc/api-reference/interfaces/DrawingModuleProps.html +5 -0
  100. package/doc/api-reference/interfaces/DrawingState.html +48 -0
  101. package/doc/api-reference/interfaces/HistogramData.html +5 -0
  102. package/doc/api-reference/interfaces/HollowCandlestickData.html +14 -0
  103. package/doc/api-reference/interfaces/IndicatorConfig.html +11 -0
  104. package/doc/api-reference/interfaces/IndicatorDataPoint.html +4 -0
  105. package/doc/api-reference/interfaces/IndicatorDataResponse.html +5 -0
  106. package/doc/api-reference/interfaces/IndicatorDefinition.html +9 -0
  107. package/doc/api-reference/interfaces/IndicatorPanelProps.html +3 -0
  108. package/doc/api-reference/interfaces/IndicatorParamDef.html +8 -0
  109. package/doc/api-reference/interfaces/IndicatorRawData.html +4 -0
  110. package/doc/api-reference/interfaces/IndicatorState.html +19 -0
  111. package/doc/api-reference/interfaces/IndicatorTagProps.html +2 -0
  112. package/doc/api-reference/interfaces/KlineReplayOptions.html +4 -0
  113. package/doc/api-reference/interfaces/LayoutSwitcherProps.html +3 -0
  114. package/doc/api-reference/interfaces/LineData.html +4 -0
  115. package/doc/api-reference/interfaces/MockDataConfig.html +8 -0
  116. package/doc/api-reference/interfaces/MockIndicatorConfig.html +5 -0
  117. package/doc/api-reference/interfaces/PairInfo.html +6 -0
  118. package/doc/api-reference/interfaces/PaneInfo.html +6 -0
  119. package/doc/api-reference/interfaces/PanelConfig.html +9 -0
  120. package/doc/api-reference/interfaces/PersistenceConfig.html +12 -0
  121. package/doc/api-reference/interfaces/QLChartConfig.html +18 -0
  122. package/doc/api-reference/interfaces/QLChartLayoutProps.html +9 -0
  123. package/doc/api-reference/interfaces/QLChartPanelProps.html +13 -0
  124. package/doc/api-reference/interfaces/QLChartPanelRef.html +14 -0
  125. package/doc/api-reference/interfaces/QLToolbarProps.html +7 -0
  126. package/doc/api-reference/interfaces/RealtimeCandle.html +9 -0
  127. package/doc/api-reference/interfaces/RealtimeSubscribeFn.html +2 -0
  128. package/doc/api-reference/interfaces/RenkoData.html +16 -0
  129. package/doc/api-reference/interfaces/ReplayControllerProps.html +2 -0
  130. package/doc/api-reference/interfaces/ReplayState.html +19 -0
  131. package/doc/api-reference/interfaces/ThemeConfig.html +14 -0
  132. package/doc/api-reference/interfaces/TimeBarModuleProps.html +5 -0
  133. package/doc/api-reference/interfaces/TimeBarState.html +13 -0
  134. package/doc/api-reference/interfaces/UseChartReturn.html +4 -0
  135. package/doc/api-reference/interfaces/UseDrawingModuleOptions.html +11 -0
  136. package/doc/api-reference/interfaces/UseDrawingModuleReturn.html +6 -0
  137. package/doc/api-reference/interfaces/UseThemeReturn.html +5 -0
  138. package/doc/api-reference/types/EventHandler.html +2 -0
  139. package/doc/api-reference/types/FetchFn.html +2 -0
  140. package/doc/api-reference/types/LayoutMode.html +2 -0
  141. package/doc/api-reference/types/MarketTrend.html +2 -0
  142. package/doc/api-reference/types/ThemePreset.html +2 -0
  143. package/doc/api-reference/variables/BUILTIN_INDICATORS.html +2 -0
  144. package/doc/api-reference/variables/CATEGORY_LABELS.html +2 -0
  145. package/doc/api-reference/variables/DRAWING_TOOLS.html +3 -0
  146. package/doc/api-reference/variables/MARKET_PRESETS.html +1 -0
  147. package/doc/api-reference/variables/PAIR_PRESETS.html +1 -0
  148. package/doc/api-reference/variables/darkPreset.html +1 -0
  149. package/doc/api-reference/variables/lightPreset.html +1 -0
  150. package/doc/components/drawing-module.md +24 -0
  151. package/doc/components/indicator-list-panel.md +24 -0
  152. package/doc/components/indicator-panel.md +17 -0
  153. package/doc/components/pane-divider.md +25 -0
  154. package/doc/components/qlchart-layout.md +30 -0
  155. package/doc/components/qlchart-panel.md +93 -0
  156. package/doc/components/qlchart-provider.md +73 -0
  157. package/doc/components/qltoolbar.md +17 -0
  158. package/doc/components/replay-controller.md +23 -0
  159. package/doc/components/timebar-module.md +13 -0
  160. package/doc/core/chart-manager.md +14 -0
  161. package/doc/core/data-manager.md +33 -0
  162. package/doc/core/event-manager.md +26 -0
  163. package/doc/core/pane-manager.md +13 -0
  164. package/doc/core/series-manager.md +19 -0
  165. package/doc/core/theme-manager.md +21 -0
  166. package/doc/examples/basic-chart.md +24 -0
  167. package/doc/examples/data-format-guide.md +119 -0
  168. package/doc/examples/drawing-tools.md +30 -0
  169. package/doc/examples/indicator-properties.md +34 -0
  170. package/doc/examples/multi-pane.md +24 -0
  171. package/doc/examples/multi-panel.md +23 -0
  172. package/doc/examples/realtime-data.md +147 -0
  173. package/doc/examples/standalone-js.md +333 -0
  174. package/doc/guide/architecture.md +87 -0
  175. package/doc/guide/data-flow.md +310 -0
  176. package/doc/guide/deployment.md +59 -0
  177. package/doc/guide/drawing-properties.md +40 -0
  178. package/doc/guide/getting-started.md +94 -0
  179. package/doc/guide/pane-system.md +47 -0
  180. package/doc/guide/theme-switching.md +58 -0
  181. package/doc/hooks/use-chart.md +20 -0
  182. package/doc/hooks/use-crosshair-sync.md +14 -0
  183. package/doc/hooks/use-drawing-module.md +43 -0
  184. package/doc/hooks/use-theme.md +15 -0
  185. package/doc/index.md +33 -0
  186. package/doc/plugins/drawing/overview.md +36 -0
  187. package/doc/plugins/drawing/persistence.md +42 -0
  188. package/doc/plugins/drawing/tool-registry.md +29 -0
  189. package/doc/plugins/hollow-candlestick.md +18 -0
  190. package/doc/plugins/indicators.md +28 -0
  191. package/doc/plugins/renko.md +17 -0
  192. package/doc/plugins/replay.md +21 -0
  193. package/doc/plugins/screenshot.md +20 -0
  194. package/docs/api.md +94 -0
  195. package/package.json +54 -0
  196. package/python/qlchart/__init__.py +9 -0
  197. package/python/qlchart/__pycache__/__init__.cpython-311.pyc +0 -0
  198. package/python/qlchart/__pycache__/chart.cpython-311.pyc +0 -0
  199. package/python/qlchart/chart.py +333 -0
  200. package/python/qlchart/templates/chart_template.html +304 -0
  201. package/python/requirements.txt +1 -0
  202. package/python/setup.py +18 -0
  203. package/python/tests/__init__.py +1 -0
  204. package/python/tests/__pycache__/__init__.cpython-311.pyc +0 -0
  205. package/python/tests/__pycache__/test_chart.cpython-311-pytest-8.3.3.pyc +0 -0
  206. package/python/tests/test_chart.py +114 -0
  207. package/quantlife-qlchart-0.0.1.tgz +0 -0
  208. package/src/api/chartApi.ts +30 -0
  209. package/src/api/indicatorApi.ts +27 -0
  210. package/src/components/ChartFunctionMenu.tsx +64 -0
  211. package/src/components/PaneChartPanel.tsx +116 -0
  212. package/src/components/PaneDivider.tsx +66 -0
  213. package/src/components/QLChartLayout.tsx +151 -0
  214. package/src/components/QLChartPanel.tsx +560 -0
  215. package/src/components/QLChartProvider.tsx +90 -0
  216. package/src/components/context-menu/ChartContextMenu.tsx +139 -0
  217. package/src/components/context-menu/index.ts +2 -0
  218. package/src/components/drawing/DrawingModule.tsx +36 -0
  219. package/src/components/drawing/DrawingPropertyPanel.tsx +347 -0
  220. package/src/components/drawing/DrawingToolbar.tsx +305 -0
  221. package/src/components/drawing/index.ts +5 -0
  222. package/src/components/index.ts +43 -0
  223. package/src/components/indicator/IndicatorListPanel.tsx +94 -0
  224. package/src/components/indicator/IndicatorModal.tsx +171 -0
  225. package/src/components/indicator/IndicatorPanel.tsx +9 -0
  226. package/src/components/indicator/IndicatorPropertyPanel.tsx +130 -0
  227. package/src/components/indicator/IndicatorTag.tsx +173 -0
  228. package/src/components/indicator/index.ts +4 -0
  229. package/src/components/replay/ReplayController.css +97 -0
  230. package/src/components/replay/ReplayController.tsx +138 -0
  231. package/src/components/timebar/TimeBarModule.tsx +30 -0
  232. package/src/components/timebar/TimeRangeSelector.tsx +96 -0
  233. package/src/components/timebar/index.ts +3 -0
  234. package/src/components/toolbar/GlobalToolbar.tsx +58 -0
  235. package/src/components/toolbar/KlineTypeSelector.tsx +123 -0
  236. package/src/components/toolbar/LayoutSwitcher.tsx +45 -0
  237. package/src/components/toolbar/PeriodSelector.tsx +35 -0
  238. package/src/components/toolbar/QLToolbar.tsx +71 -0
  239. package/src/components/toolbar/TimeRangeSelector.tsx +89 -0
  240. package/src/components/ui/Modal.tsx +67 -0
  241. package/src/core/ChartManager.ts +95 -0
  242. package/src/core/DataManager.ts +427 -0
  243. package/src/core/EventManager.ts +63 -0
  244. package/src/core/IndicatorDataProcessor.ts +104 -0
  245. package/src/core/PaneManager.ts +121 -0
  246. package/src/core/RealtimeDataFeed.ts +110 -0
  247. package/src/core/SeriesManager.ts +210 -0
  248. package/src/core/ThemeManager.ts +59 -0
  249. package/src/core/index.ts +10 -0
  250. package/src/css.d.ts +4 -0
  251. package/src/hooks/useChart.ts +62 -0
  252. package/src/hooks/useCrosshairSync.ts +109 -0
  253. package/src/hooks/useDrawingModule.ts +475 -0
  254. package/src/hooks/useTheme.ts +31 -0
  255. package/src/index.ts +170 -0
  256. package/src/mock/MockDataService.ts +102 -0
  257. package/src/mock/MockIndicatorService.ts +40 -0
  258. package/src/mock/index.ts +5 -0
  259. package/src/mock/presets.ts +16 -0
  260. package/src/plugins/drawing/DrawingAdapter.ts +1762 -0
  261. package/src/plugins/drawing/DrawingPersistence.ts +273 -0
  262. package/src/plugins/drawing/DrawingPropertyTemplates.ts +327 -0
  263. package/src/plugins/drawing/DrawingSharedService.ts +125 -0
  264. package/src/plugins/drawing/DrawingToolRegistry.ts +684 -0
  265. package/src/plugins/drawing/TextLabelOverlay.ts +101 -0
  266. package/src/plugins/drawing/colorUtils.ts +53 -0
  267. package/src/plugins/drawing/index.ts +10 -0
  268. package/src/plugins/drawing/lineStyleMap.ts +46 -0
  269. package/src/plugins/drawing/migration.ts +105 -0
  270. package/src/plugins/drawing/patterns/PatternDefinitions.ts +57 -0
  271. package/src/plugins/drawing/patterns/index.ts +2 -0
  272. package/src/plugins/drawing/periodUtils.ts +51 -0
  273. package/src/plugins/indicators/AutoIndicatorRenderer.ts +204 -0
  274. package/src/plugins/indicators/IndicatorRenderer.ts +350 -0
  275. package/src/plugins/indicators/OverlayIndicator.ts +114 -0
  276. package/src/plugins/indicators/PaneIndicator.ts +137 -0
  277. package/src/plugins/indicators/index.ts +4 -0
  278. package/src/plugins/replay/KlineReplay.ts +163 -0
  279. package/src/plugins/replay/index.ts +2 -0
  280. package/src/plugins/screenshot/ScreenshotUtil.ts +123 -0
  281. package/src/plugins/screenshot/index.ts +1 -0
  282. package/src/plugins/series/HollowCandlestickSeries.ts +111 -0
  283. package/src/plugins/series/RenkoSeries.ts +104 -0
  284. package/src/plugins/series/VolumeCandlestickSeries.ts +127 -0
  285. package/src/plugins/series/index.ts +6 -0
  286. package/src/standalone.ts +386 -0
  287. package/src/store/useChartStore.ts +101 -0
  288. package/src/store/useDrawingStore.ts +135 -0
  289. package/src/store/useIndicatorStore.ts +100 -0
  290. package/src/store/usePanelRegistry.ts +50 -0
  291. package/src/store/useReplayStore.ts +42 -0
  292. package/src/store/useTimeBarStore.ts +34 -0
  293. package/src/styles/chart.css +312 -0
  294. package/src/styles/components.css +184 -0
  295. package/src/styles/context-menu.css +60 -0
  296. package/src/styles/drawing.css +524 -0
  297. package/src/styles/indicator-modal.css +216 -0
  298. package/src/styles/indicator-tag.css +210 -0
  299. package/src/styles/pane-chart.css +9 -0
  300. package/src/styles/responsive.css +71 -0
  301. package/src/styles/themes/dark.css +63 -0
  302. package/src/styles/themes/light.css +61 -0
  303. package/src/styles/toolbar.css +129 -0
  304. package/src/types/api.ts +36 -0
  305. package/src/types/chart.ts +44 -0
  306. package/src/types/drawing.ts +265 -0
  307. package/src/types/index.ts +40 -0
  308. package/src/types/indicator.ts +344 -0
  309. package/src/types/series.ts +53 -0
  310. package/src/types/theme.ts +48 -0
  311. package/src/utils/dataTransformer.ts +63 -0
  312. package/src/utils/heikinAshi.ts +41 -0
  313. package/src/utils/index.ts +3 -0
  314. package/src/utils/lineBreak.ts +88 -0
  315. package/src/utils/themePresets.ts +69 -0
  316. package/src/utils/timeFormatter.ts +29 -0
  317. package/src/utils/timeScaleUtils.ts +68 -0
  318. package/tsconfig.json +21 -0
  319. package/typedoc.json +10 -0
  320. package/vite.config.standalone.ts +31 -0
  321. package/vite.config.ts +24 -0
@@ -0,0 +1,87 @@
1
+ # 架构总览
2
+
3
+ QLChart 采用四层架构设计,从底层到上层依次为:
4
+
5
+ ```
6
+ ┌─────────────────────────────────────────────┐
7
+ │ Components 层 │
8
+ │ QLChartProvider / QLChartPanel / QLToolbar │
9
+ ├─────────────────────────────────────────────┤
10
+ │ Hooks 层 │
11
+ │ useChart / useTheme / useDrawingModule │
12
+ ├─────────────────────────────────────────────┤
13
+ │ Core 层 │
14
+ │ ChartManager / SeriesManager / ThemeManager│
15
+ ├─────────────────────────────────────────────┤
16
+ │ Plugins 层 │
17
+ │ DrawingAdapter / IndicatorRenderer / ... │
18
+ └─────────────────────────────────────────────┘
19
+ ```
20
+
21
+ ## 各层职责
22
+
23
+ ### Core 层(核心引擎)
24
+
25
+ 直接操作 `lightweight-charts` API,提供底层能力。
26
+
27
+ | 模块 | 职责 |
28
+ |------|------|
29
+ | **ChartManager** | 管理 `IChartApi` 实例的创建、销毁、配置更新 |
30
+ | **SeriesManager** | 管理 Series 的增删改查,支持主序列和叠加序列 |
31
+ | **ThemeManager** | 主题切换,内置暗色/亮色预设 |
32
+ | **PaneManager** | 多窗格管理(主图 + 副图指标) |
33
+ | **DataManager** | 数据转换和缓存 |
34
+
35
+ ### Plugins 层(功能插件)
36
+
37
+ 独立的功能模块,通过 Adapter 模式与 Core 层交互。
38
+
39
+ | 插件 | 功能 |
40
+ |------|------|
41
+ | **DrawingAdapter** | 21种绘图工具,基于 `lightweight-charts-drawing` |
42
+ | **DrawingPersistence** | 绘图数据后端存储/恢复 |
43
+ | **IndicatorRenderer** | 技术指标渲染(MA/EMA/MACD/RSI/KDJ等) |
44
+ | **ReplayController** | K线回放控制 |
45
+ | **ScreenshotHelper** | 图表截图 |
46
+
47
+ ### Hooks 层(React 绑定)
48
+
49
+ 将 Core + Plugins 封装为 React Hooks,提供响应式状态管理。
50
+
51
+ | Hook | 功能 |
52
+ |------|------|
53
+ | `useChart` | 创建和管理 Chart 实例 |
54
+ | `useTheme` | 主题状态管理 |
55
+ | `useDrawingModule` | 绘图模块集成 |
56
+ | `useCrosshairSync` | 多面板光标同步 |
57
+
58
+ ### Components 层(UI 组件)
59
+
60
+ 面向使用者的 React 组件,组合 Hooks 和 Plugins。
61
+
62
+ | 组件 | 功能 |
63
+ |------|------|
64
+ | `QLChartProvider` | 顶层 Provider,提供全局配置 |
65
+ | `QLChartPanel` | 核心图表面板 |
66
+ | `QLToolbar` | 工具栏(周期切换/序列类型/主题) |
67
+ | `QLChartLayout` | 多面板布局容器 |
68
+ | `DrawingModule` | 绘图工具UI |
69
+ | `IndicatorTag` | 指标标签 |
70
+
71
+ ## 状态管理
72
+
73
+ QLChart 使用 **Zustand** 进行状态管理,分为三个 Store:
74
+
75
+ - **useChartStore** — 图表全局状态(活跃面板、周期、序列类型等)
76
+ - **useDrawingStore** — 绘图工具状态(当前工具、磁铁、选中绘图)
77
+ - **useIndicatorStore** — 指标状态(活跃指标列表)
78
+
79
+ ## 数据流
80
+
81
+ ```
82
+ 用户操作 → Component → Hook → Core/Plugin → lightweight-charts → Canvas渲染
83
+ ↕ ↕
84
+ Store fetchFn/API
85
+ ```
86
+
87
+ 详细数据流参考 [数据流文档](./data-flow)。
@@ -0,0 +1,310 @@
1
+ # 数据流
2
+
3
+ ## 概述
4
+
5
+ QLChart 的数据流遵循单向数据流原则,支持 v1(Demo/Mock)和 v2(后端就绪后启用)两种数据格式。
6
+
7
+ ```
8
+ [后端API / MockDataService]
9
+
10
+
11
+ fetchFn(params)
12
+
13
+
14
+ [QLChartPanel.loadData()]
15
+
16
+ ├── v1格式? ──→ dataTransformer ──→ SeriesManager.setData()
17
+
18
+ └── v2格式? ──→ IndicatorDataProcessor.parse()
19
+
20
+ ├── candlestick/volume → SeriesManager
21
+ ├── overlayIndicators → IndicatorRenderer (overlay)
22
+ └── paneIndicators → IndicatorRenderer (pane)
23
+
24
+
25
+ [lightweight-charts Canvas]
26
+ ```
27
+
28
+ ---
29
+
30
+ ## 数据格式规范
31
+
32
+ ### v1 格式(当前 Demo 使用)
33
+
34
+ 简单的对象数组,每根K线包含 time(毫秒时间戳)和 OHLCV 字段:
35
+
36
+ ```json
37
+ {
38
+ "data": [
39
+ {
40
+ "time": 1718424000000,
41
+ "open": 42000.5,
42
+ "high": 42150.2,
43
+ "low": 41980.1,
44
+ "close": 42120.8,
45
+ "volume": 12500
46
+ },
47
+ {
48
+ "time": 1718427600000,
49
+ "open": 42120.8,
50
+ "high": 42200.0,
51
+ "low": 42050.3,
52
+ "close": 42180.5,
53
+ "volume": 9800
54
+ }
55
+ ]
56
+ }
57
+ ```
58
+
59
+ **特点:**
60
+ - `time` 为**毫秒级** UNIX 时间戳
61
+ - 数据转换器 `transformCandlestickData` 会自动转为 lightweight-charts 所需的**秒级**时间戳
62
+ - 指标数据由前端 `MockIndicatorService` 本地计算
63
+
64
+ ### v2 格式(新架构,后端就绪后启用)
65
+
66
+ 行列混合紧凑格式,减少传输量,支持后端预计算指标:
67
+
68
+ ```json
69
+ {
70
+ "timestamps": [1718424000000, 1718427600000],
71
+ "data": [
72
+ [42000.5, 42150.2, 41980.1, 42120.8, 12500, 41800.3, 42000.1],
73
+ [42120.8, 42200.0, 42050.3, 42180.5, 9800, 41900.5, 42100.2]
74
+ ],
75
+ "ohlcIndex": { "open": 0, "high": 1, "low": 2, "close": 3, "volume": 4 },
76
+ "indicators": [
77
+ {
78
+ "key": "MA5",
79
+ "label": "MA(5)",
80
+ "displayType": "overlay",
81
+ "lines": [
82
+ { "key": "ma", "label": "MA5", "dataIndex": 5, "renderType": "line", "color": "#FF6D00" }
83
+ ]
84
+ },
85
+ {
86
+ "key": "MACD",
87
+ "label": "MACD(12,26,9)",
88
+ "displayType": "pane",
89
+ "lines": [
90
+ { "key": "dif", "label": "DIF", "dataIndex": 6, "renderType": "line", "color": "#2962FF" },
91
+ { "key": "dea", "label": "DEA", "dataIndex": 7, "renderType": "line", "color": "#FF6D00" },
92
+ { "key": "macd", "label": "MACD", "dataIndex": 8, "renderType": "histogram", "color": "#26a69a" }
93
+ ],
94
+ "paneHeightRatio": 0.2
95
+ }
96
+ ],
97
+ "version": 2
98
+ }
99
+ ```
100
+
101
+ **特点:**
102
+ - `timestamps` 和 `data` 平行数组,每行对应一个时间点的所有值
103
+ - `ohlcIndex` 映射 OHLCV 字段在 data 行中的列位置
104
+ - `indicators` 定义指标如何从 data 行中提取和渲染
105
+ - `IndicatorDataProcessor` 负责解析 v2 格式并分发到 SeriesManager / IndicatorRenderer
106
+
107
+ ### 版本兼容机制
108
+
109
+ ```
110
+ fetchFn 返回结果
111
+
112
+ ├── result.version === 2 或 result.timestamps 存在?
113
+ │ ├── 是 → IndicatorDataProcessor.parse(result) [v2 路径]
114
+ │ └── 否 → transformCandlestickData(result.data) [v1 路径]
115
+ ```
116
+
117
+ 两种格式可共存,由返回数据中的 `version` 字段或 `timestamps` 数组自动判断。
118
+
119
+ ---
120
+
121
+ ## 数据流转详解
122
+
123
+ ### 1. K线 + 成交量数据流
124
+
125
+ ```
126
+ QLChartPanel.loadData()
127
+
128
+ ├── fetchFn({ pairId, product, period })
129
+
130
+
131
+ result.data (CandlestickRawData[])
132
+
133
+ ├── transformCandlestickData(result.data) → 毫秒→秒级时间戳
134
+
135
+ ├── transformVolumeData(result.data) → 涨跌着色
136
+
137
+
138
+ SeriesManager
139
+
140
+ ├── addMainSeries(Candlestick) → mainSeries.setData(candlestickData)
141
+
142
+ └── addOverlaySeries(Histogram, 'volume') → volumeSeries.setData(volumeData)
143
+
144
+
145
+ chart.priceScale('volume').applyOptions(
146
+ scaleMargins: { top: 0.8, bottom: 0 }
147
+ )
148
+ ```
149
+
150
+ ### 2. 指标数据流
151
+
152
+ #### v1 路径(前端 Mock)
153
+
154
+ ```
155
+ useIndicatorStore.activeIndicators 变化
156
+
157
+
158
+ QLChartPanel effect 触发
159
+
160
+ ├── MockIndicatorService.generate({ name, count })
161
+
162
+
163
+ IndicatorRenderer.renderIndicator(indicator, mockData)
164
+
165
+ ├── displayType === 'overlay' → OverlayIndicator → 主图叠加
166
+
167
+ └── displayType === 'pane' → PaneIndicator → LWC v5 原生 pane 子图
168
+ ```
169
+
170
+ #### v2 路径(后端预计算)
171
+
172
+ ```
173
+ fetchFn 返回 v2 格式
174
+
175
+
176
+ IndicatorDataProcessor.parse(result)
177
+
178
+ ├── 提取 candlestick/volume → 走 SeriesManager 标准流程
179
+
180
+ └── 遍历 result.indicators
181
+
182
+ ├── displayType === 'overlay' → IndicatorRenderer 渲染到主图
183
+
184
+ └── displayType === 'pane' → IndicatorRenderer 渲染到 pane 子图
185
+ (paneHeightRatio 控制高度比)
186
+ ```
187
+
188
+ ### 3. 绘图持久化数据流
189
+
190
+ ```
191
+ ─── 绘制阶段 ──
192
+ 用户鼠标操作 → DrawingManager → DrawingAdapter
193
+
194
+
195
+ DrawingAdapter.exportDrawings()
196
+
197
+
198
+ DrawingPersistence.autoSave()
199
+
200
+ ├── apiBaseUrl 存在 → POST /api/drawings/save
201
+ │ { chartId, drawings[] }
202
+
203
+ └── apiBaseUrl 为空 → localStorage
204
+ key: `qlchart-drawings-${chartId}`
205
+
206
+ ── 加载阶段 ──
207
+ QLChartPanel 数据加载完成 (dataLoaded: true)
208
+
209
+
210
+ useDrawingModule effect → DrawingAdapter.attach(chart, series, container)
211
+
212
+
213
+ DrawingPersistence.load()
214
+
215
+ ├── apiBaseUrl 存在 → GET /api/drawings/load?chartId=xxx
216
+
217
+ └── apiBaseUrl 为空 → localStorage.getItem(...)
218
+
219
+
220
+ DrawingAdapter.importDrawings(data)
221
+
222
+
223
+ DrawingManager → 恢复所有绘图到 Canvas
224
+ ```
225
+
226
+ ### 4. 回放数据流
227
+
228
+ ```
229
+ KlineReplay.load(allData) ← 预加载完整K线数据
230
+
231
+
232
+ KlineReplay.play() ← 开始回放
233
+
234
+ ├── series.setData([allData[0]]) ← 只显示第一根
235
+
236
+ └── setInterval ──→ series.update(allData[i]) ← 逐根追加
237
+
238
+
239
+ onProgress(current, total) → ReplayController 进度更新
240
+
241
+ KlineReplay.pause() ← clearInterval,暂停在当前K线
242
+ KlineReplay.next()/prev() ← 手动单步前进/后退
243
+ KlineReplay.stop() ← 停止回放,恢复全量数据 setData(allData)
244
+ ```
245
+
246
+ ---
247
+
248
+ ## 核心模块职责
249
+
250
+ | 模块 | 职责 |
251
+ |------|------|
252
+ | **QLChartPanel** | 数据加载编排,协调各模块,管理生命周期 |
253
+ | **DataManager** | 数据缓存、请求去重、参数管理 |
254
+ | **RealtimeDataFeed** | 实时增量数据推送,通过 LWC series.update() 更新图表 |
255
+ | **SeriesManager** | 序列注册/销毁,序列引用管理 |
256
+ | **IndicatorDataProcessor** | v2 格式数据解析,指标数据提取分发 |
257
+ | **IndicatorRenderer** | 指标渲染到主图(overlay)或副图(pane) |
258
+ | **DrawingAdapter** | 绘图创建/选择/拖拽/持久化的桥接层 |
259
+ | **DrawingPersistence** | 绘图数据存储(API/localStorage) |
260
+ | **KlineReplay** | K线逐根回放引擎 |
261
+ | **ThemeManager** | 主题切换,映射到 chart options |
262
+
263
+ ---
264
+
265
+ ## 状态同步机制
266
+
267
+ Zustand Store 在数据流中扮演协调角色:
268
+
269
+ | Store | 关键状态 | 作用 |
270
+ |-------|---------|------|
271
+ | **useChartStore** | `activePeriod` | 变化触发 `loadData` 重执行,获取新周期数据 |
272
+ | **useChartStore** | `activeSeriesType` | K线类型切换,影响 `addMainSeries` 参数 |
273
+ | **useChartStore** | `activePanelId` | 多面板布局中标识当前操作目标面板 |
274
+ | **useDrawingStore** | `activeTool` | 变化通过 `useDrawingModule` 传递给 DrawingAdapter |
275
+ | **useDrawingStore** | `selectedDrawingId` | 当前选中绘图,驱动属性面板显示 |
276
+ | **useIndicatorStore** | `activeIndicators` | 变化触发指标重新渲染 |
277
+ | **useReplayStore** | `isReplayMode` | 控制回放控制器显示/隐藏 |
278
+
279
+ ### 数据重载场景
280
+
281
+ 切换周期/品种时:
282
+
283
+ ```
284
+ 1. period/seriesType 变化 → loadData useCallback 依赖变化
285
+ 2. seriesManager.clearAll() // 清空旧序列
286
+ 3. fetchFn(newParams) // 获取新数据
287
+ 4. addMainSeries() + setData() // 新序列渲染
288
+ 5. DrawingAdapter.updateSeries() // 同步series引用(防御性修复)
289
+ 6. DrawingAdapter.setCandleData() // 更新磁铁吸附数据
290
+ ```
291
+
292
+ ---
293
+
294
+ ## API 接口规范(后端就绪后参考)
295
+
296
+ ### K线数据请求
297
+
298
+ ```
299
+ GET /api/chart/kline?pairId=BTCUSDT&product=digital_currency&period=1h&count=500
300
+ ```
301
+
302
+ ### 绘图持久化
303
+
304
+ ```
305
+ POST /api/drawings/save
306
+ Body: { chartId: string, drawings: DrawingPersistData[] }
307
+
308
+ GET /api/drawings/load?chartId=xxx
309
+ Response: { drawings: DrawingPersistData[] }
310
+ ```
@@ -0,0 +1,59 @@
1
+ # 部署与发布
2
+
3
+ ## 构建库
4
+
5
+ ```bash
6
+ pnpm build
7
+ # 输出: dist/qlchart.js + dist/style.css + dist/index.d.ts
8
+ ```
9
+
10
+ ### 独立构建(用于demo部署)
11
+
12
+ ```bash
13
+ pnpm build:standalone
14
+ ```
15
+
16
+ ## 构建文档
17
+
18
+ ```bash
19
+ # 仅 VitePress
20
+ pnpm docs:build
21
+
22
+ # 仅 TypeDoc API Reference
23
+ pnpm docs:api
24
+
25
+ # 完整文档(TypeDoc + VitePress)
26
+ pnpm docs:all
27
+ ```
28
+
29
+ 文档输出到 `doc/.vitepress/dist/`。
30
+
31
+ ## 本地预览文档
32
+
33
+ ```bash
34
+ pnpm docs:dev # 开发模式,热更新
35
+ pnpm docs:preview # 预览构建结果
36
+ ```
37
+
38
+ ## 发布到 npm
39
+
40
+ ```bash
41
+ # 1. 更新版本号
42
+ npm version patch # 或 minor / major
43
+
44
+ # 2. 构建
45
+ pnpm build
46
+
47
+ # 3. 发布
48
+ npm publish --access public
49
+ ```
50
+
51
+ ## Demo 部署
52
+
53
+ ```bash
54
+ # 启动 demo 开发服务器
55
+ pnpm demo
56
+
57
+ # 构建 demo(用于静态部署)
58
+ pnpm build:standalone
59
+ ```
@@ -0,0 +1,40 @@
1
+ # 绘图工具属性系统
2
+
3
+ QLChart 为19种绘图工具定义了差异化的属性模板,用户可通过属性面板修改每种工具的渲染样式。
4
+
5
+ ## 架构
6
+
7
+ ```
8
+ DrawingPropertyTemplates (模板定义)
9
+
10
+ getPropertyTemplate(toolType) → PropertyField[]
11
+
12
+ DrawingPropertyPanel (动态渲染UI控件)
13
+ ```
14
+
15
+ ## 属性字段类型
16
+
17
+ | 类型 | UI控件 | 说明 |
18
+ |------|--------|------|
19
+ | `color` | Color Picker | 颜色选择 |
20
+ | `range` | Slider | 数值范围 |
21
+ | `toggle` | Checkbox | 开关 |
22
+ | `select` | Dropdown | 下拉选择 |
23
+
24
+ ## 工具属性差异
25
+
26
+ 不同工具有不同的属性组合:
27
+
28
+ - **线条类**(趋势线/水平线/射线):线条颜色、线宽、样式、延伸
29
+ - **形状类**(矩形/圆/三角形):线条颜色、线宽、填充色、透明度
30
+ - **斐波那契**:线条颜色、填充透明度、标签显示
31
+ - **仓位类**(多头/空头):颜色主题固定(绿/红)、填充透明度
32
+
33
+ ## 使用
34
+
35
+ ```typescript
36
+ import { getPropertyTemplate } from '@quantlife/qlchart'
37
+
38
+ const template = getPropertyTemplate('rectangle')
39
+ // template.fields = [lineColor, lineWidth, fillColor, fillOpacity, showLabels]
40
+ ```
@@ -0,0 +1,94 @@
1
+ # 快速开始
2
+
3
+ ## 安装
4
+
5
+ ```bash
6
+ pnpm add @quantlife/qlchart
7
+ ```
8
+
9
+ ### Peer Dependencies
10
+
11
+ QLChart 依赖以下库,请确保已安装:
12
+
13
+ ```bash
14
+ pnpm add react react-dom lightweight-charts lightweight-charts-drawing zustand
15
+ ```
16
+
17
+ ## 最小示例
18
+
19
+ ```tsx
20
+ import { QLChartProvider, QLChartPanel } from '@quantlife/qlchart'
21
+ import '@quantlife/qlchart/dist/style.css'
22
+
23
+ // 定义数据获取函数
24
+ async function fetchFn(params: { pairId: string; product: string; period: string }) {
25
+ const res = await fetch(`/api/klines?${new URLSearchParams(params)}`)
26
+ return res.json()
27
+ }
28
+
29
+ function App() {
30
+ return (
31
+ <QLChartProvider config={{ fetchFn, defaultTheme: 'dark' }}>
32
+ <QLChartPanel
33
+ pairId="BTCUSDT"
34
+ product="digital_currency"
35
+ period="1h"
36
+ showToolbar
37
+ />
38
+ </QLChartProvider>
39
+ )
40
+ }
41
+ ```
42
+
43
+ ## 数据格式
44
+
45
+ `fetchFn` 返回的数据格式:
46
+
47
+ ```typescript
48
+ interface CandlestickRawData {
49
+ time: number // 毫秒时间戳
50
+ open: number
51
+ high: number
52
+ low: number
53
+ close: number
54
+ volume?: number
55
+ }
56
+
57
+ // 返回格式
58
+ {
59
+ data: CandlestickRawData[]
60
+ }
61
+ ```
62
+
63
+ ## 核心 Props
64
+
65
+ ### QLChartProvider
66
+
67
+ | Prop | Type | Required | Description |
68
+ |------|------|----------|-------------|
69
+ | `fetchFn` | `(params) => Promise<{ data: CandlestickRawData[] }>` | ✅ | K线数据获取函数 |
70
+ | `defaultTheme` | `'dark' \| 'light'` | ❌ | 默认主题,默认 `'dark'` |
71
+ | `apiBaseUrl` | `string` | ❌ | 绘图持久化API地址 |
72
+ | `cacheEnabled` | `boolean` | ❌ | 是否启用数据缓存,默认 `true` |
73
+ | `cacheTTL` | `number` | ❌ | 缓存TTL(毫秒),默认 `300000`(5分钟) |
74
+ | `realtimeSubscribe` | `RealtimeSubscribeFn` | ❌ | 实时数据订阅函数(WebSocket场景) |
75
+
76
+ ### QLChartPanel
77
+
78
+ | Prop | Type | Required | Description |
79
+ |------|------|----------|-------------|
80
+ | `pairId` | `string` | ✅ | 交易对ID |
81
+ | `product` | `string` | ✅ | 产品类型 |
82
+ | `period` | `string` | ❌ | K线周期,默认 `'1h'` |
83
+ | `seriesType` | `SeriesType` | ❌ | 图表类型,默认 `Candlestick` |
84
+ | `showToolbar` | `boolean` | ❌ | 是否显示工具栏,默认 `true` |
85
+ | `panelId` | `string` | ❌ | 面板ID(多面板场景必传) |
86
+
87
+ ## 下一步
88
+
89
+ - [架构总览](./architecture) — 了解QLChart的四层架构
90
+ - [QLChartProvider](../components/qlchart-provider) — Provider配置详解
91
+ - [QLChartPanel](../components/qlchart-panel) — 主面板组件
92
+ - [Standalone JS](../examples/standalone-js) — 纯JS使用方式
93
+ - [实时数据更新](../examples/realtime-data) — WebSocket增量推送
94
+ - [数据格式指南](../examples/data-format-guide) — 时间戳与数据转换
@@ -0,0 +1,47 @@
1
+ # 副图系统
2
+
3
+ QLChart 使用 lightweight-charts v5 原生 pane 系统支持多面板图表。
4
+
5
+ ## 架构
6
+
7
+ ```
8
+ 主Chart (pane 0)
9
+ ├── K线序列
10
+ ├── 成交量序列 (priceScaleId: 'volume')
11
+ ├── Overlay指标 (MA/EMA/BOLL)
12
+ ├── 副图pane 1 — MACD
13
+ ├── 副图pane 2 — RSI
14
+ └── 共享时间轴
15
+ ```
16
+
17
+ **优势:** 不再使用独立的PaneChartPanel,所有series在同一个Chart实例中,时间轴天然同步。
18
+
19
+ ## 使用
20
+
21
+ 副图指标通过 `IndicatorRenderer` 自动管理:
22
+
23
+ ```typescript
24
+ // 添加MACD指标时,IndicatorRenderer会自动:
25
+ // 1. 分配pane索引(1, 2, 3...)
26
+ // 2. 使用 chart.addSeries(def, opts, paneIndex) 添加到指定pane
27
+ // 3. 设置pane高度比例
28
+ ```
29
+
30
+ ## Pane高度调整
31
+
32
+ 使用 `PaneDivider` 组件拖拽调整主图/副图比例:
33
+
34
+ ```tsx
35
+ import { PaneDivider } from '@quantlife/qlchart'
36
+
37
+ <PaneDivider index={1} onDrag={(delta) => adjustRatio(delta)} />
38
+ ```
39
+
40
+ ## PaneManager API
41
+
42
+ | 方法 | 说明 |
43
+ |------|------|
44
+ | `addIndicatorPane(name, ratio)` | 创建新pane,返回paneIndex |
45
+ | `removePane(index)` | 移除pane |
46
+ | `setPaneHeight(index, ratio)` | 设置pane高度比例 |
47
+ | `getPanes()` | 获取所有pane信息 |
@@ -0,0 +1,58 @@
1
+ # 主题切换
2
+
3
+ ## 内置主题
4
+
5
+ QLChart 内置暗色和亮色两种主题。
6
+
7
+ ### 暗色主题(默认)
8
+
9
+ ```tsx
10
+ <QLChartProvider config={{ defaultTheme: 'dark' }}>
11
+ ```
12
+
13
+ ### 亮色主题
14
+
15
+ ```tsx
16
+ <QLChartProvider config={{ defaultTheme: 'light' }}>
17
+ ```
18
+
19
+ ## 运行时切换
20
+
21
+ 通过 `useTheme` Hook 在运行时切换主题:
22
+
23
+ ```tsx
24
+ import { useTheme } from '@quantlife/qlchart'
25
+
26
+ function ThemeSwitcher() {
27
+ const { theme, setTheme } = useTheme()
28
+
29
+ return (
30
+ <button onClick={() => setTheme(theme === 'dark' ? 'light' : 'dark')}>
31
+ 当前: {theme} → 切换
32
+ </button>
33
+ )
34
+ }
35
+ ```
36
+
37
+ ## QLToolbar 切换
38
+
39
+ 如果启用了工具栏 (`showToolbar={true}`),用户可通过工具栏上的主题按钮切换。
40
+
41
+ ## 自定义主题
42
+
43
+ 通过修改 `themePresets.ts` 中的预设配置自定义颜色:
44
+
45
+ ```typescript
46
+ // src/utils/themePresets.ts
47
+ export const darkTheme: DeepPartial<ChartOptions> = {
48
+ layout: {
49
+ background: { color: '#131722' },
50
+ textColor: '#d1d4dc',
51
+ },
52
+ grid: {
53
+ vertLines: { color: '#1e222d' },
54
+ horzLines: { color: '#1e222d' },
55
+ },
56
+ // ... 更多配置
57
+ }
58
+ ```