fix: price axis auto-range to show actual volatility, not 0-based

This commit is contained in:
root 2026-02-27 14:13:51 +00:00
parent 4a6232ed05
commit 41af2ed2e6

View File

@ -184,6 +184,14 @@ function FlowAnalysis({ symbol }: { symbol: Symbol }) {
const totalDelta = totalBuy - totalSell; const totalDelta = totalBuy - totalSell;
const buyPct = totalBuy + totalSell > 0 ? (totalBuy / (totalBuy + totalSell) * 100) : 50; const buyPct = totalBuy + totalSell > 0 ? (totalBuy / (totalBuy + totalSell) * 100) : 50;
// 价格轴范围只显示实际波动区间±0.3%缓冲)
const prices = chartData.map(d => d.vwap).filter(v => v > 0);
const priceMin = prices.length > 0 ? Math.min(...prices) : 0;
const priceMax = prices.length > 0 ? Math.max(...prices) : 0;
const pricePad = (priceMax - priceMin) * 0.3 || priceMax * 0.001;
const priceYMin = Math.floor(priceMin - pricePad);
const priceYMax = Math.ceil(priceMax + pricePad);
return ( return (
<div className="rounded-xl border border-slate-200 bg-white shadow-sm overflow-hidden"> <div className="rounded-xl border border-slate-200 bg-white shadow-sm overflow-hidden">
<div className="px-4 py-3 border-b border-slate-100"> <div className="px-4 py-3 border-b border-slate-100">
@ -262,8 +270,9 @@ function FlowAnalysis({ symbol }: { symbol: Symbol }) {
<XAxis dataKey="time" tick={{ fill: "#94a3b8", fontSize: 10 }} tickLine={false} interval="preserveStartEnd" /> <XAxis dataKey="time" tick={{ fill: "#94a3b8", fontSize: 10 }} tickLine={false} interval="preserveStartEnd" />
{/* 左轴Delta */} {/* 左轴Delta */}
<YAxis yAxisId="delta" tick={{ fill: "#94a3b8", fontSize: 10 }} tickLine={false} axisLine={false} width={55} /> <YAxis yAxisId="delta" tick={{ fill: "#94a3b8", fontSize: 10 }} tickLine={false} axisLine={false} width={55} />
{/* 右轴:价格 */} {/* 右轴:价格,自适应波动范围 */}
<YAxis yAxisId="price" orientation="right" tick={{ fill: "#f59e0b", fontSize: 10 }} tickLine={false} axisLine={false} width={65} <YAxis yAxisId="price" orientation="right" tick={{ fill: "#f59e0b", fontSize: 10 }} tickLine={false} axisLine={false} width={65}
domain={[priceYMin, priceYMax]}
tickFormatter={(v: number) => v >= 1000 ? `$${(v/1000).toFixed(1)}k` : `$${v.toFixed(0)}`} tickFormatter={(v: number) => v >= 1000 ? `$${(v/1000).toFixed(1)}k` : `$${v.toFixed(0)}`}
/> />
<Tooltip <Tooltip