diff --git a/manual_trading_hub/static/chart.js b/manual_trading_hub/static/chart.js index 18e1e73..bb4d7cc 100644 --- a/manual_trading_hub/static/chart.js +++ b/manual_trading_hub/static/chart.js @@ -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,34 +253,39 @@ function updatePriceTag() { if (!elPriceTag || !candleSeries || !chart) return; - tickLiveClock(); - const bar = latestCandle(); - if (!bar || bar.close == null) { - elPriceTag.classList.add("hidden"); - elPriceTag.setAttribute("aria-hidden", "true"); - return; - } - let y = null; try { - y = candleSeries.priceToCoordinate(Number(bar.close)); + tickLiveClock(); + const bar = latestCandle(); + if (!bar || bar.close == null) { + elPriceTag.classList.add("hidden"); + elPriceTag.setAttribute("aria-hidden", "true"); + return; + } + let y = null; + try { + y = candleSeries.priceToCoordinate(Number(bar.close)); + } 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) { + elPriceTag.classList.add("hidden"); + elPriceTag.setAttribute("aria-hidden", "true"); + return; + } + const up = Number(bar.close) >= Number(bar.open); + 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); } 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) { elPriceTag.classList.add("hidden"); elPriceTag.setAttribute("aria-hidden", "true"); - return; } - const up = Number(bar.close) >= Number(bar.open); - 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); } function startPriceTagTimer() { diff --git a/manual_trading_hub/static/index.html b/manual_trading_hub/static/index.html index fed78ca..c8ccda8 100644 --- a/manual_trading_hub/static/index.html +++ b/manual_trading_hub/static/index.html @@ -190,7 +190,7 @@
- - + +