修复行情区 MACD/RSI 副图分区与 scaleMargins 布局错误

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-02 14:41:00 +08:00
parent 5661ccf4ab
commit 16927444d7
2 changed files with 57 additions and 53 deletions
+56 -52
View File
@@ -447,48 +447,42 @@
const macdOn = indicatorState.macd; const macdOn = indicatorState.macd;
if (!rsiOn && !macdOn) { if (!rsiOn && !macdOn) {
return { return {
candleBottom: CANDLE_SCALE_BOTTOM, candle: { top: 0.06, bottom: CANDLE_SCALE_BOTTOM },
volTop: VOLUME_SCALE_TOP, volume: { top: VOLUME_SCALE_TOP, bottom: VOLUME_SCALE_BOTTOM },
volBottom: VOLUME_SCALE_BOTTOM, macd: null,
macdTop: null, rsi: null,
macdBottom: null,
rsiTop: null,
rsiBottom: null,
rsiOn: false,
macdOn: false,
}; };
} }
let stackH = 0;
if (rsiOn) stackH += PANEL_RSI_H; const gap = 0.02;
if (macdOn) stackH += PANEL_MACD_H; let stackBottom = gap;
const volBottom = VOLUME_SCALE_BOTTOM + stackH; let rsiMargins = null;
const volTop = volBottom + PANEL_VOL_H; let macdMargins = null;
let rsiTop = null;
let rsiBottom = null;
let macdTop = null;
let macdBottom = null;
let cursor = VOLUME_SCALE_BOTTOM;
if (rsiOn) { if (rsiOn) {
rsiBottom = cursor; rsiMargins = {
rsiTop = cursor + PANEL_RSI_H; top: 1 - stackBottom - PANEL_RSI_H,
cursor = rsiTop; bottom: stackBottom,
};
stackBottom += PANEL_RSI_H;
} }
if (macdOn) { if (macdOn) {
macdBottom = cursor; macdMargins = {
macdTop = cursor + PANEL_MACD_H; top: 1 - stackBottom - PANEL_MACD_H,
cursor = macdTop; bottom: stackBottom,
};
stackBottom += PANEL_MACD_H;
} }
const candleBottom = Math.max(CANDLE_SCALE_BOTTOM, volTop + 0.02);
const volBottom = stackBottom;
const volTop = 1 - volBottom - PANEL_VOL_H;
const candleBottom = Math.max(CANDLE_SCALE_BOTTOM, 1 - volTop + 0.01);
return { return {
candleBottom, candle: { top: 0.06, bottom: candleBottom },
volTop, volume: { top: volTop, bottom: volBottom },
volBottom, macd: macdMargins,
macdTop, rsi: rsiMargins,
macdBottom,
rsiTop,
rsiBottom,
rsiOn,
macdOn,
}; };
} }
@@ -496,21 +490,24 @@
if (!chart) return; if (!chart) return;
const L = panelLayout(); const L = panelLayout();
chart.priceScale("right").applyOptions({ chart.priceScale("right").applyOptions({
scaleMargins: { top: 0.06, bottom: L.candleBottom }, scaleMargins: L.candle,
}); });
chart.priceScale("volume").applyOptions({ if (volumeSeries && volumeSeries.priceScale) {
scaleMargins: { top: L.volTop, bottom: L.volBottom }, volumeSeries.priceScale().applyOptions({
}); scaleMargins: L.volume,
if (L.macdOn && L.macdTop != null) { borderColor: "#2a4058",
chart.priceScale("macd").applyOptions({ });
scaleMargins: { top: L.macdTop, bottom: L.macdBottom }, }
if (indSeries.macdLine && indSeries.macdLine.priceScale) {
indSeries.macdLine.priceScale().applyOptions({
scaleMargins: L.macd,
borderColor: "#2a4058", borderColor: "#2a4058",
autoScale: true, autoScale: true,
}); });
} }
if (L.rsiOn && L.rsiTop != null) { if (indSeries.rsi && indSeries.rsi.priceScale) {
chart.priceScale("rsi").applyOptions({ indSeries.rsi.priceScale().applyOptions({
scaleMargins: { top: L.rsiTop, bottom: L.rsiBottom }, scaleMargins: L.rsi,
borderColor: "#2a4058", borderColor: "#2a4058",
autoScale: true, autoScale: true,
}); });
@@ -550,7 +547,6 @@
readIndicatorState(); readIndicatorState();
clearIndicatorSeries(); clearIndicatorSeries();
divergenceMarkers = []; divergenceMarkers = [];
applyScaleLayout();
if (indicatorState.ema) { if (indicatorState.ema) {
const pf = tickToPriceFormat(priceTick); const pf = tickToPriceFormat(priceTick);
@@ -580,13 +576,21 @@
color: "#5b9cf5", color: "#5b9cf5",
title: "MACD", title: "MACD",
priceScaleId: "macd", priceScaleId: "macd",
priceLineVisible: false,
lastValueVisible: false,
}); });
indSeries.macdSignal = createLineSeries({ indSeries.macdSignal = createLineSeries({
color: "#ffb84d", color: "#ffb84d",
title: "Signal", title: "Signal",
priceScaleId: "macd", priceScaleId: "macd",
priceLineVisible: false,
lastValueVisible: false,
});
indSeries.macdHist = createHistSeries({
priceScaleId: "macd",
priceLineVisible: false,
lastValueVisible: false,
}); });
indSeries.macdHist = createHistSeries({ priceScaleId: "macd" });
if (indSeries.macdLine) indSeries.macdLine.setData(macd.macdLine); if (indSeries.macdLine) indSeries.macdLine.setData(macd.macdLine);
if (indSeries.macdSignal) indSeries.macdSignal.setData(macd.signalLine); if (indSeries.macdSignal) indSeries.macdSignal.setData(macd.signalLine);
if (indSeries.macdHist) indSeries.macdHist.setData(macd.histData); if (indSeries.macdHist) indSeries.macdHist.setData(macd.histData);
@@ -598,9 +602,11 @@
const rsiPack = buildRsiByIndex(lastCandles, 14); const rsiPack = buildRsiByIndex(lastCandles, 14);
indSeries.rsi = createLineSeries({ indSeries.rsi = createLineSeries({
color: "#8fc8ff", color: "#8fc8ff",
title: "RSI", title: "RSI(14)",
priceScaleId: "rsi", priceScaleId: "rsi",
priceFormat: { type: "price", precision: 1, minMove: 0.1 }, priceFormat: { type: "price", precision: 1, minMove: 0.1 },
priceLineVisible: false,
lastValueVisible: true,
}); });
if (indSeries.rsi) { if (indSeries.rsi) {
indSeries.rsi.setData(rsiPack.series); indSeries.rsi.setData(rsiPack.series);
@@ -629,6 +635,7 @@
updateDivergenceLegend(rsiDiv, macdDiv); updateDivergenceLegend(rsiDiv, macdDiv);
applyCandleDivergenceMarkers(); applyCandleDivergenceMarkers();
applyScaleLayout();
scheduleChartResize(); scheduleChartResize();
} }
@@ -1093,7 +1100,7 @@
const volOpts = { const volOpts = {
priceFormat: { type: "volume" }, priceFormat: { type: "volume" },
priceScaleId: "volume", priceScaleId: "",
lastValueVisible: false, lastValueVisible: false,
}; };
if (typeof chart.addHistogramSeries === "function") { if (typeof chart.addHistogramSeries === "function") {
@@ -1107,9 +1114,6 @@
} }
if (!volumeSeries) return false; if (!volumeSeries) return false;
chart.priceScale("macd");
chart.priceScale("rsi");
applyScaleLayout(); applyScaleLayout();
applyChartPriceFormat(); applyChartPriceFormat();
applyPriceAutoScale(); applyPriceAutoScale();
+1 -1
View File
@@ -240,7 +240,7 @@
<div id="toast"></div> <div id="toast"></div>
<script src="https://unpkg.com/lightweight-charts@4.2.0/dist/lightweight-charts.standalone.production.js"></script> <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-ind-fs"></script> <script src="/assets/chart.js?v=20260528-hub-ind-pane-fix"></script>
<script src="/assets/app.js?v=20260528-hub-tpsl-fix"></script> <script src="/assets/app.js?v=20260528-hub-tpsl-fix"></script>
</body> </body>
</html> </html>