修复行情区 barSpacing API 兼容(Lightweight Charts v4)
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -196,12 +196,38 @@
|
||||
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 priceTagX() {
|
||||
if (!chart || !lastCandles.length) return null;
|
||||
const bar = latestCandle();
|
||||
if (!bar) return null;
|
||||
const ts = chart.timeScale();
|
||||
const spacing = ts.barSpacing();
|
||||
const spacing = getBarSpacing(ts);
|
||||
const hostW = chartHost.clientWidth || 0;
|
||||
let x = null;
|
||||
try {
|
||||
@@ -227,6 +253,7 @@
|
||||
|
||||
function updatePriceTag() {
|
||||
if (!elPriceTag || !candleSeries || !chart) return;
|
||||
try {
|
||||
tickLiveClock();
|
||||
const bar = latestCandle();
|
||||
if (!bar || bar.close == null) {
|
||||
@@ -255,6 +282,10 @@
|
||||
elPriceTag.style.left = x + "px";
|
||||
elPriceTag.style.top = y + "px";
|
||||
if (elPriceTagValue) elPriceTagValue.textContent = fmtPrice(bar.close);
|
||||
} catch (e) {
|
||||
elPriceTag.classList.add("hidden");
|
||||
elPriceTag.setAttribute("aria-hidden", "true");
|
||||
}
|
||||
}
|
||||
|
||||
function startPriceTagTimer() {
|
||||
|
||||
@@ -190,7 +190,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-market9"></script>
|
||||
<script src="/assets/app.js?v=20260528-hub-market9"></script>
|
||||
<script src="/assets/chart.js?v=20260528-hub-market10"></script>
|
||||
<script src="/assets/app.js?v=20260528-hub-market10"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user