diff --git a/src/app/(pages)/(main)/total/lg-penetration/page.tsx b/src/app/(pages)/(main)/total/lg-penetration/page.tsx index 8bd8db7..b7520e7 100644 --- a/src/app/(pages)/(main)/total/lg-penetration/page.tsx +++ b/src/app/(pages)/(main)/total/lg-penetration/page.tsx @@ -1,60 +1,66 @@ -'use client' +"use client"; import { - GroupedOverlayBar, GroupedOverlayBarData, - signStyleGapRow, TopChartTable, TopChartTableRow + GroupedOverlayBar, + type GroupedOverlayBarData, + signStyleGapRow, + TopChartTable, + type TopChartTableRow, } from "@/components/lge-dashboard"; -import {PRODUCT_KEYS, PRODUCTS, YEARS} from "@/const/lgConst"; -import {useMemo} from "react"; -import { - apiOwnShareOfTotalPenetration, - apiTrendCategories -} from "@/config/sample.data"; +import { PRODUCT_KEYS, PRODUCTS, YEARS } from "@/const/lgConst"; +import { useMemo } from "react"; +import { apiOwnShareOfTotalPenetration, apiTrendCategories } from "@/config/sample.data"; import LifeStageDiv from "@/components/lge-dashboard/combo/LifeStageDiv"; -import {useLayoutFilter} from "@/components/layout/LayoutFilterContext"; -import {formatRowLabel} from "@/lib/lg-dashboard"; +import { useLayoutFilter } from "@/components/layout/LayoutFilterContext"; +import { formatRowLabel } from "@/lib/lg-dashboard"; const LGPenetrationPage = () => { const { isTotal, filterValue } = useLayoutFilter(); console.log(filterValue); - const productTableRows: TopChartTableRow[] = apiOwnShareOfTotalPenetration.map((row, i) => ({ - label: formatRowLabel(row.rowLabel), - values: PRODUCT_KEYS.map((k) => (row as any)[k] ?? null), - })); + const productTableRows = useMemo(() => { + return apiOwnShareOfTotalPenetration.map((row) => ({ + label: formatRowLabel(row.rowLabel), + values: PRODUCT_KEYS.map((k) => (row as any)[k] ?? null), + })); + }, []); - const total: Array> = YEARS.map(() => Array(PRODUCT_KEYS.length).fill(0)); - const focus: Array> = YEARS.map(() => Array(PRODUCT_KEYS.length).fill(0)); + const productChartData = useMemo(() => { + const total: Array> = YEARS.map(() => Array(PRODUCT_KEYS.length).fill(0)); + const focus: Array> = YEARS.map(() => Array(PRODUCT_KEYS.length).fill(0)); - const yearIndexMap = new Map(YEARS.map((y, i) => [y, i])); + const yearIndexMap = new Map(YEARS.map((y, i) => [y, i])); - const totalRows = apiTrendCategories.filter((r) => YEARS.includes(r.year as any) && r.rowLabel.endsWith("년")); - const lgRows = apiOwnShareOfTotalPenetration.filter((r) => YEARS.includes(r.year as any) && r.rowLabel.endsWith("년")); + const totalRows = apiTrendCategories.filter( + (r) => YEARS.includes(r.year as any) && r.rowLabel.endsWith("년") + ); + const lgRows = apiOwnShareOfTotalPenetration.filter( + (r) => YEARS.includes(r.year as any) && r.rowLabel.endsWith("년") + ); - lgRows.forEach((r, ri) => { - const yi = yearIndexMap.get(r.year); - if (yi == null) return; + lgRows.forEach((r, ri) => { + const yi = yearIndexMap.get(r.year); + if (yi == null) return; - for (let ci = 0; ci < PRODUCT_KEYS.length; ci++) { - const k = PRODUCT_KEYS[ci]; - const t = (totalRows[ri] as any)[k]; - const v = (r as any)[k]; - // total/focus 모두 같은 값(“전체 보급률 중 자사제품 비율”이므로) - total[yi][ci] = typeof v === "number" ? t : 0; - focus[yi][ci] = typeof v === "number" ? v : 0; - } - }) - - const productChartData: GroupedOverlayBarData = { - categories: PRODUCTS, - years: YEARS, - totalName: "전체", - focusName: "LG", - total: total, - focus: focus, - } + for (let ci = 0; ci < PRODUCT_KEYS.length; ci++) { + const k = PRODUCT_KEYS[ci]; + const t = (totalRows[ri] as any)[k]; + const v = (r as any)[k]; + total[yi][ci] = typeof t === "number" ? t : 0; + focus[yi][ci] = typeof v === "number" ? v : 0; + } + }); + return { + categories: PRODUCTS, + years: YEARS, + totalName: "전체", + focusName: "LG", + total, + focus, + }; + }, []); return (
@@ -73,10 +79,9 @@ const LGPenetrationPage = () => { signStyle={signStyleGapRow} /> - - +
); -} +}; export default LGPenetrationPage; \ No newline at end of file diff --git a/src/app/(pages)/(main)/total/lg-purchase/page.tsx b/src/app/(pages)/(main)/total/lg-purchase/page.tsx index 0196d53..2b82cea 100644 --- a/src/app/(pages)/(main)/total/lg-purchase/page.tsx +++ b/src/app/(pages)/(main)/total/lg-purchase/page.tsx @@ -1,57 +1,66 @@ -'use client' +"use client"; - -import {PRODUCT_KEYS, PRODUCTS, YEARS} from "@/const/lgConst"; +import { useMemo } from "react"; +import { PRODUCT_KEYS, PRODUCTS, YEARS } from "@/const/lgConst"; import { GroupedOverlayBar, - GroupedOverlayBarData, + type GroupedOverlayBarData, signStyleGapRow, TopChartTable, - TopChartTableRow + type TopChartTableRow, } from "@/components/lge-dashboard"; -import { apiOwnShareOfTotalPurchase, apiTrendBuy} from "@/config/sample.data"; -import {useLayoutFilter} from "@/components/layout/LayoutFilterContext"; -import {formatRowLabel} from "@/lib/lg-dashboard"; +import { apiOwnShareOfTotalPurchase, apiTrendBuy } from "@/config/sample.data"; +import { useLayoutFilter } from "@/components/layout/LayoutFilterContext"; +import { formatRowLabel } from "@/lib/lg-dashboard"; const LGPurchasePage = () => { const { isTotal, filterValue } = useLayoutFilter(); console.log(filterValue); - const purchaseTableRows: TopChartTableRow[] = apiOwnShareOfTotalPurchase.map((row, i) => ({ - label: formatRowLabel(row.rowLabel), - values: PRODUCT_KEYS.map((k) => (row as any)[k] ?? null), - })); + const purchaseTableRows = useMemo(() => { + return apiOwnShareOfTotalPurchase.map((row) => ({ + label: formatRowLabel(row.rowLabel), + values: PRODUCT_KEYS.map((k) => (row as any)[k] ?? null), + })); + }, []); - const total: Array> = YEARS.map(() => Array(PRODUCT_KEYS.length).fill(0)); - const focus: Array> = YEARS.map(() => Array(PRODUCT_KEYS.length).fill(0)); + const purchaseChartData = useMemo(() => { + const total: Array> = YEARS.map(() => Array(PRODUCT_KEYS.length).fill(0)); + const focus: Array> = YEARS.map(() => Array(PRODUCT_KEYS.length).fill(0)); - const yearIndexMap = new Map(YEARS.map((y, i) => [y, i])); + const yearIndexMap = new Map(YEARS.map((y, i) => [y, i])); - const totalRows = apiTrendBuy.filter((r) => YEARS.includes(r.year as any) && r.rowLabel.endsWith("년")); - const lgRows = apiOwnShareOfTotalPurchase.filter((r) => YEARS.includes(r.year as any) && r.rowLabel.endsWith("년")); + const totalRows = apiTrendBuy.filter( + (r) => YEARS.includes(r.year as any) && r.rowLabel.endsWith("년") + ); + const lgRows = apiOwnShareOfTotalPurchase.filter( + (r) => YEARS.includes(r.year as any) && r.rowLabel.endsWith("년") + ); - lgRows.forEach((r, ri) => { - const yi = yearIndexMap.get(r.year); - if (yi == null) return; + lgRows.forEach((r, ri) => { + const yi = yearIndexMap.get(r.year); + if (yi == null) return; - for (let ci = 0; ci < PRODUCT_KEYS.length; ci++) { - const k = PRODUCT_KEYS[ci]; - const t = (totalRows[ri] as any)[k]; - const v = (r as any)[k]; - // total/focus 모두 같은 값(“전체 보급률 중 자사제품 비율”이므로) - total[yi][ci] = typeof v === "number" ? t : 0; - focus[yi][ci] = typeof v === "number" ? v : 0; - } - }) + for (let ci = 0; ci < PRODUCT_KEYS.length; ci++) { + const k = PRODUCT_KEYS[ci]; + const t = (totalRows[ri] as any)[k]; + const v = (r as any)[k]; - const purchaseChartData: GroupedOverlayBarData = { - categories: PRODUCTS, - years: YEARS, - totalName: "전체", - focusName: "LG", - total: total, - focus: focus, - } + // total은 t 기준으로 체크해야 안전 + total[yi][ci] = typeof t === "number" ? t : 0; + focus[yi][ci] = typeof v === "number" ? v : 0; + } + }); + + return { + categories: PRODUCTS, + years: YEARS, + totalName: "전체", + focusName: "LG", + total, + focus, + }; + }, []); return (
@@ -71,6 +80,6 @@ const LGPurchasePage = () => { />
); -} +}; export default LGPurchasePage; \ No newline at end of file diff --git a/src/app/(pages)/(main)/total/penetration/page.tsx b/src/app/(pages)/(main)/total/penetration/page.tsx index 2c8f37c..c019c5c 100644 --- a/src/app/(pages)/(main)/total/penetration/page.tsx +++ b/src/app/(pages)/(main)/total/penetration/page.tsx @@ -1,51 +1,64 @@ -'use client' +"use client"; -import {useEffect, useState} from "react"; +import { useEffect, useMemo, useState } from "react"; import TopChartTable from "@/components/lge-dashboard/combo/TopChartTable"; - import VerticalBar from "@/components/lge-dashboard/chart/VerticalBar"; import { - ChartData, GroupedStackBar, signStyleGapRow, TopChartTableRow, GroupedStackBarData + type ChartData, + GroupedStackBar, + signStyleGapRow, + type TopChartTableRow, + type GroupedStackBarData, } from "@/components/lge-dashboard"; -import {useLayoutFilter} from "@/components/layout/LayoutFilterContext"; -import {apiBrandByYearCategories, apiTrendCategories} from "@/config/sample.data"; -import {Button} from "@/components/ui/button"; -import {BRAND_LIST, PRODUCT_KEYS, PRODUCTS, YEARS, AXIS_HIDE_STYLE, GRID_X_NOT_PADDING} from "@/const/lgConst"; -import {formatRowLabel} from "@/lib/lg-dashboard"; - +import { useLayoutFilter } from "@/components/layout/LayoutFilterContext"; +import { apiBrandByYearCategories, apiTrendCategories } from "@/config/sample.data"; +import { Button } from "@/components/ui/button"; +import { + BRAND_LIST, + PRODUCT_KEYS, + PRODUCTS, + YEARS, + AXIS_HIDE_STYLE, + GRID_X_NOT_PADDING, +} from "@/const/lgConst"; +import { formatRowLabel } from "@/lib/lg-dashboard"; const PenetrationPage = () => { const { isTotal, filterValue, registerExcelExporter } = useLayoutFilter(); console.log(filterValue); - const [isBrandShare, setIsBrandShare] = useState(false); + const [isBrandShare, setIsBrandShare] = useState(false); - const productTableRows: TopChartTableRow[] = apiTrendCategories.map((row, i) => ({ - label: formatRowLabel(row.rowLabel), - values: PRODUCT_KEYS.map((k) => (row as any)[k] ?? null), - })); + const productTableRows = useMemo(() => { + return apiTrendCategories.map((row) => ({ + label: formatRowLabel(row.rowLabel), + values: PRODUCT_KEYS.map((k) => (row as any)[k] ?? null), + })); + }, []); - const productChartData: ChartData = { - categories: [...PRODUCTS], // 한글 라벨(세탁기/냉장고/...) - series: apiTrendCategories - .filter((r) => r.rowLabel.endsWith("년")) // 24년/25년/26년만 차트에 사용 - .map((r) => ({ - name: r.rowLabel, // legend: 24년/25년/26년 - data: PRODUCT_KEYS.map((k) => (r as any)[k] ?? null), - })), - } + const productChartData = useMemo(() => { + return { + categories: [...PRODUCTS], + series: apiTrendCategories + .filter((r) => r.rowLabel.endsWith("년")) + .map((r) => ({ + name: r.rowLabel, + data: PRODUCT_KEYS.map((k) => (r as any)[k] ?? null), + })), + }; + }, []); - const rowMap = new Map(); - for (const r of apiBrandByYearCategories) { - rowMap.set(`${r.year}__${r.rowLabel}`, r); - } + const brandShareChartData = useMemo(() => { + const rowMap = new Map(); + for (const r of apiBrandByYearCategories) { + rowMap.set(`${r.year}__${r.rowLabel}`, r); + } - const brandShareChartData: GroupedStackBarData = (() => { const values: number[][][] = YEARS.map(() => BRAND_LIST.map(() => new Array(PRODUCTS.length).fill(0)) ); - YEARS.forEach((year, yi) =>{ + YEARS.forEach((year, yi) => { BRAND_LIST.forEach((brand, bi) => { PRODUCT_KEYS.forEach((k, ci) => { const row = rowMap.get(`${year}__${brand}`); @@ -53,19 +66,15 @@ const PenetrationPage = () => { values[yi][bi][ci] = typeof v === "number" ? v : 0; }); }); - }) + }); return { categories: PRODUCTS, years: YEARS, brands: BRAND_LIST, values }; - })(); + }, []); useEffect(() => { registerExcelExporter(async (payload) => { - // payload.isTotal / payload.totalValue / payload.categoryValue 사용 가능 - // 여기서 데이터 수집 -> 엑셀 생성 -> 다운로드 수행 - // TODO: 실제 export 로직 - // await exportToExcel(payload); + // TODO: export }); - return () => registerExcelExporter(null); }, [registerExcelExporter]); @@ -74,46 +83,47 @@ const PenetrationPage = () => {
+ - : - + ) : ( + + ) } signStyle={signStyleGapRow} /> ); -} +}; export default PenetrationPage; \ No newline at end of file diff --git a/src/app/(pages)/(main)/total/purchase/page.tsx b/src/app/(pages)/(main)/total/purchase/page.tsx index 1993d1e..ba36504 100644 --- a/src/app/(pages)/(main)/total/purchase/page.tsx +++ b/src/app/(pages)/(main)/total/purchase/page.tsx @@ -1,33 +1,40 @@ -'use client' +"use client"; -import {PRODUCT_KEYS, PRODUCTS, AXIS_HIDE_STYLE, GRID_X_NOT_PADDING} from "@/const/lgConst"; +import { useMemo } from "react"; +import { PRODUCT_KEYS, PRODUCTS, AXIS_HIDE_STYLE, GRID_X_NOT_PADDING } from "@/const/lgConst"; import { - ChartData, - signStyleGapRow, TopChartTable, - TopChartTableRow, VerticalBar + type ChartData, + signStyleGapRow, + TopChartTable, + type TopChartTableRow, + VerticalBar, } from "@/components/lge-dashboard"; -import {apiTrendBuy} from "@/config/sample.data"; -import {useLayoutFilter} from "@/components/layout/LayoutFilterContext"; -import {formatRowLabel} from "@/lib/lg-dashboard"; +import { apiTrendBuy } from "@/config/sample.data"; +import { useLayoutFilter } from "@/components/layout/LayoutFilterContext"; +import { formatRowLabel } from "@/lib/lg-dashboard"; const PurchasePage = () => { const { isTotal, filterValue } = useLayoutFilter(); console.log(filterValue); - const purchaseTableRows: TopChartTableRow[] = apiTrendBuy.map((row, i) => ({ - label: formatRowLabel(row.rowLabel), - values: PRODUCT_KEYS.map((k) => (row as any)[k] ?? null), - })); + const purchaseTableRows = useMemo(() => { + return apiTrendBuy.map((row) => ({ + label: formatRowLabel(row.rowLabel), + values: PRODUCT_KEYS.map((k) => (row as any)[k] ?? null), + })); + }, []); - const purchaseChartData: ChartData = { - categories: [...PRODUCTS], // 한글 라벨(세탁기/냉장고/...) - series: apiTrendBuy - .filter((r) => r.rowLabel.endsWith("년")) // 24년/25년/26년만 차트에 사용 - .map((r) => ({ - name: r.rowLabel, // legend: 24년/25년/26년 - data: PRODUCT_KEYS.map((k) => (r as any)[k] ?? null), - })), - } + const purchaseChartData = useMemo(() => { + return { + categories: [...PRODUCTS], + series: apiTrendBuy + .filter((r) => r.rowLabel.endsWith("년")) + .map((r) => ({ + name: r.rowLabel, + data: PRODUCT_KEYS.map((k) => (r as any)[k] ?? null), + })), + }; + }, []); return (
@@ -50,6 +57,6 @@ const PurchasePage = () => { />
); -} +}; export default PurchasePage; \ No newline at end of file diff --git a/src/components/lge-dashboard/sub-page/category-page/PenetrationChange.tsx b/src/components/lge-dashboard/sub-page/category-page/PenetrationChange.tsx index 3373a3c..80f17fd 100644 --- a/src/components/lge-dashboard/sub-page/category-page/PenetrationChange.tsx +++ b/src/components/lge-dashboard/sub-page/category-page/PenetrationChange.tsx @@ -2,9 +2,9 @@ import {useLayoutFilter} from "@/components/layout/LayoutFilterContext"; import BannerSummary from "@/components/lge-dashboard/combo/BannerSummary"; -import {useEffect, useMemo, useState} from "react"; +import {useMemo} from "react"; import {ServerBannerRow} from "@/types/lg"; -import {apiOwnershipSummary, apiPurchaseRateKpis, apiYearIndex} from "@/config/sample.data"; +import {apiYearIndex} from "@/config/sample.data"; const PenetrationChange = () => { const { filterValue } = useLayoutFilter(); diff --git a/src/config/sample.data.ts b/src/config/sample.data.ts index e76b624..cf19e1a 100644 --- a/src/config/sample.data.ts +++ b/src/config/sample.data.ts @@ -265,21 +265,21 @@ export const apiOwnShareOfTotalPurchase: ServerProductRow[] = [ ]; export const apiLifeStageByProduct: ServerBannerRow[] = [ - bannerRow(26, "냉장고", 1200, {min:10, max:99}), - bannerRow(26, "세탁기", 1100, {min:10, max:99}), - bannerRow(26, "에어컨", 900, {min:10, max:99}), - bannerRow(26, "건조기", 500, {min:10, max:99}), - bannerRow(26, "TV", 950, {min:10, max:99}), - bannerRow(26, "김치 냉장고", 700, {min:10, max:99}), - bannerRow(26, "식기세척기", 450, {min:10, max:99}), - bannerRow(26, "의류 관리기", 320, {min:10, max:99}), + bannerRow(26, "냉장고", 97, {min:10, max:99}), + bannerRow(26, "세탁기", 94, {min:10, max:99}), + bannerRow(26, "에어컨", 90, {min:10, max:99}), + bannerRow(26, "건조기", 38, {min:10, max:99}), + bannerRow(26, "TV", 86, {min:10, max:99}), + bannerRow(26, "김치 냉장고", 56, {min:10, max:99}), + bannerRow(26, "식기세척기", 18, {min:10, max:99}), + bannerRow(26, "의류 관리기", 13, {min:10, max:99}), - bannerRow(26, "청소기", 1000, {min:10, max:99}), - bannerRow(26, "공기 청정기", 800, {min:10, max:99}), - bannerRow(26, "정수기", 800, {min:10, max:99}), + bannerRow(26, "청소기", 78, {min:10, max:99}), + bannerRow(26, "공기 청정기", 52, {min:10, max:99}), + bannerRow(26, "정수기", 42, {min:10, max:99}), - bannerRow(26, "로봇 청소기", 420, {min:10, max:99}), - bannerRow(26, "음식물처리기", 420, {min:10, max:99}), + bannerRow(26, "로봇 청소기", 22, {min:10, max:99}), + bannerRow(26, "음식물처리기", 26, {min:10, max:99}), ]; /** ---------------------------