260312_01_ENH: API_DECIMAL_POINT, VIEW_DECIMAL_POINT 적용, 스택 차트 색상 변경, 그룹 스택 차트 하단에 연도 레이블 출력, Total 페이지 설명문 수정
This commit is contained in:
@@ -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));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user