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