修复行情区 K 线右侧 10 根留白被可见范围覆盖的问题

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-02 12:26:04 +08:00
parent e40975d563
commit 054cf01b7a
2 changed files with 14 additions and 4 deletions
+12 -2
View File
@@ -386,13 +386,22 @@
return (exKey || "") + "|" + (sym || "") + "|" + (tf || "");
}
function applyChartRightGap() {
if (!chart) return;
chart.timeScale().applyOptions({
rightOffset: RIGHT_OFFSET_BARS,
fixRightEdge: false,
});
}
function applyDefaultVisibleRange() {
if (!chart || !lastCandles.length) return;
const n = lastCandles.length;
const visible = Math.min(DEFAULT_VISIBLE_BARS, n);
const from = Math.max(0, n - visible);
const to = n - 1;
chart.timeScale().applyOptions({ rightOffset: RIGHT_OFFSET_BARS });
// to 延伸到最后一根 K 线之后,留出 RIGHT_OFFSET_BARS 根空白(K 线与价格轴间距)
const to = n - 1 + RIGHT_OFFSET_BARS;
applyChartRightGap();
chart.timeScale().setVisibleLogicalRange({ from: from, to: to });
}
@@ -535,6 +544,7 @@
indexCandles(lastCandles);
candleSeries.setData(lastCandles);
volumeSeries.setData(buildVolumeData(lastCandles));
applyChartRightGap();
if (resetView) {
lastViewKey = vKey;
applyDefaultVisibleRange();
+2 -2
View File
@@ -193,7 +193,7 @@
<div id="toast"></div>
<script src="https://unpkg.com/lightweight-charts@4.2.0/dist/lightweight-charts.standalone.production.js"></script>
<script src="/assets/chart.js?v=20260528-hub-market12"></script>
<script src="/assets/app.js?v=20260528-hub-market12"></script>
<script src="/assets/chart.js?v=20260528-hub-market13"></script>
<script src="/assets/app.js?v=20260528-hub-market13"></script>
</body>
</html>