260330_01_ENH: 26일자 수정사항 반영(라이프스테이지 중분류 제외)
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
'use client'
|
||||
|
||||
import {DataColumn} from "@/components/lge-dashboard";
|
||||
import BannerSummary from "@/components/lge-dashboard/combo/BannerSummary";
|
||||
import {useMemo} from "react";
|
||||
import {parseNumber} from "@/lib/utils";
|
||||
import {BannerRow} from "@/types/lg.types";
|
||||
import {CategoryPageProps} from "../../sub-page/CategoryPage";
|
||||
import {LAST_YEAR} from "@/const/lg-common.const";
|
||||
@@ -30,8 +32,33 @@ const PenetrationChange = ({
|
||||
return tempProfileData;
|
||||
}, [dataMap]);
|
||||
|
||||
const getCellClassName = (row: BannerRow, column: DataColumn<BannerRow>, rowIndex: number) => {
|
||||
const currentYear = Number(row.year);
|
||||
if (currentYear !== 2024 && currentYear !== 2025) return undefined;
|
||||
if (column.key === "rowLabel" || column.key === "total") return undefined;
|
||||
|
||||
const prevRow = penetrationChangeData[rowIndex - 1];
|
||||
if (!prevRow || Number(prevRow.year) !== currentYear - 1) return undefined;
|
||||
|
||||
const currentValue = parseNumber(row[column.key]);
|
||||
const prevValue = parseNumber(prevRow[column.key]);
|
||||
if (currentValue === null || prevValue === null) return undefined;
|
||||
|
||||
const gap = currentValue - prevValue;
|
||||
|
||||
if (gap >= 3) return "lg-num-pos";
|
||||
if (gap <= -3) return "lg-num-neg";
|
||||
|
||||
return undefined;
|
||||
};
|
||||
|
||||
return(
|
||||
<BannerSummary data={penetrationChangeData} useChart={true} useYear={false} />
|
||||
<BannerSummary
|
||||
data={penetrationChangeData}
|
||||
useChart={true}
|
||||
useYear={false}
|
||||
getCellClassName={getCellClassName}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ import {
|
||||
calcGapProductRow, calcTotalBaseRow,
|
||||
formatRowLabel,
|
||||
normalizeFilterCondition,
|
||||
withGapRow, withTotalBaseRow
|
||||
withGapRow, withTotalBaseRow, wrapSampleRow
|
||||
} from "@/lib/lg-dashboard";
|
||||
import {
|
||||
buildHeader_LifeStageColumns,
|
||||
@@ -83,21 +83,23 @@ const LGPenetrationPage = () => {
|
||||
|
||||
const penetrationRows =
|
||||
data?.statisticsDataMap?.penetration
|
||||
.filter((r) => r.rowLabel == `보유`)
|
||||
.filter((r) => r.rowLabel == `보유` || r.rowLabel == `사례수`)
|
||||
.map((row) => {
|
||||
const rowLabel = row.rowLabel == `사례수`? `${formatRowLabel(row.year)} ${row.rowLabel}` : row.year;
|
||||
return {
|
||||
...row,
|
||||
rowLabel: row.year,
|
||||
rowLabel: rowLabel,
|
||||
}
|
||||
}) ?? [];
|
||||
|
||||
const penetrationLGRows =
|
||||
data?.statisticsDataMap?.penetration_lg
|
||||
.filter((row) => row.rowLabel === `보유`)
|
||||
.filter((r) => r.rowLabel == `보유` || r.rowLabel == `사례수`)
|
||||
.map((row) => {
|
||||
const rowLabel = row.rowLabel == `사례수`? `${formatRowLabel(row.year)} ${row.rowLabel}` : row.year;
|
||||
return {
|
||||
...row,
|
||||
rowLabel: row.year,
|
||||
rowLabel: rowLabel,
|
||||
}
|
||||
}) ?? [];
|
||||
|
||||
@@ -122,8 +124,9 @@ const LGPenetrationPage = () => {
|
||||
}, [penetrationLGRows]);
|
||||
|
||||
const penetrationLGRowsWithGap = useMemo(() => {
|
||||
const withGap = withGapRow(penetrationLGRows, calcGapProductRow);
|
||||
return withTotalBaseRow("보급률",penetrationRows, withGap, calcTotalBaseRow);
|
||||
const withGap = withGapRow(penetrationLGRows, calcGapProductRow, -1, -3);
|
||||
|
||||
return withTotalBaseRow("보급률",penetrationRows, wrapSampleRow(withGap, false), calcTotalBaseRow);
|
||||
}, [penetrationRows, penetrationLGRows]);
|
||||
|
||||
const productTableRows = useMemo<TopChartTableRow[]>(() => {
|
||||
|
||||
@@ -25,7 +25,7 @@ import {
|
||||
calcGapProductRow, calcTotalBaseRow,
|
||||
formatRowLabel,
|
||||
normalizeFilterCondition,
|
||||
withGapRow, withTotalBaseRow
|
||||
withGapRow, withTotalBaseRow, wrapSampleRow
|
||||
} from "@/lib/lg-dashboard";
|
||||
import {buildHeader_ProductKeyMap, exportDashboardExcel} from "@/lib/lg-export-excel";
|
||||
import {useDebouncedValue} from "@/hooks/useDebouncedValue";
|
||||
@@ -55,26 +55,28 @@ const LGPurchasePage = () => {
|
||||
|
||||
const purchaseRows =
|
||||
data?.statisticsDataMap?.purchase
|
||||
.filter((r) => r.rowLabel == `구매`)
|
||||
.filter((r) => r.rowLabel == `구매` || r.rowLabel == `사례수`)
|
||||
.map((row) => {
|
||||
const rowLabel = row.rowLabel == `사례수`? `${formatRowLabel(row.year)} ${row.rowLabel}` : row.year;
|
||||
return {
|
||||
...row,
|
||||
rowLabel: row.year,
|
||||
rowLabel: rowLabel,
|
||||
}
|
||||
}) ?? [];
|
||||
|
||||
const purchaseLGRows =
|
||||
data?.statisticsDataMap?.purchase_lg
|
||||
.filter((row) => row.rowLabel === `구입`)
|
||||
.filter((row) => row.rowLabel === `구입` || row.rowLabel == `사례수`)
|
||||
.map((row) => {
|
||||
const rowLabel = row.rowLabel == `사례수`? `${formatRowLabel(row.year)} ${row.rowLabel}` : row.year;
|
||||
return {
|
||||
...row,
|
||||
rowLabel: row.year,
|
||||
rowLabel: rowLabel,
|
||||
}
|
||||
}) ?? [];
|
||||
|
||||
const purchaseLGRowsWithGap = useMemo(() => {
|
||||
const withGap = withGapRow(purchaseLGRows, calcGapProductRow);
|
||||
const withGap = withGapRow(wrapSampleRow(purchaseLGRows, false), calcGapProductRow, -1, -3);
|
||||
return withTotalBaseRow("구입율",purchaseRows, withGap, calcTotalBaseRow);
|
||||
}, [purchaseRows, purchaseLGRows]);
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ import { AXIS_HIDE_STYLE, GRID_X_NOT_PADDING } from "@/components/lge-dashboard/
|
||||
import {
|
||||
calcCagrRow, calcGapProductRow,
|
||||
formatRowLabel,
|
||||
normalizeFilterCondition, withCagrRow, withGapRow
|
||||
normalizeFilterCondition, withCagrRow, withGapRow, wrapSampleRow
|
||||
} from "@/lib/lg-dashboard";
|
||||
import {buildHeader_ProductKeyMap, exportDashboardExcel, Section} from "@/lib/lg-export-excel";
|
||||
import {StatisticsRequest} from "@/types/lg.types";
|
||||
@@ -56,21 +56,39 @@ const PenetrationPage = () => {
|
||||
|
||||
const penetrationRows =
|
||||
data?.statisticsDataMap?.penetration
|
||||
.filter((r) => r.rowLabel == `보유`)
|
||||
.filter((r) => r.rowLabel == `보유` || r.rowLabel == `사례수`)
|
||||
.map((row) => {
|
||||
const rowLabel = row.rowLabel == `사례수`? `${formatRowLabel(row.year)} ${row.rowLabel}` : row.year;
|
||||
return {
|
||||
...row,
|
||||
rowLabel: row.year,
|
||||
rowLabel: rowLabel,
|
||||
}
|
||||
}) ?? [];
|
||||
|
||||
const penetrationBrandRows =
|
||||
const penetrationBrandRows = (
|
||||
data?.statisticsDataMap?.penetration_brand
|
||||
.filter((row) => BRAND_LIST.includes(row.rowLabel)) ?? [];
|
||||
?.filter((row) => BRAND_LIST.includes(row.rowLabel)) ?? []
|
||||
).map((row) => {
|
||||
PRODUCT_KEYS.forEach((k) => {
|
||||
(row as any)[k] = Number((row as any)[k]).toFixed(0);
|
||||
});
|
||||
|
||||
return row;
|
||||
});
|
||||
|
||||
const penetrationRowsWithGapCagr = useMemo(() => {
|
||||
const withGap = withGapRow(penetrationRows, calcGapProductRow);
|
||||
return withCagrRow(withGap, calcCagrRow);
|
||||
const withGap = withGapRow(penetrationRows, calcGapProductRow, -1, -3);
|
||||
const withCagr = withCagrRow(withGap, calcCagrRow, -1, 2);
|
||||
|
||||
withCagr.forEach((row) => {
|
||||
if (row.rowLabel !== "CAGR") {
|
||||
PRODUCT_KEYS.forEach((k) => {
|
||||
(row as any)[k] = Number((row as any)[k]).toFixed(0);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return wrapSampleRow(withCagr, false);
|
||||
}, [penetrationRows]);
|
||||
|
||||
const productTableRows = useMemo<TopChartTableRow[]>(() => {
|
||||
@@ -84,7 +102,7 @@ const PenetrationPage = () => {
|
||||
const productChartData = useMemo<ChartData>(() => {
|
||||
return {
|
||||
categories: [...PRODUCTS],
|
||||
series: penetrationRows
|
||||
series: penetrationRows.filter((r) => !r.rowLabel.includes("사례수"))
|
||||
.map((row) => ({
|
||||
name: row.year,
|
||||
data: PRODUCT_KEYS.map((k) => toNumOr0((row as any)[k])),
|
||||
@@ -148,7 +166,7 @@ const PenetrationPage = () => {
|
||||
});
|
||||
});
|
||||
return () => registerExcelExporter(null);
|
||||
}, [registerExcelExporter, penetrationRows, penetrationBrandRows]);
|
||||
}, [registerExcelExporter, penetrationRowsWithGapCagr, penetrationBrandRows]);
|
||||
|
||||
return (
|
||||
<div>
|
||||
@@ -158,12 +176,12 @@ const PenetrationPage = () => {
|
||||
variant={isBrandShare ? "default" : "secondary"}
|
||||
onClick={() => setIsBrandShare((v) => !v)}
|
||||
>
|
||||
{"브랜드별 점유율"}
|
||||
{"브랜드 점유율 변화"}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<TopChartTable
|
||||
title={isBrandShare ? "브랜드별 점유율" : "전체 보급률"}
|
||||
title={isBrandShare ? "브랜드 점유율 변화" : "전체 보급률"}
|
||||
categories={[...PRODUCTS]}
|
||||
rows={productTableRows}
|
||||
chart={
|
||||
@@ -174,7 +192,7 @@ const PenetrationPage = () => {
|
||||
xAxis={{ type: "category", data: PRODUCTS, ...AXIS_HIDE_STYLE }}
|
||||
yAxis={{ type: "value", ...AXIS_HIDE_STYLE }}
|
||||
showFocusLabel={"none"}
|
||||
yearBrandPalette={["--chart-lg","--chart-samsung","--chart-cbrand"]}
|
||||
yearBrandPalette={[ "--chart-etc", "--chart-cbrand","--chart-samsung","--chart-lg"]}
|
||||
height={260}
|
||||
/>
|
||||
) : (
|
||||
@@ -192,6 +210,7 @@ const PenetrationPage = () => {
|
||||
signStyle={signStyleGapRow}
|
||||
fillCAGR={true}
|
||||
/>
|
||||
<BottomDescription description={"CAGR(%) 5%p 이상 품목에 대해 음영 표시"} />
|
||||
<BottomDescription description={description} />
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -21,7 +21,13 @@ import {
|
||||
VerticalBar,
|
||||
} from "@/components/lge-dashboard";
|
||||
import { useLayoutFilter } from "@/components/layout/LayoutFilterContext";
|
||||
import {calcGapProductRow, formatRowLabel, normalizeFilterCondition, withGapRow} from "@/lib/lg-dashboard";
|
||||
import {
|
||||
calcGapProductRow,
|
||||
formatRowLabel,
|
||||
normalizeFilterCondition,
|
||||
withGapRow,
|
||||
wrapSampleRow
|
||||
} from "@/lib/lg-dashboard";
|
||||
import {buildHeader_ProductKeyMap, exportDashboardExcel} from "@/lib/lg-export-excel";
|
||||
import {useDebouncedValue} from "@/hooks/useDebouncedValue";
|
||||
import {SelectedMap} from "@/types/common";
|
||||
@@ -49,16 +55,17 @@ const PurchasePage = () => {
|
||||
|
||||
const purchaseRows =
|
||||
data?.statisticsDataMap?.purchase
|
||||
.filter((r) => r.rowLabel == `구매`)
|
||||
.filter((r) => r.rowLabel == `구매` || r.rowLabel == `사례수`)
|
||||
.map((row) => {
|
||||
const rowLabel = row.rowLabel == `사례수`? `${formatRowLabel(row.year)} ${row.rowLabel}` : row.year;
|
||||
return {
|
||||
...row,
|
||||
rowLabel: row.year,
|
||||
rowLabel: rowLabel,
|
||||
}
|
||||
}) ?? [];
|
||||
|
||||
const purchaseRowsWithGap = useMemo(() => {
|
||||
return withGapRow(purchaseRows, calcGapProductRow);
|
||||
return withGapRow(wrapSampleRow(purchaseRows, false), calcGapProductRow, -1, -3);
|
||||
}, [purchaseRows]);
|
||||
|
||||
const purchaseTableRows = useMemo<TopChartTableRow[]>(() => {
|
||||
@@ -72,7 +79,7 @@ const PurchasePage = () => {
|
||||
const purchaseChartData = useMemo<ChartData>(() => {
|
||||
return {
|
||||
categories: [...PRODUCTS],
|
||||
series: purchaseRows
|
||||
series: purchaseRows.filter((r) => !r.rowLabel.includes("사례수"))
|
||||
.map((r) => ({
|
||||
name: r.rowLabel,
|
||||
data: PRODUCT_KEYS.map((k) => (r as any)[k] ?? null),
|
||||
|
||||
@@ -123,11 +123,6 @@
|
||||
--lg-orange-500: 29.6 95% 56.0%;
|
||||
--lg-orange-400: 29.6 85% 68.0%;
|
||||
--lg-orange-300: 29.6 75% 78.0%;
|
||||
|
||||
--samsung-blue-600: 218.93 53.91% 52.35%; /* #4472C7 */
|
||||
--samsung-blue-500: 218.93 48.0% 56.0%; /* #597FC5 */
|
||||
--samsung-blue-400: 218.93 40.0% 66.0%; /* #869ECB */
|
||||
--samsung-blue-300: 218.93 33.0% 76.0%; /* #AEBCD6 */
|
||||
/* =============================
|
||||
Brand Core
|
||||
(semantic은 "실제 색"으로 정의)
|
||||
@@ -172,23 +167,25 @@
|
||||
--chart-2-t: 0 0% 70%;
|
||||
--chart-3-t: 0 0% 88%;
|
||||
|
||||
--chart-stack-1: 334 81% 41%;
|
||||
--chart-stack-2: 334 81% 53%;
|
||||
--chart-stack-3: 334 82% 64%;
|
||||
--chart-stack-4: 335 82% 75%;
|
||||
--chart-stack-5: 335 83% 84%;
|
||||
--chart-stack-6: 17 80% 84%;
|
||||
--chart-stack-7: 17 80% 73%;
|
||||
--chart-stack-8: 0 0% 25%;
|
||||
--chart-stack-9: 0 0% 37%;
|
||||
--chart-stack-10: 0 0% 49%;
|
||||
--chart-stack-11: 0 0% 61%;
|
||||
--chart-stack-12: 0 0% 73%;
|
||||
--chart-stack-13: 0 0% 85%;
|
||||
--chart-stack-1: 335 64% 34%;
|
||||
--chart-stack-2: 332 65% 57%;
|
||||
--chart-stack-3: 334 66% 73%;
|
||||
--chart-stack-4: 334 28% 49%;
|
||||
--chart-stack-5: 340 25% 58%;
|
||||
--chart-stack-6: 0 28% 69%;
|
||||
--chart-stack-7: 26 37% 70%;
|
||||
--chart-stack-8: 27 38% 83%;
|
||||
--chart-stack-9: 30 45% 91%;
|
||||
--chart-stack-10: 0 0% 50%;
|
||||
--chart-stack-11: 0 0% 60%;
|
||||
--chart-stack-12: 0 0% 71%;
|
||||
--chart-stack-13: 0 0% 82%;
|
||||
--chart-stack-14: 0 0% 91%;
|
||||
|
||||
--chart-lg: var(--chart-1);
|
||||
--chart-samsung: 218 48% 58%;
|
||||
--chart-cbrand: var(--chart-2);
|
||||
--chart-etc: 0 0% 74%;
|
||||
|
||||
--chart-border: hsl(0 0% 95%);
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import { useAtomValue } from "jotai";
|
||||
import { Loader2Icon } from "lucide-react";
|
||||
import { loadingAtom } from "@/store/jotai/loading";
|
||||
|
||||
export function LoadingOverlay({ force = false }: { force?: boolean }) {
|
||||
@@ -9,9 +10,11 @@ export function LoadingOverlay({ force = false }: { force?: boolean }) {
|
||||
if (!force && !isLoading) return null;
|
||||
|
||||
return (
|
||||
<div className="fixed inset-0 z-[9999] bg-black/70 flex items-center justify-center">
|
||||
{/* 심플 로딩 인디케이터 */}
|
||||
<div className="h-12 w-12 rounded-full border-4 border-gray-400 border-t-white animate-spin" />
|
||||
<div className="fixed inset-0 z-[9999] flex items-center justify-center bg-black/65">
|
||||
<div className="flex flex-col items-center gap-3">
|
||||
<Loader2Icon className="size-20 animate-spin text-white" style={{ animationDuration: "0.7s" }} />
|
||||
<div className="text-sm font-medium tracking-[0.18em] text-white/90">Loading</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,11 @@ type Props = {
|
||||
yAxis?: EChartsOption["yAxis"];
|
||||
barMaxWidth?: number;
|
||||
showFocusLabel?:ShowLabel;
|
||||
labelOptions?: {
|
||||
position?: "right" | "insideRight";
|
||||
color?: string;
|
||||
distance?: number;
|
||||
};
|
||||
};
|
||||
|
||||
const HorizontalBar = ({
|
||||
@@ -43,6 +48,7 @@ const HorizontalBar = ({
|
||||
yAxis,
|
||||
barMaxWidth,
|
||||
showFocusLabel = "all",
|
||||
labelOptions,
|
||||
}: Props) => {
|
||||
const palette = useMemo(() => buildLgPalette(paletteVarNames), [paletteVarNames]);
|
||||
|
||||
@@ -68,14 +74,16 @@ const HorizontalBar = ({
|
||||
label: showLabel
|
||||
? {
|
||||
show: true,
|
||||
position: "right",
|
||||
position: labelOptions?.position ?? "right",
|
||||
color: labelOptions?.color,
|
||||
distance: labelOptions?.distance,
|
||||
formatter: (p: any) => (p?.value ?? "") as any,
|
||||
}
|
||||
: undefined,
|
||||
};
|
||||
}),
|
||||
};
|
||||
}, [data, palette, valueFormatter, tooltip, legend, grid, xAxis, yAxis, barMaxWidth, showFocusLabel]);
|
||||
}, [data, palette, valueFormatter, tooltip, legend, grid, xAxis, yAxis, barMaxWidth, showFocusLabel, labelOptions]);
|
||||
|
||||
return <BaseEChart option={option} height={height} className={className} />;
|
||||
}
|
||||
|
||||
@@ -79,9 +79,10 @@ type BannerSummaryProps = {
|
||||
data: BannerRow[];
|
||||
useChart: boolean;
|
||||
useYear: boolean;
|
||||
getCellClassName?: (row: BannerRow, column: DataColumn<BannerRow>, rowIndex: number) => string | undefined;
|
||||
};
|
||||
|
||||
const BannerSummary = ({ data, useChart, useYear }: BannerSummaryProps) => {
|
||||
const BannerSummary = ({ data, useChart, useYear, getCellClassName }: BannerSummaryProps) => {
|
||||
const {filterValue, registerExcelExporter } = useLayoutFilter();
|
||||
const debouncedFilterValue = useDebouncedValue<CategoryFilterValue>(filterValue as CategoryFilterValue, 500);
|
||||
|
||||
@@ -179,12 +180,14 @@ const BannerSummary = ({ data, useChart, useYear }: BannerSummaryProps) => {
|
||||
title={sectionRow.specTitle}
|
||||
columns={sectionRow.columns}
|
||||
rows={sectionRow.rows}
|
||||
getCellClassName={getCellClassName}
|
||||
signStyle={signStyleGap}
|
||||
chart={
|
||||
<HorizontalBar
|
||||
data={sectionRow.chartData}
|
||||
height="100%"
|
||||
showFocusLabel="none"
|
||||
showFocusLabel="all"
|
||||
labelOptions={{ position: "insideRight", color: "#fff", distance: 4 }}
|
||||
legend={{ show: false }}
|
||||
grid={GRID_Y_NOT_PADDING}
|
||||
xAxis={{ type: "value", show: false }}
|
||||
|
||||
@@ -68,6 +68,14 @@ const CategoryByData = ({
|
||||
cellClassName: "lg-table__rowhead",
|
||||
width: 120,
|
||||
},
|
||||
{
|
||||
key: "total",
|
||||
header: `전체`,
|
||||
headRowSpan: 2,
|
||||
numeric: true,
|
||||
cellClassName: "lg-table__rowhead",
|
||||
width: 120,
|
||||
},
|
||||
];
|
||||
|
||||
const g = BANNER_GROUP[groupKey];
|
||||
|
||||
@@ -26,6 +26,7 @@ type Props<T extends Record<string, unknown>> = {
|
||||
minWidth?: number;
|
||||
starUnder30Sample?: boolean;
|
||||
unitText?: string;
|
||||
getCellClassName?: (row: T, column: DataColumn<T>, rowIndex: number) => string | undefined;
|
||||
};
|
||||
|
||||
export default function LeftChartTable<T extends Record<string, unknown>>({
|
||||
@@ -41,7 +42,8 @@ export default function LeftChartTable<T extends Record<string, unknown>>({
|
||||
minWidth,
|
||||
starUnder30Sample = true,
|
||||
unitText = UNIT_TEXT,
|
||||
}: Props<T>) {
|
||||
getCellClassName,
|
||||
}: Readonly<Props<T>>) {
|
||||
return (
|
||||
<BaseDataTable
|
||||
columns={columns}
|
||||
@@ -59,6 +61,7 @@ export default function LeftChartTable<T extends Record<string, unknown>>({
|
||||
}}
|
||||
starUnder30Sample={starUnder30Sample}
|
||||
unitText={unitText}
|
||||
getCellClassName={getCellClassName}
|
||||
mergedCell={{
|
||||
key: chartCell.key,
|
||||
content: chart,
|
||||
|
||||
@@ -5,7 +5,7 @@ import { cn, parseNumber } from "@/lib/utils";
|
||||
import type { ChartData, SignStyle, TopChartTableRow } from "../types";
|
||||
import { CHART_HEIGHTS, TABLE_DIMENSIONS } from "@/components/lge-dashboard/chart/chart.config";
|
||||
import { UNIT_TEXT } from "@/const/lg-common.const";
|
||||
import { isCagrRow } from "@/lib/lg-dashboard";
|
||||
import {isCagrRow, isSampleRow} from "@/lib/lg-dashboard";
|
||||
import BaseTableHeader from "../table/core/BaseTableHeader";
|
||||
import { formatSignedValue, getSignTextClass, resolveSignStyle, toRoundedNumber } from "../table/core/table-core.helpers";
|
||||
|
||||
@@ -41,7 +41,7 @@ export default function TopChartTable({
|
||||
signStyle,
|
||||
fillCAGR = false,
|
||||
unitText = UNIT_TEXT,
|
||||
}: TopChartTableProps) {
|
||||
}: Readonly<TopChartTableProps>) {
|
||||
const resolvedSignStyle = resolveSignStyle(signStyle, {
|
||||
positiveTextClassName: "lg-num-pos",
|
||||
negativeTextClassName: "lg-num-neg",
|
||||
@@ -93,6 +93,7 @@ export default function TopChartTable({
|
||||
<tbody>
|
||||
{rows.map((row, rowIndex) => {
|
||||
const signRow = !!signStyle?.rowSelector?.(row, rowIndex);
|
||||
const sampleRow = isSampleRow(row.label ?? "");
|
||||
const cagrRow = isCagrRow(row.label ?? "");
|
||||
const rowTotal = parseNumber(row.total);
|
||||
|
||||
@@ -104,7 +105,12 @@ export default function TopChartTable({
|
||||
|
||||
{categories.map((_, categoryIndex) => {
|
||||
const rawValue = row.values?.[categoryIndex];
|
||||
const roundedValue = toRoundedNumber(rawValue);
|
||||
|
||||
if(sampleRow){
|
||||
return <td key={categoryIndex}>{rawValue}</td>;
|
||||
}
|
||||
|
||||
const roundedValue = toRoundedNumber(rawValue, cagrRow? 1 : 0);
|
||||
|
||||
if (!signRow) {
|
||||
if (roundedValue === null) {
|
||||
|
||||
@@ -32,6 +32,7 @@ type Props<T extends Record<string, unknown>> = {
|
||||
title?: string;
|
||||
wrapperClassName?: string;
|
||||
tableClassName?: string;
|
||||
subheadRowClassName?: string;
|
||||
minWidth?: number;
|
||||
signStyle?: SignStyle<T>;
|
||||
signStyleFallback?: Partial<ResolvedSignStyle>;
|
||||
@@ -39,6 +40,7 @@ type Props<T extends Record<string, unknown>> = {
|
||||
starUnder30Sample?: boolean;
|
||||
unitText?: string;
|
||||
mergedCell?: MergedTableCell<T>;
|
||||
getCellClassName?: (row: T, column: DataColumn<T>, rowIndex: number) => string | undefined;
|
||||
};
|
||||
|
||||
export default function BaseDataTable<T extends Record<string, unknown>>({
|
||||
@@ -47,6 +49,7 @@ export default function BaseDataTable<T extends Record<string, unknown>>({
|
||||
title,
|
||||
wrapperClassName,
|
||||
tableClassName,
|
||||
subheadRowClassName,
|
||||
minWidth,
|
||||
signStyle,
|
||||
signStyleFallback,
|
||||
@@ -54,7 +57,8 @@ export default function BaseDataTable<T extends Record<string, unknown>>({
|
||||
starUnder30Sample = false,
|
||||
unitText,
|
||||
mergedCell,
|
||||
}: Props<T>) {
|
||||
getCellClassName,
|
||||
}: Readonly<Props<T>>) {
|
||||
const resolvedSignStyle = resolveSignStyle(signStyle, signStyleFallback);
|
||||
const mergedCellStart = mergedCell?.startRowIndex ?? 0;
|
||||
const mergedCellSpan = mergedCell?.rowSpan ?? Math.max(0, rows.length - mergedCellStart);
|
||||
@@ -67,6 +71,7 @@ export default function BaseDataTable<T extends Record<string, unknown>>({
|
||||
showSampleNotice={starUnder30Sample}
|
||||
wrapperClassName={wrapperClassName}
|
||||
tableClassName={tableClassName}
|
||||
subheadRowClassName={subheadRowClassName}
|
||||
minWidth={minWidth}
|
||||
>
|
||||
{rows.map((row, rowIndex) => {
|
||||
@@ -77,6 +82,8 @@ export default function BaseDataTable<T extends Record<string, unknown>>({
|
||||
return (
|
||||
<tr key={rowIndex}>
|
||||
{columns.map((column) => {
|
||||
const dynamicCellClassName = getCellClassName?.(row, column, rowIndex);
|
||||
|
||||
if (mergedCell && column.key === mergedCell.key && rowIndex >= mergedCellStart) {
|
||||
if (rowIndex > mergedCellStart) {
|
||||
return null;
|
||||
@@ -105,7 +112,7 @@ export default function BaseDataTable<T extends Record<string, unknown>>({
|
||||
<th
|
||||
key={String(column.key)}
|
||||
scope="row"
|
||||
className={cn("lg-table__rowhead", column.cellClassName)}
|
||||
className={cn("lg-table__rowhead", column.cellClassName, dynamicCellClassName)}
|
||||
style={{ textAlign: align }}
|
||||
>
|
||||
{defaultContent}
|
||||
@@ -122,7 +129,7 @@ export default function BaseDataTable<T extends Record<string, unknown>>({
|
||||
: { textAlign: align };
|
||||
|
||||
return (
|
||||
<td key={String(column.key)} className={column.cellClassName} style={cellStyle}>
|
||||
<td key={String(column.key)} className={cn(column.cellClassName, dynamicCellClassName)} style={cellStyle}>
|
||||
<span className={cn(roundedValue === null ? "text-gray-500" : getSignTextClass(roundedValue, resolvedSignStyle))}>
|
||||
{displayText}
|
||||
</span>
|
||||
@@ -137,7 +144,7 @@ export default function BaseDataTable<T extends Record<string, unknown>>({
|
||||
return (
|
||||
<td
|
||||
key={String(column.key)}
|
||||
className={cn(column.cellClassName, shouldFillCell ? "bg-red-200" : "")}
|
||||
className={cn(column.cellClassName, dynamicCellClassName, shouldFillCell ? "bg-red-200" : "")}
|
||||
style={{ textAlign: align }}
|
||||
>
|
||||
{displayContent}
|
||||
|
||||
@@ -11,6 +11,7 @@ type Props<T extends Record<string, unknown>> = {
|
||||
className?: string;
|
||||
tableClassName?: string;
|
||||
wrapperClassName?: string;
|
||||
subheadRowClassName?: string;
|
||||
signStyle?: SignStyle<T>;
|
||||
fillGreaterThan5?: boolean;
|
||||
starUnder30Sample?: boolean;
|
||||
@@ -24,6 +25,7 @@ const DataTable = <T extends Record<string, unknown>>({
|
||||
className,
|
||||
tableClassName,
|
||||
wrapperClassName,
|
||||
subheadRowClassName,
|
||||
signStyle,
|
||||
fillGreaterThan5 = false,
|
||||
starUnder30Sample = false,
|
||||
@@ -36,6 +38,7 @@ const DataTable = <T extends Record<string, unknown>>({
|
||||
title={title}
|
||||
tableClassName={tableClassName ?? className}
|
||||
wrapperClassName={wrapperClassName}
|
||||
subheadRowClassName={subheadRowClassName}
|
||||
signStyle={signStyle}
|
||||
fillGreaterThan5={fillGreaterThan5}
|
||||
starUnder30Sample={starUnder30Sample}
|
||||
|
||||
@@ -21,6 +21,7 @@ type Props<T> = {
|
||||
showSampleNotice?: boolean;
|
||||
wrapperClassName?: string;
|
||||
tableClassName?: string;
|
||||
subheadRowClassName?: string;
|
||||
minWidth?: number | string;
|
||||
colgroup?: React.ReactNode;
|
||||
renderHeaderPrefix?: React.ReactNode;
|
||||
@@ -34,11 +35,12 @@ export default function BaseTableRenderer<T>({
|
||||
showSampleNotice = false,
|
||||
wrapperClassName,
|
||||
tableClassName,
|
||||
subheadRowClassName,
|
||||
minWidth,
|
||||
colgroup,
|
||||
renderHeaderPrefix,
|
||||
children,
|
||||
}: Props<T>) {
|
||||
}: Readonly<Props<T>>) {
|
||||
const groupedHeader = hasGroupedHeader(columns);
|
||||
const groupHeaderCells = buildGroupHeaderCells(columns);
|
||||
|
||||
@@ -68,7 +70,7 @@ export default function BaseTableRenderer<T>({
|
||||
))}
|
||||
</tr>
|
||||
) : null}
|
||||
<tr className={groupedHeader ? "lg-table__subhead" : undefined}>
|
||||
<tr className={cn(groupedHeader ? "lg-table__subhead" : undefined, subheadRowClassName)}>
|
||||
{columns
|
||||
.filter((column) => column.headRowSpan !== 2)
|
||||
.map((column) => (
|
||||
|
||||
@@ -154,9 +154,9 @@ export function toTableCellContent(raw: unknown): React.ReactNode {
|
||||
return String(raw);
|
||||
}
|
||||
|
||||
export function toRoundedNumber(raw: unknown) {
|
||||
export function toRoundedNumber(raw: unknown, decimalPoint?: number) {
|
||||
const parsed = parseNumber(raw);
|
||||
return parsed === null ? null : roundNumber(parsed);
|
||||
return parsed === null ? null : roundNumber(parsed, decimalPoint);
|
||||
}
|
||||
|
||||
export function appendCellMarker(content: React.ReactNode, marker: string) {
|
||||
|
||||
@@ -11,4 +11,4 @@ export const GAP_WORDING = "전년 대비 GAP(%p)";
|
||||
export const UNIT_TEXT = "(단위 %)"
|
||||
export const SAMPLE_SIZE_NOTICE = "* 30표본 미만 해석에 주의";
|
||||
|
||||
export const BRAND_LIST = ['Cbrand', '삼성', 'LG'];
|
||||
export const BRAND_LIST = ['기타', 'C Brand', '삼성', 'LG'];
|
||||
|
||||
@@ -7,8 +7,8 @@ export const PRODUCT_KEY_MAP = {
|
||||
"KPRODUCT#6": "음식물처리기",
|
||||
|
||||
"KPRODUCT#7": "세탁기",
|
||||
"KPRODUCT#8": "청소기",
|
||||
"KPRODUCT#9": "건조기",
|
||||
"KPRODUCT#8": "청소기",
|
||||
"KPRODUCT#10": "로봇 청소기",
|
||||
"KPRODUCT#11": "의류 관리기",
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ export function formatRowLabel(
|
||||
|
||||
if (convertSample && t === "사례수") return "(사례수)";
|
||||
if (convertGap && t.toLowerCase() === "gap") return GAP_WORDING;
|
||||
if (convertCagr && t.toUpperCase() === "CAGR") return "CAGR(%p)";
|
||||
if (convertCagr && t.toUpperCase() === "CAGR") return "CAGR(%)";
|
||||
if (convertYear && /^\d{4}$/.test(t)) return `${t.substring(2,4)}년`;
|
||||
if (convertYear && /^\d{2}$/.test(t)) return `${t}년`;
|
||||
if (convertRate && t.endsWith("율")) return `${t.replaceAll('(%)','')}(%)`;
|
||||
@@ -63,7 +63,7 @@ export function formatRowLabel(
|
||||
}
|
||||
|
||||
export const wrapSampleRow = <T extends Record<string, unknown> & { rowLabel: string }>(
|
||||
rows: T[]
|
||||
rows: T[], replaceLabel: boolean = true
|
||||
): T[] => {
|
||||
return rows.map((r) => {
|
||||
if (!isSampleRow(r.rowLabel)) return r;
|
||||
@@ -73,18 +73,23 @@ export const wrapSampleRow = <T extends Record<string, unknown> & { rowLabel: st
|
||||
Object.entries(r).forEach(([k, v]) => {
|
||||
if (k == "year" || v == null) return;
|
||||
|
||||
if (typeof v === "number") {
|
||||
out[k] = `(${formatNumber(v)})`;
|
||||
if (
|
||||
typeof v === "number" ||
|
||||
(typeof v === "string" && v.trim() !== "" && !Number.isNaN(Number(v)))
|
||||
) {
|
||||
out[k] = `(${formatNumber(Number(v))})`;
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof v === "string") {
|
||||
// 이미 괄호면 그대로
|
||||
out[k] = v.startsWith("(") && v.endsWith(")") ? v : `(${v})`;
|
||||
return;
|
||||
}
|
||||
if(replaceLabel){
|
||||
if (typeof v === "string") {
|
||||
// 이미 괄호면 그대로
|
||||
out[k] = v.startsWith("(") && v.endsWith(")") ? v : `(${v})`;
|
||||
return;
|
||||
}
|
||||
|
||||
out[k] = `(${String(v)})`;
|
||||
out[k] = `(${String(v)})`;
|
||||
}
|
||||
});
|
||||
|
||||
return out as T;
|
||||
@@ -390,14 +395,16 @@ export const buildCategoryFilter = (
|
||||
return Object.keys(out).length ? out : undefined;
|
||||
}
|
||||
|
||||
const fixedDecimalPoint = (n: number): string => {
|
||||
return n.toFixed(API_DECIMAL_POINT);
|
||||
const fixedDecimalPoint = (n: number, decimalPoint?: number): string => {
|
||||
decimalPoint ??= API_DECIMAL_POINT;
|
||||
return n.toFixed(decimalPoint);
|
||||
};
|
||||
|
||||
export const roundNumber = (num: number|null) => {
|
||||
export const roundNumber = (num: number|null, decimalPoint?: number) => {
|
||||
if(num == null) return null;
|
||||
|
||||
const factor = 10 ** VIEW_DECIMAL_POINT;
|
||||
decimalPoint ??= VIEW_DECIMAL_POINT;
|
||||
const factor = 10 ** decimalPoint;
|
||||
return Math.round(num * factor) / factor;
|
||||
};
|
||||
|
||||
@@ -447,12 +454,12 @@ export const calcCagrRow = (after: ProductRow, before: ProductRow): ProductRow =
|
||||
|
||||
// total은 참고용으로만: (26/24) CAGR %
|
||||
out.total =
|
||||
fixedDecimalPoint((before?.total ?? "0") > "0" ? calcCagr(Number(after?.total ?? "0"), Number(before?.total ?? "0"), years) : 0);
|
||||
fixedDecimalPoint((before?.total ?? "0") > "0" ? calcCagr(Number(after?.total ?? "0"), Number(before?.total ?? "0"), years) : 0, 1);
|
||||
|
||||
for (const k of PRODUCT_KEYS) {
|
||||
const vBefore = before? before[k] ?? "0" : "0";
|
||||
const vAfter = after? after[k] ?? "0" : "0";
|
||||
out[k] = fixedDecimalPoint(Number(vBefore) > 0 ? calcCagr(Number(vAfter), Number(vBefore), years) : 0);
|
||||
out[k] = fixedDecimalPoint(Number(vBefore) > 0 ? calcCagr(Number(vAfter), Number(vBefore), years) : 0, 1);
|
||||
}
|
||||
return out;
|
||||
};
|
||||
@@ -465,7 +472,7 @@ export const makeTotalBasePct = (t:number|string, f:number|string):number => {
|
||||
export const calcTotalBaseRow = (label:string, totalRow: ProductRow, targetRow: ProductRow): ProductRow => {
|
||||
const out: ProductRow = {
|
||||
year: targetRow?.year ?? "",
|
||||
rowLabel: `조사 년도 ${label} 중 자사제품 비율`,
|
||||
rowLabel: `조사 년도 ${label} 중 자사제품 비율 (LG ${label} ÷ 전체 ${label}) × 100`,
|
||||
total: fixedDecimalPoint(makeTotalBasePct(totalRow.total, targetRow.total))
|
||||
};
|
||||
|
||||
@@ -480,20 +487,24 @@ export const calcTotalBaseRow = (label:string, totalRow: ProductRow, targetRow:
|
||||
|
||||
export const withGapRow = <T>(
|
||||
rows: T[],
|
||||
calcGapRow: (last: T, secondLast: T) => T
|
||||
calcGapRow: (last: T, secondLast: T) => T,
|
||||
lastIndex: number,
|
||||
secondLastIndex: number,
|
||||
): T[] => {
|
||||
const last = rows.at(-1);
|
||||
const secondLast = rows.at(-2);
|
||||
const last = rows.at(lastIndex);
|
||||
const secondLast = rows.at(secondLastIndex);
|
||||
if (!last || !secondLast) return rows;
|
||||
return [calcGapRow(last, secondLast), ...rows];
|
||||
}
|
||||
|
||||
export const withCagrRow = <T>(
|
||||
rows: T[],
|
||||
calcCagrRow: (last: T, first: T) => T
|
||||
calcCagrRow: (last: T, first: T) => T,
|
||||
lastIndex: number,
|
||||
firstIndex: number,
|
||||
): T[] => {
|
||||
const first = rows.at(1);
|
||||
const last = rows.at(-1);
|
||||
const first = rows.at(firstIndex);
|
||||
const last = rows.at(lastIndex);
|
||||
if (!first || !last) return rows;
|
||||
return [...rows, calcCagrRow(last, first)];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user