macd 그래프 오류

This commit is contained in:
Macbook
2026-06-16 01:23:59 +09:00
parent d34a824174
commit ea13347be8
2 changed files with 68 additions and 39 deletions
+47 -37
View File
@@ -181,6 +181,13 @@ function seriesByPlotId(
return i >= 0 ? entry.seriesList[i] : undefined;
}
/** hline·음영 프리미티브 부착 대상 — histogram+line 지표(MACD 등)는 line 시리즈에 부착 */
function hlineAnchorSeries(entry: Pick<IndicatorEntry, 'seriesList' | 'seriesMeta'>): ISeriesApi<SeriesType> | undefined {
if (entry.seriesList.length === 0) return undefined;
const lineIdx = entry.seriesMeta.findIndex(m => !m.isHistogram);
return entry.seriesList[lineIdx >= 0 ? lineIdx : 0];
}
function shouldShowBbBandFill(config: IndicatorConfig): boolean {
const bg = resolveBbBandBackground(config.bandBackground);
if (!bg.visible) return false;
@@ -1052,7 +1059,7 @@ export class ChartManager {
const indicatorHidden = !this._isIndicatorEffectivelyVisible(config);
for (const pl of entry.hlineRefs) {
try { entry.seriesList[0]?.removePriceLine(pl); } catch { /* ok */ }
try { hlineAnchorSeries(entry)?.removePriceLine(pl); } catch { /* ok */ }
}
entry.hlineRefs = [];
for (const s of entry.seriesList) {
@@ -1228,7 +1235,7 @@ export class ChartManager {
let fillPrimitive: IndicatorFillPrimitive | undefined;
if (!indicatorHidden && seriesList.length > 0) {
const firstSeries = seriesList[0];
const hlineHost = hlineAnchorSeries({ seriesList, seriesMeta });
const hlines = config.hlines ?? def?.hlines ?? [];
// HLineStyle → lightweight-charts LineStyle 변환
@@ -1238,28 +1245,30 @@ export class ChartManager {
return LineStyle.Dashed; // 기본값
};
for (const hl of hlines) {
if (hl.visible === false) continue;
const pl = firstSeries.createPriceLine({
price: hl.price,
color: hl.color,
lineWidth: Math.min(4, hl.lineWidth ?? 1) as 1|2|3|4,
lineStyle: toLineStyle(hl.lineStyle),
axisLabelVisible: false,
});
hlineRefs.push(pl);
}
if (hlineHost) {
for (const hl of hlines) {
if (hl.visible === false) continue;
const pl = hlineHost.createPriceLine({
price: hl.price,
color: hl.color,
lineWidth: Math.min(4, hl.lineWidth ?? 1) as 1|2|3|4,
lineStyle: toLineStyle(hl.lineStyle),
axisLabelVisible: false,
});
hlineRefs.push(pl);
}
// 과열선/침체선 레이블이 있는 hlines 가 있으면 음영 프리미티브 부착
const prices = hlines.filter(h => h.visible !== false).map(h => h.price);
const hasZone = hlines.some(h => {
const lbl = h.label ?? getHLineLabel(h.price, prices);
return (lbl === '과열선' || lbl === '침체선') && h.visible !== false;
});
const hasBg = config.hlinesBackground?.visible !== false;
if (hasZone || hasBg) {
fillPrimitive = new IndicatorFillPrimitive(hlines, config.hlinesBackground);
firstSeries.attachPrimitive(fillPrimitive);
// 과열선/침체선 레이블이 있는 hlines 가 있으면 음영 프리미티브 부착
const prices = hlines.filter(h => h.visible !== false).map(h => h.price);
const hasZone = hlines.some(h => {
const lbl = h.label ?? getHLineLabel(h.price, prices);
return (lbl === '과열선' || lbl === '침체선') && h.visible !== false;
});
const hasBg = config.hlinesBackground?.visible !== false;
if (hasZone || hasBg) {
fillPrimitive = new IndicatorFillPrimitive(hlines, config.hlinesBackground);
hlineHost.attachPrimitive(fillPrimitive);
}
}
}
@@ -1482,11 +1491,12 @@ export class ChartManager {
const entry = this.indicators.get(id);
if (!entry) return false;
if (entry.seriesList.length > 0) {
const hlineHost = hlineAnchorSeries(entry);
for (const pl of entry.hlineRefs) {
try { entry.seriesList[0].removePriceLine(pl); } catch { /* ok */ }
try { hlineHost?.removePriceLine(pl); } catch { /* ok */ }
}
if (entry.fillPrimitive) {
try { entry.seriesList[0].detachPrimitive(entry.fillPrimitive); } catch { /* ok */ }
try { hlineHost?.detachPrimitive(entry.fillPrimitive); } catch { /* ok */ }
}
}
if (entry.cloudPlugin) {
@@ -1518,8 +1528,8 @@ export class ChartManager {
try { this.mainSeries?.detachPrimitive(entry.cloudPlugin); } catch { /* ok */ }
for (const s of entry.seriesList) { try { s.detachPrimitive(entry.cloudPlugin); } catch { /* ok */ } }
}
if (entry.fillPrimitive && entry.seriesList[0]) {
try { entry.seriesList[0].detachPrimitive(entry.fillPrimitive); } catch { /* ok */ }
if (entry.fillPrimitive) {
try { hlineAnchorSeries(entry)?.detachPrimitive(entry.fillPrimitive); } catch { /* ok */ }
}
detachBbBandFill(entry);
for (const s of entry.seriesList) { try { this.chart.removeSeries(s); } catch { /* ok */ } }
@@ -3524,7 +3534,7 @@ export class ChartManager {
// ── hlines(과열선/중앙선/침체선) 동기화 ─────────────────────────────────
if (entry.seriesList.length > 0) {
const firstSeries = entry.seriesList[0];
const hlineHost = hlineAnchorSeries(entry);
const hlines = config.hlines ?? def?.hlines ?? [];
const toLineStyle2 = (s?: string): number => {
@@ -3535,19 +3545,19 @@ export class ChartManager {
// 기존 price line 제거
for (const pl of entry.hlineRefs) {
try { firstSeries.removePriceLine(pl); } catch { /* 이미 제거됨 */ }
try { hlineHost?.removePriceLine(pl); } catch { /* 이미 제거됨 */ }
}
entry.hlineRefs = [];
if (entry.fillPrimitive) {
try { firstSeries.detachPrimitive(entry.fillPrimitive); } catch { /* ok */ }
try { hlineHost?.detachPrimitive(entry.fillPrimitive); } catch { /* ok */ }
entry.fillPrimitive = undefined;
}
if (indicatorVisible) {
if (indicatorVisible && hlineHost) {
for (const hl of hlines) {
if (hl.visible === false) continue;
const pl = firstSeries.createPriceLine({
const pl = hlineHost.createPriceLine({
price: hl.price,
color: hl.color,
lineWidth: Math.min(4, hl.lineWidth ?? 1) as 1|2|3|4,
@@ -3565,7 +3575,7 @@ export class ChartManager {
const hasBg = config.hlinesBackground?.visible !== false;
if (hasZone || hasBg) {
entry.fillPrimitive = new IndicatorFillPrimitive(hlines, config.hlinesBackground);
firstSeries.attachPrimitive(entry.fillPrimitive);
hlineHost.attachPrimitive(entry.fillPrimitive);
}
}
}
@@ -3873,14 +3883,14 @@ export class ChartManager {
} as Parameters<ISeriesApi<SeriesType>['applyOptions']>[0]);
} catch { /* ok */ }
}
const first = entry.seriesList[0];
if (first) {
const hlineHost = hlineAnchorSeries(entry);
if (hlineHost) {
for (const pl of entry.hlineRefs) {
try { first.removePriceLine(pl); } catch { /* ok */ }
try { hlineHost.removePriceLine(pl); } catch { /* ok */ }
}
entry.hlineRefs = [];
if (entry.fillPrimitive) {
try { first.detachPrimitive(entry.fillPrimitive); } catch { /* ok */ }
try { hlineHost.detachPrimitive(entry.fillPrimitive); } catch { /* ok */ }
}
}
if (entry.cloudPlugin) {