260205_01_ENH: 페이지 별 엑셀 다운로드 적용
This commit is contained in:
@@ -174,7 +174,7 @@ type Opts = {
|
||||
/** 기본: ["사례수", "gap"] 제외 */
|
||||
excludeRowLabels?: string[];
|
||||
/** 기본: (y) => `${y}년` */
|
||||
yearLabel?: (y: number) => string;
|
||||
yearLabel?: (y: string) => string;
|
||||
/** StackBar에 넣을 때 "스택 방지"용(연도별 stack 분리) */
|
||||
splitStackByYear?: boolean;
|
||||
};
|
||||
@@ -186,7 +186,7 @@ export function buildYearSeriesChartData(rows: ServerBannerRow[], opts: Opts = {
|
||||
splitStackByYear = false,
|
||||
} = opts;
|
||||
|
||||
const years = Array.from(new Set(rows.map((r) => r.year))).sort((a, b) => a - 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];
|
||||
@@ -203,7 +203,7 @@ export function buildYearSeriesChartData(rows: ServerBannerRow[], opts: Opts = {
|
||||
);
|
||||
|
||||
// 빠른 조회용: year -> (rowLabel -> total)
|
||||
const map = new Map<number, Map<string, number>>();
|
||||
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;
|
||||
@@ -229,7 +229,7 @@ export function buildRowLabelSeriesChartData(
|
||||
yearLabel = (y) => `${y}년`,
|
||||
} = opts;
|
||||
|
||||
const years = Array.from(new Set(rows.map((r) => r.year))).sort((a, b) => a - b);
|
||||
const years = Array.from(new Set(rows.map((r) => r.year))).sort((a, b) => Number(a) - Number(b));
|
||||
const categories = years.map(yearLabel);
|
||||
|
||||
const baseYear = years[0];
|
||||
@@ -246,7 +246,7 @@ export function buildRowLabelSeriesChartData(
|
||||
);
|
||||
|
||||
// (year -> (rowLabel -> total)) 맵
|
||||
const valueMap = new Map<number, Map<string, number>>();
|
||||
const valueMap = new Map<string, Map<string, number>>();
|
||||
for (const y of years) valueMap.set(y, new Map());
|
||||
|
||||
for (const r of rows) {
|
||||
@@ -270,14 +270,14 @@ export const buildGapRow = (
|
||||
baseRowLabel: string,
|
||||
gapRowLabel = "gap"
|
||||
): ServerBannerRow | null => {
|
||||
const prev = rows.find(r => r.year === prevYear && r.rowLabel === baseRowLabel);
|
||||
const cur = rows.find(r => r.year === curYear && r.rowLabel === baseRowLabel);
|
||||
const prev = rows.find(r => Number(r.year) === prevYear && r.rowLabel === baseRowLabel);
|
||||
const cur = rows.find(r => Number(r.year) === curYear && r.rowLabel === baseRowLabel);
|
||||
if (!prev || !cur) return null;
|
||||
|
||||
const gap: ServerBannerRow = {
|
||||
year: curYear,
|
||||
year: String(curYear),
|
||||
rowLabel: gapRowLabel,
|
||||
total: (typeof cur.total === "number" ? cur.total : 0) - (typeof prev.total === "number" ? prev.total : 0),
|
||||
total: String(Number(cur.total) - Number(prev.total)),
|
||||
};
|
||||
|
||||
// cur가 가진 모든 key를 돌면서 "숫자 필드"면 diff 계산
|
||||
@@ -287,10 +287,7 @@ export const buildGapRow = (
|
||||
const vCur = cur[k];
|
||||
const vPrev = prev[k];
|
||||
|
||||
const hasNumber = typeof vCur === "number" || typeof vPrev === "number";
|
||||
if (!hasNumber) return;
|
||||
|
||||
(gap as any)[k] = (typeof vCur === "number" ? vCur : 0) - (typeof vPrev === "number" ? vPrev : 0);
|
||||
(gap as any)[k] = String(Number(vCur) - Number(vPrev));
|
||||
});
|
||||
|
||||
return gap;
|
||||
|
||||
Reference in New Issue
Block a user