260312_01_ENH: API_DECIMAL_POINT, VIEW_DECIMAL_POINT 적용, 스택 차트 색상 변경, 그룹 스택 차트 하단에 연도 레이블 출력, Total 페이지 설명문 수정
This commit is contained in:
@@ -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]);
|
||||
|
||||
|
||||
@@ -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`] ?? "",
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
@@ -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]);
|
||||
|
||||
|
||||
@@ -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<SelectedMap>(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<StatisticsRequest>(() => {
|
||||
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 ? (
|
||||
<GroupedStackBar
|
||||
data={brandShareChartData}
|
||||
grid={{ ...GRID_X_NOT_PADDING, top: 60 }}
|
||||
grid={{...GRID_X_NOT_PADDING, bottom: 20}}
|
||||
xAxis={{ type: "category", data: PRODUCTS, ...AXIS_HIDE_STYLE }}
|
||||
yAxis={{ type: "value", ...AXIS_HIDE_STYLE }}
|
||||
showFocusLabel={"none"}
|
||||
yearBrandPalette={chartColorByYear}
|
||||
yearBrandPalette={["--chart-lg","--chart-samsung","--chart-cbrand"]}
|
||||
height={260}
|
||||
/>
|
||||
) : (
|
||||
|
||||
@@ -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]);
|
||||
|
||||
|
||||
@@ -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%);
|
||||
|
||||
|
||||
@@ -46,9 +46,18 @@ const buildDefaultCategoryValue = (categoryFilterItems: ProductsFilterItem): Cat
|
||||
};
|
||||
|
||||
const buildTotalPartDescription = (pathname:string) => {
|
||||
return pathname.match("penetration")
|
||||
? "■ 보급률: 전체 소비자 중, 조사 년도에 LG제품을 <strong>보유하고 있는 비율</strong>"
|
||||
: "■ 구매율: 전체 소비자 중, 조사 년도에 LG제품을 <strong>구매한 비율</strong>";
|
||||
switch(pathname) {
|
||||
case "/total/penetration":
|
||||
return "■ 보급률: 전체 소비자 중, 조사 년도에 해당 제품을 <strong>보유하고 있는 비율</strong>";
|
||||
case "/total/lg-penetration":
|
||||
return "■ 보급률: 전체 소비자 중, 조사 년도에 LG 제품을 <strong>보유하고 있는 비율</strong>";
|
||||
case "/total/purchase":
|
||||
return "■ 구매율: 전체 소비자 중, 조사 년도에 해당 제품을 <strong>구매한 비율</strong>";
|
||||
case "/total/lg-purchase":
|
||||
return "■ 구매율: 전체 소비자 중, 조사 년도에 LG 제품을 <strong>구매한 비율</strong>";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
const MainLayout = ({ children }: MainLayoutProps) => {
|
||||
|
||||
@@ -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<string, (params: unknown) => 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<string, unknown>),
|
||||
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<EChartsOption>(() => {
|
||||
return {
|
||||
...option,
|
||||
series: normalizeSeries(option.series),
|
||||
};
|
||||
}, [option]);
|
||||
|
||||
return (
|
||||
<div className={className} style={{ display: "flex", flexDirection: "column", height: height }}>
|
||||
<div className={contentClassName} style={{ flex: 1, minHeight: 0 }}>
|
||||
<ReactECharts
|
||||
key={resizeKey}
|
||||
option={option}
|
||||
option={normalizedOption}
|
||||
className={chartClassName}
|
||||
style={{ width: "100%", height: "100%" }}
|
||||
notMerge={notMerge}
|
||||
|
||||
@@ -29,7 +29,7 @@ type Props = {
|
||||
showFocusLabel?: ShowLabel;
|
||||
|
||||
showYearLegend?: boolean;
|
||||
yearBrandPalette?: Record<string, string[]>;
|
||||
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:
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
@@ -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<T> = {
|
||||
/** 차트를 삽입할 컬럼 key(해당 컬럼 td는 startRow에서만 렌더되고 rowSpan 적용) */
|
||||
@@ -213,7 +213,7 @@ export default function LeftChartTable<T extends Record<string, unknown>>({
|
||||
? 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<T extends Record<string, unknown>>({
|
||||
className={cn(c.cellClassName)}
|
||||
style={c.width ? { width: c.width } : undefined}
|
||||
>
|
||||
{isStar?`${content}*`:content}
|
||||
{isStar?`${content}*`: roundNumber(parseNumber(content))}
|
||||
</td>
|
||||
);
|
||||
}
|
||||
|
||||
const n = c.numeric ? roundNumber(parseNumber(raw)) : null;
|
||||
// sign row: 값이 없으면 "-" 유지
|
||||
if (n === null) {
|
||||
return (
|
||||
|
||||
@@ -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 <td key={ci} className={cn(isFill? "bg-red-200" :"")}>{txt}</td>;
|
||||
}
|
||||
|
||||
|
||||
@@ -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<T extends Record<string, unknown>> = {
|
||||
@@ -16,7 +16,6 @@ type Props<T extends Record<string, unknown>> = {
|
||||
wrapperClassName?: string;
|
||||
signStyle?: SignStyle<T>;
|
||||
fillGreaterThan5?: boolean;
|
||||
fillCAGR?: boolean;
|
||||
starUnder30Sample?: boolean;
|
||||
unitText?: string;
|
||||
};
|
||||
@@ -24,7 +23,7 @@ type Props<T extends Record<string, unknown>> = {
|
||||
// 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 = <T extends Record<string, unknown>>({
|
||||
wrapperClassName,
|
||||
signStyle,
|
||||
fillGreaterThan5 = false,
|
||||
fillCAGR = false,
|
||||
starUnder30Sample = false,
|
||||
unitText = UNIT_TEXT,
|
||||
}: Props<T>) => {
|
||||
@@ -208,7 +213,7 @@ const DataTable = <T extends Record<string, unknown>>({
|
||||
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);
|
||||
|
||||
|
||||
@@ -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<T extends Record<string, unknown>> = {
|
||||
columns: GaugeColumn<T>[];
|
||||
@@ -81,7 +82,7 @@ const GaugeTable = <T extends Record<string, unknown>>({
|
||||
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));
|
||||
|
||||
|
||||
@@ -18,6 +18,8 @@ export const totalFilters:TotalFilterItem[] = [
|
||||
{ value: "4", label: "기혼 학령기"},
|
||||
{ value: "5", label: "기혼 성인자녀"},
|
||||
{ value: "6", label: "독립 시니어"},
|
||||
{ value: "7", label: "비혼 중년"},
|
||||
{ value: "8", label: "기타"},
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
@@ -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<LifeStageRow>[] = [
|
||||
{ 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: {
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -64,6 +64,8 @@ export type LifeStageRow = Record<string, unknown> & {
|
||||
"KLIFEstAGE#4": string;
|
||||
"KLIFEstAGE#5": string;
|
||||
"KLIFEstAGE#6": string;
|
||||
"KLIFEstAGE#7": string;
|
||||
"KLIFEstAGE#8": string;
|
||||
};
|
||||
|
||||
export type LifeStageGroup = {
|
||||
|
||||
Reference in New Issue
Block a user