260202_01_ENH: route 구조 초창기 기획으로 다시 변경 및 Category 별 하위 페이지에 샘플 데이터 모두 적용
This commit is contained in:
@@ -36,7 +36,6 @@ const CategoryFilter = ({ filterItems, value, onChange, className }: CategoryFil
|
||||
v: string | CategoryTypeValue | CategoryTargetData
|
||||
) => {
|
||||
if (value[key] === v) return;
|
||||
|
||||
const next: CategoryFilterValue = { ...value, [key]: v } as CategoryFilterValue;
|
||||
|
||||
if (key === "type" && typeof v === "object" && v.value !== value.type.value) {
|
||||
|
||||
@@ -2,13 +2,11 @@
|
||||
|
||||
import React, { createContext, useCallback, useContext, useMemo, useRef } from "react";
|
||||
import type { SelectedMap } from "@/types/common";
|
||||
import type { CategoryFilterValue } from "@/components/layout/CategoryFilter";
|
||||
import {CategoryFilterValue} from "@/components/layout/CategoryFilter";
|
||||
|
||||
export type ExcelExportContext = {
|
||||
isTotal: boolean;
|
||||
totalValue: SelectedMap;
|
||||
categoryValue: CategoryFilterValue;
|
||||
};
|
||||
export type ExcelExportContext =
|
||||
| { isTotal: true; filterValue: SelectedMap }
|
||||
| { isTotal: false; filterValue: CategoryFilterValue };
|
||||
|
||||
type ExcelExporter = (ctx: ExcelExportContext) => void | Promise<void>;
|
||||
|
||||
|
||||
@@ -1,21 +1,22 @@
|
||||
"use client";
|
||||
|
||||
import {ReactNode, useEffect, useMemo, useState} from "react";
|
||||
import { usePathname, useRouter } from "next/navigation";
|
||||
import {ReactNode, useEffect, useMemo, useRef, useState} from "react";
|
||||
import {usePathname, useRouter} from "next/navigation";
|
||||
import {cn} from "@/lib/utils";
|
||||
import {SelectedMap} from "@/types/common";
|
||||
import {topMenus, totalSubMenus, categorySubMenus} from "@/config/menu.data";
|
||||
import {categoryTarget, TARGET_SLUG, totalFilters} from "@/config/filter.data";
|
||||
import {categoryTarget, totalFilters} from "@/config/filter.data";
|
||||
import {CategoryTargetData, CategoryTargetType} from "@/config/filter.types";
|
||||
import Header from "./Header";
|
||||
import SubMenu from "./SubMenu";
|
||||
import TotalFilter from "./TotalFilter";
|
||||
import CategoryFilter, {CategoryFilterValue} from "./CategoryFilter";
|
||||
import ExcelDownloadButton from "./ExcelDownloadButton";
|
||||
import {LayoutFilterProvider} from "./LayoutFilterContext";
|
||||
import {ExcelExportContext, LayoutFilterProvider} from "./LayoutFilterContext";
|
||||
import {PRODUCTS_FILTER_ITEM} from "@/const/lgConst";
|
||||
import {ProductsFilterItem} from "@/types/lg";
|
||||
import {useLoading} from "@/hooks/useLoading";
|
||||
import {ArrowUp} from "lucide-react";
|
||||
|
||||
type MainLayoutProps = {
|
||||
children: ReactNode;
|
||||
@@ -49,6 +50,9 @@ const MainLayout = ({ children }: MainLayoutProps) => {
|
||||
const pathname = usePathname();
|
||||
const { withLoadingAsync } = useLoading();
|
||||
|
||||
const scrollRef = useRef<HTMLDivElement | null>(null);
|
||||
const [showScrollTop, setShowScrollTop] = useState(false);
|
||||
|
||||
const isTotal = pathname.startsWith("/total");
|
||||
const activeTop = topMenus.find((m) => m.match?.(pathname)) ?? topMenus[0];
|
||||
const subMenus = isTotal ? totalSubMenus : categorySubMenus;
|
||||
@@ -67,52 +71,45 @@ const MainLayout = ({ children }: MainLayoutProps) => {
|
||||
router.push(path);
|
||||
};
|
||||
|
||||
const moveCategoryPage = (path: string) => {
|
||||
const slug = TARGET_SLUG[categoryValue.target] ?? "profile";
|
||||
const nextPath = `${path}/${slug}`;
|
||||
|
||||
if (pathname !== nextPath) {
|
||||
router.push(nextPath);
|
||||
}
|
||||
}
|
||||
|
||||
const toggleFilter = () => {
|
||||
if (isTotal) setIsTotalFilterOpen((v) => !v);
|
||||
else setIsCategoryFilterOpen((v) => !v);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
/*
|
||||
withLoadingAsync(async () => {
|
||||
setCategoryValue(prev => ({...prev, product: categoryFilterItems.items[0]}))
|
||||
});
|
||||
*/
|
||||
setCategoryValue(prev => ({...prev, product: categoryFilterItems.items[0]}))
|
||||
}, [categoryFilterItems]);
|
||||
const onScrollContent = () => {
|
||||
const el = scrollRef.current;
|
||||
if (!el) return;
|
||||
setShowScrollTop(el.scrollTop > 120);
|
||||
};
|
||||
|
||||
const scrollToTop = () => {
|
||||
scrollRef.current?.scrollTo({ top: 0, behavior: "smooth" });
|
||||
};
|
||||
|
||||
const ctx = useMemo<ExcelExportContext>(() => {
|
||||
return isTotal
|
||||
? { isTotal: true, filterValue: totalValue }
|
||||
: { isTotal: false, filterValue: categoryValue };
|
||||
}, [isTotal, totalValue, categoryValue]);
|
||||
|
||||
useEffect(() => {
|
||||
if (isTotal) return;
|
||||
|
||||
const base = activeSub?.path; // "/category/ha-kitchen"
|
||||
if (!base) return;
|
||||
|
||||
const slug = TARGET_SLUG[categoryValue.target] ?? "profile";
|
||||
const nextPath = `${base}/${slug}`;
|
||||
|
||||
if (pathname !== nextPath) {
|
||||
router.replace(nextPath);
|
||||
if (isTotal){
|
||||
console.log("istotal category", buildDefaultCategoryValue(PRODUCTS_FILTER_ITEM[0]));
|
||||
setCategoryValue(buildDefaultCategoryValue(PRODUCTS_FILTER_ITEM[0]))
|
||||
return;
|
||||
}
|
||||
}, [isTotal, categoryValue.target, activeSub?.path, pathname, router]);
|
||||
|
||||
if(categoryValue.product != categoryFilterItems.items[0]){
|
||||
setCategoryValue((prev) => {
|
||||
return { ...prev, product: categoryFilterItems.items[0] };
|
||||
});
|
||||
}
|
||||
|
||||
}, [isTotal, categoryFilterItems]);
|
||||
|
||||
return (
|
||||
<div className="min-h-screen flex flex-col bg-transparent">
|
||||
<LayoutFilterProvider
|
||||
value={{
|
||||
isTotal,
|
||||
totalValue,
|
||||
categoryValue,
|
||||
}}
|
||||
>
|
||||
<div className="h-screen flex flex-col bg-transparent overflow-hidden">
|
||||
<LayoutFilterProvider value={ctx} >
|
||||
<Header
|
||||
activeTopId={activeTop.id}
|
||||
onNavigate={movePage}
|
||||
@@ -121,11 +118,11 @@ const MainLayout = ({ children }: MainLayoutProps) => {
|
||||
<SubMenu
|
||||
subMenu={subMenus}
|
||||
activeSubId={activeSub.id}
|
||||
onNavigate={isTotal? movePage : moveCategoryPage}
|
||||
onNavigate={movePage}
|
||||
/>
|
||||
<div className="flex-1 min-h-0 flex flex-col pr-4">
|
||||
<div className="bg-card lg-tab-content flex-1 min-h-0">
|
||||
<div className="shrink-0 flex items-center justify-between px-2 py-1">
|
||||
<div className="bg-card lg-tab-content flex-1 min-h-0 flex flex-col overflow-hidden">
|
||||
<div className="shrink-0 flex items-center justify-between px-2 py-1">
|
||||
<button
|
||||
type="button"
|
||||
onClick={toggleFilter}
|
||||
@@ -150,10 +147,32 @@ const MainLayout = ({ children }: MainLayoutProps) => {
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="flex-1 min-h-0 overflow-auto">
|
||||
<div className="p-3">
|
||||
<div className="relative flex-1 min-h-0">
|
||||
<div
|
||||
ref={scrollRef}
|
||||
onScroll={onScrollContent}
|
||||
className="h-full overflow-auto"
|
||||
>
|
||||
<div className="p-3 pb-8">
|
||||
{children}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{showScrollTop && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={scrollToTop}
|
||||
aria-label="위로 가기"
|
||||
className={cn(
|
||||
"absolute -bottom-2 right-4 z-20",
|
||||
"h-8 w-8 rounded-full",
|
||||
"bg-gray-900/80 text-white hover:bg-primary",
|
||||
"flex items-center justify-center"
|
||||
)}
|
||||
>
|
||||
<ArrowUp className="h-5 w-5" />
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -20,13 +20,13 @@ const BannerButtons = ({
|
||||
key={banner.variable}
|
||||
onClick={() => onSelectBanner(banner)}
|
||||
className={`
|
||||
px-4 py-2 text-sm font-medium rounded-lg transition-colors
|
||||
${
|
||||
selectedBanner === banner
|
||||
? "bg-primary text-primary-foreground"
|
||||
: "bg-gray-100 text-gray-700 hover:bg-gray-200"
|
||||
}
|
||||
`}
|
||||
px-4 py-2 text-sm font-bold rounded-lg transition-colors cursor-pointer
|
||||
${
|
||||
selectedBanner === banner
|
||||
? "bg-primary text-primary-foreground"
|
||||
: "bg-gray-100 text-gray-700 hover:bg-primary hover:text-primary-foreground"
|
||||
}
|
||||
`}
|
||||
>
|
||||
{banner.variableName}
|
||||
</button>
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
import dynamic from "next/dynamic";
|
||||
import { useMemo } from "react";
|
||||
import type { EChartsOption } from "echarts";
|
||||
import { CHART_HEIGHTS } from "@/const/chartConst";
|
||||
|
||||
const ReactECharts = dynamic(() => import("echarts-for-react"), { ssr: false });
|
||||
|
||||
@@ -19,7 +20,7 @@ type BaseEChartProps = {
|
||||
|
||||
const BaseEChart = ({
|
||||
option,
|
||||
height = 260,
|
||||
height = CHART_HEIGHTS.DEFAULT,
|
||||
className,
|
||||
notMerge = true,
|
||||
lazyUpdate = true,
|
||||
|
||||
@@ -14,6 +14,7 @@ import { buildLgPalette } from "../color";
|
||||
import { GroupedOverlayBarData, ShowLabel} from "../types";
|
||||
import {getIsShowLabel, roundedRectIcon} from "@/components/lge-dashboard/chart/utill";
|
||||
import {AXIS_HIDE_STYLE} from "@/const/lgConst";
|
||||
import { CHART_HEIGHTS, LEGEND_ITEM_SIZE } from "@/const/chartConst";
|
||||
|
||||
type Props = {
|
||||
data: GroupedOverlayBarData;
|
||||
@@ -34,7 +35,7 @@ type Props = {
|
||||
|
||||
const GroupedOverlayBar = ({
|
||||
data,
|
||||
height = 260,
|
||||
height = CHART_HEIGHTS.DEFAULT,
|
||||
tooltip,
|
||||
grid,
|
||||
xAxis,
|
||||
@@ -170,9 +171,9 @@ const GroupedOverlayBar = ({
|
||||
});
|
||||
}
|
||||
|
||||
const YEAR_ITEM_W = 25;
|
||||
const YEAR_ITEM_H = 14;
|
||||
const YEAR_RADIUS = 4;
|
||||
const YEAR_ITEM_W = LEGEND_ITEM_SIZE.WIDTH;
|
||||
const YEAR_ITEM_H = LEGEND_ITEM_SIZE.HEIGHT;
|
||||
const YEAR_RADIUS = LEGEND_ITEM_SIZE.RADIUS;
|
||||
|
||||
let yearLegendOpt: LegendComponentOption | undefined = showYearLegend
|
||||
? ({
|
||||
|
||||
@@ -14,6 +14,7 @@ import { GroupedStackBarData, ShowLabel} from "../types";
|
||||
import { buildLgPalette } from "@/components/lge-dashboard/color";
|
||||
import {getIsShowLabel, roundedRectIcon} from "@/components/lge-dashboard/chart/utill";
|
||||
import {AXIS_HIDE_STYLE} from "@/const/lgConst";
|
||||
import { CHART_HEIGHTS, LEGEND_ITEM_SIZE } from "@/const/chartConst";
|
||||
|
||||
type Props = {
|
||||
data: GroupedStackBarData;
|
||||
@@ -33,7 +34,7 @@ type Props = {
|
||||
|
||||
const GroupedStackBar = ({
|
||||
data,
|
||||
height = 260,
|
||||
height = CHART_HEIGHTS.DEFAULT,
|
||||
tooltip,
|
||||
grid,
|
||||
xAxis,
|
||||
@@ -133,10 +134,6 @@ const GroupedStackBar = ({
|
||||
}
|
||||
}
|
||||
|
||||
const YEAR_ITEM_W = 25;
|
||||
const YEAR_ITEM_H = 14;
|
||||
const YEAR_RADIUS = 4;
|
||||
|
||||
// 3) legend 2개: (좌)연도, (우)브랜드
|
||||
let yearLegendOpt: LegendComponentOption | undefined = showYearLegend
|
||||
? ({
|
||||
@@ -145,9 +142,9 @@ const GroupedStackBar = ({
|
||||
orient: "horizontal",
|
||||
data: yearLabels, // yearLegendSeries name과 일치
|
||||
selected: yearSelected,
|
||||
icon: roundedRectIcon(YEAR_ITEM_W, YEAR_ITEM_H, YEAR_RADIUS),
|
||||
itemWidth: YEAR_ITEM_W,
|
||||
itemHeight: YEAR_ITEM_H,
|
||||
icon: roundedRectIcon(LEGEND_ITEM_SIZE.WIDTH, LEGEND_ITEM_SIZE.HEIGHT, LEGEND_ITEM_SIZE.RADIUS),
|
||||
itemWidth: LEGEND_ITEM_SIZE.WIDTH,
|
||||
itemHeight: LEGEND_ITEM_SIZE.HEIGHT,
|
||||
itemGap: 8,
|
||||
...legend,
|
||||
} as LegendComponentOption)
|
||||
@@ -161,12 +158,12 @@ const GroupedStackBar = ({
|
||||
top: 25,
|
||||
right: "center",
|
||||
orient: "horizontal",
|
||||
data: brands,
|
||||
icon: roundedRectIcon(YEAR_ITEM_W, YEAR_ITEM_H, YEAR_RADIUS),
|
||||
itemWidth: YEAR_ITEM_W,
|
||||
itemHeight: YEAR_ITEM_H,
|
||||
icon: roundedRectIcon(LEGEND_ITEM_SIZE.WIDTH, LEGEND_ITEM_SIZE.HEIGHT, LEGEND_ITEM_SIZE.RADIUS),
|
||||
itemWidth: LEGEND_ITEM_SIZE.WIDTH,
|
||||
itemHeight: LEGEND_ITEM_SIZE.HEIGHT,
|
||||
itemGap: 8,
|
||||
...legend,
|
||||
data: [...brands].reverse(),
|
||||
} as LegendComponentOption);
|
||||
|
||||
const legends = yearLegendOpt ? [yearLegendOpt, brandLegendOpt] : brandLegendOpt;
|
||||
|
||||
@@ -6,6 +6,14 @@ import BaseEChart from "../BaseEChart";
|
||||
import {ChartData, ShowLabel, ValueFormatter} from "../types";
|
||||
import { buildLgPalette } from "../color";
|
||||
import {getIsShowLabel} from "@/components/lge-dashboard/chart/utill";
|
||||
import {
|
||||
createDefaultTooltip,
|
||||
createDefaultLegend,
|
||||
createDefaultGrid,
|
||||
createCategoryAxis,
|
||||
createValueAxis,
|
||||
} from "@/lib/chart-options";
|
||||
import { BAR_WIDTHS } from "@/const/chartConst";
|
||||
|
||||
type Props = {
|
||||
data: ChartData;
|
||||
@@ -41,24 +49,13 @@ const HorizontalBar = ({
|
||||
const option: EChartsOption = useMemo(() => {
|
||||
const fmt = valueFormatter ?? ((v: number) => String(v));
|
||||
|
||||
const defaultTooltip: EChartsOption["tooltip"] = {
|
||||
trigger: "axis",
|
||||
axisPointer: { type: "shadow" },
|
||||
valueFormatter: (v: unknown) => (typeof v === "number" ? fmt(v) : String(v)),
|
||||
};
|
||||
|
||||
const defaultLegend: EChartsOption["legend"] = { top: 0 };
|
||||
const defaultGrid: EChartsOption["grid"] = { left: 16, right: 16, top: 36, bottom: 12, containLabel: true };
|
||||
const defaultXAxis: EChartsOption["xAxis"] = { type: "value" };
|
||||
const defaultYAxis: EChartsOption["yAxis"] = { type: "category", data: data.categories };
|
||||
|
||||
return {
|
||||
color: palette,
|
||||
tooltip: tooltip ?? defaultTooltip,
|
||||
legend: legend ?? defaultLegend,
|
||||
grid: grid ?? defaultGrid,
|
||||
xAxis: xAxis ?? defaultXAxis,
|
||||
yAxis: yAxis ?? defaultYAxis,
|
||||
tooltip: tooltip ?? createDefaultTooltip(fmt),
|
||||
legend: legend ?? createDefaultLegend(),
|
||||
grid: grid ?? createDefaultGrid(),
|
||||
xAxis: xAxis ?? createValueAxis(),
|
||||
yAxis: yAxis ?? createCategoryAxis(data.categories),
|
||||
series: data.series.map((s, index) => {
|
||||
const showLabel = getIsShowLabel(showFocusLabel, index, data.series.length);
|
||||
|
||||
@@ -67,7 +64,7 @@ const HorizontalBar = ({
|
||||
type: "bar",
|
||||
data: s.data,
|
||||
emphasis: { disabled: true },
|
||||
barMaxWidth: barMaxWidth ?? 42,
|
||||
barMaxWidth: barMaxWidth ?? BAR_WIDTHS.DEFAULT,
|
||||
label: showLabel
|
||||
? {
|
||||
show: true,
|
||||
|
||||
@@ -5,6 +5,16 @@ import type { EChartsOption } from "echarts";
|
||||
import BaseEChart from "../BaseEChart";
|
||||
import type { ChartData, ValueFormatter } from "../types";
|
||||
import { buildLgPalette } from "../color";
|
||||
import {
|
||||
createDefaultTooltip,
|
||||
createDefaultLegend,
|
||||
createDefaultGrid,
|
||||
createCategoryAxis,
|
||||
createValueAxis,
|
||||
createBarSeries,
|
||||
createReverseTooltip,
|
||||
createReverseLegend, reverseSeries,
|
||||
} from "@/lib/chart-options";
|
||||
|
||||
type Props = {
|
||||
data: ChartData;
|
||||
@@ -13,7 +23,6 @@ type Props = {
|
||||
paletteVarNames?: string[];
|
||||
valueFormatter?: ValueFormatter;
|
||||
orientation?: "vertical" | "horizontal";
|
||||
/** series.stack이 없을 때 기본 stack key */
|
||||
defaultStackKey?: string;
|
||||
tooltip?: EChartsOption["tooltip"];
|
||||
legend?: EChartsOption["legend"];
|
||||
@@ -21,58 +30,76 @@ type Props = {
|
||||
xAxis?: EChartsOption["xAxis"];
|
||||
yAxis?: EChartsOption["yAxis"];
|
||||
barMaxWidth?: number;
|
||||
isReverse?: boolean;
|
||||
};
|
||||
|
||||
const StackBar = ({
|
||||
data,
|
||||
height,
|
||||
className,
|
||||
paletteVarNames,
|
||||
valueFormatter,
|
||||
orientation = "vertical",
|
||||
defaultStackKey = "total",
|
||||
tooltip,
|
||||
legend,
|
||||
grid,
|
||||
xAxis,
|
||||
yAxis,
|
||||
barMaxWidth,
|
||||
}: Props) => {
|
||||
const palette = useMemo(() => buildLgPalette(paletteVarNames), [paletteVarNames]);
|
||||
data,
|
||||
height,
|
||||
className,
|
||||
paletteVarNames,
|
||||
valueFormatter,
|
||||
orientation = "vertical",
|
||||
defaultStackKey = "total",
|
||||
tooltip,
|
||||
legend,
|
||||
grid,
|
||||
xAxis,
|
||||
yAxis,
|
||||
barMaxWidth,
|
||||
isReverse = false,
|
||||
}: Props) => {
|
||||
|
||||
// ✅ 렌더링용 데이터만 뒤집기
|
||||
const renderData = useMemo(
|
||||
() => (isReverse ? reverseSeries(data) : data),
|
||||
[data, isReverse]
|
||||
);
|
||||
|
||||
// ✅ 팔레트도 뒤집어줘야 "시리즈 이름별" 색이 유지됨
|
||||
const palette = useMemo(() => {
|
||||
const temp = buildLgPalette(paletteVarNames);
|
||||
const n = data.series.length; // 원본 기준
|
||||
const base = temp.slice(0, n);
|
||||
return isReverse ? [...base].reverse() : base;
|
||||
}, [paletteVarNames, data.series.length, isReverse]);
|
||||
|
||||
const option: EChartsOption = useMemo(() => {
|
||||
const fmt = valueFormatter ?? ((v: number) => String(v));
|
||||
|
||||
const isV = orientation === "vertical";
|
||||
|
||||
const defaultTooltip: EChartsOption["tooltip"] = {
|
||||
trigger: "axis",
|
||||
axisPointer: { type: "shadow" },
|
||||
valueFormatter: (v: unknown) => (typeof v === "number" ? fmt(v) : String(v)),
|
||||
};
|
||||
const defaultLegend: EChartsOption["legend"] = { top: 0 };
|
||||
const defaultGrid: EChartsOption["grid"] = { left: 16, right: 16, top: 36, bottom: 12, containLabel: true };
|
||||
const defaultXAxis: EChartsOption["xAxis"] = isV ? { type: "category", data: data.categories } : { type: "value" };
|
||||
const defaultYAxis: EChartsOption["yAxis"] = isV ? { type: "value" } : { type: "category", data: data.categories };
|
||||
return {
|
||||
color: palette,
|
||||
tooltip: tooltip ?? defaultTooltip,
|
||||
legend: legend ?? defaultLegend,
|
||||
grid: grid ?? defaultGrid,
|
||||
xAxis: xAxis ?? defaultXAxis,
|
||||
yAxis: yAxis ?? defaultYAxis,
|
||||
series: data.series.map((s) => ({
|
||||
name: s.name,
|
||||
type: "bar",
|
||||
stack: s.stack ?? defaultStackKey,
|
||||
data: s.data,
|
||||
emphasis: { disabled: true },
|
||||
barMaxWidth: barMaxWidth ?? 42,
|
||||
})),
|
||||
tooltip: tooltip ?? (isReverse ? createReverseTooltip(data, fmt) : createDefaultTooltip(fmt)),
|
||||
legend: legend ?? (isReverse ? createReverseLegend(data) : createDefaultLegend()),
|
||||
grid: grid ?? createDefaultGrid(),
|
||||
xAxis: xAxis ?? (isV ? createCategoryAxis(renderData.categories) : createValueAxis()),
|
||||
yAxis: yAxis ?? (isV ? createValueAxis() : createCategoryAxis(renderData.categories)),
|
||||
|
||||
series: renderData.series.map((s) =>
|
||||
createBarSeries(s.name, s.data, {
|
||||
stack: s.stack ?? defaultStackKey,
|
||||
barMaxWidth,
|
||||
})
|
||||
),
|
||||
};
|
||||
}, [data, palette, valueFormatter, orientation, defaultStackKey, tooltip, legend, grid, xAxis, yAxis, barMaxWidth]);
|
||||
}, [
|
||||
data,
|
||||
renderData,
|
||||
palette,
|
||||
valueFormatter,
|
||||
orientation,
|
||||
defaultStackKey,
|
||||
tooltip,
|
||||
legend,
|
||||
grid,
|
||||
xAxis,
|
||||
yAxis,
|
||||
barMaxWidth,
|
||||
isReverse,
|
||||
]);
|
||||
|
||||
return <BaseEChart option={option} height={height} className={className} />;
|
||||
}
|
||||
};
|
||||
|
||||
export default StackBar;
|
||||
@@ -6,6 +6,14 @@ import BaseEChart from "../BaseEChart";
|
||||
import {ChartData, ShowLabel, ValueFormatter} from "../types";
|
||||
import { buildLgPalette } from "../color";
|
||||
import {getIsShowLabel} from "@/components/lge-dashboard/chart/utill";
|
||||
import {
|
||||
createDefaultTooltip,
|
||||
createDefaultLegend,
|
||||
createDefaultGrid,
|
||||
createCategoryAxis,
|
||||
createValueAxis,
|
||||
} from "@/lib/chart-options";
|
||||
import { BAR_WIDTHS } from "@/const/chartConst";
|
||||
|
||||
type Props = {
|
||||
data: ChartData;
|
||||
@@ -42,24 +50,13 @@ const VerticalBar = ({
|
||||
const option: EChartsOption = useMemo(() => {
|
||||
const fmt = valueFormatter ?? ((v: number) => String(v));
|
||||
|
||||
const defaultTooltip: EChartsOption["tooltip"] = {
|
||||
trigger: "axis",
|
||||
axisPointer: { type: "shadow" },
|
||||
valueFormatter: (v: unknown) => (typeof v === "number" ? fmt(v) : String(v)),
|
||||
};
|
||||
|
||||
const defaultLegend: EChartsOption["legend"] = { top: 0 };
|
||||
const defaultGrid: EChartsOption["grid"] = { left: 16, right: 16, top: 36, bottom: 12, containLabel: true };
|
||||
const defaultXAxis: EChartsOption["xAxis"] = { type: "category", data: data.categories, axisTick: { alignWithLabel: true } };
|
||||
const defaultYAxis: EChartsOption["yAxis"] = { type: "value" };
|
||||
|
||||
return {
|
||||
color: palette,
|
||||
tooltip: tooltip ?? defaultTooltip,
|
||||
legend: legend ?? defaultLegend,
|
||||
grid: grid ?? defaultGrid,
|
||||
xAxis: xAxis ?? defaultXAxis,
|
||||
yAxis: yAxis ?? defaultYAxis,
|
||||
tooltip: tooltip ?? createDefaultTooltip(fmt),
|
||||
legend: legend ?? createDefaultLegend(),
|
||||
grid: grid ?? createDefaultGrid(),
|
||||
xAxis: xAxis ?? createCategoryAxis(data.categories, false, { axisTick: { alignWithLabel: true } }),
|
||||
yAxis: yAxis ?? createValueAxis(),
|
||||
series: data.series.map((s, index) => {
|
||||
const showLabel = getIsShowLabel(showFocusLabel, index, data.series.length);
|
||||
|
||||
@@ -68,7 +65,7 @@ const VerticalBar = ({
|
||||
type: "bar",
|
||||
data: s.data,
|
||||
emphasis: { disabled: true },
|
||||
barMaxWidth: barMaxWidth ?? 42,
|
||||
barMaxWidth: barMaxWidth ?? BAR_WIDTHS.DEFAULT,
|
||||
label: showLabel
|
||||
? {
|
||||
show: true,
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
type Hsl = { h: number; s: number; l: number };
|
||||
|
||||
|
||||
|
||||
const parseHslTriplet = (raw: string): Hsl | null => {
|
||||
// 예: "341.1 100% 32.4%" / "0 0% 85%"
|
||||
const m = raw.trim().match(/^(-?\d+(\.\d+)?)\s+(\d+(\.\d+)?)%\s+(\d+(\.\d+)?)%$/);
|
||||
|
||||
162
src/components/lge-dashboard/combo/BannerSummary.tsx
Normal file
162
src/components/lge-dashboard/combo/BannerSummary.tsx
Normal file
@@ -0,0 +1,162 @@
|
||||
import {ChartData, DataColumn, DataTable, HorizontalBar, LeftChartTable, SignStyle} from "@/components/lge-dashboard";
|
||||
import {BannerKey, ServerBannerRow} from "@/types/lg";
|
||||
import {formatRowLabel, isSampleRow} from "@/lib/lg-dashboard";
|
||||
import {useMemo} from "react";
|
||||
import {BANNER_GROUP, BANNER_KEY_MAP, GRID_Y_NOT_PADDING} from "@/const/lgConst";
|
||||
import {formatNumber, parseNumber} from "@/lib/utils";
|
||||
|
||||
|
||||
type SectionSpec = {
|
||||
title: string;
|
||||
groupKeys: Array<keyof typeof BANNER_GROUP>;
|
||||
};
|
||||
|
||||
/** 3개 섹션(테이블)도 여기서만 선언 */
|
||||
const SECTIONS: SectionSpec[] = [
|
||||
{ title: "가구 형태", groupKeys: ["lifeStage", "household", "age"] },
|
||||
{ title: "거주 형태", groupKeys: ["tenure", "housing", "pyeong"] },
|
||||
{ title: "거주 지역 및 소득 수준", groupKeys: ["region", "income"] },
|
||||
];
|
||||
|
||||
const SEP_R = "lg-table__sep-r";
|
||||
|
||||
const getSectionBannerKeys = (spec: SectionSpec): BannerKey[] =>
|
||||
spec.groupKeys.flatMap((gk) => BANNER_GROUP[gk].keys);
|
||||
|
||||
const buildColumns = (spec: SectionSpec): DataColumn<ServerBannerRow>[] => {
|
||||
const columns: DataColumn<ServerBannerRow>[] = [
|
||||
{
|
||||
key: "rowLabel",
|
||||
header: "",
|
||||
headRowSpan: 2,
|
||||
rowHead: true,
|
||||
cellClassName: "lg-table__rowhead",
|
||||
width: 120,
|
||||
},
|
||||
{
|
||||
key: "total",
|
||||
header: "전체",
|
||||
numeric: true,
|
||||
headerClassName: SEP_R,
|
||||
cellClassName: SEP_R,
|
||||
width: 80,
|
||||
},
|
||||
];
|
||||
|
||||
spec.groupKeys.forEach((groupKey) => {
|
||||
const g = BANNER_GROUP[groupKey];
|
||||
g.keys.forEach((k, idx) => {
|
||||
const isLast = idx === g.keys.length - 1;
|
||||
columns.push({
|
||||
key: k as any,
|
||||
header: BANNER_KEY_MAP[k] ?? String(k),
|
||||
group: g.label,
|
||||
numeric: true,
|
||||
headerClassName: isLast ? SEP_R : undefined,
|
||||
cellClassName: isLast ? SEP_R : undefined,
|
||||
width: 90,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
return columns;
|
||||
};
|
||||
|
||||
type BannerSummaryProps = {
|
||||
data: ServerBannerRow[];
|
||||
useChart: boolean;
|
||||
};
|
||||
|
||||
const BannerSummary = ({ data, useChart }: BannerSummaryProps) => {
|
||||
|
||||
const buildChartData = (rows: ServerBannerRow[], bannerKeys: BannerKey[]): ChartData => {
|
||||
const categories = rows
|
||||
.filter((r) => r.rowLabel !== "사례수")
|
||||
.map((r) => formatRowLabel(r.rowLabel));
|
||||
|
||||
const series = [
|
||||
{
|
||||
name:"전체",
|
||||
data: rows
|
||||
.filter((r) => r.rowLabel !== "사례수")
|
||||
.map((r) => parseNumber(r.total) ?? null),
|
||||
}
|
||||
];
|
||||
|
||||
return { categories, series };
|
||||
};
|
||||
|
||||
const rows = useMemo<ServerBannerRow[]>(() => {
|
||||
const allKeys = Array.from(
|
||||
new Set(Object.values(BANNER_GROUP).flatMap((g) => g.keys))
|
||||
) as string[];
|
||||
|
||||
return data.map((r) => {
|
||||
const out: any = { ...r };
|
||||
|
||||
if (isSampleRow(r.rowLabel)) {
|
||||
// total
|
||||
out.total = `(${formatNumber(Number(r.total ?? 0))})`;
|
||||
// banner values
|
||||
allKeys.forEach((k) => {
|
||||
const v = (r as any)[k];
|
||||
if (typeof v === "number") out[k] = `(${formatNumber(v)})`;
|
||||
});
|
||||
}
|
||||
return out as ServerBannerRow;
|
||||
});
|
||||
}, [data]);
|
||||
|
||||
const signStyleGap: SignStyle<ServerBannerRow> = {
|
||||
rowSelector: (row) => row.rowLabel === "gap",
|
||||
display: "arrow",
|
||||
arrowWithNumber: true,
|
||||
paint: "text",
|
||||
zeroText: "-",
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-6">
|
||||
{SECTIONS.map((spec) => {
|
||||
const bannerKeys = getSectionBannerKeys(spec);
|
||||
|
||||
const columns = buildColumns(spec);
|
||||
const chartData = buildChartData(rows, bannerKeys);
|
||||
|
||||
return (
|
||||
useChart ?
|
||||
<LeftChartTable<ServerBannerRow>
|
||||
key={spec.title}
|
||||
title={spec.title}
|
||||
columns={columns}
|
||||
rows={rows}
|
||||
signStyle={signStyleGap}
|
||||
chart={
|
||||
<HorizontalBar
|
||||
data={chartData}
|
||||
height="100%"
|
||||
showFocusLabel="none"
|
||||
legend={{ show: false }}
|
||||
grid={GRID_Y_NOT_PADDING}
|
||||
xAxis={{ type: "value", show: false }}
|
||||
yAxis={{ type: "category", data: chartData.categories, show: false }}
|
||||
/>
|
||||
}
|
||||
chartCell={{ key: "total", startRowIndex: 1 }}
|
||||
minWidthPx={1200}
|
||||
/>
|
||||
:
|
||||
<DataTable<ServerBannerRow>
|
||||
key={spec.title}
|
||||
title={spec.title}
|
||||
columns={columns}
|
||||
rows={rows}
|
||||
signStyle={signStyleGap}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default BannerSummary;
|
||||
134
src/components/lge-dashboard/combo/CategoryByData.tsx
Normal file
134
src/components/lge-dashboard/combo/CategoryByData.tsx
Normal file
@@ -0,0 +1,134 @@
|
||||
import {
|
||||
bannerType,
|
||||
type DataColumn,
|
||||
DataTable,
|
||||
HorizontalBar, SectionTitle, SignStyle,
|
||||
StackBar
|
||||
} from "@/components/lge-dashboard";
|
||||
import BannerButtons from "@/components/lge-dashboard/BannerButtons";
|
||||
import {totalFilters} from "@/config/filter.data";
|
||||
import {useMemo, useState} from "react";
|
||||
import {BannerGroupKey, CategoryChartMode, ServerBannerRow} from "@/types/lg";
|
||||
import {buildRowLabelSeriesChartData, buildYearSeriesChartData, isBannerGroupKey} from "@/lib/lg-dashboard";
|
||||
import {BANNER_GROUP, BANNER_KEY_MAP, LAST_YEAR} from "@/const/lgConst";
|
||||
import {createDefaultGrid, createDefaultLegend, reverseCategories} from "@/lib/chart-options";
|
||||
|
||||
type CategoryByDataProps = {
|
||||
title?: string;
|
||||
chartMode: CategoryChartMode;
|
||||
allTableData: ServerBannerRow[];
|
||||
fillGreaterThan5?: boolean;
|
||||
chartHeight?: number;
|
||||
chartWidth?: number;
|
||||
}
|
||||
|
||||
const banners: bannerType[] = totalFilters.map((filter) => {
|
||||
return {variable: filter.variable, variableName: filter.variableName}
|
||||
})
|
||||
|
||||
const signStyleGap: SignStyle<ServerBannerRow> = {
|
||||
rowSelector: (row) => row.rowLabel === "gap",
|
||||
display: "arrow",
|
||||
arrowWithNumber: true,
|
||||
paint: "text",
|
||||
zeroText: "-",
|
||||
};
|
||||
|
||||
const CategoryByData = ({
|
||||
title,
|
||||
chartMode,
|
||||
allTableData,
|
||||
fillGreaterThan5,
|
||||
chartHeight,
|
||||
chartWidth,
|
||||
}: CategoryByDataProps) => {
|
||||
const [selectedBanner, setSelectedBanner] = useState<bannerType>(banners[0]);
|
||||
|
||||
const buildColumns = (groupKey: BannerGroupKey): DataColumn<ServerBannerRow>[] => {
|
||||
const columns: DataColumn<ServerBannerRow>[] = [
|
||||
{
|
||||
key: "rowLabel",
|
||||
header: "",
|
||||
headRowSpan: 2,
|
||||
rowHead: true,
|
||||
cellClassName: "lg-table__rowhead",
|
||||
width: 120,
|
||||
},
|
||||
];
|
||||
|
||||
const g = BANNER_GROUP[groupKey];
|
||||
g.keys.forEach((k) => {
|
||||
columns.push({
|
||||
key: k as any,
|
||||
header: BANNER_KEY_MAP[k] ?? String(k),
|
||||
group: g.label,
|
||||
numeric: true,
|
||||
width: 90,
|
||||
});
|
||||
});
|
||||
|
||||
return columns;
|
||||
};
|
||||
|
||||
const chartData = useMemo(() => {
|
||||
const excludeRowLabels =["사례수", "gap"];
|
||||
if(chartMode == "horizontal"){
|
||||
return reverseCategories(buildYearSeriesChartData(allTableData, {excludeRowLabels}));
|
||||
}
|
||||
|
||||
return buildRowLabelSeriesChartData(allTableData, {excludeRowLabels});
|
||||
|
||||
}, [allTableData, chartMode]);
|
||||
|
||||
const tableColumns = useMemo(() => {
|
||||
const v = selectedBanner.variable;
|
||||
return isBannerGroupKey(v) ? buildColumns(v) : [];
|
||||
}, [selectedBanner.variable]);
|
||||
const tableData = useMemo(() => allTableData.filter((row) => row.year === LAST_YEAR), [allTableData, LAST_YEAR])
|
||||
|
||||
return (
|
||||
<div>
|
||||
{title && <SectionTitle title={title} />}
|
||||
<div className="flex gap-6 p-3">
|
||||
<div className="flex-shrink-0" style={{ width: `${chartWidth ?? 400}px`}}>
|
||||
{
|
||||
chartMode === "stack" || chartMode === "reverseStack" ?
|
||||
<StackBar
|
||||
data={chartData}
|
||||
height={`${chartHeight ?? 340}px`}
|
||||
legend={createDefaultLegend({ top: 0 })}
|
||||
grid={createDefaultGrid("default", { top: 52 })}
|
||||
isReverse={chartMode === "reverseStack"}
|
||||
/>
|
||||
:
|
||||
<HorizontalBar
|
||||
data={chartData}
|
||||
height={`${chartHeight ?? 340}px`}
|
||||
showFocusLabel="none"
|
||||
/>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div className="flex items-center">
|
||||
<BannerButtons
|
||||
banners={banners}
|
||||
selectedBanner={selectedBanner}
|
||||
onSelectBanner={setSelectedBanner}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="flex-1">
|
||||
<DataTable
|
||||
columns={tableColumns}
|
||||
rows={tableData}
|
||||
signStyle={signStyleGap}
|
||||
wrapperClassName="border rounded-lg"
|
||||
fillGreaterThan5={fillGreaterThan5}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default CategoryByData;
|
||||
@@ -1,9 +1,10 @@
|
||||
"use client";
|
||||
|
||||
import React, { useMemo } from "react";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { cn, parseNumber } from "@/lib/utils";
|
||||
import type { DataColumn, SignStyle } from "../types";
|
||||
import SectionTitle from "../SectionTitle";
|
||||
import { TABLE_DIMENSIONS } from "@/const/chartConst";
|
||||
|
||||
type MergedChartCell<T> = {
|
||||
/** 차트를 삽입할 컬럼 key(해당 컬럼 td는 startRow에서만 렌더되고 rowSpan 적용) */
|
||||
@@ -33,17 +34,7 @@ type Props<T extends Record<string, unknown>> = {
|
||||
minWidthPx?: number;
|
||||
};
|
||||
|
||||
function toNumber(v: unknown): number | null {
|
||||
if (v === null || v === undefined) return null;
|
||||
if (typeof v === "number") return Number.isFinite(v) ? v : null;
|
||||
if (typeof v === "string") {
|
||||
const s = v.trim();
|
||||
if (s === "" || s === "-") return null;
|
||||
const n = Number(s.replaceAll(",", ""));
|
||||
return Number.isFinite(n) ? n : null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
// toNumber는 utils.ts의 parseNumber로 통합됨
|
||||
|
||||
function renderSigned(
|
||||
n: number,
|
||||
@@ -73,7 +64,7 @@ export default function LeftChartTable<T extends Record<string, unknown>>({
|
||||
signStyle,
|
||||
wrapperClassName,
|
||||
tableClassName,
|
||||
minWidthPx = 1200,
|
||||
minWidthPx = TABLE_DIMENSIONS.MIN_WIDTH.COMPACT,
|
||||
}: Props<T>) {
|
||||
const hasGroupHeader = useMemo(
|
||||
() => columns.some((c) => c.group) || columns.some((c) => c.headRowSpan === 2),
|
||||
@@ -184,8 +175,8 @@ export default function LeftChartTable<T extends Record<string, unknown>>({
|
||||
<tr key={ri}>
|
||||
{columns.map((c) => {
|
||||
// 머지-차트 셀
|
||||
if (c.key === chartCell.key) {
|
||||
if (ri !== start) return null;
|
||||
if (c.key === chartCell.key && ri >= start) {
|
||||
if (ri > start) return null;
|
||||
return (
|
||||
<td
|
||||
key={String(c.key)}
|
||||
@@ -208,7 +199,7 @@ export default function LeftChartTable<T extends Record<string, unknown>>({
|
||||
? raw
|
||||
: String(raw);
|
||||
|
||||
const n = isSignRow ? toNumber(raw) : null;
|
||||
const n = isSignRow ? parseNumber(raw) : null;
|
||||
const shouldSign = isSignRow && (signStyle?.keys ? signStyle.keys.includes(c.key) : !!c.numeric);
|
||||
|
||||
if (c.rowHead) {
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
import GaugeCardTable from "../combo/GaugeCardTable";
|
||||
import GaugeCardTable from "./GaugeCardTable";
|
||||
import {GaugeColumn} from "@/components/lge-dashboard";
|
||||
import {useMemo} from "react";
|
||||
import {apiLifeStageByProduct} from "@/config/sample.data";
|
||||
import {LifeStageRow} from "@/types/lg";
|
||||
import {asNum, norm} from "@/lib/utils";
|
||||
|
||||
const LifeStageDiv = () => {
|
||||
const norm = (s: string) => s.replace(/\s+/g, "").toLowerCase();
|
||||
const asNum = (v: unknown): number | null => typeof v === "number" && Number.isFinite(v) ? v : null;
|
||||
|
||||
const LIFE_STAGE_COLUMNS: GaugeColumn<LifeStageRow>[] = [
|
||||
{ key: "item", header: "", rowHead: true, renderLabel: (r) => r.item },
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
"use client";
|
||||
|
||||
import React, { useMemo } from "react";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { cn, parseNumber } from "@/lib/utils";
|
||||
import type { ChartData, SignStyle, TopChartTableRow } from "../types";
|
||||
import SectionTitle from "../SectionTitle";
|
||||
import { CHART_HEIGHTS, TABLE_DIMENSIONS } from "@/const/chartConst";
|
||||
|
||||
type BaseProps = {
|
||||
title?: string;
|
||||
@@ -49,17 +50,7 @@ type ChartDataModeProps = BaseProps & {
|
||||
|
||||
export type TopChartTableProps = HtmlModeProps | ChartDataModeProps;
|
||||
|
||||
function toNumber(v: unknown): number | null {
|
||||
if (v === null || v === undefined) return null;
|
||||
if (typeof v === "number") return Number.isFinite(v) ? v : null;
|
||||
if (typeof v === "string") {
|
||||
const s = v.trim();
|
||||
if (s === "" || s === "-") return null;
|
||||
const n = Number(s.replaceAll(",", ""));
|
||||
return Number.isFinite(n) ? n : null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
// toNumber는 utils.ts의 parseNumber로 통합됨
|
||||
|
||||
function formatSignedNumber(n: number, zeroText: string, showPlus: boolean) {
|
||||
if (n === 0) return zeroText;
|
||||
@@ -78,8 +69,8 @@ export default function TopChartTable(props: TopChartTableProps) {
|
||||
const {
|
||||
title,
|
||||
chart,
|
||||
chartHeight = 260,
|
||||
minWidthPx = 1600,
|
||||
chartHeight = CHART_HEIGHTS.DEFAULT,
|
||||
minWidthPx = TABLE_DIMENSIONS.MIN_WIDTH.STANDARD,
|
||||
tableClassName,
|
||||
wrapperClassName,
|
||||
signStyle,
|
||||
@@ -122,7 +113,7 @@ export default function TopChartTable(props: TopChartTableProps) {
|
||||
categories,
|
||||
series: rows.map((r) => ({
|
||||
name: r.label,
|
||||
data: r.values.map((v) => toNumber(v) ?? null),
|
||||
data: r.values.map((v) => parseNumber(v) ?? null),
|
||||
})),
|
||||
}),
|
||||
[categories, rows]
|
||||
@@ -174,7 +165,7 @@ export default function TopChartTable(props: TopChartTableProps) {
|
||||
|
||||
{categories.map((_, ci) => {
|
||||
const raw = r.values?.[ci];
|
||||
const n = toNumber(raw);
|
||||
const n = parseNumber(raw);
|
||||
|
||||
// 일반 행
|
||||
if (!isSignRow) {
|
||||
|
||||
@@ -14,7 +14,7 @@ export { default as GaugeTable } from "./table/GaugeTable";
|
||||
export { default as TopChartTable } from "./combo/TopChartTable";
|
||||
export { default as LeftChartTable } from "./combo/LeftChartTable";
|
||||
export { default as GaugeCardTable } from "./combo/GaugeCardTable";
|
||||
export { default as CategoryByData } from "./sub-page/CategoryByData"
|
||||
export { default as CategoryByData } from "./combo/CategoryByData"
|
||||
|
||||
export { default as CardDefault } from "./card/Card";
|
||||
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
import {bannerType, type ChartData, type DataColumn, DataTable, StackBar} from "@/components/lge-dashboard";
|
||||
import BannerButtons from "@/components/lge-dashboard/BannerButtons";
|
||||
import {totalFilters} from "@/config/filter.data";
|
||||
import {useEffect, useState} from "react";
|
||||
|
||||
type CategoryByDataProps<T extends Record<string, unknown>> = {
|
||||
chartData:ChartData;
|
||||
tableColumns: DataColumn<T>[];
|
||||
allTableData: T[];
|
||||
}
|
||||
|
||||
const banners: bannerType[] = totalFilters.map((filter) => {
|
||||
return {variable: filter.variable, variableName: filter.variableName}
|
||||
})
|
||||
|
||||
const CategoryByData = <T extends Record<string, unknown>>({
|
||||
chartData,
|
||||
tableColumns,
|
||||
allTableData,
|
||||
}: CategoryByDataProps<T>) => {
|
||||
const [selectedBanner, setSelectedBanner] = useState<bannerType>(banners[0]);
|
||||
const [tableData, setTableData] = useState<T[]>([]);
|
||||
|
||||
useEffect(() => {
|
||||
const filteredTableData = allTableData.filter((row) => row[selectedBanner.variable] === selectedBanner.variableName);
|
||||
setTableData(filteredTableData);
|
||||
}, [selectedBanner, allTableData]);
|
||||
|
||||
return (
|
||||
<div className="flex gap-6 p-6">
|
||||
{/* 좌측: 차트 */}
|
||||
<div className="flex-shrink-0" style={{ width: "300px" }}>
|
||||
<StackBar
|
||||
data={chartData}
|
||||
height={300}
|
||||
paletteVarNames={[
|
||||
"--lg-red-300",
|
||||
"--lg-red-400",
|
||||
"--lg-red-500",
|
||||
]}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* 중앙: 버튼 */}
|
||||
<div className="flex items-center">
|
||||
<BannerButtons
|
||||
banners={banners}
|
||||
selectedBanner={selectedBanner}
|
||||
onSelectBanner={setSelectedBanner}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* 우측: 테이블 */}
|
||||
<div className="flex-1">
|
||||
<DataTable
|
||||
columns={tableColumns}
|
||||
rows={tableData}
|
||||
wrapperClassName="border rounded-lg"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default CategoryByData;
|
||||
48
src/components/lge-dashboard/sub-page/CategoryPage.tsx
Normal file
48
src/components/lge-dashboard/sub-page/CategoryPage.tsx
Normal file
@@ -0,0 +1,48 @@
|
||||
'use client'
|
||||
import {useLayoutFilter} from "@/components/layout/LayoutFilterContext";
|
||||
import {CategoryTargetData} from "@/config/filter.types";
|
||||
import Profile from "./category-page/Profile";
|
||||
import PenetrationChange from "./category-page/PenetrationChange";
|
||||
import Brand from "./category-page/Brand";
|
||||
import TypeSpec from "./category-page/TypeSpec";
|
||||
import OwnershipPath from "./category-page/OwnershipPath";
|
||||
import PurchaseBehavior from "./category-page/PurchaseBehavior";
|
||||
import PurchaseChannel from "./category-page/PurchaseChannel";
|
||||
import PaymentMethod from "./category-page/PaymentMethod";
|
||||
|
||||
|
||||
const CategoryPage = () => {
|
||||
const { isTotal, filterValue } = useLayoutFilter();
|
||||
console.log(filterValue);
|
||||
|
||||
const renderPage = () => {
|
||||
if (isTotal) return null;
|
||||
|
||||
const target = filterValue.target;
|
||||
|
||||
switch (target) {
|
||||
case CategoryTargetData.PROFILE:
|
||||
return <Profile />;
|
||||
case CategoryTargetData.PENETRATION_CHANGE:
|
||||
return <PenetrationChange />;
|
||||
case CategoryTargetData.BRAND:
|
||||
return <Brand />;
|
||||
case CategoryTargetData.TYPE_SPEC:
|
||||
return <TypeSpec />;
|
||||
case CategoryTargetData.OWNERSHIP_PATH:
|
||||
return <OwnershipPath />;
|
||||
case CategoryTargetData.PURCHASE_BEHAVIOR:
|
||||
return <PurchaseBehavior />;
|
||||
case CategoryTargetData.PURCHASE_CHANNEL:
|
||||
return <PurchaseChannel />;
|
||||
case CategoryTargetData.PAYMENT_METHOD:
|
||||
return <PaymentMethod />;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
return renderPage();
|
||||
}
|
||||
|
||||
export default CategoryPage;
|
||||
@@ -0,0 +1,62 @@
|
||||
'use client'
|
||||
|
||||
import {useMemo} from "react";
|
||||
import {useLayoutFilter} from "@/components/layout/LayoutFilterContext";
|
||||
import {CategoryByData} from "@/components/lge-dashboard";
|
||||
import {apiBrandShareByYear, apiPaymentMethodByYear} from "@/config/sample.data";
|
||||
import {PageData, ServerBannerRow} from "@/types/lg";
|
||||
import {buildGapRow} from "@/lib/lg-dashboard";
|
||||
|
||||
const Brand = () => {
|
||||
const { filterValue } = useLayoutFilter();
|
||||
console.log(filterValue);
|
||||
|
||||
const tableDataArray = useMemo<PageData<ServerBannerRow>[]>(() => {
|
||||
const cleaned = apiBrandShareByYear.filter(
|
||||
(r) => !(r.year === 26 && r.rowLabel === "gap")
|
||||
);
|
||||
|
||||
const gapRow = buildGapRow(cleaned, 25, 26, "lg", "gap");
|
||||
|
||||
let finalData = cleaned;
|
||||
|
||||
if (gapRow) {
|
||||
const insertIdx = cleaned.findIndex(
|
||||
(r) => r.year === 26 && r.rowLabel === "lg"
|
||||
);
|
||||
|
||||
if (insertIdx >= 0) {
|
||||
finalData = [
|
||||
...cleaned.slice(0, insertIdx + 1),
|
||||
gapRow,
|
||||
...cleaned.slice(insertIdx + 1),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
{
|
||||
title: "구매 형식",
|
||||
chartMode: "reverseStack",
|
||||
data: finalData,
|
||||
},
|
||||
];
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div>
|
||||
{tableDataArray.map((tableData) => (
|
||||
<CategoryByData
|
||||
key={`cbd-${tableData.title.replaceAll(/\s+/g, "_")}`}
|
||||
title={tableData.title}
|
||||
chartMode={tableData.chartMode}
|
||||
allTableData={tableData.data}
|
||||
chartHeight={tableData.chartHeight}
|
||||
chartWidth={tableData.chartWidth}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default Brand;
|
||||
@@ -0,0 +1,34 @@
|
||||
'use client'
|
||||
|
||||
import {useLayoutFilter} from "@/components/layout/LayoutFilterContext";
|
||||
import {useMemo} from "react";
|
||||
import {PageData, ServerBannerRow} from "@/types/lg";
|
||||
import {apiOwnershipPathByYear, apiOwnershipTriggerByYear} from "@/config/sample.data";
|
||||
import {CategoryByData} from "@/components/lge-dashboard";
|
||||
|
||||
const OwnershipPath = () => {
|
||||
const { filterValue } = useLayoutFilter();
|
||||
console.log(filterValue);
|
||||
|
||||
const tableDataArray = useMemo<PageData<ServerBannerRow>[]>(() => [
|
||||
{title: "보유 경로", chartMode:"reverseStack", data: apiOwnershipPathByYear.filter(r => !(r.year === 26 && r.rowLabel === "gap"))},
|
||||
{title: "구입 계기", chartMode:"horizontal", data: apiOwnershipTriggerByYear.filter(r => !(r.year === 26 && r.rowLabel === "gap"))},
|
||||
], []);
|
||||
|
||||
return (
|
||||
<div>
|
||||
{tableDataArray.map((tableData) => (
|
||||
<CategoryByData
|
||||
key={`cbd-${tableData.title.replaceAll(/\s+/g, "_")}`}
|
||||
title={tableData.title}
|
||||
chartMode={tableData.chartMode}
|
||||
allTableData={tableData.data}
|
||||
chartHeight={tableData.chartHeight}
|
||||
chartWidth={tableData.chartWidth}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default OwnershipPath;
|
||||
@@ -0,0 +1,33 @@
|
||||
'use client'
|
||||
|
||||
import {useLayoutFilter} from "@/components/layout/LayoutFilterContext";
|
||||
import {apiOwnershipPathByYear, apiOwnershipTriggerByYear, apiPaymentMethodByYear} from "@/config/sample.data";
|
||||
import {useMemo} from "react";
|
||||
import {PageData, ServerBannerRow} from "@/types/lg";
|
||||
import {CategoryByData} from "@/components/lge-dashboard";
|
||||
|
||||
const PaymentMethod = () => {
|
||||
const { filterValue } = useLayoutFilter();
|
||||
console.log(filterValue);
|
||||
|
||||
const tableDataArray = useMemo<PageData<ServerBannerRow>[]>(() => [
|
||||
{title: "구매 형식", chartMode:"reverseStack", data: apiPaymentMethodByYear.filter(r => !(r.year === 26 && r.rowLabel === "gap"))},
|
||||
], []);
|
||||
|
||||
return (
|
||||
<div>
|
||||
{tableDataArray.map((tableData) => (
|
||||
<CategoryByData
|
||||
key={`cbd-${tableData.title.replaceAll(/\s+/g, "_")}`}
|
||||
title={tableData.title}
|
||||
chartMode={tableData.chartMode}
|
||||
allTableData={tableData.data}
|
||||
chartHeight={tableData.chartHeight}
|
||||
chartWidth={tableData.chartWidth}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default PaymentMethod;
|
||||
@@ -0,0 +1,24 @@
|
||||
'use client'
|
||||
|
||||
import {useLayoutFilter} from "@/components/layout/LayoutFilterContext";
|
||||
import BannerSummary from "@/components/lge-dashboard/combo/BannerSummary";
|
||||
import {useEffect, useState} from "react";
|
||||
import {ServerBannerRow} from "@/types/lg";
|
||||
import {apiYearIndex} from "@/config/sample.data";
|
||||
|
||||
const PenetrationChange = () => {
|
||||
const { filterValue } = useLayoutFilter();
|
||||
console.log(filterValue);
|
||||
|
||||
const [penetrationChangeData, setPenetrationChangeData] = useState<ServerBannerRow[]>([]);
|
||||
|
||||
useEffect(() => {
|
||||
setPenetrationChangeData(apiYearIndex)
|
||||
},[])
|
||||
|
||||
return(
|
||||
<BannerSummary data={penetrationChangeData} useChart={true} />
|
||||
);
|
||||
}
|
||||
|
||||
export default PenetrationChange
|
||||
@@ -0,0 +1,42 @@
|
||||
'use client'
|
||||
|
||||
import {useLayoutFilter} from "@/components/layout/LayoutFilterContext";
|
||||
import BannerSummary from "@/components/lge-dashboard/combo/BannerSummary";
|
||||
import {useEffect, useMemo, useState} from "react";
|
||||
import {ServerBannerRow} from "@/types/lg";
|
||||
import {apiOwnershipSummary, apiPurchaseRateKpis} from "@/config/sample.data";
|
||||
|
||||
const Profile = () => {
|
||||
const { isTotal, filterValue } = useLayoutFilter();
|
||||
const [profileData, setProfileData] = useState<ServerBannerRow[]>([]);
|
||||
|
||||
const typeLabel = useMemo(() => {
|
||||
if (isTotal) return null; // SelectedMap 경로
|
||||
return filterValue.type.label; // CategoryFilterValue 경로로 TS가 좁혀짐
|
||||
}, [isTotal, filterValue]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!typeLabel) return;
|
||||
|
||||
switch (typeLabel) {
|
||||
case "보유":
|
||||
setProfileData(apiOwnershipSummary);
|
||||
break;
|
||||
case "구매":
|
||||
setProfileData(apiPurchaseRateKpis);
|
||||
break;
|
||||
case "향후 구매":
|
||||
setProfileData(apiPurchaseRateKpis);
|
||||
break;
|
||||
default:
|
||||
setProfileData([]);
|
||||
break;
|
||||
}
|
||||
}, [typeLabel]);
|
||||
|
||||
return (
|
||||
<BannerSummary data={profileData} useChart={false} />
|
||||
);
|
||||
}
|
||||
|
||||
export default Profile;
|
||||
@@ -0,0 +1,34 @@
|
||||
'use client'
|
||||
|
||||
import {useLayoutFilter} from "@/components/layout/LayoutFilterContext";
|
||||
import {useMemo} from "react";
|
||||
import {PageData, ServerBannerRow} from "@/types/lg";
|
||||
import { apiOwnershipPathByYear, apiOwnershipTriggerByYear} from "@/config/sample.data";
|
||||
import {CategoryByData} from "@/components/lge-dashboard";
|
||||
|
||||
const PurchaseBehavior = () => {
|
||||
const { filterValue } = useLayoutFilter();
|
||||
console.log(filterValue);
|
||||
|
||||
const tableDataArray = useMemo<PageData<ServerBannerRow>[]>(() => [
|
||||
{title: "보유 경로", chartMode:"horizontal", data: apiOwnershipPathByYear.filter(r => !(r.year === 26 && r.rowLabel === "gap"))},
|
||||
{title: "구입 계기", chartMode:"horizontal", data: apiOwnershipTriggerByYear.filter(r => !(r.year === 26 && r.rowLabel === "gap"))},
|
||||
], []);
|
||||
|
||||
return (
|
||||
<div>
|
||||
{tableDataArray.map((tableData) => (
|
||||
<CategoryByData
|
||||
key={`cbd-${tableData.title.replaceAll(/\s+/g, "_")}`}
|
||||
title={tableData.title}
|
||||
chartMode={tableData.chartMode}
|
||||
allTableData={tableData.data}
|
||||
chartHeight={tableData.chartHeight}
|
||||
chartWidth={tableData.chartWidth}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default PurchaseBehavior;
|
||||
@@ -0,0 +1,38 @@
|
||||
'use client'
|
||||
|
||||
import {useLayoutFilter} from "@/components/layout/LayoutFilterContext";
|
||||
import {apiOwnershipPathByYear, apiOwnershipTriggerByYear, apiPurchaseChannelByYear} from "@/config/sample.data";
|
||||
import {useMemo} from "react";
|
||||
import {PageData, ServerBannerRow} from "@/types/lg";
|
||||
import {CategoryByData} from "@/components/lge-dashboard";
|
||||
|
||||
const PurchaseChannel = () => {
|
||||
const { filterValue } = useLayoutFilter();
|
||||
console.log(filterValue);
|
||||
|
||||
const tableDataArray = useMemo<PageData<ServerBannerRow>[]>(() => [
|
||||
{
|
||||
title: "구매 채널",
|
||||
chartMode: "horizontal",
|
||||
data: apiPurchaseChannelByYear.filter(r => !(r.year === 26 && r.rowLabel === "gap")),
|
||||
chartHeight: 550,
|
||||
},
|
||||
], []);
|
||||
|
||||
return (
|
||||
<div>
|
||||
{tableDataArray.map((tableData) => (
|
||||
<CategoryByData
|
||||
key={`cbd-${tableData.title.replaceAll(/\s+/g, "_")}`}
|
||||
title={tableData.title}
|
||||
chartMode={tableData.chartMode}
|
||||
allTableData={tableData.data}
|
||||
chartHeight={tableData.chartHeight}
|
||||
chartWidth={tableData.chartWidth}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default PurchaseChannel;
|
||||
@@ -0,0 +1,37 @@
|
||||
'use client'
|
||||
|
||||
import {useLayoutFilter} from "@/components/layout/LayoutFilterContext";
|
||||
import {useMemo} from "react";
|
||||
import {PageData, ServerBannerRow} from "@/types/lg";
|
||||
import {apiFridgeDoorTypeByYear} from "@/config/sample.data";
|
||||
import {CategoryByData} from "@/components/lge-dashboard";
|
||||
|
||||
const TypeSpec = () => {
|
||||
const { filterValue } = useLayoutFilter();
|
||||
console.log(filterValue);
|
||||
|
||||
const tableDataArray = useMemo<PageData<ServerBannerRow>[]>(() => [
|
||||
{
|
||||
title: "타입",
|
||||
chartMode: "horizontal",
|
||||
data: apiFridgeDoorTypeByYear.filter(r => !(r.year === 26 && r.rowLabel === "gap")),
|
||||
},
|
||||
], []);
|
||||
|
||||
return (
|
||||
<div>
|
||||
{tableDataArray.map((tableData) => (
|
||||
<CategoryByData
|
||||
key={`cbd-${tableData.title.replaceAll(/\s+/g, "_")}`}
|
||||
title={tableData.title}
|
||||
chartMode={tableData.chartMode}
|
||||
allTableData={tableData.data}
|
||||
chartHeight={tableData.chartHeight}
|
||||
chartWidth={tableData.chartWidth}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default TypeSpec;
|
||||
@@ -2,32 +2,21 @@
|
||||
|
||||
import { useMemo } from "react";
|
||||
import type React from "react";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { cn, parseNumber } from "@/lib/utils";
|
||||
import type { DataColumn, SignDisplayMode, SignStyle } from "../types";
|
||||
import SectionTitle from "../SectionTitle";
|
||||
|
||||
type Props<T extends Record<string, unknown>> = {
|
||||
columns: DataColumn<T>[];
|
||||
rows: T[];
|
||||
title?: string;
|
||||
className?: string;
|
||||
wrapperClassName?: string;
|
||||
signStyle?: SignStyle<T>;
|
||||
fillGreaterThan5?: boolean;
|
||||
};
|
||||
|
||||
const parseSignedNumber = (raw: unknown): number | null => {
|
||||
if (raw === null || raw === undefined) return null;
|
||||
if (typeof raw === "number") return Number.isFinite(raw) ? raw : null;
|
||||
if (typeof raw === "string") {
|
||||
const s = raw
|
||||
.trim()
|
||||
.replaceAll(",", "")
|
||||
.replaceAll("−", "-") // 유니코드 마이너스
|
||||
.replaceAll("%", "");
|
||||
if (s === "" || s === "-") return null;
|
||||
const n = Number(s);
|
||||
return Number.isFinite(n) ? n : null;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
// parseSignedNumber는 utils.ts의 parseNumber로 통합됨
|
||||
|
||||
const defaultFmt = (v: number) =>
|
||||
Number.isInteger(v) ? String(v) : v.toLocaleString();
|
||||
@@ -53,20 +42,22 @@ const signText = (
|
||||
};
|
||||
|
||||
const DataTable = <T extends Record<string, unknown>>({
|
||||
columns,
|
||||
rows,
|
||||
className,
|
||||
wrapperClassName,
|
||||
signStyle,
|
||||
}: Props<T>) => {
|
||||
columns,
|
||||
rows,
|
||||
title,
|
||||
className,
|
||||
wrapperClassName,
|
||||
signStyle,
|
||||
fillGreaterThan5 = false,
|
||||
}: Props<T>) => {
|
||||
const hasGroup = columns.some((c) => !!c.group) || columns.some((c) => c.headRowSpan === 2);
|
||||
|
||||
// group header(1행): rowspan=2 컬럼(th) + group label(colspan)
|
||||
const groupCells = useMemo(() => {
|
||||
type GroupCell =
|
||||
| { kind: "rowspan"; label: string; colSpan: 1; rowSpan: 2; className?: string }
|
||||
| { kind: "group"; label: string; colSpan: number; rowSpan: 1; className?: string }
|
||||
| { kind: "blank"; label: string; colSpan: 1; rowSpan: 1; className?: string };
|
||||
| { kind: "rowspan"; label: string; colSpan: 1; rowSpan: 2; className?: string }
|
||||
| { kind: "group"; label: string; colSpan: number; rowSpan: 1; className?: string }
|
||||
| { kind: "blank"; label: string; colSpan: 1; rowSpan: 1; className?: string };
|
||||
|
||||
if (!hasGroup) return [] as GroupCell[];
|
||||
|
||||
@@ -148,6 +139,9 @@ const DataTable = <T extends Record<string, unknown>>({
|
||||
|
||||
return (
|
||||
<div className={cn("w-full overflow-x-auto", wrapperClassName)}>
|
||||
{title && (
|
||||
<SectionTitle title={title} />
|
||||
)}
|
||||
<table className={cn("lg-table", className)}>
|
||||
<thead>
|
||||
{hasGroup && (
|
||||
@@ -178,6 +172,7 @@ const DataTable = <T extends Record<string, unknown>>({
|
||||
<tbody>
|
||||
{rows.map((row, rIdx) => {
|
||||
const signRow = isSignRow(row, rIdx);
|
||||
const total = parseNumber(row.total);
|
||||
|
||||
return (
|
||||
<tr key={rIdx}>
|
||||
@@ -191,7 +186,7 @@ const DataTable = <T extends Record<string, unknown>>({
|
||||
const applySign = signRow && isTargetKey(c.key) && !c.rowHead;
|
||||
|
||||
if (applySign) {
|
||||
const n = parseSignedNumber(raw);
|
||||
const n = parseNumber(raw);
|
||||
const displayText =
|
||||
n === null ? "-" : signText(n, display, showPlus, arrowWithNumber, fmt, zeroText);
|
||||
|
||||
@@ -230,8 +225,13 @@ const DataTable = <T extends Record<string, unknown>>({
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
const numContent = c.numeric ? parseNumber(content) ?? 0 : 0;
|
||||
const isFill = fillGreaterThan5 && total && numContent > total + 5;
|
||||
return (
|
||||
<td key={String(c.key)} style={{ textAlign: align }} className={c.cellClassName}>
|
||||
<td key={String(c.key)} style={{ textAlign: align }} className={
|
||||
cn(c.cellClassName, isFill? "bg-red-200" :"")
|
||||
}>
|
||||
{content}
|
||||
</td>
|
||||
);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import { useMemo } from "react";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { cn, parseNumber } from "@/lib/utils";
|
||||
import {GaugeColumn} from "../types";
|
||||
|
||||
type Props<T extends Record<string, unknown>> = {
|
||||
@@ -24,14 +24,7 @@ type Props<T extends Record<string, unknown>> = {
|
||||
valueFormatter?: (v: number) => string;
|
||||
};
|
||||
|
||||
const num = (v: unknown) => {
|
||||
if (typeof v === "number" && Number.isFinite(v)) return v;
|
||||
if (typeof v === "string") {
|
||||
const n = Number(v.replaceAll(",", "").replaceAll("%", "").trim());
|
||||
return Number.isFinite(n) ? n : null;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
// num은 utils.ts의 parseNumber로 통합됨
|
||||
|
||||
const GaugeTable = <T extends Record<string, unknown>>({
|
||||
columns,
|
||||
@@ -130,7 +123,7 @@ const GaugeTable = <T extends Record<string, unknown>>({
|
||||
}
|
||||
|
||||
const raw = row[c.key];
|
||||
const v = num(raw);
|
||||
const v = parseNumber(raw);
|
||||
const max = c.max ?? 100;
|
||||
const ratio = v === null ? 0 : clamp01((v * scale) / max);
|
||||
const pct = ratio * 100;
|
||||
|
||||
@@ -124,6 +124,7 @@ export const signStyleGapRow: SignStyle<TopChartTableRow> = {
|
||||
arrowWithNumber: true,
|
||||
paint: "text",
|
||||
};
|
||||
|
||||
/** ChartLabel 보여지는 옵션 */
|
||||
export type ShowLabel = "none" | "all" | "last" | "first";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user