From 41a8e2abb284a2a543bbd1f3cf848c5f66823217 Mon Sep 17 00:00:00 2001 From: kric_jspark Date: Thu, 12 Mar 2026 13:28:21 +0900 Subject: [PATCH] =?UTF-8?q?260312=5F01=5FENH:=20API=5FDECIMAL=5FPOINT,=20V?= =?UTF-8?q?IEW=5FDECIMAL=5FPOINT=20=EC=A0=81=EC=9A=A9,=20=EC=8A=A4?= =?UTF-8?q?=ED=83=9D=20=EC=B0=A8=ED=8A=B8=20=EC=83=89=EC=83=81=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD,=20=EA=B7=B8=EB=A3=B9=20=EC=8A=A4=ED=83=9D=20?= =?UTF-8?q?=EC=B0=A8=ED=8A=B8=20=ED=95=98=EB=8B=A8=EC=97=90=20=EC=97=B0?= =?UTF-8?q?=EB=8F=84=20=EB=A0=88=EC=9D=B4=EB=B8=94=20=EC=B6=9C=EB=A0=A5,?= =?UTF-8?q?=20Total=20=ED=8E=98=EC=9D=B4=EC=A7=80=20=EC=84=A4=EB=AA=85?= =?UTF-8?q?=EB=AC=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../(main)/category/sub-page/CategoryPage.tsx | 4 +- .../(main)/total/lg-penetration/page.tsx | 8 +- .../(pages)/(main)/total/lg-purchase/page.tsx | 4 +- .../(pages)/(main)/total/penetration/page.tsx | 15 +--- .../(pages)/(main)/total/purchase/page.tsx | 4 +- src/app/globals.css | 44 ++++------ src/components/layout/MainLayout.tsx | 15 +++- src/components/lge-dashboard/BaseEChart.tsx | 49 ++++++++++- .../lge-dashboard/chart/GroupedStackBar.tsx | 31 ++++--- .../lge-dashboard/chart/StackBar.tsx | 4 +- src/components/lge-dashboard/color.ts | 29 +++++-- .../lge-dashboard/combo/LeftChartTable.tsx | 9 ++- .../lge-dashboard/combo/TopChartTable.tsx | 5 +- .../lge-dashboard/table/DataTable.tsx | 17 ++-- .../lge-dashboard/table/GaugeTable.tsx | 3 +- src/config/filter.data.ts | 2 + src/const/chartConst.ts | 81 +------------------ src/const/lgConst.ts | 8 ++ src/lib/lg-dashboard.ts | 38 +++++---- src/types/lg.ts | 2 + 20 files changed, 192 insertions(+), 180 deletions(-) diff --git a/src/app/(pages)/(main)/category/sub-page/CategoryPage.tsx b/src/app/(pages)/(main)/category/sub-page/CategoryPage.tsx index ffdbd07..4f018ce 100644 --- a/src/app/(pages)/(main)/category/sub-page/CategoryPage.tsx +++ b/src/app/(pages)/(main)/category/sub-page/CategoryPage.tsx @@ -7,7 +7,7 @@ import {BannerRow, CategoryResolvedField, StatisticsRequest} from "@/types/lg"; import {useDebouncedValue} from "@/hooks/useDebouncedValue"; import {CategoryFilterValue} from "@/components/layout/CategoryFilter"; import {buildCategoryFilter, buildPageModeConfig} from "@/lib/lg-dashboard"; -import {BANNER_GROUP_KEY, USE_CACHE} from "@/const/lgConst"; +import {BANNER_GROUP_KEY, API_DECIMAL_POINT, USE_CACHE} from "@/const/lgConst"; import Profile from "./category-page/Profile"; import PenetrationChange from "./category-page/PenetrationChange"; import CategoryDetail from "./category-page/CategoryDetail"; @@ -42,7 +42,7 @@ const CategoryPage = () => { variableIdMap, bannerIdList: BANNER_GROUP_KEY, filterCondition: buildCategoryFilter(debouncedFilterValue), - option: { useCache: USE_CACHE, lastYear: false, decimalPoint: 0 }, + option: { useCache: USE_CACHE, lastYear: false, decimalPoint: API_DECIMAL_POINT }, }; }, [variableIdMap, debouncedFilterValue]); diff --git a/src/app/(pages)/(main)/total/lg-penetration/page.tsx b/src/app/(pages)/(main)/total/lg-penetration/page.tsx index 81862c7..d28964a 100644 --- a/src/app/(pages)/(main)/total/lg-penetration/page.tsx +++ b/src/app/(pages)/(main)/total/lg-penetration/page.tsx @@ -10,7 +10,7 @@ import { } from "@/components/lge-dashboard"; import { CHART_COLOR_BY_YEAR, - CHART_FOCUS_COLOR_BY_YEAR, + CHART_FOCUS_COLOR_BY_YEAR, API_DECIMAL_POINT, LIFE_STAGE_COLUMNS, LIFE_STAGE_GROUPS, PRODUCT_KEY_MAP, @@ -48,7 +48,7 @@ const LGPenetrationPage = () => { variableIdMap: {penetration: "KQA1", penetration_lg: "KQA3_3_LG"}, bannerIdList: ["product"], filterCondition: normalizeFilterCondition(debouncedFilterValue), - option: {useCache: USE_CACHE, lastYear: false, decimalPoint: 0}, + option: {useCache: USE_CACHE, lastYear: false, decimalPoint: API_DECIMAL_POINT }, }; }, [debouncedFilterValue]); @@ -59,7 +59,7 @@ const LGPenetrationPage = () => { variableIdMap: {lifestage_lg: "KQA3_3_LG"}, bannerIdList: ["product|lifeStage"], filterCondition: normalizeFilterCondition(filter), - option: {useCache: USE_CACHE, lastYear: true, decimalPoint: 0}, + option: {useCache: USE_CACHE, lastYear: true, decimalPoint: API_DECIMAL_POINT }, }; }, [debouncedFilterValue]); @@ -181,6 +181,8 @@ const LGPenetrationPage = () => { "KLIFEstAGE#4": lifeStageData[`${key}|KLIFEstAGE#4`] ?? "", "KLIFEstAGE#5": lifeStageData[`${key}|KLIFEstAGE#5`] ?? "", "KLIFEstAGE#6": lifeStageData[`${key}|KLIFEstAGE#6`] ?? "", + "KLIFEstAGE#7": lifeStageData[`${key}|KLIFEstAGE#7`] ?? "", + "KLIFEstAGE#8": lifeStageData[`${key}|KLIFEstAGE#8`] ?? "", }; }); diff --git a/src/app/(pages)/(main)/total/lg-purchase/page.tsx b/src/app/(pages)/(main)/total/lg-purchase/page.tsx index 022fd61..82dd008 100644 --- a/src/app/(pages)/(main)/total/lg-purchase/page.tsx +++ b/src/app/(pages)/(main)/total/lg-purchase/page.tsx @@ -2,7 +2,7 @@ import {useEffect, useMemo} from "react"; import { - CHART_COLOR_BY_YEAR, CHART_FOCUS_COLOR_BY_YEAR, + CHART_COLOR_BY_YEAR, CHART_FOCUS_COLOR_BY_YEAR, API_DECIMAL_POINT, PRODUCT_KEY_MAP, PRODUCT_KEYS, SITE_TITLE, USE_CACHE, @@ -39,7 +39,7 @@ const LGPurchasePage = () => { variableIdMap: {purchase: "KQB0", purchase_lg: "KQX3_3_LG"}, bannerIdList: ["product"], filterCondition: normalizeFilterCondition(debouncedFilterValue), - option: {useCache: USE_CACHE, lastYear: false, decimalPoint: 0}, + option: {useCache: USE_CACHE, lastYear: false, decimalPoint: API_DECIMAL_POINT }, }; }, [debouncedFilterValue]); diff --git a/src/app/(pages)/(main)/total/penetration/page.tsx b/src/app/(pages)/(main)/total/penetration/page.tsx index 6c7d69d..37462b1 100644 --- a/src/app/(pages)/(main)/total/penetration/page.tsx +++ b/src/app/(pages)/(main)/total/penetration/page.tsx @@ -18,7 +18,7 @@ import { PRODUCTS, YEARS, AXIS_HIDE_STYLE, - GRID_X_NOT_PADDING, PRODUCT_KEY_MAP, SITE_TITLE, USE_CACHE + GRID_X_NOT_PADDING, PRODUCT_KEY_MAP, SITE_TITLE, USE_CACHE, API_DECIMAL_POINT } from "@/const/lgConst"; import { calcCagrRow, calcGapProductRow, @@ -37,19 +37,12 @@ const PenetrationPage = () => { const debouncedFilterValue = useDebouncedValue(filterValue as SelectedMap, 500); const [isBrandShare, setIsBrandShare] = useState(false); - const chartColorByYear = Object.fromEntries( - YEARS.map((year, i) => [ - year, - [`--chart-cbrand-${i + 1}`,`--chart-samsung-${i + 1}`,`--chart-lg-${i + 1}`], - ]) - ) as Record<(typeof YEARS)[number], string[]>; - const req = useMemo(() => { return { variableIdMap: { penetration: "KQA1", penetration_brand: "KQA3_3_NET" }, bannerIdList: ["product"], filterCondition: normalizeFilterCondition(debouncedFilterValue), - option: { useCache: USE_CACHE, lastYear: false, decimalPoint: 0 }, + option: { useCache: USE_CACHE, lastYear: false, decimalPoint: API_DECIMAL_POINT }, }; }, [debouncedFilterValue]); @@ -175,11 +168,11 @@ const PenetrationPage = () => { isBrandShare ? ( ) : ( diff --git a/src/app/(pages)/(main)/total/purchase/page.tsx b/src/app/(pages)/(main)/total/purchase/page.tsx index e12da13..8fbafa2 100644 --- a/src/app/(pages)/(main)/total/purchase/page.tsx +++ b/src/app/(pages)/(main)/total/purchase/page.tsx @@ -7,7 +7,7 @@ import { AXIS_HIDE_STYLE, GRID_X_NOT_PADDING, PRODUCT_KEY_MAP, - SITE_TITLE, USE_CACHE + SITE_TITLE, USE_CACHE, API_DECIMAL_POINT } from "@/const/lgConst"; import { BottomDescription, @@ -34,7 +34,7 @@ const PurchasePage = () => { variableIdMap: { purchase: "KQB0"}, bannerIdList: ["product"], filterCondition: normalizeFilterCondition(debouncedFilterValue), - option: { useCache: USE_CACHE, lastYear: false, decimalPoint: 0 }, + option: { useCache: USE_CACHE, lastYear: false, decimalPoint: API_DECIMAL_POINT }, }; }, [debouncedFilterValue]); diff --git a/src/app/globals.css b/src/app/globals.css index cfe6c90..ce67475 100644 --- a/src/app/globals.css +++ b/src/app/globals.css @@ -54,17 +54,6 @@ --color-warning: var(--warning); --color-info: var(--info); - /* Chart */ - --color-chart-1: var(--chart-1); - --color-chart-2: var(--chart-2); - --color-chart-3: var(--chart-3); - --color-chart-4: var(--chart-4); - --color-chart-5: var(--chart-5); - --color-chart-6: var(--chart-6); - --color-chart-7: var(--chart-7); - --color-chart-8: var(--chart-8); - --color-chart-9: var(--chart-9); - --color-chart-10: var(--chart-10); --color-chart-border: var(--chart-border); /* Sidebar (shadcn sidebar 토큰) */ @@ -183,26 +172,21 @@ --chart-2-t: 0 0% 70%; --chart-3-t: 0 0% 88%; - --chart-4: var(--lg-pink-400); - --chart-5: var(--lg-pink-600); - --chart-6: var(--lg-gray-500); - --chart-7: var(--lg-gray-600); - --chart-8: var(--lg-gray-700); - --chart-9: var(--lg-gray-800); - --chart-10: var(--lg-gray-900); + --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% 50%; + --chart-stack-10: 0 0% 65%; + --chart-stack-11: 0 0% 85%; - --chart-lg-1: var(--lg-pink-300); - --chart-lg-2: var(--lg-red-300); - --chart-lg-3: var(--lg-red-600); - --chart-total-1: var(--lg-gray-300); - --chart-total-2: var(--lg-gray-400); - --chart-total-3: var(--lg-gray-700); - --chart-cbrand-1: var(--lg-gray-300); - --chart-cbrand-2: var(--lg-gray-400); - --chart-cbrand-3: var(--lg-gray-700); - --chart-samsung-1: var(--samsung-blue-400); - --chart-samsung-2: var(--samsung-blue-500); - --chart-samsung-3: var(--samsung-blue-600); + --chart-lg: var(--chart-1); + --chart-samsung: 218 48% 58%; + --chart-cbrand: var(--chart-2); --chart-border: hsl(0 0% 95%); diff --git a/src/components/layout/MainLayout.tsx b/src/components/layout/MainLayout.tsx index f6aa5ee..3ca876f 100644 --- a/src/components/layout/MainLayout.tsx +++ b/src/components/layout/MainLayout.tsx @@ -46,9 +46,18 @@ const buildDefaultCategoryValue = (categoryFilterItems: ProductsFilterItem): Cat }; const buildTotalPartDescription = (pathname:string) => { - return pathname.match("penetration") - ? "■ 보급률: 전체 소비자 중, 조사 년도에 LG제품을 보유하고 있는 비율" - : "■ 구매율: 전체 소비자 중, 조사 년도에 LG제품을 구매한 비율"; + switch(pathname) { + case "/total/penetration": + return "■ 보급률: 전체 소비자 중, 조사 년도에 해당 제품을 보유하고 있는 비율"; + case "/total/lg-penetration": + return "■ 보급률: 전체 소비자 중, 조사 년도에 LG 제품을 보유하고 있는 비율"; + case "/total/purchase": + return "■ 구매율: 전체 소비자 중, 조사 년도에 해당 제품을 구매한 비율"; + case "/total/lg-purchase": + return "■ 구매율: 전체 소비자 중, 조사 년도에 LG 제품을 구매한 비율"; + default: + return ""; + } } const MainLayout = ({ children }: MainLayoutProps) => { diff --git a/src/components/lge-dashboard/BaseEChart.tsx b/src/components/lge-dashboard/BaseEChart.tsx index 49c206f..57a7cde 100644 --- a/src/components/lge-dashboard/BaseEChart.tsx +++ b/src/components/lge-dashboard/BaseEChart.tsx @@ -4,6 +4,9 @@ import dynamic from "next/dynamic"; import type { EChartsOption } from "echarts"; import { CHART_HEIGHTS } from "@/const/chartConst"; import {useResizeKey} from "@/hooks/useResize"; +import { VIEW_DECIMAL_POINT } from "@/const/lgConst"; +import { useMemo } from "react"; +import {roundNumber} from "@/lib/lg-dashboard"; const ReactECharts = dynamic(() => import("echarts-for-react"), { ssr: false }); @@ -20,6 +23,43 @@ type BaseEChartProps = { onEvents?: Record void>; }; +const normalizeDataValue = (value: unknown): unknown => { + if (typeof value === "number") { + return roundNumber(value); + } + + if (Array.isArray(value)) { + return value.map(normalizeDataValue); + } + + if (value && typeof value === "object" && "value" in value) { + const item = value as { value: unknown }; + return { + ...(value as Record), + value: normalizeDataValue(item.value), + }; + } + + return value; +}; + +const normalizeSeries = (series?: EChartsOption["series"]): EChartsOption["series"] => { + if (!series) return series; + + const normalizeOne = (s: any) => { + if (!s || !("data" in s) || !Array.isArray(s.data)) { + return s; + } + + return { + ...s, + data: s.data.map(normalizeDataValue), + }; + }; + + return Array.isArray(series) ? series.map(normalizeOne) : normalizeOne(series); +}; + const BaseEChart = ({ option, height = CHART_HEIGHTS.DEFAULT, @@ -32,12 +72,19 @@ const BaseEChart = ({ }: BaseEChartProps) => { const resizeKey = useResizeKey(150); + const normalizedOption = useMemo(() => { + return { + ...option, + series: normalizeSeries(option.series), + }; + }, [option]); + return (
; + yearBrandPalette?: string[]; }; const GroupedStackBar = ({ @@ -60,11 +60,10 @@ const GroupedStackBar = ({ const defaultXAxis: EChartsOption["xAxis"] = { type: "category", data: data.categories, ...AXIS_HIDE_STYLE }; const defaultYAxis: EChartsOption["yAxis"] = { type: "value", ...AXIS_HIDE_STYLE }; - const latestYear = years.at(-1); - const latestPalette = buildLgPalette(yearBrandPalette?.[String(latestYear)]); + const latestPalette = buildLgPalette(yearBrandPalette); const yearLegendTokens = years.map((y) => { - const tokens = yearBrandPalette?.[String(y)]; + const tokens = yearBrandPalette; const last = tokens?.[tokens.length - 1]; return last ?? "--lg-gray-500"; }); @@ -104,8 +103,9 @@ const GroupedStackBar = ({ for (let yi = 0; yi < years.length; yi++) { const year = years[yi]; const yearLabel = `${year}년`; + const viewYearLabel = `'${Number(year)-2000}`; - const palette = buildLgPalette(yearBrandPalette?.[String(year)]); + const palette = buildLgPalette(yearBrandPalette); for (let bi = 0; bi < brands.length; bi++) { const brand = brands[bi]; @@ -114,6 +114,8 @@ const GroupedStackBar = ({ const isYearOn = yearSelected[yearLabel]; const showLabel = getIsShowLabel(showFocusLabel, yi, years.length); + const isFirstBrand = bi === 0; + realSeries.push({ id: `${year}|${brand}`, name: brand, @@ -122,12 +124,20 @@ const GroupedStackBar = ({ emphasis: { disabled: true }, barMaxWidth: barMaxWidth ?? 42, itemStyle: { color: palette?.[bi] }, - label: showLabel - ? ({ + label: isFirstBrand + ? { + show: true, + position: "bottom", + formatter: () => viewYearLabel, + color: "#666", + fontSize: 12, + } + : showLabel + ? { show: true, position: "top", formatter: (p: any) => (p?.value ?? "") as any, - } as any) + } : undefined, data: data.categories.map((_, ci) => (isYearOn ? (row[ci] ?? null) : null)), }); @@ -155,7 +165,7 @@ const GroupedStackBar = ({ } const brandLegendOpt: LegendComponentOption = ({ - top: 25, + top: 0, //25, right: "center", orient: "horizontal", icon: roundedRectIcon(LEGEND_ITEM_SIZE.WIDTH, LEGEND_ITEM_SIZE.HEIGHT, LEGEND_ITEM_SIZE.RADIUS), @@ -166,7 +176,8 @@ const GroupedStackBar = ({ data: [...brands].reverse(), } as LegendComponentOption); - const legends = yearLegendOpt ? [yearLegendOpt, brandLegendOpt] : brandLegendOpt; + //const legends = yearLegendOpt ? [yearLegendOpt, brandLegendOpt] : brandLegendOpt; + const legends = brandLegendOpt; return { tooltip: diff --git a/src/components/lge-dashboard/chart/StackBar.tsx b/src/components/lge-dashboard/chart/StackBar.tsx index f138058..90c1bcb 100644 --- a/src/components/lge-dashboard/chart/StackBar.tsx +++ b/src/components/lge-dashboard/chart/StackBar.tsx @@ -4,7 +4,7 @@ import { useMemo } from "react"; import type { EChartsOption } from "echarts"; import BaseEChart from "../BaseEChart"; import type { ChartData, ValueFormatter } from "../types"; -import { buildLgPalette } from "../color"; +import {buildLgPalette, buildLgStackPalette} from "../color"; import { createDefaultTooltip, createDefaultLegend, @@ -56,7 +56,7 @@ const StackBar = ({ ); const palette = useMemo(() => { - const temp = buildLgPalette(paletteVarNames); + const temp = buildLgStackPalette(paletteVarNames); const n = data.series.length; // 원본 기준 const base = temp.slice(0, n); return isReverse ? [...base].reverse() : base; diff --git a/src/components/lge-dashboard/color.ts b/src/components/lge-dashboard/color.ts index b83903e..15cdf0b 100644 --- a/src/components/lge-dashboard/color.ts +++ b/src/components/lge-dashboard/color.ts @@ -69,13 +69,28 @@ export const buildLgPalette = (varNames?: string[]): string[] => { "--chart-1", "--chart-2", "--chart-3", - "--chart-4", - "--chart-5", - "--chart-6", - "--chart-7", - "--chart-8", - "--chart-9", - "--chart-10", + ]; + + return defaults.map((v) => { + const hsl = resolveHslVar(v); + return hsl ? hslCss(hsl, 1) : v; + }); +}; + +export const buildLgStackPalette = (varNames?: string[]): string[] => { + // globals.css에 정의된 스케일을 직접 참조(중첩 var(--chart-1) 회피) + const defaults = varNames ?? [ + "--chart-stack-1", + "--chart-stack-2", + "--chart-stack-3", + "--chart-stack-4", + "--chart-stack-5", + "--chart-stack-6", + "--chart-stack-7", + "--chart-stack-8", + "--chart-stack-9", + "--chart-stack-10", + "--chart-stack-11", ]; return defaults.map((v) => { diff --git a/src/components/lge-dashboard/combo/LeftChartTable.tsx b/src/components/lge-dashboard/combo/LeftChartTable.tsx index ef6285d..2efdc5e 100644 --- a/src/components/lge-dashboard/combo/LeftChartTable.tsx +++ b/src/components/lge-dashboard/combo/LeftChartTable.tsx @@ -5,8 +5,8 @@ import { cn, parseNumber } from "@/lib/utils"; import type { DataColumn, SignStyle } from "../types"; import SectionTitle from "../SectionTitle"; import { TABLE_DIMENSIONS } from "@/const/chartConst"; -import {isSampleRow} from "@/lib/lg-dashboard"; -import {SAMPLE_SIZE_NOTICE, UNIT_TEXT} from "@/const/lgConst"; +import {isSampleRow, roundNumber} from "@/lib/lg-dashboard"; +import {SAMPLE_SIZE_NOTICE, UNIT_TEXT, VIEW_DECIMAL_POINT} from "@/const/lgConst"; type MergedChartCell = { /** 차트를 삽입할 컬럼 key(해당 컬럼 td는 startRow에서만 렌더되고 rowSpan 적용) */ @@ -213,7 +213,7 @@ export default function LeftChartTable>({ ? raw : String(raw); - const n = c.numeric ? parseNumber(raw) : null; + const shouldSign = isSignRow && (signStyle?.keys ? signStyle.keys.includes(c.key) : !!c.numeric); if (c.rowHead) { @@ -239,11 +239,12 @@ export default function LeftChartTable>({ className={cn(c.cellClassName)} style={c.width ? { width: c.width } : undefined} > - {isStar?`${content}*`:content} + {isStar?`${content}*`: roundNumber(parseNumber(content))} ); } + const n = c.numeric ? roundNumber(parseNumber(raw)) : null; // sign row: 값이 없으면 "-" 유지 if (n === null) { return ( diff --git a/src/components/lge-dashboard/combo/TopChartTable.tsx b/src/components/lge-dashboard/combo/TopChartTable.tsx index 99426cf..a920de7 100644 --- a/src/components/lge-dashboard/combo/TopChartTable.tsx +++ b/src/components/lge-dashboard/combo/TopChartTable.tsx @@ -6,7 +6,7 @@ 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"; +import {isCagrRow, roundNumber} from "@/lib/lg-dashboard"; export type TopChartTableProps = { title?: string; @@ -128,7 +128,7 @@ export default function TopChartTable(props: TopChartTableProps) { {categories.map((_, ci) => { const raw = r.values?.[ci]; - const n = parseNumber(raw); + const n = roundNumber(parseNumber(raw)); // 일반 행 if (!isSignRow) { @@ -136,6 +136,7 @@ export default function TopChartTable(props: TopChartTableProps) { const isFill = fillCAGR && cagrRow && total && n > total + 5; const txt = n.toLocaleString(); + return {txt}; } diff --git a/src/components/lge-dashboard/table/DataTable.tsx b/src/components/lge-dashboard/table/DataTable.tsx index ea884bc..ba77e56 100644 --- a/src/components/lge-dashboard/table/DataTable.tsx +++ b/src/components/lge-dashboard/table/DataTable.tsx @@ -5,7 +5,7 @@ import type React from "react"; import { cn, parseNumber } from "@/lib/utils"; import type { DataColumn, SignDisplayMode, SignStyle } from "../types"; import SectionTitle from "../SectionTitle"; -import {isCagrRow, isSampleRow} from "@/lib/lg-dashboard"; +import {isCagrRow, isSampleRow, roundNumber} from "@/lib/lg-dashboard"; import {SAMPLE_SIZE_NOTICE, UNIT_TEXT} from "@/const/lgConst"; type Props> = { @@ -16,7 +16,6 @@ type Props> = { wrapperClassName?: string; signStyle?: SignStyle; fillGreaterThan5?: boolean; - fillCAGR?: boolean; starUnder30Sample?: boolean; unitText?: string; }; @@ -24,7 +23,7 @@ type Props> = { // parseSignedNumber는 utils.ts의 parseNumber로 통합됨 const defaultFmt = (v: number) => - Number.isInteger(v) ? String(v) : v.toLocaleString(); + Number.isInteger(v) ? String(roundNumber(v)) : v.toLocaleString(); const signText = ( v: number, @@ -48,7 +47,14 @@ const signText = ( const toCellContent = (raw: unknown): React.ReactNode => { if (raw == null) return ""; - if (typeof raw === "string" || typeof raw === "number") return raw; + if (typeof raw === "string"){ + const trimmed = raw.trim(); + if (trimmed === "") return raw; + + const num = Number(trimmed); + return Number.isNaN(num) ? raw : roundNumber(num); + } + if (typeof raw === "number") return String(roundNumber(raw)); return String(raw); }; @@ -60,7 +66,6 @@ const DataTable = >({ wrapperClassName, signStyle, fillGreaterThan5 = false, - fillCAGR = false, starUnder30Sample = false, unitText = UNIT_TEXT, }: Props) => { @@ -208,7 +213,7 @@ const DataTable = >({ const applySign = signRow && isTargetKey(c.key) && !c.rowHead; if (applySign) { - const n = parseNumber(raw); + const n = roundNumber(parseNumber(raw)); const displayText = n === null ? "-" : signText(n, display, showPlus, arrowWithNumber, fmt, zeroText); diff --git a/src/components/lge-dashboard/table/GaugeTable.tsx b/src/components/lge-dashboard/table/GaugeTable.tsx index c763fba..37f267f 100644 --- a/src/components/lge-dashboard/table/GaugeTable.tsx +++ b/src/components/lge-dashboard/table/GaugeTable.tsx @@ -3,6 +3,7 @@ import React, { useMemo } from "react"; import { cn, parseNumber } from "@/lib/utils"; import {GaugeColumn} from "../types"; +import {roundNumber} from "@/lib/lg-dashboard"; type Props> = { columns: GaugeColumn[]; @@ -81,7 +82,7 @@ const GaugeTable = >({ return res; }, [columns, hasGroup]); - const fmt = valueFormatter ?? ((v: number) => String(Math.round(v))); + const fmt = valueFormatter ?? ((v: number) => String(roundNumber(v))); const clamp01 = (n: number) => Math.max(0, Math.min(1, n)); diff --git a/src/config/filter.data.ts b/src/config/filter.data.ts index 9e2744c..457d3f2 100644 --- a/src/config/filter.data.ts +++ b/src/config/filter.data.ts @@ -18,6 +18,8 @@ export const totalFilters:TotalFilterItem[] = [ { value: "4", label: "기혼 학령기"}, { value: "5", label: "기혼 성인자녀"}, { value: "6", label: "독립 시니어"}, + { value: "7", label: "비혼 중년"}, + { value: "8", label: "기타"}, ] }, { diff --git a/src/const/chartConst.ts b/src/const/chartConst.ts index 3e7f748..4bb9516 100644 --- a/src/const/chartConst.ts +++ b/src/const/chartConst.ts @@ -1,10 +1,3 @@ -/** - * 차트 관련 상수 정의 - * - 차트 높이, Bar 너비, Grid 설정 등 - */ - -import {GAP_WORDING} from "@/const/lgConst"; - /** * 차트 기본 높이 설정 */ @@ -52,56 +45,6 @@ export const LEGEND_ITEM_SIZE = { RADIUS: 4, } as const; -/** - * 색상 팔레트 설정 - */ -export const CHART_COLOR_PALETTES = { - /** 연도별 트렌드 역순 (최신->과거) */ - YEAR_TREND_REVERSE: ["--chart-3", "--chart-2", "--chart-1"], - - /** LG Red 계열 */ - LG_RED_SCALE: ["--lg-red-300", "--lg-red-400", "--lg-red-500"], - - /** 연도별 전체 색상 */ - YEAR_TOTAL: { - "24": "--chart-total-1", - "25": "--chart-total-2", - "26": "--chart-total-3", - } as const, - - /** 연도별 LG 색상 */ - YEAR_LG: { - "24": "--chart-lg-1", - "25": "--chart-lg-2", - "26": "--chart-lg-3", - } as const, - - /** 연도별 브랜드 색상 (CBrand, Samsung, LG) */ - YEAR_BRAND: { - "24": ["--chart-cbrand-1", "--chart-samsung-1", "--chart-lg-1"], - "25": ["--chart-cbrand-2", "--chart-samsung-2", "--chart-lg-2"], - "26": ["--chart-cbrand-3", "--chart-samsung-3", "--chart-lg-3"], - } as const, -} as const; - -/** - * 테이블 색상 설정 - */ -export const TABLE_COLORS = { - /** 게이지 테이블 색상 */ - GAUGE: { - FILL: "hsl(var(--lg-gray-200) / 0.85)", - TRACK: "hsl(var(--lg-pink-300) / 0.2)", - }, - - /** Sign 표기 셀 배경색 */ - SIGN_CELL: { - POSITIVE: "hsl(var(--primary) / 0.08)", - NEGATIVE: "hsl(var(--info) / 0.08)", - ZERO: "hsl(var(--lg-gray-200) / 0.6)", - }, -} as const; - /** * 테이블 크기 설정 */ @@ -116,26 +59,4 @@ export const TABLE_DIMENSIONS = { COMPACT: 1200, WIDE: 2000, }, -} as const; - -/** - * 차트/테이블 라벨 텍스트 - */ -export const CHART_LABELS = { - TOTAL: "전체", - LG: "LG", - GAP: GAP_WORDING, - CAGR: "CAGR(%p)", - SAMPLE_COUNT: "(사례수)", -} as const; - -/** - * 차트 제목 텍스트 - */ -export const CHART_TITLES = { - LG_PENETRATION: "LG제품 보급률", - TOTAL_PENETRATION: "전체 보급률", - LG_PURCHASE: "LG제품 구매율", - TOTAL_PURCHASE: "전체 구매율", - BRAND_SHARE: "브랜드별 점유율", -} as const; +} as const; \ No newline at end of file diff --git a/src/const/lgConst.ts b/src/const/lgConst.ts index afa68f9..f1bebcc 100644 --- a/src/const/lgConst.ts +++ b/src/const/lgConst.ts @@ -3,6 +3,8 @@ import {GaugeColumn} from "@/components/lge-dashboard"; import {CategoryTargetData, CategoryTargetType} from "@/config/filter.types"; export const USE_CACHE = false; +export const API_DECIMAL_POINT = 0; +export const VIEW_DECIMAL_POINT = 0; export const SITE_TITLE = 'LGE CX Dashboard'; @@ -45,6 +47,8 @@ export const BANNER_KEY_MAP = { "KLIFEstAGE#4": "취학자녀", "KLIFEstAGE#5": "성인자녀", "KLIFEstAGE#6": "독립시니어", + "KLIFEstAGE#7": "비혼중년", + "KLIFEstAGE#8": "기타", // 가구원수 "KSQ8_R_DB#1": "1인 가구", @@ -108,6 +112,8 @@ export const LIFE_STAGE_COLUMNS: GaugeColumn[] = [ { key: "KLIFEstAGE#5", header: "성인자녀", group: "기혼", max: 100 , align: "left"}, { key: "KLIFEstAGE#6", header: "독립\n시니어", headRowSpan:2, max: 100 , align: "left"}, + { key: "KLIFEstAGE#7", header: "비혼중년", headRowSpan:2, max: 100 , align: "left"}, + { key: "KLIFEstAGE#8", header: "기타", headRowSpan:2, max: 100 , align: "left"}, ]; export const LIFE_STAGE_GROUPS = [ @@ -174,6 +180,8 @@ export const BANNER_GROUP = { BANNER_KEY["KLIFEstAGE#4"], BANNER_KEY["KLIFEstAGE#5"], BANNER_KEY["KLIFEstAGE#6"], + BANNER_KEY["KLIFEstAGE#7"], + BANNER_KEY["KLIFEstAGE#8"], ], }, household: { diff --git a/src/lib/lg-dashboard.ts b/src/lib/lg-dashboard.ts index 46e596a..b2b3424 100644 --- a/src/lib/lg-dashboard.ts +++ b/src/lib/lg-dashboard.ts @@ -7,11 +7,12 @@ import { } from "@/types/lg"; import {ChartData} from "@/components/lge-dashboard"; import { + API_DECIMAL_POINT, BANNER_GROUP, BANNER_KEYS, CATEGORY_PAGE_FIELDS, GAP_WORDING, - PRODUCT_KEYS + PRODUCT_KEYS, VIEW_DECIMAL_POINT } from "@/const/lgConst"; import {formatNumber} from "@/lib/utils"; import {nextApi} from "@/lib/http-client"; @@ -393,16 +394,27 @@ export const buildCategoryFilter = ( return Object.keys(out).length ? out : undefined; } +const fixedDecimalPoint = (n: number): string => { + return n.toFixed(API_DECIMAL_POINT); +}; + +export const roundNumber = (num: number|null) => { + if(num == null) return null; + + const factor = 10 ** VIEW_DECIMAL_POINT; + return Math.round(num * factor) / factor; +}; + export const calcGapProductRow = (after: ProductRow, before: ProductRow): ProductRow => { const out: ProductRow = { year: after?.year ?? "", rowLabel: "gap", - total: String(Number(after?.total ?? "0") - Number(before?.total ?? "0")), + total: fixedDecimalPoint(Number(after?.total ?? "0") - Number(before?.total ?? "0")), }; for (const k of PRODUCT_KEYS) { const a = after? after[k] ?? "0" : "0"; const b = before? before[k] ?? "0" : "0"; - out[k] = String(Number(a) - Number(b)); + out[k] = fixedDecimalPoint(Number(a) - Number(b)); } return out; }; @@ -411,24 +423,22 @@ export const calcGapBannerRow = (after: BannerRow, before: BannerRow): BannerRow const out: BannerRow = { year: after?.year ?? "", rowLabel: "gap", - total: String(Number(after?.total ?? "0") - Number(before?.total ?? "0")), + total: fixedDecimalPoint(Number(after?.total ?? "0") - Number(before?.total ?? "0")), }; for (const k of BANNER_KEYS) { const a = after? after[k] ?? "0" : "0"; const b = before? before[k] ?? "0" : "0"; - out[k] = String(Number(a) - Number(b)); + out[k] = fixedDecimalPoint(Number(a) - Number(b)); } return out; }; -const round1 = (n: number) => Math.round(n * 10) / 10; - -const calcCagr = (after: number, before: number, years:number): string => { +const calcCagr = (after: number, before: number, years:number): number => { const power = Math.pow(after / before, 1 / years); const cagr = power - 1; const cagr100 = cagr * 100; - return String(round1(cagr100)); + return cagr100; }; export const calcCagrRow = (after: ProductRow, before: ProductRow): ProductRow => { @@ -441,32 +451,32 @@ export const calcCagrRow = (after: ProductRow, before: ProductRow): ProductRow = // total은 참고용으로만: (26/24) CAGR % out.total = - Number(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); for (const k of PRODUCT_KEYS) { const vBefore = before? before[k] ?? "0" : "0"; const vAfter = after? after[k] ?? "0" : "0"; - out[k] = Number(vBefore) > 0 ? calcCagr(Number(vAfter), Number(vBefore), years) : "0"; + out[k] = fixedDecimalPoint(Number(vBefore) > 0 ? calcCagr(Number(vAfter), Number(vBefore), years) : 0); } return out; }; export const makeTotalBasePct = (t:number|string, f:number|string):number => { - return Number(t) > 0 ? Math.round((Number(f) / Number(t)) * 100) : 0; + return Number(t) > 0 ? (Number(f) * 100) / Number(t) : 0; } export const calcTotalBaseRow = (label:string, totalRow: ProductRow, targetRow: ProductRow): ProductRow => { const out: ProductRow = { year: targetRow?.year ?? "", rowLabel: `전체 ${label} 중 자사제품 비율`, - total: String(makeTotalBasePct(totalRow.total, targetRow.total)) + total: fixedDecimalPoint(makeTotalBasePct(totalRow.total, targetRow.total)) }; for (const k of PRODUCT_KEYS) { const t = totalRow? totalRow[k] ?? "0" : "0"; const f = targetRow? targetRow[k] ?? "0" : "0"; - out[k] = String(makeTotalBasePct(t, f)); + out[k] = fixedDecimalPoint(makeTotalBasePct(t, f)); } return out; diff --git a/src/types/lg.ts b/src/types/lg.ts index 90f94f1..68226ad 100644 --- a/src/types/lg.ts +++ b/src/types/lg.ts @@ -64,6 +64,8 @@ export type LifeStageRow = Record & { "KLIFEstAGE#4": string; "KLIFEstAGE#5": string; "KLIFEstAGE#6": string; + "KLIFEstAGE#7": string; + "KLIFEstAGE#8": string; }; export type LifeStageGroup = {