260205_05_ENH: 1차 lg 수정 요청사항 반영

This commit is contained in:
2026-02-05 16:54:55 +09:00
parent 8c015bd443
commit 84675b77b3
25 changed files with 452 additions and 316 deletions

View File

@@ -1,12 +1,13 @@
"use client";
import { CategoryTargetData, CategoryTargetType } from "@/config/filter.types";
import {CategoryTargetData, CategoryTargetType, TotalFilterItem} from "@/config/filter.types";
import {categoryTarget, categoryTargetType} from "@/config/filter.data";
import { ChevronRight } from "lucide-react";
import { useMemo } from "react";
import {useCallback, useMemo} from "react";
import { cn } from "@/lib/utils";
import { Button } from "@/components/ui/button";
import {ProductsFilterItem} from "@/types/lg";
import {YEARS} from "@/const/lgConst";
export type CategoryTypeValue = {
label: string;
@@ -15,6 +16,7 @@ export type CategoryTypeValue = {
export type CategoryFilterValue = {
product: string;
year: string;
type: CategoryTypeValue
target: CategoryTargetData;
};
@@ -26,111 +28,175 @@ type CategoryFilterProps = {
className?: string;
};
type Option = { key: string; label: string; value: string | CategoryTypeValue | CategoryTargetData };
type RowDef = {
id: "year" | "product" | "type" | "target";
title: string;
options: Option[];
isActive: (v: Option["value"]) => boolean;
onSelect: (v: Option["value"]) => void;
};
function FilterLine({ title, options, isActive, onSelect }: Omit<RowDef, "id">) {
return (
<div className="flex min-w-0">
<div className="flex w-[140px] shrink-0 items-center gap-2 px-3 py-2">
<ChevronRight className="h-4 w-4 text-gray-700" />
<span className="text-sm font-semibold text-gray-900 content-text-sm">
{title}
</span>
</div>
<div className="min-w-0 flex-1 overflow-x-auto px-2 py-2">
<div className="flex w-max items-center gap-1 whitespace-nowrap">
{options.map((opt) => {
const active = isActive(opt.value);
return (
<Button
key={opt.key}
type="button"
variant={active ? "default" : "secondary"}
onClick={() => onSelect(opt.value)}
className="h-8 shrink-0 rounded-sm px-3 text-sm font-semibold content-text-base"
>
{opt.label}
</Button>
);
})}
</div>
</div>
</div>
);
}
const CategoryFilter = ({ filterItems, value, onChange, className }: CategoryFilterProps) => {
const currentTargetItem = useMemo(() => {
return categoryTarget.find((item) => item.type.includes(value.type.value));
}, [value.type]);
}, [value.type.value]);
const handlePick = (
key: keyof CategoryFilterValue,
v: string | CategoryTypeValue | CategoryTargetData
) => {
if (value[key] === v) return;
const next: CategoryFilterValue = { ...value, [key]: v } as CategoryFilterValue;
// type 비교는 객체참조가 아니라 value로 비교해야 함
const handlePick = useCallback(
(key: keyof CategoryFilterValue, v: string | CategoryTypeValue | CategoryTargetData) => {
// same check
if (key === "type" && typeof v === "object" && "value" in v) {
if (value.type.value === v.value) return;
if (key === "type" && typeof v === "object" && v.value !== value.type.value) {
const nextItem = categoryTarget.find((item) => item.type.includes(v.value));
const firstTarget = nextItem?.children?.[0]?.target;
if (firstTarget) next.target = firstTarget;
}
const nextItem = categoryTarget.find((item) => item.type.includes(v.value));
const firstTarget = nextItem?.children?.[0]?.target;
onChange(next);
};
onChange({
...value,
type: v,
target: (firstTarget ?? value.target) as CategoryTargetData,
});
return;
}
if (key !== "type") {
// string/primitive 비교
if ((value as any)[key] === v) return;
onChange({ ...value, [key]: v } as CategoryFilterValue);
}
},
[value, onChange]
);
const rowDefs = useMemo<RowDef[]>(() => {
const yearRow:RowDef = {
id:"year",
title: "연도",
options:(YEARS).map((y) => ({
key:y,
label:`20${y}년`,
value:y,
})),
isActive: (v) => value.year === v,
onSelect: (v) => handlePick("year", v as string),
};
const productRow: RowDef = {
id: "product",
title: "제품",
options: (filterItems.items ?? []).map((p) => ({
key: p,
label: p,
value: p,
})),
isActive: (v) => value.product === v,
onSelect: (v) => handlePick("product", v as string),
};
const typeRow: RowDef = {
id: "type",
title: "기준",
options: categoryTargetType.map((t) => ({
key: t.label,
label: t.label,
value: { label: t.label, value: t.value },
})),
isActive: (v) => {
const vv = v as CategoryTypeValue;
return value.type.value === vv.value;
},
onSelect: (v) => handlePick("type", v as CategoryTypeValue),
};
const targetRow: RowDef = {
id: "target",
title: "데이터",
options: (currentTargetItem?.children ?? []).map((c) => ({
key: String(c.target),
label: c.label,
value: c.target,
})),
isActive: (v) => value.target === v,
onSelect: (v) => handlePick("target", v as CategoryTargetData),
};
// 여기 순서만 바꾸면 배치도 같이 바뀜 (left: 앞쪽 half, right: 뒤쪽 half)
return [yearRow, productRow, typeRow, targetRow];
}, [YEARS, filterItems.items, currentTargetItem, value, handlePick]);
const cells = useMemo(() => {
const half = Math.ceil(rowDefs.length / 2); // 3개면 2개(left) + 1개(right)
const maxRows = half;
return rowDefs.map((def, i) => {
const col = i < half ? 0 : 1; // 0:left, 1:right
const row = i < half ? i : i - half;
return { def, col, row, maxRows };
});
}, [rowDefs]);
return (
<div className={cn("w-full border border-gray-300 bg-white/70 backdrop-blur-sm", className)}>
{/* 제품 (1줄 나열) */}
<div className="flex min-w-0 border-b border-gray-200">
<div className="flex w-[140px] shrink-0 items-center gap-2 px-3 py-2">
<ChevronRight className="h-4 w-4 text-gray-700" />
<span className="text-sm font-semibold text-gray-900 content-text-sm">제품</span>
</div>
<div className="min-w-0 flex-1 overflow-x-auto px-2 py-2">
<div className="flex w-max items-center gap-1 whitespace-nowrap">
{filterItems.items.map((p) => {
const active = value.product === p;
return (
<Button
key={p}
type="button"
variant={active ? "default" : "secondary"}
onClick={() => handlePick("product", p)}
className="h-6 shrink-0 rounded-sm px-3 text-sm font-semibold content-text-sm"
>
{p}
</Button>
);
})}
</div>
</div>
</div>
{/* 기준 (1줄 나열) */}
<div className="flex min-w-0 border-b border-gray-200">
<div className="flex w-[140px] shrink-0 items-center gap-2 px-3 py-2">
<ChevronRight className="h-4 w-4 text-gray-700" />
<span className="text-sm font-semibold text-gray-900 content-text-sm">기준</span>
</div>
<div className="min-w-0 flex-1 overflow-x-auto px-2 py-2">
<div className="flex w-max items-center gap-1 whitespace-nowrap">
{categoryTargetType.map((item) => {
const active = value.type.label === item.label;
return (
<Button
key={item.label}
type="button"
variant={active ? "default" : "secondary"}
onClick={() => {
handlePick("type", {label:item.label, value:item.value});
}}
className="h-6 shrink-0 rounded-sm px-3 text-sm font-semibold content-text-sm"
>
{item.label}
</Button>
);
})}
</div>
</div>
</div>
{/* 데이터 (1줄 나열) */}
<div className="flex min-w-0">
<div className="flex w-[140px] shrink-0 items-center gap-2 px-3 py-2">
<ChevronRight className="h-4 w-4 text-gray-700" />
<span className="text-sm font-semibold text-gray-900 content-text-sm">데이터</span>
</div>
<div className="min-w-0 flex-1 overflow-x-auto px-2 py-2">
<div className="flex w-max items-center gap-1 whitespace-nowrap">
{currentTargetItem?.children?.map((child) => {
const active = value.target === child.target;
return (
<Button
key={child.target}
type="button"
variant={active ? "default" : "secondary"}
onClick={() => handlePick("target", child.target)}
className="h-6 shrink-0 rounded-sm px-3 text-sm font-semibold content-text-sm"
>
{child.label}
</Button>
);
})}
</div>
</div>
<div className="grid grid-cols-2">
{cells.map(({ def, col, row, maxRows }) => {
const showRowDivider = row < maxRows - 1; // 같은 rowIndex 기준으로 좌/우 라인 맞춤
return (
<div
key={def.id}
style={{
gridColumnStart: col + 1,
gridRowStart: row + 1,
}}
className={cn(
"min-w-0",
showRowDivider && "border-b border-gray-200",
col === 1 && "border-l-4 border-gray-300"
)}
>
<FilterLine
title={def.title}
options={def.options}
isActive={def.isActive}
onSelect={def.onSelect}
/>
</div>
);
})}
</div>
</div>
);

View File

@@ -5,8 +5,8 @@ import Image from "next/image";
import {topMenus} from "@/config/menu.data";
import {Button} from "@/components/ui/button";
import {LogOut} from "lucide-react";
import {DASHBOARD_YEAR} from "@/const/commonConst";
import {cn} from "@/lib/utils";
import {SITE_TITLE} from "@/const/lgConst";
interface HeaderProps {
activeTopId: string;
@@ -70,7 +70,7 @@ const Header = ({
</nav>
</div>
<div className="flex justify-between items-center">
<h1 className="font-bold content-text-2xl text-header-color">{DASHBOARD_YEAR}년도 가전보급률 Dashboard</h1>
<h1 className="font-bold content-text-2xl text-header-color">{SITE_TITLE}</h1>
</div>
{/* 우측 컨트롤 */}
<div className="flex items-center gap-4">

View File

@@ -13,7 +13,7 @@ import TotalFilter from "./TotalFilter";
import CategoryFilter, {CategoryFilterValue} from "./CategoryFilter";
import ExcelDownloadButton from "./ExcelDownloadButton";
import {LayoutFilterProvider} from "./LayoutFilterContext";
import {PRODUCTS_FILTER_ITEM} from "@/const/lgConst";
import {LAST_YEAR, PRODUCTS_FILTER_ITEM} from "@/const/lgConst";
import {ProductsFilterItem} from "@/types/lg";
import {ArrowUp} from "lucide-react";
@@ -38,6 +38,7 @@ export const buildDefaultCategoryValue = (categoryFilterItems: ProductsFilterIte
const initTarget = firstTarget ?? CategoryTargetData.PROFILE;
return {
year: LAST_YEAR,
product: initProduct,
type: initType,
target: initTarget,
@@ -118,73 +119,79 @@ const MainLayout = ({ children }: MainLayoutProps) => {
<LayoutFilterProvider
value={isTotal? { isTotal: true, filterValue: totalValue } : { isTotal: false, filterValue: categoryValue }}
>
<Header
activeTopId={activeTop.id}
onNavigate={movePage}
/>
<div className="flex-1 min-h-0 flex flex-col bg-lg-main-body p-1 pl-6">
<SubMenu
subMenu={subMenus}
activeSubId={activeSub.id}
<Header
activeTopId={activeTop.id}
onNavigate={movePage}
/>
<div className="flex-1 min-h-0 flex flex-col pr-4">
<div className="bg-card lg-tab-content flex-1 min-h-0 flex flex-col overflow-hidden">
<div className="shrink-0 flex items-center justify-between px-2 py-1">
<button
type="button"
onClick={toggleFilter}
className={cn(
"inline-flex items-center gap-2 font-semibold text-gray-900 content-text-sm",
"select-none"
)}
>
필터 <span className="text-sm leading-none">{isFilterOpen ? "▲" : "▼"}</span>
</button>
<ExcelDownloadButton/>
</div>
{isFilterOpen && (
<div className="shrink-0">
{isTotal ? (
<TotalFilter filters={totalFilters} value={totalValue} onChange={setTotalValue} />
) : (
<CategoryFilter filterItems={categoryFilterItems} value={categoryValue} onChange={setCategoryValue} />
)}
</div>
)}
<div className="relative flex-1 min-h-0">
<div
ref={scrollRef}
onScroll={onScrollContent}
className="h-full overflow-auto"
>
<div className="p-3 pb-8">
{children}
</div>
</div>
{showScrollTop && (
<div className="flex-1 min-h-0 flex flex-col bg-lg-main-body p-1 pl-6">
<SubMenu
subMenu={subMenus}
activeSubId={activeSub.id}
onNavigate={movePage}
/>
<div className="flex-1 min-h-0 flex flex-col pr-4">
<div className="bg-card lg-tab-content flex-1 min-h-0 flex flex-col overflow-hidden">
<div className="shrink-0 flex items-center justify-between px-2 py-1">
<div className="flex">
<button
type="button"
onClick={scrollToTop}
aria-label="위로 가기"
onClick={toggleFilter}
className={cn(
"absolute -bottom-2 right-4 z-20",
"h-8 w-8 rounded-full",
"bg-gray-900/80 text-white hover:bg-primary",
"flex items-center justify-center"
"inline-flex items-center gap-2 font-semibold text-gray-900 content-text-sm",
"select-none"
)}
>
<ArrowUp className="h-5 w-5" />
필터 <span className="text-sm leading-none">{isFilterOpen ? "▲" : "▼"}</span>
</button>
{isTotal && (
<div className={"ml-5 content-text-sm"}>
페이지에 대한 설명
</div>
)}
</div>
<ExcelDownloadButton/>
</div>
{isFilterOpen && (
<div className="shrink-0">
{isTotal ? (
<TotalFilter filters={totalFilters} value={totalValue} onChange={setTotalValue} />
) : (
<CategoryFilter filterItems={categoryFilterItems} value={categoryValue} onChange={setCategoryValue} />
)}
</div>
)}
<div className="relative flex-1 min-h-0">
<div
ref={scrollRef}
onScroll={onScrollContent}
className="h-full overflow-auto"
>
<div className="p-3 pb-8">
{children}
</div>
</div>
{showScrollTop && (
<button
type="button"
onClick={scrollToTop}
aria-label="위로 가기"
className={cn(
"absolute -bottom-2 right-4 z-20",
"h-8 w-8 rounded-full",
"bg-gray-900/80 text-white hover:bg-primary",
"flex items-center justify-center"
)}
>
<ArrowUp className="h-5 w-5" />
</button>
)}
</div>
</div>
</div>
</div>
</div>
</LayoutFilterProvider>
</div>
);

View File

@@ -14,13 +14,14 @@ const BannerButtons = ({
onSelectBanner
}: BannerButtonsProps) => {
return (
<div className="flex flex-col gap-2">
<div className="flex flex-col gap-1.5">
<div className="text-center font-bold p-1">구분 필터</div>
{banners.map((banner) => (
<button
key={banner.variable}
onClick={() => onSelectBanner(banner)}
className={`
px-4 py-2 text-sm font-bold rounded-lg transition-colors cursor-pointer
px-4 py-1.5 text-sm font-bold rounded-lg transition-colors cursor-pointer
${
selectedBanner === banner
? "bg-primary text-primary-foreground"

View File

@@ -6,7 +6,7 @@ import {
BANNER_GROUP,
BANNER_KEY_MAP,
GRID_Y_NOT_PADDING,
LAST_YEAR,
SAMPLE_SIZE_NOTICE, SITE_TITLE,
} from "@/const/lgConst";
import {parseNumber} from "@/lib/utils";
import {
@@ -36,11 +36,11 @@ const SEP_R = "lg-table__sep-r";
const getSectionBannerKeys = (spec: SectionSpec): BannerKey[] =>
spec.groupKeys.flatMap((gk) => BANNER_GROUP[gk].keys);
const buildColumns = (spec: SectionSpec): DataColumn<ServerBannerRow>[] => {
const buildColumns = (spec: SectionSpec, selectedYear:string): DataColumn<ServerBannerRow>[] => {
const columns: DataColumn<ServerBannerRow>[] = [
{
key: "rowLabel",
header: "",
header: `20${selectedYear}년`,
headRowSpan: 2,
rowHead: true,
cellClassName: "lg-table__rowhead",
@@ -79,9 +79,10 @@ const buildColumns = (spec: SectionSpec): DataColumn<ServerBannerRow>[] => {
type BannerSummaryProps = {
data: ServerBannerRow[];
useChart: boolean;
useYear: boolean;
};
const BannerSummary = ({ data, useChart }: BannerSummaryProps) => {
const BannerSummary = ({ data, useChart, useYear }: BannerSummaryProps) => {
const {filterValue, registerExcelExporter } = useLayoutFilter();
const buildChartData = (rows: ServerBannerRow[], bannerKeys: BannerKey[]): ChartData => {
@@ -117,10 +118,10 @@ const BannerSummary = ({ data, useChart }: BannerSummaryProps) => {
const specTitle = spec.title;
const bannerKeys = getSectionBannerKeys(spec);
const columns = buildColumns(spec);
const columns = buildColumns(spec, useYear? filterValue.year : "");
// rows가 spec마다 다르면 여기서 가져오도록 구성
const rows = wrapSampleRow(data);
const rows = wrapSampleRow(useYear? data.filter((d) => d.year === filterValue.year) : data);
const chartData = buildChartData(rows, bannerKeys);
return {
@@ -132,7 +133,7 @@ const BannerSummary = ({ data, useChart }: BannerSummaryProps) => {
chartData,
};
});
}, [data]);
}, [data, useYear, filterValue.year]);
useEffect(() => {
registerExcelExporter(async (payload) => {
@@ -150,7 +151,7 @@ const BannerSummary = ({ data, useChart }: BannerSummaryProps) => {
;
await exportDashboardExcel({
fileName: `20${LAST_YEAR}년도 가전 보급률 Dashboard(${sheetName}).xlsx`,
fileName: `${SITE_TITLE}(${sheetName}).xlsx`,
sheetName: sheetName,
sections: sections,
});
@@ -162,35 +163,42 @@ const BannerSummary = ({ data, useChart }: BannerSummaryProps) => {
<div className="flex flex-col gap-6">
{sectionRows.map((sectionRow) => {
return (
useChart ?
<LeftChartTable<ServerBannerRow>
key={sectionRow.specTitle}
title={sectionRow.specTitle}
columns={sectionRow.columns}
rows={sectionRow.rows}
signStyle={signStyleGap}
chart={
<HorizontalBar
data={sectionRow.chartData}
height="100%"
showFocusLabel="none"
legend={{ show: false }}
grid={GRID_Y_NOT_PADDING}
xAxis={{ type: "value", show: false }}
yAxis={{ type: "category", data: sectionRow.chartData.categories, show: false }}
/>
}
chartCell={{ key: "total", startRowIndex: 1 }}
minWidthPx={1200}
/>
:
<DataTable<ServerBannerRow>
key={sectionRow.specTitle}
title={sectionRow.specTitle}
columns={sectionRow.columns}
rows={sectionRow.rows}
signStyle={signStyleGap}
/>
<div key={`div_${sectionRow.specTitle}`}>
{
useChart ?
<LeftChartTable<ServerBannerRow>
key={sectionRow.specTitle}
title={sectionRow.specTitle}
columns={sectionRow.columns}
rows={sectionRow.rows}
signStyle={signStyleGap}
chart={
<HorizontalBar
data={sectionRow.chartData}
height="100%"
showFocusLabel="none"
legend={{ show: false }}
grid={GRID_Y_NOT_PADDING}
xAxis={{ type: "value", show: false }}
yAxis={{ type: "category", data: sectionRow.chartData.categories, show: false }}
/>
}
chartCell={{ key: "total", startRowIndex: 1 }}
minWidthPx={1200}
starUnder30Sample={true}
/>
:
<DataTable<ServerBannerRow>
key={sectionRow.specTitle}
title={sectionRow.specTitle}
columns={sectionRow.columns}
rows={sectionRow.rows}
signStyle={signStyleGap}
starUnder30Sample={true}
/>
}
<div className="float-right content-text-sm">{SAMPLE_SIZE_NOTICE}</div>
</div>
);
})}
</div>

View File

@@ -15,12 +15,11 @@ import {
isBannerGroupKey,
wrapSampleRow
} from "@/lib/lg-dashboard";
import {BANNER_GROUP, BANNER_KEY_MAP, LAST_YEAR} from "@/const/lgConst";
import {BANNER_GROUP, BANNER_KEY_MAP, LAST_YEAR, SAMPLE_SIZE_NOTICE} 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 = {
selectedYear: string;
title?: string;
chartMode: CategoryChartMode;
allTableData: ServerBannerRow[];
@@ -42,6 +41,7 @@ const signStyleGap: SignStyle<ServerBannerRow> = {
};
const CategoryByData = ({
selectedYear,
title,
chartMode,
allTableData,
@@ -51,11 +51,11 @@ const CategoryByData = ({
}: CategoryByDataProps) => {
const [selectedBanner, setSelectedBanner] = useState<bannerType>(banners[0]);
const buildColumns = (groupKey: BannerGroupKey): DataColumn<ServerBannerRow>[] => {
const buildColumns = (groupKey: BannerGroupKey, selectedYear:string): DataColumn<ServerBannerRow>[] => {
const columns: DataColumn<ServerBannerRow>[] = [
{
key: "rowLabel",
header: "",
header: `20${selectedYear}년`,
headRowSpan: 2,
rowHead: true,
cellClassName: "lg-table__rowhead",
@@ -79,20 +79,21 @@ const CategoryByData = ({
const chartData = useMemo(() => {
const excludeRowLabels =["사례수", "gap"];
const chartTargetData = allTableData.filter((row) => row.year === selectedYear || Number(row.year) === Number(selectedYear) - 1);
if(chartMode == "horizontal"){
return reverseCategories(buildYearSeriesChartData(allTableData, {excludeRowLabels}));
return reverseCategories(buildYearSeriesChartData(chartTargetData, {excludeRowLabels}));
}
return buildRowLabelSeriesChartData(allTableData, {excludeRowLabels});
return buildRowLabelSeriesChartData(chartTargetData, {excludeRowLabels});
}, [allTableData, chartMode]);
}, [allTableData, selectedYear, chartMode]);
const tableColumns = useMemo(() => {
const v = selectedBanner.variable;
return isBannerGroupKey(v) ? buildColumns(v) : [];
}, [selectedBanner.variable]);
return isBannerGroupKey(v) ? buildColumns(v, selectedYear) : [];
}, [selectedBanner.variable, selectedYear]);
const tableData = useMemo(() => wrapSampleRow(allTableData).filter((row) => row.year === LAST_YEAR), [allTableData, LAST_YEAR]);
const tableData = useMemo(() => wrapSampleRow(allTableData).filter((row) => row.year === selectedYear), [allTableData, selectedYear]);
return (
<div>
@@ -113,6 +114,7 @@ const CategoryByData = ({
data={chartData}
height={`${chartHeight ?? 340}px`}
showFocusLabel="none"
paletteVarNames={chartData.series.length === 1? ["--chart-1"]: ["--chart-2","--chart-1"]}
/>
}
</div>
@@ -132,9 +134,11 @@ const CategoryByData = ({
signStyle={signStyleGap}
wrapperClassName="border rounded-lg"
fillGreaterThan5={fillGreaterThan5}
starUnder30Sample={true}
/>
</div>
</div>
<div className="float-right content-text-sm">{SAMPLE_SIZE_NOTICE}</div>
</div>
);
};

View File

@@ -5,6 +5,7 @@ import { cn, parseNumber } from "@/lib/utils";
import type { DataColumn, SignStyle } from "../types";
import SectionTitle from "../SectionTitle";
import { TABLE_DIMENSIONS } from "@/const/chartConst";
import {isSampleRow} from "@/lib/lg-dashboard";
type MergedChartCell<T> = {
/** 차트를 삽입할 컬럼 key(해당 컬럼 td는 startRow에서만 렌더되고 rowSpan 적용) */
@@ -32,6 +33,7 @@ type Props<T extends Record<string, unknown>> = {
wrapperClassName?: string;
tableClassName?: string;
minWidthPx?: number;
starUnder30Sample?: boolean;
};
// toNumber는 utils.ts의 parseNumber로 통합됨
@@ -65,6 +67,7 @@ export default function LeftChartTable<T extends Record<string, unknown>>({
wrapperClassName,
tableClassName,
minWidthPx = TABLE_DIMENSIONS.MIN_WIDTH.COMPACT,
starUnder30Sample = true
}: Props<T>) {
const hasGroupHeader = useMemo(
() => columns.some((c) => c.group) || columns.some((c) => c.headRowSpan === 2),
@@ -169,6 +172,7 @@ export default function LeftChartTable<T extends Record<string, unknown>>({
<tbody>
{rows.map((row, ri) => {
const sampleRow = isSampleRow(row.rowLabel as string ?? "");
const isSignRow = signStyle?.rowSelector ? signStyle.rowSelector(row, ri) : false;
return (
@@ -199,7 +203,7 @@ export default function LeftChartTable<T extends Record<string, unknown>>({
? raw
: String(raw);
const n = isSignRow ? parseNumber(raw) : null;
const n = c.numeric ? parseNumber(raw) : null;
const shouldSign = isSignRow && (signStyle?.keys ? signStyle.keys.includes(c.key) : !!c.numeric);
if (c.rowHead) {
@@ -216,13 +220,16 @@ export default function LeftChartTable<T extends Record<string, unknown>>({
}
if (!shouldSign) {
const numContent = c.numeric ? parseNumber(content) ?? 0 : 0;
const isStar = starUnder30Sample && sampleRow && numContent < 30;
return (
<td
key={String(c.key)}
className={cn(c.cellClassName)}
style={c.width ? { width: c.width } : undefined}
>
{content}
{isStar?`${content}*`:content}
</td>
);
}
@@ -236,8 +243,10 @@ export default function LeftChartTable<T extends Record<string, unknown>>({
);
}
const cls = n > 0 ? posCls : n < 0 ? negCls : zeroCls;
const txt = renderSigned(n, { display, showPlus, arrowWithNumber, zeroText });
return (
<td key={String(c.key)} className={cn(c.cellClassName, cls)}>
{txt}

View File

@@ -5,44 +5,17 @@ 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 {BANNER_GROUP, BANNER_KEY_MAP, SITE_TITLE, 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, registerExcelExporter} = useLayoutFilter();
const tableDataArray = useMemo<PageData<ServerBannerRow>[]>(() => {
const cleaned = apiBrandShareByYear.filter(
(r) => !(r.year === LAST_YEAR && r.rowLabel === "gap")
);
const gapRow = buildGapRow(cleaned, 25, 26, "lg", "gap");
let finalData = cleaned;
if (gapRow) {
const insertIdx = cleaned.findIndex(
(r) => r.year === LAST_YEAR && r.rowLabel === "lg"
);
if (insertIdx >= 0) {
finalData = [
...cleaned.slice(0, insertIdx + 1),
gapRow,
...cleaned.slice(insertIdx + 1),
];
}
}
return [
{
title: "브랜드",
chartMode: "reverseStack",
data: finalData,
},
];
}, []);
const tableDataArray = useMemo<PageData<ServerBannerRow>[]>(() => [
{title: "브랜드", chartMode:"reverseStack", data: apiBrandShareByYear},
], []);
useEffect(() => {
registerExcelExporter(async (payload) => {
@@ -63,7 +36,7 @@ const Brand = () => {
});
await exportDashboardExcel({
fileName: `20${LAST_YEAR}년도 가전 보급률 Dashboard(${sheetName}).xlsx`,
fileName: `${SITE_TITLE}(${sheetName}).xlsx`,
sheetName: sheetName,
sections: sections,
});
@@ -76,6 +49,7 @@ const Brand = () => {
{tableDataArray.map((tableData) => (
<CategoryByData
key={`cbd-${tableData.title.replaceAll(/\s+/g, "_")}`}
selectedYear={filterValue.year}
title={tableData.title}
chartMode={tableData.chartMode}
allTableData={tableData.data}

View File

@@ -1,11 +1,11 @@
'use client'
import {useLayoutFilter} from "@/components/layout/LayoutFilterContext";
import {useEffect, useMemo} from "react";
import {useEffect, useMemo, useState} 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 {BANNER_GROUP, BANNER_KEY_MAP, SITE_TITLE, YEARS} from "@/const/lgConst";
import {CategoryTypeValue} from "@/components/layout/CategoryFilter";
import {buildHeader_Banner, exportDashboardExcel, Section} from "@/lib/lg-export-excel";
@@ -14,8 +14,8 @@ const OwnershipPath = () => {
console.log(filterValue);
const tableDataArray = useMemo<PageData<ServerBannerRow>[]>(() => [
{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"))},
{title: "보유 경로", chartMode:"reverseStack", data: apiOwnershipPathByYear},
{title: "구입 계기", chartMode:"horizontal", data: apiOwnershipTriggerByYear, chartHeight: 550,},
], []);
useEffect(() => {
@@ -37,7 +37,7 @@ const OwnershipPath = () => {
});
await exportDashboardExcel({
fileName: `20${LAST_YEAR}년도 가전 보급률 Dashboard(${sheetName}).xlsx`,
fileName: `${SITE_TITLE}(${sheetName}).xlsx`,
sheetName: sheetName,
sections: sections,
});
@@ -50,6 +50,7 @@ const OwnershipPath = () => {
{tableDataArray.map((tableData) => (
<CategoryByData
key={`cbd-${tableData.title.replaceAll(/\s+/g, "_")}`}
selectedYear={filterValue.year}
title={tableData.title}
chartMode={tableData.chartMode}
allTableData={tableData.data}

View File

@@ -5,7 +5,7 @@ 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 {BANNER_GROUP, BANNER_KEY_MAP, SITE_TITLE, YEARS} from "@/const/lgConst";
import {CategoryTypeValue} from "@/components/layout/CategoryFilter";
import {buildHeader_Banner, exportDashboardExcel, Section} from "@/lib/lg-export-excel";
@@ -14,7 +14,7 @@ const PaymentMethod = () => {
console.log(filterValue);
const tableDataArray = useMemo<PageData<ServerBannerRow>[]>(() => [
{title: "구매 형식", chartMode:"reverseStack", data: apiPaymentMethodByYear.filter(r => !(r.year === LAST_YEAR && r.rowLabel === "gap"))},
{title: "구매 형식", chartMode:"reverseStack", data: apiPaymentMethodByYear},
], []);
useEffect(() => {
@@ -36,7 +36,7 @@ const PaymentMethod = () => {
});
await exportDashboardExcel({
fileName: `20${LAST_YEAR}년도 가전 보급률 Dashboard(${sheetName}).xlsx`,
fileName: `${SITE_TITLE}(${sheetName}).xlsx`,
sheetName: sheetName,
sections: sections,
});
@@ -49,6 +49,7 @@ const PaymentMethod = () => {
{tableDataArray.map((tableData) => (
<CategoryByData
key={`cbd-${tableData.title.replaceAll(/\s+/g, "_")}`}
selectedYear={filterValue.year}
title={tableData.title}
chartMode={tableData.chartMode}
allTableData={tableData.data}

View File

@@ -13,7 +13,7 @@ const PenetrationChange = () => {
const penetrationChangeData = useMemo<ServerBannerRow[]>(() => apiYearIndex, []);
return(
<BannerSummary data={penetrationChangeData} useChart={true} />
<BannerSummary data={penetrationChangeData} useChart={true} useYear={false} />
);
}

View File

@@ -27,7 +27,7 @@ const Profile = () => {
}, [isTotal, filterValue]);
return (
<BannerSummary data={profileData} useChart={false} />
<BannerSummary data={profileData} useChart={false} useYear={true} />
);
}

View File

@@ -5,7 +5,7 @@ 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 {BANNER_GROUP, BANNER_KEY_MAP, SITE_TITLE, YEARS} from "@/const/lgConst";
import {CategoryTypeValue} from "@/components/layout/CategoryFilter";
import {buildHeader_Banner, exportDashboardExcel, Section} from "@/lib/lg-export-excel";
@@ -14,8 +14,8 @@ const PurchaseBehavior = () => {
console.log(filterValue);
const tableDataArray = useMemo<PageData<ServerBannerRow>[]>(() => [
{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"))},
{title: "보유 경로", chartMode:"horizontal", data: apiOwnershipPathByYear},
{title: "구입 계기", chartMode:"horizontal", data: apiOwnershipTriggerByYear},
], []);
useEffect(() => {
@@ -37,7 +37,7 @@ const PurchaseBehavior = () => {
});
await exportDashboardExcel({
fileName: `20${LAST_YEAR}년도 가전 보급률 Dashboard(${sheetName}).xlsx`,
fileName: `${SITE_TITLE}(${sheetName}).xlsx`,
sheetName: sheetName,
sections: sections,
});
@@ -50,6 +50,7 @@ const PurchaseBehavior = () => {
{tableDataArray.map((tableData) => (
<CategoryByData
key={`cbd-${tableData.title.replaceAll(/\s+/g, "_")}`}
selectedYear={filterValue.year}
title={tableData.title}
chartMode={tableData.chartMode}
allTableData={tableData.data}

View File

@@ -8,7 +8,7 @@ import {
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 {BANNER_GROUP, BANNER_KEY_MAP, SITE_TITLE, YEARS} from "@/const/lgConst";
import {CategoryTypeValue} from "@/components/layout/CategoryFilter";
import {buildHeader_Banner, exportDashboardExcel, Section} from "@/lib/lg-export-excel";
@@ -20,12 +20,12 @@ const PurchaseChannel = () => {
{
title: "구매 채널(온/오프라인)",
chartMode: "reverseStack",
data: apiPurchaseChannelSummaryByYear.filter(r => !(r.year === LAST_YEAR && r.rowLabel === "gap")),
data: apiPurchaseChannelSummaryByYear,
},
{
title: "구매 채널(상세)",
chartMode: "horizontal",
data: apiPurchaseChannelByYear.filter(r => !(r.year === LAST_YEAR && r.rowLabel === "gap")),
data: apiPurchaseChannelByYear,
chartHeight: 550,
},
], []);
@@ -49,7 +49,7 @@ const PurchaseChannel = () => {
});
await exportDashboardExcel({
fileName: `20${LAST_YEAR}년도 가전 보급률 Dashboard(${sheetName}).xlsx`,
fileName: `${SITE_TITLE}(${sheetName}).xlsx`,
sheetName: sheetName,
sections: sections,
});
@@ -62,6 +62,7 @@ const PurchaseChannel = () => {
{tableDataArray.map((tableData) => (
<CategoryByData
key={`cbd-${tableData.title.replaceAll(/\s+/g, "_")}`}
selectedYear={filterValue.year}
title={tableData.title}
chartMode={tableData.chartMode}
allTableData={tableData.data}

View File

@@ -5,7 +5,7 @@ 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 {BANNER_GROUP, BANNER_KEY_MAP, SITE_TITLE, YEARS} from "@/const/lgConst";
import {CategoryTypeValue} from "@/components/layout/CategoryFilter";
import {buildHeader_Banner, exportDashboardExcel, Section} from "@/lib/lg-export-excel";
@@ -17,7 +17,7 @@ const TypeSpec = () => {
{
title: "타입",
chartMode: "horizontal",
data: apiFridgeDoorTypeByYear.filter(r => !(r.year === LAST_YEAR && r.rowLabel === "gap")),
data: apiFridgeDoorTypeByYear,
},
], []);
@@ -40,7 +40,7 @@ const TypeSpec = () => {
});
await exportDashboardExcel({
fileName: `20${LAST_YEAR}년도 가전 보급률 Dashboard(${sheetName}).xlsx`,
fileName: `${SITE_TITLE}(${sheetName}).xlsx`,
sheetName: sheetName,
sections: sections,
});
@@ -53,6 +53,7 @@ const TypeSpec = () => {
{tableDataArray.map((tableData) => (
<CategoryByData
key={`cbd-${tableData.title.replaceAll(/\s+/g, "_")}`}
selectedYear={filterValue.year}
title={tableData.title}
chartMode={tableData.chartMode}
allTableData={tableData.data}

View File

@@ -5,6 +5,7 @@ import type React from "react";
import { cn, parseNumber } from "@/lib/utils";
import type { DataColumn, SignDisplayMode, SignStyle } from "../types";
import SectionTitle from "../SectionTitle";
import {isSampleRow} from "@/lib/lg-dashboard";
type Props<T extends Record<string, unknown>> = {
columns: DataColumn<T>[];
@@ -14,6 +15,7 @@ type Props<T extends Record<string, unknown>> = {
wrapperClassName?: string;
signStyle?: SignStyle<T>;
fillGreaterThan5?: boolean;
starUnder30Sample?: boolean;
};
// parseSignedNumber는 utils.ts의 parseNumber로 통합됨
@@ -55,6 +57,7 @@ const DataTable = <T extends Record<string, unknown>>({
wrapperClassName,
signStyle,
fillGreaterThan5 = false,
starUnder30Sample = false,
}: Props<T>) => {
const hasGroup = columns.some((c) => !!c.group) || columns.some((c) => c.headRowSpan === 2);
@@ -177,6 +180,7 @@ const DataTable = <T extends Record<string, unknown>>({
<tbody>
{rows.map((row, rIdx) => {
const sampleRow = isSampleRow(row.rowLabel as string ?? "");
const signRow = isSignRow(row, rIdx);
const total = parseNumber(row.total);
@@ -227,14 +231,15 @@ const DataTable = <T extends Record<string, unknown>>({
);
}
const numContent = c.numeric ? parseNumber(content) ?? 0 : 0;
const isFill = fillGreaterThan5 && total && numContent > total + 5;
const isStar = starUnder30Sample && sampleRow && numContent < 30;
return (
<td key={String(c.key)} style={{ textAlign: align }} className={
cn(c.cellClassName, isFill? "bg-red-200" :"")
}>
{content}
{isStar?`${content}*`:content}
</td>
);
})}