行情区:现价标签移入右侧10根留白区,倒计时在现价下方

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-02 12:08:21 +08:00
parent ffe5f230fd
commit 43f6aced94
3 changed files with 51 additions and 28 deletions
+35 -4
View File
@@ -4,7 +4,7 @@
(function () {
const AUTO_REFRESH_MS = 5000;
const DEFAULT_VISIBLE_BARS = 200;
const RIGHT_OFFSET_BARS = 12;
const RIGHT_OFFSET_BARS = 10;
const TF_MS = {
"1m": 60_000,
"5m": 5 * 60_000,
@@ -24,7 +24,6 @@
const elStatus = document.getElementById("market-status");
const elUpdated = document.getElementById("market-updated");
const elBarCountdown = document.getElementById("market-bar-countdown");
const elPriceGutter = document.querySelector(".market-price-gutter");
const elO = document.getElementById("mkt-o");
const elH = document.getElementById("mkt-h");
const elL = document.getElementById("mkt-l");
@@ -197,6 +196,35 @@
if (elBarCountdown) elBarCountdown.textContent = "距收盘 " + cd;
}
function priceTagX() {
if (!chart || !lastCandles.length) return null;
const bar = latestCandle();
if (!bar) return null;
const ts = chart.timeScale();
const spacing = ts.barSpacing();
const hostW = chartHost.clientWidth || 0;
let x = null;
try {
const lastIdx = lastCandles.length - 1;
const lastX = ts.logicalToCoordinate(lastIdx);
if (lastX != null && Number.isFinite(lastX)) {
x = lastX + (RIGHT_OFFSET_BARS * spacing) / 2;
}
} catch (e) {}
if (x == null) {
try {
const tx = ts.timeToCoordinate(bar.time);
if (tx != null && Number.isFinite(tx)) {
x = tx + (RIGHT_OFFSET_BARS * spacing) / 2;
}
} catch (e2) {}
}
if (x == null && hostW > 0 && spacing > 0) {
x = hostW - (RIGHT_OFFSET_BARS * spacing) / 2;
}
return x;
}
function updatePriceTag() {
if (!elPriceTag || !candleSeries || !chart) return;
tickLiveClock();
@@ -212,8 +240,10 @@
} catch (e) {
y = null;
}
const hostH = (elPriceGutter && elPriceGutter.clientHeight) || chartHost.clientHeight || 0;
if (y == null || y < 8 || y > hostH - 8) {
const x = priceTagX();
const hostH = chartHost.clientHeight || 0;
const hostW = chartHost.clientWidth || 0;
if (y == null || x == null || y < 8 || y > hostH - 8 || x < 8 || x > hostW - 8) {
elPriceTag.classList.add("hidden");
elPriceTag.setAttribute("aria-hidden", "true");
return;
@@ -222,6 +252,7 @@
elPriceTag.classList.remove("hidden", "is-up", "is-down");
elPriceTag.classList.add(up ? "is-up" : "is-down");
elPriceTag.setAttribute("aria-hidden", "false");
elPriceTag.style.left = x + "px";
elPriceTag.style.top = y + "px";
if (elPriceTagValue) elPriceTagValue.textContent = fmtPrice(bar.close);
}