行情区:现价标签固定于价格轴,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 -2
View File
@@ -2062,16 +2062,17 @@ body.login-page {
.market-price-tag {
position: absolute;
right: 0;
z-index: 5;
pointer-events: none;
padding: 4px 8px;
border-radius: 4px;
border-radius: 4px 0 0 4px;
font-family: var(--font);
font-size: 0.72rem;
font-weight: 600;
line-height: 1.25;
text-align: center;
transform: translate(-50%, -50%);
transform: translateY(-50%);
min-width: 72px;
box-shadow: 0 1px 6px rgba(0, 0, 0, 0.35);
}
+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) {
+2 -2
View File
@@ -193,7 +193,7 @@
<div id="toast"></div>
<script src="https://unpkg.com/lightweight-charts@4.2.0/dist/lightweight-charts.standalone.production.js"></script>
<script src="/assets/chart.js?v=20260528-hub-market11"></script>
<script src="/assets/app.js?v=20260528-hub-market11"></script>
<script src="/assets/chart.js?v=20260528-hub-market12"></script>
<script src="/assets/app.js?v=20260528-hub-market12"></script>
</body>
</html>