@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.
- package/.idea/QLChart.iml +12 -0
- package/.idea/modules.xml +8 -0
- package/.idea/vcs.xml +6 -0
- package/README.md +75 -0
- package/demo/App.css +213 -0
- package/demo/App.tsx +46 -0
- package/demo/components/ControlPanel.tsx +13 -0
- package/demo/components/DemoNav.tsx +27 -0
- package/demo/index.html +16 -0
- package/demo/main.tsx +10 -0
- package/demo/pages/BasicChartDemo.tsx +61 -0
- package/demo/pages/DrawingDemo.tsx +22 -0
- package/demo/pages/IndicatorDemo.tsx +22 -0
- package/demo/pages/LayoutDemo.tsx +35 -0
- package/demo/pages/MultiPeriodDemo.tsx +31 -0
- package/demo/pages/ReplayDemo.tsx +195 -0
- package/demo/pages/SaveDemo.tsx +27 -0
- package/demo/pages/ThemeDemo.tsx +29 -0
- package/demo/standalone-demo.html +597 -0
- package/demo/vite.config.demo.ts +17 -0
- package/dist/index.d.ts +1973 -0
- package/dist/qlchart.js +23169 -0
- package/dist/style.css +1 -0
- package/doc/api/indicator-data-processor.md +35 -0
- package/doc/api-reference/.nojekyll +1 -0
- package/doc/api-reference/assets/hierarchy.js +1 -0
- package/doc/api-reference/assets/highlight.css +43 -0
- package/doc/api-reference/assets/icons.js +18 -0
- package/doc/api-reference/assets/icons.svg +1 -0
- package/doc/api-reference/assets/main.js +60 -0
- package/doc/api-reference/assets/navigation.js +1 -0
- package/doc/api-reference/assets/search.js +1 -0
- package/doc/api-reference/assets/style.css +1611 -0
- package/doc/api-reference/classes/ChartManager.html +16 -0
- package/doc/api-reference/classes/DataManager.html +13 -0
- package/doc/api-reference/classes/DrawingAdapter.html +64 -0
- package/doc/api-reference/classes/DrawingPersistence.html +21 -0
- package/doc/api-reference/classes/EventManager.html +12 -0
- package/doc/api-reference/classes/HollowCandlestickSeries.html +22 -0
- package/doc/api-reference/classes/IndicatorRenderer.html +20 -0
- package/doc/api-reference/classes/KlineReplay.html +31 -0
- package/doc/api-reference/classes/MockDataService.html +13 -0
- package/doc/api-reference/classes/MockIndicatorService.html +4 -0
- package/doc/api-reference/classes/OverlayIndicator.html +11 -0
- package/doc/api-reference/classes/PaneIndicator.html +16 -0
- package/doc/api-reference/classes/PaneManager.html +24 -0
- package/doc/api-reference/classes/RealtimeDataFeed.html +22 -0
- package/doc/api-reference/classes/RenkoSeries.html +22 -0
- package/doc/api-reference/classes/ScreenshotUtil.html +10 -0
- package/doc/api-reference/classes/SeriesManager.html +30 -0
- package/doc/api-reference/classes/ThemeManager.html +18 -0
- package/doc/api-reference/enums/ChartEvent.html +12 -0
- package/doc/api-reference/enums/IndicatorType.html +4 -0
- package/doc/api-reference/enums/SeriesType.html +13 -0
- package/doc/api-reference/functions/ChartFunctionMenu.html +1 -0
- package/doc/api-reference/functions/DrawingModule.html +8 -0
- package/doc/api-reference/functions/IndicatorPanel.html +2 -0
- package/doc/api-reference/functions/IndicatorTag.html +2 -0
- package/doc/api-reference/functions/KlineTypeSelector.html +1 -0
- package/doc/api-reference/functions/LayoutSwitcher.html +1 -0
- package/doc/api-reference/functions/PeriodSelector.html +1 -0
- package/doc/api-reference/functions/QLChartLayout.html +1 -0
- package/doc/api-reference/functions/QLChartPanel.html +10 -0
- package/doc/api-reference/functions/QLChartProvider.html +2 -0
- package/doc/api-reference/functions/QLToolbar.html +1 -0
- package/doc/api-reference/functions/ReplayController.html +1 -0
- package/doc/api-reference/functions/TimeBarModule.html +4 -0
- package/doc/api-reference/functions/TimeRangeSelector.html +1 -0
- package/doc/api-reference/functions/createIndicatorConfig.html +2 -0
- package/doc/api-reference/functions/getToolConfig.html +2 -0
- package/doc/api-reference/functions/getToolsByCategory.html +2 -0
- package/doc/api-reference/functions/getToolsByPriority.html +2 -0
- package/doc/api-reference/functions/mapLibTypeToOurs.html +2 -0
- package/doc/api-reference/functions/mapToolTypeToLib.html +3 -0
- package/doc/api-reference/functions/transformCandlestickData.html +3 -0
- package/doc/api-reference/functions/transformIndicatorData.html +2 -0
- package/doc/api-reference/functions/transformVolumeData.html +3 -0
- package/doc/api-reference/functions/useChart.html +4 -0
- package/doc/api-reference/functions/useChartStore.html +8 -0
- package/doc/api-reference/functions/useCrosshairSync.html +8 -0
- package/doc/api-reference/functions/useDrawingModule.html +1 -0
- package/doc/api-reference/functions/useDrawingStore.html +8 -0
- package/doc/api-reference/functions/useIndicatorStore.html +8 -0
- package/doc/api-reference/functions/useQLChartConfig.html +2 -0
- package/doc/api-reference/functions/useReplayStore.html +8 -0
- package/doc/api-reference/functions/useTheme.html +2 -0
- package/doc/api-reference/functions/useTimeBarStore.html +8 -0
- package/doc/api-reference/index.html +1 -0
- package/doc/api-reference/interfaces/CandlestickData.html +7 -0
- package/doc/api-reference/interfaces/CandlestickRawData.html +8 -0
- package/doc/api-reference/interfaces/ChartFunctionMenuProps.html +2 -0
- package/doc/api-reference/interfaces/ChartManagerCreateOptions.html +4 -0
- package/doc/api-reference/interfaces/ChartOptions.html +8 -0
- package/doc/api-reference/interfaces/ChartRequestParams.html +8 -0
- package/doc/api-reference/interfaces/ChartResponse.html +5 -0
- package/doc/api-reference/interfaces/ChartState.html +24 -0
- package/doc/api-reference/interfaces/ChartThemeOptions.html +5 -0
- package/doc/api-reference/interfaces/CrosshairData.html +5 -0
- package/doc/api-reference/interfaces/DrawingModuleProps.html +5 -0
- package/doc/api-reference/interfaces/DrawingState.html +48 -0
- package/doc/api-reference/interfaces/HistogramData.html +5 -0
- package/doc/api-reference/interfaces/HollowCandlestickData.html +14 -0
- package/doc/api-reference/interfaces/IndicatorConfig.html +11 -0
- package/doc/api-reference/interfaces/IndicatorDataPoint.html +4 -0
- package/doc/api-reference/interfaces/IndicatorDataResponse.html +5 -0
- package/doc/api-reference/interfaces/IndicatorDefinition.html +9 -0
- package/doc/api-reference/interfaces/IndicatorPanelProps.html +3 -0
- package/doc/api-reference/interfaces/IndicatorParamDef.html +8 -0
- package/doc/api-reference/interfaces/IndicatorRawData.html +4 -0
- package/doc/api-reference/interfaces/IndicatorState.html +19 -0
- package/doc/api-reference/interfaces/IndicatorTagProps.html +2 -0
- package/doc/api-reference/interfaces/KlineReplayOptions.html +4 -0
- package/doc/api-reference/interfaces/LayoutSwitcherProps.html +3 -0
- package/doc/api-reference/interfaces/LineData.html +4 -0
- package/doc/api-reference/interfaces/MockDataConfig.html +8 -0
- package/doc/api-reference/interfaces/MockIndicatorConfig.html +5 -0
- package/doc/api-reference/interfaces/PairInfo.html +6 -0
- package/doc/api-reference/interfaces/PaneInfo.html +6 -0
- package/doc/api-reference/interfaces/PanelConfig.html +9 -0
- package/doc/api-reference/interfaces/PersistenceConfig.html +12 -0
- package/doc/api-reference/interfaces/QLChartConfig.html +18 -0
- package/doc/api-reference/interfaces/QLChartLayoutProps.html +9 -0
- package/doc/api-reference/interfaces/QLChartPanelProps.html +13 -0
- package/doc/api-reference/interfaces/QLChartPanelRef.html +14 -0
- package/doc/api-reference/interfaces/QLToolbarProps.html +7 -0
- package/doc/api-reference/interfaces/RealtimeCandle.html +9 -0
- package/doc/api-reference/interfaces/RealtimeSubscribeFn.html +2 -0
- package/doc/api-reference/interfaces/RenkoData.html +16 -0
- package/doc/api-reference/interfaces/ReplayControllerProps.html +2 -0
- package/doc/api-reference/interfaces/ReplayState.html +19 -0
- package/doc/api-reference/interfaces/ThemeConfig.html +14 -0
- package/doc/api-reference/interfaces/TimeBarModuleProps.html +5 -0
- package/doc/api-reference/interfaces/TimeBarState.html +13 -0
- package/doc/api-reference/interfaces/UseChartReturn.html +4 -0
- package/doc/api-reference/interfaces/UseDrawingModuleOptions.html +11 -0
- package/doc/api-reference/interfaces/UseDrawingModuleReturn.html +6 -0
- package/doc/api-reference/interfaces/UseThemeReturn.html +5 -0
- package/doc/api-reference/types/EventHandler.html +2 -0
- package/doc/api-reference/types/FetchFn.html +2 -0
- package/doc/api-reference/types/LayoutMode.html +2 -0
- package/doc/api-reference/types/MarketTrend.html +2 -0
- package/doc/api-reference/types/ThemePreset.html +2 -0
- package/doc/api-reference/variables/BUILTIN_INDICATORS.html +2 -0
- package/doc/api-reference/variables/CATEGORY_LABELS.html +2 -0
- package/doc/api-reference/variables/DRAWING_TOOLS.html +3 -0
- package/doc/api-reference/variables/MARKET_PRESETS.html +1 -0
- package/doc/api-reference/variables/PAIR_PRESETS.html +1 -0
- package/doc/api-reference/variables/darkPreset.html +1 -0
- package/doc/api-reference/variables/lightPreset.html +1 -0
- package/doc/components/drawing-module.md +24 -0
- package/doc/components/indicator-list-panel.md +24 -0
- package/doc/components/indicator-panel.md +17 -0
- package/doc/components/pane-divider.md +25 -0
- package/doc/components/qlchart-layout.md +30 -0
- package/doc/components/qlchart-panel.md +93 -0
- package/doc/components/qlchart-provider.md +73 -0
- package/doc/components/qltoolbar.md +17 -0
- package/doc/components/replay-controller.md +23 -0
- package/doc/components/timebar-module.md +13 -0
- package/doc/core/chart-manager.md +14 -0
- package/doc/core/data-manager.md +33 -0
- package/doc/core/event-manager.md +26 -0
- package/doc/core/pane-manager.md +13 -0
- package/doc/core/series-manager.md +19 -0
- package/doc/core/theme-manager.md +21 -0
- package/doc/examples/basic-chart.md +24 -0
- package/doc/examples/data-format-guide.md +119 -0
- package/doc/examples/drawing-tools.md +30 -0
- package/doc/examples/indicator-properties.md +34 -0
- package/doc/examples/multi-pane.md +24 -0
- package/doc/examples/multi-panel.md +23 -0
- package/doc/examples/realtime-data.md +147 -0
- package/doc/examples/standalone-js.md +333 -0
- package/doc/guide/architecture.md +87 -0
- package/doc/guide/data-flow.md +310 -0
- package/doc/guide/deployment.md +59 -0
- package/doc/guide/drawing-properties.md +40 -0
- package/doc/guide/getting-started.md +94 -0
- package/doc/guide/pane-system.md +47 -0
- package/doc/guide/theme-switching.md +58 -0
- package/doc/hooks/use-chart.md +20 -0
- package/doc/hooks/use-crosshair-sync.md +14 -0
- package/doc/hooks/use-drawing-module.md +43 -0
- package/doc/hooks/use-theme.md +15 -0
- package/doc/index.md +33 -0
- package/doc/plugins/drawing/overview.md +36 -0
- package/doc/plugins/drawing/persistence.md +42 -0
- package/doc/plugins/drawing/tool-registry.md +29 -0
- package/doc/plugins/hollow-candlestick.md +18 -0
- package/doc/plugins/indicators.md +28 -0
- package/doc/plugins/renko.md +17 -0
- package/doc/plugins/replay.md +21 -0
- package/doc/plugins/screenshot.md +20 -0
- package/docs/api.md +94 -0
- package/package.json +54 -0
- package/python/qlchart/__init__.py +9 -0
- package/python/qlchart/__pycache__/__init__.cpython-311.pyc +0 -0
- package/python/qlchart/__pycache__/chart.cpython-311.pyc +0 -0
- package/python/qlchart/chart.py +333 -0
- package/python/qlchart/templates/chart_template.html +304 -0
- package/python/requirements.txt +1 -0
- package/python/setup.py +18 -0
- package/python/tests/__init__.py +1 -0
- package/python/tests/__pycache__/__init__.cpython-311.pyc +0 -0
- package/python/tests/__pycache__/test_chart.cpython-311-pytest-8.3.3.pyc +0 -0
- package/python/tests/test_chart.py +114 -0
- package/quantlife-qlchart-0.0.1.tgz +0 -0
- package/src/api/chartApi.ts +30 -0
- package/src/api/indicatorApi.ts +27 -0
- package/src/components/ChartFunctionMenu.tsx +64 -0
- package/src/components/PaneChartPanel.tsx +116 -0
- package/src/components/PaneDivider.tsx +66 -0
- package/src/components/QLChartLayout.tsx +151 -0
- package/src/components/QLChartPanel.tsx +560 -0
- package/src/components/QLChartProvider.tsx +90 -0
- package/src/components/context-menu/ChartContextMenu.tsx +139 -0
- package/src/components/context-menu/index.ts +2 -0
- package/src/components/drawing/DrawingModule.tsx +36 -0
- package/src/components/drawing/DrawingPropertyPanel.tsx +347 -0
- package/src/components/drawing/DrawingToolbar.tsx +305 -0
- package/src/components/drawing/index.ts +5 -0
- package/src/components/index.ts +43 -0
- package/src/components/indicator/IndicatorListPanel.tsx +94 -0
- package/src/components/indicator/IndicatorModal.tsx +171 -0
- package/src/components/indicator/IndicatorPanel.tsx +9 -0
- package/src/components/indicator/IndicatorPropertyPanel.tsx +130 -0
- package/src/components/indicator/IndicatorTag.tsx +173 -0
- package/src/components/indicator/index.ts +4 -0
- package/src/components/replay/ReplayController.css +97 -0
- package/src/components/replay/ReplayController.tsx +138 -0
- package/src/components/timebar/TimeBarModule.tsx +30 -0
- package/src/components/timebar/TimeRangeSelector.tsx +96 -0
- package/src/components/timebar/index.ts +3 -0
- package/src/components/toolbar/GlobalToolbar.tsx +58 -0
- package/src/components/toolbar/KlineTypeSelector.tsx +123 -0
- package/src/components/toolbar/LayoutSwitcher.tsx +45 -0
- package/src/components/toolbar/PeriodSelector.tsx +35 -0
- package/src/components/toolbar/QLToolbar.tsx +71 -0
- package/src/components/toolbar/TimeRangeSelector.tsx +89 -0
- package/src/components/ui/Modal.tsx +67 -0
- package/src/core/ChartManager.ts +95 -0
- package/src/core/DataManager.ts +427 -0
- package/src/core/EventManager.ts +63 -0
- package/src/core/IndicatorDataProcessor.ts +104 -0
- package/src/core/PaneManager.ts +121 -0
- package/src/core/RealtimeDataFeed.ts +110 -0
- package/src/core/SeriesManager.ts +210 -0
- package/src/core/ThemeManager.ts +59 -0
- package/src/core/index.ts +10 -0
- package/src/css.d.ts +4 -0
- package/src/hooks/useChart.ts +62 -0
- package/src/hooks/useCrosshairSync.ts +109 -0
- package/src/hooks/useDrawingModule.ts +475 -0
- package/src/hooks/useTheme.ts +31 -0
- package/src/index.ts +170 -0
- package/src/mock/MockDataService.ts +102 -0
- package/src/mock/MockIndicatorService.ts +40 -0
- package/src/mock/index.ts +5 -0
- package/src/mock/presets.ts +16 -0
- package/src/plugins/drawing/DrawingAdapter.ts +1762 -0
- package/src/plugins/drawing/DrawingPersistence.ts +273 -0
- package/src/plugins/drawing/DrawingPropertyTemplates.ts +327 -0
- package/src/plugins/drawing/DrawingSharedService.ts +125 -0
- package/src/plugins/drawing/DrawingToolRegistry.ts +684 -0
- package/src/plugins/drawing/TextLabelOverlay.ts +101 -0
- package/src/plugins/drawing/colorUtils.ts +53 -0
- package/src/plugins/drawing/index.ts +10 -0
- package/src/plugins/drawing/lineStyleMap.ts +46 -0
- package/src/plugins/drawing/migration.ts +105 -0
- package/src/plugins/drawing/patterns/PatternDefinitions.ts +57 -0
- package/src/plugins/drawing/patterns/index.ts +2 -0
- package/src/plugins/drawing/periodUtils.ts +51 -0
- package/src/plugins/indicators/AutoIndicatorRenderer.ts +204 -0
- package/src/plugins/indicators/IndicatorRenderer.ts +350 -0
- package/src/plugins/indicators/OverlayIndicator.ts +114 -0
- package/src/plugins/indicators/PaneIndicator.ts +137 -0
- package/src/plugins/indicators/index.ts +4 -0
- package/src/plugins/replay/KlineReplay.ts +163 -0
- package/src/plugins/replay/index.ts +2 -0
- package/src/plugins/screenshot/ScreenshotUtil.ts +123 -0
- package/src/plugins/screenshot/index.ts +1 -0
- package/src/plugins/series/HollowCandlestickSeries.ts +111 -0
- package/src/plugins/series/RenkoSeries.ts +104 -0
- package/src/plugins/series/VolumeCandlestickSeries.ts +127 -0
- package/src/plugins/series/index.ts +6 -0
- package/src/standalone.ts +386 -0
- package/src/store/useChartStore.ts +101 -0
- package/src/store/useDrawingStore.ts +135 -0
- package/src/store/useIndicatorStore.ts +100 -0
- package/src/store/usePanelRegistry.ts +50 -0
- package/src/store/useReplayStore.ts +42 -0
- package/src/store/useTimeBarStore.ts +34 -0
- package/src/styles/chart.css +312 -0
- package/src/styles/components.css +184 -0
- package/src/styles/context-menu.css +60 -0
- package/src/styles/drawing.css +524 -0
- package/src/styles/indicator-modal.css +216 -0
- package/src/styles/indicator-tag.css +210 -0
- package/src/styles/pane-chart.css +9 -0
- package/src/styles/responsive.css +71 -0
- package/src/styles/themes/dark.css +63 -0
- package/src/styles/themes/light.css +61 -0
- package/src/styles/toolbar.css +129 -0
- package/src/types/api.ts +36 -0
- package/src/types/chart.ts +44 -0
- package/src/types/drawing.ts +265 -0
- package/src/types/index.ts +40 -0
- package/src/types/indicator.ts +344 -0
- package/src/types/series.ts +53 -0
- package/src/types/theme.ts +48 -0
- package/src/utils/dataTransformer.ts +63 -0
- package/src/utils/heikinAshi.ts +41 -0
- package/src/utils/index.ts +3 -0
- package/src/utils/lineBreak.ts +88 -0
- package/src/utils/themePresets.ts +69 -0
- package/src/utils/timeFormatter.ts +29 -0
- package/src/utils/timeScaleUtils.ts +68 -0
- package/tsconfig.json +21 -0
- package/typedoc.json +10 -0
- package/vite.config.standalone.ts +31 -0
- package/vite.config.ts +24 -0
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
import { useState, useCallback, useMemo, useEffect, useRef } from 'react';
|
|
2
|
+
import { createPortal } from 'react-dom';
|
|
3
|
+
import {
|
|
4
|
+
DRAWING_TOOLS,
|
|
5
|
+
getToolsByCategory,
|
|
6
|
+
CATEGORY_LABELS,
|
|
7
|
+
} from '../../plugins/drawing/DrawingToolRegistry.js';
|
|
8
|
+
import { DrawingToolCategory } from '../../types/index.js';
|
|
9
|
+
import type { DrawingToolType, DrawingToolConfig } from '../../types/index.js';
|
|
10
|
+
import { useDrawingStore } from '../../store/useDrawingStore.js';
|
|
11
|
+
import { useChartStore } from '../../store/useChartStore.js';
|
|
12
|
+
import { usePanelRegistry } from '../../store/usePanelRegistry.js';
|
|
13
|
+
|
|
14
|
+
/** 分类排序 */
|
|
15
|
+
const CATEGORY_ORDER: DrawingToolCategory[] = [
|
|
16
|
+
DrawingToolCategory.Lines,
|
|
17
|
+
DrawingToolCategory.Channels,
|
|
18
|
+
DrawingToolCategory.Fibonacci,
|
|
19
|
+
DrawingToolCategory.Shapes,
|
|
20
|
+
DrawingToolCategory.Annotations,
|
|
21
|
+
DrawingToolCategory.Positions,
|
|
22
|
+
DrawingToolCategory.Measure,
|
|
23
|
+
DrawingToolCategory.Patterns,
|
|
24
|
+
];
|
|
25
|
+
|
|
26
|
+
export function DrawingToolbar() {
|
|
27
|
+
const activeTool = useDrawingStore((s) => s.activeTool);
|
|
28
|
+
const magnetEnabled = useDrawingStore((s) => s.magnetEnabled);
|
|
29
|
+
const expandedCategory = useDrawingStore((s) => s.expandedCategory);
|
|
30
|
+
const categoryActiveTools = useDrawingStore((s) => s.categoryActiveTools);
|
|
31
|
+
const drawingCount = useDrawingStore((s) => s.drawingCount);
|
|
32
|
+
const setActiveTool = useDrawingStore((s) => s.setActiveTool);
|
|
33
|
+
const setMagnetEnabled = useDrawingStore((s) => s.setMagnetEnabled);
|
|
34
|
+
const setExpandedCategory = useDrawingStore((s) => s.setExpandedCategory);
|
|
35
|
+
const setCategoryActiveTool = useDrawingStore((s) => s.setCategoryActiveTool);
|
|
36
|
+
|
|
37
|
+
// Bug2/功能1:从 store 获取工具栏拖拽状态
|
|
38
|
+
const toolbarOrientation = useDrawingStore((s) => s.toolbarOrientation);
|
|
39
|
+
const toolbarPosition = useDrawingStore((s) => s.toolbarPosition);
|
|
40
|
+
const isToolbarDragging = useDrawingStore((s) => s.isToolbarDragging);
|
|
41
|
+
const setToolbarOrientation = useDrawingStore((s) => s.setToolbarOrientation);
|
|
42
|
+
const setToolbarPosition = useDrawingStore((s) => s.setToolbarPosition);
|
|
43
|
+
const setIsToolbarDragging = useDrawingStore((s) => s.setIsToolbarDragging);
|
|
44
|
+
// ★ V2: 副图绘图 pane 指示器
|
|
45
|
+
const currentPaneIndex = useDrawingStore((s) => s.currentPaneIndex);
|
|
46
|
+
|
|
47
|
+
const activePanelId = useChartStore((s) => s.activePanelId);
|
|
48
|
+
const getHandle = usePanelRegistry((s) => s.getHandle);
|
|
49
|
+
|
|
50
|
+
const [allVisible, setAllVisible] = useState(true);
|
|
51
|
+
|
|
52
|
+
// 功能1:拖拽逻辑
|
|
53
|
+
const toolbarRef = useRef<HTMLDivElement>(null);
|
|
54
|
+
const dragStartRef = useRef<{ mouseX: number; mouseY: number; toolbarX: number; toolbarY: number } | null>(null);
|
|
55
|
+
|
|
56
|
+
const handleDragStart = useCallback((e: React.MouseEvent) => {
|
|
57
|
+
e.preventDefault();
|
|
58
|
+
e.stopPropagation();
|
|
59
|
+
const toolbar = toolbarRef.current;
|
|
60
|
+
const parent = toolbar?.parentElement;
|
|
61
|
+
if (!toolbar || !parent) return;
|
|
62
|
+
|
|
63
|
+
const toolbarRect = toolbar.getBoundingClientRect();
|
|
64
|
+
const parentRect = parent.getBoundingClientRect();
|
|
65
|
+
const currentPos = toolbarPosition ?? {
|
|
66
|
+
x: toolbarRect.left - parentRect.left,
|
|
67
|
+
y: toolbarRect.top - parentRect.top,
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
dragStartRef.current = {
|
|
71
|
+
mouseX: e.clientX, mouseY: e.clientY,
|
|
72
|
+
toolbarX: currentPos.x, toolbarY: currentPos.y,
|
|
73
|
+
};
|
|
74
|
+
setIsToolbarDragging(true);
|
|
75
|
+
}, [toolbarPosition, setIsToolbarDragging]);
|
|
76
|
+
|
|
77
|
+
useEffect(() => {
|
|
78
|
+
if (!isToolbarDragging) return;
|
|
79
|
+
|
|
80
|
+
const handleMouseMove = (e: MouseEvent) => {
|
|
81
|
+
const start = dragStartRef.current;
|
|
82
|
+
if (!start) return;
|
|
83
|
+
const parent = toolbarRef.current?.parentElement;
|
|
84
|
+
if (!parent) return;
|
|
85
|
+
const parentRect = parent.getBoundingClientRect();
|
|
86
|
+
const toolbarW = toolbarRef.current?.offsetWidth ?? 40;
|
|
87
|
+
const toolbarH = toolbarRef.current?.offsetHeight ?? 200;
|
|
88
|
+
|
|
89
|
+
const newX = Math.max(0, Math.min(parentRect.width - toolbarW, start.toolbarX + (e.clientX - start.mouseX)));
|
|
90
|
+
const newY = Math.max(0, Math.min(parentRect.height - toolbarH, start.toolbarY + (e.clientY - start.mouseY)));
|
|
91
|
+
setToolbarPosition({ x: newX, y: newY });
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const handleMouseUp = () => {
|
|
95
|
+
setIsToolbarDragging(false);
|
|
96
|
+
dragStartRef.current = null;
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
document.addEventListener('mousemove', handleMouseMove);
|
|
100
|
+
document.addEventListener('mouseup', handleMouseUp);
|
|
101
|
+
return () => {
|
|
102
|
+
document.removeEventListener('mousemove', handleMouseMove);
|
|
103
|
+
document.removeEventListener('mouseup', handleMouseUp);
|
|
104
|
+
};
|
|
105
|
+
}, [isToolbarDragging, setToolbarPosition, setIsToolbarDragging]);
|
|
106
|
+
|
|
107
|
+
const handleToggleOrientation = useCallback(() => {
|
|
108
|
+
setToolbarPosition(null);
|
|
109
|
+
setToolbarOrientation(toolbarOrientation === 'vertical' ? 'horizontal' : 'vertical');
|
|
110
|
+
}, [toolbarOrientation, setToolbarOrientation, setToolbarPosition]);
|
|
111
|
+
|
|
112
|
+
// 绘图数量归零时重置 allVisible
|
|
113
|
+
useEffect(() => {
|
|
114
|
+
if (drawingCount === 0) setAllVisible(true);
|
|
115
|
+
}, [drawingCount]);
|
|
116
|
+
|
|
117
|
+
const grouped = useMemo(() => {
|
|
118
|
+
const byCategory = getToolsByCategory();
|
|
119
|
+
const result: Array<{ category: DrawingToolCategory; label: string; tools: DrawingToolConfig[] }> = [];
|
|
120
|
+
for (const cat of CATEGORY_ORDER) {
|
|
121
|
+
const tools = byCategory.get(cat);
|
|
122
|
+
if (tools && tools.length > 0) {
|
|
123
|
+
result.push({
|
|
124
|
+
category: cat,
|
|
125
|
+
label: CATEGORY_LABELS[cat],
|
|
126
|
+
tools: tools.sort((a, b) => a.priority - b.priority),
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return result;
|
|
131
|
+
}, []);
|
|
132
|
+
|
|
133
|
+
const handleCategoryClick = useCallback((category: DrawingToolCategory) => {
|
|
134
|
+
if (expandedCategory === category) {
|
|
135
|
+
setExpandedCategory(null); // 再次点击折叠
|
|
136
|
+
} else {
|
|
137
|
+
setExpandedCategory(category);
|
|
138
|
+
}
|
|
139
|
+
}, [expandedCategory, setExpandedCategory]);
|
|
140
|
+
|
|
141
|
+
const handleToolSelect = useCallback((tool: DrawingToolConfig) => {
|
|
142
|
+
setActiveTool(tool.type);
|
|
143
|
+
setCategoryActiveTool(tool.category, tool.type);
|
|
144
|
+
setExpandedCategory(null); // 选中后折叠
|
|
145
|
+
}, [setActiveTool, setCategoryActiveTool, setExpandedCategory]);
|
|
146
|
+
|
|
147
|
+
// 获取分类行显示的 icon(当前选中工具 or 分类第一个工具)
|
|
148
|
+
const getCategoryIcon = useCallback((category: DrawingToolCategory) => {
|
|
149
|
+
const activeInCategory = categoryActiveTools[category];
|
|
150
|
+
if (activeInCategory) {
|
|
151
|
+
const tool = DRAWING_TOOLS.find(t => t.type === activeInCategory);
|
|
152
|
+
if (tool) return tool.icon;
|
|
153
|
+
}
|
|
154
|
+
const tools = grouped.find(g => g.category === category)?.tools;
|
|
155
|
+
return tools?.[0]?.icon ?? '📌';
|
|
156
|
+
}, [categoryActiveTools, grouped]);
|
|
157
|
+
|
|
158
|
+
// 判断分类是否有工具被选中
|
|
159
|
+
const isCategoryActive = useCallback((category: DrawingToolCategory) => {
|
|
160
|
+
const tools = grouped.find(g => g.category === category)?.tools ?? [];
|
|
161
|
+
return tools.some(t => t.type === activeTool);
|
|
162
|
+
}, [activeTool, grouped]);
|
|
163
|
+
|
|
164
|
+
// 批量操作:删除所有(带确认)
|
|
165
|
+
const [deleteAllConfirmOpen, setDeleteAllConfirmOpen] = useState(false);
|
|
166
|
+
|
|
167
|
+
const handleDeleteAll = useCallback(() => {
|
|
168
|
+
setDeleteAllConfirmOpen(true);
|
|
169
|
+
}, []);
|
|
170
|
+
|
|
171
|
+
const handleDeleteAllConfirm = useCallback(() => {
|
|
172
|
+
const handle = getHandle(activePanelId ?? 'panel_0');
|
|
173
|
+
handle?.drawingAdapter?.clearAll();
|
|
174
|
+
setDeleteAllConfirmOpen(false);
|
|
175
|
+
}, [activePanelId, getHandle]);
|
|
176
|
+
|
|
177
|
+
// 批量操作:隐藏/显示切换
|
|
178
|
+
const handleToggleVisible = useCallback(() => {
|
|
179
|
+
const handle = getHandle(activePanelId ?? 'panel_0');
|
|
180
|
+
const adapter = handle?.drawingAdapter;
|
|
181
|
+
if (!adapter) return;
|
|
182
|
+
const newVisible = !allVisible;
|
|
183
|
+
adapter.setAllVisible(newVisible);
|
|
184
|
+
setAllVisible(newVisible);
|
|
185
|
+
}, [activePanelId, getHandle, allVisible]);
|
|
186
|
+
|
|
187
|
+
return (
|
|
188
|
+
<div
|
|
189
|
+
ref={toolbarRef}
|
|
190
|
+
className={`qlchart-drawing-toolbar-${toolbarOrientation === 'vertical' ? 'vertical' : 'horizontal'}${isToolbarDragging ? ' dragging' : ''}`}
|
|
191
|
+
style={toolbarPosition ? { position: 'absolute' as const, left: toolbarPosition.x, top: toolbarPosition.y, zIndex: 100 } : {}}
|
|
192
|
+
>
|
|
193
|
+
{/* 功能1:拖拽把手 */}
|
|
194
|
+
<div
|
|
195
|
+
className="qlchart-dvt-drag-handle"
|
|
196
|
+
onMouseDown={handleDragStart}
|
|
197
|
+
title="拖拽移动工具栏"
|
|
198
|
+
>
|
|
199
|
+
⠿
|
|
200
|
+
</div>
|
|
201
|
+
|
|
202
|
+
{/* 光标按钮 */}
|
|
203
|
+
<button
|
|
204
|
+
className={`qlchart-dvt-btn ${activeTool === 'cursor' ? 'active' : ''}`}
|
|
205
|
+
onClick={() => setActiveTool('cursor')}
|
|
206
|
+
title="光标"
|
|
207
|
+
>
|
|
208
|
+
👆
|
|
209
|
+
</button>
|
|
210
|
+
|
|
211
|
+
{/* 分类按钮 */}
|
|
212
|
+
{grouped.map(({ category }) => (
|
|
213
|
+
<div key={category} className="qlchart-dvt-category">
|
|
214
|
+
<button
|
|
215
|
+
className={`qlchart-dvt-btn ${expandedCategory === category ? 'expanded' : ''} ${isCategoryActive(category) ? 'has-active' : ''}`}
|
|
216
|
+
onClick={() => handleCategoryClick(category)}
|
|
217
|
+
title={CATEGORY_LABELS[category]}
|
|
218
|
+
>
|
|
219
|
+
{getCategoryIcon(category)}
|
|
220
|
+
</button>
|
|
221
|
+
|
|
222
|
+
{/* 展开的子面板 */}
|
|
223
|
+
{expandedCategory === category && (
|
|
224
|
+
<div className="qlchart-dvt-subpanel">
|
|
225
|
+
{grouped.find(g => g.category === category)?.tools.map(tool => (
|
|
226
|
+
<button
|
|
227
|
+
key={tool.type}
|
|
228
|
+
className={`qlchart-dvt-sub-btn ${activeTool === tool.type ? 'active' : ''}`}
|
|
229
|
+
onClick={() => handleToolSelect(tool)}
|
|
230
|
+
title={tool.label}
|
|
231
|
+
>
|
|
232
|
+
{tool.icon}
|
|
233
|
+
<span className="qlchart-dvt-sub-label">{tool.label}</span>
|
|
234
|
+
</button>
|
|
235
|
+
))}
|
|
236
|
+
</div>
|
|
237
|
+
)}
|
|
238
|
+
</div>
|
|
239
|
+
))}
|
|
240
|
+
|
|
241
|
+
{/* 磁铁吸附 */}
|
|
242
|
+
<div className="qlchart-dvt-separator" />
|
|
243
|
+
<button
|
|
244
|
+
className={`qlchart-dvt-btn ${magnetEnabled ? 'active' : ''}`}
|
|
245
|
+
onClick={() => setMagnetEnabled(!magnetEnabled)}
|
|
246
|
+
title="磁铁吸附"
|
|
247
|
+
>
|
|
248
|
+
🧲
|
|
249
|
+
</button>
|
|
250
|
+
|
|
251
|
+
{/* 批量操作(drawingCount > 0 时显示) */}
|
|
252
|
+
{drawingCount > 0 && (
|
|
253
|
+
<>
|
|
254
|
+
<div className="qlchart-dvt-separator" />
|
|
255
|
+
<button
|
|
256
|
+
className="qlchart-dvt-btn"
|
|
257
|
+
onClick={handleToggleVisible}
|
|
258
|
+
title={allVisible ? '隐藏所有' : '显示所有'}
|
|
259
|
+
>
|
|
260
|
+
{allVisible ? '🙈' : '👁️'}
|
|
261
|
+
</button>
|
|
262
|
+
<button
|
|
263
|
+
className="qlchart-dvt-btn"
|
|
264
|
+
onClick={handleDeleteAll}
|
|
265
|
+
title="删除所有"
|
|
266
|
+
>
|
|
267
|
+
🗑️
|
|
268
|
+
</button>
|
|
269
|
+
</>
|
|
270
|
+
)}
|
|
271
|
+
|
|
272
|
+
{/* ★ V2: 副图 pane 指示器 */}
|
|
273
|
+
{currentPaneIndex > 0 && (
|
|
274
|
+
<div className="qlchart-dvt-pane-indicator">
|
|
275
|
+
<span className="qlchart-dvt-pane-badge">P{currentPaneIndex}</span>
|
|
276
|
+
</div>
|
|
277
|
+
)}
|
|
278
|
+
|
|
279
|
+
{/* 功能1:底部横竖转换按钮 */}
|
|
280
|
+
<button
|
|
281
|
+
className="qlchart-dvt-btn qlchart-dvt-orientation-toggle"
|
|
282
|
+
onClick={handleToggleOrientation}
|
|
283
|
+
title={toolbarOrientation === 'vertical' ? '切换为横向' : '切换为纵向'}
|
|
284
|
+
>
|
|
285
|
+
{toolbarOrientation === 'vertical' ? '⤵' : '⤴'}
|
|
286
|
+
</button>
|
|
287
|
+
|
|
288
|
+
{/* ★ 需求2:删除所有确认 Modal */}
|
|
289
|
+
{deleteAllConfirmOpen && createPortal(
|
|
290
|
+
<div className="qlchart-confirm-overlay" onClick={() => setDeleteAllConfirmOpen(false)}>
|
|
291
|
+
<div className="qlchart-confirm-modal" onClick={(e) => e.stopPropagation()}>
|
|
292
|
+
<div className="qlchart-confirm-icon">⚠️</div>
|
|
293
|
+
<div className="qlchart-confirm-title">确认删除所有绘图</div>
|
|
294
|
+
<div className="qlchart-confirm-desc">确定要删除所有绘图吗?此操作不可撤销。</div>
|
|
295
|
+
<div className="qlchart-confirm-actions">
|
|
296
|
+
<button className="qlchart-confirm-cancel" onClick={() => setDeleteAllConfirmOpen(false)}>取消</button>
|
|
297
|
+
<button className="qlchart-confirm-ok" onClick={handleDeleteAllConfirm}>🗑️ 全部删除</button>
|
|
298
|
+
</div>
|
|
299
|
+
</div>
|
|
300
|
+
</div>,
|
|
301
|
+
document.body,
|
|
302
|
+
)}
|
|
303
|
+
</div>
|
|
304
|
+
);
|
|
305
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { DrawingToolbar } from './DrawingToolbar.js';
|
|
2
|
+
export { DrawingPropertyPanel } from './DrawingPropertyPanel.js';
|
|
3
|
+
export type { DrawingPropertyPanelProps } from './DrawingPropertyPanel.js';
|
|
4
|
+
export { DrawingModule } from './DrawingModule.js';
|
|
5
|
+
export type { DrawingModuleProps } from './DrawingModule.js';
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export { QLChartProvider, useQLChartConfig, QLChartContext } from './QLChartProvider.js';
|
|
2
|
+
export type { QLChartConfig, RealtimeSubscribeFn, RealtimeCandle as ProviderRealtimeCandle } from './QLChartProvider.js';
|
|
3
|
+
export { QLChartPanel } from './QLChartPanel.js';
|
|
4
|
+
export type { QLChartPanelProps, QLChartPanelRef } from './QLChartPanel.js';
|
|
5
|
+
export { QLToolbar } from './toolbar/QLToolbar.js';
|
|
6
|
+
export type { QLToolbarProps } from './toolbar/QLToolbar.js';
|
|
7
|
+
export { PeriodSelector } from './toolbar/PeriodSelector.js';
|
|
8
|
+
export { TimeRangeSelector } from './timebar/TimeRangeSelector.js';
|
|
9
|
+
export { KlineTypeSelector } from './toolbar/KlineTypeSelector.js';
|
|
10
|
+
|
|
11
|
+
// Indicator components
|
|
12
|
+
export { IndicatorPanel } from './indicator/index.js';
|
|
13
|
+
export type { IndicatorPanelProps } from './indicator/index.js';
|
|
14
|
+
export { IndicatorTag } from './indicator/index.js';
|
|
15
|
+
export type { IndicatorTagProps } from './indicator/index.js';
|
|
16
|
+
|
|
17
|
+
// Drawing components
|
|
18
|
+
export { DrawingToolbar, DrawingPropertyPanel } from './drawing/index.js';
|
|
19
|
+
export type { DrawingPropertyPanelProps } from './drawing/index.js';
|
|
20
|
+
export { DrawingModule } from './drawing/index.js';
|
|
21
|
+
export type { DrawingModuleProps } from './drawing/index.js';
|
|
22
|
+
|
|
23
|
+
// Context Menu
|
|
24
|
+
export { ChartContextMenu } from './context-menu/index.js';
|
|
25
|
+
export type { ChartContextMenuProps } from './context-menu/index.js';
|
|
26
|
+
|
|
27
|
+
// ChartFunctionMenu
|
|
28
|
+
export { ChartFunctionMenu } from './ChartFunctionMenu.js';
|
|
29
|
+
export type { ChartFunctionMenuProps } from './ChartFunctionMenu.js';
|
|
30
|
+
|
|
31
|
+
// TimeBar components
|
|
32
|
+
export { TimeBarModule } from './timebar/index.js';
|
|
33
|
+
export type { TimeBarModuleProps } from './timebar/index.js';
|
|
34
|
+
|
|
35
|
+
// Layout
|
|
36
|
+
export { QLChartLayout } from './QLChartLayout.js';
|
|
37
|
+
export type { QLChartLayoutProps } from './QLChartLayout.js';
|
|
38
|
+
export { LayoutSwitcher } from './toolbar/LayoutSwitcher.js';
|
|
39
|
+
export type { LayoutSwitcherProps } from './toolbar/LayoutSwitcher.js';
|
|
40
|
+
|
|
41
|
+
// Replay
|
|
42
|
+
export { ReplayController } from './replay/ReplayController.js';
|
|
43
|
+
export type { ReplayControllerProps } from './replay/ReplayController.js';
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { useMemo, useState } from 'react';
|
|
2
|
+
import type { IndicatorTemplate } from '../../types/indicator.js';
|
|
3
|
+
|
|
4
|
+
export interface IndicatorListPanelProps {
|
|
5
|
+
/** 可用指标列表 */
|
|
6
|
+
indicators: IndicatorTemplate[];
|
|
7
|
+
/** 当前激活的指标key列表 */
|
|
8
|
+
activeKeys: string[];
|
|
9
|
+
/** 选择指标回调 */
|
|
10
|
+
onSelect: (template: IndicatorTemplate) => void;
|
|
11
|
+
/** 取消选择回调 */
|
|
12
|
+
onDeselect: (key: string) => void;
|
|
13
|
+
/** 关闭面板 */
|
|
14
|
+
onClose: () => void;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* IndicatorListPanel - 指标列表选择面板
|
|
19
|
+
* 按category分组展示所有可用指标
|
|
20
|
+
*/
|
|
21
|
+
export function IndicatorListPanel({
|
|
22
|
+
indicators,
|
|
23
|
+
activeKeys,
|
|
24
|
+
onSelect,
|
|
25
|
+
onDeselect,
|
|
26
|
+
onClose,
|
|
27
|
+
}: IndicatorListPanelProps) {
|
|
28
|
+
const [search, setSearch] = useState('');
|
|
29
|
+
|
|
30
|
+
// 按category分组
|
|
31
|
+
const grouped = useMemo(() => {
|
|
32
|
+
const filtered = search
|
|
33
|
+
? indicators.filter(i =>
|
|
34
|
+
i.label.toLowerCase().includes(search.toLowerCase()) ||
|
|
35
|
+
i.key.toLowerCase().includes(search.toLowerCase())
|
|
36
|
+
)
|
|
37
|
+
: indicators;
|
|
38
|
+
|
|
39
|
+
const map = new Map<string, IndicatorTemplate[]>();
|
|
40
|
+
for (const ind of filtered) {
|
|
41
|
+
const cat = ind.category || '其他';
|
|
42
|
+
if (!map.has(cat)) map.set(cat, []);
|
|
43
|
+
map.get(cat)!.push(ind);
|
|
44
|
+
}
|
|
45
|
+
// 按sortOrder排序
|
|
46
|
+
for (const [, list] of map) {
|
|
47
|
+
list.sort((a, b) => (a.sortOrder ?? 99) - (b.sortOrder ?? 99));
|
|
48
|
+
}
|
|
49
|
+
return Array.from(map.entries());
|
|
50
|
+
}, [indicators, search]);
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<div className="qlchart-indicator-list-panel">
|
|
54
|
+
<div className="qlchart-indicator-list-header">
|
|
55
|
+
<span>指标管理</span>
|
|
56
|
+
<button onClick={onClose}>✕</button>
|
|
57
|
+
</div>
|
|
58
|
+
|
|
59
|
+
<div className="qlchart-indicator-list-search">
|
|
60
|
+
<input
|
|
61
|
+
type="text"
|
|
62
|
+
placeholder="搜索指标..."
|
|
63
|
+
value={search}
|
|
64
|
+
onChange={e => setSearch(e.target.value)}
|
|
65
|
+
/>
|
|
66
|
+
</div>
|
|
67
|
+
|
|
68
|
+
<div className="qlchart-indicator-list-body">
|
|
69
|
+
{grouped.map(([category, list]) => (
|
|
70
|
+
<div key={category} className="qlchart-indicator-list-group">
|
|
71
|
+
<div className="qlchart-indicator-list-group-title">{category}</div>
|
|
72
|
+
{list.map(ind => {
|
|
73
|
+
const isActive = activeKeys.includes(ind.key);
|
|
74
|
+
return (
|
|
75
|
+
<div
|
|
76
|
+
key={ind.key}
|
|
77
|
+
className={`qlchart-indicator-list-item ${isActive ? 'active' : ''}`}
|
|
78
|
+
onClick={() => isActive ? onDeselect(ind.key) : onSelect(ind)}
|
|
79
|
+
>
|
|
80
|
+
<span className="qlchart-indicator-list-icon">{ind.icon ?? '📊'}</span>
|
|
81
|
+
<div className="qlchart-indicator-list-info">
|
|
82
|
+
<div className="qlchart-indicator-list-label">{ind.label}</div>
|
|
83
|
+
<div className="qlchart-indicator-list-desc">{ind.description}</div>
|
|
84
|
+
</div>
|
|
85
|
+
<span className="qlchart-indicator-list-check">{isActive ? '✓' : '+'}</span>
|
|
86
|
+
</div>
|
|
87
|
+
);
|
|
88
|
+
})}
|
|
89
|
+
</div>
|
|
90
|
+
))}
|
|
91
|
+
</div>
|
|
92
|
+
</div>
|
|
93
|
+
);
|
|
94
|
+
}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { useState, useMemo, useCallback } from 'react';
|
|
2
|
+
import { createPortal } from 'react-dom';
|
|
3
|
+
import {
|
|
4
|
+
useIndicatorStore,
|
|
5
|
+
createIndicatorConfig,
|
|
6
|
+
} from '../../store/useIndicatorStore.js';
|
|
7
|
+
import {
|
|
8
|
+
type IndicatorDefinition,
|
|
9
|
+
type IndicatorConfig,
|
|
10
|
+
IndicatorType,
|
|
11
|
+
} from '../../types/index.js';
|
|
12
|
+
|
|
13
|
+
export interface IndicatorModalProps {
|
|
14
|
+
open: boolean;
|
|
15
|
+
onClose: () => void;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** 向后兼容别名 */
|
|
19
|
+
export type IndicatorPanelProps = IndicatorModalProps;
|
|
20
|
+
|
|
21
|
+
/** 分类标签映射 */
|
|
22
|
+
const CATEGORY_LABELS: Record<string, string> = {
|
|
23
|
+
all: '全部',
|
|
24
|
+
trend: '趋势',
|
|
25
|
+
oscillator: '震荡',
|
|
26
|
+
volume: '成交量',
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/** 根据指标名称推断分类 */
|
|
30
|
+
function inferCategory(def: IndicatorDefinition): string {
|
|
31
|
+
if (def.type === IndicatorType.Overlay) return 'trend';
|
|
32
|
+
const name = def.name.toUpperCase();
|
|
33
|
+
if (name === 'OBV') return 'volume';
|
|
34
|
+
return 'oscillator';
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function IndicatorModal({ open, onClose }: IndicatorModalProps) {
|
|
38
|
+
const availableIndicators = useIndicatorStore((s) => s.availableIndicators);
|
|
39
|
+
const activeIndicators = useIndicatorStore((s) => s.activeIndicators);
|
|
40
|
+
const addIndicator = useIndicatorStore((s) => s.addIndicator);
|
|
41
|
+
const removeIndicator = useIndicatorStore((s) => s.removeIndicator);
|
|
42
|
+
|
|
43
|
+
const [searchKeyword, setSearchKeyword] = useState('');
|
|
44
|
+
const [activeCategory, setActiveCategory] = useState('all');
|
|
45
|
+
|
|
46
|
+
const allIndicators = useMemo(() => availableIndicators, [availableIndicators]);
|
|
47
|
+
|
|
48
|
+
// 动态提取分类
|
|
49
|
+
const categories = useMemo(() => {
|
|
50
|
+
const cats = new Set(allIndicators.map((i) => inferCategory(i)));
|
|
51
|
+
return ['all', ...Array.from(cats)];
|
|
52
|
+
}, [allIndicators]);
|
|
53
|
+
|
|
54
|
+
// 过滤
|
|
55
|
+
const filtered = useMemo(() => {
|
|
56
|
+
let result = allIndicators;
|
|
57
|
+
if (activeCategory !== 'all') {
|
|
58
|
+
result = result.filter((i) => inferCategory(i) === activeCategory);
|
|
59
|
+
}
|
|
60
|
+
if (searchKeyword) {
|
|
61
|
+
const kw = searchKeyword.toLowerCase();
|
|
62
|
+
result = result.filter(
|
|
63
|
+
(i) =>
|
|
64
|
+
i.name.toLowerCase().includes(kw) ||
|
|
65
|
+
(i.label ?? '').toLowerCase().includes(kw),
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
return result;
|
|
69
|
+
}, [allIndicators, activeCategory, searchKeyword]);
|
|
70
|
+
|
|
71
|
+
const isActive = useCallback(
|
|
72
|
+
(name: string) => activeIndicators.some((i) => i.name === name),
|
|
73
|
+
[activeIndicators],
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
const getActiveConfig = useCallback(
|
|
77
|
+
(name: string): IndicatorConfig | undefined =>
|
|
78
|
+
activeIndicators.find((i) => i.name === name),
|
|
79
|
+
[activeIndicators],
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
const handleToggle = useCallback(
|
|
83
|
+
(def: IndicatorDefinition) => {
|
|
84
|
+
if (isActive(def.name)) {
|
|
85
|
+
const config = getActiveConfig(def.name);
|
|
86
|
+
if (config) removeIndicator(config.id);
|
|
87
|
+
} else {
|
|
88
|
+
addIndicator(createIndicatorConfig(def));
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
[isActive, getActiveConfig, addIndicator, removeIndicator],
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
if (!open) return null;
|
|
95
|
+
|
|
96
|
+
// ★ Bug3修复:使用 Portal 渲染到 document.body,避免被容器 overflow:hidden 裁剪
|
|
97
|
+
return createPortal(
|
|
98
|
+
<div className="qlchart-modal-overlay" onClick={onClose}>
|
|
99
|
+
<div
|
|
100
|
+
className="qlchart-indicator-modal"
|
|
101
|
+
onClick={(e) => e.stopPropagation()}
|
|
102
|
+
>
|
|
103
|
+
{/* Header */}
|
|
104
|
+
<div className="qlchart-modal-header">
|
|
105
|
+
<span>📊 指标管理</span>
|
|
106
|
+
<button className="qlchart-modal-close" onClick={onClose}>
|
|
107
|
+
✕
|
|
108
|
+
</button>
|
|
109
|
+
</div>
|
|
110
|
+
|
|
111
|
+
{/* Search */}
|
|
112
|
+
<div className="qlchart-modal-search">
|
|
113
|
+
<input
|
|
114
|
+
placeholder="搜索指标名称..."
|
|
115
|
+
value={searchKeyword}
|
|
116
|
+
onChange={(e) => setSearchKeyword(e.target.value)}
|
|
117
|
+
/>
|
|
118
|
+
</div>
|
|
119
|
+
|
|
120
|
+
{/* Body: Sidebar + Content */}
|
|
121
|
+
<div className="qlchart-modal-body">
|
|
122
|
+
<div className="qlchart-modal-sidebar">
|
|
123
|
+
{categories.map((cat) => (
|
|
124
|
+
<button
|
|
125
|
+
key={cat}
|
|
126
|
+
className={`qlchart-modal-tab ${
|
|
127
|
+
activeCategory === cat ? 'active' : ''
|
|
128
|
+
}`}
|
|
129
|
+
onClick={() => setActiveCategory(cat)}
|
|
130
|
+
>
|
|
131
|
+
{CATEGORY_LABELS[cat] ?? cat}
|
|
132
|
+
</button>
|
|
133
|
+
))}
|
|
134
|
+
</div>
|
|
135
|
+
<div className="qlchart-modal-content">
|
|
136
|
+
{filtered.map((def) => (
|
|
137
|
+
<div
|
|
138
|
+
key={def.name}
|
|
139
|
+
className={`qlchart-indicator-card ${
|
|
140
|
+
isActive(def.name) ? 'selected' : ''
|
|
141
|
+
}`}
|
|
142
|
+
onClick={() => handleToggle(def)}
|
|
143
|
+
>
|
|
144
|
+
<div className="qlchart-indicator-name">
|
|
145
|
+
{def.label ?? def.name}
|
|
146
|
+
</div>
|
|
147
|
+
<div className="qlchart-indicator-type">
|
|
148
|
+
{def.type === IndicatorType.Overlay ? '主图' : '副图'}
|
|
149
|
+
</div>
|
|
150
|
+
</div>
|
|
151
|
+
))}
|
|
152
|
+
{filtered.length === 0 && (
|
|
153
|
+
<div className="qlchart-modal-empty">无匹配指标</div>
|
|
154
|
+
)}
|
|
155
|
+
</div>
|
|
156
|
+
</div>
|
|
157
|
+
|
|
158
|
+
{/* Footer */}
|
|
159
|
+
<div className="qlchart-modal-footer">
|
|
160
|
+
<span className="qlchart-modal-selected">
|
|
161
|
+
已选: {activeIndicators.map((i) => i.name).join(', ') || '无'}
|
|
162
|
+
</span>
|
|
163
|
+
<button className="qlchart-modal-confirm" onClick={onClose}>
|
|
164
|
+
确定
|
|
165
|
+
</button>
|
|
166
|
+
</div>
|
|
167
|
+
</div>
|
|
168
|
+
</div>,
|
|
169
|
+
document.body,
|
|
170
|
+
);
|
|
171
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { IndicatorModal } from './IndicatorModal.js';
|
|
2
|
+
import type { IndicatorPanelProps } from './IndicatorModal.js';
|
|
3
|
+
|
|
4
|
+
export type { IndicatorPanelProps };
|
|
5
|
+
|
|
6
|
+
/** 指标面板 — 现在渲染 IndicatorModal */
|
|
7
|
+
export function IndicatorPanel(props: IndicatorPanelProps) {
|
|
8
|
+
return <IndicatorModal {...props} />;
|
|
9
|
+
}
|