行情区:现价标签固定于价格轴,K线右侧保留10根留白

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-02 12:22:54 +08:00
parent 3dcf91c573
commit e40975d563
3 changed files with 8 additions and 55 deletions
+3 -51
View File
@@ -196,52 +196,6 @@
if (elBarCountdown) elBarCountdown.textContent = "距收盘 " + cd;
}
function getBarSpacing(ts) {
if (!ts) return 6;
try {
if (typeof ts.barSpacing === "function") {
const v = ts.barSpacing();
if (Number.isFinite(v) && v > 0) return v;
}
} catch (e) {}
try {
if (typeof ts.options === "function") {
const opts = ts.options();
const v = opts && opts.barSpacing;
if (Number.isFinite(v) && v > 0) return v;
}
} catch (e) {}
try {
const x0 = ts.logicalToCoordinate(0);
const x1 = ts.logicalToCoordinate(1);
if (x0 != null && x1 != null) {
const d = Math.abs(x1 - x0);
if (Number.isFinite(d) && d > 0) return d;
}
} catch (e) {}
return 6;
}
function plotAreaWidth() {
if (!chart) return chartHost.clientWidth || 0;
const ts = chart.timeScale();
try {
if (typeof ts.width === "function") {
const w = ts.width();
if (Number.isFinite(w) && w > 0) return w;
}
} catch (e) {}
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() {
if (!elPriceTag || !candleSeries || !chart) return;
try {
@@ -258,10 +212,8 @@
} catch (e) {
y = null;
}
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) {
if (y == null || y < 8 || y > hostH - 8) {
elPriceTag.classList.add("hidden");
elPriceTag.setAttribute("aria-hidden", "true");
return;
@@ -270,8 +222,8 @@
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.right = "auto";
elPriceTag.style.left = "auto";
elPriceTag.style.right = "0";
elPriceTag.style.top = y + "px";
if (elPriceTagValue) elPriceTagValue.textContent = fmtPrice(bar.close);
} catch (e) {