260128_03_ENH: 샘플데이터 랜덤 적용, lg 보급률 하단 카드 + 게이지 테이블 적용
This commit is contained in:
@@ -1,15 +1,18 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import {Button} from "@/components/ui/button";
|
|
||||||
import TopChartTable from "../../../../../components/lge-dashboard/combo/TopChartTable";
|
|
||||||
import {
|
import {
|
||||||
GroupedOverlayBar, GroupedOverlayBarData,
|
GaugeCardTable, GaugeColumn,
|
||||||
signStyleGapRow, TopChartTableRow
|
GroupedOverlayBar, GroupedOverlayBarData, LifeStageRow,
|
||||||
|
signStyleGapRow, TopChartTable, TopChartTableRow
|
||||||
} from "@/components/lge-dashboard";
|
} from "@/components/lge-dashboard";
|
||||||
import {PRODUCT_KEYS, PRODUCTS, YEARS} from "@/const/lgConst";
|
import {PRODUCT_KEYS, PRODUCTS, YEARS} from "@/const/lgConst";
|
||||||
import {useLayoutFilter} from "@/components/layout/LayoutFilterContext";
|
import {useMemo} from "react";
|
||||||
import {useEffect} from "react";
|
import {
|
||||||
import {apiOwnShareOfTotalPenetration, apiTrendCategories} from "@/config/sample.data";
|
apiLifeStageByProduct,
|
||||||
|
apiLifeStageByProductForGauge,
|
||||||
|
apiOwnShareOfTotalPenetration,
|
||||||
|
apiTrendCategories
|
||||||
|
} from "@/config/sample.data";
|
||||||
|
|
||||||
const LGPenetrationPage = () => {
|
const LGPenetrationPage = () => {
|
||||||
|
|
||||||
@@ -54,6 +57,53 @@ const LGPenetrationPage = () => {
|
|||||||
focus: focus,
|
focus: focus,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 },
|
||||||
|
|
||||||
|
{ key: "total", header: "전체", max: 100, align: "left", cellType:"number"},
|
||||||
|
{ key: "single", header: "미혼", max: 100 , align: "left"},
|
||||||
|
|
||||||
|
{ key: "noKids", header: "무자녀", group: "기혼", max: 100 , align: "left"},
|
||||||
|
{ key: "preschoolKids", header: "미취학", group: "기혼", max: 100 , align: "left"},
|
||||||
|
{ key: "schoolKids", header: "취학자녀", group: "기혼", max: 100 , align: "left"},
|
||||||
|
{ key: "adultKids", header: "성인자녀", group: "기혼", max: 100 , align: "left"},
|
||||||
|
|
||||||
|
{ key: "independentSenior", header: "독립\n시니어", max: 100 , align: "left"},
|
||||||
|
];
|
||||||
|
|
||||||
|
const LIFE_STAGE_GROUPS = [
|
||||||
|
{ title: "필수가전 군", items: ["냉장고", "세탁기", "에어컨", "TV", "청소기", "김치 냉장고"] },
|
||||||
|
{ title: "케어가전 군", items: ["공기 청정기", "가습기", "제습기"] },
|
||||||
|
{ title: "Must & Best", items: ["건조기", "식기 세척기", "의류 관리기"] },
|
||||||
|
{ title: "신가전 군", items: ["로봇 청소기"] },
|
||||||
|
] as const;
|
||||||
|
|
||||||
|
const lifeStageRowsByGroup = useMemo(() => {
|
||||||
|
const pick = (label: string) => apiLifeStageByProduct.find((r) => norm(r.rowLabel) === norm(label));
|
||||||
|
|
||||||
|
return LIFE_STAGE_GROUPS.map((g) => {
|
||||||
|
const rows: LifeStageRow[] = g.items.map((label) => {
|
||||||
|
const r = pick(label);
|
||||||
|
|
||||||
|
return {
|
||||||
|
item: label,
|
||||||
|
total: asNum((r as any)?.total), // 서버에 all이 없으면 null로 남음
|
||||||
|
single: asNum((r as any)?.single),
|
||||||
|
noKids: asNum((r as any)?.noKids),
|
||||||
|
preschoolKids: asNum((r as any)?.preschoolKids),
|
||||||
|
schoolKids: asNum((r as any)?.schoolKids),
|
||||||
|
adultKids: asNum((r as any)?.adultKids),
|
||||||
|
independentSenior: asNum((r as any)?.independentSenior),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
return { title: g.title, rows };
|
||||||
|
});
|
||||||
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<TopChartTable
|
<TopChartTable
|
||||||
@@ -70,6 +120,35 @@ const LGPenetrationPage = () => {
|
|||||||
}
|
}
|
||||||
signStyle={signStyleGapRow}
|
signStyle={signStyleGapRow}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<div className="mt-6">
|
||||||
|
<div className="flex justify-end gap-6 text-xs text-muted-foreground mb-2">
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<span className="inline-block h-3 w-5 border bg-gray-200"/>
|
||||||
|
<span>제품 보유율</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<span
|
||||||
|
className="inline-block h-3 w-5 border"
|
||||||
|
style={{ backgroundColor: "hsl(var(--lg-pink-300) / 0.4)" }}
|
||||||
|
/>
|
||||||
|
<span>시장 기회공간</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="grid grid-cols-2 gap-4">
|
||||||
|
{lifeStageRowsByGroup.map((g) => (
|
||||||
|
<GaugeCardTable
|
||||||
|
key={g.title}
|
||||||
|
title={g.title}
|
||||||
|
columns={LIFE_STAGE_COLUMNS}
|
||||||
|
rows={g.rows}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,14 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import TopChartTable from "../../../../../components/lge-dashboard/combo/TopChartTable";
|
|
||||||
import {PRODUCT_KEYS, PRODUCTS, YEARS} from "@/const/lgConst";
|
import {PRODUCT_KEYS, PRODUCTS, YEARS} from "@/const/lgConst";
|
||||||
import {GroupedOverlayBar, GroupedOverlayBarData, signStyleGapRow, TopChartTableRow} from "@/components/lge-dashboard";
|
import {
|
||||||
|
GroupedOverlayBar,
|
||||||
|
GroupedOverlayBarData,
|
||||||
|
signStyleGapRow,
|
||||||
|
TopChartTable,
|
||||||
|
TopChartTableRow
|
||||||
|
} from "@/components/lge-dashboard";
|
||||||
import { apiOwnShareOfTotalPurchase, apiTrendBuy} from "@/config/sample.data";
|
import { apiOwnShareOfTotalPurchase, apiTrendBuy} from "@/config/sample.data";
|
||||||
|
|
||||||
const LGPurchasePage = () => {
|
const LGPurchasePage = () => {
|
||||||
|
|||||||
@@ -5,14 +5,12 @@ import TopChartTable from "@/components/lge-dashboard/combo/TopChartTable";
|
|||||||
|
|
||||||
import VerticalBar from "@/components/lge-dashboard/chart/VerticalBar";
|
import VerticalBar from "@/components/lge-dashboard/chart/VerticalBar";
|
||||||
import {
|
import {
|
||||||
AXIS_HIDE_STYLE, ChartData,
|
ChartData, GroupedStackBar, signStyleGapRow, TopChartTableRow, GroupedStackBarData
|
||||||
GRID_X_NOT_PADDING,
|
|
||||||
GroupedStackBar, signStyleGapRow, TopChartTableRow, GroupedStackBarData
|
|
||||||
} from "@/components/lge-dashboard";
|
} from "@/components/lge-dashboard";
|
||||||
import {useLayoutFilter} from "@/components/layout/LayoutFilterContext";
|
import {useLayoutFilter} from "@/components/layout/LayoutFilterContext";
|
||||||
import {apiBrandByYearCategories, apiTrendCategories} from "@/config/sample.data";
|
import {apiBrandByYearCategories, apiTrendCategories} from "@/config/sample.data";
|
||||||
import {Button} from "@/components/ui/button";
|
import {Button} from "@/components/ui/button";
|
||||||
import {BRAND_LIST, PRODUCT_KEYS, PRODUCTS, YEARS} from "@/const/lgConst";
|
import {BRAND_LIST, PRODUCT_KEYS, PRODUCTS, YEARS, AXIS_HIDE_STYLE, GRID_X_NOT_PADDING} from "@/const/lgConst";
|
||||||
|
|
||||||
|
|
||||||
const PenetrationPage = () => {
|
const PenetrationPage = () => {
|
||||||
|
|||||||
@@ -1,15 +1,11 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import {Button} from "@/components/ui/button";
|
import {PRODUCT_KEYS, PRODUCTS, AXIS_HIDE_STYLE, GRID_X_NOT_PADDING} from "@/const/lgConst";
|
||||||
import TopChartTable from "../../../../../components/lge-dashboard/combo/TopChartTable";
|
|
||||||
import {PRODUCT_KEYS, PRODUCTS} from "@/const/lgConst";
|
|
||||||
import {
|
import {
|
||||||
AXIS_HIDE_STYLE, ChartData,
|
ChartData,
|
||||||
GRID_X_NOT_PADDING,
|
signStyleGapRow, TopChartTable,
|
||||||
signStyleGapRow,
|
TopChartTableRow, VerticalBar
|
||||||
TopChartTableRow
|
|
||||||
} from "@/components/lge-dashboard";
|
} from "@/components/lge-dashboard";
|
||||||
import VerticalBar from "../../../../../components/lge-dashboard/chart/VerticalBar";
|
|
||||||
import {apiTrendBuy} from "@/config/sample.data";
|
import {apiTrendBuy} from "@/config/sample.data";
|
||||||
|
|
||||||
const PurchasePage = () => {
|
const PurchasePage = () => {
|
||||||
|
|||||||
@@ -11,8 +11,9 @@ import type {
|
|||||||
} from "echarts";
|
} from "echarts";
|
||||||
import BaseEChart from "../BaseEChart";
|
import BaseEChart from "../BaseEChart";
|
||||||
import { buildLgPalette } from "../color";
|
import { buildLgPalette } from "../color";
|
||||||
import {AXIS_HIDE_STYLE, GroupedOverlayBarData, ShowLabel} from "../types";
|
import { GroupedOverlayBarData, ShowLabel} from "../types";
|
||||||
import {getIsShowLabel, roundedRectIcon} from "@/components/lge-dashboard/chart/utill";
|
import {getIsShowLabel, roundedRectIcon} from "@/components/lge-dashboard/chart/utill";
|
||||||
|
import {AXIS_HIDE_STYLE} from "@/const/lgConst";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
data: GroupedOverlayBarData;
|
data: GroupedOverlayBarData;
|
||||||
|
|||||||
@@ -10,9 +10,10 @@ import type {
|
|||||||
SeriesOption, EChartsOption,
|
SeriesOption, EChartsOption,
|
||||||
} from "echarts";
|
} from "echarts";
|
||||||
import BaseEChart from "../BaseEChart";
|
import BaseEChart from "../BaseEChart";
|
||||||
import {AXIS_HIDE_STYLE, GroupedStackBarData, ShowLabel} from "../types";
|
import { GroupedStackBarData, ShowLabel} from "../types";
|
||||||
import { buildLgPalette } from "@/components/lge-dashboard/color";
|
import { buildLgPalette } from "@/components/lge-dashboard/color";
|
||||||
import {getIsShowLabel, roundedRectIcon} from "@/components/lge-dashboard/chart/utill";
|
import {getIsShowLabel, roundedRectIcon} from "@/components/lge-dashboard/chart/utill";
|
||||||
|
import {AXIS_HIDE_STYLE} from "@/const/lgConst";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
data: GroupedStackBarData;
|
data: GroupedStackBarData;
|
||||||
|
|||||||
58
src/components/lge-dashboard/combo/GaugeCardTable.tsx
Normal file
58
src/components/lge-dashboard/combo/GaugeCardTable.tsx
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import React from "react";
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
import {GaugeColumn, GaugeTable} from "@/components/lge-dashboard";
|
||||||
|
import Card from "@/components/lge-dashboard/card/Card";
|
||||||
|
|
||||||
|
export type GaugeCardTableProps<T> = {
|
||||||
|
/** 카드 제목 */
|
||||||
|
title: string;
|
||||||
|
/** GaugeTable columns */
|
||||||
|
columns: GaugeColumn<T>[];
|
||||||
|
/** GaugeTable rows */
|
||||||
|
rows: T[];
|
||||||
|
|
||||||
|
/** GaugeTable 옵션들 (필요한 것만 노출) */
|
||||||
|
cellHeight?: number;
|
||||||
|
fillColor?: string;
|
||||||
|
trackColor?: string;
|
||||||
|
|
||||||
|
className?: string;
|
||||||
|
cardClassName?: string;
|
||||||
|
tableClassName?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
const GaugeCardTable = <T extends Record<string, unknown>>(
|
||||||
|
props: GaugeCardTableProps<T>
|
||||||
|
) => {
|
||||||
|
const {
|
||||||
|
title,
|
||||||
|
columns,
|
||||||
|
rows,
|
||||||
|
cellHeight = 26,
|
||||||
|
fillColor,
|
||||||
|
trackColor,
|
||||||
|
className,
|
||||||
|
cardClassName,
|
||||||
|
tableClassName,
|
||||||
|
} = props;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={cn("w-full", className)}>
|
||||||
|
<Card label={title} className={cardClassName}>
|
||||||
|
<div className={cn("w-full", tableClassName)}>
|
||||||
|
<GaugeTable
|
||||||
|
columns={columns}
|
||||||
|
rows={rows}
|
||||||
|
cellHeight={cellHeight}
|
||||||
|
fillColor={fillColor}
|
||||||
|
trackColor={trackColor}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</Card>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default GaugeCardTable;
|
||||||
@@ -13,5 +13,7 @@ export { default as GaugeTable } from "./table/GaugeTable";
|
|||||||
|
|
||||||
export { default as TopChartTable } from "./combo/TopChartTable";
|
export { default as TopChartTable } from "./combo/TopChartTable";
|
||||||
export { default as LeftChartTable } from "./combo/LeftChartTable";
|
export { default as LeftChartTable } from "./combo/LeftChartTable";
|
||||||
|
export { default as GaugeCardTable } from "./combo/GaugeCardTable";
|
||||||
|
export { default as CategoryByData } from "./combo/CategoryByData"
|
||||||
|
|
||||||
export { default as CardDefault } from "./card/Card";
|
export { default as CardDefault } from "./card/Card";
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ type Props<T extends Record<string, unknown>> = {
|
|||||||
cellHeight?: number; // 기본 26
|
cellHeight?: number; // 기본 26
|
||||||
|
|
||||||
/** 숫자 표시 여부/포맷 */
|
/** 숫자 표시 여부/포맷 */
|
||||||
showValue?: boolean; // 기본 true
|
|
||||||
valueFormatter?: (v: number) => string;
|
valueFormatter?: (v: number) => string;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -40,10 +39,9 @@ const GaugeTable = <T extends Record<string, unknown>>({
|
|||||||
className,
|
className,
|
||||||
wrapperClassName,
|
wrapperClassName,
|
||||||
scale = 1,
|
scale = 1,
|
||||||
fillColor = "hsl(var(--primary) / 0.85)",
|
fillColor = "hsl(var(--lg-gray-200) / 0.85)",
|
||||||
trackColor = "hsl(var(--lg-gray-200) / 0.85)",
|
trackColor = "hsl(var(--lg-pink-300) / 0.2)",
|
||||||
cellHeight = 26,
|
cellHeight = 26,
|
||||||
showValue = true,
|
|
||||||
valueFormatter,
|
valueFormatter,
|
||||||
}: Props<T>) => {
|
}: Props<T>) => {
|
||||||
const hasGroup = columns.some((c) => !!c.group);
|
const hasGroup = columns.some((c) => !!c.group);
|
||||||
@@ -68,9 +66,23 @@ const GaugeTable = <T extends Record<string, unknown>>({
|
|||||||
|
|
||||||
const fmt = valueFormatter ?? ((v: number) => String(Math.round(v)));
|
const fmt = valueFormatter ?? ((v: number) => String(Math.round(v)));
|
||||||
|
|
||||||
|
const clamp01 = (n: number) => Math.max(0, Math.min(1, n));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={cn("w-full overflow-x-auto", wrapperClassName)}>
|
<div className={cn("w-full overflow-x-auto", wrapperClassName)}>
|
||||||
<table className={cn("lg-table", className)}>
|
<table className={cn("lg-table", className)} style={{minWidth:"100%"}}>
|
||||||
|
<colgroup>
|
||||||
|
{columns.map((c, i) => (
|
||||||
|
<col
|
||||||
|
key={`${String(c.key)}-${i}`}
|
||||||
|
style={{
|
||||||
|
width:
|
||||||
|
c.width ??
|
||||||
|
(c.rowHead ? 50 : 40), // 기본 폭(필요시 숫자 조절)
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</colgroup>
|
||||||
<thead>
|
<thead>
|
||||||
{hasGroup && (
|
{hasGroup && (
|
||||||
<tr className="lg-table__group">
|
<tr className="lg-table__group">
|
||||||
@@ -83,7 +95,7 @@ const GaugeTable = <T extends Record<string, unknown>>({
|
|||||||
)}
|
)}
|
||||||
<tr className={hasGroup ? "lg-table__subhead" : undefined}>
|
<tr className={hasGroup ? "lg-table__subhead" : undefined}>
|
||||||
{columns.map((c) => (
|
{columns.map((c) => (
|
||||||
<th key={String(c.key)} style={{ width: c.width }}>
|
<th key={String(c.key)}>
|
||||||
{c.header}
|
{c.header}
|
||||||
</th>
|
</th>
|
||||||
))}
|
))}
|
||||||
@@ -95,6 +107,7 @@ const GaugeTable = <T extends Record<string, unknown>>({
|
|||||||
<tr key={rIdx}>
|
<tr key={rIdx}>
|
||||||
{columns.map((c) => {
|
{columns.map((c) => {
|
||||||
const align = c.align ?? (c.rowHead ? "left" : "center");
|
const align = c.align ?? (c.rowHead ? "left" : "center");
|
||||||
|
const cellType = c.cellType ?? "gauge";
|
||||||
|
|
||||||
if (c.rowHead) {
|
if (c.rowHead) {
|
||||||
const raw = row[c.key];
|
const raw = row[c.key];
|
||||||
@@ -119,35 +132,42 @@ const GaugeTable = <T extends Record<string, unknown>>({
|
|||||||
const raw = row[c.key];
|
const raw = row[c.key];
|
||||||
const v = num(raw);
|
const v = num(raw);
|
||||||
const max = c.max ?? 100;
|
const max = c.max ?? 100;
|
||||||
const ratio = v === null ? 0 : Math.max(0, Math.min(1, (v * scale) / max));
|
const ratio = v === null ? 0 : clamp01((v * scale) / max);
|
||||||
const pct = ratio * 100;
|
const pct = ratio * 100;
|
||||||
|
|
||||||
return (
|
const fill = fillColor;
|
||||||
<td key={String(c.key)} style={{ textAlign: align }}>
|
const track = trackColor;
|
||||||
<div
|
|
||||||
className="relative overflow-hidden rounded-md"
|
const cellBg =
|
||||||
style={{
|
v === null
|
||||||
height: cellHeight,
|
? undefined
|
||||||
background: trackColor,
|
: `linear-gradient(to right, ${fill} ${pct}%, ${track} 0%)`;
|
||||||
border: "1px solid hsl(var(--border))",
|
console.log(cellBg);
|
||||||
}}
|
if (cellType === "number") {
|
||||||
|
return (
|
||||||
|
<td
|
||||||
|
key={String(c.key)}
|
||||||
|
className="px-2 content-text-sm"
|
||||||
|
style={{ textAlign: align }}
|
||||||
>
|
>
|
||||||
<div
|
{v === null ? "-" : fmt(v)}
|
||||||
className="absolute inset-y-0 left-0"
|
</td>
|
||||||
style={{
|
);
|
||||||
width: `${pct}%`,
|
}
|
||||||
background: fillColor,
|
|
||||||
}}
|
return (
|
||||||
/>
|
<td
|
||||||
{showValue && (
|
key={String(c.key)}
|
||||||
<div
|
className="px-2 content-text-sm"
|
||||||
className="relative z-10 flex h-full items-center justify-center content-text-sm"
|
style={{
|
||||||
style={{ color: "hsl(var(--lg-gray-900))" }}
|
textAlign: "left",
|
||||||
>
|
height: cellHeight,
|
||||||
{v === null ? "-" : fmt(v)}
|
whiteSpace: "nowrap",
|
||||||
</div>
|
background: cellBg,
|
||||||
)}
|
backgroundClip: "padding-box",
|
||||||
</div>
|
}}
|
||||||
|
>
|
||||||
|
{v === null ? "-" : fmt(v)}
|
||||||
</td>
|
</td>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
|||||||
@@ -112,6 +112,17 @@ export type ServerBannerRow = ServerBaseRow &
|
|||||||
[k: string]: number | string;
|
[k: string]: number | string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type LifeStageRow = Record<string, unknown> & {
|
||||||
|
item: string;
|
||||||
|
total: number | null;
|
||||||
|
single: number | null;
|
||||||
|
noKids: number | null;
|
||||||
|
preschoolKids: number | null;
|
||||||
|
schoolKids: number | null;
|
||||||
|
adultKids: number | null;
|
||||||
|
independentSenior: number | null;
|
||||||
|
};
|
||||||
|
|
||||||
export type ChartSeries = {
|
export type ChartSeries = {
|
||||||
/** legend에 노출될 이름 */
|
/** legend에 노출될 이름 */
|
||||||
name: string;
|
name: string;
|
||||||
@@ -190,6 +201,7 @@ export type GaugeColumn<T> = {
|
|||||||
/** 게이지 최대값 기준(기본 100) */
|
/** 게이지 최대값 기준(기본 100) */
|
||||||
max?: number;
|
max?: number;
|
||||||
renderLabel?: (row: T) => React.ReactNode; // rowHead에 쓰기 좋음
|
renderLabel?: (row: T) => React.ReactNode; // rowHead에 쓰기 좋음
|
||||||
|
cellType?: "gauge" | "number"; // default: "gauge"
|
||||||
};
|
};
|
||||||
|
|
||||||
export type SignDisplayMode = "number" | "arrow";
|
export type SignDisplayMode = "number" | "arrow";
|
||||||
@@ -233,13 +245,6 @@ export const signStyleGapRow: SignStyle<TopChartTableRow> = {
|
|||||||
arrowWithNumber: true,
|
arrowWithNumber: true,
|
||||||
paint: "text",
|
paint: "text",
|
||||||
};
|
};
|
||||||
|
|
||||||
/** X 축 패딩 없앤 GridOption*/
|
|
||||||
export const GRID_X_NOT_PADDING = { left: 0, right: 0, top: 50, bottom: 10, containLabel: false } as const;
|
|
||||||
/** T 축 패딩 없앤 GridOption*/
|
|
||||||
export const GRID_Y_NOT_PADDING = { left: 10, right: 10, top: 0, bottom: 0, containLabel: false } as const;
|
|
||||||
/** 축 스타일 감춤 */
|
|
||||||
export const AXIS_HIDE_STYLE = { axisLabel: { show: false }, axisTick: { show: false }, axisLine: { show: false }} as const;
|
|
||||||
/** ChartLabel 보여지는 옵션 */
|
/** ChartLabel 보여지는 옵션 */
|
||||||
export type ShowLabel = "none" | "all" | "last" | "first";
|
export type ShowLabel = "none" | "all" | "last" | "first";
|
||||||
|
|
||||||
|
|||||||
@@ -9,17 +9,42 @@ import {PRODUCT_KEY_MAP} from "@/components/lge-dashboard";
|
|||||||
|
|
||||||
const PRODUCT_KEYS = Object.keys(PRODUCT_KEY_MAP) as ProductKey[];
|
const PRODUCT_KEYS = Object.keys(PRODUCT_KEY_MAP) as ProductKey[];
|
||||||
|
|
||||||
const randInt = (min: number, max: number) =>
|
const DUMMY_SEED = Number(process.env.NEXT_PUBLIC_DUMMY_SEED ?? 12345);
|
||||||
Math.floor(Math.random() * (max - min + 1)) + min;
|
|
||||||
|
// 문자열 → 32bit 해시
|
||||||
|
const hash32 = (s: string) => {
|
||||||
|
let h = 2166136261;
|
||||||
|
for (let i = 0; i < s.length; i++) {
|
||||||
|
h ^= s.charCodeAt(i);
|
||||||
|
h = Math.imul(h, 16777619);
|
||||||
|
}
|
||||||
|
return h >>> 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
// 결정적 PRNG
|
||||||
|
const mulberry32 = (a: number) => {
|
||||||
|
return () => {
|
||||||
|
let t = (a += 0x6d2b79f5);
|
||||||
|
t = Math.imul(t ^ (t >>> 15), t | 1);
|
||||||
|
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
|
||||||
|
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const randInt = (r: () => number, min: number, max: number) =>
|
||||||
|
Math.floor(r() * (max - min + 1)) + min;
|
||||||
|
|
||||||
type RandRange = { min: number | null; max: number | null };
|
type RandRange = { min: number | null; max: number | null };
|
||||||
|
|
||||||
const makeProductDist = (range?: RandRange): Record<ProductKey, number> => {
|
const makeProductDist = (seedKey: string, range?: RandRange): Record<ProductKey, number> => {
|
||||||
const min = range?.min ?? 1;
|
const min = range?.min ?? 1;
|
||||||
const max = range?.max ?? 60;
|
const max = range?.max ?? 60;
|
||||||
|
|
||||||
|
const seed = (hash32(seedKey) ^ DUMMY_SEED) >>> 0;
|
||||||
|
const r = mulberry32(seed);
|
||||||
|
|
||||||
const out = {} as Record<ProductKey, number>;
|
const out = {} as Record<ProductKey, number>;
|
||||||
for (const k of PRODUCT_KEYS) out[k] = randInt(min, max);
|
for (const k of PRODUCT_KEYS) out[k] = randInt(r, min, max);
|
||||||
return out;
|
return out;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -33,7 +58,7 @@ const productRow = (
|
|||||||
year,
|
year,
|
||||||
rowLabel,
|
rowLabel,
|
||||||
total,
|
total,
|
||||||
...makeProductDist(range),
|
...makeProductDist(`${year}|${rowLabel}|${range.min ?? ""}|${range.max ?? ""}`, range),
|
||||||
...(extra ?? {}),
|
...(extra ?? {}),
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -69,71 +94,119 @@ const calcCagrRow = (row24: ServerProductRow, row26: ServerProductRow): ServerPr
|
|||||||
return out;
|
return out;
|
||||||
};
|
};
|
||||||
|
|
||||||
// 배너(41키) 그룹별 합이 100 되도록 고정 분포
|
const splitTo100 = (r: () => number, n: number, minEach: number, maxEach: number): number[] => {
|
||||||
const BANNER_DIST_DEFAULT: Record<BannerKey, number> = {
|
// 불가능한 범위 방어
|
||||||
// 라이프스테이지(6)
|
const minSum = n * minEach;
|
||||||
single: 20,
|
const maxSum = n * maxEach;
|
||||||
noKids: 20,
|
if (minSum > 100) throw new Error(`splitTo100 invalid: minEach too large (n=${n}, minEach=${minEach})`);
|
||||||
preschoolKids: 20,
|
if (maxSum < 100) throw new Error(`splitTo100 invalid: maxEach too small (n=${n}, maxEach=${maxEach})`);
|
||||||
schoolKids: 20,
|
|
||||||
adultKids: 10,
|
|
||||||
independentSenior: 10,
|
|
||||||
|
|
||||||
// 가구원수(4)
|
// 1) 최소값으로 깔기
|
||||||
hh1: 25,
|
const out = Array(n).fill(minEach);
|
||||||
hh2: 35,
|
const remain = 100 - minSum;
|
||||||
hh3: 20,
|
|
||||||
hh4Plus: 20,
|
|
||||||
|
|
||||||
// 연령(5)
|
// 2) 각 슬롯이 추가로 받을 수 있는 상한
|
||||||
age20s: 15,
|
const caps = Array(n).fill(maxEach - minEach);
|
||||||
age30s: 25,
|
|
||||||
age40s: 30,
|
|
||||||
age50s: 20,
|
|
||||||
age60s: 10,
|
|
||||||
|
|
||||||
// 점유형태(5)
|
// 3) remain을 cap 내에서 랜덤 분배
|
||||||
ownerOccupied: 50,
|
// (가중치 기반으로 일단 분배 → cap 초과를 다시 재분배)
|
||||||
jeonse: 25,
|
const w = Array.from({ length: n }, () => randInt(r, 1, 100));
|
||||||
depositAndMonthly: 10,
|
const wSum = w.reduce((a, b) => a + b, 0);
|
||||||
monthlyNoDeposit: 10,
|
|
||||||
otherTenure: 5,
|
|
||||||
|
|
||||||
// 주거형태(6)
|
const add = w.map((wi) => Math.floor((wi / wSum) * remain));
|
||||||
apartment: 60,
|
const used = add.reduce((a, b) => a + b, 0);
|
||||||
house: 15,
|
const left = remain - used;
|
||||||
officetel: 10,
|
|
||||||
villa: 10,
|
|
||||||
studio: 3,
|
|
||||||
otherHousingType: 2,
|
|
||||||
|
|
||||||
// 평형(5)
|
// 남은 left를 가중치 큰 순으로 1씩
|
||||||
under19Pyeong: 10,
|
const order = w
|
||||||
pyeong20s: 20,
|
.map((wi, i) => ({ wi, i }))
|
||||||
pyeong30s: 35,
|
.sort((a, b) => b.wi - a.wi)
|
||||||
pyeong40s: 20,
|
.map((x) => x.i);
|
||||||
pyeong50Plus: 15,
|
|
||||||
|
|
||||||
// 권역(6)
|
for (let k = 0; k < left; k++) add[order[k % n]] += 1;
|
||||||
regionCapital: 45,
|
|
||||||
regionGyeongnamBusanUlsan: 15,
|
|
||||||
regionGyeongbukDaegu: 10,
|
|
||||||
regionJeollaGwangju: 10,
|
|
||||||
regionChungcheongDaejeonSejong: 10,
|
|
||||||
regionGangwonJeju: 10,
|
|
||||||
|
|
||||||
// 소득(4)
|
// cap 적용(초과분 회수)
|
||||||
incomeUnder299: 20,
|
let overflow = 0;
|
||||||
income300to599: 40,
|
for (let i = 0; i < n; i++) {
|
||||||
income600to899: 25,
|
if (add[i] > caps[i]) {
|
||||||
income900Plus: 15,
|
overflow += add[i] - caps[i];
|
||||||
|
add[i] = caps[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 회수한 overflow를 cap 남은 곳에 다시 채우기(랜덤)
|
||||||
|
while (overflow > 0) {
|
||||||
|
const candidates = [];
|
||||||
|
for (let i = 0; i < n; i++) {
|
||||||
|
const room = caps[i] - add[i];
|
||||||
|
if (room > 0) candidates.push({ i, room });
|
||||||
|
}
|
||||||
|
if (candidates.length === 0) break;
|
||||||
|
|
||||||
|
const pick = candidates[randInt(r, 0, candidates.length - 1)];
|
||||||
|
add[pick.i] += 1;
|
||||||
|
overflow -= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 최종 합 100 보장
|
||||||
|
for (let i = 0; i < n; i++) out[i] += add[i];
|
||||||
|
const sum = out.reduce((a, b) => a + b, 0);
|
||||||
|
if (sum !== 100) {
|
||||||
|
// 마지막 보정(이론상 거의 안 탐)
|
||||||
|
out[n - 1] += 100 - sum;
|
||||||
|
}
|
||||||
|
return out;
|
||||||
};
|
};
|
||||||
|
|
||||||
const bannerRow = (year: number, rowLabel: string, total: number, extra?: Record<string, number>): ServerBannerRow => ({
|
/** ✅ 그룹 키 정의(각 그룹 합 100) */
|
||||||
|
const BANNER_GROUPS: Record<string, BannerKey[]> = {
|
||||||
|
lifeStage: ["single", "noKids", "preschoolKids", "schoolKids", "adultKids", "independentSenior"],
|
||||||
|
household: ["hh1", "hh2", "hh3", "hh4Plus"],
|
||||||
|
age: ["age20s", "age30s", "age40s", "age50s", "age60s"],
|
||||||
|
tenure: ["ownerOccupied", "jeonse", "depositAndMonthly", "monthlyNoDeposit", "otherTenure"],
|
||||||
|
housing: ["apartment", "house", "officetel", "villa", "studio", "otherHousingType"],
|
||||||
|
pyeong: ["under19Pyeong", "pyeong20s", "pyeong30s", "pyeong40s", "pyeong50Plus"],
|
||||||
|
region: [
|
||||||
|
"regionCapital",
|
||||||
|
"regionGyeongnamBusanUlsan",
|
||||||
|
"regionGyeongbukDaegu",
|
||||||
|
"regionJeollaGwangju",
|
||||||
|
"regionChungcheongDaejeonSejong",
|
||||||
|
"regionGangwonJeju",
|
||||||
|
],
|
||||||
|
income: ["incomeUnder299", "income300to599", "income600to899", "income900Plus"],
|
||||||
|
};
|
||||||
|
|
||||||
|
/** ✅ 기존 상수 대신: 호출할 때마다 “결정적 랜덤” 분포 생성 */
|
||||||
|
export const makeBannerDistDefault = (seedKey: string, range?: RandRange): Record<BannerKey, number> => {
|
||||||
|
const seed = (hash32(seedKey) ^ DUMMY_SEED) >>> 0;
|
||||||
|
const r = mulberry32(seed);
|
||||||
|
|
||||||
|
const minEach = range?.min ?? 1;
|
||||||
|
const maxEach = range?.max ?? 60;
|
||||||
|
|
||||||
|
const out = {} as Record<BannerKey, number>;
|
||||||
|
|
||||||
|
(Object.keys(BANNER_GROUPS) as Array<keyof typeof BANNER_GROUPS>).forEach((groupName) => {
|
||||||
|
const keys = BANNER_GROUPS[groupName];
|
||||||
|
const parts = splitTo100(r, keys.length, minEach, maxEach); // ✅ min/max 적용
|
||||||
|
for (let i = 0; i < keys.length; i++) out[keys[i]] = parts[i];
|
||||||
|
});
|
||||||
|
|
||||||
|
return out;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const bannerRow = (
|
||||||
|
year: number,
|
||||||
|
rowLabel: string,
|
||||||
|
total: number,
|
||||||
|
range: RandRange = { min: null, max: null },
|
||||||
|
extra?: Partial<Record<BannerKey, number>>,
|
||||||
|
): ServerBannerRow => ({
|
||||||
year,
|
year,
|
||||||
rowLabel,
|
rowLabel,
|
||||||
total,
|
total,
|
||||||
...BANNER_DIST_DEFAULT,
|
...makeBannerDistDefault(`${year}|${rowLabel}`, range), // ✅ min/max 적용
|
||||||
...(extra ?? {}),
|
...(extra ?? {}),
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -197,21 +270,36 @@ export const apiOwnShareOfTotalPurchase: ServerProductRow[] = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
export const apiLifeStageByProduct: ServerBannerRow[] = [
|
export const apiLifeStageByProduct: ServerBannerRow[] = [
|
||||||
bannerRow(26, "냉장고", 1200, { single: 18, noKids: 22, preschoolKids: 20, schoolKids: 20, adultKids: 10, independentSenior: 10 }),
|
bannerRow(26, "냉장고", 1200),
|
||||||
bannerRow(26, "세탁기", 1100, { single: 18, noKids: 22, preschoolKids: 20, schoolKids: 20, adultKids: 10, independentSenior: 10 }),
|
bannerRow(26, "세탁기", 1100),
|
||||||
bannerRow(26, "에어컨", 900, { single: 22, noKids: 18, preschoolKids: 20, schoolKids: 20, adultKids: 10, independentSenior: 10 }),
|
bannerRow(26, "에어컨", 900),
|
||||||
bannerRow(26, "TV", 950, { single: 18, noKids: 22, preschoolKids: 20, schoolKids: 20, adultKids: 10, independentSenior: 10 }),
|
bannerRow(26, "TV", 950),
|
||||||
bannerRow(26, "청소기", 1000, { single: 22, noKids: 18, preschoolKids: 20, schoolKids: 20, adultKids: 10, independentSenior: 10 }),
|
bannerRow(26, "청소기", 1000),
|
||||||
bannerRow(26, "김치 냉장고", 700, { single: 22, noKids: 18, preschoolKids: 20, schoolKids: 20, adultKids: 10, independentSenior: 10 }),
|
bannerRow(26, "김치 냉장고", 700),
|
||||||
bannerRow(26, "공기 청정기", 800, { single: 22, noKids: 18, preschoolKids: 20, schoolKids: 20, adultKids: 10, independentSenior: 10 }),
|
bannerRow(26, "공기 청정기", 800),
|
||||||
bannerRow(26, "가습기", 650, { single: 22, noKids: 18, preschoolKids: 20, schoolKids: 20, adultKids: 10, independentSenior: 10 }),
|
bannerRow(26, "가습기", 650),
|
||||||
bannerRow(26, "제습기", 600, { single: 18, noKids: 22, preschoolKids: 20, schoolKids: 20, adultKids: 10, independentSenior: 10 }),
|
bannerRow(26, "제습기", 600),
|
||||||
bannerRow(26, "건조기", 500, { single: 18, noKids: 22, preschoolKids: 20, schoolKids: 20, adultKids: 10, independentSenior: 10 }),
|
bannerRow(26, "건조기", 500),
|
||||||
bannerRow(26, "식기세척기", 450, { single: 22, noKids: 18, preschoolKids: 20, schoolKids: 20, adultKids: 10, independentSenior: 10 }),
|
bannerRow(26, "식기세척기", 450),
|
||||||
bannerRow(26, "의류 관리기", 320, { single: 18, noKids: 22, preschoolKids: 20, schoolKids: 20, adultKids: 10, independentSenior: 10 }),
|
bannerRow(26, "의류 관리기", 320),
|
||||||
bannerRow(26, "로봇 청소기", 420, { single: 22, noKids: 18, preschoolKids: 20, schoolKids: 20, adultKids: 10, independentSenior: 10 }),
|
bannerRow(26, "로봇 청소기", 420),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
export const apiLifeStageByProductForGauge: ServerBannerRow[] = [
|
||||||
|
bannerRow(26, "냉장고", 1200, {min:10, max:99}),
|
||||||
|
bannerRow(26, "세탁기", 1100, {min:10, max:99}),
|
||||||
|
bannerRow(26, "에어컨", 900, {min:10, max:99}),
|
||||||
|
bannerRow(26, "TV", 950, {min:10, max:99}),
|
||||||
|
bannerRow(26, "청소기", 1000, {min:10, max:99}),
|
||||||
|
bannerRow(26, "김치 냉장고", 700, {min:10, max:99}),
|
||||||
|
bannerRow(26, "공기 청정기", 800, {min:10, max:99}),
|
||||||
|
bannerRow(26, "가습기", 650, {min:10, max:99}),
|
||||||
|
bannerRow(26, "제습기", 600, {min:10, max:99}),
|
||||||
|
bannerRow(26, "건조기", 500, {min:10, max:99}),
|
||||||
|
bannerRow(26, "식기세척기", 450, {min:10, max:99}),
|
||||||
|
bannerRow(26, "의류 관리기", 320, {min:10, max:99}),
|
||||||
|
bannerRow(26, "로봇 청소기", 420, {min:10, max:99}),
|
||||||
|
];
|
||||||
/** ---------------------------
|
/** ---------------------------
|
||||||
* API #6
|
* API #6
|
||||||
* year rowLabel total banner
|
* year rowLabel total banner
|
||||||
|
|||||||
@@ -4,3 +4,10 @@ export const PRODUCT_KEYS = Object.keys(PRODUCT_KEY_MAP) as Array<keyof typeof P
|
|||||||
export const PRODUCTS = Object.values(PRODUCT_KEY_MAP) as Array<string>;
|
export const PRODUCTS = Object.values(PRODUCT_KEY_MAP) as Array<string>;
|
||||||
export const YEARS = [24, 25, 26];
|
export const YEARS = [24, 25, 26];
|
||||||
export const BRAND_LIST = ['Cbrand', 'Samsung', 'LG'];
|
export const BRAND_LIST = ['Cbrand', 'Samsung', 'LG'];
|
||||||
|
|
||||||
|
/** X 축 패딩 없앤 GridOption*/
|
||||||
|
export const GRID_X_NOT_PADDING = { left: 0, right: 0, top: 50, bottom: 10, containLabel: false } as const;
|
||||||
|
/** T 축 패딩 없앤 GridOption*/
|
||||||
|
export const GRID_Y_NOT_PADDING = { left: 10, right: 10, top: 0, bottom: 0, containLabel: false } as const;
|
||||||
|
/** 축 스타일 감춤 */
|
||||||
|
export const AXIS_HIDE_STYLE = { axisLabel: { show: false }, axisTick: { show: false }, axisLine: { show: false }} as const;
|
||||||
Reference in New Issue
Block a user