Remove 12h timeframe and stabilize chart wheel zoom.

Drop 12h from market chart options and storage, and avoid left-pan reload and tail refresh from resetting the viewport while zooming.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-08 07:54:37 +08:00
parent 4afea6bb97
commit 3ac854d74c
5 changed files with 50 additions and 66 deletions
+39 -17
View File
@@ -14,7 +14,6 @@
"1h": 200,
"2h": 200,
"4h": 200,
"12h": 200,
"1d": 200,
"1w": 150,
};
@@ -25,7 +24,6 @@
"1h": 300,
"2h": 300,
"4h": 300,
"12h": 200,
"1d": 200,
"1w": 150,
};
@@ -36,7 +34,6 @@
"1h": 1000,
"2h": 1000,
"4h": 1000,
"12h": 1000,
"1d": 1000,
"1w": 500,
};
@@ -56,7 +53,6 @@
"1h": 60 * 60_000,
"2h": 2 * 60 * 60_000,
"4h": 4 * 60 * 60_000,
"12h": 12 * 60 * 60_000,
"1d": 24 * 60 * 60_000,
"1w": 7 * 24 * 60 * 60_000,
};
@@ -67,7 +63,6 @@
"60": "1h",
"120": "2h",
"240": "4h",
"720": "12h",
"1440": "1d",
"10080": "1w",
};
@@ -81,7 +76,6 @@
"1h": "1小时",
"2h": "2小时",
"4h": "4小时",
"12h": "12小时",
"1d": "日线",
"1w": "周线",
};
@@ -179,6 +173,8 @@
let loadingLeft = false;
let chartDataLoading = false;
let chartViewEpoch = 0;
let rangeUiTimer = null;
let loadOlderTimer = null;
let priceTagTimer = null;
let tfDigitBuf = "";
let tfDigitTimer = null;
@@ -1954,8 +1950,7 @@
});
chart.timeScale().subscribeVisibleLogicalRangeChange(function (range) {
updateVisibleRangeMarkers();
updatePriceTag();
scheduleRangeUiUpdate();
if (
!range ||
chartDataLoading ||
@@ -1967,9 +1962,7 @@
return;
}
if (currentChartViewKey() !== lastViewKey) return;
if (range.from < CHART_LOAD_LEFT_THRESHOLD) {
void loadOlderCandles();
}
scheduleLoadOlderOnRange(range);
});
window.addEventListener("resize", function () {
@@ -2032,6 +2025,37 @@
return range.to >= maxTo - 24;
}
function shouldLoadOlderOnRange(range) {
if (!range || !lastCandles.length) return false;
const n = lastCandles.length;
const maxTo = n - 1 + RIGHT_OFFSET_BARS;
if (range.from >= CHART_LOAD_LEFT_THRESHOLD) return false;
// 缩小图表时 from 会变小,但 to 仍靠近最新 — 不应触发左拖补历史
if (range.to >= maxTo - 30) return false;
return true;
}
function scheduleRangeUiUpdate() {
if (rangeUiTimer) clearTimeout(rangeUiTimer);
rangeUiTimer = setTimeout(function () {
rangeUiTimer = null;
updateVisibleRangeMarkers();
updatePriceTag();
}, 120);
}
function scheduleLoadOlderOnRange(range) {
if (!shouldLoadOlderOnRange(range)) return;
if (loadOlderTimer) clearTimeout(loadOlderTimer);
loadOlderTimer = setTimeout(function () {
loadOlderTimer = null;
if (!chart) return;
const cur = chart.timeScale().getVisibleLogicalRange();
if (!shouldLoadOlderOnRange(cur)) return;
void loadOlderCandles();
}, 280);
}
function tailVisibleLogicalRange(candleCount) {
const n = Math.max(0, Number(candleCount) || 0);
if (n <= 0) return null;
@@ -2196,20 +2220,18 @@
if (epochAtStart !== chartViewEpoch) return;
const n = lastCandles.length;
const curRange = chart && chart.timeScale().getVisibleLogicalRange();
if (wasViewingTail) {
const tailRange = tailVisibleLogicalRange(n);
if (tailRange) chart.timeScale().setVisibleLogicalRange(tailRange);
} else if (
const minorTailUpdate = Math.abs(n - candleCountBefore) <= 5;
if (
savedRange &&
isVisibleRangeValidForCandles(savedRange, n) &&
Math.abs(n - candleCountBefore) < chartChunkLimit(tf)
(minorTailUpdate || !wasViewingTail)
) {
chart.timeScale().setVisibleLogicalRange(savedRange);
} else if (!isVisibleRangeValidForCandles(curRange, n)) {
const tailRange = tailVisibleLogicalRange(n);
if (tailRange) chart.timeScale().setVisibleLogicalRange(tailRange);
}
updateVisibleRangeMarkers();
scheduleRangeUiUpdate();
if (posContext) {
updateLivePosPnl();
refreshPosPnlFromBoard();
-2
View File
@@ -93,7 +93,6 @@
<option value="1h">1h</option>
<option value="2h">2h</option>
<option value="4h">4h</option>
<option value="12h">12h</option>
<option value="1d" selected>1d</option>
<option value="1w">1w</option>
</select>
@@ -150,7 +149,6 @@
<option value="1h">1h</option>
<option value="2h">2h</option>
<option value="4h">4h</option>
<option value="12h">12h</option>
<option value="1d">1d</option>
<option value="1w">1w</option>
</select>