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

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-02 12:20:24 +08:00
parent 441bdf7e71
commit 3dcf91c573
3 changed files with 49 additions and 29 deletions
+17 -25
View File
@@ -183,8 +183,8 @@
color: up ? "#00ff9d" : "#ff4d6d",
lineWidth: 1,
lineStyle: 2,
axisLabelVisible: true,
title: "现价",
axisLabelVisible: false,
title: "",
});
}
@@ -222,33 +222,24 @@
return 6;
}
function priceTagX() {
if (!chart || !lastCandles.length) return null;
const bar = latestCandle();
if (!bar) return null;
function plotAreaWidth() {
if (!chart) return chartHost.clientWidth || 0;
const ts = chart.timeScale();
const spacing = getBarSpacing(ts);
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;
if (typeof ts.width === "function") {
const w = ts.width();
if (Number.isFinite(w) && w > 0) return w;
}
} 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;
return chartHost.clientWidth || 0;
}
/** 固定在右侧 10 根 K 线留白区中央,不随 K 线横向滚动 */
function priceTagX() {
const spacing = getBarSpacing(chart && chart.timeScale());
const plotW = plotAreaWidth();
if (plotW <= 0 || spacing <= 0) return null;
return plotW - (RIGHT_OFFSET_BARS * spacing) / 2;
}
function updatePriceTag() {
@@ -280,6 +271,7 @@
elPriceTag.classList.add(up ? "is-up" : "is-down");
elPriceTag.setAttribute("aria-hidden", "false");
elPriceTag.style.left = x + "px";
elPriceTag.style.right = "auto";
elPriceTag.style.top = y + "px";
if (elPriceTagValue) elPriceTagValue.textContent = fmtPrice(bar.close);
} catch (e) {