260330_02_ENH: 연도별 사례수 row에서 Column으로 이동
This commit is contained in:
@@ -83,23 +83,29 @@ const LGPenetrationPage = () => {
|
|||||||
|
|
||||||
const penetrationRows =
|
const penetrationRows =
|
||||||
data?.statisticsDataMap?.penetration
|
data?.statisticsDataMap?.penetration
|
||||||
.filter((r) => r.rowLabel == `보유` || r.rowLabel == `사례수`)
|
.filter((r) => r.rowLabel == `보유`)
|
||||||
.map((row) => {
|
.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 {
|
return {
|
||||||
...row,
|
...row,
|
||||||
rowLabel: rowLabel,
|
rowLabel: row.year,
|
||||||
|
sample: `(${rowSample})`,
|
||||||
}
|
}
|
||||||
}) ?? [];
|
}) ?? [];
|
||||||
|
|
||||||
const penetrationLGRows =
|
const penetrationLGRows =
|
||||||
data?.statisticsDataMap?.penetration_lg
|
data?.statisticsDataMap?.penetration_lg
|
||||||
.filter((r) => r.rowLabel == `보유` || r.rowLabel == `사례수`)
|
.filter((r) => r.rowLabel == `보유`)
|
||||||
.map((row) => {
|
.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 {
|
return {
|
||||||
...row,
|
...row,
|
||||||
rowLabel: rowLabel,
|
rowLabel: row.year,
|
||||||
|
sample: `(${rowSample})`,
|
||||||
}
|
}
|
||||||
}) ?? [];
|
}) ?? [];
|
||||||
|
|
||||||
@@ -124,7 +130,7 @@ const LGPenetrationPage = () => {
|
|||||||
}, [penetrationLGRows]);
|
}, [penetrationLGRows]);
|
||||||
|
|
||||||
const penetrationLGRowsWithGap = useMemo(() => {
|
const penetrationLGRowsWithGap = useMemo(() => {
|
||||||
const withGap = withGapRow(penetrationLGRows, calcGapProductRow, -1, -3);
|
const withGap = withGapRow(penetrationLGRows, calcGapProductRow, -1, -2);
|
||||||
|
|
||||||
return withTotalBaseRow("보급률",penetrationRows, wrapSampleRow(withGap, false), calcTotalBaseRow);
|
return withTotalBaseRow("보급률",penetrationRows, wrapSampleRow(withGap, false), calcTotalBaseRow);
|
||||||
}, [penetrationRows, penetrationLGRows]);
|
}, [penetrationRows, penetrationLGRows]);
|
||||||
@@ -132,6 +138,7 @@ const LGPenetrationPage = () => {
|
|||||||
const productTableRows = useMemo<TopChartTableRow[]>(() => {
|
const productTableRows = useMemo<TopChartTableRow[]>(() => {
|
||||||
return penetrationLGRowsWithGap.map((row) => ({
|
return penetrationLGRowsWithGap.map((row) => ({
|
||||||
label: formatRowLabel(row.rowLabel),
|
label: formatRowLabel(row.rowLabel),
|
||||||
|
sample: row.sample,
|
||||||
total: row.total,
|
total: row.total,
|
||||||
values: includeProductKeys.map((k) => (row as any)[k] ?? null),
|
values: includeProductKeys.map((k) => (row as any)[k] ?? null),
|
||||||
}));
|
}));
|
||||||
@@ -204,7 +211,7 @@ const LGPenetrationPage = () => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
registerExcelExporter(async () => {
|
registerExcelExporter(async () => {
|
||||||
const excelHeader = buildHeader_ProductKeyMap(productKeyMap);
|
const excelHeader = buildHeader_ProductKeyMap(productKeyMap, "sample");
|
||||||
const lifeStageHeader = buildHeader_LifeStageColumns(LIFE_STAGE_COLUMNS);
|
const lifeStageHeader = buildHeader_LifeStageColumns(LIFE_STAGE_COLUMNS);
|
||||||
|
|
||||||
type AnyRow = Record<string, any>;
|
type AnyRow = Record<string, any>;
|
||||||
|
|||||||
@@ -55,28 +55,34 @@ const LGPurchasePage = () => {
|
|||||||
|
|
||||||
const purchaseRows =
|
const purchaseRows =
|
||||||
data?.statisticsDataMap?.purchase
|
data?.statisticsDataMap?.purchase
|
||||||
.filter((r) => r.rowLabel == `구매` || r.rowLabel == `사례수`)
|
.filter((r) => r.rowLabel == `구매`)
|
||||||
.map((row) => {
|
.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 {
|
return {
|
||||||
...row,
|
...row,
|
||||||
rowLabel: rowLabel,
|
rowLabel: row.year,
|
||||||
|
sample: `(${rowSample})`,
|
||||||
}
|
}
|
||||||
}) ?? [];
|
}) ?? [];
|
||||||
|
|
||||||
const purchaseLGRows =
|
const purchaseLGRows =
|
||||||
data?.statisticsDataMap?.purchase_lg
|
data?.statisticsDataMap?.purchase_lg
|
||||||
.filter((row) => row.rowLabel === `구입` || row.rowLabel == `사례수`)
|
.filter((row) => row.rowLabel === `구입`)
|
||||||
.map((row) => {
|
.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 {
|
return {
|
||||||
...row,
|
...row,
|
||||||
rowLabel: rowLabel,
|
rowLabel: row.year,
|
||||||
|
sample: `(${rowSample})`,
|
||||||
}
|
}
|
||||||
}) ?? [];
|
}) ?? [];
|
||||||
|
|
||||||
const purchaseLGRowsWithGap = useMemo(() => {
|
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);
|
return withTotalBaseRow("구입율",purchaseRows, withGap, calcTotalBaseRow);
|
||||||
}, [purchaseRows, purchaseLGRows]);
|
}, [purchaseRows, purchaseLGRows]);
|
||||||
|
|
||||||
@@ -99,6 +105,7 @@ const LGPurchasePage = () => {
|
|||||||
const purchaseTableRows = useMemo<TopChartTableRow[]>(() => {
|
const purchaseTableRows = useMemo<TopChartTableRow[]>(() => {
|
||||||
return purchaseLGRowsWithGap.map((row) => ({
|
return purchaseLGRowsWithGap.map((row) => ({
|
||||||
label: formatRowLabel(row.rowLabel),
|
label: formatRowLabel(row.rowLabel),
|
||||||
|
sample: row.sample,
|
||||||
total: row.total,
|
total: row.total,
|
||||||
values: includeProductKeys.map((k) => (row as any)[k] ?? null),
|
values: includeProductKeys.map((k) => (row as any)[k] ?? null),
|
||||||
}));
|
}));
|
||||||
@@ -146,7 +153,7 @@ const LGPurchasePage = () => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
registerExcelExporter(async () => {
|
registerExcelExporter(async () => {
|
||||||
const excelHeader = buildHeader_ProductKeyMap(productKeyMap);
|
const excelHeader = buildHeader_ProductKeyMap(productKeyMap, "sample");
|
||||||
|
|
||||||
await exportDashboardExcel({
|
await exportDashboardExcel({
|
||||||
fileName: `${SITE_TITLE}(LG제품 구매율).xlsx`,
|
fileName: `${SITE_TITLE}(LG제품 구매율).xlsx`,
|
||||||
|
|||||||
@@ -56,12 +56,15 @@ const PenetrationPage = () => {
|
|||||||
|
|
||||||
const penetrationRows =
|
const penetrationRows =
|
||||||
data?.statisticsDataMap?.penetration
|
data?.statisticsDataMap?.penetration
|
||||||
.filter((r) => r.rowLabel == `보유` || r.rowLabel == `사례수`)
|
.filter((r) => r.rowLabel == `보유`)
|
||||||
.map((row) => {
|
.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 {
|
return {
|
||||||
...row,
|
...row,
|
||||||
rowLabel: rowLabel,
|
rowLabel: row.year,
|
||||||
|
sample: `(${rowSample})`,
|
||||||
}
|
}
|
||||||
}) ?? [];
|
}) ?? [];
|
||||||
|
|
||||||
@@ -77,8 +80,8 @@ const PenetrationPage = () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const penetrationRowsWithGapCagr = useMemo(() => {
|
const penetrationRowsWithGapCagr = useMemo(() => {
|
||||||
const withGap = withGapRow(penetrationRows, calcGapProductRow, -1, -3);
|
const withGap = withGapRow(penetrationRows, calcGapProductRow, -1, -2);
|
||||||
const withCagr = withCagrRow(withGap, calcCagrRow, -1, 2);
|
const withCagr = withCagrRow(withGap, calcCagrRow, -1, 1);
|
||||||
|
|
||||||
withCagr.forEach((row) => {
|
withCagr.forEach((row) => {
|
||||||
if (row.rowLabel !== "CAGR") {
|
if (row.rowLabel !== "CAGR") {
|
||||||
@@ -94,6 +97,7 @@ const PenetrationPage = () => {
|
|||||||
const productTableRows = useMemo<TopChartTableRow[]>(() => {
|
const productTableRows = useMemo<TopChartTableRow[]>(() => {
|
||||||
return penetrationRowsWithGapCagr.map((row) => ({
|
return penetrationRowsWithGapCagr.map((row) => ({
|
||||||
label: formatRowLabel(row.rowLabel),
|
label: formatRowLabel(row.rowLabel),
|
||||||
|
sample: row.sample,
|
||||||
total: row.total,
|
total: row.total,
|
||||||
values: PRODUCT_KEYS.map((k) => (row as any)[k] ?? null),
|
values: PRODUCT_KEYS.map((k) => (row as any)[k] ?? null),
|
||||||
}))
|
}))
|
||||||
@@ -102,7 +106,7 @@ const PenetrationPage = () => {
|
|||||||
const productChartData = useMemo<ChartData>(() => {
|
const productChartData = useMemo<ChartData>(() => {
|
||||||
return {
|
return {
|
||||||
categories: [...PRODUCTS],
|
categories: [...PRODUCTS],
|
||||||
series: penetrationRows.filter((r) => !r.rowLabel.includes("사례수"))
|
series: penetrationRows
|
||||||
.map((row) => ({
|
.map((row) => ({
|
||||||
name: row.year,
|
name: row.year,
|
||||||
data: PRODUCT_KEYS.map((k) => toNumOr0((row as any)[k])),
|
data: PRODUCT_KEYS.map((k) => toNumOr0((row as any)[k])),
|
||||||
@@ -144,7 +148,8 @@ const PenetrationPage = () => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
registerExcelExporter(async () => {
|
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>;
|
type AnyRow = Record<string, any>;
|
||||||
|
|
||||||
const sections: Section<AnyRow>[] = [
|
const sections: Section<AnyRow>[] = [
|
||||||
@@ -152,7 +157,7 @@ const PenetrationPage = () => {
|
|||||||
...YEARS.map((year) => (
|
...YEARS.map((year) => (
|
||||||
{
|
{
|
||||||
title: `브랜드 별 점유율_${year}년`,
|
title: `브랜드 별 점유율_${year}년`,
|
||||||
header: excelHeader,
|
header: brandHeader,
|
||||||
rows: penetrationBrandRows.filter((row) => row.year === year),
|
rows: penetrationBrandRows.filter((row) => row.year === year),
|
||||||
rowGap: 1,
|
rowGap: 1,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,22 +55,26 @@ const PurchasePage = () => {
|
|||||||
|
|
||||||
const purchaseRows =
|
const purchaseRows =
|
||||||
data?.statisticsDataMap?.purchase
|
data?.statisticsDataMap?.purchase
|
||||||
.filter((r) => r.rowLabel == `구매` || r.rowLabel == `사례수`)
|
.filter((r) => r.rowLabel == `구매`)
|
||||||
.map((row) => {
|
.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 {
|
return {
|
||||||
...row,
|
...row,
|
||||||
rowLabel: rowLabel,
|
rowLabel: row.year,
|
||||||
|
sample: `(${rowSample})`,
|
||||||
}
|
}
|
||||||
}) ?? [];
|
}) ?? [];
|
||||||
|
|
||||||
const purchaseRowsWithGap = useMemo(() => {
|
const purchaseRowsWithGap = useMemo(() => {
|
||||||
return withGapRow(wrapSampleRow(purchaseRows, false), calcGapProductRow, -1, -3);
|
return withGapRow(wrapSampleRow(purchaseRows, false), calcGapProductRow, -1, -2);
|
||||||
}, [purchaseRows]);
|
}, [purchaseRows]);
|
||||||
|
|
||||||
const purchaseTableRows = useMemo<TopChartTableRow[]>(() => {
|
const purchaseTableRows = useMemo<TopChartTableRow[]>(() => {
|
||||||
return purchaseRowsWithGap.map((row) => ({
|
return purchaseRowsWithGap.map((row) => ({
|
||||||
label: formatRowLabel(row.rowLabel),
|
label: formatRowLabel(row.rowLabel),
|
||||||
|
sample: row.sample,
|
||||||
total: row.total,
|
total: row.total,
|
||||||
values: PRODUCT_KEYS.map((k) => (row as any)[k] ?? null),
|
values: PRODUCT_KEYS.map((k) => (row as any)[k] ?? null),
|
||||||
}));
|
}));
|
||||||
@@ -100,7 +104,7 @@ const PurchasePage = () => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
registerExcelExporter(async () => {
|
registerExcelExporter(async () => {
|
||||||
const excelHeader = buildHeader_ProductKeyMap(PRODUCT_KEY_MAP);
|
const excelHeader = buildHeader_ProductKeyMap(PRODUCT_KEY_MAP, "sample");
|
||||||
|
|
||||||
await exportDashboardExcel({
|
await exportDashboardExcel({
|
||||||
fileName: `${SITE_TITLE}(구매율).xlsx`,
|
fileName: `${SITE_TITLE}(구매율).xlsx`,
|
||||||
|
|||||||
@@ -75,13 +75,15 @@ export default function TopChartTable({
|
|||||||
<table className={cn("lg-table", tableClassName)} style={{ minWidth: `${minWidth ?? minWidthPx}px` }}>
|
<table className={cn("lg-table", tableClassName)} style={{ minWidth: `${minWidth ?? minWidthPx}px` }}>
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<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 }}>
|
<td colSpan={categories.length} style={{ padding: 0, height: chartNode ? chartHeight : 0 }}>
|
||||||
{chartNode ? <div style={{ width: "100%", height: "100%" }}>{chartNode}</div> : null}
|
{chartNode ? <div style={{ width: "100%", height: "100%" }}>{chartNode}</div> : null}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
<tr className="lg-table__subhead">
|
<tr className="lg-table__subhead">
|
||||||
|
<th className="lg-table__sep-r"></th>
|
||||||
|
<th className="content-text-xs">사례수</th>
|
||||||
{categories.map((category) => (
|
{categories.map((category) => (
|
||||||
<th key={category} className="content-text-xs">
|
<th key={category} className="content-text-xs">
|
||||||
{category}
|
{category}
|
||||||
@@ -102,6 +104,9 @@ export default function TopChartTable({
|
|||||||
<th scope="row" className="lg-table__rowhead lg-table__sep-r content-text-sm">
|
<th scope="row" className="lg-table__rowhead lg-table__sep-r content-text-sm">
|
||||||
{row.label}
|
{row.label}
|
||||||
</th>
|
</th>
|
||||||
|
<td>
|
||||||
|
{row.sample}
|
||||||
|
</td>
|
||||||
|
|
||||||
{categories.map((_, categoryIndex) => {
|
{categories.map((_, categoryIndex) => {
|
||||||
const rawValue = row.values?.[categoryIndex];
|
const rawValue = row.values?.[categoryIndex];
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ export type TopChartTableRow = {
|
|||||||
/** 좌측 rowhead 라벨 */
|
/** 좌측 rowhead 라벨 */
|
||||||
label: string;
|
label: string;
|
||||||
total: number | string | null | undefined;
|
total: number | string | null | undefined;
|
||||||
|
sample: number | string | null | undefined;
|
||||||
/** categories 순서대로 값 */
|
/** categories 순서대로 값 */
|
||||||
values: Array<number | string | null | undefined>;
|
values: Array<number | string | null | undefined>;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -517,12 +517,16 @@ function colToLetters(col: number) {
|
|||||||
*/
|
*/
|
||||||
export function buildHeader_ProductKeyMap(
|
export function buildHeader_ProductKeyMap(
|
||||||
productKeyMap: Record<string, string>,
|
productKeyMap: Record<string, string>,
|
||||||
|
sampleHeadKey? :string,
|
||||||
rowHeadKey = "rowLabel"
|
rowHeadKey = "rowLabel"
|
||||||
): HeaderBlock {
|
): HeaderBlock {
|
||||||
const entries = typedEntries(productKeyMap);
|
const entries = typedEntries(productKeyMap);
|
||||||
|
|
||||||
const headerRow: HeaderCell[] = [
|
const headerRow: HeaderCell[] = [
|
||||||
{ text: "", styleKey: "header", align: "center" },
|
{ text: "", styleKey: "header", align: "center" },
|
||||||
|
...(sampleHeadKey
|
||||||
|
? [{ text: "사례수", styleKey: "header", align: "center" } as const]
|
||||||
|
: []),
|
||||||
...entries.map(([, label]) => ({
|
...entries.map(([, label]) => ({
|
||||||
text: String(label),
|
text: String(label),
|
||||||
styleKey: "header" as const,
|
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 };
|
return { headerRows: [headerRow], leafKeys, totalCols: headerRow.length };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ export type BaseRow = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// { year, rowLabel, total, ...category }
|
// { 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 }
|
// { year, rowLabel, total, ...banner }
|
||||||
// (배너는 기본 41개 키 + 차트별 추가 키가 생길 수 있으니 확장 허용)
|
// (배너는 기본 41개 키 + 차트별 추가 키가 생길 수 있으니 확장 허용)
|
||||||
|
|||||||
Reference in New Issue
Block a user