260331_05_ENH: 차트에 사례수 흘러들어가지 않도록 조치

This commit is contained in:
2026-03-31 14:46:50 +09:00
parent 8540df7274
commit 882a5f046a

View File

@@ -192,6 +192,9 @@ export function buildOverlayBarData<T extends { year: number; rowLabel: string }
};
}
const shouldExcludeLabel = (excludeRowLabels: string[], label: string) =>
excludeRowLabels.some((el) => label.includes(el));
type Opts = {
/** 기본: ["사례수", "gap"] 제외 */
excludeRowLabels?: string[];
@@ -210,25 +213,22 @@ export function buildYearSeriesChartData(rows: BannerRow[], opts: Opts = {}): Ch
const years = Array.from(new Set(rows.map((r) => r.year))).sort((a, b) => Number(a) - Number(b));
// rowLabel 순서: 첫 연도 기준으로 고정(없으면 전체 unique)
const baseYear = years[0];
const baseLabels = rows
.filter((r) => r.year === baseYear)
.map((r) => r.rowLabel)
.filter((l) => !excludeRowLabels.includes(l));
.filter((r) => r.year === baseYear)
.map((r) => r.rowLabel)
.filter((l) => !shouldExcludeLabel(excludeRowLabels, l));
const labels =
baseLabels.length > 0
? baseLabels
: Array.from(
new Set(rows.map((r) => r.rowLabel).filter((l) => !excludeRowLabels.includes(l)))
);
: Array.from(new Set(rows.map((r) => r.rowLabel).filter((l) => !shouldExcludeLabel(excludeRowLabels, l))));
// 빠른 조회용: year -> (rowLabel -> total)
const map = new Map<string, Map<string, number>>();
for (const y of years) map.set(y, new Map());
for (const r of rows) {
if (excludeRowLabels.includes(r.rowLabel)) continue;
if (shouldExcludeLabel(excludeRowLabels, r.rowLabel)) continue;
map.get(r.year)?.set(r.rowLabel, Number(r.total ?? 0));
}
@@ -237,7 +237,7 @@ export function buildYearSeriesChartData(rows: BannerRow[], opts: Opts = {}): Ch
series: years.map((y) => ({
name: yearLabel(y),
data: labels.map((lbl) => map.get(y)?.get(lbl) ?? null),
...(splitStackByYear ? { stack: String(y) } : {}), // 같은 stack이면 "연도끼리 스택"되어버리니 방지용
...(splitStackByYear ? { stack: String(y) } : {}),
})),
};
}
@@ -258,13 +258,13 @@ export function buildRowLabelSeriesChartData(
const baseRowLabels = rows
.filter((r) => r.year === baseYear)
.map((r) => r.rowLabel)
.filter((l) => !excludeRowLabels.includes(l));
.filter((l) => !shouldExcludeLabel(excludeRowLabels, l));
const rowLabels =
baseRowLabels.length > 0
? baseRowLabels
: Array.from(
new Set(rows.map((r) => r.rowLabel).filter((l) => !excludeRowLabels.includes(l)))
new Set(rows.map((r) => r.rowLabel).filter((l) => !shouldExcludeLabel(excludeRowLabels, l)))
);
// (year -> (rowLabel -> total)) 맵
@@ -272,7 +272,7 @@ export function buildRowLabelSeriesChartData(
for (const y of years) valueMap.set(y, new Map());
for (const r of rows) {
if (excludeRowLabels.includes(r.rowLabel)) continue;
if (shouldExcludeLabel(excludeRowLabels, r.rowLabel)) continue;
valueMap.get(r.year)!.set(r.rowLabel, Number(r.total ?? 0));
}