260209_01_ENH: 테이블에 단위 텍스트 추가, 하단 설명 추가
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import {
|
||||
BottomDescription,
|
||||
GroupedOverlayBar,
|
||||
type GroupedOverlayBarData,
|
||||
signStyleGapRow,
|
||||
@@ -39,6 +40,7 @@ const LGPenetrationPage = () => {
|
||||
const productTableRows = useMemo<TopChartTableRow[]>(() => {
|
||||
return apiOwnShareOfTotalPenetration.map((row) => ({
|
||||
label: formatRowLabel(row.rowLabel),
|
||||
total: row.total,
|
||||
values: PRODUCT_KEYS.map((k) => (row as any)[k] ?? null),
|
||||
}));
|
||||
}, []);
|
||||
@@ -103,6 +105,12 @@ const LGPenetrationPage = () => {
|
||||
});
|
||||
}, []);
|
||||
|
||||
const description = useMemo(() => {
|
||||
return "Q. 다음 중 귀댁에서 보유하고 계신 가전/전자 제품은 무엇입니까? 모두 선택해주세요.<br/>" +
|
||||
"* 구독/렌탈/선물/경품/아파트 내 빌트인 제품을 모두 포함하여 선택해주세요.<br/>" +
|
||||
"Q. 보유하고 계신 (제품)의 브랜드는 어떻게 되십니까?";
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
registerExcelExporter(async () => {
|
||||
const excelHeader = buildHeader_ProductKeyMap(PRODUCT_KEY_MAP);
|
||||
@@ -152,6 +160,8 @@ const LGPenetrationPage = () => {
|
||||
signStyle={signStyleGapRow}
|
||||
/>
|
||||
|
||||
<BottomDescription description={description} />
|
||||
|
||||
<LifeStageDiv lifeStageRowsByGroup={lifeStageRowsByGroup} />
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -23,6 +23,7 @@ const LGPurchasePage = () => {
|
||||
const purchaseTableRows = useMemo<TopChartTableRow[]>(() => {
|
||||
return apiOwnShareOfTotalPurchase.map((row) => ({
|
||||
label: formatRowLabel(row.rowLabel),
|
||||
total: row.total,
|
||||
values: PRODUCT_KEYS.map((k) => (row as any)[k] ?? null),
|
||||
}));
|
||||
}, []);
|
||||
@@ -65,6 +66,16 @@ const LGPurchasePage = () => {
|
||||
};
|
||||
}, []);
|
||||
|
||||
const description = useMemo(() => {
|
||||
return "Q. 다음 중 귀댁에서 보유하고 계신 가전/전자 제품은 무엇입니까? 모두 선택해주세요.<br/>" +
|
||||
"* 구독/렌탈/선물/경품/아파트 내 빌트인 제품을 모두 포함하여 선택해주세요.<br/>" +
|
||||
"Q. 보유하고 계신 (제품)을 언제 구입하셨습니까?<br/>" +
|
||||
"* 새 상품을 선물 받은 경우, 선물 받은 연도로 입력해주세요.<br/>" +
|
||||
"** 중고 제품인 경우, 중고 제품을 구입한 연도로 입력해주세요.<br/>" +
|
||||
"*** 신규 입주 시 빌트인되어 있던 제품은 입주한 연도를 입력해주세요.<br/>" +
|
||||
"Q. 보유하고 계신 (제품)의 브랜드는 어떻게 되십니까?";
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
registerExcelExporter(async () => {
|
||||
const excelHeader = buildHeader_ProductKeyMap(PRODUCT_KEY_MAP);
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
GroupedStackBar,
|
||||
signStyleGapRow,
|
||||
type TopChartTableRow,
|
||||
type GroupedStackBarData,
|
||||
type GroupedStackBarData, BottomDescription,
|
||||
} from "@/components/lge-dashboard";
|
||||
import { useLayoutFilter } from "@/components/layout/LayoutFilterContext";
|
||||
import {apiBrandByYearCategories, apiTrendCategories} from "@/config/sample.data";
|
||||
@@ -33,6 +33,7 @@ const PenetrationPage = () => {
|
||||
const productTableRows = useMemo<TopChartTableRow[]>(() => {
|
||||
return apiTrendCategories.map((row) => ({
|
||||
label: formatRowLabel(row.rowLabel),
|
||||
total: row.total,
|
||||
values: PRODUCT_KEYS.map((k) => (row as any)[k] ?? null),
|
||||
}));
|
||||
}, []);
|
||||
@@ -71,6 +72,15 @@ const PenetrationPage = () => {
|
||||
return { categories: PRODUCTS, years: YEARS, brands: BRAND_LIST, values };
|
||||
}, []);
|
||||
|
||||
const description = useMemo(() => {
|
||||
if(isBrandShare){
|
||||
return "Q. 보유하고 계신 (제품)의 브랜드는 어떻게 되십니까?";
|
||||
}
|
||||
|
||||
return "Q. 다음 중 귀댁에서 보유하고 계신 가전/전자 제품은 무엇입니까? 모두 선택해주세요.<br/>" +
|
||||
"* 구독/렌탈/선물/경품/아파트 내 빌트인 제품을 모두 포함하여 선택해주세요.";
|
||||
}, [isBrandShare]);
|
||||
|
||||
useEffect(() => {
|
||||
registerExcelExporter(async () => {
|
||||
const excelHeader = buildHeader_ProductKeyMap(PRODUCT_KEY_MAP);
|
||||
@@ -140,7 +150,9 @@ const PenetrationPage = () => {
|
||||
)
|
||||
}
|
||||
signStyle={signStyleGapRow}
|
||||
fillCAGR={true}
|
||||
/>
|
||||
<BottomDescription description={description} />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
SITE_TITLE
|
||||
} from "@/const/lgConst";
|
||||
import {
|
||||
BottomDescription,
|
||||
type ChartData,
|
||||
signStyleGapRow,
|
||||
TopChartTable,
|
||||
@@ -28,6 +29,7 @@ const PurchasePage = () => {
|
||||
const purchaseTableRows = useMemo<TopChartTableRow[]>(() => {
|
||||
return apiTrendBuy.map((row) => ({
|
||||
label: formatRowLabel(row.rowLabel),
|
||||
total: row.total,
|
||||
values: PRODUCT_KEYS.map((k) => (row as any)[k] ?? null),
|
||||
}));
|
||||
}, []);
|
||||
@@ -44,6 +46,15 @@ const PurchasePage = () => {
|
||||
};
|
||||
}, []);
|
||||
|
||||
const description = useMemo(() => {
|
||||
return "Q. 다음 중 귀댁에서 보유하고 계신 가전/전자 제품은 무엇입니까? 모두 선택해주세요.<br/>" +
|
||||
"* 구독/렌탈/선물/경품/아파트 내 빌트인 제품을 모두 포함하여 선택해주세요.<br/>" +
|
||||
"Q. 보유하고 계신 (제품)을 언제 구입하셨습니까?<br/>" +
|
||||
"* 새 상품을 선물 받은 경우, 선물 받은 연도로 입력해주세요.<br/>" +
|
||||
"** 중고 제품인 경우, 중고 제품을 구입한 연도로 입력해주세요.<br/>" +
|
||||
"*** 신규 입주 시 빌트인되어 있던 제품은 입주한 연도를 입력해주세요.";
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
registerExcelExporter(async () => {
|
||||
const excelHeader = buildHeader_ProductKeyMap(PRODUCT_KEY_MAP);
|
||||
@@ -78,6 +89,8 @@ const PurchasePage = () => {
|
||||
}
|
||||
signStyle={signStyleGapRow}
|
||||
/>
|
||||
|
||||
<BottomDescription description={description} />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -31,7 +31,7 @@ const buildDefaultTotalValue = (): SelectedMap => {
|
||||
return init;
|
||||
};
|
||||
|
||||
export const buildDefaultCategoryValue = (categoryFilterItems: ProductsFilterItem): CategoryFilterValue => {
|
||||
const buildDefaultCategoryValue = (categoryFilterItems: ProductsFilterItem): CategoryFilterValue => {
|
||||
const initProduct = categoryFilterItems.items[0];
|
||||
const initType = {label:"보유", value:CategoryTargetType.PENETRATION}
|
||||
const firstTarget = categoryTarget.find((x) => x.type.includes(initType.value))?.children?.[0]?.target;
|
||||
@@ -45,6 +45,12 @@ export const buildDefaultCategoryValue = (categoryFilterItems: ProductsFilterIte
|
||||
};
|
||||
};
|
||||
|
||||
const buildTotalPartDescription = (pathname:string) => {
|
||||
return pathname.match("penetration")
|
||||
? "■ 보급률: 전체 소비자 중, 조사 년도에 해당 제품을 <strong>보유하고 있는 비율</strong>"
|
||||
: "■ 구매율: 전체 소비자 중, 조사 년도에 해당 제품을 <strong>구매한 비율</strong>";
|
||||
}
|
||||
|
||||
const MainLayout = ({ children }: MainLayoutProps) => {
|
||||
const router = useRouter();
|
||||
const pathname = usePathname();
|
||||
@@ -62,6 +68,7 @@ const MainLayout = ({ children }: MainLayoutProps) => {
|
||||
const isFilterOpen = isTotal ? isTotalFilterOpen : isCategoryFilterOpen;
|
||||
|
||||
const categoryFilterItems = PRODUCTS_FILTER_ITEM.find((m) => pathname.match?.(m.path)) ?? PRODUCTS_FILTER_ITEM[0];
|
||||
const totalPartDescription = buildTotalPartDescription(pathname);
|
||||
|
||||
const [totalValue, setTotalValue] = useState<SelectedMap>(() => buildDefaultTotalValue());
|
||||
const [categoryValue, setCategoryValue] = useState<CategoryFilterValue>(() => buildDefaultCategoryValue(categoryFilterItems));
|
||||
@@ -137,16 +144,15 @@ const MainLayout = ({ children }: MainLayoutProps) => {
|
||||
type="button"
|
||||
onClick={toggleFilter}
|
||||
className={cn(
|
||||
"inline-flex items-center gap-2 font-semibold text-gray-900 content-text-sm",
|
||||
"inline-flex items-center gap-2 font-semibold text-gray-900 content-text-sm cursor-pointer",
|
||||
"select-none"
|
||||
)}
|
||||
>
|
||||
<Filter className="h-4 w-4 fill-[hsl(var(--lg-gray-500))] stroke-[hsl(var(--lg-gray-500))]" />
|
||||
필터 <span className="text-sm leading-none">{isFilterOpen ? "▲" : "▼"}</span>
|
||||
필터 <span className="text-sm leading-none mb-1">{isFilterOpen ? "▲" : "▼"}</span>
|
||||
</button>
|
||||
{isTotal && (
|
||||
<div className={"ml-5 content-text-sm"}>
|
||||
페이지에 대한 설명
|
||||
<div className={"ml-5 content-text-sm"} dangerouslySetInnerHTML={{__html: totalPartDescription}}>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
8
src/components/lge-dashboard/BottomDescription.tsx
Normal file
8
src/components/lge-dashboard/BottomDescription.tsx
Normal file
@@ -0,0 +1,8 @@
|
||||
const BottomDescription = ({description}:{description:string}) => {
|
||||
return (
|
||||
<div className="content-text-sm mt-2" dangerouslySetInnerHTML={{__html: description}}>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default BottomDescription;
|
||||
@@ -1,6 +1,6 @@
|
||||
const SectionTitle = ({title}:{title:string}) => {
|
||||
return (
|
||||
<div className="mb-2 font-semibold flex items-center gap-2">
|
||||
<div className="font-semibold flex items-center gap-2">
|
||||
<span className="w-3 h-3 bg-primary" />
|
||||
{title}
|
||||
</div>
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
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 {formatRowLabel, isGapRow, wrapSampleRow} from "@/lib/lg-dashboard";
|
||||
import {useEffect, useMemo} from "react";
|
||||
import {
|
||||
BANNER_GROUP,
|
||||
BANNER_KEY_MAP,
|
||||
GRID_Y_NOT_PADDING,
|
||||
SAMPLE_SIZE_NOTICE, SITE_TITLE,
|
||||
SITE_TITLE,
|
||||
} from "@/const/lgConst";
|
||||
import {parseNumber} from "@/lib/utils";
|
||||
import {
|
||||
@@ -27,7 +27,7 @@ type SectionSpec = {
|
||||
/** 3개 섹션(테이블)도 여기서만 선언 */
|
||||
const SECTIONS: SectionSpec[] = [
|
||||
{ title: "가구 형태", groupKeys: ["lifeStage", "household", "age"] },
|
||||
{ title: "거주 형태", groupKeys: ["tenure", "housing", "pyeong"] },
|
||||
{ title: "거주 형태", groupKeys: ["occupancy", "housing", "houseSize"] },
|
||||
{ title: "거주 지역 및 소득 수준", groupKeys: ["region", "income"] },
|
||||
];
|
||||
|
||||
@@ -105,7 +105,7 @@ const BannerSummary = ({ data, useChart, useYear }: BannerSummaryProps) => {
|
||||
};
|
||||
|
||||
const signStyleGap: SignStyle<ServerBannerRow> = {
|
||||
rowSelector: (row) => row.rowLabel === "gap",
|
||||
rowSelector: (row) => isGapRow(row.rowLabel),
|
||||
display: "arrow",
|
||||
arrowWithNumber: true,
|
||||
paint: "text",
|
||||
@@ -121,7 +121,12 @@ const BannerSummary = ({ data, useChart, useYear }: BannerSummaryProps) => {
|
||||
const columns = buildColumns(spec, useYear? filterValue.year : "");
|
||||
|
||||
// rows가 spec마다 다르면 여기서 가져오도록 구성
|
||||
const rows = wrapSampleRow(useYear? data.filter((d) => d.year === filterValue.year) : data);
|
||||
const rows =
|
||||
wrapSampleRow(useYear? data.filter((d) => d.year === filterValue.year) : data)
|
||||
.map((row) => {
|
||||
row.rowLabel = formatRowLabel(row.rowLabel);
|
||||
return row
|
||||
})
|
||||
const chartData = buildChartData(rows, bannerKeys);
|
||||
|
||||
return {
|
||||
@@ -197,7 +202,6 @@ const BannerSummary = ({ data, useChart, useYear }: BannerSummaryProps) => {
|
||||
starUnder30Sample={true}
|
||||
/>
|
||||
}
|
||||
<div className="float-right content-text-sm">{SAMPLE_SIZE_NOTICE}</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
|
||||
@@ -7,15 +7,15 @@ import {
|
||||
} from "@/components/lge-dashboard";
|
||||
import BannerButtons from "@/components/lge-dashboard/BannerButtons";
|
||||
import {totalFilters} from "@/config/filter.data";
|
||||
import {useEffect, useMemo, useState} from "react";
|
||||
import React, {useMemo, useState} from "react";
|
||||
import {BannerGroupKey, CategoryChartMode, ServerBannerRow} from "@/types/lg";
|
||||
import {
|
||||
buildRowLabelSeriesChartData,
|
||||
buildYearSeriesChartData,
|
||||
isBannerGroupKey,
|
||||
buildYearSeriesChartData, formatRowLabel,
|
||||
isBannerGroupKey, isGapRow,
|
||||
wrapSampleRow
|
||||
} from "@/lib/lg-dashboard";
|
||||
import {BANNER_GROUP, BANNER_KEY_MAP, LAST_YEAR, SAMPLE_SIZE_NOTICE} from "@/const/lgConst";
|
||||
import {BANNER_GROUP, BANNER_KEY_MAP, GAP_WORDING, SAMPLE_SIZE_NOTICE, UNIT_TEXT} from "@/const/lgConst";
|
||||
import {createDefaultGrid, createDefaultLegend, reverseCategories} from "@/lib/chart-options";
|
||||
|
||||
type CategoryByDataProps = {
|
||||
@@ -26,6 +26,7 @@ type CategoryByDataProps = {
|
||||
fillGreaterThan5?: boolean;
|
||||
chartHeight?: number;
|
||||
chartWidth?: number;
|
||||
unitText?: string;
|
||||
}
|
||||
|
||||
const banners: bannerType[] = totalFilters.map((filter) => {
|
||||
@@ -33,7 +34,7 @@ const banners: bannerType[] = totalFilters.map((filter) => {
|
||||
})
|
||||
|
||||
const signStyleGap: SignStyle<ServerBannerRow> = {
|
||||
rowSelector: (row) => row.rowLabel === "gap",
|
||||
rowSelector: (row) => isGapRow(row.rowLabel),
|
||||
display: "arrow",
|
||||
arrowWithNumber: true,
|
||||
paint: "text",
|
||||
@@ -48,6 +49,7 @@ const CategoryByData = ({
|
||||
fillGreaterThan5,
|
||||
chartHeight,
|
||||
chartWidth,
|
||||
unitText = UNIT_TEXT,
|
||||
}: CategoryByDataProps) => {
|
||||
const [selectedBanner, setSelectedBanner] = useState<bannerType>(banners[0]);
|
||||
|
||||
@@ -93,11 +95,20 @@ const CategoryByData = ({
|
||||
return isBannerGroupKey(v) ? buildColumns(v, selectedYear) : [];
|
||||
}, [selectedBanner.variable, selectedYear]);
|
||||
|
||||
const tableData = useMemo(() => wrapSampleRow(allTableData).filter((row) => row.year === selectedYear), [allTableData, selectedYear]);
|
||||
const tableData = useMemo(() =>
|
||||
wrapSampleRow(allTableData)
|
||||
.filter((row) => row.year === selectedYear)
|
||||
.map((row) => {
|
||||
row.rowLabel = formatRowLabel(row.rowLabel);
|
||||
return row
|
||||
})
|
||||
, [allTableData, selectedYear]);
|
||||
|
||||
return (
|
||||
<div>
|
||||
{title && <SectionTitle title={title} />}
|
||||
<div className="mb-2 flex items-center pr-6">
|
||||
{title ? <SectionTitle title={title} /> : <div />}
|
||||
</div>
|
||||
<div className="flex gap-6 p-3">
|
||||
<div className="flex-shrink-0" style={{ width: `${chartWidth ?? 400}px`}}>
|
||||
{
|
||||
@@ -132,13 +143,11 @@ const CategoryByData = ({
|
||||
columns={tableColumns}
|
||||
rows={tableData}
|
||||
signStyle={signStyleGap}
|
||||
wrapperClassName="border rounded-lg"
|
||||
fillGreaterThan5={fillGreaterThan5}
|
||||
starUnder30Sample={true}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="float-right content-text-sm">{SAMPLE_SIZE_NOTICE}</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -6,6 +6,7 @@ import type { DataColumn, SignStyle } from "../types";
|
||||
import SectionTitle from "../SectionTitle";
|
||||
import { TABLE_DIMENSIONS } from "@/const/chartConst";
|
||||
import {isSampleRow} from "@/lib/lg-dashboard";
|
||||
import {SAMPLE_SIZE_NOTICE, UNIT_TEXT} from "@/const/lgConst";
|
||||
|
||||
type MergedChartCell<T> = {
|
||||
/** 차트를 삽입할 컬럼 key(해당 컬럼 td는 startRow에서만 렌더되고 rowSpan 적용) */
|
||||
@@ -34,6 +35,7 @@ type Props<T extends Record<string, unknown>> = {
|
||||
tableClassName?: string;
|
||||
minWidthPx?: number;
|
||||
starUnder30Sample?: boolean;
|
||||
unitText?: string;
|
||||
};
|
||||
|
||||
// toNumber는 utils.ts의 parseNumber로 통합됨
|
||||
@@ -67,7 +69,8 @@ export default function LeftChartTable<T extends Record<string, unknown>>({
|
||||
wrapperClassName,
|
||||
tableClassName,
|
||||
minWidthPx = TABLE_DIMENSIONS.MIN_WIDTH.COMPACT,
|
||||
starUnder30Sample = true
|
||||
starUnder30Sample = true,
|
||||
unitText = UNIT_TEXT,
|
||||
}: Props<T>) {
|
||||
const hasGroupHeader = useMemo(
|
||||
() => columns.some((c) => c.group) || columns.some((c) => c.headRowSpan === 2),
|
||||
@@ -137,9 +140,16 @@ export default function LeftChartTable<T extends Record<string, unknown>>({
|
||||
|
||||
return (
|
||||
<div className={cn("w-full", wrapperClassName)}>
|
||||
{title && (
|
||||
<SectionTitle title={title} />
|
||||
)}
|
||||
<div className="mb-2 flex items-center justify-between">
|
||||
{ title && <SectionTitle title={title} />}
|
||||
{
|
||||
(unitText || starUnder30Sample) &&
|
||||
<div className="ml-auto text-gray-500 content-text-xs font-semibold text-right">
|
||||
{unitText}
|
||||
{starUnder30Sample && <><br/>{SAMPLE_SIZE_NOTICE}</>}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div className="overflow-x-auto">
|
||||
<table className={cn("lg-table", tableClassName)} style={{ minWidth: `${minWidthPx}px` }}>
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import GaugeCardTable from "./GaugeCardTable";
|
||||
import {LIFE_STAGE_COLUMNS} from "@/const/lgConst";
|
||||
import {LIFE_STAGE_COLUMNS, UNIT_TEXT} from "@/const/lgConst";
|
||||
import {LifeStageGroup} from "@/types/lg";
|
||||
import SectionTitle from "../SectionTitle";
|
||||
import React from "react";
|
||||
|
||||
type lifeStageDivProps = {
|
||||
lifeStageRowsByGroup:LifeStageGroup[];
|
||||
@@ -10,11 +12,10 @@ type lifeStageDivProps = {
|
||||
const LifeStageDiv = ({lifeStageRowsByGroup}:lifeStageDivProps) => {
|
||||
return (
|
||||
<div className="mt-6">
|
||||
<div className="flex justify-between text-muted-foreground mb-5">
|
||||
<div className=" content-text-xs">
|
||||
* 하위 테이블들에 대한 설명
|
||||
</div>
|
||||
<div className="flex justify-end gap-6 content-text-xs">
|
||||
<SectionTitle title={"LG 가전 보급률 기준 라이프스테이지별 기회 영역"} />
|
||||
|
||||
<div className="flex justify-end text-muted-foreground mb-5">
|
||||
<div className="flex justify-end gap-4 content-text-xs">
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="inline-block h-4 w-8 border bg-gray-200 border-gray-300"/>
|
||||
<span>제품 보유율</span>
|
||||
@@ -27,6 +28,9 @@ const LifeStageDiv = ({lifeStageRowsByGroup}:lifeStageDivProps) => {
|
||||
/>
|
||||
<span>시장 기회공간</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
{UNIT_TEXT}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -5,18 +5,20 @@ import { cn, parseNumber } from "@/lib/utils";
|
||||
import type { ChartData, SignStyle, TopChartTableRow } from "../types";
|
||||
import SectionTitle from "../SectionTitle";
|
||||
import { CHART_HEIGHTS, TABLE_DIMENSIONS } from "@/const/chartConst";
|
||||
import {UNIT_TEXT} from "@/const/lgConst";
|
||||
import {isCagrRow} from "@/lib/lg-dashboard";
|
||||
|
||||
type BaseProps = {
|
||||
export type TopChartTableProps = {
|
||||
title?: string;
|
||||
categories: string[];
|
||||
rows: TopChartTableRow[];
|
||||
/** 테이블 상단(헤더 1행) 콜스팬 셀 내부에 렌더될 차트 */
|
||||
chart?:
|
||||
| React.ReactNode
|
||||
| ((ctx: {
|
||||
/** 테이블 컬럼(=x축) 기준으로 구성된 ChartData */
|
||||
chartData: ChartData;
|
||||
tableCategories: string[];
|
||||
tableRows: TopChartTableRow[];
|
||||
}) => React.ReactNode);
|
||||
| React.ReactNode
|
||||
| ((ctx: {
|
||||
/** 테이블 컬럼(=x축) 기준으로 구성된 ChartData */
|
||||
chartData: ChartData;
|
||||
}) => React.ReactNode);
|
||||
/** chart 셀 높이(px) */
|
||||
chartHeight?: number;
|
||||
/** 가로 스크롤 min-width */
|
||||
@@ -25,31 +27,9 @@ type BaseProps = {
|
||||
wrapperClassName?: string;
|
||||
/** +/-/0 색상/표기 옵션(선택) */
|
||||
signStyle?: SignStyle<TopChartTableRow>;
|
||||
fillCAGR?: boolean;
|
||||
unitText?: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* 1) (신규) HTML 형태: columns=categories, rows=TopChartTableRow
|
||||
*/
|
||||
type HtmlModeProps = BaseProps & {
|
||||
categories: string[];
|
||||
rows: TopChartTableRow[];
|
||||
};
|
||||
|
||||
/**
|
||||
* 2) (호환) 기존 형태: ChartData 기반으로 rows/columns 자동 생성
|
||||
* - rows = data.categories
|
||||
* - cols = data.series.name
|
||||
*/
|
||||
type ChartDataModeProps = BaseProps & {
|
||||
data: ChartData;
|
||||
/** 좌측 rowhead 컬럼 헤더 */
|
||||
categoryHeader?: string;
|
||||
/** 값 표기 포맷터 */
|
||||
valueFormatter?: (v: number) => string;
|
||||
};
|
||||
|
||||
export type TopChartTableProps = HtmlModeProps | ChartDataModeProps;
|
||||
|
||||
// toNumber는 utils.ts의 parseNumber로 통합됨
|
||||
|
||||
function formatSignedNumber(n: number, zeroText: string, showPlus: boolean) {
|
||||
@@ -68,12 +48,16 @@ function toCellValue(v: unknown): CellValue {
|
||||
export default function TopChartTable(props: TopChartTableProps) {
|
||||
const {
|
||||
title,
|
||||
rows,
|
||||
categories,
|
||||
chart,
|
||||
chartHeight = CHART_HEIGHTS.DEFAULT,
|
||||
minWidthPx = TABLE_DIMENSIONS.MIN_WIDTH.STANDARD,
|
||||
tableClassName,
|
||||
wrapperClassName,
|
||||
signStyle,
|
||||
fillCAGR = false,
|
||||
unitText = UNIT_TEXT
|
||||
} = props;
|
||||
|
||||
const display = signStyle?.display ?? "number";
|
||||
@@ -83,63 +67,40 @@ export default function TopChartTable(props: TopChartTableProps) {
|
||||
const negCls = signStyle?.negativeTextClassName ?? "lg-num-neg";
|
||||
const zeroText = signStyle?.zeroText ?? "-";
|
||||
|
||||
const { categories, rows, rowHeadHeader, valueFormatter } = useMemo(() => {
|
||||
if ("data" in props) {
|
||||
const d = props.data;
|
||||
const tableRows: TopChartTableRow[] = d.categories.map((cat, i) => ({
|
||||
label: String(cat ?? ""),
|
||||
values: d.series.map((s) => toCellValue(s.data[i] ?? null)),
|
||||
}));
|
||||
|
||||
return {
|
||||
categories: d.series.map((s) => s.name),
|
||||
rows: tableRows,
|
||||
rowHeadHeader: props.categoryHeader ?? "",
|
||||
valueFormatter: props.valueFormatter,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
categories: props.categories,
|
||||
rows: props.rows,
|
||||
rowHeadHeader: "",
|
||||
valueFormatter: undefined,
|
||||
};
|
||||
}, [props]);
|
||||
|
||||
// 테이블 컬럼(=categories)을 x축으로 사용하는 chartData를 항상 제공
|
||||
const chartData: ChartData = useMemo(
|
||||
() => ({
|
||||
categories,
|
||||
series: rows.map((r) => ({
|
||||
name: r.label,
|
||||
data: r.values.map((v) => parseNumber(v) ?? null),
|
||||
})),
|
||||
}),
|
||||
[categories, rows]
|
||||
() => ({
|
||||
categories,
|
||||
series: rows.map((r) => ({
|
||||
name: r.label,
|
||||
data: r.values.map((v) => parseNumber(v) ?? null),
|
||||
})),
|
||||
}),
|
||||
[categories, rows]
|
||||
);
|
||||
|
||||
const chartNode = useMemo(() => {
|
||||
if (!chart) return null;
|
||||
return typeof chart === "function" ? chart({ chartData, tableCategories: categories, tableRows: rows }) : chart;
|
||||
return typeof chart === "function" ? chart({ chartData }) : chart;
|
||||
}, [chart, chartData, categories, rows]);
|
||||
|
||||
return (
|
||||
<div className={cn("w-full", wrapperClassName)}>
|
||||
{title && (
|
||||
<SectionTitle title={title} />
|
||||
)}
|
||||
<div className={cn("w-full", wrapperClassName)}>
|
||||
<div className="mb-2 flex items-center justify-between">
|
||||
{title ? <SectionTitle title={title} /> : <div />}
|
||||
{unitText ? <div className="text-gray-500 text-xs font-semibold">{unitText}</div> : null}
|
||||
</div>
|
||||
|
||||
<div className="overflow-x-auto">
|
||||
<table
|
||||
className={cn("lg-table", tableClassName)}
|
||||
style={{ minWidth: `${minWidthPx}px` }}
|
||||
>
|
||||
<thead>
|
||||
<div className="overflow-x-auto">
|
||||
<table
|
||||
className={cn("lg-table", tableClassName)}
|
||||
style={{ minWidth: `${minWidthPx}px` }}
|
||||
>
|
||||
<thead>
|
||||
<tr>
|
||||
{/* 좌상단: rowhead 헤더(필요 시 표시). HTML과 동일하게 2행 rowspan */}
|
||||
<th rowSpan={2} className="lg-table__sep-r w-15" style={{ whiteSpace: "nowrap" }}>
|
||||
{rowHeadHeader}
|
||||
|
||||
</th>
|
||||
<td colSpan={categories.length} style={{ padding: 0, height: chartNode ? chartHeight : 0 }}>
|
||||
{chartNode ? <div style={{ width: "100%", height: "100%" }}>{chartNode}</div> : null}
|
||||
@@ -148,61 +109,65 @@ export default function TopChartTable(props: TopChartTableProps) {
|
||||
|
||||
<tr className="lg-table__subhead">
|
||||
{categories.map((c) => (
|
||||
<th key={c} className={"content-text-xs"}>{c}</th>
|
||||
<th key={c} className={"content-text-xs"}>{c}</th>
|
||||
))}
|
||||
</tr>
|
||||
</thead>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
<tbody>
|
||||
{rows.map((r, ri) => {
|
||||
const isSignRow = !!(signStyle?.rowSelector && signStyle.rowSelector(r, ri));
|
||||
const cagrRow = isCagrRow(r.label as string ?? "");
|
||||
const total = parseNumber(r.total);
|
||||
|
||||
return (
|
||||
<tr key={`${r.label}-${ri}`}>
|
||||
<th scope="row" className="lg-table__rowhead lg-table__sep-r content-text-sm">
|
||||
{r.label}
|
||||
</th>
|
||||
<tr key={`${r.label}-${ri}`}>
|
||||
<th scope="row" className="lg-table__rowhead lg-table__sep-r content-text-sm">
|
||||
{r.label}
|
||||
</th>
|
||||
|
||||
{categories.map((_, ci) => {
|
||||
const raw = r.values?.[ci];
|
||||
const n = parseNumber(raw);
|
||||
{categories.map((_, ci) => {
|
||||
const raw = r.values?.[ci];
|
||||
const n = parseNumber(raw);
|
||||
|
||||
// 일반 행
|
||||
if (!isSignRow) {
|
||||
// 일반 행
|
||||
if (!isSignRow) {
|
||||
if (n === null) return <td key={ci}>-</td>;
|
||||
|
||||
const isFill = fillCAGR && cagrRow && total && n > total + 5;
|
||||
const txt = n.toLocaleString();
|
||||
return <td key={ci} className={cn(isFill? "bg-red-200" :"")}>{txt}</td>;
|
||||
}
|
||||
|
||||
// sign row
|
||||
if (n === null) return <td key={ci}>-</td>;
|
||||
const txt = valueFormatter ? valueFormatter(n) : n.toLocaleString();
|
||||
return <td key={ci}>{txt}</td>;
|
||||
}
|
||||
if (n === 0) return <td key={ci}>{zeroText}</td>;
|
||||
|
||||
// sign row
|
||||
if (n === null) return <td key={ci}>-</td>;
|
||||
if (n === 0) return <td key={ci}>{zeroText}</td>;
|
||||
const cls = n > 0 ? posCls : negCls;
|
||||
|
||||
const cls = n > 0 ? posCls : negCls;
|
||||
if (display === "arrow") {
|
||||
const arrow = n > 0 ? "▲" : "▼";
|
||||
const num = Math.abs(n);
|
||||
return (
|
||||
<td key={ci} className={cls}>
|
||||
{arrow}
|
||||
{arrowWithNumber ? ` ${num}` : ""}
|
||||
</td>
|
||||
);
|
||||
}
|
||||
|
||||
if (display === "arrow") {
|
||||
const arrow = n > 0 ? "▲" : "▼";
|
||||
const num = Math.abs(n);
|
||||
return (
|
||||
<td key={ci} className={cls}>
|
||||
{arrow}
|
||||
{arrowWithNumber ? ` ${num}` : ""}
|
||||
</td>
|
||||
<td key={ci} className={cls}>
|
||||
{formatSignedNumber(n, zeroText, showPlus)}
|
||||
</td>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<td key={ci} className={cls}>
|
||||
{formatSignedNumber(n, zeroText, showPlus)}
|
||||
</td>
|
||||
);
|
||||
})}
|
||||
</tr>
|
||||
})}
|
||||
</tr>
|
||||
);
|
||||
})}
|
||||
</tbody>
|
||||
</table>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -19,3 +19,4 @@ export { default as CategoryByData } from "./combo/CategoryByData"
|
||||
export { default as CardDefault } from "./card/Card";
|
||||
|
||||
export { default as SectionTitle } from "./SectionTitle";
|
||||
export { default as BottomDescription } from "./BottomDescription";
|
||||
@@ -14,7 +14,7 @@ const Brand = () => {
|
||||
const {filterValue, registerExcelExporter} = useLayoutFilter();
|
||||
|
||||
const tableDataArray = useMemo<PageData<ServerBannerRow>[]>(() => [
|
||||
{title: "브랜드", chartMode:"reverseStack", data: apiBrandShareByYear},
|
||||
{title: "브랜드", chartMode:"reverseStack", data: apiBrandShareByYear, chartHeight:400},
|
||||
], []);
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
@@ -5,7 +5,8 @@ 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";
|
||||
import {isCagrRow, isSampleRow} from "@/lib/lg-dashboard";
|
||||
import {SAMPLE_SIZE_NOTICE, UNIT_TEXT} from "@/const/lgConst";
|
||||
|
||||
type Props<T extends Record<string, unknown>> = {
|
||||
columns: DataColumn<T>[];
|
||||
@@ -15,7 +16,9 @@ type Props<T extends Record<string, unknown>> = {
|
||||
wrapperClassName?: string;
|
||||
signStyle?: SignStyle<T>;
|
||||
fillGreaterThan5?: boolean;
|
||||
fillCAGR?: boolean;
|
||||
starUnder30Sample?: boolean;
|
||||
unitText?: string;
|
||||
};
|
||||
|
||||
// parseSignedNumber는 utils.ts의 parseNumber로 통합됨
|
||||
@@ -57,7 +60,9 @@ const DataTable = <T extends Record<string, unknown>>({
|
||||
wrapperClassName,
|
||||
signStyle,
|
||||
fillGreaterThan5 = false,
|
||||
fillCAGR = false,
|
||||
starUnder30Sample = false,
|
||||
unitText = UNIT_TEXT,
|
||||
}: Props<T>) => {
|
||||
const hasGroup = columns.some((c) => !!c.group) || columns.some((c) => c.headRowSpan === 2);
|
||||
|
||||
@@ -148,9 +153,16 @@ const DataTable = <T extends Record<string, unknown>>({
|
||||
|
||||
return (
|
||||
<div className={cn("w-full overflow-x-auto", wrapperClassName)}>
|
||||
{title && (
|
||||
<SectionTitle title={title} />
|
||||
)}
|
||||
<div className="mb-2 flex items-center justify-between">
|
||||
{ title && <SectionTitle title={title} />}
|
||||
{
|
||||
(unitText || starUnder30Sample) &&
|
||||
<div className="ml-auto text-gray-500 content-text-xs font-semibold text-right">
|
||||
{unitText}
|
||||
{starUnder30Sample && <><br/>{SAMPLE_SIZE_NOTICE}</>}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
<table className={cn("lg-table", className)}>
|
||||
<thead>
|
||||
{hasGroup && (
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type React from "react";
|
||||
import {GAP_WORDING} from "@/const/lgConst";
|
||||
|
||||
export type NewNumber = number | null | undefined;
|
||||
|
||||
@@ -45,6 +46,7 @@ export type GroupedOverlayBarData = {
|
||||
export type TopChartTableRow = {
|
||||
/** 좌측 rowhead 라벨 */
|
||||
label: string;
|
||||
total: number | string | null | undefined;
|
||||
/** categories 순서대로 값 */
|
||||
values: Array<number | string | null | undefined>;
|
||||
};
|
||||
@@ -122,7 +124,7 @@ export type SignStyle<T> = {
|
||||
};
|
||||
|
||||
export const signStyleGapRow: SignStyle<TopChartTableRow> = {
|
||||
rowSelector: (row) => row.label === "전년 대비 GAP(%)",
|
||||
rowSelector: (row) => row.label === GAP_WORDING,
|
||||
display: "arrow",
|
||||
arrowWithNumber: true,
|
||||
paint: "text",
|
||||
|
||||
@@ -32,7 +32,7 @@ export const totalFilters:TotalFilterItem[] = [
|
||||
]
|
||||
},
|
||||
{
|
||||
variable:"tenure",
|
||||
variable:"occupancy",
|
||||
variableName:"입주 형태",
|
||||
children:[
|
||||
{ value: "0", label: "전체"},
|
||||
@@ -44,7 +44,7 @@ export const totalFilters:TotalFilterItem[] = [
|
||||
]
|
||||
},
|
||||
{
|
||||
variable:"pyeong",
|
||||
variable:"houseSize",
|
||||
variableName:"거주 평형",
|
||||
children:[
|
||||
{ value: "0", label: "전체"},
|
||||
|
||||
@@ -158,9 +158,9 @@ const BANNER_GROUPS: Record<string, BannerKey[]> = {
|
||||
lifeStage: ["single", "noKids", "preschoolKids", "schoolKids", "adultKids", "independentSenior"],
|
||||
household: ["hh1", "hh2", "hh3", "hh4Plus"],
|
||||
age: ["age20s", "age30s", "age40s", "age50s", "age60s"],
|
||||
tenure: ["ownerOccupied", "jeonse", "depositAndMonthly", "monthlyNoDeposit", "otherTenure"],
|
||||
occupancy: ["ownerOccupied", "jeonse", "depositAndMonthly", "monthlyNoDeposit", "otherOccupancyType"],
|
||||
housing: ["apartment", "house", "officetel", "villa", "studio", "otherHousingType"],
|
||||
pyeong: ["under19Pyeong", "pyeong20s", "pyeong30s", "pyeong40s", "pyeong50Plus"],
|
||||
houseSize: ["under19Pyeong", "pyeong20s", "pyeong30s", "pyeong40s", "pyeong50Plus"],
|
||||
region: [
|
||||
"regionCapital",
|
||||
"regionGyeongnamBusanUlsan",
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
* - 차트 높이, Bar 너비, Grid 설정 등
|
||||
*/
|
||||
|
||||
import {GAP_WORDING} from "@/const/lgConst";
|
||||
|
||||
/**
|
||||
* 차트 기본 높이 설정
|
||||
*/
|
||||
@@ -122,8 +124,8 @@ export const TABLE_DIMENSIONS = {
|
||||
export const CHART_LABELS = {
|
||||
TOTAL: "전체",
|
||||
LG: "LG",
|
||||
GAP: "전년 대비 GAP(%)",
|
||||
CAGR: "CAGR(%)",
|
||||
GAP: GAP_WORDING,
|
||||
CAGR: "CAGR(%p)",
|
||||
SAMPLE_COUNT: "(사례수)",
|
||||
} as const;
|
||||
|
||||
|
||||
@@ -3,6 +3,11 @@ import {GaugeColumn} from "@/components/lge-dashboard";
|
||||
|
||||
export const SITE_TITLE = 'LGE CX Dashboard';
|
||||
|
||||
export const GAP_WORDING = "전년 대비 GAP(%p)";
|
||||
|
||||
export const UNIT_TEXT = "(단위 %)"
|
||||
export const SAMPLE_SIZE_NOTICE = "* 30표본 미만 해석에 주의";
|
||||
|
||||
export const PRODUCT_KEY_MAP = {
|
||||
refrigerator: "냉장고",
|
||||
kimchiRefrigerator: "김치 냉장고",
|
||||
@@ -52,7 +57,7 @@ export const BANNER_KEY_MAP = {
|
||||
jeonse: "전세",
|
||||
depositAndMonthly: "전+월세 (보증금有)",
|
||||
monthlyNoDeposit: "월세 (보증금無)",
|
||||
otherTenure: "기타",
|
||||
otherOccupancyType: "기타",
|
||||
|
||||
// 주거형태
|
||||
apartment: "아파트",
|
||||
@@ -181,15 +186,15 @@ export const BANNER_GROUP = {
|
||||
label: "연령",
|
||||
keys: [BANNER_KEY.age20s, BANNER_KEY.age30s, BANNER_KEY.age40s, BANNER_KEY.age50s, BANNER_KEY.age60s],
|
||||
},
|
||||
tenure: {
|
||||
occupancy: {
|
||||
label: "입주 형태",
|
||||
keys: [BANNER_KEY.ownerOccupied, BANNER_KEY.jeonse, BANNER_KEY.depositAndMonthly, BANNER_KEY.monthlyNoDeposit, BANNER_KEY.otherTenure],
|
||||
keys: [BANNER_KEY.ownerOccupied, BANNER_KEY.jeonse, BANNER_KEY.depositAndMonthly, BANNER_KEY.monthlyNoDeposit, BANNER_KEY.otherOccupancyType],
|
||||
},
|
||||
housing: {
|
||||
label: "주거 형태",
|
||||
keys: [BANNER_KEY.apartment, BANNER_KEY.house, BANNER_KEY.officetel, BANNER_KEY.villa, BANNER_KEY.studio, BANNER_KEY.otherHousingType],
|
||||
},
|
||||
pyeong: {
|
||||
houseSize: {
|
||||
label: "거주 평형",
|
||||
keys: [BANNER_KEY.under19Pyeong, BANNER_KEY.pyeong20s, BANNER_KEY.pyeong30s, BANNER_KEY.pyeong40s, BANNER_KEY.pyeong50Plus],
|
||||
},
|
||||
@@ -208,6 +213,4 @@ export const BANNER_GROUP = {
|
||||
label: "소득수준",
|
||||
keys: [BANNER_KEY.incomeUnder299, BANNER_KEY.income300to599, BANNER_KEY.income600to899, BANNER_KEY.income900Plus],
|
||||
},
|
||||
} as const;
|
||||
|
||||
export const SAMPLE_SIZE_NOTICE = "* 30 미만 샘플에 대한 설명";
|
||||
} as const;
|
||||
@@ -1,14 +1,18 @@
|
||||
import {BannerGroupKey, ServerBannerRow} from "@/types/lg";
|
||||
import {ChartData} from "@/components/lge-dashboard";
|
||||
import {BANNER_GROUP} from "@/const/lgConst";
|
||||
import {BANNER_GROUP, GAP_WORDING} from "@/const/lgConst";
|
||||
import {formatNumber} from "@/lib/utils";
|
||||
|
||||
export const isSampleRow = (raw: string) => raw.replace(/\s+/g, "").includes("사례수");
|
||||
|
||||
export const isCagrRow = (raw: string) => raw.replace(/\s+/g, "").toUpperCase().includes("CAGR");
|
||||
|
||||
export const isGapRow = (raw: string) => raw.replace(/\s+/g, "").toUpperCase().includes("GAP");
|
||||
|
||||
/**
|
||||
* Row Label을 표시용 텍스트로 포맷팅합니다.
|
||||
* - "사례수" -> "(사례수)"
|
||||
* - "gap" -> "전년 대비 GAP(%)"
|
||||
* - "gap" -> "전년 대비 GAP(%p)"
|
||||
* - "CAGR" -> "CAGR(%)"
|
||||
* - "24" -> "24년"
|
||||
* - "보급율" -> "보급율(%)"
|
||||
@@ -18,7 +22,7 @@ export function formatRowLabel(
|
||||
label: string,
|
||||
options?: {
|
||||
convertSample?: boolean; // "사례수" -> "(사례수)" (기본값: true)
|
||||
convertGap?: boolean; // "gap" -> "전년 대비 GAP(%)" (기본값: true)
|
||||
convertGap?: boolean; // "gap" -> "전년 대비 GAP(%p)" (기본값: true)
|
||||
convertCagr?: boolean; // "CAGR" -> "CAGR(%)" (기본값: true)
|
||||
convertYear?: boolean; // "24" -> "24년" (기본값: true)
|
||||
convertRate?: boolean; // "~율" -> "~율(%)" (기본값: true)
|
||||
@@ -37,11 +41,11 @@ export function formatRowLabel(
|
||||
const t = label.trim();
|
||||
|
||||
if (convertSample && t === "사례수") return "(사례수)";
|
||||
if (convertGap && t.toLowerCase() === "gap") return "전년 대비 GAP(%)";
|
||||
if (convertCagr && t.toUpperCase() === "CAGR") return "CAGR(%)";
|
||||
if (convertGap && t.toLowerCase() === "gap") return GAP_WORDING;
|
||||
if (convertCagr && t.toUpperCase() === "CAGR") return "CAGR(%p)";
|
||||
if (convertYear && /^\d{2}$/.test(t)) return `${t}년`;
|
||||
if (convertRate && t.endsWith("율")) return `${t}(%)`;
|
||||
if (convertCount && t.includes("대수")) return `${t}(대)`;
|
||||
if (convertRate && t.endsWith("율")) return `${t.replaceAll('(%)','')}(%)`;
|
||||
if (convertCount && t.includes("대수")) return `${t.replaceAll('(대)','')}(대)`;
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user