develop #6
@@ -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 = {
|
type Opts = {
|
||||||
/** 기본: ["사례수", "gap"] 제외 */
|
/** 기본: ["사례수", "gap"] 제외 */
|
||||||
excludeRowLabels?: string[];
|
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));
|
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 baseYear = years[0];
|
||||||
const baseLabels = rows
|
const baseLabels = rows
|
||||||
.filter((r) => r.year === baseYear)
|
.filter((r) => r.year === baseYear)
|
||||||
.map((r) => r.rowLabel)
|
.map((r) => r.rowLabel)
|
||||||
.filter((l) => !excludeRowLabels.includes(l));
|
.filter((l) => !shouldExcludeLabel(excludeRowLabels, l));
|
||||||
|
|
||||||
const labels =
|
const labels =
|
||||||
baseLabels.length > 0
|
baseLabels.length > 0
|
||||||
? baseLabels
|
? baseLabels
|
||||||
: Array.from(
|
: Array.from(new Set(rows.map((r) => r.rowLabel).filter((l) => !shouldExcludeLabel(excludeRowLabels, l))));
|
||||||
new Set(rows.map((r) => r.rowLabel).filter((l) => !excludeRowLabels.includes(l)))
|
|
||||||
);
|
|
||||||
|
|
||||||
// 빠른 조회용: year -> (rowLabel -> total)
|
|
||||||
const map = new Map<string, Map<string, number>>();
|
const map = new Map<string, Map<string, number>>();
|
||||||
for (const y of years) map.set(y, new Map());
|
for (const y of years) map.set(y, new Map());
|
||||||
|
|
||||||
for (const r of rows) {
|
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));
|
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) => ({
|
series: years.map((y) => ({
|
||||||
name: yearLabel(y),
|
name: yearLabel(y),
|
||||||
data: labels.map((lbl) => map.get(y)?.get(lbl) ?? null),
|
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
|
const baseRowLabels = rows
|
||||||
.filter((r) => r.year === baseYear)
|
.filter((r) => r.year === baseYear)
|
||||||
.map((r) => r.rowLabel)
|
.map((r) => r.rowLabel)
|
||||||
.filter((l) => !excludeRowLabels.includes(l));
|
.filter((l) => !shouldExcludeLabel(excludeRowLabels, l));
|
||||||
|
|
||||||
const rowLabels =
|
const rowLabels =
|
||||||
baseRowLabels.length > 0
|
baseRowLabels.length > 0
|
||||||
? baseRowLabels
|
? baseRowLabels
|
||||||
: Array.from(
|
: 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)) 맵
|
// (year -> (rowLabel -> total)) 맵
|
||||||
@@ -272,7 +272,7 @@ export function buildRowLabelSeriesChartData(
|
|||||||
for (const y of years) valueMap.set(y, new Map());
|
for (const y of years) valueMap.set(y, new Map());
|
||||||
|
|
||||||
for (const r of rows) {
|
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));
|
valueMap.get(r.year)!.set(r.rowLabel, Number(r.total ?? 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user