260205_01_ENH: 페이지 별 엑셀 다운로드 적용
This commit is contained in:
@@ -23,11 +23,12 @@ const BaseEChart = ({
|
||||
height = CHART_HEIGHTS.DEFAULT,
|
||||
className,
|
||||
notMerge = true,
|
||||
lazyUpdate = true,
|
||||
lazyUpdate = false, //이거 켜져있으면 오류남 Cannot read properties of undefined (reading 'getRawIndex')
|
||||
onEvents,
|
||||
}: BaseEChartProps) => {
|
||||
const style = useMemo(() => ({ height }), [height]);
|
||||
|
||||
|
||||
return (
|
||||
<div className={className}>
|
||||
<ReactECharts option={option} style={style} notMerge={notMerge} lazyUpdate={lazyUpdate} onEvents={onEvents} />
|
||||
|
||||
@@ -1,9 +1,22 @@
|
||||
import {ChartData, DataColumn, DataTable, HorizontalBar, LeftChartTable, SignStyle} from "@/components/lge-dashboard";
|
||||
import {BannerKey, ServerBannerRow} from "@/types/lg";
|
||||
import {formatRowLabel, wrapSampleRow} from "@/lib/lg-dashboard";
|
||||
import {useMemo} from "react";
|
||||
import {BANNER_GROUP, BANNER_KEY_MAP, GRID_Y_NOT_PADDING} from "@/const/lgConst";
|
||||
import {useEffect, useMemo} from "react";
|
||||
import {
|
||||
BANNER_GROUP,
|
||||
BANNER_KEY_MAP,
|
||||
GRID_Y_NOT_PADDING,
|
||||
LAST_YEAR,
|
||||
} from "@/const/lgConst";
|
||||
import {parseNumber} from "@/lib/utils";
|
||||
import {
|
||||
buildHeader_DataColumn,
|
||||
exportDashboardExcel,
|
||||
Section
|
||||
} from "@/lib/lg-export-excel";
|
||||
import {useLayoutFilter} from "@/components/layout/LayoutFilterContext";
|
||||
import {CategoryTypeValue} from "@/components/layout/CategoryFilter";
|
||||
import {CategoryTargetData} from "@/config/filter.types";
|
||||
|
||||
|
||||
type SectionSpec = {
|
||||
@@ -37,6 +50,7 @@ const buildColumns = (spec: SectionSpec): DataColumn<ServerBannerRow>[] => {
|
||||
key: "total",
|
||||
header: "전체",
|
||||
numeric: true,
|
||||
headRowSpan: 2,
|
||||
headerClassName: SEP_R,
|
||||
cellClassName: SEP_R,
|
||||
width: 80,
|
||||
@@ -68,25 +82,27 @@ type BannerSummaryProps = {
|
||||
};
|
||||
|
||||
const BannerSummary = ({ data, useChart }: BannerSummaryProps) => {
|
||||
const {filterValue, registerExcelExporter } = useLayoutFilter();
|
||||
|
||||
const buildChartData = (rows: ServerBannerRow[], bannerKeys: BannerKey[]): ChartData => {
|
||||
const categories = rows
|
||||
.filter((r) => !r.rowLabel.includes("사례수"))
|
||||
.map((r) => formatRowLabel(r.rowLabel));
|
||||
.map((r) => formatRowLabel(r.rowLabel))
|
||||
.reverse();
|
||||
|
||||
const series = [
|
||||
{
|
||||
name:"전체",
|
||||
data: rows
|
||||
.filter((r) => !r.rowLabel.includes("사례수"))
|
||||
.map((r) => parseNumber(r.total) ?? null),
|
||||
.map((r) => parseNumber(r.total) ?? null)
|
||||
.reverse(),
|
||||
}
|
||||
];
|
||||
|
||||
return { categories, series };
|
||||
};
|
||||
|
||||
const rows = useMemo<ServerBannerRow[]>(() => wrapSampleRow(data), [data]);
|
||||
|
||||
const signStyleGap: SignStyle<ServerBannerRow> = {
|
||||
rowSelector: (row) => row.rowLabel === "gap",
|
||||
display: "arrow",
|
||||
@@ -95,31 +111,73 @@ const BannerSummary = ({ data, useChart }: BannerSummaryProps) => {
|
||||
zeroText: "-",
|
||||
};
|
||||
|
||||
|
||||
const sectionRows = useMemo(() => {
|
||||
return SECTIONS.map((spec) => {
|
||||
const specTitle = spec.title;
|
||||
|
||||
const bannerKeys = getSectionBannerKeys(spec);
|
||||
const columns = buildColumns(spec);
|
||||
|
||||
// rows가 spec마다 다르면 여기서 가져오도록 구성
|
||||
const rows = wrapSampleRow(data);
|
||||
const chartData = buildChartData(rows, bannerKeys);
|
||||
|
||||
return {
|
||||
spec,
|
||||
specTitle,
|
||||
bannerKeys,
|
||||
columns,
|
||||
rows,
|
||||
chartData,
|
||||
};
|
||||
});
|
||||
}, [data]);
|
||||
|
||||
useEffect(() => {
|
||||
registerExcelExporter(async (payload) => {
|
||||
const targetString =filterValue.target === CategoryTargetData.PROFILE? "Profile" : "보급률 변화"
|
||||
const sheetName = `${filterValue.product}_${(filterValue.type as CategoryTypeValue).label}_${targetString}`
|
||||
|
||||
type AnyRow = Record<string, any>;
|
||||
const sections: Section<AnyRow>[] =
|
||||
sectionRows.map((sectionRow) => ({
|
||||
title: sectionRow.specTitle,
|
||||
header: buildHeader_DataColumn(sectionRow.columns),
|
||||
rows: sectionRow.rows as AnyRow[],
|
||||
rowGap: 1,
|
||||
}))
|
||||
;
|
||||
|
||||
await exportDashboardExcel({
|
||||
fileName: `20${LAST_YEAR}년도 가전 보급률 Dashboard(${sheetName}).xlsx`,
|
||||
sheetName: sheetName,
|
||||
sections: sections,
|
||||
});
|
||||
});
|
||||
return () => registerExcelExporter(null);
|
||||
}, [registerExcelExporter]);
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-6">
|
||||
{SECTIONS.map((spec) => {
|
||||
const bannerKeys = getSectionBannerKeys(spec);
|
||||
|
||||
const columns = buildColumns(spec);
|
||||
const chartData = buildChartData(rows, bannerKeys);
|
||||
|
||||
{sectionRows.map((sectionRow) => {
|
||||
return (
|
||||
useChart ?
|
||||
<LeftChartTable<ServerBannerRow>
|
||||
key={spec.title}
|
||||
title={spec.title}
|
||||
columns={columns}
|
||||
rows={rows}
|
||||
key={sectionRow.specTitle}
|
||||
title={sectionRow.specTitle}
|
||||
columns={sectionRow.columns}
|
||||
rows={sectionRow.rows}
|
||||
signStyle={signStyleGap}
|
||||
chart={
|
||||
<HorizontalBar
|
||||
data={chartData}
|
||||
data={sectionRow.chartData}
|
||||
height="100%"
|
||||
showFocusLabel="none"
|
||||
legend={{ show: false }}
|
||||
grid={GRID_Y_NOT_PADDING}
|
||||
xAxis={{ type: "value", show: false }}
|
||||
yAxis={{ type: "category", data: chartData.categories, show: false }}
|
||||
yAxis={{ type: "category", data: sectionRow.chartData.categories, show: false }}
|
||||
/>
|
||||
}
|
||||
chartCell={{ key: "total", startRowIndex: 1 }}
|
||||
@@ -127,10 +185,10 @@ const BannerSummary = ({ data, useChart }: BannerSummaryProps) => {
|
||||
/>
|
||||
:
|
||||
<DataTable<ServerBannerRow>
|
||||
key={spec.title}
|
||||
title={spec.title}
|
||||
columns={columns}
|
||||
rows={rows}
|
||||
key={sectionRow.specTitle}
|
||||
title={sectionRow.specTitle}
|
||||
columns={sectionRow.columns}
|
||||
rows={sectionRow.rows}
|
||||
signStyle={signStyleGap}
|
||||
/>
|
||||
);
|
||||
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
} from "@/components/lge-dashboard";
|
||||
import BannerButtons from "@/components/lge-dashboard/BannerButtons";
|
||||
import {totalFilters} from "@/config/filter.data";
|
||||
import {useMemo, useState} from "react";
|
||||
import {useEffect, useMemo, useState} from "react";
|
||||
import {BannerGroupKey, CategoryChartMode, ServerBannerRow} from "@/types/lg";
|
||||
import {
|
||||
buildRowLabelSeriesChartData,
|
||||
@@ -17,6 +17,8 @@ import {
|
||||
} from "@/lib/lg-dashboard";
|
||||
import {BANNER_GROUP, BANNER_KEY_MAP, LAST_YEAR} from "@/const/lgConst";
|
||||
import {createDefaultGrid, createDefaultLegend, reverseCategories} from "@/lib/chart-options";
|
||||
import {useLayoutFilter} from "@/components/layout/LayoutFilterContext";
|
||||
import {CategoryTypeValue} from "@/components/layout/CategoryFilter";
|
||||
|
||||
type CategoryByDataProps = {
|
||||
title?: string;
|
||||
@@ -90,7 +92,7 @@ const CategoryByData = ({
|
||||
return isBannerGroupKey(v) ? buildColumns(v) : [];
|
||||
}, [selectedBanner.variable]);
|
||||
|
||||
const tableData = useMemo(() => wrapSampleRow(allTableData).filter((row) => row.year === LAST_YEAR), [allTableData, LAST_YEAR])
|
||||
const tableData = useMemo(() => wrapSampleRow(allTableData).filter((row) => row.year === LAST_YEAR), [allTableData, LAST_YEAR]);
|
||||
|
||||
return (
|
||||
<div>
|
||||
|
||||
@@ -1,54 +1,13 @@
|
||||
import GaugeCardTable from "./GaugeCardTable";
|
||||
import {GaugeColumn} from "@/components/lge-dashboard";
|
||||
import {useMemo} from "react";
|
||||
import {apiLifeStageByProduct} from "@/config/sample.data";
|
||||
import {LifeStageRow} from "@/types/lg";
|
||||
import {asNum, norm} from "@/lib/utils";
|
||||
import {LIFE_STAGE_COLUMNS} from "@/const/lgConst";
|
||||
import {LifeStageGroup} from "@/types/lg";
|
||||
|
||||
const LifeStageDiv = () => {
|
||||
const LIFE_STAGE_COLUMNS: GaugeColumn<LifeStageRow>[] = [
|
||||
{ key: "item", header: "", rowHead: true, renderLabel: (r) => r.item },
|
||||
type lifeStageDivProps = {
|
||||
lifeStageRowsByGroup:LifeStageGroup[];
|
||||
}
|
||||
|
||||
{ key: "total", header: "전체", max: 100, align: "left", cellType:"number"},
|
||||
{ key: "single", header: "미혼", max: 100 , align: "left"},
|
||||
|
||||
{ key: "noKids", header: "무자녀", group: "기혼", max: 100 , align: "left"},
|
||||
{ key: "preschoolKids", header: "미취학", group: "기혼", max: 100 , align: "left"},
|
||||
{ key: "schoolKids", header: "취학자녀", group: "기혼", max: 100 , align: "left"},
|
||||
{ key: "adultKids", header: "성인자녀", group: "기혼", max: 100 , align: "left"},
|
||||
|
||||
{ key: "independentSenior", header: "독립\n시니어", max: 100 , align: "left"},
|
||||
];
|
||||
|
||||
const LIFE_STAGE_GROUPS = [
|
||||
{ title: "대형가전 군", items: ["냉장고", "세탁기", "건조기", "에어컨", "TV", "김치 냉장고", "식기세척기", "의류 관리기"] },
|
||||
{ title: "소형가전 군", items: ["청소기", "공기 청정기", "정수기"] },
|
||||
{ title: "신가전 군", items: ["로봇 청소기", "음식물처리기"] },
|
||||
] as const;
|
||||
|
||||
const lifeStageRowsByGroup = useMemo(() => {
|
||||
const pick = (label: string) => apiLifeStageByProduct.find((r) => norm(r.rowLabel) === norm(label));
|
||||
|
||||
return LIFE_STAGE_GROUPS.map((g) => {
|
||||
const rows: LifeStageRow[] = g.items.map((label) => {
|
||||
const r = pick(label);
|
||||
|
||||
return {
|
||||
item: label,
|
||||
total: asNum((r as any)?.total), // 서버에 all이 없으면 null로 남음
|
||||
single: asNum((r as any)?.single),
|
||||
noKids: asNum((r as any)?.noKids),
|
||||
preschoolKids: asNum((r as any)?.preschoolKids),
|
||||
schoolKids: asNum((r as any)?.schoolKids),
|
||||
adultKids: asNum((r as any)?.adultKids),
|
||||
independentSenior: asNum((r as any)?.independentSenior),
|
||||
};
|
||||
});
|
||||
|
||||
return { title: g.title, rows };
|
||||
});
|
||||
}, []);
|
||||
|
||||
const LifeStageDiv = ({lifeStageRowsByGroup}:lifeStageDivProps) => {
|
||||
return (
|
||||
<div className="mt-6">
|
||||
<div className="flex justify-end gap-6 text-xs text-muted-foreground mb-2">
|
||||
|
||||
@@ -1,18 +1,20 @@
|
||||
'use client'
|
||||
|
||||
import {useMemo} from "react";
|
||||
import {useLayoutFilter} from "@/components/layout/LayoutFilterContext";
|
||||
import {useEffect, useMemo} from "react";
|
||||
import {CategoryByData} from "@/components/lge-dashboard";
|
||||
import {apiBrandShareByYear} from "@/config/sample.data";
|
||||
import {PageData, ServerBannerRow} from "@/types/lg";
|
||||
import {buildGapRow} from "@/lib/lg-dashboard";
|
||||
import {BANNER_GROUP, BANNER_KEY_MAP, LAST_YEAR, YEARS} from "@/const/lgConst";
|
||||
import {useLayoutFilter} from "@/components/layout/LayoutFilterContext";
|
||||
import {CategoryTypeValue} from "@/components/layout/CategoryFilter";
|
||||
import {buildHeader_Banner, exportDashboardExcel, Section} from "@/lib/lg-export-excel";
|
||||
|
||||
const Brand = () => {
|
||||
const { filterValue } = useLayoutFilter();
|
||||
|
||||
const {filterValue, registerExcelExporter} = useLayoutFilter();
|
||||
const tableDataArray = useMemo<PageData<ServerBannerRow>[]>(() => {
|
||||
const cleaned = apiBrandShareByYear.filter(
|
||||
(r) => !(r.year === 26 && r.rowLabel === "gap")
|
||||
(r) => !(r.year === LAST_YEAR && r.rowLabel === "gap")
|
||||
);
|
||||
|
||||
const gapRow = buildGapRow(cleaned, 25, 26, "lg", "gap");
|
||||
@@ -21,7 +23,7 @@ const Brand = () => {
|
||||
|
||||
if (gapRow) {
|
||||
const insertIdx = cleaned.findIndex(
|
||||
(r) => r.year === 26 && r.rowLabel === "lg"
|
||||
(r) => r.year === LAST_YEAR && r.rowLabel === "lg"
|
||||
);
|
||||
|
||||
if (insertIdx >= 0) {
|
||||
@@ -42,6 +44,33 @@ const Brand = () => {
|
||||
];
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
registerExcelExporter(async (payload) => {
|
||||
|
||||
const sheetName = `${filterValue.product}_${(filterValue.type as CategoryTypeValue).label}_브랜드`
|
||||
const h3 = buildHeader_Banner(BANNER_GROUP, BANNER_KEY_MAP);
|
||||
|
||||
type AnyRow = Record<string, any>;
|
||||
const sections: Section<AnyRow>[] = tableDataArray.flatMap((tableData) => {
|
||||
const years = [YEARS.at(-1), YEARS.at(-2)];
|
||||
|
||||
return years.map((year) => ({
|
||||
title: `${tableData.title}_${year}년`,
|
||||
header: h3,
|
||||
rows: tableData.data.filter((d) => d.year === year) as AnyRow[],
|
||||
rowGap: 1,
|
||||
}));
|
||||
});
|
||||
|
||||
await exportDashboardExcel({
|
||||
fileName: `20${LAST_YEAR}년도 가전 보급률 Dashboard(${sheetName}).xlsx`,
|
||||
sheetName: sheetName,
|
||||
sections: sections,
|
||||
});
|
||||
});
|
||||
return () => registerExcelExporter(null);
|
||||
}, [registerExcelExporter]);
|
||||
|
||||
return (
|
||||
<div>
|
||||
{tableDataArray.map((tableData) => (
|
||||
|
||||
@@ -1,20 +1,50 @@
|
||||
'use client'
|
||||
|
||||
import {useLayoutFilter} from "@/components/layout/LayoutFilterContext";
|
||||
import {useMemo} from "react";
|
||||
import {useEffect, useMemo} from "react";
|
||||
import {PageData, ServerBannerRow} from "@/types/lg";
|
||||
import {apiOwnershipPathByYear, apiOwnershipTriggerByYear} from "@/config/sample.data";
|
||||
import {CategoryByData} from "@/components/lge-dashboard";
|
||||
import {BANNER_GROUP, BANNER_KEY_MAP, LAST_YEAR, YEARS} from "@/const/lgConst";
|
||||
import {CategoryTypeValue} from "@/components/layout/CategoryFilter";
|
||||
import {buildHeader_Banner, exportDashboardExcel, Section} from "@/lib/lg-export-excel";
|
||||
|
||||
const OwnershipPath = () => {
|
||||
const { filterValue } = useLayoutFilter();
|
||||
const { filterValue, registerExcelExporter } = useLayoutFilter();
|
||||
console.log(filterValue);
|
||||
|
||||
const tableDataArray = useMemo<PageData<ServerBannerRow>[]>(() => [
|
||||
{title: "보유 경로", chartMode:"reverseStack", data: apiOwnershipPathByYear.filter(r => !(r.year === 26 && r.rowLabel === "gap"))},
|
||||
{title: "구입 계기", chartMode:"horizontal", data: apiOwnershipTriggerByYear.filter(r => !(r.year === 26 && r.rowLabel === "gap"))},
|
||||
{title: "보유 경로", chartMode:"reverseStack", data: apiOwnershipPathByYear.filter(r => !(r.year === LAST_YEAR && r.rowLabel === "gap"))},
|
||||
{title: "구입 계기", chartMode:"horizontal", data: apiOwnershipTriggerByYear.filter(r => !(r.year === LAST_YEAR && r.rowLabel === "gap"))},
|
||||
], []);
|
||||
|
||||
useEffect(() => {
|
||||
registerExcelExporter(async (payload) => {
|
||||
|
||||
const sheetName = `${filterValue.product}_${(filterValue.type as CategoryTypeValue).label}_보유 경로`
|
||||
const h3 = buildHeader_Banner(BANNER_GROUP, BANNER_KEY_MAP);
|
||||
|
||||
type AnyRow = Record<string, any>;
|
||||
const sections: Section<AnyRow>[] = tableDataArray.flatMap((tableData) => {
|
||||
const years = [YEARS.at(-1), YEARS.at(-2)];
|
||||
|
||||
return years.map((year) => ({
|
||||
title: `${tableData.title}_${year}년`,
|
||||
header: h3,
|
||||
rows: tableData.data.filter((d) => d.year === year) as AnyRow[],
|
||||
rowGap: 1,
|
||||
}));
|
||||
});
|
||||
|
||||
await exportDashboardExcel({
|
||||
fileName: `20${LAST_YEAR}년도 가전 보급률 Dashboard(${sheetName}).xlsx`,
|
||||
sheetName: sheetName,
|
||||
sections: sections,
|
||||
});
|
||||
});
|
||||
return () => registerExcelExporter(null);
|
||||
}, [registerExcelExporter]);
|
||||
|
||||
return (
|
||||
<div>
|
||||
{tableDataArray.map((tableData) => (
|
||||
|
||||
@@ -1,19 +1,49 @@
|
||||
'use client'
|
||||
|
||||
import {useLayoutFilter} from "@/components/layout/LayoutFilterContext";
|
||||
import {apiOwnershipPathByYear, apiOwnershipTriggerByYear, apiPaymentMethodByYear} from "@/config/sample.data";
|
||||
import {useMemo} from "react";
|
||||
import {apiPaymentMethodByYear} from "@/config/sample.data";
|
||||
import {useEffect, useMemo} from "react";
|
||||
import {PageData, ServerBannerRow} from "@/types/lg";
|
||||
import {CategoryByData} from "@/components/lge-dashboard";
|
||||
import {BANNER_GROUP, BANNER_KEY_MAP, LAST_YEAR, YEARS} from "@/const/lgConst";
|
||||
import {CategoryTypeValue} from "@/components/layout/CategoryFilter";
|
||||
import {buildHeader_Banner, exportDashboardExcel, Section} from "@/lib/lg-export-excel";
|
||||
|
||||
const PaymentMethod = () => {
|
||||
const { filterValue } = useLayoutFilter();
|
||||
const { filterValue, registerExcelExporter } = useLayoutFilter();
|
||||
console.log(filterValue);
|
||||
|
||||
const tableDataArray = useMemo<PageData<ServerBannerRow>[]>(() => [
|
||||
{title: "구매 형식", chartMode:"reverseStack", data: apiPaymentMethodByYear.filter(r => !(r.year === 26 && r.rowLabel === "gap"))},
|
||||
{title: "구매 형식", chartMode:"reverseStack", data: apiPaymentMethodByYear.filter(r => !(r.year === LAST_YEAR && r.rowLabel === "gap"))},
|
||||
], []);
|
||||
|
||||
useEffect(() => {
|
||||
registerExcelExporter(async (payload) => {
|
||||
|
||||
const sheetName = `${filterValue.product}_${(filterValue.type as CategoryTypeValue).label}_구매 형식`
|
||||
const h3 = buildHeader_Banner(BANNER_GROUP, BANNER_KEY_MAP);
|
||||
|
||||
type AnyRow = Record<string, any>;
|
||||
const sections: Section<AnyRow>[] = tableDataArray.flatMap((tableData) => {
|
||||
const years = [YEARS.at(-1), YEARS.at(-2)];
|
||||
|
||||
return years.map((year) => ({
|
||||
title: `${tableData.title}_${year}년`,
|
||||
header: h3,
|
||||
rows: tableData.data.filter((d) => d.year === year) as AnyRow[],
|
||||
rowGap: 1,
|
||||
}));
|
||||
});
|
||||
|
||||
await exportDashboardExcel({
|
||||
fileName: `20${LAST_YEAR}년도 가전 보급률 Dashboard(${sheetName}).xlsx`,
|
||||
sheetName: sheetName,
|
||||
sections: sections,
|
||||
});
|
||||
});
|
||||
return () => registerExcelExporter(null);
|
||||
}, [registerExcelExporter]);
|
||||
|
||||
return (
|
||||
<div>
|
||||
{tableDataArray.map((tableData) => (
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import {useLayoutFilter} from "@/components/layout/LayoutFilterContext";
|
||||
import BannerSummary from "@/components/lge-dashboard/combo/BannerSummary";
|
||||
import { useMemo } from "react";
|
||||
import {useMemo} from "react";
|
||||
import {ServerBannerRow} from "@/types/lg";
|
||||
import {apiOwnershipSummary, apiPurchaseRateKpis} from "@/config/sample.data";
|
||||
|
||||
|
||||
@@ -1,20 +1,50 @@
|
||||
'use client'
|
||||
|
||||
import {useLayoutFilter} from "@/components/layout/LayoutFilterContext";
|
||||
import {useMemo} from "react";
|
||||
import {useEffect, useMemo} from "react";
|
||||
import {PageData, ServerBannerRow} from "@/types/lg";
|
||||
import { apiOwnershipPathByYear, apiOwnershipTriggerByYear} from "@/config/sample.data";
|
||||
import {CategoryByData} from "@/components/lge-dashboard";
|
||||
import {BANNER_GROUP, BANNER_KEY_MAP, LAST_YEAR, YEARS} from "@/const/lgConst";
|
||||
import {CategoryTypeValue} from "@/components/layout/CategoryFilter";
|
||||
import {buildHeader_Banner, exportDashboardExcel, Section} from "@/lib/lg-export-excel";
|
||||
|
||||
const PurchaseBehavior = () => {
|
||||
const { filterValue } = useLayoutFilter();
|
||||
const { filterValue, registerExcelExporter } = useLayoutFilter();
|
||||
console.log(filterValue);
|
||||
|
||||
const tableDataArray = useMemo<PageData<ServerBannerRow>[]>(() => [
|
||||
{title: "보유 경로", chartMode:"horizontal", data: apiOwnershipPathByYear.filter(r => !(r.year === 26 && r.rowLabel === "gap"))},
|
||||
{title: "구입 계기", chartMode:"horizontal", data: apiOwnershipTriggerByYear.filter(r => !(r.year === 26 && r.rowLabel === "gap"))},
|
||||
{title: "보유 경로", chartMode:"horizontal", data: apiOwnershipPathByYear.filter(r => !(r.year === LAST_YEAR && r.rowLabel === "gap"))},
|
||||
{title: "구입 계기", chartMode:"horizontal", data: apiOwnershipTriggerByYear.filter(r => !(r.year === LAST_YEAR && r.rowLabel === "gap"))},
|
||||
], []);
|
||||
|
||||
useEffect(() => {
|
||||
registerExcelExporter(async (payload) => {
|
||||
|
||||
const sheetName = `${filterValue.product}_${(filterValue.type as CategoryTypeValue).label}_구입 행태`
|
||||
const h3 = buildHeader_Banner(BANNER_GROUP, BANNER_KEY_MAP);
|
||||
|
||||
type AnyRow = Record<string, any>;
|
||||
const sections: Section<AnyRow>[] = tableDataArray.flatMap((tableData) => {
|
||||
const years = [YEARS.at(-1), YEARS.at(-2)];
|
||||
|
||||
return years.map((year) => ({
|
||||
title: `${tableData.title}_${year}년`,
|
||||
header: h3,
|
||||
rows: tableData.data.filter((d) => d.year === year) as AnyRow[],
|
||||
rowGap: 1,
|
||||
}));
|
||||
});
|
||||
|
||||
await exportDashboardExcel({
|
||||
fileName: `20${LAST_YEAR}년도 가전 보급률 Dashboard(${sheetName}).xlsx`,
|
||||
sheetName: sheetName,
|
||||
sections: sections,
|
||||
});
|
||||
});
|
||||
return () => registerExcelExporter(null);
|
||||
}, [registerExcelExporter]);
|
||||
|
||||
return (
|
||||
<div>
|
||||
{tableDataArray.map((tableData) => (
|
||||
|
||||
@@ -2,33 +2,61 @@
|
||||
|
||||
import {useLayoutFilter} from "@/components/layout/LayoutFilterContext";
|
||||
import {
|
||||
apiOwnershipPathByYear,
|
||||
apiOwnershipTriggerByYear,
|
||||
apiPurchaseChannelByYear,
|
||||
apiPurchaseChannelSummaryByYear
|
||||
} from "@/config/sample.data";
|
||||
import {useMemo} from "react";
|
||||
import {useEffect, useMemo} from "react";
|
||||
import {PageData, ServerBannerRow} from "@/types/lg";
|
||||
import {CategoryByData} from "@/components/lge-dashboard";
|
||||
import {BANNER_GROUP, BANNER_KEY_MAP, LAST_YEAR, YEARS} from "@/const/lgConst";
|
||||
import {CategoryTypeValue} from "@/components/layout/CategoryFilter";
|
||||
import {buildHeader_Banner, exportDashboardExcel, Section} from "@/lib/lg-export-excel";
|
||||
|
||||
const PurchaseChannel = () => {
|
||||
const { filterValue } = useLayoutFilter();
|
||||
const { filterValue, registerExcelExporter } = useLayoutFilter();
|
||||
console.log(filterValue);
|
||||
|
||||
const tableDataArray = useMemo<PageData<ServerBannerRow>[]>(() => [
|
||||
{
|
||||
title: "구매 채널(온/오프라인)",
|
||||
chartMode: "reverseStack",
|
||||
data: apiPurchaseChannelSummaryByYear.filter(r => !(r.year === 26 && r.rowLabel === "gap")),
|
||||
data: apiPurchaseChannelSummaryByYear.filter(r => !(r.year === LAST_YEAR && r.rowLabel === "gap")),
|
||||
},
|
||||
{
|
||||
title: "구매 채널(상세)",
|
||||
chartMode: "horizontal",
|
||||
data: apiPurchaseChannelByYear.filter(r => !(r.year === 26 && r.rowLabel === "gap")),
|
||||
data: apiPurchaseChannelByYear.filter(r => !(r.year === LAST_YEAR && r.rowLabel === "gap")),
|
||||
chartHeight: 550,
|
||||
},
|
||||
], []);
|
||||
|
||||
useEffect(() => {
|
||||
registerExcelExporter(async (payload) => {
|
||||
|
||||
const sheetName = `${filterValue.product}_${(filterValue.type as CategoryTypeValue).label}_구매 채널`
|
||||
const h3 = buildHeader_Banner(BANNER_GROUP, BANNER_KEY_MAP);
|
||||
|
||||
type AnyRow = Record<string, any>;
|
||||
const sections: Section<AnyRow>[] = tableDataArray.flatMap((tableData) => {
|
||||
const years = [YEARS.at(-1), YEARS.at(-2)];
|
||||
|
||||
return years.map((year) => ({
|
||||
title: `${tableData.title}_${year}년`,
|
||||
header: h3,
|
||||
rows: tableData.data.filter((d) => d.year === year) as AnyRow[],
|
||||
rowGap: 1,
|
||||
}));
|
||||
});
|
||||
|
||||
await exportDashboardExcel({
|
||||
fileName: `20${LAST_YEAR}년도 가전 보급률 Dashboard(${sheetName}).xlsx`,
|
||||
sheetName: sheetName,
|
||||
sections: sections,
|
||||
});
|
||||
});
|
||||
return () => registerExcelExporter(null);
|
||||
}, [registerExcelExporter]);
|
||||
|
||||
return (
|
||||
<div>
|
||||
{tableDataArray.map((tableData) => (
|
||||
|
||||
@@ -1,23 +1,53 @@
|
||||
'use client'
|
||||
|
||||
import {useLayoutFilter} from "@/components/layout/LayoutFilterContext";
|
||||
import {useMemo} from "react";
|
||||
import {useEffect, useMemo} from "react";
|
||||
import {PageData, ServerBannerRow} from "@/types/lg";
|
||||
import {apiFridgeDoorTypeByYear} from "@/config/sample.data";
|
||||
import {CategoryByData} from "@/components/lge-dashboard";
|
||||
import {BANNER_GROUP, BANNER_KEY_MAP, LAST_YEAR, YEARS} from "@/const/lgConst";
|
||||
import {CategoryTypeValue} from "@/components/layout/CategoryFilter";
|
||||
import {buildHeader_Banner, exportDashboardExcel, Section} from "@/lib/lg-export-excel";
|
||||
|
||||
const TypeSpec = () => {
|
||||
const { filterValue } = useLayoutFilter();
|
||||
const { filterValue, registerExcelExporter } = useLayoutFilter();
|
||||
console.log(filterValue);
|
||||
|
||||
const tableDataArray = useMemo<PageData<ServerBannerRow>[]>(() => [
|
||||
{
|
||||
title: "타입",
|
||||
chartMode: "horizontal",
|
||||
data: apiFridgeDoorTypeByYear.filter(r => !(r.year === 26 && r.rowLabel === "gap")),
|
||||
data: apiFridgeDoorTypeByYear.filter(r => !(r.year === LAST_YEAR && r.rowLabel === "gap")),
|
||||
},
|
||||
], []);
|
||||
|
||||
useEffect(() => {
|
||||
registerExcelExporter(async (payload) => {
|
||||
|
||||
const sheetName = `${filterValue.product}_${(filterValue.type as CategoryTypeValue).label}_타입/스펙`
|
||||
const h3 = buildHeader_Banner(BANNER_GROUP, BANNER_KEY_MAP);
|
||||
|
||||
type AnyRow = Record<string, any>;
|
||||
const sections: Section<AnyRow>[] = tableDataArray.flatMap((tableData) => {
|
||||
const years = [YEARS.at(-1), YEARS.at(-2)];
|
||||
|
||||
return years.map((year) => ({
|
||||
title: `${tableData.title}_${year}년`,
|
||||
header: h3,
|
||||
rows: tableData.data.filter((d) => d.year === year) as AnyRow[],
|
||||
rowGap: 1,
|
||||
}));
|
||||
});
|
||||
|
||||
await exportDashboardExcel({
|
||||
fileName: `20${LAST_YEAR}년도 가전 보급률 Dashboard(${sheetName}).xlsx`,
|
||||
sheetName: sheetName,
|
||||
sections: sections,
|
||||
});
|
||||
});
|
||||
return () => registerExcelExporter(null);
|
||||
}, [registerExcelExporter]);
|
||||
|
||||
return (
|
||||
<div>
|
||||
{tableDataArray.map((tableData) => (
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import { useMemo } from "react";
|
||||
import React, { useMemo } from "react";
|
||||
import { cn, parseNumber } from "@/lib/utils";
|
||||
import {GaugeColumn} from "../types";
|
||||
|
||||
@@ -37,23 +37,47 @@ const GaugeTable = <T extends Record<string, unknown>>({
|
||||
cellHeight = 26,
|
||||
valueFormatter,
|
||||
}: Props<T>) => {
|
||||
const hasGroup = columns.some((c) => !!c.group);
|
||||
const hasGroup = columns.some((c) => !!c.group) || columns.some((c) => c.headRowSpan === 2);
|
||||
|
||||
const groupCells = useMemo(() => {
|
||||
if (!hasGroup) return [];
|
||||
const res: { label: string; span: number }[] = [];
|
||||
type GroupCell =
|
||||
| { kind: "rowspan"; label: string; colSpan: 1; rowSpan: 2; className?: string }
|
||||
| { kind: "group"; label: string; colSpan: number; rowSpan: 1; className?: string }
|
||||
| { kind: "blank"; label: string; colSpan: 1; rowSpan: 1; className?: string };
|
||||
|
||||
if (!hasGroup) return [] as GroupCell[];
|
||||
|
||||
const res: GroupCell[] = [];
|
||||
let i = 0;
|
||||
|
||||
while (i < columns.length) {
|
||||
const g = columns[i].group ?? "";
|
||||
const c = columns[i];
|
||||
|
||||
if (c.headRowSpan === 2) {
|
||||
res.push({ kind: "rowspan", label: c.header, colSpan: 1, rowSpan: 2 });
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
|
||||
const g = c.group;
|
||||
if (!g) {
|
||||
// group 미지정: 1칸짜리 blank group 셀
|
||||
res.push({ kind: "blank", label: "", colSpan: 1, rowSpan: 1 });
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
|
||||
// 같은 group 연속 구간 colSpan
|
||||
let span = 1;
|
||||
let j = i + 1;
|
||||
while (j < columns.length && (columns[j].group ?? "") === g) {
|
||||
while (j < columns.length && columns[j].headRowSpan !== 2 && columns[j].group === g) {
|
||||
span++;
|
||||
j++;
|
||||
}
|
||||
res.push({ label: g, span });
|
||||
res.push({ kind: "group", label: g, colSpan: span, rowSpan: 1 });
|
||||
i = j;
|
||||
}
|
||||
|
||||
return res;
|
||||
}, [columns, hasGroup]);
|
||||
|
||||
@@ -80,14 +104,19 @@ const GaugeTable = <T extends Record<string, unknown>>({
|
||||
{hasGroup && (
|
||||
<tr className="lg-table__group">
|
||||
{groupCells.map((g, idx) => (
|
||||
<th key={`${g.label}-${idx}`} colSpan={g.span}>
|
||||
<th
|
||||
key={`${g.kind}-${g.label}-${idx}`}
|
||||
colSpan={g.colSpan}
|
||||
rowSpan={g.rowSpan}
|
||||
className={g.className}
|
||||
>
|
||||
{g.label}
|
||||
</th>
|
||||
))}
|
||||
</tr>
|
||||
)}
|
||||
<tr className={hasGroup ? "lg-table__subhead" : undefined}>
|
||||
{columns.map((c) => (
|
||||
{columns.filter((c) => c.headRowSpan !== 2).map((c) => (
|
||||
<th key={String(c.key)}>
|
||||
{c.header}
|
||||
</th>
|
||||
@@ -104,8 +133,8 @@ const GaugeTable = <T extends Record<string, unknown>>({
|
||||
|
||||
if (c.rowHead) {
|
||||
const raw = row[c.key];
|
||||
const label = c.renderLabel
|
||||
? c.renderLabel(row)
|
||||
const label = c.render
|
||||
? c.render(row)
|
||||
: raw === null || raw === undefined
|
||||
? ""
|
||||
: typeof raw === "string" || typeof raw === "number"
|
||||
|
||||
@@ -34,7 +34,7 @@ export type GroupedStackBarData = {
|
||||
|
||||
export type GroupedOverlayBarData = {
|
||||
categories: string[]; // 제품
|
||||
years: number[]; // 예: [24,25,26]
|
||||
years: string[]; // 예: [24,25,26]
|
||||
totalName?: string; // default: "전체"
|
||||
focusName?: string; // default: "LG"
|
||||
total: Array<Array<number | null>>; // [yearIndex][categoryIndex]
|
||||
@@ -76,10 +76,13 @@ export type GaugeColumn<T> = {
|
||||
width?: number | string;
|
||||
align?: "left" | "center" | "right";
|
||||
group?: string;
|
||||
groupKey?:string;// 2단 헤더 그룹
|
||||
|
||||
headRowSpan?: 1 | 2;
|
||||
rowHead?: boolean;
|
||||
/** 게이지 최대값 기준(기본 100) */
|
||||
max?: number;
|
||||
renderLabel?: (row: T) => React.ReactNode; // rowHead에 쓰기 좋음
|
||||
render?: (row: T) => React.ReactNode; // rowHead에 쓰기 좋음
|
||||
cellType?: "gauge" | "number"; // default: "gauge"
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user