fix(web): 开关缠论元素保留视窗;分周期 Trend 涨跌配色

本地重绘统一冻结视窗;次/次次周期 Trend 上涨下跌使用独立颜色。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
jackyu66git
2026-08-25 23:56:55 +08:00
co-authored by Cursor
parent 90499533fb
commit 97e77847d0
6 changed files with 130 additions and 84 deletions
+26 -2
View File
@@ -66,7 +66,19 @@ function chartTvFinalize(ctx) {
const allChartsNow = [mainChart, volumeChart, atrChart]
.concat(showMacd && macdChart ? [macdChart] : [])
.concat(showMacd && chanMacdChart ? [chanMacdChart] : []);
if (!hasPendingRestoreView || !pendingView) {
const restoreOpts = function () {
const firstT = candles && candles.length ? candles[0].time : null;
const lastT = candles && candles.length ? candles[candles.length - 1].time : null;
return {
firstBarTime: firstT,
lastBarTime: lastT,
oldBarCount: window._preserveViewBarCount || 0,
newBarCount: totalBars
};
};
if (hasPendingRestoreView && pendingView) {
restoreChartViewState(allChartsNow, pendingView, restoreOpts());
} else {
// 显示最近 200 根K线而非全部挤压(避免K线过多时重叠)
if (totalBars > visibleBarsCount) {
const rangeFrom = totalBars - visibleBarsCount;
@@ -77,9 +89,21 @@ function chartTvFinalize(ctx) {
}
}
// 立即同步其他图表到主图表的范围(无 pending 时)
// 立即同步其他图表到主图表的范围
setTimeout(() => {
if (pendingView) {
restoreChartViewState(allChartsNow, pendingView, restoreOpts());
const logRange = mainChart.timeScale().getVisibleLogicalRange();
if (logRange) {
volumeChart.timeScale().setVisibleLogicalRange(logRange);
atrChart.timeScale().setVisibleLogicalRange(logRange);
if (showMacd && macdChart) {
macdChart.timeScale().setVisibleLogicalRange(logRange);
}
if (showMacd && chanMacdChart) {
chanMacdChart.timeScale().setVisibleLogicalRange(logRange);
}
}
return;
}
const logRange = mainChart.timeScale().getVisibleLogicalRange();