From 3053527504ea52f80ad5099b592a626ce0df30d6 Mon Sep 17 00:00:00 2001 From: dekun Date: Sat, 30 May 2026 11:08:12 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0K=E7=BA=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/charts.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/web/charts.js b/web/charts.js index cd96c11..7070c56 100644 --- a/web/charts.js +++ b/web/charts.js @@ -32,6 +32,8 @@ const COLORS = { const MINI_SIZE = { w: 380, h: 100 }; /** 弹窗 K 线区域固定尺寸(带鱼屏居中大图) */ const MODAL_CHART_SIZE = { w: 1920, h: 1080 }; +/** 自动模式下右侧留空的 K 线根数 */ +const CHART_RIGHT_OFFSET_BARS = 10; const DEFAULT_MINI_INTERVAL = "1d"; let chartModalSymbol = ""; @@ -198,10 +200,21 @@ function updateOhlcFromTime(time, modeLabel) { if (candle) renderOhlcPanel(candle, modeLabel); } +function applyChartRightOffset() { + if (!lwcChart) return; + lwcChart.timeScale().applyOptions({ rightOffset: CHART_RIGHT_OFFSET_BARS }); +} + +function fitChartContent() { + if (!lwcChart) return; + applyChartRightOffset(); + lwcChart.timeScale().fitContent(); +} + function onChartAutoscale() { if (!lwcChart) return; lwcPinnedCandleTime = null; - lwcChart.timeScale().fitContent(); + fitChartContent(); lwcChart.priceScale("right").applyOptions({ autoScale: true }); requestAnimationFrame(() => { updateHighLowForVisibleWindow(); @@ -672,6 +685,7 @@ function ensureLwcChart(container) { borderColor: COLORS.grid, timeVisible: true, secondsVisible: false, + rightOffset: CHART_RIGHT_OFFSET_BARS, }, }); @@ -725,7 +739,7 @@ function renderLwcChart(candles, interval, priceMeta) { const { ohlc, vol } = candlesToLwc(candles, interval); lwcCandleSeries.setData(ohlc); lwcVolumeSeries.setData(vol); - lwcChart.timeScale().fitContent(); + fitChartContent(); requestAnimationFrame(() => { updateHighLowForVisibleWindow(); showLatestOhlcPanel();