Respect manual chart zoom when auto-follow is off.

Tie the market auto toggle to both price scale and viewport: tail refresh updates data silently while preserving zoom/pan when auto is disabled.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-08 08:30:44 +08:00
parent c8ffc764e1
commit bae78d8368
2 changed files with 11 additions and 5 deletions
+10 -4
View File
@@ -1,5 +1,5 @@
/**
* 中控行情区:K 线 + 成交量;Hub 后台轮询 + SSE 推送;价格轴「自动」。
* 中控行情区:K 线 + 成交量;Hub 后台轮询 + SSE 推送;「自动」控制价格轴与视口跟随
*/
(function () {
const AUTO_REFRESH_MS = 5000;
@@ -2255,22 +2255,27 @@
applyChartPriceFormat();
}
}
const autoFollow = priceAutoScale;
const shouldPreserve =
savedRange &&
isVisibleRangeValidForCandles(savedRange, candleCountBefore) &&
(chartRangeUserLocked || !wasViewingTail);
(!autoFollow || chartRangeUserLocked || !wasViewingTail);
applyCandlesToChart(
mergeCandles(lastCandles, alignCandlesToTick(data.candles), { prepend: false }),
0,
{
preserveRange: !!shouldPreserve,
skipAutoScale: chartRangeUserLocked,
skipAutoScale: !autoFollow,
}
);
if (epochAtStart !== chartViewEpoch) return;
const n = lastCandles.length;
const minorTailUpdate = Math.abs(n - candleCountBefore) <= CHART_TAIL_REFRESH_LIMIT + 5;
if (wasViewingTail && !chartRangeUserLocked) {
if (!autoFollow) {
if (savedRange && isVisibleRangeValidForCandles(savedRange, n)) {
restoreVisibleLogicalRange(savedRange, n);
}
} else if (wasViewingTail && !chartRangeUserLocked) {
restoreVisibleLogicalRange(tailVisibleLogicalRange(n), n);
} else if (shouldPreserve && minorTailUpdate) {
if (!restoreVisibleLogicalRange(savedRange, n) && !chartRangeUserLocked) {
@@ -2659,6 +2664,7 @@
elPriceAuto.addEventListener("click", function () {
priceAutoScale = !priceAutoScale;
applyPriceAutoScale();
if (priceAutoScale) applyDefaultVisibleRange();
});
}
if (elPosClear) {