260209_01_ENH: 테이블에 단위 텍스트 추가, 하단 설명 추가
This commit is contained in:
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user