Skip to content

Commit 97348f5

Browse files
refactor: 新增深度图组件,支持图表类型切换与实时市场深度可视化
- **新增 DepthChart 组件**: - 采用 Canvas + React 混合渲染,实现币安风格的市场深度图 - 支持阶梯面积图(渐变填充)、网格线、十字光标与 Tooltip - 新增拐角平滑算法(quadraticCurveTo),消除锯齿的同时保留梯度感 - 实现缩放控件(4 档缩放级别:10%/25%/50%/100%),聚焦中间价附近深度 - 显示实时买卖力量比
1 parent 88e6b63 commit 97348f5

6 files changed

Lines changed: 857 additions & 68 deletions

File tree

src/App.tsx

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import KLineChart, {
1313
type KLineChartHandle,
1414
} from './components/Dashboard/Chart';
1515
import ChartToolbar from './components/Dashboard/Chart/ChartToolbar';
16+
import DepthChart from './components/Dashboard/Chart/DepthChart';
1617
import { TradeForm, MobileTradebar } from './components/Dashboard/Trade';
1718
import { useUiStore } from './hooks/ui/useUiStore';
1819
import type { UiState } from './hooks/ui/useUiStore';
@@ -347,7 +348,7 @@ function App() {
347348
onScreenshotClick={handleScreenshot}
348349
/>
349350

350-
{/* K-Line Chart Area - 移动端图表占高度*/}
351+
{/* Chart Area - 移动端图表占高度*/}
351352
<div className="flex flex-col h-[60vh] md:flex-1 md:h-auto min-h-0">
352353
{/* Chart Sub-Header */}
353354
<div className="shrink-0 h-7 md:h-8 px-2 md:px-3 flex items-center justify-between border-b border-border-dark bg-bg-black">
@@ -356,22 +357,37 @@ function App() {
356357
{latestData?.symbol ?? 'BTC-USDT'} · Perp
357358
</h2>
358359
<span className="text-[9px] md:text-[10px] font-mono text-gray-600">
359-
{candleHistory.length} candles
360+
{activeChartType === 'Depth'
361+
? 'Market Depth'
362+
: `${candleHistory.length} candles`}
360363
</span>
361364
</div>
362365
<div className="hidden sm:flex items-center gap-2 text-[10px] font-mono text-gray-500">
363-
<span className="flex items-center gap-1">
364-
<span className="w-2 h-2 bg-success rounded-sm" />
365-
<span className="w-2 h-2 bg-danger rounded-sm" />
366-
</span>
367-
<span>OHLC</span>
366+
{activeChartType === 'Depth' ? (
367+
<>
368+
<span className="flex items-center gap-1">
369+
<span className="w-2 h-2 bg-success rounded-sm" />
370+
<span>BID</span>
371+
</span>
372+
<span className="flex items-center gap-1">
373+
<span className="w-2 h-2 bg-danger rounded-sm" />
374+
<span>ASK</span>
375+
</span>
376+
</>
377+
) : (
378+
<>
379+
<span className="flex items-center gap-1">
380+
<span className="w-2 h-2 bg-success rounded-sm" />
381+
<span className="w-2 h-2 bg-danger rounded-sm" />
382+
</span>
383+
<span>OHLC</span>
384+
</>
385+
)}
368386
</div>
369387
</div>
370388

371389
{/* Chart Body */}
372390
<div className="flex-1 min-h-0 overflow-hidden relative">
373-
{/* TODO: AI待确认: 完善图表区域 Skeleton(骨架屏样式/密度/渐变),支持不同布局 */}
374-
{/* TODO: AI待确认: 增强移动端切换视觉反馈(震动/Toast/顶部提示条),与桌面端一致 */}
375391
{switchVisible && (
376392
<div className="absolute inset-0 z-10 flex items-center justify-center bg-bg-black/60 backdrop-blur-[1px]">
377393
<div className="flex flex-col items-center gap-2">
@@ -384,14 +400,22 @@ function App() {
384400
</div>
385401
</div>
386402
)}
387-
<KLineChart
388-
ref={chartRef}
389-
candleHistory={candleHistory}
390-
currentLiveCandle={currentLiveCandle}
391-
indicatorData={indicatorData}
392-
activeMainIndicators={activeMainIndicators}
393-
activeSubIndicators={activeSubIndicators}
394-
/>
403+
{activeChartType === 'Depth' ? (
404+
<DepthChart
405+
bids={latestData?.bids ?? []}
406+
asks={latestData?.asks ?? []}
407+
price={latestData?.price}
408+
/>
409+
) : (
410+
<KLineChart
411+
ref={chartRef}
412+
candleHistory={candleHistory}
413+
currentLiveCandle={currentLiveCandle}
414+
indicatorData={indicatorData}
415+
activeMainIndicators={activeMainIndicators}
416+
activeSubIndicators={activeSubIndicators}
417+
/>
418+
)}
395419
</div>
396420
</div>
397421

0 commit comments

Comments
 (0)