develop #3
@@ -1,5 +1,5 @@
|
||||
NEXT_PUBLIC_ENV=prod
|
||||
NEXT_PUBLIC_API_BASE=https://test-lg-cxdash.kric.com/api
|
||||
NEXT_PUBLIC_API_BASE=https://lg-cxdash.kric.com/api
|
||||
|
||||
ENV=prod
|
||||
API_BACK_SERVER=http://127.0.0.1:6101/api/v1
|
||||
@@ -1,4 +1,4 @@
|
||||
import CategoryPage from "@/components/lge-dashboard/sub-page/CategoryPage";
|
||||
import CategoryPage from "../sub-page/CategoryPage";
|
||||
|
||||
const ESPage = () => {
|
||||
return <CategoryPage/>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import CategoryPage from "@/components/lge-dashboard/sub-page/CategoryPage";
|
||||
import CategoryPage from "../sub-page/CategoryPage";
|
||||
|
||||
const KitchenPage = () => {
|
||||
return <CategoryPage/>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import CategoryPage from "@/components/lge-dashboard/sub-page/CategoryPage";
|
||||
import CategoryPage from "../sub-page/CategoryPage";
|
||||
|
||||
const LivingPage = () => {
|
||||
return <CategoryPage/>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import CategoryPage from "@/components/lge-dashboard/sub-page/CategoryPage";
|
||||
import CategoryPage from "../sub-page/CategoryPage";
|
||||
|
||||
const MSPage = () => {
|
||||
return <CategoryPage/>
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
'use client'
|
||||
|
||||
import {useMemo} from "react";
|
||||
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 {BannerRow, CategoryResolvedField, StatisticsRequest} from "@/types/lg";
|
||||
import {CategoryTargetData} from "@/types/filter.types";
|
||||
import {BannerRow, CategoryResolvedField, StatisticsRequest} from "@/types/lg.types";
|
||||
import {useDebouncedValue} from "@/hooks/useDebouncedValue";
|
||||
import {CategoryFilterValue} from "@/components/layout/CategoryFilter";
|
||||
import {useMemo} from "react";
|
||||
import {buildCategoryFilter, buildPageModeConfig} from "@/lib/lg-dashboard";
|
||||
import {BANNER_GROUP_KEY} from "@/const/lgConst";
|
||||
import {useBannerStatisticsQuery} from "@/hooks/useLgStatisticsQuery";
|
||||
import CategoryDetail from "@/components/lge-dashboard/sub-page/category-page/CategoryDetail";
|
||||
import {BANNER_GROUP_KEY} from "@/const/lg-banner.const";
|
||||
import {API_DECIMAL_POINT, USE_CACHE} from "@/const/lg-common.const";
|
||||
import Profile from "./category-page/Profile";
|
||||
import PenetrationChange from "./category-page/PenetrationChange";
|
||||
import CategoryDetail from "./category-page/CategoryDetail";
|
||||
import {useBannerStatisticsQuery} from "@/query/statistics";
|
||||
|
||||
export type CategoryPageProps = {
|
||||
fields: CategoryResolvedField[];
|
||||
@@ -41,7 +43,7 @@ const CategoryPage = () => {
|
||||
variableIdMap,
|
||||
bannerIdList: BANNER_GROUP_KEY,
|
||||
filterCondition: buildCategoryFilter(debouncedFilterValue),
|
||||
option: { useCache: true, lastYear: false, decimalPoint: 0 },
|
||||
option: { useCache: USE_CACHE, lastYear: false, decimalPoint: API_DECIMAL_POINT },
|
||||
};
|
||||
}, [variableIdMap, debouncedFilterValue]);
|
||||
|
||||
@@ -54,4 +56,4 @@ const CategoryPage = () => {
|
||||
return Comp ? <Comp fields={fields} variableIdMap={variableIdMap} dataMap={dataMap} /> : null;
|
||||
}
|
||||
|
||||
export default CategoryPage;
|
||||
export default CategoryPage;
|
||||
@@ -1,11 +1,14 @@
|
||||
import {CategoryPageProps} from "@/components/lge-dashboard/sub-page/CategoryPage";
|
||||
import {CategoryPageProps} from "../../sub-page/CategoryPage";
|
||||
import {useLayoutFilter} from "@/components/layout/LayoutFilterContext";
|
||||
import {useDebouncedValue} from "@/hooks/useDebouncedValue";
|
||||
import {CategoryFilterValue} from "@/components/layout/CategoryFilter";
|
||||
import {useEffect, useMemo} from "react";
|
||||
import {BannerRow, PageData} from "@/types/lg";
|
||||
import {BannerRow, PageData} from "@/types/lg.types";
|
||||
import {buildHeader_Banner, exportDashboardExcel, Section} from "@/lib/lg-export-excel";
|
||||
import {BANNER_GROUP, BANNER_KEY_MAP, SITE_TITLE, YEARS} from "@/const/lgConst";
|
||||
import {BANNER_GROUP} from "@/const/lg-banner.const";
|
||||
import {BANNER_KEY_MAP} from "@/const/lg-schema.const";
|
||||
import {QID_SURVEY_TITLE} from "@/const/lg-survey.const";
|
||||
import {SITE_TITLE, YEARS} from "@/const/lg-common.const";
|
||||
import {CategoryByData} from "@/components/lge-dashboard";
|
||||
|
||||
const CategoryDetail = ({
|
||||
@@ -16,12 +19,20 @@ const CategoryDetail = ({
|
||||
const debouncedFilterValue = useDebouncedValue<CategoryFilterValue>(filterValue as CategoryFilterValue, 500);
|
||||
|
||||
const tableDataArray = useMemo<PageData<BannerRow>[]>(() => {
|
||||
const tempTableDataArray = fields.map((f) => {
|
||||
const tempTableDataArray = fields.map((f) :PageData<BannerRow> => {
|
||||
const dataLength = dataMap?.[f.requestKeyResolved].filter((row) => row.rowLabel !=`사례수`).length;
|
||||
const qid = f.qidByMode[debouncedFilterValue.type.value];
|
||||
|
||||
let surveyTitle = qid? QID_SURVEY_TITLE[qid] ?? "" : "";
|
||||
surveyTitle = surveyTitle.replaceAll("[#YEAR#]", debouncedFilterValue.year);
|
||||
surveyTitle = surveyTitle.replaceAll("[#NEXT_YEAR#]", String(Number(debouncedFilterValue.year) + 1));
|
||||
|
||||
return {
|
||||
title: typeof f.title === "string"? f.title : f.title[debouncedFilterValue.type.value],
|
||||
surveyTitle: surveyTitle,
|
||||
chartMode:f.chartMode,
|
||||
chartLegend:f.chartLegend,
|
||||
chartTopMargin:f.chartTopMargin,
|
||||
data: dataLength && dataLength > 0 ? dataMap[f.requestKeyResolved] : []
|
||||
};
|
||||
});
|
||||
@@ -68,7 +79,10 @@ const CategoryDetail = ({
|
||||
key={`cbd-${tableData.title.replaceAll(/\s+/g, "_")}`}
|
||||
selectedYear={filterValue.year}
|
||||
title={tableData.title}
|
||||
surveyTitle={tableData.surveyTitle}
|
||||
chartMode={tableData.chartMode}
|
||||
chartLegend={tableData.chartLegend}
|
||||
chartTopMargin={tableData.chartTopMargin}
|
||||
allTableData={tableData.data}
|
||||
chartHeight={tableData.chartHeight}
|
||||
chartWidth={tableData.chartWidth}
|
||||
@@ -78,4 +92,4 @@ const CategoryDetail = ({
|
||||
);
|
||||
}
|
||||
|
||||
export default CategoryDetail;
|
||||
export default CategoryDetail;
|
||||
@@ -0,0 +1,65 @@
|
||||
'use client'
|
||||
|
||||
import {DataColumn} from "@/components/lge-dashboard";
|
||||
import BannerSummary from "@/components/lge-dashboard/combo/BannerSummary";
|
||||
import {useMemo} from "react";
|
||||
import {parseNumber} from "@/lib/utils";
|
||||
import {BannerRow} from "@/types/lg.types";
|
||||
import {CategoryPageProps} from "../../sub-page/CategoryPage";
|
||||
import {LAST_YEAR} from "@/const/lg-common.const";
|
||||
|
||||
const PenetrationChange = ({
|
||||
dataMap
|
||||
}:CategoryPageProps) => {
|
||||
|
||||
const penetrationChangeData = useMemo<BannerRow[]>(() => {
|
||||
if (dataMap === undefined) return [];
|
||||
|
||||
const tempProfileData: BannerRow[] = [];
|
||||
Object.keys(dataMap).forEach(requestKey => {
|
||||
const data = dataMap[requestKey];
|
||||
tempProfileData.push(
|
||||
...data.filter((r) => r.rowLabel === `사례수` && r.year === LAST_YEAR),
|
||||
...data.filter((r) => r.rowLabel === `보유`)
|
||||
.map((row) => {
|
||||
return {
|
||||
...row,
|
||||
rowLabel: row.year,
|
||||
}
|
||||
}));
|
||||
});
|
||||
|
||||
return tempProfileData;
|
||||
}, [dataMap]);
|
||||
|
||||
const getCellClassName = (row: BannerRow, column: DataColumn<BannerRow>, rowIndex: number) => {
|
||||
const currentYear = Number(row.year);
|
||||
if (currentYear !== 2024 && currentYear !== 2025) return undefined;
|
||||
if (column.key === "rowLabel" || column.key === "total") return undefined;
|
||||
|
||||
const prevRow = penetrationChangeData[rowIndex - 1];
|
||||
if (!prevRow || Number(prevRow.year) !== currentYear - 1) return undefined;
|
||||
|
||||
const currentValue = parseNumber(row[column.key]);
|
||||
const prevValue = parseNumber(prevRow[column.key]);
|
||||
if (currentValue === null || prevValue === null) return undefined;
|
||||
|
||||
const gap = currentValue - prevValue;
|
||||
|
||||
if (gap >= 3) return "lg-num-pos";
|
||||
if (gap <= -3) return "lg-num-neg";
|
||||
|
||||
return undefined;
|
||||
};
|
||||
|
||||
return(
|
||||
<BannerSummary
|
||||
data={penetrationChangeData}
|
||||
useChart={true}
|
||||
useYear={false}
|
||||
getCellClassName={getCellClassName}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export default PenetrationChange
|
||||
@@ -3,13 +3,13 @@
|
||||
import {useLayoutFilter} from "@/components/layout/LayoutFilterContext";
|
||||
import BannerSummary from "@/components/lge-dashboard/combo/BannerSummary";
|
||||
import {useMemo} from "react";
|
||||
import {BannerRow} from "@/types/lg";
|
||||
import {BannerRow} from "@/types/lg.types";
|
||||
import {CategoryFilterValue} from "@/components/layout/CategoryFilter";
|
||||
import {useDebouncedValue} from "@/hooks/useDebouncedValue";
|
||||
import { calcGapBannerRow } from "@/lib/lg-dashboard";
|
||||
import {YEARS} from "@/const/lgConst";
|
||||
import {CategoryTargetType} from "@/config/filter.types";
|
||||
import {CategoryPageProps} from "@/components/lge-dashboard/sub-page/CategoryPage";
|
||||
import {YEARS} from "@/const/lg-common.const";
|
||||
import {CategoryTargetType} from "@/types/filter.types";
|
||||
import {CategoryPageProps} from "../../sub-page/CategoryPage";
|
||||
|
||||
const Profile = ({
|
||||
dataMap
|
||||
@@ -22,7 +22,7 @@ const Profile = ({
|
||||
|
||||
const targetMap = {
|
||||
[CategoryTargetType.PENETRATION]: "보유",
|
||||
[CategoryTargetType.PURCHASE]: "해당년도",
|
||||
[CategoryTargetType.PURCHASE]: "구매",
|
||||
[CategoryTargetType.INTENDED]: "향후구매",
|
||||
}
|
||||
|
||||
@@ -76,4 +76,4 @@ const Profile = ({
|
||||
);
|
||||
}
|
||||
|
||||
export default Profile;
|
||||
export default Profile;
|
||||
@@ -9,15 +9,18 @@ import {
|
||||
type TopChartTableRow,
|
||||
} from "@/components/lge-dashboard";
|
||||
import {
|
||||
CHART_COLOR_BY_YEAR,
|
||||
CHART_FOCUS_COLOR_BY_YEAR,
|
||||
LIFE_STAGE_COLUMNS,
|
||||
LIFE_STAGE_GROUPS,
|
||||
PRODUCT_KEY_MAP,
|
||||
PRODUCT_KEYS,
|
||||
} from "@/const/lg-product.const";
|
||||
import { PRODUCT_KEY_MAP } from "@/const/lg-schema.const";
|
||||
import {
|
||||
API_DECIMAL_POINT,
|
||||
SITE_TITLE,
|
||||
YEARS
|
||||
} from "@/const/lgConst";
|
||||
USE_CACHE,
|
||||
YEARS,
|
||||
} from "@/const/lg-common.const";
|
||||
import { CHART_COLOR_BY_YEAR, CHART_FOCUS_COLOR_BY_YEAR } from "@/components/lge-dashboard/chart/chart.config";
|
||||
import {useEffect, useMemo} from "react";
|
||||
import LifeStageDiv from "@/components/lge-dashboard/combo/LifeStageDiv";
|
||||
import {useLayoutFilter} from "@/components/layout/LayoutFilterContext";
|
||||
@@ -25,7 +28,7 @@ import {
|
||||
calcGapProductRow, calcTotalBaseRow,
|
||||
formatRowLabel,
|
||||
normalizeFilterCondition,
|
||||
withGapRow, withTotalBaseRow
|
||||
withGapRow, withTotalBaseRow, wrapSampleRow
|
||||
} from "@/lib/lg-dashboard";
|
||||
import {
|
||||
buildHeader_LifeStageColumns,
|
||||
@@ -34,10 +37,10 @@ import {
|
||||
Section
|
||||
} from "@/lib/lg-export-excel";
|
||||
import {toNumOr0} from "@/lib/utils";
|
||||
import {LifeStageGroup, LifeStageRow, ProductKey, StatisticsRequest} from "@/types/lg";
|
||||
import {LifeStageGroup, LifeStageRow, ProductKey, StatisticsRequest} from "@/types/lg.types";
|
||||
import {useDebouncedValue} from "@/hooks/useDebouncedValue";
|
||||
import {SelectedMap} from "@/types/common";
|
||||
import {useBannerStatisticsQuery, useProductStatisticsQuery} from "@/hooks/useLgStatisticsQuery";
|
||||
import {useBannerStatisticsQuery, useProductStatisticsQuery} from "@/query/statistics";
|
||||
|
||||
const LGPenetrationPage = () => {
|
||||
const {filterValue, registerExcelExporter} = useLayoutFilter();
|
||||
@@ -48,7 +51,7 @@ const LGPenetrationPage = () => {
|
||||
variableIdMap: {penetration: "KQA1", penetration_lg: "KQA3_3_LG"},
|
||||
bannerIdList: ["product"],
|
||||
filterCondition: normalizeFilterCondition(debouncedFilterValue),
|
||||
option: {useCache: true, lastYear: false, decimalPoint: 0},
|
||||
option: {useCache: USE_CACHE, lastYear: false, decimalPoint: API_DECIMAL_POINT },
|
||||
};
|
||||
}, [debouncedFilterValue]);
|
||||
|
||||
@@ -59,7 +62,7 @@ const LGPenetrationPage = () => {
|
||||
variableIdMap: {lifestage_lg: "KQA3_3_LG"},
|
||||
bannerIdList: ["product|lifeStage"],
|
||||
filterCondition: normalizeFilterCondition(filter),
|
||||
option: {useCache: true, lastYear: true, decimalPoint: 0},
|
||||
option: {useCache: USE_CACHE, lastYear: true, decimalPoint: API_DECIMAL_POINT },
|
||||
};
|
||||
}, [debouncedFilterValue]);
|
||||
|
||||
@@ -80,21 +83,23 @@ const LGPenetrationPage = () => {
|
||||
|
||||
const penetrationRows =
|
||||
data?.statisticsDataMap?.penetration
|
||||
.filter((r) => r.rowLabel == `보유`)
|
||||
.filter((r) => r.rowLabel == `보유` || r.rowLabel == `사례수`)
|
||||
.map((row) => {
|
||||
const rowLabel = row.rowLabel == `사례수`? `${formatRowLabel(row.year)} ${row.rowLabel}` : row.year;
|
||||
return {
|
||||
...row,
|
||||
rowLabel: row.year,
|
||||
rowLabel: rowLabel,
|
||||
}
|
||||
}) ?? [];
|
||||
|
||||
const penetrationLGRows =
|
||||
data?.statisticsDataMap?.penetration_lg
|
||||
.filter((row) => row.rowLabel === `보유`)
|
||||
.filter((r) => r.rowLabel == `보유` || r.rowLabel == `사례수`)
|
||||
.map((row) => {
|
||||
const rowLabel = row.rowLabel == `사례수`? `${formatRowLabel(row.year)} ${row.rowLabel}` : row.year;
|
||||
return {
|
||||
...row,
|
||||
rowLabel: row.year,
|
||||
rowLabel: rowLabel,
|
||||
}
|
||||
}) ?? [];
|
||||
|
||||
@@ -119,8 +124,9 @@ const LGPenetrationPage = () => {
|
||||
}, [penetrationLGRows]);
|
||||
|
||||
const penetrationLGRowsWithGap = useMemo(() => {
|
||||
const withGap = withGapRow(penetrationLGRows, calcGapProductRow);
|
||||
return withTotalBaseRow("보급률",penetrationRows, withGap, calcTotalBaseRow);
|
||||
const withGap = withGapRow(penetrationLGRows, calcGapProductRow, -1, -3);
|
||||
|
||||
return withTotalBaseRow("보급률",penetrationRows, wrapSampleRow(withGap, false), calcTotalBaseRow);
|
||||
}, [penetrationRows, penetrationLGRows]);
|
||||
|
||||
const productTableRows = useMemo<TopChartTableRow[]>(() => {
|
||||
@@ -181,6 +187,8 @@ const LGPenetrationPage = () => {
|
||||
"KLIFEstAGE#4": lifeStageData[`${key}|KLIFEstAGE#4`] ?? "",
|
||||
"KLIFEstAGE#5": lifeStageData[`${key}|KLIFEstAGE#5`] ?? "",
|
||||
"KLIFEstAGE#6": lifeStageData[`${key}|KLIFEstAGE#6`] ?? "",
|
||||
"KLIFEstAGE#7": lifeStageData[`${key}|KLIFEstAGE#7`] ?? "",
|
||||
"KLIFEstAGE#8": lifeStageData[`${key}|KLIFEstAGE#8`] ?? "",
|
||||
};
|
||||
});
|
||||
|
||||
@@ -235,6 +243,7 @@ const LGPenetrationPage = () => {
|
||||
chart={
|
||||
<GroupedOverlayBar
|
||||
data={productChartData}
|
||||
questionText={"보급률"}
|
||||
yearTotalColor={CHART_COLOR_BY_YEAR}
|
||||
yearFocusColor={CHART_FOCUS_COLOR_BY_YEAR}
|
||||
showFocusLabel={"last"}
|
||||
@@ -251,4 +260,4 @@ const LGPenetrationPage = () => {
|
||||
);
|
||||
};
|
||||
|
||||
export default LGPenetrationPage;
|
||||
export default LGPenetrationPage;
|
||||
|
||||
@@ -2,12 +2,16 @@
|
||||
|
||||
import {useEffect, useMemo} from "react";
|
||||
import {
|
||||
CHART_COLOR_BY_YEAR, CHART_FOCUS_COLOR_BY_YEAR,
|
||||
PRODUCT_KEY_MAP,
|
||||
PRODUCT_KEYS,
|
||||
} from "@/const/lg-product.const";
|
||||
import { PRODUCT_KEY_MAP } from "@/const/lg-schema.const";
|
||||
import {
|
||||
API_DECIMAL_POINT,
|
||||
SITE_TITLE,
|
||||
YEARS
|
||||
} from "@/const/lgConst";
|
||||
USE_CACHE,
|
||||
YEARS,
|
||||
} from "@/const/lg-common.const";
|
||||
import { CHART_COLOR_BY_YEAR, CHART_FOCUS_COLOR_BY_YEAR } from "@/components/lge-dashboard/chart/chart.config";
|
||||
import {
|
||||
BottomDescription,
|
||||
GroupedOverlayBar,
|
||||
@@ -21,13 +25,13 @@ import {
|
||||
calcGapProductRow, calcTotalBaseRow,
|
||||
formatRowLabel,
|
||||
normalizeFilterCondition,
|
||||
withGapRow, withTotalBaseRow
|
||||
withGapRow, withTotalBaseRow, wrapSampleRow
|
||||
} from "@/lib/lg-dashboard";
|
||||
import {buildHeader_ProductKeyMap, exportDashboardExcel} from "@/lib/lg-export-excel";
|
||||
import {useDebouncedValue} from "@/hooks/useDebouncedValue";
|
||||
import {SelectedMap} from "@/types/common";
|
||||
import {ProductKey, StatisticsRequest} from "@/types/lg";
|
||||
import {useProductStatisticsQuery} from "@/hooks/useLgStatisticsQuery";
|
||||
import {ProductKey, StatisticsRequest} from "@/types/lg.types";
|
||||
import {useProductStatisticsQuery} from "@/query/statistics";
|
||||
import {toNumOr0} from "@/lib/utils";
|
||||
|
||||
const LGPurchasePage = () => {
|
||||
@@ -36,10 +40,10 @@ const LGPurchasePage = () => {
|
||||
|
||||
const req = useMemo<StatisticsRequest>(() => {
|
||||
return {
|
||||
variableIdMap: {purchase: "KQA3_2", purchase_lg: "KQX3_3_LG"},
|
||||
variableIdMap: {purchase: "KQB0", purchase_lg: "KQX3_3_LG"},
|
||||
bannerIdList: ["product"],
|
||||
filterCondition: normalizeFilterCondition(debouncedFilterValue),
|
||||
option: {useCache: true, lastYear: false, decimalPoint: 0},
|
||||
option: {useCache: USE_CACHE, lastYear: false, decimalPoint: API_DECIMAL_POINT },
|
||||
};
|
||||
}, [debouncedFilterValue]);
|
||||
|
||||
@@ -51,26 +55,28 @@ const LGPurchasePage = () => {
|
||||
|
||||
const purchaseRows =
|
||||
data?.statisticsDataMap?.purchase
|
||||
.filter((r) => r.rowLabel == `해당년도`)
|
||||
.filter((r) => r.rowLabel == `구매` || r.rowLabel == `사례수`)
|
||||
.map((row) => {
|
||||
const rowLabel = row.rowLabel == `사례수`? `${formatRowLabel(row.year)} ${row.rowLabel}` : row.year;
|
||||
return {
|
||||
...row,
|
||||
rowLabel: row.year,
|
||||
rowLabel: rowLabel,
|
||||
}
|
||||
}) ?? [];
|
||||
|
||||
const purchaseLGRows =
|
||||
data?.statisticsDataMap?.purchase_lg
|
||||
.filter((row) => row.rowLabel === `구입`)
|
||||
.filter((row) => row.rowLabel === `구입` || row.rowLabel == `사례수`)
|
||||
.map((row) => {
|
||||
const rowLabel = row.rowLabel == `사례수`? `${formatRowLabel(row.year)} ${row.rowLabel}` : row.year;
|
||||
return {
|
||||
...row,
|
||||
rowLabel: row.year,
|
||||
rowLabel: rowLabel,
|
||||
}
|
||||
}) ?? [];
|
||||
|
||||
const purchaseLGRowsWithGap = useMemo(() => {
|
||||
const withGap = withGapRow(purchaseLGRows, calcGapProductRow);
|
||||
const withGap = withGapRow(wrapSampleRow(purchaseLGRows, false), calcGapProductRow, -1, -3);
|
||||
return withTotalBaseRow("구입율",purchaseRows, withGap, calcTotalBaseRow);
|
||||
}, [purchaseRows, purchaseLGRows]);
|
||||
|
||||
@@ -110,8 +116,8 @@ const LGPurchasePage = () => {
|
||||
|
||||
for (let ci = 0; ci < includeProductKeys.length; ci++) {
|
||||
const k = includeProductKeys[ci];
|
||||
const t = (purchaseRows[ri] as any)[k];
|
||||
const v = (r as any)[k];
|
||||
const t = (purchaseRows[ri] as any)[k] ?? "";
|
||||
const v = (r as any)[k] ?? "";
|
||||
|
||||
total[yi][ci] = Number(t);
|
||||
focus[yi][ci] = Number(v);
|
||||
@@ -132,9 +138,9 @@ const LGPurchasePage = () => {
|
||||
return "Q. 다음 중 귀댁에서 보유하고 계신 가전/전자 제품은 무엇입니까? 모두 선택해주세요.<br/>" +
|
||||
"* 구독/렌탈/선물/경품/아파트 내 빌트인 제품을 모두 포함하여 선택해주세요.<br/>" +
|
||||
"Q. 보유하고 계신 (제품)을 언제 구입하셨습니까?<br/>" +
|
||||
"* 새 상품을 선물 받은 경우, 선물 받은 연도로 입력해주세요.<br/>" +
|
||||
"** 중고 제품인 경우, 중고 제품을 구입한 연도로 입력해주세요.<br/>" +
|
||||
"*** 신규 입주 시 빌트인되어 있던 제품은 입주한 연도를 입력해주세요.<br/>" +
|
||||
//"* 새 상품을 선물 받은 경우, 선물 받은 연도로 입력해주세요.<br/>" +
|
||||
//"** 중고 제품인 경우, 중고 제품을 구입한 연도로 입력해주세요.<br/>" +
|
||||
//"*** 신규 입주 시 빌트인되어 있던 제품은 입주한 연도를 입력해주세요.<br/>" +
|
||||
"Q. 보유하고 계신 (제품)의 브랜드는 어떻게 되십니까?";
|
||||
}, []);
|
||||
|
||||
@@ -162,6 +168,7 @@ const LGPurchasePage = () => {
|
||||
chart={
|
||||
<GroupedOverlayBar
|
||||
data={purchaseChartData}
|
||||
questionText={"구매율"}
|
||||
yearTotalColor={CHART_COLOR_BY_YEAR}
|
||||
yearFocusColor={CHART_FOCUS_COLOR_BY_YEAR}
|
||||
showFocusLabel={"last"}
|
||||
@@ -176,4 +183,4 @@ const LGPurchasePage = () => {
|
||||
);
|
||||
};
|
||||
|
||||
export default LGPurchasePage;
|
||||
export default LGPurchasePage;
|
||||
|
||||
@@ -14,20 +14,22 @@ import { useLayoutFilter } from "@/components/layout/LayoutFilterContext";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
BRAND_LIST,
|
||||
PRODUCT_KEYS,
|
||||
PRODUCTS,
|
||||
YEARS,
|
||||
AXIS_HIDE_STYLE,
|
||||
GRID_X_NOT_PADDING, PRODUCT_KEY_MAP, SITE_TITLE
|
||||
} from "@/const/lgConst";
|
||||
SITE_TITLE,
|
||||
USE_CACHE,
|
||||
API_DECIMAL_POINT,
|
||||
} from "@/const/lg-common.const";
|
||||
import { PRODUCT_KEY_MAP } from "@/const/lg-schema.const";
|
||||
import { PRODUCT_KEYS, PRODUCTS } from "@/const/lg-product.const";
|
||||
import { AXIS_HIDE_STYLE, GRID_X_NOT_PADDING } from "@/components/lge-dashboard/chart/chart.config";
|
||||
import {
|
||||
calcCagrRow, calcGapProductRow,
|
||||
formatRowLabel,
|
||||
normalizeFilterCondition, withCagrRow, withGapRow
|
||||
normalizeFilterCondition, withCagrRow, withGapRow, wrapSampleRow
|
||||
} from "@/lib/lg-dashboard";
|
||||
import {buildHeader_ProductKeyMap, exportDashboardExcel, Section} from "@/lib/lg-export-excel";
|
||||
import {StatisticsRequest} from "@/types/lg";
|
||||
import {useProductStatisticsQuery} from "@/hooks/useLgStatisticsQuery";
|
||||
import {StatisticsRequest} from "@/types/lg.types";
|
||||
import {useProductStatisticsQuery} from "@/query/statistics";
|
||||
import {useDebouncedValue} from "@/hooks/useDebouncedValue";
|
||||
import {toNumOr0} from "@/lib/utils";
|
||||
import {SelectedMap} from "@/types/common";
|
||||
@@ -37,19 +39,12 @@ const PenetrationPage = () => {
|
||||
const debouncedFilterValue = useDebouncedValue<SelectedMap>(filterValue as SelectedMap, 500);
|
||||
const [isBrandShare, setIsBrandShare] = useState(false);
|
||||
|
||||
const chartColorByYear = Object.fromEntries(
|
||||
YEARS.map((year, i) => [
|
||||
year,
|
||||
[`--chart-cbrand-${i + 1}`,`--chart-samsung-${i + 1}`,`--chart-lg-${i + 1}`],
|
||||
])
|
||||
) as Record<(typeof YEARS)[number], string[]>;
|
||||
|
||||
const req = useMemo<StatisticsRequest>(() => {
|
||||
return {
|
||||
variableIdMap: { penetration: "KQA1", penetration_brand: "KQA3_3_NET" },
|
||||
bannerIdList: ["product"],
|
||||
filterCondition: normalizeFilterCondition(debouncedFilterValue),
|
||||
option: { useCache: true, lastYear: false, decimalPoint: 0 },
|
||||
option: { useCache: USE_CACHE, lastYear: false, decimalPoint: API_DECIMAL_POINT },
|
||||
};
|
||||
}, [debouncedFilterValue]);
|
||||
|
||||
@@ -61,21 +56,39 @@ const PenetrationPage = () => {
|
||||
|
||||
const penetrationRows =
|
||||
data?.statisticsDataMap?.penetration
|
||||
.filter((r) => r.rowLabel == `보유`)
|
||||
.filter((r) => r.rowLabel == `보유` || r.rowLabel == `사례수`)
|
||||
.map((row) => {
|
||||
const rowLabel = row.rowLabel == `사례수`? `${formatRowLabel(row.year)} ${row.rowLabel}` : row.year;
|
||||
return {
|
||||
...row,
|
||||
rowLabel: row.year,
|
||||
rowLabel: rowLabel,
|
||||
}
|
||||
}) ?? [];
|
||||
|
||||
const penetrationBrandRows =
|
||||
const penetrationBrandRows = (
|
||||
data?.statisticsDataMap?.penetration_brand
|
||||
.filter((row) => BRAND_LIST.includes(row.rowLabel)) ?? [];
|
||||
?.filter((row) => BRAND_LIST.includes(row.rowLabel)) ?? []
|
||||
).map((row) => {
|
||||
PRODUCT_KEYS.forEach((k) => {
|
||||
(row as any)[k] = Number((row as any)[k]).toFixed(0);
|
||||
});
|
||||
|
||||
return row;
|
||||
});
|
||||
|
||||
const penetrationRowsWithGapCagr = useMemo(() => {
|
||||
const withGap = withGapRow(penetrationRows, calcGapProductRow);
|
||||
return withCagrRow(withGap, calcCagrRow);
|
||||
const withGap = withGapRow(penetrationRows, calcGapProductRow, -1, -3);
|
||||
const withCagr = withCagrRow(withGap, calcCagrRow, -1, 2);
|
||||
|
||||
withCagr.forEach((row) => {
|
||||
if (row.rowLabel !== "CAGR") {
|
||||
PRODUCT_KEYS.forEach((k) => {
|
||||
(row as any)[k] = Number((row as any)[k]).toFixed(0);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return wrapSampleRow(withCagr, false);
|
||||
}, [penetrationRows]);
|
||||
|
||||
const productTableRows = useMemo<TopChartTableRow[]>(() => {
|
||||
@@ -89,7 +102,7 @@ const PenetrationPage = () => {
|
||||
const productChartData = useMemo<ChartData>(() => {
|
||||
return {
|
||||
categories: [...PRODUCTS],
|
||||
series: penetrationRows
|
||||
series: penetrationRows.filter((r) => !r.rowLabel.includes("사례수"))
|
||||
.map((row) => ({
|
||||
name: row.year,
|
||||
data: PRODUCT_KEYS.map((k) => toNumOr0((row as any)[k])),
|
||||
@@ -153,7 +166,7 @@ const PenetrationPage = () => {
|
||||
});
|
||||
});
|
||||
return () => registerExcelExporter(null);
|
||||
}, [registerExcelExporter, penetrationRows, penetrationBrandRows]);
|
||||
}, [registerExcelExporter, penetrationRowsWithGapCagr, penetrationBrandRows]);
|
||||
|
||||
return (
|
||||
<div>
|
||||
@@ -163,23 +176,23 @@ const PenetrationPage = () => {
|
||||
variant={isBrandShare ? "default" : "secondary"}
|
||||
onClick={() => setIsBrandShare((v) => !v)}
|
||||
>
|
||||
{"브랜드별 점유율"}
|
||||
{"브랜드 점유율 변화"}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<TopChartTable
|
||||
title={isBrandShare ? "브랜드별 점유율" : "전체 보급률"}
|
||||
title={isBrandShare ? "브랜드 점유율 변화" : "전체 보급률"}
|
||||
categories={[...PRODUCTS]}
|
||||
rows={productTableRows}
|
||||
chart={
|
||||
isBrandShare ? (
|
||||
<GroupedStackBar
|
||||
data={brandShareChartData}
|
||||
grid={{ ...GRID_X_NOT_PADDING, top: 60 }}
|
||||
grid={{...GRID_X_NOT_PADDING, bottom: 20}}
|
||||
xAxis={{ type: "category", data: PRODUCTS, ...AXIS_HIDE_STYLE }}
|
||||
yAxis={{ type: "value", ...AXIS_HIDE_STYLE }}
|
||||
showFocusLabel={"none"}
|
||||
yearBrandPalette={chartColorByYear}
|
||||
yearBrandPalette={[ "--chart-etc", "--chart-cbrand","--chart-samsung","--chart-lg"]}
|
||||
height={260}
|
||||
/>
|
||||
) : (
|
||||
@@ -197,9 +210,10 @@ const PenetrationPage = () => {
|
||||
signStyle={signStyleGapRow}
|
||||
fillCAGR={true}
|
||||
/>
|
||||
<BottomDescription description={"CAGR(%) 5%p 이상 품목에 대해 음영 표시"} />
|
||||
<BottomDescription description={description} />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default PenetrationPage;
|
||||
export default PenetrationPage;
|
||||
|
||||
@@ -4,11 +4,14 @@ import {useEffect, useMemo} from "react";
|
||||
import {
|
||||
PRODUCT_KEYS,
|
||||
PRODUCTS,
|
||||
AXIS_HIDE_STYLE,
|
||||
GRID_X_NOT_PADDING,
|
||||
PRODUCT_KEY_MAP,
|
||||
SITE_TITLE
|
||||
} from "@/const/lgConst";
|
||||
} from "@/const/lg-product.const";
|
||||
import { PRODUCT_KEY_MAP } from "@/const/lg-schema.const";
|
||||
import {
|
||||
SITE_TITLE,
|
||||
USE_CACHE,
|
||||
API_DECIMAL_POINT,
|
||||
} from "@/const/lg-common.const";
|
||||
import { AXIS_HIDE_STYLE, GRID_X_NOT_PADDING } from "@/components/lge-dashboard/chart/chart.config";
|
||||
import {
|
||||
BottomDescription,
|
||||
type ChartData,
|
||||
@@ -18,12 +21,18 @@ import {
|
||||
VerticalBar,
|
||||
} from "@/components/lge-dashboard";
|
||||
import { useLayoutFilter } from "@/components/layout/LayoutFilterContext";
|
||||
import {calcGapProductRow, formatRowLabel, normalizeFilterCondition, withGapRow} from "@/lib/lg-dashboard";
|
||||
import {
|
||||
calcGapProductRow,
|
||||
formatRowLabel,
|
||||
normalizeFilterCondition,
|
||||
withGapRow,
|
||||
wrapSampleRow
|
||||
} from "@/lib/lg-dashboard";
|
||||
import {buildHeader_ProductKeyMap, exportDashboardExcel} from "@/lib/lg-export-excel";
|
||||
import {useDebouncedValue} from "@/hooks/useDebouncedValue";
|
||||
import {SelectedMap} from "@/types/common";
|
||||
import {StatisticsRequest} from "@/types/lg";
|
||||
import {useProductStatisticsQuery} from "@/hooks/useLgStatisticsQuery";
|
||||
import {StatisticsRequest} from "@/types/lg.types";
|
||||
import {useProductStatisticsQuery} from "@/query/statistics";
|
||||
|
||||
const PurchasePage = () => {
|
||||
const { filterValue, registerExcelExporter } = useLayoutFilter();
|
||||
@@ -31,10 +40,10 @@ const PurchasePage = () => {
|
||||
|
||||
const req = useMemo<StatisticsRequest>(() => {
|
||||
return {
|
||||
variableIdMap: { purchase: "KQA3_2"},
|
||||
variableIdMap: { purchase: "KQB0"},
|
||||
bannerIdList: ["product"],
|
||||
filterCondition: normalizeFilterCondition(debouncedFilterValue),
|
||||
option: { useCache: true, lastYear: false, decimalPoint: 0 },
|
||||
option: { useCache: USE_CACHE, lastYear: false, decimalPoint: API_DECIMAL_POINT },
|
||||
};
|
||||
}, [debouncedFilterValue]);
|
||||
|
||||
@@ -46,16 +55,17 @@ const PurchasePage = () => {
|
||||
|
||||
const purchaseRows =
|
||||
data?.statisticsDataMap?.purchase
|
||||
.filter((r) => r.rowLabel == `해당년도`)
|
||||
.filter((r) => r.rowLabel == `구매` || r.rowLabel == `사례수`)
|
||||
.map((row) => {
|
||||
const rowLabel = row.rowLabel == `사례수`? `${formatRowLabel(row.year)} ${row.rowLabel}` : row.year;
|
||||
return {
|
||||
...row,
|
||||
rowLabel: row.year,
|
||||
rowLabel: rowLabel,
|
||||
}
|
||||
}) ?? [];
|
||||
|
||||
const purchaseRowsWithGap = useMemo(() => {
|
||||
return withGapRow(purchaseRows, calcGapProductRow);
|
||||
return withGapRow(wrapSampleRow(purchaseRows, false), calcGapProductRow, -1, -3);
|
||||
}, [purchaseRows]);
|
||||
|
||||
const purchaseTableRows = useMemo<TopChartTableRow[]>(() => {
|
||||
@@ -69,7 +79,7 @@ const PurchasePage = () => {
|
||||
const purchaseChartData = useMemo<ChartData>(() => {
|
||||
return {
|
||||
categories: [...PRODUCTS],
|
||||
series: purchaseRows
|
||||
series: purchaseRows.filter((r) => !r.rowLabel.includes("사례수"))
|
||||
.map((r) => ({
|
||||
name: r.rowLabel,
|
||||
data: PRODUCT_KEYS.map((k) => (r as any)[k] ?? null),
|
||||
@@ -80,10 +90,12 @@ const PurchasePage = () => {
|
||||
const description = useMemo(() => {
|
||||
return "Q. 다음 중 귀댁에서 보유하고 계신 가전/전자 제품은 무엇입니까? 모두 선택해주세요.<br/>" +
|
||||
"* 구독/렌탈/선물/경품/아파트 내 빌트인 제품을 모두 포함하여 선택해주세요.<br/>" +
|
||||
"Q. 보유하고 계신 (제품)을 언제 구입하셨습니까?<br/>" +
|
||||
"Q. 보유하고 계신 (제품)을 언제 구입하셨습니까?<br/>";
|
||||
/*
|
||||
"* 새 상품을 선물 받은 경우, 선물 받은 연도로 입력해주세요.<br/>" +
|
||||
"** 중고 제품인 경우, 중고 제품을 구입한 연도로 입력해주세요.<br/>" +
|
||||
"*** 신규 입주 시 빌트인되어 있던 제품은 입주한 연도를 입력해주세요.";
|
||||
*/
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -113,7 +125,7 @@ const PurchasePage = () => {
|
||||
paletteVarNames={["--chart-3", "--chart-2", "--chart-1"]}
|
||||
grid={GRID_X_NOT_PADDING}
|
||||
xAxis={{ type: "category", data: [...PRODUCTS], ...AXIS_HIDE_STYLE }}
|
||||
yAxis={{ type: "value", ...AXIS_HIDE_STYLE }}
|
||||
yAxis={{ type: "value", min:0, max:100, ...AXIS_HIDE_STYLE }}
|
||||
showFocusLabel={"last"}
|
||||
height={260}
|
||||
/>
|
||||
@@ -126,4 +138,4 @@ const PurchasePage = () => {
|
||||
);
|
||||
};
|
||||
|
||||
export default PurchasePage;
|
||||
export default PurchasePage;
|
||||
|
||||
@@ -1,14 +1,9 @@
|
||||
import {createBackApi} from "@/lib/server-api";
|
||||
import {LoginRequest, LoginUser} from "@/types/auth";
|
||||
import {LoginRequest, LoginResponse, LoginUser} from "@/types/auth";
|
||||
import {NextRequest, NextResponse} from "next/server";
|
||||
import {serverEnv} from "@/lib/env.server";
|
||||
import {errorToResponse} from "@/lib/http-util";
|
||||
|
||||
type LoginResponse = {
|
||||
accessToken: string;
|
||||
user: LoginUser;
|
||||
};
|
||||
|
||||
export const POST = async (req: NextRequest) => {
|
||||
try {
|
||||
const backApi = await createBackApi();
|
||||
|
||||
@@ -2,7 +2,7 @@ import {NextRequest, NextResponse} from "next/server";
|
||||
import {RouteContext} from "@/types/common";
|
||||
import {errorToResponse} from "@/lib/http-util";
|
||||
import {createBackApi} from "@/lib/server-api";
|
||||
import {ProductResponse, BannerResponse} from "@/types/lg";
|
||||
import {ProductResponse, BannerResponse} from "@/types/lg.types";
|
||||
|
||||
export async function POST(
|
||||
req: NextRequest,
|
||||
@@ -36,4 +36,4 @@ export async function POST(
|
||||
} catch (error: unknown) {
|
||||
return errorToResponse(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,17 +54,6 @@
|
||||
--color-warning: var(--warning);
|
||||
--color-info: var(--info);
|
||||
|
||||
/* Chart */
|
||||
--color-chart-1: var(--chart-1);
|
||||
--color-chart-2: var(--chart-2);
|
||||
--color-chart-3: var(--chart-3);
|
||||
--color-chart-4: var(--chart-4);
|
||||
--color-chart-5: var(--chart-5);
|
||||
--color-chart-6: var(--chart-6);
|
||||
--color-chart-7: var(--chart-7);
|
||||
--color-chart-8: var(--chart-8);
|
||||
--color-chart-9: var(--chart-9);
|
||||
--color-chart-10: var(--chart-10);
|
||||
--color-chart-border: var(--chart-border);
|
||||
|
||||
/* Sidebar (shadcn sidebar 토큰) */
|
||||
@@ -134,11 +123,6 @@
|
||||
--lg-orange-500: 29.6 95% 56.0%;
|
||||
--lg-orange-400: 29.6 85% 68.0%;
|
||||
--lg-orange-300: 29.6 75% 78.0%;
|
||||
|
||||
--samsung-blue-600: 218.93 53.91% 52.35%; /* #4472C7 */
|
||||
--samsung-blue-500: 218.93 48.0% 56.0%; /* #597FC5 */
|
||||
--samsung-blue-400: 218.93 40.0% 66.0%; /* #869ECB */
|
||||
--samsung-blue-300: 218.93 33.0% 76.0%; /* #AEBCD6 */
|
||||
/* =============================
|
||||
Brand Core
|
||||
(semantic은 "실제 색"으로 정의)
|
||||
@@ -183,26 +167,25 @@
|
||||
--chart-2-t: 0 0% 70%;
|
||||
--chart-3-t: 0 0% 88%;
|
||||
|
||||
--chart-4: var(--lg-pink-400);
|
||||
--chart-5: var(--lg-pink-600);
|
||||
--chart-6: var(--lg-gray-500);
|
||||
--chart-7: var(--lg-gray-600);
|
||||
--chart-8: var(--lg-gray-700);
|
||||
--chart-9: var(--lg-gray-800);
|
||||
--chart-10: var(--lg-gray-900);
|
||||
--chart-stack-1: 335 64% 34%;
|
||||
--chart-stack-2: 332 65% 57%;
|
||||
--chart-stack-3: 334 66% 73%;
|
||||
--chart-stack-4: 334 28% 49%;
|
||||
--chart-stack-5: 340 25% 58%;
|
||||
--chart-stack-6: 0 28% 69%;
|
||||
--chart-stack-7: 26 37% 70%;
|
||||
--chart-stack-8: 27 38% 83%;
|
||||
--chart-stack-9: 30 45% 91%;
|
||||
--chart-stack-10: 0 0% 50%;
|
||||
--chart-stack-11: 0 0% 60%;
|
||||
--chart-stack-12: 0 0% 71%;
|
||||
--chart-stack-13: 0 0% 82%;
|
||||
--chart-stack-14: 0 0% 91%;
|
||||
|
||||
--chart-lg-1: var(--lg-pink-300);
|
||||
--chart-lg-2: var(--lg-red-300);
|
||||
--chart-lg-3: var(--lg-red-600);
|
||||
--chart-total-1: var(--lg-gray-300);
|
||||
--chart-total-2: var(--lg-gray-400);
|
||||
--chart-total-3: var(--lg-gray-700);
|
||||
--chart-cbrand-1: var(--lg-gray-300);
|
||||
--chart-cbrand-2: var(--lg-gray-400);
|
||||
--chart-cbrand-3: var(--lg-gray-700);
|
||||
--chart-samsung-1: var(--samsung-blue-400);
|
||||
--chart-samsung-2: var(--samsung-blue-500);
|
||||
--chart-samsung-3: var(--samsung-blue-600);
|
||||
--chart-lg: var(--chart-1);
|
||||
--chart-samsung: 218 48% 58%;
|
||||
--chart-cbrand: var(--chart-2);
|
||||
--chart-etc: 0 0% 74%;
|
||||
|
||||
--chart-border: hsl(0 0% 95%);
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import { useAtomValue } from "jotai";
|
||||
import { Loader2Icon } from "lucide-react";
|
||||
import { loadingAtom } from "@/store/jotai/loading";
|
||||
|
||||
export function LoadingOverlay({ force = false }: { force?: boolean }) {
|
||||
@@ -9,9 +10,11 @@ export function LoadingOverlay({ force = false }: { force?: boolean }) {
|
||||
if (!force && !isLoading) return null;
|
||||
|
||||
return (
|
||||
<div className="fixed inset-0 z-[9999] bg-black/70 flex items-center justify-center">
|
||||
{/* 심플 로딩 인디케이터 */}
|
||||
<div className="h-12 w-12 rounded-full border-4 border-gray-400 border-t-white animate-spin" />
|
||||
<div className="fixed inset-0 z-[9999] flex items-center justify-center bg-black/65">
|
||||
<div className="flex flex-col items-center gap-3">
|
||||
<Loader2Icon className="size-20 animate-spin text-white" style={{ animationDuration: "0.7s" }} />
|
||||
<div className="text-sm font-medium tracking-[0.18em] text-white/90">Loading</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,14 +3,15 @@
|
||||
import {
|
||||
CategoryTargetType,
|
||||
TargetChild,
|
||||
} from "@/config/filter.types";
|
||||
import {categoryTarget, categoryTargetType} from "@/config/filter.data";
|
||||
} from "@/types/filter.types";
|
||||
import {categoryTarget, categoryTargetType} from "@/const/filter.const";
|
||||
import { ChevronRight } from "lucide-react";
|
||||
import {useCallback, useMemo} from "react";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {ProductKey, ProductsFilterItem} from "@/types/lg";
|
||||
import {PRODUCT_KEY_MAP, YEARS} from "@/const/lgConst";
|
||||
import {ProductKey, ProductsFilterItem} from "@/types/lg.types";
|
||||
import {PRODUCT_KEY_MAP} from "@/const/lg-schema.const";
|
||||
import {YEARS} from "@/const/lg-common.const";
|
||||
|
||||
export type CategoryTypeValue = {
|
||||
label: string;
|
||||
|
||||
@@ -2,11 +2,11 @@ import {useAuth} from "@/hooks/useAuth";
|
||||
import {useEffect, useState} from "react";
|
||||
import {LoginUser} from "@/types/auth";
|
||||
import Image from "next/image";
|
||||
import {topMenus} from "@/config/menu.data";
|
||||
import {topMenus} from "@/const/menu.const";
|
||||
import {Button} from "@/components/ui/button";
|
||||
import {LogOut} from "lucide-react";
|
||||
import {cn} from "@/lib/utils";
|
||||
import {SITE_TITLE} from "@/const/lgConst";
|
||||
import {SITE_TITLE} from "@/const/lg-common.const";
|
||||
|
||||
interface HeaderProps {
|
||||
activeTopId: string;
|
||||
@@ -89,4 +89,4 @@ const Header = ({
|
||||
);
|
||||
}
|
||||
|
||||
export default Header;
|
||||
export default Header;
|
||||
|
||||
@@ -1,21 +1,23 @@
|
||||
"use client";
|
||||
|
||||
import {ReactNode, useEffect, useRef, useState} from "react";
|
||||
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, totalFilters} from "@/config/filter.data";
|
||||
import {CategoryTargetData, CategoryTargetType} from "@/config/filter.types";
|
||||
import {topMenus, totalSubMenus, categorySubMenus} from "@/const/menu.const";
|
||||
import {categoryTarget, totalFilters} from "@/const/filter.const";
|
||||
import {CategoryTargetData, CategoryTargetType} from "@/types/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 {LAST_YEAR, PRODUCTS_FILTER_ITEM} from "@/const/lgConst";
|
||||
import {ProductsFilterItem} from "@/types/lg";
|
||||
import {LAST_YEAR} from "@/const/lg-common.const";
|
||||
import {PRODUCTS_FILTER_ITEM} from "@/const/lg-product.const";
|
||||
import {ProductsFilterItem} from "@/types/lg.types";
|
||||
import {ArrowUp, Filter} from "lucide-react";
|
||||
import {Button} from "@/components/ui/button";
|
||||
|
||||
type MainLayoutProps = {
|
||||
children: ReactNode;
|
||||
@@ -46,9 +48,18 @@ const buildDefaultCategoryValue = (categoryFilterItems: ProductsFilterItem): Cat
|
||||
};
|
||||
|
||||
const buildTotalPartDescription = (pathname:string) => {
|
||||
return pathname.match("penetration")
|
||||
? "■ 보급률: 전체 소비자 중, 조사 년도에 해당 제품을 <strong>보유하고 있는 비율</strong>"
|
||||
: "■ 구매율: 전체 소비자 중, 조사 년도에 해당 제품을 <strong>구매한 비율</strong>";
|
||||
switch(pathname) {
|
||||
case "/total/penetration":
|
||||
return "■ 보급률: 전체 소비자 중, 조사 년도에 해당 제품을 <strong>보유하고 있는 비율</strong>";
|
||||
case "/total/lg-penetration":
|
||||
return "■ 보급률: 전체 소비자 중, 조사 년도에 LG 제품을 <strong>보유하고 있는 비율</strong>";
|
||||
case "/total/purchase":
|
||||
return "■ 구매율: 전체 소비자 중, 조사 년도에 해당 제품을 <strong>구매한 비율</strong>";
|
||||
case "/total/lg-purchase":
|
||||
return "■ 구매율: 전체 소비자 중, 조사 년도에 LG 제품을 <strong>구매한 비율</strong>";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
const MainLayout = ({ children }: MainLayoutProps) => {
|
||||
@@ -94,6 +105,21 @@ const MainLayout = ({ children }: MainLayoutProps) => {
|
||||
scrollRef.current?.scrollTo({ top: 0, behavior: "smooth" });
|
||||
};
|
||||
|
||||
const isDefaultTotalFilter = useMemo(() => {
|
||||
if(!isTotal) return false;
|
||||
|
||||
return Object.values(totalValue).every(value => value === "0");
|
||||
},[isTotal, totalValue])
|
||||
|
||||
const setDefaletTotalFilter = () => {
|
||||
if(isTotal && !isDefaultTotalFilter){
|
||||
setTotalValue(prev =>
|
||||
Object.fromEntries(
|
||||
Object.keys(prev).map(key => [key, "0"])
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
const prevIsTotal = prevIsTotalRef.current;
|
||||
@@ -152,8 +178,17 @@ const MainLayout = ({ children }: MainLayoutProps) => {
|
||||
필터 <span className="text-sm leading-none mb-1">{isFilterOpen ? "▲" : "▼"}</span>
|
||||
</button>
|
||||
{isTotal && (
|
||||
<div className={"ml-5 content-text-sm"} dangerouslySetInnerHTML={{__html: totalPartDescription}}>
|
||||
</div>
|
||||
<>
|
||||
<Button
|
||||
variant={isDefaultTotalFilter ? "secondary" : "default"}
|
||||
onClick={setDefaletTotalFilter}
|
||||
className="h-6 rounded-sm px-3 ml-3 text-sm font-semibold content-text-sm"
|
||||
>
|
||||
초기화
|
||||
</Button>
|
||||
<div className={"ml-5 content-text-sm"} dangerouslySetInnerHTML={{__html: totalPartDescription}}>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
<ExcelDownloadButton/>
|
||||
@@ -204,4 +239,4 @@ const MainLayout = ({ children }: MainLayoutProps) => {
|
||||
);
|
||||
}
|
||||
|
||||
export default MainLayout;
|
||||
export default MainLayout;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {SubMenuItem} from "@/config/menu.types";
|
||||
import {SubMenuItem} from "@/types/menu.types";
|
||||
import {cn} from "@/lib/utils";
|
||||
|
||||
interface SubMenuProps {
|
||||
@@ -45,4 +45,4 @@ const SubMenu = ({
|
||||
);
|
||||
}
|
||||
|
||||
export default SubMenu;
|
||||
export default SubMenu;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {TotalFilterItem} from "@/config/filter.types";
|
||||
import {TotalFilterItem} from "@/types/filter.types";
|
||||
import {SelectedMap} from "@/types/common";
|
||||
import {useMemo} from "react";
|
||||
import {cn} from "@/lib/utils";
|
||||
@@ -97,4 +97,4 @@ const TotalFilter = ({
|
||||
);
|
||||
}
|
||||
|
||||
export default TotalFilter;
|
||||
export default TotalFilter;
|
||||
|
||||
@@ -2,8 +2,11 @@
|
||||
|
||||
import dynamic from "next/dynamic";
|
||||
import type { EChartsOption } from "echarts";
|
||||
import { CHART_HEIGHTS } from "@/const/chartConst";
|
||||
import { CHART_HEIGHTS } from "@/components/lge-dashboard/chart/chart.config";
|
||||
import {useResizeKey} from "@/hooks/useResize";
|
||||
import { VIEW_DECIMAL_POINT } from "@/const/lg-common.const";
|
||||
import { useMemo } from "react";
|
||||
import {roundNumber} from "@/lib/lg-dashboard";
|
||||
|
||||
const ReactECharts = dynamic(() => import("echarts-for-react"), { ssr: false });
|
||||
|
||||
@@ -20,6 +23,42 @@ type BaseEChartProps = {
|
||||
onEvents?: Record<string, (params: unknown) => void>;
|
||||
};
|
||||
|
||||
const normalizeDataValue = (value: unknown): unknown => {
|
||||
if (typeof value === "number") {
|
||||
return roundNumber(value);
|
||||
}
|
||||
|
||||
if (Array.isArray(value)) {
|
||||
return value.map(normalizeDataValue);
|
||||
}
|
||||
|
||||
if (value && typeof value === "object" && "value" in value) {
|
||||
const item = value as { value: unknown };
|
||||
return {
|
||||
...(value as Record<string, unknown>),
|
||||
value: normalizeDataValue(item.value),
|
||||
};
|
||||
}
|
||||
|
||||
return value;
|
||||
};
|
||||
|
||||
const normalizeSeries = (series?: EChartsOption["series"]): EChartsOption["series"] => {
|
||||
if (!series) return series;
|
||||
|
||||
const normalizeOne = (s: any) => {
|
||||
if (!s || !("data" in s) || !Array.isArray(s.data)) {
|
||||
return s;
|
||||
}
|
||||
|
||||
return {
|
||||
...s,
|
||||
data: s.data.map(normalizeDataValue),
|
||||
};
|
||||
};
|
||||
|
||||
return Array.isArray(series) ? series.map(normalizeOne) : normalizeOne(series);
|
||||
};
|
||||
const BaseEChart = ({
|
||||
option,
|
||||
height = CHART_HEIGHTS.DEFAULT,
|
||||
@@ -32,12 +71,19 @@ const BaseEChart = ({
|
||||
}: BaseEChartProps) => {
|
||||
const resizeKey = useResizeKey(150);
|
||||
|
||||
const normalizedOption = useMemo<EChartsOption>(() => {
|
||||
return {
|
||||
...option,
|
||||
series: normalizeSeries(option.series),
|
||||
};
|
||||
}, [option]);
|
||||
|
||||
return (
|
||||
<div className={className} style={{ display: "flex", flexDirection: "column", height: height }}>
|
||||
<div className={contentClassName} style={{ flex: 1, minHeight: 0 }}>
|
||||
<ReactECharts
|
||||
key={resizeKey}
|
||||
option={option}
|
||||
option={normalizedOption}
|
||||
className={chartClassName}
|
||||
style={{ width: "100%", height: "100%" }}
|
||||
notMerge={notMerge}
|
||||
@@ -49,4 +95,4 @@ const BaseEChart = ({
|
||||
);
|
||||
}
|
||||
|
||||
export default BaseEChart;
|
||||
export default BaseEChart;
|
||||
|
||||
@@ -13,14 +13,13 @@ import BaseEChart from "../BaseEChart";
|
||||
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";
|
||||
import {AXIS_HIDE_STYLE, AXIS_HIDE_Y_STYLE, CHART_HEIGHTS, LEGEND_ITEM_SIZE} from "@/components/lge-dashboard/chart/chart.config";
|
||||
import {makeTotalBasePct} from "@/lib/lg-dashboard";
|
||||
|
||||
type Props = {
|
||||
data: GroupedOverlayBarData;
|
||||
height?: number | string;
|
||||
|
||||
questionText: string;
|
||||
tooltip?: TooltipComponentOption;
|
||||
grid?: GridComponentOption;
|
||||
xAxis?: XAXisComponentOption;
|
||||
@@ -36,6 +35,7 @@ type Props = {
|
||||
|
||||
const GroupedOverlayBar = ({
|
||||
data,
|
||||
questionText,
|
||||
height = CHART_HEIGHTS.DEFAULT,
|
||||
tooltip,
|
||||
grid,
|
||||
@@ -60,7 +60,7 @@ const GroupedOverlayBar = ({
|
||||
|
||||
const option = useMemo(() => {
|
||||
const defaultGrid: EChartsOption["grid"] = {left: 10, right: 10, top: 40, bottom: 10, containLabel: true};
|
||||
const defaultYAxis: EChartsOption["yAxis"] = { type: "value", ...AXIS_HIDE_STYLE };
|
||||
const defaultYAxis: EChartsOption["yAxis"] = { type: "value", ...AXIS_HIDE_Y_STYLE };
|
||||
const expandedCategories: string[] = [];
|
||||
data.categories.forEach((cat, catIdx) => {
|
||||
years.forEach(year => {
|
||||
@@ -204,6 +204,7 @@ const GroupedOverlayBar = ({
|
||||
formatter: (params: any) => {
|
||||
const arr = Array.isArray(params) ? params : [params];
|
||||
const header = arr?.[0]?.axisValueLabel ?? "";
|
||||
//header += ` ${questionText}`;
|
||||
|
||||
// bar만
|
||||
const barItems = arr
|
||||
@@ -229,8 +230,10 @@ const GroupedOverlayBar = ({
|
||||
const t = v.total ?? 0;
|
||||
const f = v.focus ?? 0;
|
||||
const pct = makeTotalBasePct(t, f);
|
||||
const pctStr = pct > 0 ? ` (${pct}%)` : "";
|
||||
return `${totalName} ${t} 중 ${focusName} ${f}${pctStr}`;
|
||||
//const pctStr = pct > 0 ? ` (${pct}%)` : "";
|
||||
//return `${totalName} ${t} 중 ${focusName} ${f}${pctStr}`;
|
||||
//return `${totalName} ${t} 중 ${focusName} ${f}`;
|
||||
return `${questionText} ${totalName} ${t} 중 ${focusName} ${f}`;
|
||||
});
|
||||
|
||||
return [header, ...lines].join("<br/>");
|
||||
@@ -283,4 +286,4 @@ const GroupedOverlayBar = ({
|
||||
return <BaseEChart option={option} height={height} onEvents={onEvents} />;
|
||||
}
|
||||
|
||||
export default GroupedOverlayBar;
|
||||
export default GroupedOverlayBar;
|
||||
|
||||
@@ -13,8 +13,7 @@ import BaseEChart from "../BaseEChart";
|
||||
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 { LEGEND_ITEM_SIZE } from "@/const/chartConst";
|
||||
import {AXIS_HIDE_STYLE, AXIS_HIDE_Y_STYLE, LEGEND_ITEM_SIZE} from "@/components/lge-dashboard/chart/chart.config";
|
||||
|
||||
type Props = {
|
||||
data: GroupedStackBarData;
|
||||
@@ -29,7 +28,7 @@ type Props = {
|
||||
showFocusLabel?: ShowLabel;
|
||||
|
||||
showYearLegend?: boolean;
|
||||
yearBrandPalette?: Record<string, string[]>;
|
||||
yearBrandPalette?: string[];
|
||||
};
|
||||
|
||||
const GroupedStackBar = ({
|
||||
@@ -58,14 +57,12 @@ const GroupedStackBar = ({
|
||||
const option = useMemo(() => {
|
||||
const defaultGrid: EChartsOption["grid"] = {left: 10, right: 10, top: 60, bottom: 10, containLabel: true};
|
||||
const defaultXAxis: EChartsOption["xAxis"] = { type: "category", data: data.categories, ...AXIS_HIDE_STYLE };
|
||||
const defaultYAxis: EChartsOption["yAxis"] = { type: "value", ...AXIS_HIDE_STYLE };
|
||||
const defaultYAxis: EChartsOption["yAxis"] = { type: "value", ...AXIS_HIDE_Y_STYLE };
|
||||
|
||||
const latestYear = years.at(-1);
|
||||
console.log(yearBrandPalette, String(latestYear), yearBrandPalette?.[String(latestYear)])
|
||||
const latestPalette = buildLgPalette(yearBrandPalette?.[String(latestYear)]);
|
||||
const latestPalette = buildLgPalette(yearBrandPalette);
|
||||
|
||||
const yearLegendTokens = years.map((y) => {
|
||||
const tokens = yearBrandPalette?.[String(y)];
|
||||
const tokens = yearBrandPalette;
|
||||
const last = tokens?.[tokens.length - 1];
|
||||
return last ?? "--lg-gray-500";
|
||||
});
|
||||
@@ -105,8 +102,9 @@ const GroupedStackBar = ({
|
||||
for (let yi = 0; yi < years.length; yi++) {
|
||||
const year = years[yi];
|
||||
const yearLabel = `${year}년`;
|
||||
const viewYearLabel = `'${Number(year)-2000}`;
|
||||
|
||||
const palette = buildLgPalette(yearBrandPalette?.[String(year)]);
|
||||
const palette = buildLgPalette(yearBrandPalette);
|
||||
|
||||
for (let bi = 0; bi < brands.length; bi++) {
|
||||
const brand = brands[bi];
|
||||
@@ -115,6 +113,8 @@ const GroupedStackBar = ({
|
||||
const isYearOn = yearSelected[yearLabel];
|
||||
const showLabel = getIsShowLabel(showFocusLabel, yi, years.length);
|
||||
|
||||
const isFirstBrand = bi === 0;
|
||||
|
||||
realSeries.push({
|
||||
id: `${year}|${brand}`,
|
||||
name: brand,
|
||||
@@ -123,12 +123,20 @@ const GroupedStackBar = ({
|
||||
emphasis: { disabled: true },
|
||||
barMaxWidth: barMaxWidth ?? 42,
|
||||
itemStyle: { color: palette?.[bi] },
|
||||
label: showLabel
|
||||
? ({
|
||||
label: isFirstBrand
|
||||
? {
|
||||
show: true,
|
||||
position: "bottom",
|
||||
formatter: () => viewYearLabel,
|
||||
color: "#666",
|
||||
fontSize: 12,
|
||||
}
|
||||
: showLabel
|
||||
? {
|
||||
show: true,
|
||||
position: "top",
|
||||
formatter: (p: any) => (p?.value ?? "") as any,
|
||||
} as any)
|
||||
}
|
||||
: undefined,
|
||||
data: data.categories.map((_, ci) => (isYearOn ? (row[ci] ?? null) : null)),
|
||||
});
|
||||
@@ -156,7 +164,7 @@ const GroupedStackBar = ({
|
||||
}
|
||||
|
||||
const brandLegendOpt: LegendComponentOption = ({
|
||||
top: 25,
|
||||
top: 0, //25,
|
||||
right: "center",
|
||||
orient: "horizontal",
|
||||
icon: roundedRectIcon(LEGEND_ITEM_SIZE.WIDTH, LEGEND_ITEM_SIZE.HEIGHT, LEGEND_ITEM_SIZE.RADIUS),
|
||||
@@ -167,7 +175,8 @@ const GroupedStackBar = ({
|
||||
data: [...brands].reverse(),
|
||||
} as LegendComponentOption);
|
||||
|
||||
const legends = yearLegendOpt ? [yearLegendOpt, brandLegendOpt] : brandLegendOpt;
|
||||
//const legends = yearLegendOpt ? [yearLegendOpt, brandLegendOpt] : brandLegendOpt;
|
||||
const legends = brandLegendOpt;
|
||||
|
||||
return {
|
||||
tooltip:
|
||||
|
||||
@@ -13,7 +13,7 @@ import {
|
||||
createCategoryAxis,
|
||||
createValueAxis,
|
||||
} from "@/lib/chart-options";
|
||||
import { BAR_WIDTHS } from "@/const/chartConst";
|
||||
import { BAR_WIDTHS } from "@/components/lge-dashboard/chart/chart.config";
|
||||
|
||||
type Props = {
|
||||
data: ChartData;
|
||||
@@ -28,6 +28,11 @@ type Props = {
|
||||
yAxis?: EChartsOption["yAxis"];
|
||||
barMaxWidth?: number;
|
||||
showFocusLabel?:ShowLabel;
|
||||
labelOptions?: {
|
||||
position?: "right" | "insideRight";
|
||||
color?: string;
|
||||
distance?: number;
|
||||
};
|
||||
};
|
||||
|
||||
const HorizontalBar = ({
|
||||
@@ -43,6 +48,7 @@ const HorizontalBar = ({
|
||||
yAxis,
|
||||
barMaxWidth,
|
||||
showFocusLabel = "all",
|
||||
labelOptions,
|
||||
}: Props) => {
|
||||
const palette = useMemo(() => buildLgPalette(paletteVarNames), [paletteVarNames]);
|
||||
|
||||
@@ -68,16 +74,18 @@ const HorizontalBar = ({
|
||||
label: showLabel
|
||||
? {
|
||||
show: true,
|
||||
position: "right",
|
||||
position: labelOptions?.position ?? "right",
|
||||
color: labelOptions?.color,
|
||||
distance: labelOptions?.distance,
|
||||
formatter: (p: any) => (p?.value ?? "") as any,
|
||||
}
|
||||
: undefined,
|
||||
};
|
||||
}),
|
||||
};
|
||||
}, [data, palette, valueFormatter, tooltip, legend, grid, xAxis, yAxis, barMaxWidth, showFocusLabel]);
|
||||
}, [data, palette, valueFormatter, tooltip, legend, grid, xAxis, yAxis, barMaxWidth, showFocusLabel, labelOptions]);
|
||||
|
||||
return <BaseEChart option={option} height={height} className={className} />;
|
||||
}
|
||||
|
||||
export default HorizontalBar;
|
||||
export default HorizontalBar;
|
||||
|
||||
@@ -4,7 +4,7 @@ import { useMemo } from "react";
|
||||
import type { EChartsOption } from "echarts";
|
||||
import BaseEChart from "../BaseEChart";
|
||||
import type { ChartData, ValueFormatter } from "../types";
|
||||
import { buildLgPalette } from "../color";
|
||||
import {buildLgPalette, buildLgStackPalette} from "../color";
|
||||
import {
|
||||
createDefaultTooltip,
|
||||
createDefaultLegend,
|
||||
@@ -56,7 +56,7 @@ const StackBar = ({
|
||||
);
|
||||
|
||||
const palette = useMemo(() => {
|
||||
const temp = buildLgPalette(paletteVarNames);
|
||||
const temp = buildLgStackPalette(paletteVarNames);
|
||||
const n = data.series.length; // 원본 기준
|
||||
const base = temp.slice(0, n);
|
||||
return isReverse ? [...base].reverse() : base;
|
||||
@@ -66,13 +66,26 @@ const StackBar = ({
|
||||
const fmt = valueFormatter ?? ((v: number) => String(v));
|
||||
const isV = orientation === "vertical";
|
||||
|
||||
const seriseSum: number[] = new Array(renderData.categories.length).fill(0);
|
||||
renderData.categories.forEach((c, i) => {
|
||||
renderData.series.forEach((s) => {
|
||||
seriseSum[i] += Number(s.data[i]);
|
||||
})
|
||||
});
|
||||
|
||||
const seriesSumMax = Math.max(...seriseSum);
|
||||
const valueAxis: { min: number; max?: number } = { min: 0 };
|
||||
if (seriesSumMax > 100) {
|
||||
valueAxis.max = Math.ceil(seriesSumMax / 5) * 5;
|
||||
}
|
||||
|
||||
return {
|
||||
color: palette,
|
||||
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)),
|
||||
xAxis: xAxis ?? (isV ? createCategoryAxis(renderData.categories) : createValueAxis(false, valueAxis)),
|
||||
yAxis: yAxis ?? (isV ? createValueAxis(false, valueAxis) : createCategoryAxis(renderData.categories)),
|
||||
|
||||
series: renderData.series.map((s) =>
|
||||
createBarSeries(s.name, s.data, {
|
||||
|
||||
@@ -13,7 +13,7 @@ import {
|
||||
createCategoryAxis,
|
||||
createValueAxis,
|
||||
} from "@/lib/chart-options";
|
||||
import { BAR_WIDTHS } from "@/const/chartConst";
|
||||
import { BAR_WIDTHS } from "@/components/lge-dashboard/chart/chart.config";
|
||||
|
||||
type Props = {
|
||||
data: ChartData;
|
||||
@@ -81,4 +81,4 @@ const VerticalBar = ({
|
||||
return <BaseEChart option={option} height={height} className={className} />;
|
||||
}
|
||||
|
||||
export default VerticalBar;
|
||||
export default VerticalBar;
|
||||
|
||||
86
src/components/lge-dashboard/chart/chart.config.ts
Normal file
86
src/components/lge-dashboard/chart/chart.config.ts
Normal file
@@ -0,0 +1,86 @@
|
||||
/**
|
||||
* 차트 기본 높이 설정
|
||||
*/
|
||||
export const CHART_HEIGHTS = {
|
||||
DEFAULT: "100%",
|
||||
COMPACT: 200,
|
||||
EXPANDED: 320,
|
||||
} as const;
|
||||
|
||||
/**
|
||||
* Bar 차트의 Bar 너비 설정
|
||||
*/
|
||||
export const BAR_WIDTHS = {
|
||||
DEFAULT: 42,
|
||||
NARROW: 30,
|
||||
WIDE: 60,
|
||||
} as const;
|
||||
|
||||
/**
|
||||
* 차트 Grid 기본 패딩 설정
|
||||
*/
|
||||
export const CHART_GRID_DEFAULTS = {
|
||||
DEFAULT: {
|
||||
left: 16,
|
||||
right: 16,
|
||||
top: 36,
|
||||
bottom: 12,
|
||||
containLabel: true,
|
||||
},
|
||||
COMPACT: {
|
||||
left: 10,
|
||||
right: 10,
|
||||
top: 20,
|
||||
bottom: 8,
|
||||
containLabel: true,
|
||||
},
|
||||
} as const;
|
||||
|
||||
/**
|
||||
* Legend 아이템 크기 설정 (GroupedOverlayBar, GroupedStackBar에서 사용)
|
||||
*/
|
||||
export const LEGEND_ITEM_SIZE = {
|
||||
WIDTH: 25,
|
||||
HEIGHT: 14,
|
||||
RADIUS: 4,
|
||||
} as const;
|
||||
|
||||
/**
|
||||
* 테이블 크기 설정
|
||||
*/
|
||||
export const TABLE_DIMENSIONS = {
|
||||
CELL_HEIGHT: {
|
||||
DEFAULT: 26,
|
||||
COMPACT: 20,
|
||||
EXPANDED: 32,
|
||||
},
|
||||
MIN_WIDTH: {
|
||||
STANDARD: 1600,
|
||||
COMPACT: 1200,
|
||||
WIDE: 2000,
|
||||
},
|
||||
} as const;
|
||||
|
||||
import {YEARS} from "@/const/lg-common.const";
|
||||
|
||||
/** 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;
|
||||
export const AXIS_HIDE_Y_STYLE = { min:0, max:100, axisLabel: { show: false }, axisTick: { show: false }, axisLine: { show: false }} as const;
|
||||
|
||||
export const CHART_COLOR_BY_YEAR = Object.fromEntries(
|
||||
YEARS.map((year, i) => [
|
||||
year,
|
||||
`--chart-${YEARS.length-i}-t`,
|
||||
])
|
||||
) as Record<(typeof YEARS)[number], string>;
|
||||
|
||||
export const CHART_FOCUS_COLOR_BY_YEAR = Object.fromEntries(
|
||||
YEARS.map((year, i) => [
|
||||
year,
|
||||
`--chart-${YEARS.length-i}`,
|
||||
])
|
||||
) as Record<(typeof YEARS)[number], string>;
|
||||
@@ -69,13 +69,30 @@ export const buildLgPalette = (varNames?: string[]): string[] => {
|
||||
"--chart-1",
|
||||
"--chart-2",
|
||||
"--chart-3",
|
||||
"--chart-4",
|
||||
"--chart-5",
|
||||
"--chart-6",
|
||||
"--chart-7",
|
||||
"--chart-8",
|
||||
"--chart-9",
|
||||
"--chart-10",
|
||||
];
|
||||
|
||||
return defaults.map((v) => {
|
||||
const hsl = resolveHslVar(v);
|
||||
return hsl ? hslCss(hsl, 1) : v;
|
||||
});
|
||||
};
|
||||
|
||||
export const buildLgStackPalette = (varNames?: string[]): string[] => {
|
||||
// globals.css에 정의된 스케일을 직접 참조(중첩 var(--chart-1) 회피)
|
||||
const defaults = varNames ?? [
|
||||
"--chart-stack-1",
|
||||
"--chart-stack-2",
|
||||
"--chart-stack-3",
|
||||
"--chart-stack-4",
|
||||
"--chart-stack-5",
|
||||
"--chart-stack-6",
|
||||
"--chart-stack-7",
|
||||
"--chart-stack-8",
|
||||
"--chart-stack-9",
|
||||
"--chart-stack-10",
|
||||
"--chart-stack-11",
|
||||
"--chart-stack-12",
|
||||
"--chart-stack-13",
|
||||
];
|
||||
|
||||
return defaults.map((v) => {
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
import {ChartData, DataColumn, DataTable, HorizontalBar, LeftChartTable, SignStyle} from "@/components/lge-dashboard";
|
||||
import {BannerKey, BannerRow} from "@/types/lg";
|
||||
import {BannerKey, BannerRow} from "@/types/lg.types";
|
||||
import {formatRowLabel, isGapRow, wrapSampleRow} from "@/lib/lg-dashboard";
|
||||
import {useEffect, useMemo} from "react";
|
||||
import {
|
||||
BANNER_GROUP,
|
||||
BANNER_KEY_MAP,
|
||||
GRID_Y_NOT_PADDING,
|
||||
SITE_TITLE,
|
||||
} from "@/const/lgConst";
|
||||
import {BANNER_GROUP} from "@/const/lg-banner.const";
|
||||
import {BANNER_KEY_MAP} from "@/const/lg-schema.const";
|
||||
import {SITE_TITLE} from "@/const/lg-common.const";
|
||||
import { GRID_Y_NOT_PADDING } from "@/components/lge-dashboard/chart/chart.config";
|
||||
import {parseNumber} from "@/lib/utils";
|
||||
import {
|
||||
buildHeader_DataColumn,
|
||||
@@ -16,7 +14,7 @@ import {
|
||||
} from "@/lib/lg-export-excel";
|
||||
import {useLayoutFilter} from "@/components/layout/LayoutFilterContext";
|
||||
import {CategoryFilterValue} from "@/components/layout/CategoryFilter";
|
||||
import {CategoryTargetData} from "@/config/filter.types";
|
||||
import {CategoryTargetData} from "@/types/filter.types";
|
||||
import {useDebouncedValue} from "@/hooks/useDebouncedValue";
|
||||
|
||||
|
||||
@@ -81,9 +79,10 @@ type BannerSummaryProps = {
|
||||
data: BannerRow[];
|
||||
useChart: boolean;
|
||||
useYear: boolean;
|
||||
getCellClassName?: (row: BannerRow, column: DataColumn<BannerRow>, rowIndex: number) => string | undefined;
|
||||
};
|
||||
|
||||
const BannerSummary = ({ data, useChart, useYear }: BannerSummaryProps) => {
|
||||
const BannerSummary = ({ data, useChart, useYear, getCellClassName }: BannerSummaryProps) => {
|
||||
const {filterValue, registerExcelExporter } = useLayoutFilter();
|
||||
const debouncedFilterValue = useDebouncedValue<CategoryFilterValue>(filterValue as CategoryFilterValue, 500);
|
||||
|
||||
@@ -181,12 +180,14 @@ const BannerSummary = ({ data, useChart, useYear }: BannerSummaryProps) => {
|
||||
title={sectionRow.specTitle}
|
||||
columns={sectionRow.columns}
|
||||
rows={sectionRow.rows}
|
||||
getCellClassName={getCellClassName}
|
||||
signStyle={signStyleGap}
|
||||
chart={
|
||||
<HorizontalBar
|
||||
data={sectionRow.chartData}
|
||||
height="100%"
|
||||
showFocusLabel="none"
|
||||
showFocusLabel="all"
|
||||
labelOptions={{ position: "insideRight", color: "#fff", distance: 4 }}
|
||||
legend={{ show: false }}
|
||||
grid={GRID_Y_NOT_PADDING}
|
||||
xAxis={{ type: "value", show: false }}
|
||||
@@ -215,4 +216,4 @@ const BannerSummary = ({ data, useChart, useYear }: BannerSummaryProps) => {
|
||||
);
|
||||
}
|
||||
|
||||
export default BannerSummary;
|
||||
export default BannerSummary;
|
||||
|
||||
@@ -6,29 +6,33 @@ import {
|
||||
StackBar
|
||||
} from "@/components/lge-dashboard";
|
||||
import BannerButtons from "@/components/lge-dashboard/BannerButtons";
|
||||
import {totalFilters} from "@/config/filter.data";
|
||||
import {categoryByDataBanner, totalFilters} from "@/const/filter.const";
|
||||
import React, {useMemo, useState} from "react";
|
||||
import {BannerGroupKey, CategoryChartMode, BannerRow} from "@/types/lg";
|
||||
import {BannerGroupKey, CategoryChartMode, BannerRow, LegendOption} from "@/types/lg.types";
|
||||
import {
|
||||
buildRowLabelSeriesChartData,
|
||||
buildYearSeriesChartData, formatRowLabel,
|
||||
isBannerGroupKey, isGapRow,
|
||||
wrapSampleRow
|
||||
} from "@/lib/lg-dashboard";
|
||||
import {BANNER_GROUP, BANNER_KEY_MAP} from "@/const/lgConst";
|
||||
import {BANNER_GROUP} from "@/const/lg-banner.const";
|
||||
import {BANNER_KEY_MAP} from "@/const/lg-schema.const";
|
||||
import {createDefaultGrid, reverseCategories} from "@/lib/chart-options";
|
||||
|
||||
type CategoryByDataProps = {
|
||||
selectedYear: string;
|
||||
title?: string;
|
||||
surveyTitle?: string;
|
||||
chartMode: CategoryChartMode;
|
||||
chartLegend?: LegendOption;
|
||||
chartTopMargin?: number;
|
||||
allTableData: BannerRow[];
|
||||
fillGreaterThan5?: boolean;
|
||||
chartHeight?: number | string;
|
||||
chartWidth?: number;
|
||||
}
|
||||
|
||||
const banners: bannerType[] = totalFilters.map((filter) => {
|
||||
const banners: bannerType[] = categoryByDataBanner.map((filter) => {
|
||||
return {variable: filter.variable, variableName: filter.variableName}
|
||||
})
|
||||
|
||||
@@ -43,7 +47,10 @@ const signStyleGap: SignStyle<BannerRow> = {
|
||||
const CategoryByData = ({
|
||||
selectedYear,
|
||||
title,
|
||||
surveyTitle,
|
||||
chartMode,
|
||||
chartLegend,
|
||||
chartTopMargin,
|
||||
allTableData,
|
||||
fillGreaterThan5,
|
||||
chartHeight,
|
||||
@@ -61,6 +68,14 @@ const CategoryByData = ({
|
||||
cellClassName: "lg-table__rowhead",
|
||||
width: 120,
|
||||
},
|
||||
{
|
||||
key: "total",
|
||||
header: `전체`,
|
||||
headRowSpan: 2,
|
||||
numeric: true,
|
||||
cellClassName: "lg-table__rowhead",
|
||||
width: 120,
|
||||
},
|
||||
];
|
||||
|
||||
const g = BANNER_GROUP[groupKey];
|
||||
@@ -102,6 +117,7 @@ const CategoryByData = ({
|
||||
})
|
||||
, [allTableData, selectedYear]);
|
||||
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="mb-2 flex items-center pr-6">
|
||||
@@ -115,6 +131,8 @@ const CategoryByData = ({
|
||||
return (
|
||||
<HorizontalBar
|
||||
data={chartData}
|
||||
legend={chartLegend}
|
||||
grid={chartTopMargin?createDefaultGrid("default", { top: chartTopMargin }):undefined}
|
||||
height={chartHeight}
|
||||
showFocusLabel="none"
|
||||
paletteVarNames={
|
||||
@@ -127,8 +145,9 @@ const CategoryByData = ({
|
||||
return (
|
||||
<StackBar
|
||||
data={chartData}
|
||||
legend={chartLegend}
|
||||
height={chartHeight}
|
||||
grid={createDefaultGrid("default", { top: 52 })}
|
||||
grid={createDefaultGrid("default", { top: chartTopMargin?chartTopMargin:52 })}
|
||||
isReverse={chartMode === "reverseStack"}
|
||||
/>
|
||||
);
|
||||
@@ -136,7 +155,6 @@ const CategoryByData = ({
|
||||
return null;
|
||||
}
|
||||
})()}
|
||||
|
||||
</div>
|
||||
|
||||
<div className="flex items-center">
|
||||
@@ -157,8 +175,9 @@ const CategoryByData = ({
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex content-text-sm ml-5 mb-5 -mt-3">{surveyTitle}</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default CategoryByData;
|
||||
export default CategoryByData;
|
||||
|
||||
@@ -1,21 +1,15 @@
|
||||
"use client";
|
||||
|
||||
import React, { useMemo } from "react";
|
||||
import { cn, parseNumber } from "@/lib/utils";
|
||||
import type React from "react";
|
||||
import { TABLE_DIMENSIONS } from "@/components/lge-dashboard/chart/chart.config";
|
||||
import { UNIT_TEXT } from "@/const/lg-common.const";
|
||||
import type { DataColumn, SignStyle } from "../types";
|
||||
import SectionTitle from "../SectionTitle";
|
||||
import { TABLE_DIMENSIONS } from "@/const/chartConst";
|
||||
import {isSampleRow} from "@/lib/lg-dashboard";
|
||||
import {SAMPLE_SIZE_NOTICE, UNIT_TEXT} from "@/const/lgConst";
|
||||
import BaseDataTable from "../table/BaseDataTable";
|
||||
|
||||
type MergedChartCell<T> = {
|
||||
/** 차트를 삽입할 컬럼 key(해당 컬럼 td는 startRow에서만 렌더되고 rowSpan 적용) */
|
||||
key: keyof T;
|
||||
/** rowSpan 시작 row index (기본 0) */
|
||||
startRowIndex?: number;
|
||||
/** rowSpan 수 (기본: rows.length - startRowIndex) */
|
||||
rowSpan?: number;
|
||||
/** chart td 클래스 (예: lg-table__sep-r) */
|
||||
className?: string;
|
||||
};
|
||||
|
||||
@@ -23,42 +17,18 @@ type Props<T extends Record<string, unknown>> = {
|
||||
title?: string;
|
||||
columns: DataColumn<T>[];
|
||||
rows: T[];
|
||||
/** 머지된 셀 안에 렌더할 차트 */
|
||||
chart: React.ReactNode;
|
||||
/** 어떤 컬럼을 머지-차트 셀로 교체할지 */
|
||||
chartCell: MergedChartCell<T>;
|
||||
|
||||
/** +/-/0 표기/색상 옵션(선택) */
|
||||
signStyle?: SignStyle<T>;
|
||||
|
||||
wrapperClassName?: string;
|
||||
tableClassName?: string;
|
||||
minWidthPx?: number;
|
||||
minWidth?: number;
|
||||
starUnder30Sample?: boolean;
|
||||
unitText?: string;
|
||||
getCellClassName?: (row: T, column: DataColumn<T>, rowIndex: number) => string | undefined;
|
||||
};
|
||||
|
||||
// toNumber는 utils.ts의 parseNumber로 통합됨
|
||||
|
||||
function renderSigned(
|
||||
n: number,
|
||||
opts: {
|
||||
display: "number" | "arrow";
|
||||
showPlus: boolean;
|
||||
arrowWithNumber: boolean;
|
||||
zeroText: string;
|
||||
}
|
||||
) {
|
||||
if (n === 0) return opts.zeroText;
|
||||
if (opts.display === "arrow") {
|
||||
const arrow = n > 0 ? "▲" : "▼";
|
||||
const num = Math.abs(n);
|
||||
return opts.arrowWithNumber ? `${arrow} ${num}` : arrow;
|
||||
}
|
||||
if (n > 0) return opts.showPlus ? `+${n}` : `${n}`;
|
||||
return `${n}`;
|
||||
}
|
||||
|
||||
export default function LeftChartTable<T extends Record<string, unknown>>({
|
||||
title,
|
||||
columns,
|
||||
@@ -69,206 +39,36 @@ export default function LeftChartTable<T extends Record<string, unknown>>({
|
||||
wrapperClassName,
|
||||
tableClassName,
|
||||
minWidthPx = TABLE_DIMENSIONS.MIN_WIDTH.COMPACT,
|
||||
minWidth,
|
||||
starUnder30Sample = true,
|
||||
unitText = UNIT_TEXT,
|
||||
}: Props<T>) {
|
||||
const hasGroupHeader = useMemo(
|
||||
() => columns.some((c) => c.group) || columns.some((c) => c.headRowSpan === 2),
|
||||
[columns]
|
||||
);
|
||||
|
||||
const groupCells = useMemo(() => {
|
||||
if (!hasGroupHeader) return [] as Array<
|
||||
| { 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 }
|
||||
>;
|
||||
|
||||
type Cell =
|
||||
| { 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 };
|
||||
|
||||
const out: Cell[] = [];
|
||||
let i = 0;
|
||||
while (i < columns.length) {
|
||||
const c = columns[i];
|
||||
if (c.headRowSpan === 2) {
|
||||
out.push({
|
||||
kind: "rowspan",
|
||||
label: c.header,
|
||||
colSpan: 1,
|
||||
rowSpan: 2,
|
||||
className: c.headerClassName,
|
||||
});
|
||||
i += 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
const g = c.group ?? "";
|
||||
if (!g) {
|
||||
out.push({ kind: "blank", label: "", colSpan: 1, rowSpan: 1, className: c.headerClassName });
|
||||
i += 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
let span = 1;
|
||||
while (
|
||||
i + span < columns.length &&
|
||||
(columns[i + span].headRowSpan ?? 1) !== 2 &&
|
||||
(columns[i + span].group ?? "") === g
|
||||
) {
|
||||
span += 1;
|
||||
}
|
||||
|
||||
out.push({ kind: "group", label: g, colSpan: span, rowSpan: 1, className: columns[i + span -1].headerClassName });
|
||||
i += span;
|
||||
}
|
||||
return out;
|
||||
}, [columns, hasGroupHeader]);
|
||||
|
||||
const display = signStyle?.display ?? "number";
|
||||
const arrowWithNumber = signStyle?.arrowWithNumber ?? true;
|
||||
const showPlus = signStyle?.showPlus ?? true;
|
||||
const zeroText = signStyle?.zeroText ?? "-";
|
||||
const posCls = signStyle?.positiveTextClassName ?? "lg-num-pos";
|
||||
const negCls = signStyle?.negativeTextClassName ?? "lg-num-neg";
|
||||
const zeroCls = signStyle?.zeroTextClassName ?? "";
|
||||
|
||||
const start = chartCell.startRowIndex ?? 0;
|
||||
const rowSpan = chartCell.rowSpan ?? Math.max(0, rows.length - start);
|
||||
|
||||
getCellClassName,
|
||||
}: Readonly<Props<T>>) {
|
||||
return (
|
||||
<div className={cn("w-full", wrapperClassName)}>
|
||||
<div className="mb-2 flex items-center justify-between">
|
||||
{ title && <SectionTitle title={title} />}
|
||||
{
|
||||
(unitText || starUnder30Sample) &&
|
||||
<div className="ml-auto text-gray-500 content-text-xs font-semibold text-right">
|
||||
{unitText}
|
||||
{starUnder30Sample && <><br/>{SAMPLE_SIZE_NOTICE}</>}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div className="overflow-x-auto">
|
||||
<table className={cn("lg-table", tableClassName)} style={{ minWidth: `${minWidthPx}px` }}>
|
||||
<thead>
|
||||
{hasGroupHeader ? (
|
||||
<tr className="lg-table__group">
|
||||
{groupCells.map((g, idx) => (
|
||||
<th
|
||||
key={`${g.kind}-${idx}`}
|
||||
className={cn(g.className)}
|
||||
colSpan={g.colSpan}
|
||||
rowSpan={g.rowSpan}
|
||||
>
|
||||
{g.label}
|
||||
</th>
|
||||
))}
|
||||
</tr>
|
||||
) : null}
|
||||
|
||||
<tr className={hasGroupHeader ? "lg-table__subhead" : undefined}>
|
||||
{columns
|
||||
.filter((c) => (c.headRowSpan ?? 1) !== 2)
|
||||
.map((c) => (
|
||||
<th key={String(c.key)} className={cn(c.headerClassName)} style={c.width ? { width: c.width } : undefined}>
|
||||
{c.header}
|
||||
</th>
|
||||
))}
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
{rows.map((row, ri) => {
|
||||
const sampleRow = isSampleRow(row.rowLabel as string ?? "");
|
||||
const isSignRow = signStyle?.rowSelector ? signStyle.rowSelector(row, ri) : false;
|
||||
|
||||
return (
|
||||
<tr key={ri}>
|
||||
{columns.map((c) => {
|
||||
// 머지-차트 셀
|
||||
if (c.key === chartCell.key && ri >= start) {
|
||||
if (ri > start) return null;
|
||||
return (
|
||||
<td
|
||||
key={String(c.key)}
|
||||
rowSpan={rowSpan}
|
||||
className={cn(c.cellClassName, chartCell.className)}
|
||||
style={{ padding: 0, verticalAlign: "middle" }}
|
||||
>
|
||||
{chart}
|
||||
</td>
|
||||
);
|
||||
}
|
||||
|
||||
// 일반 셀
|
||||
const raw = c.key in row ? row[c.key] : undefined;
|
||||
const content = c.render
|
||||
? c.render(row)
|
||||
: raw === null || raw === undefined
|
||||
? ""
|
||||
: typeof raw === "string" || typeof raw === "number"
|
||||
? raw
|
||||
: String(raw);
|
||||
|
||||
const n = c.numeric ? parseNumber(raw) : null;
|
||||
const shouldSign = isSignRow && (signStyle?.keys ? signStyle.keys.includes(c.key) : !!c.numeric);
|
||||
|
||||
if (c.rowHead) {
|
||||
return (
|
||||
<th
|
||||
key={String(c.key)}
|
||||
scope="row"
|
||||
className={cn("lg-table__rowhead", c.cellClassName)}
|
||||
style={c.width ? { width: c.width } : undefined}
|
||||
>
|
||||
{content}
|
||||
</th>
|
||||
);
|
||||
}
|
||||
|
||||
if (!shouldSign) {
|
||||
const numContent = c.numeric ? parseNumber(content) ?? 0 : 0;
|
||||
const isStar = starUnder30Sample && sampleRow && numContent < 30;
|
||||
|
||||
return (
|
||||
<td
|
||||
key={String(c.key)}
|
||||
className={cn(c.cellClassName)}
|
||||
style={c.width ? { width: c.width } : undefined}
|
||||
>
|
||||
{isStar?`${content}*`:content}
|
||||
</td>
|
||||
);
|
||||
}
|
||||
|
||||
// sign row: 값이 없으면 "-" 유지
|
||||
if (n === null) {
|
||||
return (
|
||||
<td key={String(c.key)} className={cn(c.cellClassName)}>
|
||||
-
|
||||
</td>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
const cls = n > 0 ? posCls : n < 0 ? negCls : zeroCls;
|
||||
const txt = renderSigned(n, { display, showPlus, arrowWithNumber, zeroText });
|
||||
|
||||
return (
|
||||
<td key={String(c.key)} className={cn(c.cellClassName, cls)}>
|
||||
{txt}
|
||||
</td>
|
||||
);
|
||||
})}
|
||||
</tr>
|
||||
);
|
||||
})}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<BaseDataTable
|
||||
columns={columns}
|
||||
rows={rows}
|
||||
title={title}
|
||||
wrapperClassName={wrapperClassName}
|
||||
tableClassName={tableClassName}
|
||||
minWidth={minWidth ?? minWidthPx}
|
||||
signStyle={signStyle}
|
||||
signStyleFallback={{
|
||||
positiveTextClassName: "lg-num-pos",
|
||||
negativeTextClassName: "lg-num-neg",
|
||||
zeroTextClassName: "",
|
||||
arrowWithNumber: true,
|
||||
}}
|
||||
starUnder30Sample={starUnder30Sample}
|
||||
unitText={unitText}
|
||||
getCellClassName={getCellClassName}
|
||||
mergedCell={{
|
||||
key: chartCell.key,
|
||||
content: chart,
|
||||
startRowIndex: chartCell.startRowIndex,
|
||||
rowSpan: chartCell.rowSpan,
|
||||
className: chartCell.className,
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import GaugeCardTable from "./GaugeCardTable";
|
||||
import {LIFE_STAGE_COLUMNS, UNIT_TEXT} from "@/const/lgConst";
|
||||
import {LifeStageGroup} from "@/types/lg";
|
||||
import {LIFE_STAGE_COLUMNS} from "@/const/lg-product.const";
|
||||
import {UNIT_TEXT} from "@/const/lg-common.const";
|
||||
import {LifeStageGroup} from "@/types/lg.types";
|
||||
import SectionTitle from "../SectionTitle";
|
||||
import React from "react";
|
||||
|
||||
@@ -48,4 +49,4 @@ const LifeStageDiv = ({lifeStageRowsByGroup}:lifeStageDivProps) => {
|
||||
);
|
||||
}
|
||||
|
||||
export default LifeStageDiv;
|
||||
export default LifeStageDiv;
|
||||
|
||||
@@ -3,171 +3,140 @@
|
||||
import React, { useMemo } from "react";
|
||||
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";
|
||||
import {UNIT_TEXT} from "@/const/lgConst";
|
||||
import {isCagrRow} from "@/lib/lg-dashboard";
|
||||
import { CHART_HEIGHTS, TABLE_DIMENSIONS } from "@/components/lge-dashboard/chart/chart.config";
|
||||
import { UNIT_TEXT } from "@/const/lg-common.const";
|
||||
import {isCagrRow, isSampleRow} from "@/lib/lg-dashboard";
|
||||
import BaseTableHeader from "../table/core/BaseTableHeader";
|
||||
import { formatSignedValue, getSignTextClass, resolveSignStyle, toRoundedNumber } from "../table/core/table-core.helpers";
|
||||
|
||||
export type TopChartTableProps = {
|
||||
title?: string;
|
||||
categories: string[];
|
||||
rows: TopChartTableRow[];
|
||||
/** 테이블 상단(헤더 1행) 콜스팬 셀 내부에 렌더될 차트 */
|
||||
chart?:
|
||||
| React.ReactNode
|
||||
| ((ctx: {
|
||||
/** 테이블 컬럼(=x축) 기준으로 구성된 ChartData */
|
||||
chartData: ChartData;
|
||||
}) => React.ReactNode);
|
||||
/** chart 셀 높이(px) */
|
||||
chartHeight?: number;
|
||||
/** 가로 스크롤 min-width */
|
||||
| React.ReactNode
|
||||
| ((ctx: {
|
||||
chartData: ChartData;
|
||||
}) => React.ReactNode);
|
||||
chartHeight?: number | string;
|
||||
minWidthPx?: number;
|
||||
minWidth?: number;
|
||||
tableClassName?: string;
|
||||
wrapperClassName?: string;
|
||||
/** +/-/0 색상/표기 옵션(선택) */
|
||||
signStyle?: SignStyle<TopChartTableRow>;
|
||||
fillCAGR?: boolean;
|
||||
unitText?: string;
|
||||
};
|
||||
// toNumber는 utils.ts의 parseNumber로 통합됨
|
||||
|
||||
function formatSignedNumber(n: number, zeroText: string, showPlus: boolean) {
|
||||
if (n === 0) return zeroText;
|
||||
if (n > 0) return showPlus ? `+${n}` : `${n}`;
|
||||
return `${n}`;
|
||||
}
|
||||
export default function TopChartTable({
|
||||
title,
|
||||
rows,
|
||||
categories,
|
||||
chart,
|
||||
chartHeight = CHART_HEIGHTS.DEFAULT,
|
||||
minWidthPx = TABLE_DIMENSIONS.MIN_WIDTH.STANDARD,
|
||||
minWidth,
|
||||
tableClassName,
|
||||
wrapperClassName,
|
||||
signStyle,
|
||||
fillCAGR = false,
|
||||
unitText = UNIT_TEXT,
|
||||
}: Readonly<TopChartTableProps>) {
|
||||
const resolvedSignStyle = resolveSignStyle(signStyle, {
|
||||
positiveTextClassName: "lg-num-pos",
|
||||
negativeTextClassName: "lg-num-neg",
|
||||
zeroTextClassName: "",
|
||||
arrowWithNumber: true,
|
||||
});
|
||||
|
||||
type CellValue = TopChartTableRow["values"][number];
|
||||
function toCellValue(v: unknown): CellValue {
|
||||
if (v === null || v === undefined) return v;
|
||||
if (typeof v === "number" || typeof v === "string") return v;
|
||||
return String(v);
|
||||
}
|
||||
|
||||
export default function TopChartTable(props: TopChartTableProps) {
|
||||
const {
|
||||
title,
|
||||
rows,
|
||||
categories,
|
||||
chart,
|
||||
chartHeight = CHART_HEIGHTS.DEFAULT,
|
||||
minWidthPx = TABLE_DIMENSIONS.MIN_WIDTH.STANDARD,
|
||||
tableClassName,
|
||||
wrapperClassName,
|
||||
signStyle,
|
||||
fillCAGR = false,
|
||||
unitText = UNIT_TEXT
|
||||
} = props;
|
||||
|
||||
const display = signStyle?.display ?? "number";
|
||||
const arrowWithNumber = signStyle?.arrowWithNumber ?? true;
|
||||
const showPlus = signStyle?.showPlus ?? true;
|
||||
const posCls = signStyle?.positiveTextClassName ?? "lg-num-pos";
|
||||
const negCls = signStyle?.negativeTextClassName ?? "lg-num-neg";
|
||||
const zeroText = signStyle?.zeroText ?? "-";
|
||||
|
||||
// 테이블 컬럼(=categories)을 x축으로 사용하는 chartData를 항상 제공
|
||||
const chartData: ChartData = useMemo(
|
||||
() => ({
|
||||
categories,
|
||||
series: rows.map((r) => ({
|
||||
name: r.label,
|
||||
data: r.values.map((v) => parseNumber(v) ?? null),
|
||||
})),
|
||||
}),
|
||||
[categories, rows]
|
||||
() => ({
|
||||
categories,
|
||||
series: rows.map((row) => ({
|
||||
name: row.label,
|
||||
data: row.values.map((value) => parseNumber(value) ?? null),
|
||||
})),
|
||||
}),
|
||||
[categories, rows]
|
||||
);
|
||||
|
||||
const chartNode = useMemo(() => {
|
||||
if (!chart) return null;
|
||||
if (!chart) {
|
||||
return null;
|
||||
}
|
||||
return typeof chart === "function" ? chart({ chartData }) : chart;
|
||||
}, [chart, chartData, categories, rows]);
|
||||
}, [chart, chartData]);
|
||||
|
||||
return (
|
||||
<div className={cn("w-full", wrapperClassName)}>
|
||||
<div className="mb-2 flex items-center justify-between">
|
||||
{title ? <SectionTitle title={title} /> : <div />}
|
||||
{unitText ? <div className="text-gray-500 text-xs font-semibold">{unitText}</div> : null}
|
||||
</div>
|
||||
<div className={cn("w-full", wrapperClassName)}>
|
||||
<BaseTableHeader title={title} unitText={unitText} />
|
||||
|
||||
<div className="overflow-x-auto">
|
||||
<table
|
||||
className={cn("lg-table", tableClassName)}
|
||||
style={{ minWidth: `${minWidthPx}px` }}
|
||||
>
|
||||
<thead>
|
||||
<div className="overflow-x-auto">
|
||||
<table className={cn("lg-table", tableClassName)} style={{ minWidth: `${minWidth ?? minWidthPx}px` }}>
|
||||
<thead>
|
||||
<tr>
|
||||
{/* 좌상단: rowhead 헤더(필요 시 표시). HTML과 동일하게 2행 rowspan */}
|
||||
<th rowSpan={2} className="lg-table__sep-r w-31" style={{ whiteSpace: "nowrap" }}>
|
||||
|
||||
</th>
|
||||
<th rowSpan={2} className="lg-table__sep-r w-31" style={{ whiteSpace: "nowrap" }} />
|
||||
<td colSpan={categories.length} style={{ padding: 0, height: chartNode ? chartHeight : 0 }}>
|
||||
{chartNode ? <div style={{ width: "100%", height: "100%" }}>{chartNode}</div> : null}
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr className="lg-table__subhead">
|
||||
{categories.map((c) => (
|
||||
<th key={c} className={"content-text-xs"}>{c}</th>
|
||||
{categories.map((category) => (
|
||||
<th key={category} className="content-text-xs">
|
||||
{category}
|
||||
</th>
|
||||
))}
|
||||
</tr>
|
||||
</thead>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
{rows.map((r, ri) => {
|
||||
const isSignRow = !!(signStyle?.rowSelector && signStyle.rowSelector(r, ri));
|
||||
const cagrRow = isCagrRow(r.label as string ?? "");
|
||||
const total = parseNumber(r.total);
|
||||
<tbody>
|
||||
{rows.map((row, rowIndex) => {
|
||||
const signRow = !!signStyle?.rowSelector?.(row, rowIndex);
|
||||
const sampleRow = isSampleRow(row.label ?? "");
|
||||
const cagrRow = isCagrRow(row.label ?? "");
|
||||
const rowTotal = parseNumber(row.total);
|
||||
|
||||
return (
|
||||
<tr key={`${r.label}-${ri}`}>
|
||||
<th scope="row" className="lg-table__rowhead lg-table__sep-r content-text-sm">
|
||||
{r.label}
|
||||
</th>
|
||||
<tr key={`${row.label}-${rowIndex}`}>
|
||||
<th scope="row" className="lg-table__rowhead lg-table__sep-r content-text-sm">
|
||||
{row.label}
|
||||
</th>
|
||||
|
||||
{categories.map((_, ci) => {
|
||||
const raw = r.values?.[ci];
|
||||
const n = parseNumber(raw);
|
||||
{categories.map((_, categoryIndex) => {
|
||||
const rawValue = row.values?.[categoryIndex];
|
||||
|
||||
// 일반 행
|
||||
if (!isSignRow) {
|
||||
if (n === null) return <td key={ci}>-</td>;
|
||||
if(sampleRow){
|
||||
return <td key={categoryIndex}>{rawValue}</td>;
|
||||
}
|
||||
|
||||
const isFill = fillCAGR && cagrRow && total && n > total + 5;
|
||||
const txt = n.toLocaleString();
|
||||
return <td key={ci} className={cn(isFill? "bg-red-200" :"")}>{txt}</td>;
|
||||
const roundedValue = toRoundedNumber(rawValue, cagrRow? 1 : 0);
|
||||
|
||||
if (!signRow) {
|
||||
if (roundedValue === null) {
|
||||
return <td key={categoryIndex}>-</td>;
|
||||
}
|
||||
|
||||
// sign row
|
||||
if (n === null) return <td key={ci}>-</td>;
|
||||
if (n === 0) return <td key={ci}>{zeroText}</td>;
|
||||
const shouldFillCell = fillCAGR && cagrRow && rowTotal !== null && roundedValue > rowTotal + 5;
|
||||
return <td key={categoryIndex} className={cn(shouldFillCell ? "bg-red-200" : "")}>{roundedValue.toLocaleString()}</td>;
|
||||
}
|
||||
|
||||
const cls = n > 0 ? posCls : negCls;
|
||||
if (roundedValue === null) {
|
||||
return <td key={categoryIndex}>-</td>;
|
||||
}
|
||||
|
||||
if (display === "arrow") {
|
||||
const arrow = n > 0 ? "▲" : "▼";
|
||||
const num = Math.abs(n);
|
||||
return (
|
||||
<td key={ci} className={cls}>
|
||||
{arrow}
|
||||
{arrowWithNumber ? ` ${num}` : ""}
|
||||
</td>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<td key={ci} className={cls}>
|
||||
{formatSignedNumber(n, zeroText, showPlus)}
|
||||
</td>
|
||||
);
|
||||
})}
|
||||
</tr>
|
||||
return (
|
||||
<td key={categoryIndex} className={getSignTextClass(roundedValue, resolvedSignStyle)}>
|
||||
{formatSignedValue(roundedValue, resolvedSignStyle)}
|
||||
</td>
|
||||
);
|
||||
})}
|
||||
</tr>
|
||||
);
|
||||
})}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
'use client'
|
||||
|
||||
import BannerSummary from "@/components/lge-dashboard/combo/BannerSummary";
|
||||
import {useMemo} from "react";
|
||||
import {BannerRow} from "@/types/lg";
|
||||
import {CategoryPageProps} from "@/components/lge-dashboard/sub-page/CategoryPage";
|
||||
import {LAST_YEAR} from "@/const/lgConst";
|
||||
|
||||
const PenetrationChange = ({
|
||||
dataMap
|
||||
}:CategoryPageProps) => {
|
||||
|
||||
const penetrationChangeData = useMemo<BannerRow[]>(() => {
|
||||
if (dataMap === undefined) return [];
|
||||
|
||||
const tempProfileData: BannerRow[] = [];
|
||||
Object.keys(dataMap).forEach(requestKey => {
|
||||
const data = dataMap[requestKey];
|
||||
tempProfileData.push(
|
||||
...data.filter((r) => r.rowLabel === `사례수` && r.year === LAST_YEAR),
|
||||
...data.filter((r) => r.rowLabel === `보유`)
|
||||
.map((row) => {
|
||||
return {
|
||||
...row,
|
||||
rowLabel: row.year,
|
||||
}
|
||||
}));
|
||||
});
|
||||
|
||||
console.log(tempProfileData)
|
||||
|
||||
return tempProfileData;
|
||||
}, [dataMap]);
|
||||
|
||||
return(
|
||||
<BannerSummary data={penetrationChangeData} useChart={true} useYear={false} />
|
||||
);
|
||||
}
|
||||
|
||||
export default PenetrationChange
|
||||
159
src/components/lge-dashboard/table/BaseDataTable.tsx
Normal file
159
src/components/lge-dashboard/table/BaseDataTable.tsx
Normal file
@@ -0,0 +1,159 @@
|
||||
"use client";
|
||||
|
||||
import type React from "react";
|
||||
import { cn, parseNumber } from "@/lib/utils";
|
||||
import { isSampleRow } from "@/lib/lg-dashboard";
|
||||
import type { DataColumn, SignStyle } from "../types";
|
||||
import BaseTableRenderer from "./core/BaseTableRenderer";
|
||||
import {
|
||||
appendCellMarker,
|
||||
formatSignedValue,
|
||||
getColumnAlign,
|
||||
getSignCellBackground,
|
||||
getSignTextClass,
|
||||
resolveSignStyle,
|
||||
shouldApplySignToColumn,
|
||||
toRoundedNumber,
|
||||
toTableCellContent,
|
||||
type ResolvedSignStyle,
|
||||
} from "./core/table-core.helpers";
|
||||
|
||||
export type MergedTableCell<T> = {
|
||||
key: keyof T;
|
||||
content: React.ReactNode;
|
||||
startRowIndex?: number;
|
||||
rowSpan?: number;
|
||||
className?: string;
|
||||
};
|
||||
|
||||
type Props<T extends Record<string, unknown>> = {
|
||||
columns: DataColumn<T>[];
|
||||
rows: T[];
|
||||
title?: string;
|
||||
wrapperClassName?: string;
|
||||
tableClassName?: string;
|
||||
subheadRowClassName?: string;
|
||||
minWidth?: number;
|
||||
signStyle?: SignStyle<T>;
|
||||
signStyleFallback?: Partial<ResolvedSignStyle>;
|
||||
fillGreaterThan5?: boolean;
|
||||
starUnder30Sample?: boolean;
|
||||
unitText?: string;
|
||||
mergedCell?: MergedTableCell<T>;
|
||||
getCellClassName?: (row: T, column: DataColumn<T>, rowIndex: number) => string | undefined;
|
||||
};
|
||||
|
||||
export default function BaseDataTable<T extends Record<string, unknown>>({
|
||||
columns,
|
||||
rows,
|
||||
title,
|
||||
wrapperClassName,
|
||||
tableClassName,
|
||||
subheadRowClassName,
|
||||
minWidth,
|
||||
signStyle,
|
||||
signStyleFallback,
|
||||
fillGreaterThan5 = false,
|
||||
starUnder30Sample = false,
|
||||
unitText,
|
||||
mergedCell,
|
||||
getCellClassName,
|
||||
}: Readonly<Props<T>>) {
|
||||
const resolvedSignStyle = resolveSignStyle(signStyle, signStyleFallback);
|
||||
const mergedCellStart = mergedCell?.startRowIndex ?? 0;
|
||||
const mergedCellSpan = mergedCell?.rowSpan ?? Math.max(0, rows.length - mergedCellStart);
|
||||
|
||||
return (
|
||||
<BaseTableRenderer
|
||||
columns={columns}
|
||||
title={title}
|
||||
unitText={unitText}
|
||||
showSampleNotice={starUnder30Sample}
|
||||
wrapperClassName={wrapperClassName}
|
||||
tableClassName={tableClassName}
|
||||
subheadRowClassName={subheadRowClassName}
|
||||
minWidth={minWidth}
|
||||
>
|
||||
{rows.map((row, rowIndex) => {
|
||||
const sampleRow = isSampleRow((row.rowLabel as string) ?? "");
|
||||
const signRow = !!signStyle?.rowSelector?.(row, rowIndex);
|
||||
const rowTotal = parseNumber(row.total);
|
||||
|
||||
return (
|
||||
<tr key={rowIndex}>
|
||||
{columns.map((column) => {
|
||||
const dynamicCellClassName = getCellClassName?.(row, column, rowIndex);
|
||||
|
||||
if (mergedCell && column.key === mergedCell.key && rowIndex >= mergedCellStart) {
|
||||
if (rowIndex > mergedCellStart) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<td
|
||||
key={String(column.key)}
|
||||
rowSpan={mergedCellSpan}
|
||||
className={cn(column.cellClassName, mergedCell.className)}
|
||||
style={{ padding: 0, verticalAlign: "middle" }}
|
||||
>
|
||||
{mergedCell.content}
|
||||
</td>
|
||||
);
|
||||
}
|
||||
|
||||
const rawValue = row[column.key];
|
||||
const align = getColumnAlign(column);
|
||||
const defaultContent = column.render ? column.render(row) : toTableCellContent(rawValue);
|
||||
const numericValue = column.numeric ? parseNumber(rawValue ?? defaultContent) ?? 0 : 0;
|
||||
const applySign = signRow && shouldApplySignToColumn(column, signStyle);
|
||||
|
||||
if (column.rowHead) {
|
||||
return (
|
||||
<th
|
||||
key={String(column.key)}
|
||||
scope="row"
|
||||
className={cn("lg-table__rowhead", column.cellClassName, dynamicCellClassName)}
|
||||
style={{ textAlign: align }}
|
||||
>
|
||||
{defaultContent}
|
||||
</th>
|
||||
);
|
||||
}
|
||||
|
||||
if (applySign) {
|
||||
const roundedValue = toRoundedNumber(rawValue);
|
||||
const displayText = roundedValue === null ? "-" : formatSignedValue(roundedValue, resolvedSignStyle);
|
||||
const cellStyle: React.CSSProperties =
|
||||
resolvedSignStyle.paint === "cell"
|
||||
? { textAlign: align, background: getSignCellBackground(roundedValue ?? 0, resolvedSignStyle) }
|
||||
: { textAlign: align };
|
||||
|
||||
return (
|
||||
<td key={String(column.key)} className={cn(column.cellClassName, dynamicCellClassName)} style={cellStyle}>
|
||||
<span className={cn(roundedValue === null ? "text-gray-500" : getSignTextClass(roundedValue, resolvedSignStyle))}>
|
||||
{displayText}
|
||||
</span>
|
||||
</td>
|
||||
);
|
||||
}
|
||||
|
||||
const shouldFillCell = fillGreaterThan5 && rowTotal !== null && numericValue > rowTotal + 5;
|
||||
const shouldMarkSample = starUnder30Sample && sampleRow && numericValue < 30;
|
||||
const displayContent = shouldMarkSample ? appendCellMarker(defaultContent, "*") : defaultContent;
|
||||
|
||||
return (
|
||||
<td
|
||||
key={String(column.key)}
|
||||
className={cn(column.cellClassName, dynamicCellClassName, shouldFillCell ? "bg-red-200" : "")}
|
||||
style={{ textAlign: align }}
|
||||
>
|
||||
{displayContent}
|
||||
</td>
|
||||
);
|
||||
})}
|
||||
</tr>
|
||||
);
|
||||
})}
|
||||
</BaseTableRenderer>
|
||||
);
|
||||
}
|
||||
@@ -1,267 +1,50 @@
|
||||
"use client";
|
||||
|
||||
import { useMemo } from "react";
|
||||
import type React from "react";
|
||||
import { cn, parseNumber } from "@/lib/utils";
|
||||
import type { DataColumn, SignDisplayMode, SignStyle } from "../types";
|
||||
import SectionTitle from "../SectionTitle";
|
||||
import {isCagrRow, isSampleRow} from "@/lib/lg-dashboard";
|
||||
import {SAMPLE_SIZE_NOTICE, UNIT_TEXT} from "@/const/lgConst";
|
||||
import type { DataColumn, SignStyle } from "../types";
|
||||
import { UNIT_TEXT } from "@/const/lg-common.const";
|
||||
import BaseDataTable from "./BaseDataTable";
|
||||
|
||||
type Props<T extends Record<string, unknown>> = {
|
||||
columns: DataColumn<T>[];
|
||||
rows: T[];
|
||||
title?: string;
|
||||
className?: string;
|
||||
tableClassName?: string;
|
||||
wrapperClassName?: string;
|
||||
subheadRowClassName?: string;
|
||||
signStyle?: SignStyle<T>;
|
||||
fillGreaterThan5?: boolean;
|
||||
fillCAGR?: boolean;
|
||||
starUnder30Sample?: boolean;
|
||||
unitText?: string;
|
||||
};
|
||||
|
||||
// parseSignedNumber는 utils.ts의 parseNumber로 통합됨
|
||||
|
||||
const defaultFmt = (v: number) =>
|
||||
Number.isInteger(v) ? String(v) : v.toLocaleString();
|
||||
|
||||
const signText = (
|
||||
v: number,
|
||||
display: SignDisplayMode,
|
||||
showPlus: boolean,
|
||||
arrowWithNumber: boolean,
|
||||
fmt: (n: number) => string,
|
||||
zeroText: string
|
||||
) => {
|
||||
if (display === "arrow") {
|
||||
if (v > 0) return arrowWithNumber ? `▲ ${fmt(Math.abs(v))}` : "▲";
|
||||
if (v < 0) return arrowWithNumber ? `▼ ${fmt(Math.abs(v))}` : "▼";
|
||||
return zeroText;
|
||||
}
|
||||
|
||||
// number
|
||||
if (v > 0) return showPlus ? `+${fmt(v)}` : fmt(v);
|
||||
if (v < 0) return fmt(v); // 음수는 기본적으로 - 포함
|
||||
return zeroText;
|
||||
};
|
||||
|
||||
const toCellContent = (raw: unknown): React.ReactNode => {
|
||||
if (raw == null) return "";
|
||||
if (typeof raw === "string" || typeof raw === "number") return raw;
|
||||
return String(raw);
|
||||
};
|
||||
|
||||
const DataTable = <T extends Record<string, unknown>>({
|
||||
columns,
|
||||
rows,
|
||||
title,
|
||||
className,
|
||||
wrapperClassName,
|
||||
signStyle,
|
||||
fillGreaterThan5 = false,
|
||||
fillCAGR = false,
|
||||
starUnder30Sample = false,
|
||||
unitText = UNIT_TEXT,
|
||||
}: 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 };
|
||||
|
||||
if (!hasGroup) return [] as GroupCell[];
|
||||
|
||||
const res: GroupCell[] = [];
|
||||
let i = 0;
|
||||
|
||||
while (i < columns.length) {
|
||||
const c = columns[i];
|
||||
|
||||
if (c.headRowSpan === 2) {
|
||||
res.push({ kind: "rowspan", label: c.header, colSpan: 1, rowSpan: 2, className: c.headerClassName });
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
|
||||
const g = c.group;
|
||||
if (!g) {
|
||||
// group 미지정: 1칸짜리 blank group 셀
|
||||
res.push({ kind: "blank", label: "", colSpan: 1, rowSpan: 1, className: c.headerClassName });
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
|
||||
// 같은 group 연속 구간 colSpan
|
||||
let span = 1;
|
||||
let j = i + 1;
|
||||
while (j < columns.length && columns[j].headRowSpan !== 2 && columns[j].group === g) {
|
||||
span++;
|
||||
j++;
|
||||
}
|
||||
res.push({ kind: "group", label: g, colSpan: span, rowSpan: 1, className: c.headerClassName });
|
||||
i = j;
|
||||
}
|
||||
|
||||
return res;
|
||||
}, [columns, hasGroup]);
|
||||
|
||||
const {
|
||||
rowSelector,
|
||||
keys,
|
||||
paint = "text",
|
||||
display = "number",
|
||||
showPlus = true,
|
||||
arrowWithNumber = false,
|
||||
zeroText = "-",
|
||||
valueFormatter,
|
||||
positiveTextClassName = "text-primary font-semibold",
|
||||
negativeTextClassName = "text-info font-semibold",
|
||||
zeroTextClassName = "text-gray-600",
|
||||
positiveCellBg = "hsl(var(--primary) / 0.08)",
|
||||
negativeCellBg = "hsl(var(--info) / 0.08)",
|
||||
zeroCellBg = "hsl(var(--lg-gray-200) / 0.6)",
|
||||
} = signStyle ?? ({} as SignStyle<T>);
|
||||
|
||||
const fmt = valueFormatter ?? defaultFmt;
|
||||
|
||||
const isSignRow = (row: T, rowIndex: number) =>
|
||||
!!signStyle && !!rowSelector?.(row, rowIndex);
|
||||
|
||||
const isTargetKey = (k: keyof T) => {
|
||||
if (!signStyle) return false;
|
||||
if (keys && keys.length) return keys.includes(k);
|
||||
// keys 미지정이면 numeric 컬럼 전체
|
||||
const col = columns.find((c) => c.key === k);
|
||||
return !!col?.numeric;
|
||||
};
|
||||
|
||||
const signClass = (v: number) => {
|
||||
if (v > 0) return positiveTextClassName;
|
||||
if (v < 0) return negativeTextClassName;
|
||||
return zeroTextClassName;
|
||||
};
|
||||
|
||||
const signBg = (v: number) => {
|
||||
if (v > 0) return positiveCellBg;
|
||||
if (v < 0) return negativeCellBg;
|
||||
return zeroCellBg;
|
||||
};
|
||||
|
||||
columns,
|
||||
rows,
|
||||
title,
|
||||
className,
|
||||
tableClassName,
|
||||
wrapperClassName,
|
||||
subheadRowClassName,
|
||||
signStyle,
|
||||
fillGreaterThan5 = false,
|
||||
starUnder30Sample = false,
|
||||
unitText = UNIT_TEXT,
|
||||
}: Props<T>) => {
|
||||
return (
|
||||
<div className={cn("w-full overflow-x-auto", wrapperClassName)}>
|
||||
<div className="mb-2 flex items-center justify-between">
|
||||
{ title && <SectionTitle title={title} />}
|
||||
{
|
||||
(unitText || starUnder30Sample) &&
|
||||
<div className="ml-auto text-gray-500 content-text-xs font-semibold text-right">
|
||||
{unitText}
|
||||
{starUnder30Sample && <><br/>{SAMPLE_SIZE_NOTICE}</>}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
<table className={cn("lg-table", className)}>
|
||||
<thead>
|
||||
{hasGroup && (
|
||||
<tr className="lg-table__group">
|
||||
{groupCells.map((g, idx) => (
|
||||
<th
|
||||
key={`${g.kind}-${g.label}-${idx}`}
|
||||
colSpan={g.colSpan}
|
||||
rowSpan={g.rowSpan}
|
||||
className={g.className}
|
||||
>
|
||||
{g.label}
|
||||
</th>
|
||||
))}
|
||||
</tr>
|
||||
)}
|
||||
<tr className={hasGroup ? "lg-table__subhead" : undefined}>
|
||||
{columns
|
||||
.filter((c) => c.headRowSpan !== 2)
|
||||
.map((c) => (
|
||||
<th key={String(c.key)} style={{ width: c.width }} className={c.headerClassName}>
|
||||
{c.header}
|
||||
</th>
|
||||
))}
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
{rows.map((row, rIdx) => {
|
||||
const sampleRow = isSampleRow(row.rowLabel as string ?? "");
|
||||
const signRow = isSignRow(row, rIdx);
|
||||
const total = parseNumber(row.total);
|
||||
|
||||
return (
|
||||
<tr key={rIdx}>
|
||||
{columns.map((c) => {
|
||||
const raw: unknown = c.key ? (row[c.key] as unknown) : undefined;
|
||||
const align = c.align ?? (c.numeric ? "right" : "center");
|
||||
|
||||
// headRowSpan=2 컬럼은 thead 2행에서 제외되므로, tbody는 항상 렌더
|
||||
|
||||
// sign row + target column이면 색상/표기 적용
|
||||
const applySign = signRow && isTargetKey(c.key) && !c.rowHead;
|
||||
|
||||
if (applySign) {
|
||||
const n = parseNumber(raw);
|
||||
const displayText =
|
||||
n === null ? "-" : signText(n, display, showPlus, arrowWithNumber, fmt, zeroText);
|
||||
|
||||
const style: React.CSSProperties =
|
||||
paint === "cell"
|
||||
? { textAlign: align, background: signBg(n ?? 0) }
|
||||
: { textAlign: align };
|
||||
|
||||
return (
|
||||
<td key={String(c.key)} style={style} className={c.cellClassName}>
|
||||
<span className={cn(n === null ? "text-gray-500" : signClass(n))}>
|
||||
{displayText}
|
||||
</span>
|
||||
</td>
|
||||
);
|
||||
}
|
||||
|
||||
// 일반 셀
|
||||
const content: React.ReactNode = c.render
|
||||
? c.render(row)
|
||||
: toCellContent(raw);
|
||||
|
||||
if (c.rowHead) {
|
||||
return (
|
||||
<th
|
||||
key={String(c.key)}
|
||||
className={cn("lg-table__rowhead", c.cellClassName)}
|
||||
style={{ textAlign: align }}
|
||||
>
|
||||
{content}
|
||||
</th>
|
||||
);
|
||||
}
|
||||
|
||||
const numContent = c.numeric ? parseNumber(content) ?? 0 : 0;
|
||||
const isFill = fillGreaterThan5 && total && numContent > total + 5;
|
||||
const isStar = starUnder30Sample && sampleRow && numContent < 30;
|
||||
|
||||
return (
|
||||
<td key={String(c.key)} style={{ textAlign: align }} className={
|
||||
cn(c.cellClassName, isFill? "bg-red-200" :"")
|
||||
}>
|
||||
{isStar?`${content}*`:content}
|
||||
</td>
|
||||
);
|
||||
})}
|
||||
</tr>
|
||||
);
|
||||
})}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<BaseDataTable
|
||||
columns={columns}
|
||||
rows={rows}
|
||||
title={title}
|
||||
tableClassName={tableClassName ?? className}
|
||||
wrapperClassName={wrapperClassName}
|
||||
subheadRowClassName={subheadRowClassName}
|
||||
signStyle={signStyle}
|
||||
fillGreaterThan5={fillGreaterThan5}
|
||||
starUnder30Sample={starUnder30Sample}
|
||||
unitText={unitText}
|
||||
/>
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
export default DataTable;
|
||||
export default DataTable;
|
||||
|
||||
@@ -1,204 +1,113 @@
|
||||
"use client";
|
||||
|
||||
import React, { useMemo } from "react";
|
||||
import { cn, parseNumber } from "@/lib/utils";
|
||||
import {GaugeColumn} from "../types";
|
||||
import { roundNumber } from "@/lib/lg-dashboard";
|
||||
import type { GaugeColumn } from "../types";
|
||||
import BaseTableRenderer from "./core/BaseTableRenderer";
|
||||
import { getColumnAlign, toTableCellContent } from "./core/table-core.helpers";
|
||||
|
||||
type Props<T extends Record<string, unknown>> = {
|
||||
columns: GaugeColumn<T>[];
|
||||
rows: T[];
|
||||
className?: string;
|
||||
tableClassName?: string;
|
||||
wrapperClassName?: string;
|
||||
|
||||
/** value가 0~100이 아니라 0~1이면 scale=100 */
|
||||
scale?: number; // 기본 1
|
||||
|
||||
/** 색상(기본: primary 채움 + gray 트랙) */
|
||||
fillColor?: string; // ex) "hsl(var(--primary) / 0.9)"
|
||||
trackColor?: string; // ex) "hsl(var(--lg-gray-200) / 0.9)"
|
||||
|
||||
/** 셀 높이 */
|
||||
cellHeight?: number; // 기본 26
|
||||
|
||||
/** 숫자 표시 여부/포맷 */
|
||||
valueFormatter?: (v: number) => string;
|
||||
scale?: number;
|
||||
fillColor?: string;
|
||||
trackColor?: string;
|
||||
cellHeight?: number;
|
||||
valueFormatter?: (value: number) => string;
|
||||
};
|
||||
|
||||
// num은 utils.ts의 parseNumber로 통합됨
|
||||
|
||||
const GaugeTable = <T extends Record<string, unknown>>({
|
||||
columns,
|
||||
rows,
|
||||
className,
|
||||
wrapperClassName,
|
||||
scale = 1,
|
||||
fillColor = "hsl(var(--lg-gray-200) / 0.85)",
|
||||
trackColor = "hsl(var(--lg-pink-300) / 0.2)",
|
||||
cellHeight = 26,
|
||||
valueFormatter,
|
||||
}: Props<T>) => {
|
||||
const hasGroup = columns.some((c) => !!c.group) || columns.some((c) => c.headRowSpan === 2);
|
||||
|
||||
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 };
|
||||
|
||||
if (!hasGroup) return [] as GroupCell[];
|
||||
|
||||
const res: GroupCell[] = [];
|
||||
let i = 0;
|
||||
|
||||
while (i < columns.length) {
|
||||
const c = columns[i];
|
||||
|
||||
if (c.headRowSpan === 2) {
|
||||
res.push({ kind: "rowspan", label: c.header, colSpan: 1, rowSpan: 2 });
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
|
||||
const g = c.group;
|
||||
if (!g) {
|
||||
// group 미지정: 1칸짜리 blank group 셀
|
||||
res.push({ kind: "blank", label: "", colSpan: 1, rowSpan: 1 });
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
|
||||
// 같은 group 연속 구간 colSpan
|
||||
let span = 1;
|
||||
let j = i + 1;
|
||||
while (j < columns.length && columns[j].headRowSpan !== 2 && columns[j].group === g) {
|
||||
span++;
|
||||
j++;
|
||||
}
|
||||
res.push({ kind: "group", label: g, colSpan: span, rowSpan: 1 });
|
||||
i = j;
|
||||
}
|
||||
|
||||
return res;
|
||||
}, [columns, hasGroup]);
|
||||
|
||||
const fmt = valueFormatter ?? ((v: number) => String(Math.round(v)));
|
||||
|
||||
const clamp01 = (n: number) => Math.max(0, Math.min(1, n));
|
||||
columns,
|
||||
rows,
|
||||
className,
|
||||
tableClassName,
|
||||
wrapperClassName,
|
||||
scale = 1,
|
||||
fillColor = "hsl(var(--lg-gray-200) / 0.85)",
|
||||
trackColor = "hsl(var(--lg-pink-300) / 0.2)",
|
||||
cellHeight = 26,
|
||||
valueFormatter,
|
||||
}: Props<T>) => {
|
||||
const formatValue = valueFormatter ?? ((value: number) => String(roundNumber(value)));
|
||||
const clampRatio = (value: number) => Math.max(0, Math.min(1, value));
|
||||
|
||||
return (
|
||||
<div className={cn("w-full overflow-x-auto", wrapperClassName)}>
|
||||
<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>
|
||||
{hasGroup && (
|
||||
<tr className="lg-table__group">
|
||||
{groupCells.map((g, idx) => (
|
||||
<th
|
||||
key={`${g.kind}-${g.label}-${idx}`}
|
||||
colSpan={g.colSpan}
|
||||
rowSpan={g.rowSpan}
|
||||
className={g.className}
|
||||
>
|
||||
{g.label}
|
||||
</th>
|
||||
))}
|
||||
</tr>
|
||||
)}
|
||||
<tr className={hasGroup ? "lg-table__subhead" : undefined}>
|
||||
{columns.filter((c) => c.headRowSpan !== 2).map((c) => (
|
||||
<th key={String(c.key)}>
|
||||
{c.header}
|
||||
</th>
|
||||
))}
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
{rows.map((row, rIdx) => (
|
||||
<tr key={rIdx}>
|
||||
{columns.map((c) => {
|
||||
const align = c.align ?? (c.rowHead ? "left" : "center");
|
||||
const cellType = c.cellType ?? "gauge";
|
||||
|
||||
if (c.rowHead) {
|
||||
const raw = row[c.key];
|
||||
const label = c.render
|
||||
? c.render(row)
|
||||
: raw === null || raw === undefined
|
||||
? ""
|
||||
: typeof raw === "string" || typeof raw === "number"
|
||||
? raw
|
||||
: String(raw);
|
||||
return (
|
||||
<th
|
||||
key={String(c.key)}
|
||||
className="lg-table__rowhead"
|
||||
style={{ textAlign: align }}
|
||||
>
|
||||
{label}
|
||||
</th>
|
||||
);
|
||||
}
|
||||
|
||||
const raw = row[c.key];
|
||||
const v = parseNumber(raw);
|
||||
const max = c.max ?? 100;
|
||||
const ratio = v === null ? 0 : clamp01((v * scale) / max);
|
||||
const pct = ratio * 100;
|
||||
|
||||
const fill = fillColor;
|
||||
const track = trackColor;
|
||||
|
||||
const cellBg =
|
||||
v === null
|
||||
? undefined
|
||||
: `linear-gradient(to right, ${fill} ${pct}%, ${track} 0%)`;
|
||||
|
||||
if (cellType === "number") {
|
||||
return (
|
||||
<td
|
||||
key={String(c.key)}
|
||||
className="px-2 content-text-sm"
|
||||
style={{ textAlign: align }}
|
||||
>
|
||||
{v === null ? "-" : fmt(v)}
|
||||
</td>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<td
|
||||
key={String(c.key)}
|
||||
className="px-2 content-text-sm"
|
||||
style={{
|
||||
textAlign: "left",
|
||||
height: cellHeight,
|
||||
whiteSpace: "nowrap",
|
||||
background: cellBg,
|
||||
backgroundClip: "padding-box",
|
||||
}}
|
||||
>
|
||||
{v === null ? "-" : fmt(v)}
|
||||
</td>
|
||||
);
|
||||
})}
|
||||
</tr>
|
||||
<BaseTableRenderer
|
||||
columns={columns}
|
||||
wrapperClassName={wrapperClassName}
|
||||
tableClassName={tableClassName ?? className}
|
||||
minWidth="100%"
|
||||
colgroup={
|
||||
<colgroup>
|
||||
{columns.map((column, index) => (
|
||||
<col
|
||||
key={`${String(column.key)}-${index}`}
|
||||
style={{
|
||||
width: column.width ?? (column.rowHead ? 50 : 40),
|
||||
}}
|
||||
/>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
</colgroup>
|
||||
}
|
||||
>
|
||||
{rows.map((row, rowIndex) => (
|
||||
<tr key={rowIndex}>
|
||||
{columns.map((column) => {
|
||||
const align = getColumnAlign(column);
|
||||
|
||||
export default GaugeTable;
|
||||
if (column.rowHead) {
|
||||
const content = column.render ? column.render(row) : toTableCellContent(row[column.key]);
|
||||
return (
|
||||
<th
|
||||
key={String(column.key)}
|
||||
scope="row"
|
||||
className={cn("lg-table__rowhead", column.cellClassName)}
|
||||
style={{ textAlign: align }}
|
||||
>
|
||||
{content}
|
||||
</th>
|
||||
);
|
||||
}
|
||||
|
||||
const rawValue = row[column.key];
|
||||
const numericValue = parseNumber(rawValue);
|
||||
const max = column.max ?? 100;
|
||||
const ratio = numericValue === null ? 0 : clampRatio((numericValue * scale) / max);
|
||||
const percentage = ratio * 100;
|
||||
const background =
|
||||
numericValue === null ? undefined : `linear-gradient(to right, ${fillColor} ${percentage}%, ${trackColor} 0%)`;
|
||||
|
||||
if ((column.cellType ?? "gauge") === "number") {
|
||||
return (
|
||||
<td key={String(column.key)} className={cn("px-2 content-text-sm", column.cellClassName)} style={{ textAlign: align }}>
|
||||
{numericValue === null ? "-" : formatValue(numericValue)}
|
||||
</td>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<td
|
||||
key={String(column.key)}
|
||||
className={cn("px-2 content-text-sm", column.cellClassName)}
|
||||
style={{
|
||||
textAlign: "left",
|
||||
height: cellHeight,
|
||||
whiteSpace: "nowrap",
|
||||
background,
|
||||
backgroundClip: "padding-box",
|
||||
}}
|
||||
>
|
||||
{numericValue === null ? "-" : formatValue(numericValue)}
|
||||
</td>
|
||||
);
|
||||
})}
|
||||
</tr>
|
||||
))}
|
||||
</BaseTableRenderer>
|
||||
);
|
||||
};
|
||||
|
||||
export default GaugeTable;
|
||||
|
||||
31
src/components/lge-dashboard/table/core/BaseTableHeader.tsx
Normal file
31
src/components/lge-dashboard/table/core/BaseTableHeader.tsx
Normal file
@@ -0,0 +1,31 @@
|
||||
import SectionTitle from "../../SectionTitle";
|
||||
import { SAMPLE_SIZE_NOTICE } from "@/const/lg-common.const";
|
||||
|
||||
type Props = {
|
||||
title?: string;
|
||||
unitText?: string;
|
||||
showSampleNotice?: boolean;
|
||||
};
|
||||
|
||||
export default function BaseTableHeader({ title, unitText, showSampleNotice = false }: Props) {
|
||||
if (!title && !unitText && !showSampleNotice) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="mb-2 flex items-center justify-between">
|
||||
{title ? <SectionTitle title={title} /> : <div />}
|
||||
{unitText || showSampleNotice ? (
|
||||
<div className="ml-auto text-right text-gray-500 content-text-xs font-semibold">
|
||||
{unitText}
|
||||
{showSampleNotice ? (
|
||||
<>
|
||||
<br />
|
||||
{SAMPLE_SIZE_NOTICE}
|
||||
</>
|
||||
) : null}
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
"use client";
|
||||
|
||||
import type React from "react";
|
||||
import { cn } from "@/lib/utils";
|
||||
import BaseTableHeader from "./BaseTableHeader";
|
||||
import { buildGroupHeaderCells, hasGroupedHeader } from "./table-core.helpers";
|
||||
|
||||
type BaseColumn<T> = {
|
||||
key: keyof T;
|
||||
header: string;
|
||||
width?: number | string;
|
||||
group?: string;
|
||||
headRowSpan?: 1 | 2;
|
||||
headerClassName?: string;
|
||||
};
|
||||
|
||||
type Props<T> = {
|
||||
columns: BaseColumn<T>[];
|
||||
title?: string;
|
||||
unitText?: string;
|
||||
showSampleNotice?: boolean;
|
||||
wrapperClassName?: string;
|
||||
tableClassName?: string;
|
||||
subheadRowClassName?: string;
|
||||
minWidth?: number | string;
|
||||
colgroup?: React.ReactNode;
|
||||
renderHeaderPrefix?: React.ReactNode;
|
||||
children: React.ReactNode;
|
||||
};
|
||||
|
||||
export default function BaseTableRenderer<T>({
|
||||
columns,
|
||||
title,
|
||||
unitText,
|
||||
showSampleNotice = false,
|
||||
wrapperClassName,
|
||||
tableClassName,
|
||||
subheadRowClassName,
|
||||
minWidth,
|
||||
colgroup,
|
||||
renderHeaderPrefix,
|
||||
children,
|
||||
}: Readonly<Props<T>>) {
|
||||
const groupedHeader = hasGroupedHeader(columns);
|
||||
const groupHeaderCells = buildGroupHeaderCells(columns);
|
||||
|
||||
return (
|
||||
<div className={cn("w-full", wrapperClassName)}>
|
||||
<BaseTableHeader title={title} unitText={unitText} showSampleNotice={showSampleNotice} />
|
||||
|
||||
<div className="overflow-x-auto">
|
||||
<table
|
||||
className={cn("lg-table", tableClassName)}
|
||||
style={minWidth === undefined ? undefined : { minWidth: typeof minWidth === "number" ? `${minWidth}px` : minWidth }}
|
||||
>
|
||||
{colgroup}
|
||||
<thead>
|
||||
{renderHeaderPrefix}
|
||||
{groupedHeader ? (
|
||||
<tr className="lg-table__group">
|
||||
{groupHeaderCells.map((cell, index) => (
|
||||
<th
|
||||
key={`${cell.kind}-${cell.label}-${index}`}
|
||||
colSpan={cell.colSpan}
|
||||
rowSpan={cell.rowSpan}
|
||||
className={cell.className}
|
||||
>
|
||||
{cell.label}
|
||||
</th>
|
||||
))}
|
||||
</tr>
|
||||
) : null}
|
||||
<tr className={cn(groupedHeader ? "lg-table__subhead" : undefined, subheadRowClassName)}>
|
||||
{columns
|
||||
.filter((column) => column.headRowSpan !== 2)
|
||||
.map((column) => (
|
||||
<th
|
||||
key={String(column.key)}
|
||||
className={column.headerClassName}
|
||||
style={column.width ? { width: column.width } : undefined}
|
||||
>
|
||||
{column.header}
|
||||
</th>
|
||||
))}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>{children}</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
247
src/components/lge-dashboard/table/core/table-core.helpers.tsx
Normal file
247
src/components/lge-dashboard/table/core/table-core.helpers.tsx
Normal file
@@ -0,0 +1,247 @@
|
||||
import type React from "react";
|
||||
import { parseNumber } from "@/lib/utils";
|
||||
import { roundNumber } from "@/lib/lg-dashboard";
|
||||
import type { SignDisplayMode, SignStyle, ValueFormatter } from "../../types";
|
||||
|
||||
type BaseTableColumn<T> = {
|
||||
key: keyof T;
|
||||
header: string;
|
||||
width?: number | string;
|
||||
align?: "left" | "center" | "right";
|
||||
group?: string;
|
||||
headRowSpan?: 1 | 2;
|
||||
rowHead?: boolean;
|
||||
numeric?: boolean;
|
||||
headerClassName?: string;
|
||||
cellClassName?: string;
|
||||
};
|
||||
|
||||
export type GroupHeaderCell = {
|
||||
kind: "rowspan" | "group" | "blank";
|
||||
label: string;
|
||||
colSpan: number;
|
||||
rowSpan: number;
|
||||
className?: string;
|
||||
};
|
||||
|
||||
export type ResolvedSignStyle = {
|
||||
paint: "text" | "cell";
|
||||
display: SignDisplayMode;
|
||||
showPlus: boolean;
|
||||
arrowWithNumber: boolean;
|
||||
zeroText: string;
|
||||
valueFormatter: ValueFormatter;
|
||||
positiveTextClassName: string;
|
||||
negativeTextClassName: string;
|
||||
zeroTextClassName: string;
|
||||
positiveCellBg: string;
|
||||
negativeCellBg: string;
|
||||
zeroCellBg: string;
|
||||
};
|
||||
|
||||
const defaultValueFormatter: ValueFormatter = (value) =>
|
||||
Number.isInteger(value) ? String(roundNumber(value)) : value.toLocaleString();
|
||||
|
||||
const defaultSignStyle: ResolvedSignStyle = {
|
||||
paint: "text",
|
||||
display: "number",
|
||||
showPlus: true,
|
||||
arrowWithNumber: false,
|
||||
zeroText: "-",
|
||||
valueFormatter: defaultValueFormatter,
|
||||
positiveTextClassName: "text-primary font-semibold",
|
||||
negativeTextClassName: "text-info font-semibold",
|
||||
zeroTextClassName: "text-gray-600",
|
||||
positiveCellBg: "hsl(var(--primary) / 0.08)",
|
||||
negativeCellBg: "hsl(var(--info) / 0.08)",
|
||||
zeroCellBg: "hsl(var(--lg-gray-200) / 0.6)",
|
||||
};
|
||||
|
||||
export function hasGroupedHeader<T>(columns: BaseTableColumn<T>[]) {
|
||||
return columns.some((column) => column.group) || columns.some((column) => column.headRowSpan === 2);
|
||||
}
|
||||
|
||||
export function buildGroupHeaderCells<T>(columns: BaseTableColumn<T>[]) {
|
||||
if (!hasGroupedHeader(columns)) {
|
||||
return [] as GroupHeaderCell[];
|
||||
}
|
||||
|
||||
const cells: GroupHeaderCell[] = [];
|
||||
let index = 0;
|
||||
|
||||
while (index < columns.length) {
|
||||
const column = columns[index];
|
||||
|
||||
if (column.headRowSpan === 2) {
|
||||
cells.push({
|
||||
kind: "rowspan",
|
||||
label: column.header,
|
||||
colSpan: 1,
|
||||
rowSpan: 2,
|
||||
className: column.headerClassName,
|
||||
});
|
||||
index += 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!column.group) {
|
||||
cells.push({
|
||||
kind: "blank",
|
||||
label: "",
|
||||
colSpan: 1,
|
||||
rowSpan: 1,
|
||||
className: column.headerClassName,
|
||||
});
|
||||
index += 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
let span = 1;
|
||||
let cursor = index + 1;
|
||||
while (cursor < columns.length && columns[cursor].headRowSpan !== 2 && columns[cursor].group === column.group) {
|
||||
span += 1;
|
||||
cursor += 1;
|
||||
}
|
||||
|
||||
cells.push({
|
||||
kind: "group",
|
||||
label: column.group,
|
||||
colSpan: span,
|
||||
rowSpan: 1,
|
||||
className: column.headerClassName,
|
||||
});
|
||||
index = cursor;
|
||||
}
|
||||
|
||||
return cells;
|
||||
}
|
||||
|
||||
export function getColumnAlign<T>(column: BaseTableColumn<T>, fallback: "left" | "center" | "right" = "center") {
|
||||
if (column.align) {
|
||||
return column.align;
|
||||
}
|
||||
|
||||
if (column.numeric) {
|
||||
return "right";
|
||||
}
|
||||
|
||||
if (column.rowHead) {
|
||||
return "left";
|
||||
}
|
||||
|
||||
return fallback;
|
||||
}
|
||||
|
||||
export function toTableCellContent(raw: unknown): React.ReactNode {
|
||||
if (raw == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
if (typeof raw === "string") {
|
||||
const trimmed = raw.trim();
|
||||
if (!trimmed) {
|
||||
return raw;
|
||||
}
|
||||
|
||||
const parsed = Number(trimmed);
|
||||
return Number.isNaN(parsed) ? raw : roundNumber(parsed);
|
||||
}
|
||||
|
||||
if (typeof raw === "number") {
|
||||
return String(roundNumber(raw));
|
||||
}
|
||||
|
||||
return String(raw);
|
||||
}
|
||||
|
||||
export function toRoundedNumber(raw: unknown, decimalPoint?: number) {
|
||||
const parsed = parseNumber(raw);
|
||||
return parsed === null ? null : roundNumber(parsed, decimalPoint);
|
||||
}
|
||||
|
||||
export function appendCellMarker(content: React.ReactNode, marker: string) {
|
||||
if (!marker) {
|
||||
return content;
|
||||
}
|
||||
|
||||
if (typeof content === "string" || typeof content === "number") {
|
||||
return `${content}${marker}`;
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
{content}
|
||||
{marker}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export function resolveSignStyle<T>(signStyle?: SignStyle<T>, fallback?: Partial<ResolvedSignStyle>) {
|
||||
return {
|
||||
...defaultSignStyle,
|
||||
...fallback,
|
||||
...signStyle,
|
||||
valueFormatter: signStyle?.valueFormatter ?? fallback?.valueFormatter ?? defaultSignStyle.valueFormatter,
|
||||
};
|
||||
}
|
||||
|
||||
export function shouldApplySignToColumn<T>(column: BaseTableColumn<T>, signStyle?: SignStyle<T>) {
|
||||
if (!signStyle || column.rowHead) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (signStyle.keys?.length) {
|
||||
return signStyle.keys.includes(column.key);
|
||||
}
|
||||
|
||||
return !!column.numeric;
|
||||
}
|
||||
|
||||
export function formatSignedValue(
|
||||
value: number,
|
||||
options: Pick<ResolvedSignStyle, "arrowWithNumber" | "display" | "showPlus" | "valueFormatter" | "zeroText">
|
||||
) {
|
||||
if (options.display === "arrow") {
|
||||
if (value > 0) {
|
||||
return options.arrowWithNumber ? `▲ ${options.valueFormatter(Math.abs(value))}` : "▲";
|
||||
}
|
||||
if (value < 0) {
|
||||
return options.arrowWithNumber ? `▼ ${options.valueFormatter(Math.abs(value))}` : "▼";
|
||||
}
|
||||
return options.zeroText;
|
||||
}
|
||||
|
||||
if (value > 0) {
|
||||
return options.showPlus ? `+${options.valueFormatter(value)}` : options.valueFormatter(value);
|
||||
}
|
||||
if (value < 0) {
|
||||
return options.valueFormatter(value);
|
||||
}
|
||||
return options.zeroText;
|
||||
}
|
||||
|
||||
export function getSignTextClass(
|
||||
value: number,
|
||||
options: Pick<ResolvedSignStyle, "negativeTextClassName" | "positiveTextClassName" | "zeroTextClassName">
|
||||
) {
|
||||
if (value > 0) {
|
||||
return options.positiveTextClassName;
|
||||
}
|
||||
if (value < 0) {
|
||||
return options.negativeTextClassName;
|
||||
}
|
||||
return options.zeroTextClassName;
|
||||
}
|
||||
|
||||
export function getSignCellBackground(
|
||||
value: number,
|
||||
options: Pick<ResolvedSignStyle, "negativeCellBg" | "positiveCellBg" | "zeroCellBg">
|
||||
) {
|
||||
if (value > 0) {
|
||||
return options.positiveCellBg;
|
||||
}
|
||||
if (value < 0) {
|
||||
return options.negativeCellBg;
|
||||
}
|
||||
return options.zeroCellBg;
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import type React from "react";
|
||||
import {GAP_WORDING} from "@/const/lgConst";
|
||||
import {GAP_WORDING} from "@/const/lg-common.const";
|
||||
|
||||
export type NewNumber = number | null | undefined;
|
||||
|
||||
@@ -86,6 +86,8 @@ export type GaugeColumn<T> = {
|
||||
max?: number;
|
||||
render?: (row: T) => React.ReactNode; // rowHead에 쓰기 좋음
|
||||
cellType?: "gauge" | "number"; // default: "gauge"
|
||||
headerClassName?: string;
|
||||
cellClassName?: string;
|
||||
};
|
||||
|
||||
export type SignDisplayMode = "number" | "arrow";
|
||||
@@ -136,4 +138,4 @@ export type ShowLabel = "none" | "all" | "last" | "first";
|
||||
export type bannerType = {
|
||||
variable:string;
|
||||
variableName:string;
|
||||
}
|
||||
}
|
||||
|
||||
254
src/config/lg-page.config.ts
Normal file
254
src/config/lg-page.config.ts
Normal file
@@ -0,0 +1,254 @@
|
||||
import {CategoryFieldSpec} from "@/types/lg.types";
|
||||
import {CategoryTargetData, CategoryTargetType} from "@/types/filter.types";
|
||||
|
||||
export const CATEGORY_PAGE_FIELDS: Record<CategoryTargetData, CategoryFieldSpec[]> = {
|
||||
[CategoryTargetData.PROFILE]: [
|
||||
{
|
||||
title: {
|
||||
[CategoryTargetType.PENETRATION]: "보유율"
|
||||
, [CategoryTargetType.PURCHASE]: "구매율"
|
||||
, [CategoryTargetType.INTENDED]: "향후 구매율"
|
||||
},
|
||||
requestKey: "category_${keyBase}",
|
||||
chartMode:"none",
|
||||
qidByMode: {
|
||||
[CategoryTargetType.PENETRATION]: "KQA1"
|
||||
, [CategoryTargetType.PURCHASE]: "KQB0"
|
||||
, [CategoryTargetType.INTENDED]: "KQC1"
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "보유대수",
|
||||
requestKey: "category_penetration_count",
|
||||
chartMode:"none",
|
||||
qidByMode: {
|
||||
[CategoryTargetType.PENETRATION]: "KQA2"
|
||||
},
|
||||
},
|
||||
],
|
||||
|
||||
[CategoryTargetData.PENETRATION_CHANGE]: [
|
||||
{
|
||||
title: "보급률 변화",
|
||||
requestKey: "category_${keyBase}",
|
||||
chartMode:"none",
|
||||
qidByMode: {
|
||||
[CategoryTargetType.PENETRATION]: "KQA1"
|
||||
},
|
||||
},
|
||||
],
|
||||
|
||||
[CategoryTargetData.BRAND]: [
|
||||
{
|
||||
title: "브랜드",
|
||||
requestKey: "category_${keyBase}_brand",
|
||||
chartMode:"reverseStack",
|
||||
chartTopMargin: 80,
|
||||
qidByMode: {
|
||||
[CategoryTargetType.PENETRATION]: "KQA3_3",
|
||||
[CategoryTargetType.PURCHASE]: "KQX3_3",
|
||||
},
|
||||
},
|
||||
{
|
||||
title: {
|
||||
[CategoryTargetType.PENETRATION]: "",
|
||||
[CategoryTargetType.PURCHASE]: "구매 고려 브랜드",
|
||||
[CategoryTargetType.INTENDED]: "브랜드",
|
||||
},
|
||||
requestKey: "category_${keyBase}_consider_brand",
|
||||
chartMode:"horizontal",
|
||||
qidByMode: {
|
||||
[CategoryTargetType.PURCHASE]: "KQB1",
|
||||
[CategoryTargetType.INTENDED]: "KQC2",
|
||||
},
|
||||
},
|
||||
],
|
||||
|
||||
[CategoryTargetData.TYPE_SPEC]: [
|
||||
{
|
||||
title: "타입",
|
||||
requestKey: "category_${keyBase}_type",
|
||||
chartMode: "horizontal",
|
||||
qidByMode: {
|
||||
[CategoryTargetType.PENETRATION]: "KQA3_4",
|
||||
[CategoryTargetType.PURCHASE]: "KQX3_4",
|
||||
[CategoryTargetType.INTENDED]: "KQC3_1"
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "깊이 타입",
|
||||
requestKey: "category_${keyBase}_depthType",
|
||||
chartMode: "horizontal",
|
||||
qidByMode: {
|
||||
[CategoryTargetType.PENETRATION]: "KQA3_5",
|
||||
[CategoryTargetType.PURCHASE]: "KQX3_5",
|
||||
[CategoryTargetType.INTENDED]: "KQC3_2"
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "용량",
|
||||
requestKey: "category_${keyBase}_capacity",
|
||||
chartMode: "horizontal",
|
||||
qidByMode: {
|
||||
[CategoryTargetType.PENETRATION]: "KQA3_6",
|
||||
[CategoryTargetType.PURCHASE]: "KQX3_6"
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "설치 형태",
|
||||
requestKey: "category_${keyBase}_installType",
|
||||
chartMode: "horizontal",
|
||||
qidByMode: {
|
||||
[CategoryTargetType.PENETRATION]: "KQA3_7",
|
||||
[CategoryTargetType.PURCHASE]: "KQX3_7",
|
||||
[CategoryTargetType.INTENDED]: "KQC3_3"
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "시공 방식",
|
||||
requestKey: "category_${keyBase}_installMethod",
|
||||
chartMode: "horizontal",
|
||||
qidByMode: {
|
||||
[CategoryTargetType.INTENDED]: "KQC3_4"
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "냉장고 & 김치냉장고 설치 형태",
|
||||
requestKey: "category_${keyBase}_fridgeInstallType",
|
||||
chartMode: "horizontal",
|
||||
qidByMode: {
|
||||
[CategoryTargetType.INTENDED]: "KQC3_5"
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "설치 위치",
|
||||
requestKey: "category_${keyBase}_installLocation",
|
||||
chartMode: "horizontal",
|
||||
qidByMode: {
|
||||
[CategoryTargetType.INTENDED]: "KQC3_6"
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "배치/설치환경",
|
||||
requestKey: "category_${keyBase}_installEnv",
|
||||
chartMode: "horizontal",
|
||||
qidByMode: {
|
||||
[CategoryTargetType.PENETRATION]: "KQA3_8",
|
||||
[CategoryTargetType.PURCHASE]: "KQX3_8",
|
||||
[CategoryTargetType.INTENDED]: "KQC3_7"
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "구입 고려 특징",
|
||||
requestKey: "category_${keyBase}_buyConsiderations",
|
||||
chartMode: "horizontal",
|
||||
qidByMode: {
|
||||
[CategoryTargetType.INTENDED]: "KQC3_8"
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "기능",
|
||||
requestKey: "category_${keyBase}_features",
|
||||
chartMode: "horizontal",
|
||||
qidByMode: {
|
||||
[CategoryTargetType.PENETRATION]: "KQA3_9",
|
||||
[CategoryTargetType.PURCHASE]: "KQX3_9"
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "스크린 사이즈",
|
||||
requestKey: "category_${keyBase}_screenSize",
|
||||
chartMode: "horizontal",
|
||||
qidByMode: {
|
||||
[CategoryTargetType.PENETRATION]: "KQA3_10",
|
||||
[CategoryTargetType.PURCHASE]: "KQX3_10"
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "용도",
|
||||
requestKey: "category_${keyBase}_usage",
|
||||
chartMode: "horizontal",
|
||||
qidByMode: {
|
||||
[CategoryTargetType.PENETRATION]: "KQA3_11",
|
||||
[CategoryTargetType.PURCHASE]: "KQX3_11"
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "스마트 모니터 여부",
|
||||
requestKey: "category_${keyBase}_isSmartMonitor",
|
||||
chartMode: "horizontal",
|
||||
qidByMode: {
|
||||
[CategoryTargetType.PENETRATION]: "KQA3_12",
|
||||
[CategoryTargetType.PURCHASE]: "KQX3_12"
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "음식물처리기 구동 방식",
|
||||
requestKey: "category_${keyBase}_driveMethod",
|
||||
chartMode: "horizontal",
|
||||
qidByMode: {
|
||||
[CategoryTargetType.PENETRATION]: "KQA3_13",
|
||||
[CategoryTargetType.PURCHASE]: "KQX3_13"
|
||||
}
|
||||
},
|
||||
],
|
||||
|
||||
[CategoryTargetData.BEHAVIOR]: [
|
||||
{
|
||||
title: {
|
||||
[CategoryTargetType.PENETRATION]: "보유 경로"
|
||||
, [CategoryTargetType.PURCHASE]: "구입 행태"
|
||||
, [CategoryTargetType.INTENDED]: "구입 행태"
|
||||
},
|
||||
requestKey: "category_${keyBase}_behavior",
|
||||
chartMode: "horizontal",
|
||||
qidByMode: {
|
||||
[CategoryTargetType.PENETRATION]: "KQA3_1",
|
||||
[CategoryTargetType.PURCHASE]: "KQB2",
|
||||
[CategoryTargetType.INTENDED]: "KQC5"
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "구입 계기",
|
||||
requestKey: "category_${keyBase}_chance",
|
||||
chartMode: "horizontal",
|
||||
qidByMode: {
|
||||
[CategoryTargetType.PURCHASE]: "KQB3"
|
||||
},
|
||||
},
|
||||
],
|
||||
|
||||
[CategoryTargetData.PURCHASE_CHANNEL]: [
|
||||
{
|
||||
title: "구매 채널(온/오프라인)",
|
||||
requestKey: "category_${keyBase}_channel",
|
||||
chartMode: "reverseStack",
|
||||
qidByMode: {
|
||||
[CategoryTargetType.PURCHASE]: "KQB4_NET",
|
||||
[CategoryTargetType.INTENDED]: "KQC6_NET"
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "구매 채널(상세)",
|
||||
requestKey: "category_${keyBase}_channel_detail",
|
||||
chartMode: "horizontal",
|
||||
qidByMode: {
|
||||
[CategoryTargetType.PURCHASE]: "KQB4",
|
||||
[CategoryTargetType.INTENDED]: "KQC6"
|
||||
},
|
||||
},
|
||||
],
|
||||
|
||||
[CategoryTargetData.PAYMENT_METHOD]: [
|
||||
{
|
||||
title: "구매형식",
|
||||
requestKey: "category_${keyBase}_method",
|
||||
chartMode:"reverseStack",
|
||||
qidByMode: {
|
||||
[CategoryTargetType.PENETRATION]: "KQA3_2_1",
|
||||
[CategoryTargetType.PURCHASE]: "KQX3_2_1",
|
||||
[CategoryTargetType.INTENDED]: "KQC7"
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
@@ -1,141 +0,0 @@
|
||||
/**
|
||||
* 차트 관련 상수 정의
|
||||
* - 차트 높이, Bar 너비, Grid 설정 등
|
||||
*/
|
||||
|
||||
import {GAP_WORDING} from "@/const/lgConst";
|
||||
|
||||
/**
|
||||
* 차트 기본 높이 설정
|
||||
*/
|
||||
export const CHART_HEIGHTS = {
|
||||
DEFAULT: "100%",
|
||||
COMPACT: 200,
|
||||
EXPANDED: 320,
|
||||
} as const;
|
||||
|
||||
/**
|
||||
* Bar 차트의 Bar 너비 설정
|
||||
*/
|
||||
export const BAR_WIDTHS = {
|
||||
DEFAULT: 42,
|
||||
NARROW: 30,
|
||||
WIDE: 60,
|
||||
} as const;
|
||||
|
||||
/**
|
||||
* 차트 Grid 기본 패딩 설정
|
||||
*/
|
||||
export const CHART_GRID_DEFAULTS = {
|
||||
DEFAULT: {
|
||||
left: 16,
|
||||
right: 16,
|
||||
top: 36,
|
||||
bottom: 12,
|
||||
containLabel: true,
|
||||
},
|
||||
COMPACT: {
|
||||
left: 10,
|
||||
right: 10,
|
||||
top: 20,
|
||||
bottom: 8,
|
||||
containLabel: true,
|
||||
},
|
||||
} as const;
|
||||
|
||||
/**
|
||||
* Legend 아이템 크기 설정 (GroupedOverlayBar, GroupedStackBar에서 사용)
|
||||
*/
|
||||
export const LEGEND_ITEM_SIZE = {
|
||||
WIDTH: 25,
|
||||
HEIGHT: 14,
|
||||
RADIUS: 4,
|
||||
} as const;
|
||||
|
||||
/**
|
||||
* 색상 팔레트 설정
|
||||
*/
|
||||
export const CHART_COLOR_PALETTES = {
|
||||
/** 연도별 트렌드 역순 (최신->과거) */
|
||||
YEAR_TREND_REVERSE: ["--chart-3", "--chart-2", "--chart-1"],
|
||||
|
||||
/** LG Red 계열 */
|
||||
LG_RED_SCALE: ["--lg-red-300", "--lg-red-400", "--lg-red-500"],
|
||||
|
||||
/** 연도별 전체 색상 */
|
||||
YEAR_TOTAL: {
|
||||
"24": "--chart-total-1",
|
||||
"25": "--chart-total-2",
|
||||
"26": "--chart-total-3",
|
||||
} as const,
|
||||
|
||||
/** 연도별 LG 색상 */
|
||||
YEAR_LG: {
|
||||
"24": "--chart-lg-1",
|
||||
"25": "--chart-lg-2",
|
||||
"26": "--chart-lg-3",
|
||||
} as const,
|
||||
|
||||
/** 연도별 브랜드 색상 (CBrand, Samsung, LG) */
|
||||
YEAR_BRAND: {
|
||||
"24": ["--chart-cbrand-1", "--chart-samsung-1", "--chart-lg-1"],
|
||||
"25": ["--chart-cbrand-2", "--chart-samsung-2", "--chart-lg-2"],
|
||||
"26": ["--chart-cbrand-3", "--chart-samsung-3", "--chart-lg-3"],
|
||||
} as const,
|
||||
} as const;
|
||||
|
||||
/**
|
||||
* 테이블 색상 설정
|
||||
*/
|
||||
export const TABLE_COLORS = {
|
||||
/** 게이지 테이블 색상 */
|
||||
GAUGE: {
|
||||
FILL: "hsl(var(--lg-gray-200) / 0.85)",
|
||||
TRACK: "hsl(var(--lg-pink-300) / 0.2)",
|
||||
},
|
||||
|
||||
/** Sign 표기 셀 배경색 */
|
||||
SIGN_CELL: {
|
||||
POSITIVE: "hsl(var(--primary) / 0.08)",
|
||||
NEGATIVE: "hsl(var(--info) / 0.08)",
|
||||
ZERO: "hsl(var(--lg-gray-200) / 0.6)",
|
||||
},
|
||||
} as const;
|
||||
|
||||
/**
|
||||
* 테이블 크기 설정
|
||||
*/
|
||||
export const TABLE_DIMENSIONS = {
|
||||
CELL_HEIGHT: {
|
||||
DEFAULT: 26,
|
||||
COMPACT: 20,
|
||||
EXPANDED: 32,
|
||||
},
|
||||
MIN_WIDTH: {
|
||||
STANDARD: 1600,
|
||||
COMPACT: 1200,
|
||||
WIDE: 2000,
|
||||
},
|
||||
} as const;
|
||||
|
||||
/**
|
||||
* 차트/테이블 라벨 텍스트
|
||||
*/
|
||||
export const CHART_LABELS = {
|
||||
TOTAL: "전체",
|
||||
LG: "LG",
|
||||
GAP: GAP_WORDING,
|
||||
CAGR: "CAGR(%p)",
|
||||
SAMPLE_COUNT: "(사례수)",
|
||||
} as const;
|
||||
|
||||
/**
|
||||
* 차트 제목 텍스트
|
||||
*/
|
||||
export const CHART_TITLES = {
|
||||
LG_PENETRATION: "LG제품 보급률",
|
||||
TOTAL_PENETRATION: "전체 보급률",
|
||||
LG_PURCHASE: "LG제품 구매율",
|
||||
TOTAL_PURCHASE: "전체 구매율",
|
||||
BRAND_SHARE: "브랜드별 점유율",
|
||||
} as const;
|
||||
@@ -2,9 +2,9 @@ import {
|
||||
CategoryTargetData,
|
||||
CategoryTargetItem,
|
||||
CategoryTargetType,
|
||||
CategoryTargetTypeItem,
|
||||
CategoryTargetTypeItem, FilterItem,
|
||||
TotalFilterItem
|
||||
} from "./filter.types";
|
||||
} from "@/types/filter.types";
|
||||
|
||||
export const totalFilters:TotalFilterItem[] = [
|
||||
{
|
||||
@@ -18,6 +18,8 @@ export const totalFilters:TotalFilterItem[] = [
|
||||
{ value: "4", label: "기혼 학령기"},
|
||||
{ value: "5", label: "기혼 성인자녀"},
|
||||
{ value: "6", label: "독립 시니어"},
|
||||
{ value: "7", label: "비혼 중년"},
|
||||
{ value: "8", label: "기타"},
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -64,7 +66,8 @@ export const totalFilters:TotalFilterItem[] = [
|
||||
{ value: "2", label: "주택"},
|
||||
{ value: "3", label: "오피스텔"},
|
||||
{ value: "4", label: "(연립)빌라"},
|
||||
{ value: "5", label: "기타"},
|
||||
{ value: "5", label: "원룸"},
|
||||
{ value: "6", label: "기타"},
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -85,11 +88,11 @@ export const totalFilters:TotalFilterItem[] = [
|
||||
variableName:"연령대",
|
||||
children:[
|
||||
{ value: "0", label: "전체"},
|
||||
{ value: "2", label: "20대"},
|
||||
{ value: "3", label: "30대"},
|
||||
{ value: "4", label: "40대"},
|
||||
{ value: "5", label: "50대"},
|
||||
{ value: "6", label: "60대"},
|
||||
{ value: "1", label: "20대"},
|
||||
{ value: "2", label: "30대"},
|
||||
{ value: "3", label: "40대"},
|
||||
{ value: "4", label: "50대"},
|
||||
{ value: "5", label: "60대"},
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -143,4 +146,39 @@ export const categoryTarget: CategoryTargetItem[] = [
|
||||
{ value: CategoryTargetData.PAYMENT_METHOD, label: "구매 형식"},
|
||||
]
|
||||
},
|
||||
]
|
||||
]
|
||||
|
||||
export const categoryByDataBanner:FilterItem[] = [
|
||||
{
|
||||
variable:"lifeStage",
|
||||
variableName:"라이프 스테이지",
|
||||
},
|
||||
{
|
||||
variable:"age",
|
||||
variableName:"연령대",
|
||||
},
|
||||
{
|
||||
variable:"household",
|
||||
variableName:"가구원 수",
|
||||
},
|
||||
{
|
||||
variable:"occupancy",
|
||||
variableName:"입주 형태",
|
||||
},
|
||||
{
|
||||
variable:"housing",
|
||||
variableName:"주거 형태",
|
||||
},
|
||||
{
|
||||
variable:"houseSize",
|
||||
variableName:"거주 평형",
|
||||
},
|
||||
{
|
||||
variable:"income",
|
||||
variableName:"월 소득 규모",
|
||||
},
|
||||
{
|
||||
variable:"region",
|
||||
variableName:"지역",
|
||||
},
|
||||
]
|
||||
96
src/const/lg-banner.const.ts
Normal file
96
src/const/lg-banner.const.ts
Normal file
@@ -0,0 +1,96 @@
|
||||
import type {BannerKey} from "@/types/lg.types";
|
||||
import {BANNER_KEY_MAP} from "@/const/lg-schema.const";
|
||||
|
||||
export const BANNER_KEYS = Object.keys(BANNER_KEY_MAP) as Array<keyof typeof BANNER_KEY_MAP>;
|
||||
export const BANNER_KEY = Object.keys(BANNER_KEY_MAP).reduce((acc, k) => {
|
||||
(acc as any)[k] = k;
|
||||
return acc;
|
||||
}, {} as { [K in BannerKey]: K });
|
||||
|
||||
export const BANNER_GROUP = {
|
||||
lifeStage: {
|
||||
label: "라이프스테이지 별",
|
||||
keys: [
|
||||
BANNER_KEY["KLIFEstAGE#1"],
|
||||
BANNER_KEY["KLIFEstAGE#2"],
|
||||
BANNER_KEY["KLIFEstAGE#3"],
|
||||
BANNER_KEY["KLIFEstAGE#4"],
|
||||
BANNER_KEY["KLIFEstAGE#5"],
|
||||
BANNER_KEY["KLIFEstAGE#6"],
|
||||
BANNER_KEY["KLIFEstAGE#7"],
|
||||
BANNER_KEY["KLIFEstAGE#8"],
|
||||
],
|
||||
},
|
||||
household: {
|
||||
label: "가구원수 별",
|
||||
keys: [
|
||||
BANNER_KEY["KSQ8_R_DB#1"],
|
||||
BANNER_KEY["KSQ8_R_DB#2"],
|
||||
BANNER_KEY["KSQ8_R_DB#3"],
|
||||
BANNER_KEY["KSQ8_R_DB#4"],
|
||||
],
|
||||
},
|
||||
age: {
|
||||
label: "연령",
|
||||
keys: [
|
||||
BANNER_KEY["KSQ2_R_R#1"],
|
||||
BANNER_KEY["KSQ2_R_R#2"],
|
||||
BANNER_KEY["KSQ2_R_R#3"],
|
||||
BANNER_KEY["KSQ2_R_R#4"],
|
||||
BANNER_KEY["KSQ2_R_R#5"],
|
||||
],
|
||||
},
|
||||
occupancy: {
|
||||
label: "입주 형태",
|
||||
keys: [
|
||||
BANNER_KEY["KDQ6#1"],
|
||||
BANNER_KEY["KDQ6#2"],
|
||||
BANNER_KEY["KDQ6#3"],
|
||||
BANNER_KEY["KDQ6#4"],
|
||||
BANNER_KEY["KDQ6#5"],
|
||||
],
|
||||
},
|
||||
housing: {
|
||||
label: "주거 형태",
|
||||
keys: [
|
||||
BANNER_KEY["KDQ4#1"],
|
||||
BANNER_KEY["KDQ4#2"],
|
||||
BANNER_KEY["KDQ4#3"],
|
||||
BANNER_KEY["KDQ4#4"],
|
||||
BANNER_KEY["KDQ4#5"],
|
||||
BANNER_KEY["KDQ4#6"],
|
||||
],
|
||||
},
|
||||
houseSize: {
|
||||
label: "거주 평형",
|
||||
keys: [
|
||||
BANNER_KEY["KDQ5#1"],
|
||||
BANNER_KEY["KDQ5#2"],
|
||||
BANNER_KEY["KDQ5#3"],
|
||||
BANNER_KEY["KDQ5#4"],
|
||||
BANNER_KEY["KDQ5#5"],
|
||||
],
|
||||
},
|
||||
region: {
|
||||
label: "거주 지역",
|
||||
keys: [
|
||||
BANNER_KEY["KSQ4_R_R#1"],
|
||||
BANNER_KEY["KSQ4_R_R#2"],
|
||||
BANNER_KEY["KSQ4_R_R#3"],
|
||||
BANNER_KEY["KSQ4_R_R#4"],
|
||||
BANNER_KEY["KSQ4_R_R#5"],
|
||||
BANNER_KEY["KSQ4_R_R#6"],
|
||||
],
|
||||
},
|
||||
income: {
|
||||
label: "소득수준",
|
||||
keys: [
|
||||
BANNER_KEY["KDQ3_DB#1"],
|
||||
BANNER_KEY["KDQ3_DB#2"],
|
||||
BANNER_KEY["KDQ3_DB#3"],
|
||||
BANNER_KEY["KDQ3_DB#4"],
|
||||
],
|
||||
},
|
||||
} as const;
|
||||
|
||||
export const BANNER_GROUP_KEY = Object.keys(BANNER_GROUP) as string[];
|
||||
14
src/const/lg-common.const.ts
Normal file
14
src/const/lg-common.const.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
export const USE_CACHE = true;
|
||||
export const API_DECIMAL_POINT = 0;
|
||||
export const VIEW_DECIMAL_POINT = 0;
|
||||
|
||||
export const SITE_TITLE = 'LGE CX Dashboard';
|
||||
|
||||
export const YEARS = ["2023", "2024", "2025"];
|
||||
export const LAST_YEAR = YEARS.at(-1)!;
|
||||
|
||||
export const GAP_WORDING = "전년 대비 GAP(%p)";
|
||||
export const UNIT_TEXT = "(단위 %)"
|
||||
export const SAMPLE_SIZE_NOTICE = "* 30표본 미만 해석에 주의";
|
||||
|
||||
export const BRAND_LIST = ['기타', 'C Brand', '삼성', 'LG'];
|
||||
67
src/const/lg-product.const.ts
Normal file
67
src/const/lg-product.const.ts
Normal file
@@ -0,0 +1,67 @@
|
||||
import {GaugeColumn} from "@/components/lge-dashboard";
|
||||
import {PRODUCT_KEY_MAP} from "@/const/lg-schema.const";
|
||||
import type {LifeStageRow} from "@/types/lg.types";
|
||||
|
||||
export const LIFE_STAGE_COLUMNS: GaugeColumn<LifeStageRow>[] = [
|
||||
{ key: "item", header: "", headRowSpan:2, rowHead: true, render: (r) => r.item },
|
||||
|
||||
{ key: "total", header: "전체", headRowSpan:2, max: 100, align: "left", cellType:"number"},
|
||||
{ key: "KLIFEstAGE#1", header: "미혼" , headRowSpan:2, max: 100 , align: "left"},
|
||||
|
||||
{ key: "KLIFEstAGE#2", header: "무자녀", group: "기혼", max: 100 , align: "left"},
|
||||
{ key: "KLIFEstAGE#3", header: "미취학", group: "기혼", max: 100 , align: "left"},
|
||||
{ key: "KLIFEstAGE#4", header: "취학자녀", group: "기혼", max: 100 , align: "left"},
|
||||
{ key: "KLIFEstAGE#5", header: "성인자녀", group: "기혼", max: 100 , align: "left"},
|
||||
|
||||
{ key: "KLIFEstAGE#6", header: "독립\n시니어", headRowSpan:2, max: 100 , align: "left"},
|
||||
{ key: "KLIFEstAGE#7", header: "비혼중년", headRowSpan:2, max: 100 , align: "left"},
|
||||
{ key: "KLIFEstAGE#8", header: "기타", headRowSpan:2, max: 100 , align: "left"},
|
||||
];
|
||||
|
||||
export const LIFE_STAGE_GROUPS = [
|
||||
{ title: "대형가전 군", items: ["KPRODUCT#1", "KPRODUCT#7", "KPRODUCT#8", "KPRODUCT#12", "KPRODUCT#14", "KPRODUCT#2", "KPRODUCT#3", "KPRODUCT#11"] },
|
||||
{ title: "소형가전 군", items: ["KPRODUCT#9", "KPRODUCT#13", "KPRODUCT#4"] },
|
||||
{ title: "신가전 군", items: ["KPRODUCT#10", "KPRODUCT#6"] },
|
||||
] as const;
|
||||
|
||||
export const PRODUCT_KEYS = Object.keys(PRODUCT_KEY_MAP) as Array<keyof typeof PRODUCT_KEY_MAP>;
|
||||
export const PRODUCTS = Object.values(PRODUCT_KEY_MAP) as Array<string>;
|
||||
|
||||
export const PRODUCTS_FILTER_ITEM = [
|
||||
{
|
||||
path: "kitchen",
|
||||
items: [
|
||||
"KPRODUCT#1", // 냉장고
|
||||
"KPRODUCT#2", // 김치 냉장고
|
||||
"KPRODUCT#3", // 정수기
|
||||
"KPRODUCT#4", // 전기 레인지
|
||||
"KPRODUCT#5", // 식기 세척기
|
||||
"KPRODUCT#6", // 음식물처리기
|
||||
],
|
||||
},
|
||||
{
|
||||
path: "living",
|
||||
items: [
|
||||
"KPRODUCT#7", // 세탁기
|
||||
"KPRODUCT#9", // 건조기
|
||||
"KPRODUCT#8", // 청소기
|
||||
"KPRODUCT#10", // 로봇 청소기
|
||||
"KPRODUCT#11", // 의류 관리기
|
||||
],
|
||||
},
|
||||
{
|
||||
path: "es",
|
||||
items: [
|
||||
"KPRODUCT#12", // 에어컨
|
||||
"KPRODUCT#13", // 공기 청정기
|
||||
],
|
||||
},
|
||||
{
|
||||
path: "ms",
|
||||
items: [
|
||||
"KPRODUCT#14", // TV
|
||||
"KPRODUCT#15", // 노트북
|
||||
"KPRODUCT#16", // 모니터
|
||||
],
|
||||
},
|
||||
] as const;
|
||||
82
src/const/lg-schema.const.ts
Normal file
82
src/const/lg-schema.const.ts
Normal file
@@ -0,0 +1,82 @@
|
||||
export const PRODUCT_KEY_MAP = {
|
||||
"KPRODUCT#1": "냉장고",
|
||||
"KPRODUCT#2": "김치 냉장고",
|
||||
"KPRODUCT#3": "정수기",
|
||||
"KPRODUCT#4": "전기 레인지",
|
||||
"KPRODUCT#5": "식기 세척기",
|
||||
"KPRODUCT#6": "음식물처리기",
|
||||
|
||||
"KPRODUCT#7": "세탁기",
|
||||
"KPRODUCT#9": "건조기",
|
||||
"KPRODUCT#8": "청소기",
|
||||
"KPRODUCT#10": "로봇 청소기",
|
||||
"KPRODUCT#11": "의류 관리기",
|
||||
|
||||
"KPRODUCT#12": "에어컨",
|
||||
"KPRODUCT#13": "공기 청정기",
|
||||
|
||||
"KPRODUCT#14": "TV",
|
||||
"KPRODUCT#15": "노트북",
|
||||
"KPRODUCT#16": "모니터",
|
||||
} as const;
|
||||
|
||||
export const BANNER_KEY_MAP = {
|
||||
// 라이프 스테이지
|
||||
"KLIFEstAGE#1": "미혼",
|
||||
"KLIFEstAGE#2": "무자녀",
|
||||
"KLIFEstAGE#3": "미취학",
|
||||
"KLIFEstAGE#4": "취학자녀",
|
||||
"KLIFEstAGE#5": "성인자녀",
|
||||
"KLIFEstAGE#6": "독립시니어",
|
||||
"KLIFEstAGE#7": "비혼중년",
|
||||
"KLIFEstAGE#8": "기타",
|
||||
|
||||
// 가구원수
|
||||
"KSQ8_R_DB#1": "1인 가구",
|
||||
"KSQ8_R_DB#2": "2인 가구",
|
||||
"KSQ8_R_DB#3": "3인 가구",
|
||||
"KSQ8_R_DB#4": "4인 이상 가구",
|
||||
|
||||
// 연령
|
||||
"KSQ2_R_R#1": "20대",
|
||||
"KSQ2_R_R#2": "30대",
|
||||
"KSQ2_R_R#3": "40대",
|
||||
"KSQ2_R_R#4": "50대",
|
||||
"KSQ2_R_R#5": "60대",
|
||||
|
||||
// 점유형태
|
||||
"KDQ6#1": "자가",
|
||||
"KDQ6#2": "전세",
|
||||
"KDQ6#3": "전+월세 (보증금有)",
|
||||
"KDQ6#4": "월세 (보증금無)",
|
||||
"KDQ6#5": "기타",
|
||||
|
||||
// 주거형태
|
||||
"KDQ4#1": "아파트",
|
||||
"KDQ4#2": "주택",
|
||||
"KDQ4#3": "오피스텔",
|
||||
"KDQ4#4": "(연립)빌라",
|
||||
"KDQ4#5": "원룸",
|
||||
"KDQ4#6": "기타",
|
||||
|
||||
// 평형
|
||||
"KDQ5#1": "19평 이하",
|
||||
"KDQ5#2": "20평형 대",
|
||||
"KDQ5#3": "30평형 대",
|
||||
"KDQ5#4": "40평형 대",
|
||||
"KDQ5#5": "50평형 대 이상",
|
||||
|
||||
// 권역
|
||||
"KSQ4_R_R#1": "서울, 인천, 경기도",
|
||||
"KSQ4_R_R#2": "경남, 부산, 울산",
|
||||
"KSQ4_R_R#3": "경북, 대구",
|
||||
"KSQ4_R_R#4": "전라도, 광주",
|
||||
"KSQ4_R_R#5": "충청, 대전, 세종",
|
||||
"KSQ4_R_R#6": "강원, 제주",
|
||||
|
||||
// 소득
|
||||
"KDQ3_DB#1": "299만원 이하",
|
||||
"KDQ3_DB#2": "300~599만원 이하",
|
||||
"KDQ3_DB#3": "600~899만원 이하",
|
||||
"KDQ3_DB#4": "900만원 이상",
|
||||
} as const;
|
||||
45
src/const/lg-survey.const.ts
Normal file
45
src/const/lg-survey.const.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
export const QID_SURVEY_TITLE: Record<string, string> = {
|
||||
"KQX3_3": "Q. 귀하께서 [#YEAR#]년에 구매하신 제품의 브랜드는 어떻게 되십니까?",
|
||||
"KQB1": "Q. 귀하께서 [#YEAR#]년에 제품을 구매하실 때 구매를 고려하셨던 브랜드는 무엇입니까? 모두 선택하여 주시기 바랍니다",
|
||||
"KQX3_4": "Q. 귀하께서 [#YEAR#]년에 구매하신 제품의 타입은 어떻게 되십니까?",
|
||||
"KQX3_5": "Q. 귀하께서 [#YEAR#]년에 구매하신 제품의 깊이 타입은 어떻게 되십니까?",
|
||||
"KQX3_6": "Q. 귀하께서 [#YEAR#]년에 구매하신 제품의 용량은 어떻게 되십니까?",
|
||||
"KQX3_7": "Q. 귀하께서 [#YEAR#]년에 구매하신 제품의 설치 형태는 어떻게 되십니까?",
|
||||
"KQX3_8": "Q. 귀하께서 [#YEAR#]년에 구매하신 제품은 메인 가구와 어떻게 배치되어 있습니까?",
|
||||
"KQX3_9": "Q. 귀하께서 [#YEAR#]년에 구매하신 제품에 포함되어 있는 기능이 있으십니까? 모두 선택해 주세요.",
|
||||
"KQX3_10": "Q. 귀하께서 [#YEAR#]년에 구매하신 제품의 스크린 사이즈는 어떻게 되십니까?",
|
||||
"KQX3_11": "Q. 귀하께서 [#YEAR#]년에 구매하신 제품의 가장 주된 용도는 무엇입니까?",
|
||||
"KQX3_12": "Q. 귀하께서 [#YEAR#]년에 구매하신 제품은 스마트 모니터(자체적으로 OS를 가지고 있어, 기타 기기 연결 없이 작동이 가능한 모니터) 입니까?",
|
||||
"KQX3_13": "Q. 보유하고 계신 제품의 구동 방식은 어떻게 되십니까?",
|
||||
"KQB2": "Q. 귀하께서는 [#YEAR#]년에 제품을 신규로 구입하신 건가요? 교체/추가 구입하신 건가요? 한 가지만 선택해주세요",
|
||||
"KQB3": "Q. 귀하께서 [#YEAR#]년에 제품을 구입하신 이유/계기(상황)는 무엇입니까? 가장 주요한 이유/계기를 한 가지만 선택해주세요",
|
||||
"KQB4_NET": "Q. 최종적으로 제품을 구매하신 곳은 어디십니까? 한 가지만 선택해주세요",
|
||||
"KQB4": "Q. 최종적으로 제품을 구매하신 곳은 어디십니까? 한 가지만 선택해주세요",
|
||||
"KQX3_2_1": "Q. 귀하께서는 제품을 어떤 방식으로 구입하셨습니까? 한가지만 선택해주세요",
|
||||
"KQA3_3": "Q. 보유하고 계신 제품의 브랜드는 어떻게 되십니까?",
|
||||
"KQA3_4": "Q. 보유하고 계신 제품의 타입은 어떻게 되십니까?",
|
||||
"KQA3_5": "Q. 보유하고 계신 제품의 깊이 타입은 어떻게 되십니까?",
|
||||
"KQA3_6": "Q. 보유하고 계신 제품의 용량은 어떻게 되십니까?",
|
||||
"KQA3_7": "Q. 보유하고 계신 제품의 설치 형태는 어떻게 되십니까?",
|
||||
"KQA3_8": "Q. 보유하고 계신 제품은 메인 가구와 어떻게 배치되어 있습니까?",
|
||||
"KQA3_9": "Q. 보유하고 계신 제품에 포함되어 있는 기능이 있으십니까? 모두 선택해 주세요.",
|
||||
"KQA3_10": "Q. 보유하고 계신 제품의 스크린 사이즈는 어떻게 되십니까?",
|
||||
"KQA3_11": "Q. 보유하고 계신 제품의 가장 주된 용도는 무엇입니까?",
|
||||
"KQA3_12": "Q. 보유하고 계신 제품은 스마트 모니터(자체적으로 OS를 가지고 있어, 기타 기기 연결 없이 작동이 가능한 모니터) 입니까?",
|
||||
"KQA3_13": "Q. 보유하고 계신 제품의 구동 방식은 어떻게 되십니까?",
|
||||
"KQA3_1": "Q. 보유하고 계신 제품을 구매 또는 보유하게 된 경로가 어떻게 되십니까? ",
|
||||
"KQA3_2_1": "Q. 귀하께서는 제품을 어떤 방식으로 구입하셨습니까? ",
|
||||
"KQC2": "Q. 귀하께서 [#NEXT_YEAR#]년 이내 구입을 고려하시는 제품의 브랜드로 고려하고 계신 것은 무엇입니까? 모두 선택해주세요",
|
||||
"KQC3_1": "Q. 귀하께서 [#NEXT_YEAR#]년 이내 구입을 고려하시는 제품의 타입으로 고려하고 계신 것은 무엇입니까? 모두 선택해주세요",
|
||||
"KQC3_2": "Q. 귀하께서 [#NEXT_YEAR#]년 이내 구입을 고려하시는 제품의 깊이 타입으로 고려하고 계신 것은 무엇입니까? 모두 선택해주세요",
|
||||
"KQC3_3": "Q. 귀하께서 [#NEXT_YEAR#]년 이내 구입을 고려하시는 제품의 설치 형태로 고려하고 계신 것은 무엇입니까? 모두 선택해주세요",
|
||||
"KQC3_4": "Q. 귀하께서 [#NEXT_YEAR#]년 이내 구입을 고려하시는 제품의 설치 방식을 실제 공간에 구현하기 위해서 다음 중 어떤 방식의 시공이 필요하다고 생각하십니까?",
|
||||
"KQC3_5": "Q. 귀하께서 [#NEXT_YEAR#]년 이내 구입을 고려하시는 <냉장고와 김치냉장고>를 어떤 형태로 설치하실 계획이십니까?",
|
||||
"KQC3_6": "Q. 귀하께서 [#NEXT_YEAR#]년 이내 구입을 고려하시는 제품은 어디에 설치하실 계획이십니까?",
|
||||
"KQC3_7": "Q. 귀하께서 [#NEXT_YEAR#]년 이내 구입을 고려하시는 제품은 어떤 환경에 설치하실 계획이십니까?",
|
||||
"KQC3_8": "Q. 귀하께서 [#NEXT_YEAR#]년 이내 구입을 고려하시는 제품의 특징으로 고려하고 계신 것은 무엇입니까? 모두 선택해주세요",
|
||||
"KQC5": "Q. 귀하께서 [#NEXT_YEAR#]년 이내 구입을 고려하시는 제품을 신규로 구입하실 건가요? 교체/추가 구입하실 건가요? 한 가지만 선택해주세요",
|
||||
"KQC6_NET": "Q. [#NEXT_YEAR#]년 이내 구입을 고려하시는 제품을 구매하고 싶으신 곳은 어디십니까? 한 가지만 선택해주세요",
|
||||
"KQC6": "Q. [#NEXT_YEAR#]년 이내 구입을 고려하시는 제품을 구매하고 싶으신 곳은 어디십니까? 한 가지만 선택해주세요",
|
||||
"KQC7": "Q. 그렇다면, [#NEXT_YEAR#]년 이내 구입을 고려하시는 제품을 어떤 방식으로 구입하길 원하십니까? 한가지만 선택해주세요",
|
||||
}
|
||||
@@ -1,511 +0,0 @@
|
||||
import {BannerKey, CategoryFieldSpec, LifeStageRow} from "@/types/lg";
|
||||
import {GaugeColumn} from "@/components/lge-dashboard";
|
||||
import {CategoryTargetData, CategoryTargetType} from "@/config/filter.types";
|
||||
|
||||
export const SITE_TITLE = 'LGE CX Dashboard';
|
||||
|
||||
export const YEARS = ["2023", "2024", "2025"];
|
||||
export const LAST_YEAR = YEARS.at(-1)!;
|
||||
|
||||
export const GAP_WORDING = "전년 대비 GAP(%p)";
|
||||
export const UNIT_TEXT = "(단위 %)"
|
||||
export const SAMPLE_SIZE_NOTICE = "* 30표본 미만 해석에 주의";
|
||||
|
||||
export const BRAND_LIST = ['Cbrand', '삼성', 'LG'];
|
||||
|
||||
export const PRODUCT_KEY_MAP = {
|
||||
"KPRODUCT#1": "냉장고",
|
||||
"KPRODUCT#2": "김치 냉장고",
|
||||
"KPRODUCT#3": "식기 세척기",
|
||||
"KPRODUCT#4": "정수기",
|
||||
"KPRODUCT#5": "전기 레인지",
|
||||
"KPRODUCT#6": "음식물처리기",
|
||||
|
||||
"KPRODUCT#7": "세탁기",
|
||||
"KPRODUCT#8": "건조기",
|
||||
"KPRODUCT#9": "청소기",
|
||||
"KPRODUCT#10": "로봇 청소기",
|
||||
"KPRODUCT#11": "의류 관리기",
|
||||
|
||||
"KPRODUCT#12": "에어컨",
|
||||
"KPRODUCT#13": "공기 청정기",
|
||||
|
||||
"KPRODUCT#14": "TV",
|
||||
"KPRODUCT#15": "모니터",
|
||||
"KPRODUCT#16": "노트북",
|
||||
} as const;
|
||||
|
||||
export const BANNER_KEY_MAP = {
|
||||
// 라이프 스테이지
|
||||
"KLIFEstAGE#1": "미혼",
|
||||
"KLIFEstAGE#2": "무자녀",
|
||||
"KLIFEstAGE#3": "미취학",
|
||||
"KLIFEstAGE#4": "취학자녀",
|
||||
"KLIFEstAGE#5": "성인자녀",
|
||||
"KLIFEstAGE#6": "독립시니어",
|
||||
|
||||
// 가구원수
|
||||
"KSQ8_R_DB#1": "1인 가구",
|
||||
"KSQ8_R_DB#2": "2인 가구",
|
||||
"KSQ8_R_DB#3": "3인 가구",
|
||||
"KSQ8_R_DB#4": "4인 이상 가구",
|
||||
|
||||
// 연령
|
||||
"KSQ2_R_R#1": "20대",
|
||||
"KSQ2_R_R#2": "30대",
|
||||
"KSQ2_R_R#3": "40대",
|
||||
"KSQ2_R_R#4": "50대",
|
||||
"KSQ2_R_R#5": "60대",
|
||||
|
||||
// 점유형태
|
||||
"KDQ6#1": "자가",
|
||||
"KDQ6#2": "전세",
|
||||
"KDQ6#3": "전+월세 (보증금有)",
|
||||
"KDQ6#4": "월세 (보증금無)",
|
||||
"KDQ6#5": "기타",
|
||||
|
||||
// 주거형태
|
||||
"KDQ4#1": "아파트",
|
||||
"KDQ4#2": "주택",
|
||||
"KDQ4#3": "오피스텔",
|
||||
"KDQ4#4": "(연립)빌라",
|
||||
"KDQ4#5": "원룸",
|
||||
"KDQ4#6": "기타",
|
||||
|
||||
// 평형
|
||||
"KDQ5#1": "19평 이하",
|
||||
"KDQ5#2": "20평형 대",
|
||||
"KDQ5#3": "30평형 대",
|
||||
"KDQ5#4": "40평형 대",
|
||||
"KDQ5#5": "50평형 대 이상",
|
||||
|
||||
// 권역
|
||||
"KSQ4_R_R#1": "서울, 인천, 경기도",
|
||||
"KSQ4_R_R#2": "경남, 부산, 울산",
|
||||
"KSQ4_R_R#3": "경북, 대구",
|
||||
"KSQ4_R_R#4": "전라도, 광주",
|
||||
"KSQ4_R_R#5": "충청, 대전, 세종",
|
||||
"KSQ4_R_R#6": "강원, 제주",
|
||||
|
||||
// 소득
|
||||
"KDQ3_DB#1": "299만원 이하",
|
||||
"KDQ3_DB#2": "300~599만원 이하",
|
||||
"KDQ3_DB#3": "600~899만원 이하",
|
||||
"KDQ3_DB#4": "900만원 이상",
|
||||
} as const;
|
||||
|
||||
export const LIFE_STAGE_COLUMNS: GaugeColumn<LifeStageRow>[] = [
|
||||
{ key: "item", header: "", headRowSpan:2, rowHead: true, render: (r) => r.item },
|
||||
|
||||
{ key: "total", header: "전체", headRowSpan:2, max: 100, align: "left", cellType:"number"},
|
||||
{ key: "KLIFEstAGE#1", header: "미혼" , headRowSpan:2, max: 100 , align: "left"},
|
||||
|
||||
{ key: "KLIFEstAGE#2", header: "무자녀", group: "기혼", max: 100 , align: "left"},
|
||||
{ key: "KLIFEstAGE#3", header: "미취학", group: "기혼", max: 100 , align: "left"},
|
||||
{ key: "KLIFEstAGE#4", header: "취학자녀", group: "기혼", max: 100 , align: "left"},
|
||||
{ key: "KLIFEstAGE#5", header: "성인자녀", group: "기혼", max: 100 , align: "left"},
|
||||
|
||||
{ key: "KLIFEstAGE#6", header: "독립\n시니어", headRowSpan:2, max: 100 , align: "left"},
|
||||
];
|
||||
|
||||
export const LIFE_STAGE_GROUPS = [
|
||||
{ title: "대형가전 군", items: ["KPRODUCT#1", "KPRODUCT#7", "KPRODUCT#8", "KPRODUCT#12", "KPRODUCT#14", "KPRODUCT#2", "KPRODUCT#3", "KPRODUCT#11"] },
|
||||
{ title: "소형가전 군", items: ["KPRODUCT#9", "KPRODUCT#13", "KPRODUCT#4"] },
|
||||
{ title: "신가전 군", items: ["KPRODUCT#10", "KPRODUCT#6"] },
|
||||
] as const;
|
||||
|
||||
export const PRODUCT_KEYS = Object.keys(PRODUCT_KEY_MAP) as Array<keyof typeof PRODUCT_KEY_MAP>;
|
||||
export const PRODUCTS = Object.values(PRODUCT_KEY_MAP) as Array<string>;
|
||||
|
||||
export const PRODUCTS_FILTER_ITEM = [
|
||||
{
|
||||
path: "kitchen",
|
||||
items: [
|
||||
"KPRODUCT#1", // 냉장고
|
||||
"KPRODUCT#2", // 김치 냉장고
|
||||
"KPRODUCT#3", // 식기 세척기
|
||||
"KPRODUCT#4", // 정수기
|
||||
"KPRODUCT#5", // 전기 레인지
|
||||
"KPRODUCT#6", // 음식물처리기
|
||||
],
|
||||
},
|
||||
{
|
||||
path: "living",
|
||||
items: [
|
||||
"KPRODUCT#7", // 세탁기
|
||||
"KPRODUCT#8", // 건조기
|
||||
"KPRODUCT#9", // 청소기
|
||||
"KPRODUCT#10", // 로봇 청소기
|
||||
"KPRODUCT#11", // 의류 관리기
|
||||
],
|
||||
},
|
||||
{
|
||||
path: "es",
|
||||
items: [
|
||||
"KPRODUCT#12", // 에어컨
|
||||
"KPRODUCT#13", // 공기 청정기
|
||||
],
|
||||
},
|
||||
{
|
||||
path: "ms",
|
||||
items: [
|
||||
"KPRODUCT#14", // TV
|
||||
"KPRODUCT#15", // 모니터
|
||||
"KPRODUCT#16", // 노트북
|
||||
],
|
||||
},
|
||||
] as const;
|
||||
|
||||
export const BANNER_KEYS = Object.keys(BANNER_KEY_MAP) as Array<keyof typeof BANNER_KEY_MAP>;
|
||||
export const BANNER_KEY = Object.keys(BANNER_KEY_MAP).reduce((acc, k) => {
|
||||
(acc as any)[k] = k;
|
||||
return acc;
|
||||
}, {} as { [K in BannerKey]: K });
|
||||
|
||||
export const BANNER_GROUP = {
|
||||
lifeStage: {
|
||||
label: "라이프스테이지 별",
|
||||
keys: [
|
||||
BANNER_KEY["KLIFEstAGE#1"],
|
||||
BANNER_KEY["KLIFEstAGE#2"],
|
||||
BANNER_KEY["KLIFEstAGE#3"],
|
||||
BANNER_KEY["KLIFEstAGE#4"],
|
||||
BANNER_KEY["KLIFEstAGE#5"],
|
||||
BANNER_KEY["KLIFEstAGE#6"],
|
||||
],
|
||||
},
|
||||
household: {
|
||||
label: "가구원수 별",
|
||||
keys: [
|
||||
BANNER_KEY["KSQ8_R_DB#1"],
|
||||
BANNER_KEY["KSQ8_R_DB#2"],
|
||||
BANNER_KEY["KSQ8_R_DB#3"],
|
||||
BANNER_KEY["KSQ8_R_DB#4"],
|
||||
],
|
||||
},
|
||||
age: {
|
||||
label: "연령",
|
||||
keys: [
|
||||
BANNER_KEY["KSQ2_R_R#1"],
|
||||
BANNER_KEY["KSQ2_R_R#2"],
|
||||
BANNER_KEY["KSQ2_R_R#3"],
|
||||
BANNER_KEY["KSQ2_R_R#4"],
|
||||
BANNER_KEY["KSQ2_R_R#5"],
|
||||
],
|
||||
},
|
||||
occupancy: {
|
||||
label: "입주 형태",
|
||||
keys: [
|
||||
BANNER_KEY["KDQ6#1"],
|
||||
BANNER_KEY["KDQ6#2"],
|
||||
BANNER_KEY["KDQ6#3"],
|
||||
BANNER_KEY["KDQ6#4"],
|
||||
BANNER_KEY["KDQ6#5"],
|
||||
],
|
||||
},
|
||||
housing: {
|
||||
label: "주거 형태",
|
||||
keys: [
|
||||
BANNER_KEY["KDQ4#1"],
|
||||
BANNER_KEY["KDQ4#2"],
|
||||
BANNER_KEY["KDQ4#3"],
|
||||
BANNER_KEY["KDQ4#4"],
|
||||
BANNER_KEY["KDQ4#5"],
|
||||
BANNER_KEY["KDQ4#6"],
|
||||
],
|
||||
},
|
||||
houseSize: {
|
||||
label: "거주 평형",
|
||||
keys: [
|
||||
BANNER_KEY["KDQ5#1"],
|
||||
BANNER_KEY["KDQ5#2"],
|
||||
BANNER_KEY["KDQ5#3"],
|
||||
BANNER_KEY["KDQ5#4"],
|
||||
BANNER_KEY["KDQ5#5"],
|
||||
],
|
||||
},
|
||||
region: {
|
||||
label: "거주 지역",
|
||||
keys: [
|
||||
BANNER_KEY["KSQ4_R_R#1"],
|
||||
BANNER_KEY["KSQ4_R_R#2"],
|
||||
BANNER_KEY["KSQ4_R_R#3"],
|
||||
BANNER_KEY["KSQ4_R_R#4"],
|
||||
BANNER_KEY["KSQ4_R_R#5"],
|
||||
BANNER_KEY["KSQ4_R_R#6"],
|
||||
],
|
||||
},
|
||||
income: {
|
||||
label: "소득수준",
|
||||
keys: [
|
||||
BANNER_KEY["KDQ3_DB#1"],
|
||||
BANNER_KEY["KDQ3_DB#2"],
|
||||
BANNER_KEY["KDQ3_DB#3"],
|
||||
BANNER_KEY["KDQ3_DB#4"],
|
||||
],
|
||||
},
|
||||
} as const;
|
||||
|
||||
export const BANNER_GROUP_KEY = Object.keys(BANNER_GROUP) as string[];
|
||||
|
||||
export const CATEGORY_PAGE_FIELDS: Record<CategoryTargetData, CategoryFieldSpec[]> = {
|
||||
[CategoryTargetData.PROFILE]: [
|
||||
{
|
||||
title: {
|
||||
[CategoryTargetType.PENETRATION]: "보유율"
|
||||
, [CategoryTargetType.PURCHASE]: "구매율"
|
||||
, [CategoryTargetType.INTENDED]: "향후 구매율"
|
||||
},
|
||||
requestKey: "category_${keyBase}",
|
||||
chartMode:"none",
|
||||
qidByMode: {
|
||||
[CategoryTargetType.PENETRATION]: "KQA1"
|
||||
, [CategoryTargetType.PURCHASE]: "KQA3_2"
|
||||
, [CategoryTargetType.INTENDED]: "KQC1"
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "보유대수",
|
||||
requestKey: "category_penetration_count",
|
||||
chartMode:"none",
|
||||
qidByMode: {
|
||||
[CategoryTargetType.PENETRATION]: "KQA2"
|
||||
},
|
||||
},
|
||||
],
|
||||
|
||||
[CategoryTargetData.PENETRATION_CHANGE]: [
|
||||
{
|
||||
title: "보급률 변화",
|
||||
requestKey: "category_${keyBase}",
|
||||
chartMode:"none",
|
||||
qidByMode: {
|
||||
[CategoryTargetType.PENETRATION]: "KQA1"
|
||||
},
|
||||
},
|
||||
],
|
||||
|
||||
[CategoryTargetData.BRAND]: [
|
||||
{
|
||||
title: "브랜드",
|
||||
requestKey: "category_${keyBase}_brand",
|
||||
chartMode:"reverseStack",
|
||||
qidByMode: {
|
||||
[CategoryTargetType.PENETRATION]: "KQA3_3",
|
||||
[CategoryTargetType.PURCHASE]: "KQX3_3",
|
||||
},
|
||||
},
|
||||
{
|
||||
title: {
|
||||
[CategoryTargetType.PENETRATION]: "",
|
||||
[CategoryTargetType.PURCHASE]: "구매 고려 브랜드",
|
||||
[CategoryTargetType.INTENDED]: "브랜드",
|
||||
},
|
||||
requestKey: "category_${keyBase}_consider_brand",
|
||||
chartMode:"horizontal",
|
||||
qidByMode: {
|
||||
[CategoryTargetType.PURCHASE]: "KQB1",
|
||||
[CategoryTargetType.INTENDED]: "KQC2",
|
||||
},
|
||||
},
|
||||
],
|
||||
|
||||
[CategoryTargetData.TYPE_SPEC]: [
|
||||
{
|
||||
title: "타입",
|
||||
requestKey: "category_${keyBase}_type",
|
||||
chartMode: "horizontal",
|
||||
qidByMode: {
|
||||
[CategoryTargetType.PENETRATION]: "KQA3_4",
|
||||
[CategoryTargetType.PURCHASE]: "KQX3_4",
|
||||
[CategoryTargetType.INTENDED]: "KQC3_1" }
|
||||
},
|
||||
{
|
||||
title: "깊이 타입",
|
||||
requestKey: "category_${keyBase}_depthType",
|
||||
chartMode: "horizontal",
|
||||
qidByMode: {
|
||||
[CategoryTargetType.PENETRATION]: "KQA3_5",
|
||||
[CategoryTargetType.PURCHASE]: "KQX3_5",
|
||||
[CategoryTargetType.INTENDED]: "KQC3_2"
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "용량",
|
||||
requestKey: "category_${keyBase}_capacity",
|
||||
chartMode: "horizontal",
|
||||
qidByMode: {
|
||||
[CategoryTargetType.PENETRATION]: "KQA3_6",
|
||||
[CategoryTargetType.PURCHASE]: "KQX3_6"
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "설치 형태",
|
||||
requestKey: "category_${keyBase}_installType",
|
||||
chartMode: "horizontal",
|
||||
qidByMode: {
|
||||
[CategoryTargetType.PENETRATION]: "KQA3_7",
|
||||
[CategoryTargetType.PURCHASE]: "KQX3_7",
|
||||
[CategoryTargetType.INTENDED]: "KQC3_3"
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "시공 방식",
|
||||
requestKey: "category_${keyBase}_installMethod",
|
||||
chartMode: "horizontal",
|
||||
qidByMode: {
|
||||
[CategoryTargetType.INTENDED]: "KQC3_4"
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "냉장고 & 김치냉장고 설치 형태",
|
||||
requestKey: "category_${keyBase}_fridgeInstallType",
|
||||
chartMode: "horizontal",
|
||||
qidByMode: {
|
||||
[CategoryTargetType.INTENDED]: "KQC3_5"
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "설치 위치",
|
||||
requestKey: "category_${keyBase}_installLocation",
|
||||
chartMode: "horizontal",
|
||||
qidByMode: {
|
||||
[CategoryTargetType.INTENDED]: "KQC3_6"
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "배치/설치환경",
|
||||
requestKey: "category_${keyBase}_installEnv",
|
||||
chartMode: "horizontal",
|
||||
qidByMode: {
|
||||
[CategoryTargetType.PENETRATION]: "KQA3_8",
|
||||
[CategoryTargetType.PURCHASE]: "KQX3_8",
|
||||
[CategoryTargetType.INTENDED]: "KQC3_7"
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "구입 고려 특징",
|
||||
requestKey: "category_${keyBase}_buyConsiderations",
|
||||
chartMode: "horizontal",
|
||||
qidByMode: {
|
||||
[CategoryTargetType.INTENDED]: "KQC3_8"
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "기능",
|
||||
requestKey: "category_${keyBase}_features",
|
||||
chartMode: "horizontal",
|
||||
qidByMode: {
|
||||
[CategoryTargetType.PENETRATION]: "KQA3_9",
|
||||
[CategoryTargetType.PURCHASE]: "KQX3_9"
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "스크린 사이즈",
|
||||
requestKey: "category_${keyBase}_screenSize",
|
||||
chartMode: "horizontal",
|
||||
qidByMode: {
|
||||
[CategoryTargetType.PENETRATION]: "KQA3_10",
|
||||
[CategoryTargetType.PURCHASE]: "KQX3_10"
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "용도",
|
||||
requestKey: "category_${keyBase}_usage",
|
||||
chartMode: "horizontal",
|
||||
qidByMode: {
|
||||
[CategoryTargetType.PENETRATION]: "KQA3_11",
|
||||
[CategoryTargetType.PURCHASE]: "KQX3_11"
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "스마트 모니터 여부",
|
||||
requestKey: "category_${keyBase}_isSmartMonitor",
|
||||
chartMode: "horizontal",
|
||||
qidByMode: {
|
||||
[CategoryTargetType.PENETRATION]: "KQA3_12",
|
||||
[CategoryTargetType.PURCHASE]: "KQX3_12"
|
||||
}
|
||||
},
|
||||
],
|
||||
|
||||
[CategoryTargetData.BEHAVIOR]: [
|
||||
{
|
||||
title: {
|
||||
[CategoryTargetType.PENETRATION]: "보유 경로"
|
||||
, [CategoryTargetType.PURCHASE]: "구입 행태"
|
||||
, [CategoryTargetType.INTENDED]: "구입 행태"
|
||||
},
|
||||
requestKey: "category_${keyBase}_behavior",
|
||||
chartMode: "horizontal",
|
||||
qidByMode: {
|
||||
[CategoryTargetType.PENETRATION]: "KQA3_1",
|
||||
[CategoryTargetType.PURCHASE]: "KQB2",
|
||||
[CategoryTargetType.INTENDED]: "KQC5"
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "구입 계기",
|
||||
requestKey: "category_${keyBase}_chance",
|
||||
chartMode: "horizontal",
|
||||
qidByMode: {
|
||||
[CategoryTargetType.PURCHASE]: "KQB3"
|
||||
},
|
||||
},
|
||||
],
|
||||
|
||||
[CategoryTargetData.PURCHASE_CHANNEL]: [
|
||||
{
|
||||
title: "구매 채널(온/오프라인)",
|
||||
requestKey: "category_${keyBase}_channel",
|
||||
chartMode: "reverseStack",
|
||||
qidByMode: {
|
||||
[CategoryTargetType.PURCHASE]: "KQB4_NET",
|
||||
[CategoryTargetType.INTENDED]: "KQC6_NET"
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "구매 채널(상세)",
|
||||
requestKey: "category_${keyBase}_channel_detail",
|
||||
chartMode: "horizontal",
|
||||
qidByMode: {
|
||||
[CategoryTargetType.PURCHASE]: "KQB4",
|
||||
[CategoryTargetType.INTENDED]: "KQC6"
|
||||
},
|
||||
},
|
||||
],
|
||||
|
||||
[CategoryTargetData.PAYMENT_METHOD]: [
|
||||
{
|
||||
title: "구매형식",
|
||||
requestKey: "category_${keyBase}_method",
|
||||
chartMode:"reverseStack",
|
||||
qidByMode: {
|
||||
[CategoryTargetType.PENETRATION]: "KQA3_2_1",
|
||||
[CategoryTargetType.PURCHASE]: "KQX3_2_1",
|
||||
[CategoryTargetType.INTENDED]: "KQC7"
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
/** 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;
|
||||
|
||||
export const CHART_COLOR_BY_YEAR = Object.fromEntries(
|
||||
YEARS.map((year, i) => [
|
||||
year,
|
||||
`--chart-${YEARS.length-i}-t`,
|
||||
])
|
||||
) as Record<(typeof YEARS)[number], string>;
|
||||
|
||||
export const CHART_FOCUS_COLOR_BY_YEAR = Object.fromEntries(
|
||||
YEARS.map((year, i) => [
|
||||
year,
|
||||
`--chart-${YEARS.length-i}`,
|
||||
])
|
||||
) as Record<(typeof YEARS)[number], string>;
|
||||
@@ -1,4 +1,4 @@
|
||||
import {SubMenuItem, TopMenuItem} from "@/config/menu.types";
|
||||
import {SubMenuItem, TopMenuItem} from "@/types/menu.types";
|
||||
|
||||
export const topMenus: TopMenuItem[] = [
|
||||
{
|
||||
@@ -59,4 +59,4 @@ export const categorySubMenus: SubMenuItem[] = [
|
||||
label: "MS",
|
||||
path: "/category/ms",
|
||||
},
|
||||
]
|
||||
]
|
||||
@@ -1,4 +1,4 @@
|
||||
import { CHART_GRID_DEFAULTS, BAR_WIDTHS } from "@/const/chartConst";
|
||||
import { AXIS_HIDE_Y_STYLE, BAR_WIDTHS, CHART_GRID_DEFAULTS } from "@/components/lge-dashboard/chart/chart.config";
|
||||
import {ChartData, NewNumber} from "@/components/lge-dashboard";
|
||||
|
||||
export function reverseCategories<T extends ChartData>(data: T): T {
|
||||
@@ -180,9 +180,7 @@ export function createValueAxis(
|
||||
if (hideStyle) {
|
||||
return {
|
||||
...base,
|
||||
axisLabel: { show: false },
|
||||
axisTick: { show: false },
|
||||
axisLine: { show: false },
|
||||
...AXIS_HIDE_Y_STYLE,
|
||||
splitLine: { show: false },
|
||||
...overrides,
|
||||
};
|
||||
|
||||
@@ -4,15 +4,12 @@ import {
|
||||
BannerRow, BuildPageModeConfigResult,
|
||||
ProductResponse, ProductRow,
|
||||
StatisticsRequest
|
||||
} from "@/types/lg";
|
||||
} from "@/types/lg.types";
|
||||
import {ChartData} from "@/components/lge-dashboard";
|
||||
import {
|
||||
BANNER_GROUP,
|
||||
BANNER_KEYS,
|
||||
CATEGORY_PAGE_FIELDS,
|
||||
GAP_WORDING,
|
||||
PRODUCT_KEYS
|
||||
} from "@/const/lgConst";
|
||||
import {API_DECIMAL_POINT, GAP_WORDING, VIEW_DECIMAL_POINT} from "@/const/lg-common.const";
|
||||
import {BANNER_GROUP, BANNER_KEYS} from "@/const/lg-banner.const";
|
||||
import {PRODUCT_KEYS} from "@/const/lg-product.const";
|
||||
import {CATEGORY_PAGE_FIELDS} from "@/config/lg-page.config";
|
||||
import {formatNumber} from "@/lib/utils";
|
||||
import {nextApi} from "@/lib/http-client";
|
||||
import {CategoryFilterValue} from "@/components/layout/CategoryFilter";
|
||||
@@ -56,7 +53,7 @@ export function formatRowLabel(
|
||||
|
||||
if (convertSample && t === "사례수") return "(사례수)";
|
||||
if (convertGap && t.toLowerCase() === "gap") return GAP_WORDING;
|
||||
if (convertCagr && t.toUpperCase() === "CAGR") return "CAGR(%p)";
|
||||
if (convertCagr && t.toUpperCase() === "CAGR") return "CAGR(%)";
|
||||
if (convertYear && /^\d{4}$/.test(t)) return `${t.substring(2,4)}년`;
|
||||
if (convertYear && /^\d{2}$/.test(t)) return `${t}년`;
|
||||
if (convertRate && t.endsWith("율")) return `${t.replaceAll('(%)','')}(%)`;
|
||||
@@ -66,7 +63,7 @@ export function formatRowLabel(
|
||||
}
|
||||
|
||||
export const wrapSampleRow = <T extends Record<string, unknown> & { rowLabel: string }>(
|
||||
rows: T[]
|
||||
rows: T[], replaceLabel: boolean = true
|
||||
): T[] => {
|
||||
return rows.map((r) => {
|
||||
if (!isSampleRow(r.rowLabel)) return r;
|
||||
@@ -76,18 +73,23 @@ export const wrapSampleRow = <T extends Record<string, unknown> & { rowLabel: st
|
||||
Object.entries(r).forEach(([k, v]) => {
|
||||
if (k == "year" || v == null) return;
|
||||
|
||||
if (typeof v === "number") {
|
||||
out[k] = `(${formatNumber(v)})`;
|
||||
if (
|
||||
typeof v === "number" ||
|
||||
(typeof v === "string" && v.trim() !== "" && !Number.isNaN(Number(v)))
|
||||
) {
|
||||
out[k] = `(${formatNumber(Number(v))})`;
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof v === "string") {
|
||||
// 이미 괄호면 그대로
|
||||
out[k] = v.startsWith("(") && v.endsWith(")") ? v : `(${v})`;
|
||||
return;
|
||||
}
|
||||
if(replaceLabel){
|
||||
if (typeof v === "string") {
|
||||
// 이미 괄호면 그대로
|
||||
out[k] = v.startsWith("(") && v.endsWith(")") ? v : `(${v})`;
|
||||
return;
|
||||
}
|
||||
|
||||
out[k] = `(${String(v)})`;
|
||||
out[k] = `(${String(v)})`;
|
||||
}
|
||||
});
|
||||
|
||||
return out as T;
|
||||
@@ -393,16 +395,29 @@ export const buildCategoryFilter = (
|
||||
return Object.keys(out).length ? out : undefined;
|
||||
}
|
||||
|
||||
const fixedDecimalPoint = (n: number, decimalPoint?: number): string => {
|
||||
decimalPoint ??= API_DECIMAL_POINT;
|
||||
return n.toFixed(decimalPoint);
|
||||
};
|
||||
|
||||
export const roundNumber = (num: number|null, decimalPoint?: number) => {
|
||||
if(num == null) return null;
|
||||
|
||||
decimalPoint ??= VIEW_DECIMAL_POINT;
|
||||
const factor = 10 ** decimalPoint;
|
||||
return Math.round(num * factor) / factor;
|
||||
};
|
||||
|
||||
export const calcGapProductRow = (after: ProductRow, before: ProductRow): ProductRow => {
|
||||
const out: ProductRow = {
|
||||
year: after?.year ?? "",
|
||||
rowLabel: "gap",
|
||||
total: String(Number(after?.total ?? "0") - Number(before?.total ?? "0")),
|
||||
total: fixedDecimalPoint(Number(after?.total ?? "0") - Number(before?.total ?? "0")),
|
||||
};
|
||||
for (const k of PRODUCT_KEYS) {
|
||||
const a = after? after[k] ?? "0" : "0";
|
||||
const b = before? before[k] ?? "0" : "0";
|
||||
out[k] = String(Number(a) - Number(b));
|
||||
out[k] = fixedDecimalPoint(Number(a) - Number(b));
|
||||
}
|
||||
return out;
|
||||
};
|
||||
@@ -411,17 +426,23 @@ export const calcGapBannerRow = (after: BannerRow, before: BannerRow): BannerRow
|
||||
const out: BannerRow = {
|
||||
year: after?.year ?? "",
|
||||
rowLabel: "gap",
|
||||
total: String(Number(after?.total ?? "0") - Number(before?.total ?? "0")),
|
||||
total: fixedDecimalPoint(Number(after?.total ?? "0") - Number(before?.total ?? "0")),
|
||||
};
|
||||
for (const k of BANNER_KEYS) {
|
||||
const a = after? after[k] ?? "0" : "0";
|
||||
const b = before? before[k] ?? "0" : "0";
|
||||
out[k] = String(Number(a) - Number(b));
|
||||
out[k] = fixedDecimalPoint(Number(a) - Number(b));
|
||||
}
|
||||
return out;
|
||||
};
|
||||
|
||||
const round1 = (n: number) => Math.round(n * 10) / 10;
|
||||
const calcCagr = (after: number, before: number, years:number): number => {
|
||||
const power = Math.pow(after / before, 1 / years);
|
||||
const cagr = power - 1;
|
||||
const cagr100 = cagr * 100;
|
||||
|
||||
return cagr100;
|
||||
};
|
||||
|
||||
export const calcCagrRow = (after: ProductRow, before: ProductRow): ProductRow => {
|
||||
const years = 2; // 24 -> 26
|
||||
@@ -433,32 +454,32 @@ export const calcCagrRow = (after: ProductRow, before: ProductRow): ProductRow =
|
||||
|
||||
// total은 참고용으로만: (26/24) CAGR %
|
||||
out.total =
|
||||
Number(before?.total ?? "0") > 0 ? String(round1((Math.pow(Number(after?.total ?? "0") / Number(before?.total ?? "0"), 1 / years) - 1) * 100)) : "0";
|
||||
fixedDecimalPoint((before?.total ?? "0") > "0" ? calcCagr(Number(after?.total ?? "0"), Number(before?.total ?? "0"), years) : 0, 1);
|
||||
|
||||
for (const k of PRODUCT_KEYS) {
|
||||
const vBefore = before? before[k] ?? "0" : "0";
|
||||
const vAfter = after? after[k] ?? "0" : "0";
|
||||
out[k] = Number(vBefore) > 0 ? String(round1((Math.pow(Number(vAfter) / Number(vBefore), 1 / years) - 1) * 100)) : "0";
|
||||
out[k] = fixedDecimalPoint(Number(vBefore) > 0 ? calcCagr(Number(vAfter), Number(vBefore), years) : 0, 1);
|
||||
}
|
||||
return out;
|
||||
};
|
||||
|
||||
|
||||
export const makeTotalBasePct = (t:number|string, f:number|string):number => {
|
||||
return Number(t) > 0 ? Math.round((Number(f) / Number(t)) * 100) : 0;
|
||||
return Number(t) > 0 ? (Number(f) * 100) / Number(t) : 0;
|
||||
}
|
||||
|
||||
export const calcTotalBaseRow = (label:string, totalRow: ProductRow, targetRow: ProductRow): ProductRow => {
|
||||
const out: ProductRow = {
|
||||
year: targetRow?.year ?? "",
|
||||
rowLabel: `전체 ${label} 중 자사제품 비율`,
|
||||
total: String(makeTotalBasePct(totalRow.total, targetRow.total))
|
||||
rowLabel: `조사 년도 ${label} 중 자사제품 비율 (LG ${label} ÷ 전체 ${label}) × 100`,
|
||||
total: fixedDecimalPoint(makeTotalBasePct(totalRow.total, targetRow.total))
|
||||
};
|
||||
|
||||
for (const k of PRODUCT_KEYS) {
|
||||
const t = totalRow? totalRow[k] ?? "0" : "0";
|
||||
const f = targetRow? targetRow[k] ?? "0" : "0";
|
||||
out[k] = String(makeTotalBasePct(t, f));
|
||||
out[k] = fixedDecimalPoint(makeTotalBasePct(t, f));
|
||||
}
|
||||
return out;
|
||||
|
||||
@@ -466,20 +487,24 @@ export const calcTotalBaseRow = (label:string, totalRow: ProductRow, targetRow:
|
||||
|
||||
export const withGapRow = <T>(
|
||||
rows: T[],
|
||||
calcGapRow: (last: T, secondLast: T) => T
|
||||
calcGapRow: (last: T, secondLast: T) => T,
|
||||
lastIndex: number,
|
||||
secondLastIndex: number,
|
||||
): T[] => {
|
||||
const last = rows.at(-1);
|
||||
const secondLast = rows.at(-2);
|
||||
const last = rows.at(lastIndex);
|
||||
const secondLast = rows.at(secondLastIndex);
|
||||
if (!last || !secondLast) return rows;
|
||||
return [calcGapRow(last, secondLast), ...rows];
|
||||
}
|
||||
|
||||
export const withCagrRow = <T>(
|
||||
rows: T[],
|
||||
calcCagrRow: (last: T, first: T) => T
|
||||
calcCagrRow: (last: T, first: T) => T,
|
||||
lastIndex: number,
|
||||
firstIndex: number,
|
||||
): T[] => {
|
||||
const first = rows.at(0);
|
||||
const last = rows.at(-1);
|
||||
const first = rows.at(firstIndex);
|
||||
const last = rows.at(lastIndex);
|
||||
if (!first || !last) return rows;
|
||||
return [...rows, calcCagrRow(last, first)];
|
||||
}
|
||||
@@ -515,4 +540,4 @@ export const buildPageModeConfig = (
|
||||
const variableIdMap = Object.fromEntries(fields.map((f) => [f.requestKeyResolved, f.qid])) as Record<string, string>;
|
||||
|
||||
return { fields, variableIdMap };
|
||||
};
|
||||
};
|
||||
|
||||
@@ -672,7 +672,7 @@ export function buildHeader_DataColumn<T>(cols: DataColumn<T>[]): HeaderBlock {
|
||||
* (3) BANNER_GROUP + BANNER_KEY_MAP:
|
||||
* - A1: "" (rowspan2)
|
||||
* - B1: "전체" (rowspan2) key=total
|
||||
* - C1~: group(label) (colSpan = keys.length)
|
||||
* - C1~: group(label) (colSpan = keys.ts.length)
|
||||
* - 2행: 각 key의 라벨(BANNER_KEY_MAP[key])
|
||||
*/
|
||||
export function buildHeader_Banner<K extends string>(
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import type { StatisticsRequest, ProductResponse, BannerResponse } from "@/types/lg";
|
||||
import {fetchBannerStatistics, fetchProductStatistics} from "@/lib/lg-dashboard";
|
||||
import type {StatisticsRequest} from "@/types/lg.types";
|
||||
|
||||
const sortRecord = <T,>(obj?: Record<string, T> | null): Record<string, T> => {
|
||||
if (!obj) return {};
|
||||
@@ -20,7 +18,6 @@ const sortNumberArrayRecord = (obj?: Record<string, number[]> | null): Record<st
|
||||
);
|
||||
};
|
||||
|
||||
// queryKey에 넣을 “안정적인 req”
|
||||
const normalizeReqForKey = (req: StatisticsRequest) => ({
|
||||
variableIdMap: sortRecord(req.variableIdMap),
|
||||
bannerIdList: [...(req.bannerIdList ?? [])].sort(),
|
||||
@@ -33,27 +30,3 @@ export const productStatisticsKey = (req: StatisticsRequest) =>
|
||||
|
||||
export const bannerStatisticsKey = (req: StatisticsRequest) =>
|
||||
["statistics", "banner", normalizeReqForKey(req)] as const;
|
||||
|
||||
export function useProductStatisticsQuery(req: StatisticsRequest, enabled = true) {
|
||||
return useQuery<ProductResponse>({
|
||||
queryKey: productStatisticsKey(req),
|
||||
queryFn: () => fetchProductStatistics(req),
|
||||
enabled,
|
||||
staleTime: 60_000,
|
||||
gcTime: 10 * 60_000,
|
||||
});
|
||||
}
|
||||
|
||||
export function useBannerStatisticsQuery(req: StatisticsRequest, enabled = true) {
|
||||
return useQuery<BannerResponse>({
|
||||
queryKey: bannerStatisticsKey(req),
|
||||
queryFn: () => fetchBannerStatistics(req),
|
||||
enabled,
|
||||
/*
|
||||
refetchOnMount: "always",
|
||||
staleTime: 0,
|
||||
*/
|
||||
staleTime: 60_000,
|
||||
gcTime: 10 * 60_000,
|
||||
});
|
||||
}
|
||||
28
src/query/statistics.ts
Normal file
28
src/query/statistics.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import {BannerResponse, ProductResponse, StatisticsRequest} from "@/types/lg.types";
|
||||
import {useQuery} from "@tanstack/react-query";
|
||||
import {bannerStatisticsKey, productStatisticsKey} from "@/query/keys";
|
||||
import {fetchBannerStatistics, fetchProductStatistics} from "@/lib/lg-dashboard";
|
||||
|
||||
export function useProductStatisticsQuery(req: StatisticsRequest, enabled = true) {
|
||||
return useQuery<ProductResponse>({
|
||||
queryKey: productStatisticsKey(req),
|
||||
queryFn: () => fetchProductStatistics(req),
|
||||
enabled,
|
||||
staleTime: 60_000,
|
||||
gcTime: 10 * 60_000,
|
||||
});
|
||||
}
|
||||
|
||||
export function useBannerStatisticsQuery(req: StatisticsRequest, enabled = true) {
|
||||
return useQuery<BannerResponse>({
|
||||
queryKey: bannerStatisticsKey(req),
|
||||
queryFn: () => fetchBannerStatistics(req),
|
||||
enabled,
|
||||
/*
|
||||
refetchOnMount: "always",
|
||||
staleTime: 0,
|
||||
*/
|
||||
staleTime: 60_000,
|
||||
gcTime: 10 * 60_000,
|
||||
});
|
||||
}
|
||||
@@ -3,6 +3,11 @@ export type LoginRequest = {
|
||||
userPw: string;
|
||||
};
|
||||
|
||||
export type LoginResponse = {
|
||||
accessToken: string;
|
||||
user: LoginUser;
|
||||
};
|
||||
|
||||
export type LoginUser = {
|
||||
userId: string;
|
||||
userName: string;
|
||||
|
||||
@@ -3,9 +3,12 @@ export type FilterChild = {
|
||||
label: string;
|
||||
}
|
||||
|
||||
export type TotalFilterItem = {
|
||||
export type FilterItem = {
|
||||
variable: string;
|
||||
variableName: string;
|
||||
};
|
||||
|
||||
export type TotalFilterItem = FilterItem & {
|
||||
children: FilterChild[];
|
||||
};
|
||||
|
||||
@@ -38,4 +41,4 @@ export type TargetChild = {
|
||||
export type CategoryTargetItem = {
|
||||
type: CategoryTargetType[];
|
||||
children: TargetChild[];
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,8 @@
|
||||
import {BANNER_GROUP, BANNER_KEY_MAP, PRODUCT_KEY_MAP, PRODUCTS_FILTER_ITEM} from "@/const/lgConst";
|
||||
import {CategoryTargetType} from "@/config/filter.types";
|
||||
import {BANNER_GROUP} from "@/const/lg-banner.const";
|
||||
import {BANNER_KEY_MAP, PRODUCT_KEY_MAP} from "@/const/lg-schema.const";
|
||||
import {PRODUCTS_FILTER_ITEM} from "@/const/lg-product.const";
|
||||
import {CategoryTargetType} from "@/types/filter.types";
|
||||
import {EChartsOption} from "echarts";
|
||||
|
||||
export type ProductKey = keyof typeof PRODUCT_KEY_MAP;
|
||||
export type BannerKey = keyof typeof BANNER_KEY_MAP;
|
||||
@@ -63,6 +66,8 @@ export type LifeStageRow = Record<string, unknown> & {
|
||||
"KLIFEstAGE#4": string;
|
||||
"KLIFEstAGE#5": string;
|
||||
"KLIFEstAGE#6": string;
|
||||
"KLIFEstAGE#7": string;
|
||||
"KLIFEstAGE#8": string;
|
||||
};
|
||||
|
||||
export type LifeStageGroup = {
|
||||
@@ -76,16 +81,23 @@ export type CategoryChartMode = "none" | "stack" | "reverseStack" | "horizontal"
|
||||
|
||||
export type PageData<T> = {
|
||||
title: string;
|
||||
surveyTitle: string;
|
||||
chartMode: CategoryChartMode;
|
||||
data: T[];
|
||||
chartLegend?: LegendOption;
|
||||
chartTopMargin?:number;
|
||||
chartHeight?: number | string;
|
||||
chartWidth?: number;
|
||||
data: T[];
|
||||
};
|
||||
|
||||
export type LegendOption = EChartsOption["legend"];
|
||||
|
||||
export type CategoryFieldSpec = {
|
||||
title: string | Record<CategoryTargetType, string>;
|
||||
requestKey: string;
|
||||
chartMode:CategoryChartMode;
|
||||
chartLegend?: LegendOption;
|
||||
chartTopMargin?:number;
|
||||
qidByMode: Partial<Record<CategoryTargetType, string>>; // mode별 qid (없으면 숨김/요청 제외)
|
||||
};
|
||||
|
||||
@@ -97,4 +109,4 @@ export type CategoryResolvedField = CategoryFieldSpec & {
|
||||
export type BuildPageModeConfigResult = {
|
||||
fields: CategoryResolvedField[];
|
||||
variableIdMap: Record<string, string>;
|
||||
};
|
||||
};
|
||||
@@ -10,4 +10,4 @@ export type SubMenuItem = {
|
||||
id: string;
|
||||
label: string;
|
||||
path: string;
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user