diff --git a/src/app/(pages)/(main)/total/lg-penetration/page.tsx b/src/app/(pages)/(main)/total/lg-penetration/page.tsx index d459201..1ee5174 100644 --- a/src/app/(pages)/(main)/total/lg-penetration/page.tsx +++ b/src/app/(pages)/(main)/total/lg-penetration/page.tsx @@ -83,23 +83,29 @@ const LGPenetrationPage = () => { const penetrationRows = data?.statisticsDataMap?.penetration - .filter((r) => r.rowLabel == `보유` || r.rowLabel == `사례수`) + .filter((r) => r.rowLabel == `보유`) .map((row) => { - const rowLabel = row.rowLabel == `사례수`? `${formatRowLabel(row.year)} ${row.rowLabel}` : row.year; + const rowSample = data?.statisticsDataMap?.penetration + .find(r => r.rowLabel == '사례수' && r.year == row.year)?.total ?? 0; + return { ...row, - rowLabel: rowLabel, + rowLabel: row.year, + sample: `(${rowSample})`, } }) ?? []; const penetrationLGRows = data?.statisticsDataMap?.penetration_lg - .filter((r) => r.rowLabel == `보유` || r.rowLabel == `사례수`) + .filter((r) => r.rowLabel == `보유`) .map((row) => { - const rowLabel = row.rowLabel == `사례수`? `${formatRowLabel(row.year)} ${row.rowLabel}` : row.year; + const rowSample = data?.statisticsDataMap?.penetration_lg + .find(r => r.rowLabel == '사례수' && r.year == row.year)?.total ?? 0; + return { ...row, - rowLabel: rowLabel, + rowLabel: row.year, + sample: `(${rowSample})`, } }) ?? []; @@ -124,7 +130,7 @@ const LGPenetrationPage = () => { }, [penetrationLGRows]); const penetrationLGRowsWithGap = useMemo(() => { - const withGap = withGapRow(penetrationLGRows, calcGapProductRow, -1, -3); + const withGap = withGapRow(penetrationLGRows, calcGapProductRow, -1, -2); return withTotalBaseRow("보급률",penetrationRows, wrapSampleRow(withGap, false), calcTotalBaseRow); }, [penetrationRows, penetrationLGRows]); @@ -132,6 +138,7 @@ const LGPenetrationPage = () => { const productTableRows = useMemo(() => { return penetrationLGRowsWithGap.map((row) => ({ label: formatRowLabel(row.rowLabel), + sample: row.sample, total: row.total, values: includeProductKeys.map((k) => (row as any)[k] ?? null), })); @@ -204,7 +211,7 @@ const LGPenetrationPage = () => { useEffect(() => { registerExcelExporter(async () => { - const excelHeader = buildHeader_ProductKeyMap(productKeyMap); + const excelHeader = buildHeader_ProductKeyMap(productKeyMap, "sample"); const lifeStageHeader = buildHeader_LifeStageColumns(LIFE_STAGE_COLUMNS); type AnyRow = Record; diff --git a/src/app/(pages)/(main)/total/lg-purchase/page.tsx b/src/app/(pages)/(main)/total/lg-purchase/page.tsx index d3e8795..b96fa4d 100644 --- a/src/app/(pages)/(main)/total/lg-purchase/page.tsx +++ b/src/app/(pages)/(main)/total/lg-purchase/page.tsx @@ -55,28 +55,34 @@ const LGPurchasePage = () => { const purchaseRows = data?.statisticsDataMap?.purchase - .filter((r) => r.rowLabel == `구매` || r.rowLabel == `사례수`) + .filter((r) => r.rowLabel == `구매`) .map((row) => { - const rowLabel = row.rowLabel == `사례수`? `${formatRowLabel(row.year)} ${row.rowLabel}` : row.year; + const rowSample = data?.statisticsDataMap?.purchase + .find(r => r.rowLabel == '사례수' && r.year == row.year)?.total ?? 0; + return { ...row, - rowLabel: rowLabel, + rowLabel: row.year, + sample: `(${rowSample})`, } }) ?? []; const purchaseLGRows = data?.statisticsDataMap?.purchase_lg - .filter((row) => row.rowLabel === `구입` || row.rowLabel == `사례수`) + .filter((row) => row.rowLabel === `구입`) .map((row) => { - const rowLabel = row.rowLabel == `사례수`? `${formatRowLabel(row.year)} ${row.rowLabel}` : row.year; + const rowSample = data?.statisticsDataMap?.purchase_lg + .find(r => r.rowLabel == '사례수' && r.year == row.year)?.total ?? 0; + return { ...row, - rowLabel: rowLabel, + rowLabel: row.year, + sample: `(${rowSample})`, } }) ?? []; const purchaseLGRowsWithGap = useMemo(() => { - const withGap = withGapRow(wrapSampleRow(purchaseLGRows, false), calcGapProductRow, -1, -3); + const withGap = withGapRow(wrapSampleRow(purchaseLGRows, false), calcGapProductRow, -1, -2); return withTotalBaseRow("구입율",purchaseRows, withGap, calcTotalBaseRow); }, [purchaseRows, purchaseLGRows]); @@ -99,6 +105,7 @@ const LGPurchasePage = () => { const purchaseTableRows = useMemo(() => { return purchaseLGRowsWithGap.map((row) => ({ label: formatRowLabel(row.rowLabel), + sample: row.sample, total: row.total, values: includeProductKeys.map((k) => (row as any)[k] ?? null), })); @@ -146,7 +153,7 @@ const LGPurchasePage = () => { useEffect(() => { registerExcelExporter(async () => { - const excelHeader = buildHeader_ProductKeyMap(productKeyMap); + const excelHeader = buildHeader_ProductKeyMap(productKeyMap, "sample"); await exportDashboardExcel({ fileName: `${SITE_TITLE}(LG제품 구매율).xlsx`, diff --git a/src/app/(pages)/(main)/total/penetration/page.tsx b/src/app/(pages)/(main)/total/penetration/page.tsx index 1a707ad..c0fadc3 100644 --- a/src/app/(pages)/(main)/total/penetration/page.tsx +++ b/src/app/(pages)/(main)/total/penetration/page.tsx @@ -56,12 +56,15 @@ const PenetrationPage = () => { const penetrationRows = data?.statisticsDataMap?.penetration - .filter((r) => r.rowLabel == `보유` || r.rowLabel == `사례수`) + .filter((r) => r.rowLabel == `보유`) .map((row) => { - const rowLabel = row.rowLabel == `사례수`? `${formatRowLabel(row.year)} ${row.rowLabel}` : row.year; + const rowSample = data?.statisticsDataMap?.penetration + .find(r => r.rowLabel == '사례수' && r.year == row.year)?.total ?? 0; + return { ...row, - rowLabel: rowLabel, + rowLabel: row.year, + sample: `(${rowSample})`, } }) ?? []; @@ -77,8 +80,8 @@ const PenetrationPage = () => { }); const penetrationRowsWithGapCagr = useMemo(() => { - const withGap = withGapRow(penetrationRows, calcGapProductRow, -1, -3); - const withCagr = withCagrRow(withGap, calcCagrRow, -1, 2); + const withGap = withGapRow(penetrationRows, calcGapProductRow, -1, -2); + const withCagr = withCagrRow(withGap, calcCagrRow, -1, 1); withCagr.forEach((row) => { if (row.rowLabel !== "CAGR") { @@ -94,6 +97,7 @@ const PenetrationPage = () => { const productTableRows = useMemo(() => { return penetrationRowsWithGapCagr.map((row) => ({ label: formatRowLabel(row.rowLabel), + sample: row.sample, total: row.total, values: PRODUCT_KEYS.map((k) => (row as any)[k] ?? null), })) @@ -102,7 +106,7 @@ const PenetrationPage = () => { const productChartData = useMemo(() => { return { categories: [...PRODUCTS], - series: penetrationRows.filter((r) => !r.rowLabel.includes("사례수")) + series: penetrationRows .map((row) => ({ name: row.year, data: PRODUCT_KEYS.map((k) => toNumOr0((row as any)[k])), @@ -144,7 +148,8 @@ const PenetrationPage = () => { useEffect(() => { registerExcelExporter(async () => { - const excelHeader = buildHeader_ProductKeyMap(PRODUCT_KEY_MAP); + const excelHeader = buildHeader_ProductKeyMap(PRODUCT_KEY_MAP, "sample"); + const brandHeader = buildHeader_ProductKeyMap(PRODUCT_KEY_MAP); type AnyRow = Record; const sections: Section[] = [ @@ -152,7 +157,7 @@ const PenetrationPage = () => { ...YEARS.map((year) => ( { title: `브랜드 별 점유율_${year}년`, - header: excelHeader, + header: brandHeader, rows: penetrationBrandRows.filter((row) => row.year === year), rowGap: 1, } diff --git a/src/app/(pages)/(main)/total/purchase/page.tsx b/src/app/(pages)/(main)/total/purchase/page.tsx index 64bde75..e1a139c 100644 --- a/src/app/(pages)/(main)/total/purchase/page.tsx +++ b/src/app/(pages)/(main)/total/purchase/page.tsx @@ -55,22 +55,26 @@ const PurchasePage = () => { const purchaseRows = data?.statisticsDataMap?.purchase - .filter((r) => r.rowLabel == `구매` || r.rowLabel == `사례수`) + .filter((r) => r.rowLabel == `구매`) .map((row) => { - const rowLabel = row.rowLabel == `사례수`? `${formatRowLabel(row.year)} ${row.rowLabel}` : row.year; + const rowSample = data?.statisticsDataMap?.purchase + .find(r => r.rowLabel == '사례수' && r.year == row.year)?.total ?? 0; + return { ...row, - rowLabel: rowLabel, + rowLabel: row.year, + sample: `(${rowSample})`, } }) ?? []; const purchaseRowsWithGap = useMemo(() => { - return withGapRow(wrapSampleRow(purchaseRows, false), calcGapProductRow, -1, -3); + return withGapRow(wrapSampleRow(purchaseRows, false), calcGapProductRow, -1, -2); }, [purchaseRows]); const purchaseTableRows = useMemo(() => { return purchaseRowsWithGap.map((row) => ({ label: formatRowLabel(row.rowLabel), + sample: row.sample, total: row.total, values: PRODUCT_KEYS.map((k) => (row as any)[k] ?? null), })); @@ -100,7 +104,7 @@ const PurchasePage = () => { useEffect(() => { registerExcelExporter(async () => { - const excelHeader = buildHeader_ProductKeyMap(PRODUCT_KEY_MAP); + const excelHeader = buildHeader_ProductKeyMap(PRODUCT_KEY_MAP, "sample"); await exportDashboardExcel({ fileName: `${SITE_TITLE}(구매율).xlsx`, diff --git a/src/components/lge-dashboard/combo/TopChartTable.tsx b/src/components/lge-dashboard/combo/TopChartTable.tsx index f1b21b4..706ca79 100644 --- a/src/components/lge-dashboard/combo/TopChartTable.tsx +++ b/src/components/lge-dashboard/combo/TopChartTable.tsx @@ -75,13 +75,15 @@ export default function TopChartTable({ - + + {categories.map((category) => ( + {categories.map((_, categoryIndex) => { const rawValue = row.values?.[categoryIndex]; diff --git a/src/components/lge-dashboard/types.ts b/src/components/lge-dashboard/types.ts index aefe79c..b7bbcc2 100644 --- a/src/components/lge-dashboard/types.ts +++ b/src/components/lge-dashboard/types.ts @@ -47,6 +47,7 @@ export type TopChartTableRow = { /** 좌측 rowhead 라벨 */ label: string; total: number | string | null | undefined; + sample: number | string | null | undefined; /** categories 순서대로 값 */ values: Array; }; diff --git a/src/lib/lg-export-excel.ts b/src/lib/lg-export-excel.ts index d956f7c..ea9ed47 100644 --- a/src/lib/lg-export-excel.ts +++ b/src/lib/lg-export-excel.ts @@ -517,12 +517,16 @@ function colToLetters(col: number) { */ export function buildHeader_ProductKeyMap( productKeyMap: Record, + sampleHeadKey? :string, rowHeadKey = "rowLabel" ): HeaderBlock { const entries = typedEntries(productKeyMap); const headerRow: HeaderCell[] = [ { text: "", styleKey: "header", align: "center" }, + ...(sampleHeadKey + ? [{ text: "사례수", styleKey: "header", align: "center" } as const] + : []), ...entries.map(([, label]) => ({ text: String(label), styleKey: "header" as const, @@ -530,7 +534,8 @@ export function buildHeader_ProductKeyMap( })), ]; - const leafKeys = [rowHeadKey, ...entries.map(([k]) => String(k))]; + + const leafKeys = [rowHeadKey, ...(sampleHeadKey? [sampleHeadKey]: []), ...entries.map(([k]) => String(k))]; return { headerRows: [headerRow], leafKeys, totalCols: headerRow.length }; } diff --git a/src/types/lg.types.ts b/src/types/lg.types.ts index 6fff342..320912b 100644 --- a/src/types/lg.types.ts +++ b/src/types/lg.types.ts @@ -15,7 +15,7 @@ export type BaseRow = { }; // { year, rowLabel, total, ...category } -export type ProductRow = BaseRow & Partial>; +export type ProductRow = BaseRow & Partial<{sample: string;}> & Partial>; // { year, rowLabel, total, ...banner } // (배너는 기본 41개 키 + 차트별 추가 키가 생길 수 있으니 확장 허용)
+ {chartNode ?
{chartNode}
: null}
사례수 {category} @@ -102,6 +104,9 @@ export default function TopChartTable({ {row.label} + {row.sample} +