260330_02_ENH: 연도별 사례수 row에서 Column으로 이동
This commit is contained in:
@@ -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<TopChartTableRow[]>(() => {
|
||||
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<string, any>;
|
||||
|
||||
@@ -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<TopChartTableRow[]>(() => {
|
||||
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`,
|
||||
|
||||
@@ -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<TopChartTableRow[]>(() => {
|
||||
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<ChartData>(() => {
|
||||
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<string, any>;
|
||||
|
||||
const sections: Section<AnyRow>[] = [
|
||||
@@ -152,7 +157,7 @@ const PenetrationPage = () => {
|
||||
...YEARS.map((year) => (
|
||||
{
|
||||
title: `브랜드 별 점유율_${year}년`,
|
||||
header: excelHeader,
|
||||
header: brandHeader,
|
||||
rows: penetrationBrandRows.filter((row) => row.year === year),
|
||||
rowGap: 1,
|
||||
}
|
||||
|
||||
@@ -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<TopChartTableRow[]>(() => {
|
||||
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`,
|
||||
|
||||
@@ -75,13 +75,15 @@ export default function TopChartTable({
|
||||
<table className={cn("lg-table", tableClassName)} style={{ minWidth: `${minWidth ?? minWidthPx}px` }}>
|
||||
<thead>
|
||||
<tr>
|
||||
<th rowSpan={2} className="lg-table__sep-r w-31" style={{ whiteSpace: "nowrap" }} />
|
||||
<th colSpan={2} className="w-40" style={{ whiteSpace: "nowrap" }} />
|
||||
<td colSpan={categories.length} style={{ padding: 0, height: chartNode ? chartHeight : 0 }}>
|
||||
{chartNode ? <div style={{ width: "100%", height: "100%" }}>{chartNode}</div> : null}
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr className="lg-table__subhead">
|
||||
<th className="lg-table__sep-r"></th>
|
||||
<th className="content-text-xs">사례수</th>
|
||||
{categories.map((category) => (
|
||||
<th key={category} className="content-text-xs">
|
||||
{category}
|
||||
@@ -102,6 +104,9 @@ export default function TopChartTable({
|
||||
<th scope="row" className="lg-table__rowhead lg-table__sep-r content-text-sm">
|
||||
{row.label}
|
||||
</th>
|
||||
<td>
|
||||
{row.sample}
|
||||
</td>
|
||||
|
||||
{categories.map((_, categoryIndex) => {
|
||||
const rawValue = row.values?.[categoryIndex];
|
||||
|
||||
@@ -47,6 +47,7 @@ export type TopChartTableRow = {
|
||||
/** 좌측 rowhead 라벨 */
|
||||
label: string;
|
||||
total: number | string | null | undefined;
|
||||
sample: number | string | null | undefined;
|
||||
/** categories 순서대로 값 */
|
||||
values: Array<number | string | null | undefined>;
|
||||
};
|
||||
|
||||
@@ -517,12 +517,16 @@ function colToLetters(col: number) {
|
||||
*/
|
||||
export function buildHeader_ProductKeyMap(
|
||||
productKeyMap: Record<string, string>,
|
||||
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 };
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ export type BaseRow = {
|
||||
};
|
||||
|
||||
// { year, rowLabel, total, ...category }
|
||||
export type ProductRow = BaseRow & Partial<Record<ProductKey, string>>;
|
||||
export type ProductRow = BaseRow & Partial<{sample: string;}> & Partial<Record<ProductKey, string>>;
|
||||
|
||||
// { year, rowLabel, total, ...banner }
|
||||
// (배너는 기본 41개 키 + 차트별 추가 키가 생길 수 있으니 확장 허용)
|
||||
|
||||
Reference in New Issue
Block a user