@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,100 @@
1
+ import { create } from 'zustand';
2
+ import {
3
+ type IndicatorConfig,
4
+ type IndicatorDefinition,
5
+ type IndicatorDataResponse,
6
+ IndicatorType,
7
+ BUILTIN_INDICATORS,
8
+ } from '../types/index.js';
9
+
10
+ export interface IndicatorState {
11
+ /** 当前活跃的指标 */
12
+ activeIndicators: IndicatorConfig[];
13
+ /** 可用指标列表 */
14
+ availableIndicators: IndicatorDefinition[];
15
+ /** 指标数据缓存 name → data */
16
+ indicatorDataCache: Record<string, IndicatorDataResponse>;
17
+
18
+ /** 添加指标 */
19
+ addIndicator: (config: IndicatorConfig) => void;
20
+ /** 移除指标 */
21
+ removeIndicator: (id: string) => void;
22
+ /** 切换指标可见性 */
23
+ toggleIndicator: (id: string) => void;
24
+ /** 更新指标参数 */
25
+ updateIndicatorParams: (id: string, params: Record<string, number>) => void;
26
+ /** 设置指标数据 */
27
+ setIndicatorData: (name: string, data: IndicatorDataResponse) => void;
28
+ /** 清理所有 */
29
+ clearAll: () => void;
30
+ }
31
+
32
+ let indicatorIdCounter = 0;
33
+
34
+ /** 创建一个指标配置 */
35
+ export function createIndicatorConfig(
36
+ definition: IndicatorDefinition,
37
+ overrides?: Partial<IndicatorConfig>,
38
+ ): IndicatorConfig {
39
+ return {
40
+ id: `ind_${definition.name}_${++indicatorIdCounter}_${Date.now()}`,
41
+ name: definition.name,
42
+ label: definition.label,
43
+ type: definition.type,
44
+ params: { ...definition.defaultParams },
45
+ visible: true,
46
+ color: definition.colors[0],
47
+ seriesIds: [],
48
+ ...overrides,
49
+ };
50
+ }
51
+
52
+ export const useIndicatorStore = create<IndicatorState>((set) => ({
53
+ activeIndicators: [],
54
+ availableIndicators: BUILTIN_INDICATORS,
55
+ indicatorDataCache: {},
56
+
57
+ addIndicator: (config) =>
58
+ set((state) => ({
59
+ activeIndicators: [...state.activeIndicators, config],
60
+ })),
61
+
62
+ removeIndicator: (id) =>
63
+ set((state) => {
64
+ const indicator = state.activeIndicators.find((i) => i.id === id);
65
+ if (!indicator) return state;
66
+
67
+ const newCache = { ...state.indicatorDataCache };
68
+ delete newCache[indicator.name];
69
+
70
+ return {
71
+ activeIndicators: state.activeIndicators.filter((i) => i.id !== id),
72
+ indicatorDataCache: newCache,
73
+ };
74
+ }),
75
+
76
+ toggleIndicator: (id) =>
77
+ set((state) => ({
78
+ activeIndicators: state.activeIndicators.map((i) =>
79
+ i.id === id ? { ...i, visible: !i.visible } : i,
80
+ ),
81
+ })),
82
+
83
+ updateIndicatorParams: (id, params) =>
84
+ set((state) => ({
85
+ activeIndicators: state.activeIndicators.map((i) =>
86
+ i.id === id ? { ...i, params: { ...i.params, ...params } } : i,
87
+ ),
88
+ })),
89
+
90
+ setIndicatorData: (name, data) =>
91
+ set((state) => ({
92
+ indicatorDataCache: { ...state.indicatorDataCache, [name]: data },
93
+ })),
94
+
95
+ clearAll: () =>
96
+ set({
97
+ activeIndicators: [],
98
+ indicatorDataCache: {},
99
+ }),
100
+ }));
@@ -0,0 +1,50 @@
1
+ import { create } from 'zustand';
2
+ import { useChartStore } from './useChartStore.js';
3
+ import type { IChartApi, ISeriesApi, SeriesType as LWCSeriesType } from 'lightweight-charts';
4
+ import type { ChartManager } from '../core/ChartManager.js';
5
+ import type { SeriesManager } from '../core/SeriesManager.js';
6
+ import type { DrawingAdapter } from '../plugins/drawing/DrawingAdapter.js';
7
+
8
+ export interface PanelHandle {
9
+ panelId: string;
10
+ chartManager: ChartManager;
11
+ seriesManager: SeriesManager;
12
+ drawingAdapter: DrawingAdapter;
13
+ chart: IChartApi;
14
+ container: HTMLElement;
15
+ }
16
+
17
+ export interface PanelRegistryState {
18
+ panels: Map<string, PanelHandle>;
19
+
20
+ register: (panelId: string, handle: PanelHandle) => void;
21
+ unregister: (panelId: string) => void;
22
+ getHandle: (panelId: string) => PanelHandle | undefined;
23
+ getActiveHandle: () => PanelHandle | undefined;
24
+ }
25
+
26
+ export const usePanelRegistry = create<PanelRegistryState>((set, get) => ({
27
+ panels: new Map(),
28
+
29
+ register: (panelId, handle) =>
30
+ set((state) => {
31
+ const panels = new Map(state.panels);
32
+ panels.set(panelId, handle);
33
+ return { panels };
34
+ }),
35
+
36
+ unregister: (panelId) =>
37
+ set((state) => {
38
+ const panels = new Map(state.panels);
39
+ panels.delete(panelId);
40
+ return { panels };
41
+ }),
42
+
43
+ getHandle: (panelId) => get().panels.get(panelId),
44
+
45
+ getActiveHandle: () => {
46
+ const activePanelId = useChartStore.getState().activePanelId;
47
+ if (!activePanelId) return undefined;
48
+ return get().panels.get(activePanelId);
49
+ },
50
+ }));
@@ -0,0 +1,42 @@
1
+ import { create } from 'zustand';
2
+
3
+ export interface ReplayState {
4
+ /** 是否处于回放模式 */
5
+ isReplayMode: boolean;
6
+ /** 是否正在播放 */
7
+ isPlaying: boolean;
8
+ /** 播放速度 ms/根 */
9
+ speed: number;
10
+ /** 进度 */
11
+ progress: { current: number; total: number };
12
+
13
+ /** 进入回放模式 */
14
+ enterReplay: () => void;
15
+ /** 退出回放模式 */
16
+ exitReplay: () => void;
17
+ /** 设置播放状态 */
18
+ setPlaying: (playing: boolean) => void;
19
+ /** 设置速度 */
20
+ setSpeed: (ms: number) => void;
21
+ /** 设置进度 */
22
+ setProgress: (current: number, total: number) => void;
23
+ }
24
+
25
+ export const useReplayStore = create<ReplayState>((set) => ({
26
+ isReplayMode: false,
27
+ isPlaying: false,
28
+ speed: 1000,
29
+ progress: { current: 0, total: 0 },
30
+
31
+ enterReplay: () =>
32
+ set({ isReplayMode: true, isPlaying: false, progress: { current: 0, total: 0 } }),
33
+
34
+ exitReplay: () =>
35
+ set({ isReplayMode: false, isPlaying: false, progress: { current: 0, total: 0 } }),
36
+
37
+ setPlaying: (playing) => set({ isPlaying: playing }),
38
+
39
+ setSpeed: (ms) => set({ speed: Math.max(50, Math.min(ms, 5000)) }),
40
+
41
+ setProgress: (current, total) => set({ progress: { current, total } }),
42
+ }));
@@ -0,0 +1,34 @@
1
+ import { create } from 'zustand';
2
+
3
+ export interface TimeBarState {
4
+ /** 当前选中的快捷范围标签 */
5
+ activeRangeLabel: string | null;
6
+ /** 自定义起始日期 */
7
+ customStartDate: string;
8
+ /** 自定义结束日期 */
9
+ customEndDate: string;
10
+ /** 是否显示日期选择器 */
11
+ showDatePicker: boolean;
12
+
13
+ // Actions
14
+ setActiveRangeLabel: (label: string | null) => void;
15
+ setCustomDateRange: (start: string, end: string) => void;
16
+ setShowDatePicker: (show: boolean) => void;
17
+ reset: () => void;
18
+ }
19
+
20
+ const initialState = {
21
+ activeRangeLabel: null,
22
+ customStartDate: '',
23
+ customEndDate: '',
24
+ showDatePicker: false,
25
+ };
26
+
27
+ export const useTimeBarStore = create<TimeBarState>((set) => ({
28
+ ...initialState,
29
+
30
+ setActiveRangeLabel: (label) => set({ activeRangeLabel: label }),
31
+ setCustomDateRange: (start, end) => set({ customStartDate: start, customEndDate: end }),
32
+ setShowDatePicker: (show) => set({ showDatePicker: show }),
33
+ reset: () => set(initialState),
34
+ }));
@@ -0,0 +1,312 @@
1
+ .qlchart-container {
2
+ position: relative;
3
+ width: 100%;
4
+ height: 100%;
5
+ display: flex;
6
+ flex-direction: column;
7
+ overflow: hidden;
8
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
9
+ border: 2px solid transparent;
10
+ transition: border-color 0.15s;
11
+ }
12
+
13
+ .qlchart-container.active-panel {
14
+ border-color: var(--qlchart-accent, #2962ff);
15
+ }
16
+
17
+ .qlchart-panel {
18
+ position: relative;
19
+ flex: 1;
20
+ min-height: 0;
21
+ overflow: hidden;
22
+ }
23
+
24
+ .qlchart-chart-wrapper {
25
+ width: 100%;
26
+ height: 100%;
27
+ }
28
+
29
+ .qlchart-loading {
30
+ position: absolute;
31
+ top: 0;
32
+ left: 0;
33
+ right: 0;
34
+ bottom: 0;
35
+ display: flex;
36
+ align-items: center;
37
+ justify-content: center;
38
+ background: var(--qlchart-bg, #131722);
39
+ color: var(--qlchart-text, #d1d4dc);
40
+ font-size: 14px;
41
+ z-index: 10;
42
+ }
43
+
44
+ .qlchart-error {
45
+ position: absolute;
46
+ top: 0;
47
+ left: 0;
48
+ right: 0;
49
+ bottom: 0;
50
+ display: flex;
51
+ align-items: center;
52
+ justify-content: center;
53
+ background: var(--qlchart-bg, #131722);
54
+ color: #ef5350;
55
+ font-size: 14px;
56
+ z-index: 10;
57
+ }
58
+
59
+ /* Indicator tags */
60
+ .qlchart-indicator-tags {
61
+ display: flex;
62
+ flex-wrap: wrap;
63
+ gap: 4px;
64
+ padding: 4px 8px;
65
+ background: var(--qlchart-bg, #131722);
66
+ border-bottom: 1px solid var(--qlchart-border, #1e222d);
67
+ }
68
+
69
+ .qlchart-indicator-tag {
70
+ font-size: 11px;
71
+ }
72
+
73
+ .qlchart-indicator-tag-label {
74
+ font-weight: 500;
75
+ }
76
+
77
+ .qlchart-indicator-tag-value {
78
+ opacity: 0.8;
79
+ font-family: monospace;
80
+ }
81
+
82
+ /* Indicator tag buttons */
83
+ .qlchart-indicator-tag button {
84
+ background: none;
85
+ border: none;
86
+ cursor: pointer;
87
+ padding: 0 2px;
88
+ font-size: 10px;
89
+ opacity: 0.6;
90
+ color: var(--qlchart-text, #d1d4dc);
91
+ }
92
+
93
+ .qlchart-indicator-tag button:hover {
94
+ opacity: 1;
95
+ }
96
+
97
+ .qlchart-indicator-tag.hidden {
98
+ opacity: 0.5;
99
+ }
100
+
101
+ /* Indicator drawer overlay */
102
+ .qlchart-indicator-drawer-overlay {
103
+ position: fixed;
104
+ top: 0;
105
+ left: 0;
106
+ right: 0;
107
+ bottom: 0;
108
+ background: rgba(0, 0, 0, 0.4);
109
+ z-index: 1000;
110
+ display: flex;
111
+ justify-content: flex-end;
112
+ }
113
+
114
+ .qlchart-indicator-drawer {
115
+ width: 320px;
116
+ max-width: 80vw;
117
+ height: 100%;
118
+ background: var(--qlchart-bg, #1a1e2e);
119
+ color: var(--qlchart-text, #d1d4dc);
120
+ display: flex;
121
+ flex-direction: column;
122
+ box-shadow: -4px 0 16px rgba(0, 0, 0, 0.3);
123
+ }
124
+
125
+ .qlchart-indicator-drawer-header {
126
+ display: flex;
127
+ justify-content: space-between;
128
+ align-items: center;
129
+ padding: 12px 16px;
130
+ border-bottom: 1px solid var(--qlchart-border, #2a2e3e);
131
+ }
132
+
133
+ .qlchart-indicator-drawer-title {
134
+ font-size: 16px;
135
+ font-weight: 600;
136
+ }
137
+
138
+ .qlchart-indicator-drawer-close {
139
+ background: none;
140
+ border: none;
141
+ color: var(--qlchart-text, #d1d4dc);
142
+ cursor: pointer;
143
+ font-size: 16px;
144
+ padding: 4px;
145
+ }
146
+
147
+ .qlchart-indicator-drawer-body {
148
+ flex: 1;
149
+ overflow-y: auto;
150
+ padding: 12px;
151
+ }
152
+
153
+ .qlchart-indicator-section {
154
+ margin-bottom: 16px;
155
+ }
156
+
157
+ .qlchart-indicator-section-title {
158
+ font-size: 13px;
159
+ font-weight: 600;
160
+ margin-bottom: 8px;
161
+ color: var(--qlchart-text-secondary, #9ca3af);
162
+ }
163
+
164
+ .qlchart-indicator-item {
165
+ padding: 8px 0;
166
+ border-bottom: 1px solid var(--qlchart-border, #1e222d);
167
+ }
168
+
169
+ .qlchart-indicator-item-header {
170
+ display: flex;
171
+ align-items: center;
172
+ gap: 8px;
173
+ }
174
+
175
+ .qlchart-indicator-item-label {
176
+ font-weight: 500;
177
+ font-size: 13px;
178
+ min-width: 80px;
179
+ }
180
+
181
+ .qlchart-indicator-item-desc {
182
+ flex: 1;
183
+ font-size: 11px;
184
+ color: var(--qlchart-text-secondary, #9ca3af);
185
+ }
186
+
187
+ .qlchart-indicator-item-btn {
188
+ background: none;
189
+ border: 1px solid var(--qlchart-border, #2a2e3e);
190
+ color: var(--qlchart-text, #d1d4dc);
191
+ cursor: pointer;
192
+ padding: 2px 10px;
193
+ border-radius: 4px;
194
+ font-size: 12px;
195
+ }
196
+
197
+ .qlchart-indicator-item-btn:hover {
198
+ border-color: #26a69a;
199
+ color: #26a69a;
200
+ }
201
+
202
+ .qlchart-indicator-item-btn.active {
203
+ border-color: #ef5350;
204
+ color: #ef5350;
205
+ }
206
+
207
+ .qlchart-indicator-item-params {
208
+ display: flex;
209
+ gap: 12px;
210
+ margin-top: 6px;
211
+ flex-wrap: wrap;
212
+ }
213
+
214
+ .qlchart-indicator-param {
215
+ display: flex;
216
+ align-items: center;
217
+ gap: 4px;
218
+ font-size: 11px;
219
+ }
220
+
221
+ .qlchart-indicator-param-label {
222
+ color: var(--qlchart-text-secondary, #9ca3af);
223
+ }
224
+
225
+ .qlchart-indicator-param-input {
226
+ width: 60px;
227
+ padding: 2px 4px;
228
+ background: var(--qlchart-bg, #131722);
229
+ border: 1px solid var(--qlchart-border, #2a2e3e);
230
+ border-radius: 3px;
231
+ color: var(--qlchart-text, #d1d4dc);
232
+ font-size: 11px;
233
+ }
234
+
235
+ /* Toolbar indicator button */
236
+ .qlchart-toolbar-btn {
237
+ background: none;
238
+ border: 1px solid var(--qlchart-border, #2a2e3e);
239
+ color: var(--qlchart-text, #d1d4dc);
240
+ cursor: pointer;
241
+ padding: 4px 10px;
242
+ border-radius: 4px;
243
+ font-size: 12px;
244
+ }
245
+
246
+ .qlchart-toolbar-btn:hover {
247
+ border-color: #26a69a;
248
+ color: #26a69a;
249
+ }
250
+
251
+ /* ChartFunctionMenu */
252
+ .qlchart-function-menu-wrapper {
253
+ position: absolute;
254
+ bottom: 28px;
255
+ right: 60px;
256
+ z-index: 10;
257
+ }
258
+
259
+ .qlchart-function-menu-trigger {
260
+ width: 24px;
261
+ height: 24px;
262
+ border: none;
263
+ background: rgba(30, 34, 45, 0.8);
264
+ color: #d1d4dc;
265
+ border-radius: 4px;
266
+ cursor: pointer;
267
+ font-size: 14px;
268
+ display: flex;
269
+ align-items: center;
270
+ justify-content: center;
271
+ }
272
+
273
+ .qlchart-function-menu-trigger:hover {
274
+ background: rgba(42, 46, 57, 0.9);
275
+ }
276
+
277
+ .qlchart-function-menu-popup {
278
+ position: absolute;
279
+ bottom: 28px;
280
+ right: 0;
281
+ background: #1e222d;
282
+ border: 1px solid #2a2e39;
283
+ border-radius: 4px;
284
+ padding: 4px 0;
285
+ min-width: 140px;
286
+ box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
287
+ }
288
+
289
+ .qlchart-fm-item {
290
+ display: block;
291
+ width: 100%;
292
+ padding: 8px 12px;
293
+ border: none;
294
+ background: transparent;
295
+ color: #d1d4dc;
296
+ text-align: left;
297
+ cursor: pointer;
298
+ font-size: 13px;
299
+ }
300
+
301
+ .qlchart-fm-item:hover {
302
+ background: #2a2e39;
303
+ }
304
+
305
+ /* 全局绘图Sidebar容器 */
306
+ .qlchart-global-drawing-sidebar {
307
+ position: relative;
308
+ width: 40px;
309
+ flex-shrink: 0;
310
+ border-right: 1px solid #2a2e39;
311
+ overflow: visible;
312
+ }
@@ -0,0 +1,184 @@
1
+ /* ════════════════════════════════════════════
2
+ QLChart 组件样式系统 — 基于 CSS 变量
3
+ ════════════════════════════════════════════ */
4
+
5
+ /* ── 统一按钮 ── */
6
+ .qlchart-btn {
7
+ display: inline-flex;
8
+ align-items: center;
9
+ justify-content: center;
10
+ gap: var(--qlchart-space-sm);
11
+ padding: var(--qlchart-space-md) var(--qlchart-space-lg);
12
+ border: 1px solid var(--qlchart-border);
13
+ border-radius: var(--qlchart-radius-md);
14
+ background: var(--qlchart-toolbar-active-bg);
15
+ color: var(--qlchart-text);
16
+ font-size: var(--qlchart-text-base);
17
+ cursor: pointer;
18
+ transition: all var(--qlchart-transition);
19
+ user-select: none;
20
+ }
21
+
22
+ .qlchart-btn:hover {
23
+ background: var(--qlchart-hover);
24
+ border-color: var(--qlchart-accent);
25
+ }
26
+
27
+ .qlchart-btn:active {
28
+ transform: scale(0.97);
29
+ }
30
+
31
+ .qlchart-btn-primary {
32
+ background: var(--qlchart-accent);
33
+ color: #fff;
34
+ border-color: var(--qlchart-accent);
35
+ }
36
+
37
+ .qlchart-btn-primary:hover {
38
+ filter: brightness(1.1);
39
+ }
40
+
41
+ .qlchart-btn-danger {
42
+ background: rgba(239, 83, 80, 0.15);
43
+ color: #ef5350;
44
+ border-color: transparent;
45
+ }
46
+
47
+ .qlchart-btn-danger:hover {
48
+ background: rgba(239, 83, 80, 0.25);
49
+ }
50
+
51
+ .qlchart-btn-ghost {
52
+ background: transparent;
53
+ border-color: transparent;
54
+ }
55
+
56
+ .qlchart-btn-ghost:hover {
57
+ background: var(--qlchart-hover);
58
+ }
59
+
60
+ /* ── 统一 Modal ── */
61
+ .qlchart-modal-root {
62
+ position: fixed;
63
+ inset: 0;
64
+ z-index: 2100;
65
+ display: flex;
66
+ align-items: center;
67
+ justify-content: center;
68
+ }
69
+
70
+ .qlchart-modal-overlay {
71
+ position: fixed;
72
+ inset: 0;
73
+ background: var(--qlchart-modal-overlay, rgba(0, 0, 0, 0.6));
74
+ }
75
+
76
+ .qlchart-modal-overlay-enter-from { opacity: 0; }
77
+ .qlchart-modal-overlay-enter-to { opacity: 1; }
78
+ .qlchart-modal-overlay-leave-from { opacity: 1; }
79
+ .qlchart-modal-overlay-leave-to { opacity: 0; }
80
+
81
+ .qlchart-modal-panel {
82
+ position: relative;
83
+ z-index: 1;
84
+ background: var(--qlchart-toolbar-bg);
85
+ border: 1px solid var(--qlchart-border);
86
+ border-radius: var(--qlchart-radius-lg);
87
+ box-shadow: var(--qlchart-shadow-lg);
88
+ max-height: 80vh;
89
+ display: flex;
90
+ flex-direction: column;
91
+ overflow: hidden;
92
+ }
93
+
94
+ .qlchart-modal-content-enter-from {
95
+ opacity: 0;
96
+ transform: scale(0.95) translateY(-10px);
97
+ }
98
+ .qlchart-modal-content-enter-to {
99
+ opacity: 1;
100
+ transform: scale(1) translateY(0);
101
+ }
102
+ .qlchart-modal-content-leave-from {
103
+ opacity: 1;
104
+ transform: scale(1) translateY(0);
105
+ }
106
+ .qlchart-modal-content-leave-to {
107
+ opacity: 0;
108
+ transform: scale(0.95) translateY(-10px);
109
+ }
110
+
111
+ .qlchart-modal-enter {
112
+ transition: all var(--qlchart-transition);
113
+ }
114
+ .qlchart-modal-leave {
115
+ transition: all var(--qlchart-transition);
116
+ }
117
+
118
+ .qlchart-modal-title {
119
+ padding: var(--qlchart-space-lg) var(--qlchart-space-lg) var(--qlchart-space-md);
120
+ font-size: var(--qlchart-text-md);
121
+ font-weight: 600;
122
+ color: var(--qlchart-text);
123
+ border-bottom: 1px solid var(--qlchart-border);
124
+ }
125
+
126
+ /* ── 统一输入框 ── */
127
+ .qlchart-input {
128
+ width: 100%;
129
+ padding: var(--qlchart-space-md) var(--qlchart-space-lg);
130
+ background: var(--qlchart-bg);
131
+ border: 1px solid var(--qlchart-border);
132
+ border-radius: var(--qlchart-radius-sm);
133
+ color: var(--qlchart-text);
134
+ font-size: var(--qlchart-text-base);
135
+ outline: none;
136
+ transition: border-color var(--qlchart-transition);
137
+ }
138
+
139
+ .qlchart-input:focus {
140
+ border-color: var(--qlchart-accent);
141
+ box-shadow: 0 0 0 2px var(--qlchart-focus);
142
+ }
143
+
144
+ .qlchart-input::placeholder {
145
+ color: var(--qlchart-text-secondary);
146
+ }
147
+
148
+ /* ── 微交互增强 ── */
149
+ .qlchart-btn,
150
+ .qlchart-dvt-btn,
151
+ .qlchart-dvt-sub-btn {
152
+ transition: background var(--qlchart-transition),
153
+ color var(--qlchart-transition),
154
+ transform 0.1s ease,
155
+ box-shadow var(--qlchart-transition);
156
+ }
157
+
158
+ /* hover 时微妙上浮 */
159
+ .qlchart-dvt-btn:hover:not(.active),
160
+ .qlchart-dvt-sub-btn:hover:not(.active) {
161
+ transform: translateY(-1px);
162
+ }
163
+
164
+ /* ── 滚动条美化 ── */
165
+ .qlchart-drawing-property-panel::-webkit-scrollbar,
166
+ .qlchart-fib-levels-editor::-webkit-scrollbar {
167
+ width: 4px;
168
+ }
169
+
170
+ .qlchart-drawing-property-panel::-webkit-scrollbar-track,
171
+ .qlchart-fib-levels-editor::-webkit-scrollbar-track {
172
+ background: transparent;
173
+ }
174
+
175
+ .qlchart-drawing-property-panel::-webkit-scrollbar-thumb,
176
+ .qlchart-fib-levels-editor::-webkit-scrollbar-thumb {
177
+ background: var(--qlchart-border);
178
+ border-radius: 2px;
179
+ }
180
+
181
+ .qlchart-drawing-property-panel::-webkit-scrollbar-thumb:hover,
182
+ .qlchart-fib-levels-editor::-webkit-scrollbar-thumb:hover {
183
+ background: var(--qlchart-text-secondary);
184
+ }