260127_01_ENH: 커스텀 컴포넌트들 1차 완성 및 일부페이지에 SampleData 적용
This commit is contained in:
@@ -1,6 +1,76 @@
|
||||
'use client'
|
||||
|
||||
import {Button} from "@/components/ui/button";
|
||||
import TopChartTable from "../../../../../components/lge-dashboard/combo/TopChartTable";
|
||||
import {
|
||||
GroupedOverlayBar, GroupedOverlayBarData,
|
||||
signStyleGapRow, TopChartTableRow
|
||||
} from "@/components/lge-dashboard";
|
||||
import {PRODUCT_KEYS, PRODUCTS, YEARS} from "@/const/lgConst";
|
||||
import {useLayoutFilter} from "@/components/layout/LayoutFilterContext";
|
||||
import {useEffect} from "react";
|
||||
import {apiOwnShareOfTotalPenetration, apiTrendCategories} from "@/config/sample.data";
|
||||
|
||||
const LGPenetrationPage = () => {
|
||||
|
||||
const displayRowLabel = (i:number, rowLabel: string) => {
|
||||
if (rowLabel === "gap") return "전년 대비 GAP(%)";
|
||||
return rowLabel;
|
||||
};
|
||||
|
||||
const productTableRows: TopChartTableRow[] = apiOwnShareOfTotalPenetration.map((row, i) => ({
|
||||
label: displayRowLabel(i, row.rowLabel),
|
||||
values: PRODUCT_KEYS.map((k) => (row as any)[k] ?? null),
|
||||
}));
|
||||
|
||||
const total: Array<Array<number>> = YEARS.map(() => Array(PRODUCT_KEYS.length).fill(0));
|
||||
const focus: Array<Array<number>> = YEARS.map(() => Array(PRODUCT_KEYS.length).fill(0));
|
||||
|
||||
const yearIndexMap = new Map<number, number>(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("년"));
|
||||
|
||||
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,
|
||||
}
|
||||
|
||||
return (
|
||||
<div>LGPenetrationPage</div>
|
||||
<div>
|
||||
<TopChartTable
|
||||
title={"LG제품 보급률"}
|
||||
categories={[...PRODUCTS]}
|
||||
rows={productTableRows}
|
||||
chart={
|
||||
<GroupedOverlayBar
|
||||
data={productChartData}
|
||||
yearTotalColor={{ "24": "--chart-total-1", "25": "--chart-total-2", "26": "--chart-total-3" }}
|
||||
yearFocusColor={{ "24": "--chart-lg-1", "25": "--chart-lg-2", "26": "--chart-lg-3" }}
|
||||
showFocusLabel={"last"}
|
||||
/>
|
||||
}
|
||||
signStyle={signStyleGapRow}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user