From d58c0b4dd42d37633af940e7fabf0b59777cd866 Mon Sep 17 00:00:00 2001 From: kric_jspark Date: Tue, 31 Mar 2026 11:08:30 +0900 Subject: [PATCH 01/10] =?UTF-8?q?260331=5F02=5FENH:=20=EA=B7=B8=EB=A3=B9?= =?UTF-8?q?=20=ED=97=A4=EB=8D=94=20=EB=8B=A4=EB=8B=A8=EB=8F=84=20=EA=B0=80?= =?UTF-8?q?=EB=8A=A5=ED=95=98=EA=B2=8C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sub-page/category-page/CategoryDetail.tsx | 3 +- .../category-page/PenetrationChange.tsx | 2 + .../lge-dashboard/combo/BannerSummary.tsx | 200 ++++++++-------- .../lge-dashboard/combo/CategoryByData.tsx | 222 ++++++++--------- .../lge-dashboard/table/BaseDataTable.tsx | 6 +- .../lge-dashboard/table/GaugeTable.tsx | 11 +- .../table/core/BaseTableRenderer.tsx | 47 +--- .../table/core/table-core.helpers.tsx | 163 +++++++------ src/components/lge-dashboard/types.ts | 75 +++--- src/const/lg-banner.const.ts | 149 +++++++----- src/const/lg-product.const.ts | 53 +++-- src/lib/lg-dashboard.ts | 44 +++- src/lib/lg-export-excel.ts | 224 +++++------------- 13 files changed, 577 insertions(+), 622 deletions(-) diff --git a/src/app/(pages)/(main)/category/sub-page/category-page/CategoryDetail.tsx b/src/app/(pages)/(main)/category/sub-page/category-page/CategoryDetail.tsx index d7d47fd..f739155 100644 --- a/src/app/(pages)/(main)/category/sub-page/category-page/CategoryDetail.tsx +++ b/src/app/(pages)/(main)/category/sub-page/category-page/CategoryDetail.tsx @@ -10,6 +10,7 @@ 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"; +import {wrapSampleRow} from "@/lib/lg-dashboard"; const CategoryDetail = ({ fields, @@ -33,7 +34,7 @@ const CategoryDetail = ({ chartMode:f.chartMode, chartLegend:f.chartLegend, chartTopMargin:f.chartTopMargin, - data: dataLength && dataLength > 0 ? dataMap[f.requestKeyResolved] : [] + data: dataLength && dataLength > 0 ? wrapSampleRow(dataMap[f.requestKeyResolved]) : [] }; }); diff --git a/src/app/(pages)/(main)/category/sub-page/category-page/PenetrationChange.tsx b/src/app/(pages)/(main)/category/sub-page/category-page/PenetrationChange.tsx index 6c7b39b..d8026c6 100644 --- a/src/app/(pages)/(main)/category/sub-page/category-page/PenetrationChange.tsx +++ b/src/app/(pages)/(main)/category/sub-page/category-page/PenetrationChange.tsx @@ -33,6 +33,8 @@ const PenetrationChange = ({ }, [dataMap]); const getCellClassName = (row: BannerRow, column: DataColumn, rowIndex: number) => { + if (!("key" in column) || column.key === undefined) return undefined; + const currentYear = Number(row.year); if (currentYear !== 2024 && currentYear !== 2025) return undefined; if (column.key === "rowLabel" || column.key === "total") return undefined; diff --git a/src/components/lge-dashboard/combo/BannerSummary.tsx b/src/components/lge-dashboard/combo/BannerSummary.tsx index 1c871fc..85ffcb7 100644 --- a/src/components/lge-dashboard/combo/BannerSummary.tsx +++ b/src/components/lge-dashboard/combo/BannerSummary.tsx @@ -1,22 +1,17 @@ -import {ChartData, DataColumn, DataTable, HorizontalBar, LeftChartTable, SignStyle} from "@/components/lge-dashboard"; -import {BannerKey, BannerRow} from "@/types/lg.types"; -import {formatRowLabel, isGapRow, wrapSampleRow} from "@/lib/lg-dashboard"; -import {useEffect, useMemo} from "react"; -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 { ChartData, DataColumn, DataTable, HorizontalBar, LeftChartTable, SignStyle } from "@/components/lge-dashboard"; +import { BannerKey, BannerRow } from "@/types/lg.types"; +import { buildBannerGroupColumns, formatRowLabel, isGapRow, wrapSampleRow } from "@/lib/lg-dashboard"; +import { useEffect, useMemo } from "react"; +import { BANNER_GROUP, flattenBannerGroupKeys } 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, - exportDashboardExcel, - Section -} from "@/lib/lg-export-excel"; -import {useLayoutFilter} from "@/components/layout/LayoutFilterContext"; -import {CategoryFilterValue} from "@/components/layout/CategoryFilter"; -import {CategoryTargetData} from "@/types/filter.types"; -import {useDebouncedValue} from "@/hooks/useDebouncedValue"; - +import { parseNumber } from "@/lib/utils"; +import { buildHeader_DataColumn, exportDashboardExcel, Section } from "@/lib/lg-export-excel"; +import { useLayoutFilter } from "@/components/layout/LayoutFilterContext"; +import { CategoryFilterValue } from "@/components/layout/CategoryFilter"; +import { CategoryTargetData } from "@/types/filter.types"; +import { useDebouncedValue } from "@/hooks/useDebouncedValue"; type SectionSpec = { title: string; @@ -33,14 +28,13 @@ const SECTIONS: SectionSpec[] = [ const SEP_R = "lg-table__sep-r"; const getSectionBannerKeys = (spec: SectionSpec): BannerKey[] => - spec.groupKeys.flatMap((gk) => BANNER_GROUP[gk].keys); + spec.groupKeys.flatMap((gk) => flattenBannerGroupKeys(BANNER_GROUP[gk].children)); -const buildColumns = (spec: SectionSpec, selectedYear:string): DataColumn[] => { +const buildColumns = (spec: SectionSpec, selectedYear: string): DataColumn[] => { const columns: DataColumn[] = [ { key: "rowLabel", header: `${selectedYear}년`, - headRowSpan: 2, rowHead: true, cellClassName: "lg-table__rowhead", width: 120, @@ -49,7 +43,6 @@ const buildColumns = (spec: SectionSpec, selectedYear:string): DataColumn { const g = BANNER_GROUP[groupKey]; - g.keys.forEach((k, idx) => { - const isLast = idx === g.keys.length - 1; - columns.push({ - key: k as any, - header: BANNER_KEY_MAP[k] ?? String(k), - group: g.label, + columns.push({ + id: `banner-group-${groupKey}`, + header: g.label, + children: buildBannerGroupColumns(g, BANNER_KEY_MAP, { numeric: true, - headerClassName: isLast ? SEP_R : undefined, - cellClassName: isLast ? SEP_R : undefined, width: 90, - }); + resolveLeafMeta: (_key, idx, total) => { + const isLast = idx === total - 1; + return { + headerClassName: isLast ? SEP_R : undefined, + cellClassName: isLast ? SEP_R : undefined, + }; + }, + }), }); }); @@ -83,23 +79,23 @@ type BannerSummaryProps = { }; const BannerSummary = ({ data, useChart, useYear, getCellClassName }: BannerSummaryProps) => { - const {filterValue, registerExcelExporter } = useLayoutFilter(); + const { filterValue, registerExcelExporter } = useLayoutFilter(); const debouncedFilterValue = useDebouncedValue(filterValue as CategoryFilterValue, 500); const buildChartData = (rows: BannerRow[]): ChartData => { const categories = rows - .filter((r) => !r.rowLabel.includes("사례수")) - .map((r) => formatRowLabel(r.rowLabel)) - .reverse(); + .filter((r) => !r.rowLabel.includes("사례수")) + .map((r) => formatRowLabel(r.rowLabel)) + .reverse(); const series = [ { - name:"전체", + name: "전체", data: rows - .filter((r) => !r.rowLabel.includes("사례수")) - .map((r) => parseNumber(r.total) ?? null) - .reverse(), - } + .filter((r) => !r.rowLabel.includes("사례수")) + .map((r) => parseNumber(r.total) ?? null) + .reverse(), + }, ]; return { categories, series }; @@ -113,21 +109,17 @@ const BannerSummary = ({ data, useChart, useYear, getCellClassName }: BannerSumm zeroText: "-", }; - const sectionRows = useMemo(() => { return SECTIONS.map((spec) => { const specTitle = spec.title; - const bannerKeys = getSectionBannerKeys(spec); - const columns = buildColumns(spec, useYear? filterValue.year : ""); + const columns = buildColumns(spec, useYear ? filterValue.year : ""); // rows가 spec마다 다르면 여기서 가져오도록 구성 - const rows = - wrapSampleRow(useYear? data.filter((d) => d.year === filterValue.year) : data) - .map((row) => { - row.rowLabel = formatRowLabel(row.rowLabel); - return row - }) + const rows = wrapSampleRow(useYear ? data.filter((d) => d.year === filterValue.year) : data).map((row) => { + row.rowLabel = formatRowLabel(row.rowLabel); + return row; + }); const chartData = buildChartData(rows); return { @@ -145,75 +137,71 @@ const BannerSummary = ({ data, useChart, useYear, getCellClassName }: BannerSumm registerExcelExporter(async () => { const product = debouncedFilterValue.product; const type = debouncedFilterValue.type.label; - const target = debouncedFilterValue.target.value === CategoryTargetData.PROFILE? "Profile" : "보급률 변화" - - const sheetName = `${product}_${type}_${target}` + const target = debouncedFilterValue.target.value === CategoryTargetData.PROFILE ? "Profile" : "보급률 변화"; + const sheetName = `${product}_${type}_${target}`; type AnyRow = Record; - const sections: Section[] = - sectionRows.map((sectionRow) => ({ - title: sectionRow.specTitle, - header: buildHeader_DataColumn(sectionRow.columns), - rows: sectionRow.rows as AnyRow[], - rowGap: 1, - })) - ; + const sections: Section[] = sectionRows.map((sectionRow) => ({ + title: sectionRow.specTitle, + header: buildHeader_DataColumn(sectionRow.columns), + rows: sectionRow.rows as AnyRow[], + rowGap: 1, + })); await exportDashboardExcel({ fileName: `${SITE_TITLE}(${sheetName}).xlsx`, - sheetName: sheetName, - sections: sections, + sheetName, + sections, }); }); return () => registerExcelExporter(null); }, [registerExcelExporter, debouncedFilterValue, sectionRows]); return ( -
- {sectionRows.map((sectionRow) => { - return ( -
- { - useChart ? - - key={sectionRow.specTitle} - title={sectionRow.specTitle} - columns={sectionRow.columns} - rows={sectionRow.rows} - getCellClassName={getCellClassName} - signStyle={signStyleGap} - chart={ - - } - chartCell={{ key: "total", startRowIndex: 1 }} - minWidthPx={1200} - starUnder30Sample={true} - /> - : - - key={sectionRow.specTitle} - title={sectionRow.specTitle} - columns={sectionRow.columns} - rows={sectionRow.rows} - signStyle={signStyleGap} - unitText={""} - starUnder30Sample={true} - /> +
+ {sectionRows.map((sectionRow) => { + return ( +
+ {useChart ? ( + + key={sectionRow.specTitle} + title={sectionRow.specTitle} + columns={sectionRow.columns} + rows={sectionRow.rows} + getCellClassName={getCellClassName} + signStyle={signStyleGap} + chart={ + } -
- ); - })} -
+ chartCell={{ key: "total", startRowIndex: 1 }} + minWidthPx={1200} + starUnder30Sample={true} + /> + ) : ( + + key={sectionRow.specTitle} + title={sectionRow.specTitle} + columns={sectionRow.columns} + rows={sectionRow.rows} + signStyle={signStyleGap} + unitText={""} + starUnder30Sample={true} + /> + )} +
+ ); + })} +
); -} +}; export default BannerSummary; diff --git a/src/components/lge-dashboard/combo/CategoryByData.tsx b/src/components/lge-dashboard/combo/CategoryByData.tsx index 3d4eaf7..b9d329b 100644 --- a/src/components/lge-dashboard/combo/CategoryByData.tsx +++ b/src/components/lge-dashboard/combo/CategoryByData.tsx @@ -1,23 +1,12 @@ -import { - bannerType, - type DataColumn, - DataTable, - HorizontalBar, SectionTitle, SignStyle, - StackBar -} from "@/components/lge-dashboard"; +import { bannerType, type DataColumn, DataTable, HorizontalBar, SectionTitle, SignStyle, StackBar } from "@/components/lge-dashboard"; import BannerButtons from "@/components/lge-dashboard/BannerButtons"; -import {categoryByDataBanner, totalFilters} from "@/const/filter.const"; -import React, {useMemo, useState} from "react"; -import {BannerGroupKey, CategoryChartMode, BannerRow, LegendOption} from "@/types/lg.types"; -import { - buildRowLabelSeriesChartData, - buildYearSeriesChartData, formatRowLabel, - isBannerGroupKey, isGapRow, - wrapSampleRow -} from "@/lib/lg-dashboard"; -import {BANNER_GROUP} from "@/const/lg-banner.const"; -import {BANNER_KEY_MAP} from "@/const/lg-schema.const"; -import {createDefaultGrid, reverseCategories} from "@/lib/chart-options"; +import { categoryByDataBanner } from "@/const/filter.const"; +import React, { useMemo, useState } from "react"; +import { BannerGroupKey, CategoryChartMode, BannerRow, LegendOption } from "@/types/lg.types"; +import { buildBannerGroupColumns, buildRowLabelSeriesChartData, buildYearSeriesChartData, formatRowLabel, isBannerGroupKey, isGapRow, wrapSampleRow } from "@/lib/lg-dashboard"; +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; @@ -30,11 +19,11 @@ type CategoryByDataProps = { fillGreaterThan5?: boolean; chartHeight?: number | string; chartWidth?: number; -} +}; const banners: bannerType[] = categoryByDataBanner.map((filter) => { - return {variable: filter.variable, variableName: filter.variableName} -}) + return { variable: filter.variable, variableName: filter.variableName }; +}); const signStyleGap: SignStyle = { rowSelector: (row) => isGapRow(row.rowLabel), @@ -45,62 +34,56 @@ const signStyleGap: SignStyle = { }; const CategoryByData = ({ - selectedYear, - title, - surveyTitle, - chartMode, - chartLegend, - chartTopMargin, - allTableData, - fillGreaterThan5, - chartHeight, - chartWidth, - }: CategoryByDataProps) => { + selectedYear, + title, + surveyTitle, + chartMode, + chartLegend, + chartTopMargin, + allTableData, + fillGreaterThan5, + chartHeight, + chartWidth, +}: CategoryByDataProps) => { const [selectedBanner, setSelectedBanner] = useState(banners[0]); - const buildColumns = (groupKey: BannerGroupKey, selectedYear:string): DataColumn[] => { - const columns: DataColumn[] = [ + const buildColumns = (groupKey: BannerGroupKey, year: string): DataColumn[] => { + const g = BANNER_GROUP[groupKey]; + + return [ { key: "rowLabel", - header: `${selectedYear}년`, - headRowSpan: 2, + header: `${year}년`, rowHead: true, cellClassName: "lg-table__rowhead", width: 120, }, { key: "total", - header: `전체`, - headRowSpan: 2, + header: "전체", numeric: true, cellClassName: "lg-table__rowhead", width: 120, }, + { + id: `category-banner-${groupKey}`, + header: g.label, + children: buildBannerGroupColumns(g, BANNER_KEY_MAP, { + numeric: true, + width: 90, + }), + }, ]; - - const g = BANNER_GROUP[groupKey]; - g.keys.forEach((k) => { - columns.push({ - key: k as any, - header: BANNER_KEY_MAP[k] ?? String(k), - group: g.label, - numeric: true, - width: 90, - }); - }); - - return columns; }; const chartData = useMemo(() => { - const excludeRowLabels =["사례수", "gap"]; + const excludeRowLabels = ["사례수", "gap"]; const chartTargetData = allTableData.filter((row) => row.year === selectedYear || Number(row.year) === Number(selectedYear) - 1); - if(chartMode == "horizontal"){ - return reverseCategories(buildYearSeriesChartData(chartTargetData, {excludeRowLabels})); + if (chartMode === "horizontal") { + return reverseCategories(buildYearSeriesChartData(chartTargetData, { excludeRowLabels })); } - return buildRowLabelSeriesChartData(chartTargetData, {excludeRowLabels}); - + return buildRowLabelSeriesChartData(chartTargetData, { excludeRowLabels }); }, [allTableData, selectedYear, chartMode]); const tableColumns = useMemo(() => { @@ -108,75 +91,70 @@ const CategoryByData = ({ return isBannerGroupKey(v) ? buildColumns(v, selectedYear) : []; }, [selectedBanner.variable, selectedYear]); - const tableData = useMemo(() => + const tableData = useMemo( + () => wrapSampleRow(allTableData) - .filter((row) => row.year === selectedYear) - .map((row) => { - row.rowLabel = formatRowLabel(row.rowLabel); - return row - }) - , [allTableData, selectedYear]); - + .filter((row) => row.year === selectedYear) + .map((row) => { + row.rowLabel = formatRowLabel(row.rowLabel); + return row; + }), + [allTableData, selectedYear] + ); return ( -
-
- {title ? :
} -
-
-
- {(() => { - switch (chartMode) { - case "horizontal": - return ( - - ); - case "stack": - case "reverseStack": - return ( - - ); - default: - return null; - } - })()} -
- -
- -
- -
- -
-
-
{surveyTitle}
+
+
+ {title ? :
}
+
+
+ {(() => { + switch (chartMode) { + case "horizontal": + return ( + + ); + case "stack": + case "reverseStack": + return ( + + ); + default: + return null; + } + })()} +
+ +
+ +
+ +
+ +
+
+
{surveyTitle}
+
); }; diff --git a/src/components/lge-dashboard/table/BaseDataTable.tsx b/src/components/lge-dashboard/table/BaseDataTable.tsx index d3493b0..bec8e16 100644 --- a/src/components/lge-dashboard/table/BaseDataTable.tsx +++ b/src/components/lge-dashboard/table/BaseDataTable.tsx @@ -9,6 +9,7 @@ import { appendCellMarker, formatSignedValue, getColumnAlign, + getLeafColumns, getSignCellBackground, getSignTextClass, resolveSignStyle, @@ -62,6 +63,7 @@ export default function BaseDataTable>({ const resolvedSignStyle = resolveSignStyle(signStyle, signStyleFallback); const mergedCellStart = mergedCell?.startRowIndex ?? 0; const mergedCellSpan = mergedCell?.rowSpan ?? Math.max(0, rows.length - mergedCellStart); + const leafColumns = getLeafColumns(columns); return ( >({ return ( - {columns.map((column) => { + {leafColumns.map((column) => { const dynamicCellClassName = getCellClassName?.(row, column, rowIndex); if (mergedCell && column.key === mergedCell.key && rowIndex >= mergedCellStart) { @@ -104,7 +106,7 @@ export default function BaseDataTable>({ 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 numericValue = "numeric" in column && column.numeric ? parseNumber(rawValue ?? defaultContent) ?? 0 : 0; const applySign = signRow && shouldApplySignToColumn(column, signStyle); if (column.rowHead) { diff --git a/src/components/lge-dashboard/table/GaugeTable.tsx b/src/components/lge-dashboard/table/GaugeTable.tsx index bebec97..e3f2f0c 100644 --- a/src/components/lge-dashboard/table/GaugeTable.tsx +++ b/src/components/lge-dashboard/table/GaugeTable.tsx @@ -4,7 +4,7 @@ import { cn, parseNumber } from "@/lib/utils"; import { roundNumber } from "@/lib/lg-dashboard"; import type { GaugeColumn } from "../types"; import BaseTableRenderer from "./core/BaseTableRenderer"; -import { getColumnAlign, toTableCellContent } from "./core/table-core.helpers"; +import { getColumnAlign, getLeafColumns, toTableCellContent } from "./core/table-core.helpers"; type Props> = { columns: GaugeColumn[]; @@ -33,6 +33,7 @@ const GaugeTable = >({ }: Props) => { const formatValue = valueFormatter ?? ((value: number) => String(roundNumber(value))); const clampRatio = (value: number) => Math.max(0, Math.min(1, value)); + const leafColumns = getLeafColumns(columns); return ( >({ minWidth="100%" colgroup={ - {columns.map((column, index) => ( + {leafColumns.map((column, index) => ( >({ > {rows.map((row, rowIndex) => ( - {columns.map((column) => { + {leafColumns.map((column) => { const align = getColumnAlign(column); if (column.rowHead) { @@ -74,13 +75,13 @@ const GaugeTable = >({ const rawValue = row[column.key]; const numericValue = parseNumber(rawValue); - const max = column.max ?? 100; + const max = "max" in column ? column.max ?? 100 : 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") { + if (("cellType" in column ? column.cellType : "gauge") === "number") { return ( {numericValue === null ? "-" : formatValue(numericValue)} diff --git a/src/components/lge-dashboard/table/core/BaseTableRenderer.tsx b/src/components/lge-dashboard/table/core/BaseTableRenderer.tsx index 0c08947..044b907 100644 --- a/src/components/lge-dashboard/table/core/BaseTableRenderer.tsx +++ b/src/components/lge-dashboard/table/core/BaseTableRenderer.tsx @@ -2,17 +2,11 @@ import type React from "react"; import { cn } from "@/lib/utils"; +import type { DataColumn, GaugeColumn } from "../../types"; import BaseTableHeader from "./BaseTableHeader"; -import { buildGroupHeaderCells, hasGroupedHeader } from "./table-core.helpers"; +import { buildHeaderRows } from "./table-core.helpers"; -type BaseColumn = { - key: keyof T; - header: string; - width?: number | string; - group?: string; - headRowSpan?: 1 | 2; - headerClassName?: string; -}; +type BaseColumn = DataColumn | GaugeColumn; type Props = { columns: BaseColumn[]; @@ -41,8 +35,8 @@ export default function BaseTableRenderer({ renderHeaderPrefix, children, }: Readonly>) { - const groupedHeader = hasGroupedHeader(columns); - const groupHeaderCells = buildGroupHeaderCells(columns); + const headerRows = buildHeaderRows(columns); + const lastHeaderRowIndex = headerRows.length - 1; return (
@@ -56,33 +50,18 @@ export default function BaseTableRenderer({ {colgroup} {renderHeaderPrefix} - {groupedHeader ? ( - - {groupHeaderCells.map((cell, index) => ( - + {headerRows.map((row, rowIndex) => ( + + {row.map((cell) => ( + {cell.label} ))} - ) : null} - - {columns - .filter((column) => column.headRowSpan !== 2) - .map((column) => ( - - {column.header} - - ))} - + ))} {children} diff --git a/src/components/lge-dashboard/table/core/table-core.helpers.tsx b/src/components/lge-dashboard/table/core/table-core.helpers.tsx index 029c049..f352d17 100644 --- a/src/components/lge-dashboard/table/core/table-core.helpers.tsx +++ b/src/components/lge-dashboard/table/core/table-core.helpers.tsx @@ -1,27 +1,26 @@ import type React from "react"; import { parseNumber } from "@/lib/utils"; import { roundNumber } from "@/lib/lg-dashboard"; -import type { SignDisplayMode, SignStyle, ValueFormatter } from "../../types"; +import type { + DataColumn, + DataColumnLeaf, + GaugeColumn, + GaugeColumnLeaf, + SignDisplayMode, + SignStyle, + ValueFormatter, +} from "../../types"; -type BaseTableColumn = { - 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 TableColumnNode = DataColumn | GaugeColumn; +export type TableColumnLeaf = DataColumnLeaf | GaugeColumnLeaf; export type GroupHeaderCell = { - kind: "rowspan" | "group" | "blank"; + id: string; label: string; colSpan: number; rowSpan: number; className?: string; + isLeaf: boolean; }; export type ResolvedSignStyle = { @@ -57,71 +56,93 @@ const defaultSignStyle: ResolvedSignStyle = { zeroCellBg: "hsl(var(--lg-gray-200) / 0.6)", }; -export function hasGroupedHeader(columns: BaseTableColumn[]) { - return columns.some((column) => column.group) || columns.some((column) => column.headRowSpan === 2); +function isColumnLeaf(column: TableColumnNode): column is TableColumnLeaf { + return !("children" in column) || !column.children?.length; } -export function buildGroupHeaderCells(columns: BaseTableColumn[]) { - if (!hasGroupedHeader(columns)) { - return [] as GroupHeaderCell[]; - } +export function getLeafColumns(columns: TableColumnNode[]) { + const leaves: TableColumnLeaf[] = []; - const cells: GroupHeaderCell[] = []; - let index = 0; + const visit = (nodes: TableColumnNode[]) => { + nodes.forEach((node) => { + if (isColumnLeaf(node)) { + leaves.push(node); + return; + } - 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, + visit(node.children); }); - index = cursor; - } + }; - return cells; + visit(columns); + return leaves; } -export function getColumnAlign(column: BaseTableColumn, fallback: "left" | "center" | "right" = "center") { +function getHeaderDepth(columns: TableColumnNode[]) { + const visit = (nodes: TableColumnNode[], depth: number): number => + nodes.reduce((maxDepth, node) => { + if (isColumnLeaf(node)) { + return Math.max(maxDepth, depth); + } + + return Math.max(maxDepth, visit(node.children, depth + 1)); + }, depth); + + return columns.length ? visit(columns, 1) : 0; +} + +function getLeafCount(column: TableColumnNode): number { + if (isColumnLeaf(column)) { + return 1; + } + + return column.children.reduce((sum, child) => sum + getLeafCount(child), 0); +} + +export function buildHeaderRows(columns: TableColumnNode[]) { + const depth = getHeaderDepth(columns); + + if (!depth) { + return [] as GroupHeaderCell[][]; + } + + const rows = Array.from({ length: depth }, () => [] as GroupHeaderCell[]); + + const visit = (nodes: TableColumnNode[], level: number, path: string[]) => { + nodes.forEach((node, index) => { + const nodeId = node.id ?? (isColumnLeaf(node) ? String(node.key) : `${path.join(".") || "root"}:${index}:${node.header}`); + const nextPath = [...path, nodeId]; + const isLeaf = isColumnLeaf(node); + + rows[level].push({ + id: nextPath.join("/"), + label: node.header, + colSpan: isLeaf ? 1 : getLeafCount(node), + rowSpan: isLeaf ? depth - level : 1, + className: node.headerClassName, + isLeaf, + }); + + if (!isLeaf) { + visit(node.children, level + 1, nextPath); + } + }); + }; + + visit(columns, 0, []); + return rows; +} + +export function hasGroupedHeader(columns: TableColumnNode[]) { + return getHeaderDepth(columns) > 1; +} + +export function getColumnAlign(column: TableColumnLeaf, fallback: "left" | "center" | "right" = "center") { if (column.align) { return column.align; } - if (column.numeric) { + if ("numeric" in column && column.numeric) { return "right"; } @@ -185,7 +206,7 @@ export function resolveSignStyle(signStyle?: SignStyle, fallback?: Partial }; } -export function shouldApplySignToColumn(column: BaseTableColumn, signStyle?: SignStyle) { +export function shouldApplySignToColumn(column: TableColumnLeaf, signStyle?: SignStyle) { if (!signStyle || column.rowHead) { return false; } @@ -194,7 +215,7 @@ export function shouldApplySignToColumn(column: BaseTableColumn, signStyle return signStyle.keys.includes(column.key); } - return !!column.numeric; + return "numeric" in column ? !!column.numeric : false; } export function formatSignedValue( @@ -203,10 +224,10 @@ export function formatSignedValue( ) { if (options.display === "arrow") { if (value > 0) { - return options.arrowWithNumber ? `▲ ${options.valueFormatter(Math.abs(value))}` : "▲"; + return options.arrowWithNumber ? `▲${options.valueFormatter(Math.abs(value))}` : "▲"; } if (value < 0) { - return options.arrowWithNumber ? `▼ ${options.valueFormatter(Math.abs(value))}` : "▼"; + return options.arrowWithNumber ? `▼${options.valueFormatter(Math.abs(value))}` : "▼"; } return options.zeroText; } diff --git a/src/components/lge-dashboard/types.ts b/src/components/lge-dashboard/types.ts index b7bbcc2..bf0ca77 100644 --- a/src/components/lge-dashboard/types.ts +++ b/src/components/lge-dashboard/types.ts @@ -1,5 +1,5 @@ import type React from "react"; -import {GAP_WORDING} from "@/const/lg-common.const"; +import { GAP_WORDING } from "@/const/lg-common.const"; export type NewNumber = number | null | undefined; @@ -34,10 +34,10 @@ export type GroupedStackBarData = { }; export type GroupedOverlayBarData = { - categories: string[]; // 제품 - years: string[]; // 예: [24,25,26] - totalName?: string; // default: "전체" - focusName?: string; // default: "LG" + categories: string[]; // 제품 + years: string[]; // 예: [24,25,26] + totalName?: string; // default: "전체" + focusName?: string; // default: "LG" total: Array>; // [yearIndex][categoryIndex] focus: Array>; // [yearIndex][categoryIndex] }; @@ -54,43 +54,54 @@ export type TopChartTableRow = { export type ValueFormatter = (v: number) => string; -export type DataColumn = { - key: keyof T; +export type TableColumnAlign = "left" | "center" | "right"; + +type TableColumnShared = { + id?: string; header: string; width?: number | string; - align?: "left" | "center" | "right"; - group?: string; // 2단 헤더 그룹 - groupKey?:string;// 2단 헤더 그룹 - - /** group header에서 해당 컬럼 헤더를 rowspan=2로 올릴 때 사용(HTML 테이블과 동일한 구조 지원) */ - headRowSpan?: 1 | 2; - rowHead?: boolean; // 첫 컬럼 등 row header - numeric?: boolean; // 숫자열(정렬 기본값/색상 타겟 기본값에 사용) - /** th 클래스(필요 시 lg-table__sep-r 등 주입) */ + align?: TableColumnAlign; headerClassName?: string; - /** td 클래스(필요 시 lg-table__sep-l, lg-table__sep-r 등 주입) */ cellClassName?: string; render?: (row: T) => React.ReactNode; }; -export type GaugeColumn = { +export type DataColumnLeaf = TableColumnShared & { key: keyof T; - header: string; - width?: number | string; - align?: "left" | "center" | "right"; - group?: string; - groupKey?:string;// 2단 헤더 그룹 + rowHead?: boolean; // 첫 컬럼 등 row header + numeric?: boolean; // 숫자열(정렬 기본값/색상 타겟 기본값에 사용) + children?: undefined; +}; - headRowSpan?: 1 | 2; +export type DataColumnGroup = TableColumnShared & { + children: DataColumn[]; + key?: undefined; + rowHead?: undefined; + numeric?: undefined; +}; + +export type DataColumn = DataColumnLeaf | DataColumnGroup; + +export type GaugeColumnLeaf = TableColumnShared & { + key: keyof T; rowHead?: boolean; /** 게이지 최대값 기준(기본 100) */ max?: number; render?: (row: T) => React.ReactNode; // rowHead에 쓰기 좋음 cellType?: "gauge" | "number"; // default: "gauge" - headerClassName?: string; - cellClassName?: string; + children?: undefined; }; +export type GaugeColumnGroup = TableColumnShared & { + children: GaugeColumn[]; + key?: undefined; + rowHead?: undefined; + max?: undefined; + cellType?: undefined; +}; + +export type GaugeColumn = GaugeColumnLeaf | GaugeColumnGroup; + export type SignDisplayMode = "number" | "arrow"; export type SignStyle = { @@ -105,7 +116,7 @@ export type SignStyle = { /** 표기 방식 */ display?: SignDisplayMode; // 기본 number - showPlus?: boolean; // number 모드에서 + 표시(기본 true) + showPlus?: boolean; // number 모드에서 + 표시(기본 true) /** 0 값 표기(기본 "-") */ zeroText?: string; @@ -119,11 +130,11 @@ export type SignStyle = { /** 색상 커스터마이즈(기본: + primary, - info, 0 gray) */ positiveTextClassName?: string; // 기본 "text-primary font-semibold" negativeTextClassName?: string; // 기본 "text-info font-semibold" - zeroTextClassName?: string; // 기본 "text-gray-600" + zeroTextClassName?: string; // 기본 "text-gray-600" positiveCellBg?: string; // ex) "hsl(var(--primary) / 0.08)" negativeCellBg?: string; // ex) "hsl(var(--info) / 0.08)" - zeroCellBg?: string; // ex) "hsl(var(--lg-gray-200) / 0.6)" + zeroCellBg?: string; // ex) "hsl(var(--lg-gray-200) / 0.6)" }; export const signStyleGapRow: SignStyle = { @@ -137,6 +148,6 @@ export const signStyleGapRow: SignStyle = { export type ShowLabel = "none" | "all" | "last" | "first"; export type bannerType = { - variable:string; - variableName:string; -} + variable: string; + variableName: string; +}; diff --git a/src/const/lg-banner.const.ts b/src/const/lg-banner.const.ts index df3d404..4603cb6 100644 --- a/src/const/lg-banner.const.ts +++ b/src/const/lg-banner.const.ts @@ -1,5 +1,24 @@ -import type {BannerKey} from "@/types/lg.types"; -import {BANNER_KEY_MAP} from "@/const/lg-schema.const"; +import type { BannerKey } from "@/types/lg.types"; +import { BANNER_KEY_MAP } from "@/const/lg-schema.const"; + +export type BannerGroupLeafNode = { + type: "leaf"; + key: BannerKey; +}; + +export type BannerGroupBranchNode = { + type: "group"; + id: string; + label: string; + children: readonly BannerGroupNode[]; +}; + +export type BannerGroupNode = BannerGroupLeafNode | BannerGroupBranchNode; + +export type BannerGroupDefinition = { + label: string; + children: readonly BannerGroupNode[]; +}; export const BANNER_KEYS = Object.keys(BANNER_KEY_MAP) as Array; export const BANNER_KEY = Object.keys(BANNER_KEY_MAP).reduce((acc, k) => { @@ -7,90 +26,112 @@ export const BANNER_KEY = Object.keys(BANNER_KEY_MAP).reduce((acc, k) => { return acc; }, {} as { [K in BannerKey]: K }); +const leaf = (key: BannerKey): BannerGroupLeafNode => ({ + type: "leaf", + key, +}); + +const group = (id: string, label: string, children: readonly BannerGroupNode[]): BannerGroupBranchNode => ({ + type: "group", + id, + label, + children, +}); + 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"], + children: [ + leaf(BANNER_KEY["KLIFEstAGE#1"]), + group("life-stage-married", "기혼", [ + leaf(BANNER_KEY["KLIFEstAGE#2"]), + leaf(BANNER_KEY["KLIFEstAGE#3"]), + leaf(BANNER_KEY["KLIFEstAGE#4"]), + leaf(BANNER_KEY["KLIFEstAGE#5"]), + ]), + leaf(BANNER_KEY["KLIFEstAGE#6"]), + leaf(BANNER_KEY["KLIFEstAGE#7"]), + leaf(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"], + children: [ + leaf(BANNER_KEY["KSQ8_R_DB#1"]), + leaf(BANNER_KEY["KSQ8_R_DB#2"]), + leaf(BANNER_KEY["KSQ8_R_DB#3"]), + leaf(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"], + children: [ + leaf(BANNER_KEY["KSQ2_R_R#1"]), + leaf(BANNER_KEY["KSQ2_R_R#2"]), + leaf(BANNER_KEY["KSQ2_R_R#3"]), + leaf(BANNER_KEY["KSQ2_R_R#4"]), + leaf(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"], + children: [ + leaf(BANNER_KEY["KDQ6#1"]), + leaf(BANNER_KEY["KDQ6#2"]), + leaf(BANNER_KEY["KDQ6#3"]), + leaf(BANNER_KEY["KDQ6#4"]), + leaf(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"], + children: [ + leaf(BANNER_KEY["KDQ4#1"]), + leaf(BANNER_KEY["KDQ4#2"]), + leaf(BANNER_KEY["KDQ4#3"]), + leaf(BANNER_KEY["KDQ4#4"]), + leaf(BANNER_KEY["KDQ4#5"]), + leaf(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"], + children: [ + leaf(BANNER_KEY["KDQ5#1"]), + leaf(BANNER_KEY["KDQ5#2"]), + leaf(BANNER_KEY["KDQ5#3"]), + leaf(BANNER_KEY["KDQ5#4"]), + leaf(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"], + children: [ + leaf(BANNER_KEY["KSQ4_R_R#1"]), + leaf(BANNER_KEY["KSQ4_R_R#2"]), + leaf(BANNER_KEY["KSQ4_R_R#3"]), + leaf(BANNER_KEY["KSQ4_R_R#4"]), + leaf(BANNER_KEY["KSQ4_R_R#5"]), + leaf(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"], + children: [ + leaf(BANNER_KEY["KDQ3_DB#1"]), + leaf(BANNER_KEY["KDQ3_DB#2"]), + leaf(BANNER_KEY["KDQ3_DB#3"]), + leaf(BANNER_KEY["KDQ3_DB#4"]), ], }, -} as const; +} as const satisfies Record; + +export const isBannerGroupBranchNode = (node: BannerGroupNode): node is BannerGroupBranchNode => { + return node.type === "group"; +} + +export const flattenBannerGroupKeys = (nodes: readonly BannerGroupNode[]): BannerKey[] => { + return nodes.flatMap((node) => (node.type === "leaf" ? [node.key] : flattenBannerGroupKeys(node.children))); +} export const BANNER_GROUP_KEY = Object.keys(BANNER_GROUP) as string[]; diff --git a/src/const/lg-product.const.ts b/src/const/lg-product.const.ts index bb000f9..333d6a2 100644 --- a/src/const/lg-product.const.ts +++ b/src/const/lg-product.const.ts @@ -1,21 +1,24 @@ -import {GaugeColumn} from "@/components/lge-dashboard"; -import {PRODUCT_KEY_MAP} from "@/const/lg-schema.const"; -import type {LifeStageRow} from "@/types/lg.types"; +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[] = [ - { 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"}, + { key: "item", header: "", rowHead: true, render: (r) => r.item }, + { key: "total", header: "전체", max: 100, align: "left", cellType: "number" }, + { key: "KLIFEstAGE#1", header: "미혼", max: 100, align: "left" }, + { + id: "life-stage-married", + header: "기혼", + children: [ + { key: "KLIFEstAGE#2", header: "무자녀", max: 100, align: "left" }, + { key: "KLIFEstAGE#3", header: "미취학", max: 100, align: "left" }, + { key: "KLIFEstAGE#4", header: "취학자녀", max: 100, align: "left" }, + { key: "KLIFEstAGE#5", header: "성인자녀", max: 100, align: "left" }, + ], + }, + { key: "KLIFEstAGE#6", header: "독립\n시니어", max: 100, align: "left" }, + { key: "KLIFEstAGE#7", header: "비혼중년", max: 100, align: "left" }, + { key: "KLIFEstAGE#8", header: "기타", max: 100, align: "left" }, ]; export const LIFE_STAGE_GROUPS = [ @@ -31,20 +34,20 @@ export const PRODUCTS_FILTER_ITEM = [ { path: "kitchen", items: [ - "KPRODUCT#1", // 냉장고 - "KPRODUCT#2", // 김치 냉장고 - "KPRODUCT#3", // 정수기 - "KPRODUCT#4", // 전기 레인지 - "KPRODUCT#5", // 식기 세척기 - "KPRODUCT#6", // 음식물처리기 + "KPRODUCT#1", // 냉장고 + "KPRODUCT#2", // 김치 냉장고 + "KPRODUCT#3", // 정수기 + "KPRODUCT#4", // 전기 레인지 + "KPRODUCT#5", // 식기 세척기 + "KPRODUCT#6", // 음식물처리기 ], }, { path: "living", items: [ - "KPRODUCT#7", // 세탁기 - "KPRODUCT#9", // 건조기 - "KPRODUCT#8", // 청소기 + "KPRODUCT#7", // 세탁기 + "KPRODUCT#9", // 건조기 + "KPRODUCT#8", // 청소기 "KPRODUCT#10", // 로봇 청소기 "KPRODUCT#11", // 의류 관리기 ], diff --git a/src/lib/lg-dashboard.ts b/src/lib/lg-dashboard.ts index b0a1ca4..6130998 100644 --- a/src/lib/lg-dashboard.ts +++ b/src/lib/lg-dashboard.ts @@ -6,8 +6,9 @@ import { StatisticsRequest } from "@/types/lg.types"; import {ChartData} from "@/components/lge-dashboard"; +import type { DataColumn } from "@/components/lge-dashboard/types"; 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 {BANNER_GROUP, BANNER_KEYS, type BannerGroupDefinition, type BannerGroupNode, flattenBannerGroupKeys} 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"; @@ -316,6 +317,47 @@ export const buildGapRow = ( export const isBannerGroupKey = (v: string): v is BannerGroupKey => v in BANNER_GROUP; +export function buildBannerGroupColumns>( + group: BannerGroupDefinition, + keyLabelMap: Record, + options: { + width?: number | string; + numeric?: boolean; + resolveLeafMeta?: (key: string, index: number, total: number) => { + headerClassName?: string; + cellClassName?: string; + }; + } = {} +): DataColumn[] { + const leafKeys = flattenBannerGroupKeys(group.children); + let leafIndex = 0; + + const visit = (nodes: readonly BannerGroupNode[]): DataColumn[] => + nodes.map((node) => { + if (node.type === "leaf") { + const currentLeafIndex = leafIndex++; + const meta = options.resolveLeafMeta?.(node.key, currentLeafIndex, leafKeys.length); + + return { + key: node.key as keyof T, + header: keyLabelMap[node.key] ?? String(node.key), + numeric: options.numeric, + width: options.width, + headerClassName: meta?.headerClassName, + cellClassName: meta?.cellClassName, + }; + } + + return { + id: node.id, + header: node.label, + children: visit(node.children), + }; + }); + + return visit(group.children); +} + export const fetchProductStatistics = (req: StatisticsRequest) => nextApi.post("/statistics/product", req); diff --git a/src/lib/lg-export-excel.ts b/src/lib/lg-export-excel.ts index ea9ed47..dde4877 100644 --- a/src/lib/lg-export-excel.ts +++ b/src/lib/lg-export-excel.ts @@ -1,15 +1,17 @@ -// exportDashboardExcel.ts +// exportDashboardExcel.ts "use client"; -import {formatRowLabel} from "@/lib/lg-dashboard"; -import {DataColumn} from "@/components/lge-dashboard"; +import { buildBannerGroupColumns, formatRowLabel } from "@/lib/lg-dashboard"; +import { DataColumn, GaugeColumn } from "@/components/lge-dashboard"; +import { buildHeaderRows, getLeafColumns, type TableColumnNode } from "@/components/lge-dashboard/table/core/table-core.helpers"; +import type { BannerGroupDefinition } from "@/const/lg-banner.const"; /** * 요구사항: - * - 한 파일에 (1) PRODUCT_KEY_MAP 헤더, (2) LIFE_STAGE_COLUMNS 헤더(그룹 머지), (3) BANNER_GROUP 헤더(좌측 2칸 rowspan2 + 그룹 머지) - * - Excel export (한 시트, 섹션 간 1행 띄움) + * - 한 파일에 (1) PRODUCT_KEY_MAP 헤더, (2) LIFE_STAGE_COLUMNS 헤더, (3) BANNER_GROUP 헤더를 함께 지원 + * - Excel export는 한 시트에 여러 섹션을 순서대로 기록 * - 헤더 스타일: - * group: background = --lg-gray-400 + * group: background = --lg-gray-400 * header: background = --lg-gray-600 * font: #fff, bold */ @@ -47,9 +49,9 @@ type ExportOptions> = { sheetName?: string; sections: Section[]; // CSS 변수(없으면 기본값) - groupBgVar?: string; // default "--lg-gray-400" + groupBgVar?: string; // default "--lg-gray-400" headerBgVar?: string; // default "--lg-gray-600" - borderVar?: string; // default "--lg-gray-300" + borderVar?: string; // default "--lg-gray-300" }; /* ========================================================= @@ -208,11 +210,11 @@ function writeMergedHeader( } type AutoFitOpt = { - minColWidth?: number; // Excel column width units + minColWidth?: number; // Excel column width units maxColWidth?: number; - padding?: number; // width 여유(문자수 기준) + padding?: number; // width 여유(문자수 기준) baseRowHeight?: number; // pt - maxRowHeight?: number; // pt + maxRowHeight?: number; // pt useCanvasMeasure?: boolean; // 브라우저에서 measureText로 더 정확하게 }; @@ -257,7 +259,7 @@ function fitColumns(ws: any, mergeMap: Map, o: Required 1) { - // 머지된 텍스트는 span만큼 나눠서 분배(머지 텍스트 때문에 한 컬럼이 과대해지는 현상 방지) + // 머지된 텍스트는 span만큼 나눠서 분배(한 컬럼 폭이 과대해지는 현상 방지) const perCol = w / mi.colSpan; for (let c = mi.leftCol; c <= mi.rightCol; c++) { widths[c] = Math.max(widths[c], perCol); @@ -299,7 +301,7 @@ function fitRows(ws: any, mergeMap: Map, o: Required) { if (o.useCanvasMeasure && typeof document !== "undefined") { const px = measureTextPx(maxLine, cell); - // Excel column width 단위는 폰트마다 다르지만 Calibri 11 기준으로 px/7 정도가 근사치로 많이 씀 + // Excel column width 단위는 폰트마다 다르지만 Calibri 11 기준으로 px/7 정도를 사용 return px / 7; } - // canvas 못 쓰는 환경(또는 성능 이유) -> 문자폭 가중치 근사 + // canvas를 못 쓰는 환경이면 문자 폭 가중치로 근사 return estimateByCharWeight(maxLine); } @@ -350,11 +352,11 @@ function getMeasureCanvas() { return __canvas; } -// 한글/중국어/일본어 등 wide char 가중치 + 숫자/영문 가중치 +// 한글/CJK wide char 가중치 + 숫자/영문 가중치 function estimateByCharWeight(s: string) { let w = 0; for (const ch of s) { - if (isWideChar(ch)) w += 1.7; // 한글/한자/가나 등 + if (isWideChar(ch)) w += 1.7; // 한글/한자/가나 등 else if (ch === " ") w += 0.6; else if (/[A-Z]/.test(ch)) w += 1.1; else if (/[0-9]/.test(ch)) w += 1.0; @@ -441,7 +443,7 @@ function buildMergeMap(ws: any) { const merges = ws?._merges; if (!merges) return map; - // ws._merges: Map 형태인 경우가 많음. key가 "A1:C1" 같은 range + // ws._merges: Map 형태인 경우가 많고 key는 "A1:C1" 같은 range const keys: string[] = merges instanceof Map ? Array.from(merges.keys()) : Object.keys(merges); @@ -459,7 +461,7 @@ function buildMergeMap(ws: any) { return map; } -// "A1:C3" -> 좌표 +// "A1:C3" -> 醫뚰몴 function parseRange(range: string): Omit | null { const parts = range.split(":"); if (parts.length !== 2) return null; @@ -507,7 +509,7 @@ function colToLetters(col: number) { } /* ========================================================= - * 3) 헤더 빌더 3종 + * 3) 헤더 빌더 * ========================================================= */ /** @@ -541,138 +543,31 @@ export function buildHeader_ProductKeyMap( /** * (2) LIFE_STAGE_COLUMNS: - * - 1행: group 머지(같은 group 연속 구간) - * - 2행: header 텍스트 - * - * group 없는 컬럼은 1행에 빈 셀(그룹 스타일) 1칸 채움 + * - 트리 기반 컬럼에서 header row를 계산 + * - HTML 테이블과 동일한 merge 구조를 Excel에 적용 */ -export type GaugeColumn = { - key: string; - header: string; - rowHead?: boolean; - group?: string; - align?: "left" | "center" | "right"; -}; +function buildHeaderBlockFromColumns(cols: TableColumnNode[]): HeaderBlock { + const headerRows = buildHeaderRows(cols).map((row) => + row.map((cell) => ({ + text: cell.label, + styleKey: (cell.isLeaf ? "header" : "group") as HeaderStyleKey, + rowSpan: cell.rowSpan, + colSpan: cell.colSpan, + align: "center" as const, + })) + ); -export function buildHeader_LifeStageColumns(cols: GaugeColumn[]): HeaderBlock { - const row1: HeaderCell[] = []; - const row2: HeaderCell[] = []; - const leafKeys = cols.map((c) => c.key); + const leafKeys = getLeafColumns(cols).map((column) => String(column.key)); + return { headerRows, leafKeys, totalCols: leafKeys.length }; +} - let i = 0; - while (i < cols.length) { - const c = cols[i]; - const g = c.group; - - if (!g) { - row1.push({ text: "", styleKey: "group", colSpan: 1, align: "center" }); - i += 1; - continue; - } - - let j = i + 1; - while (j < cols.length && cols[j].group === g) j += 1; - const span = j - i; - - row1.push({ text: g, styleKey: "group", colSpan: span, align: "center" }); - i = j; - } - - for (const c of cols) { - row2.push({ text: c.header ?? "", styleKey: "header", colSpan: 1, align: "center" }); - } - - return { headerRows: [row1, row2], leafKeys, totalCols: cols.length }; +export function buildHeader_LifeStageColumns(cols: GaugeColumn[]): HeaderBlock { + return buildHeaderBlockFromColumns(cols); } export function buildHeader_DataColumn(cols: DataColumn[]): HeaderBlock { - const row1: HeaderCell[] = []; - const row2: HeaderCell[] = []; - - const leafKeys = cols.map((c) => String(c.key)); - - // 1행: 그룹 머지 / rowspan 처리 - let i = 0; - while (i < cols.length) { - const c = cols[i]; - const rs = c.headRowSpan ?? 1; - - // (A) rowspan=2면: 1행에 header를 올리고(세로머지), 2행은 빈 칸(placeholder) - if (rs === 2) { - row1.push({ - text: c.header ?? "", - styleKey: "header", - colSpan: 1, - rowSpan: 2, - align: c.align ?? "center", - }); - i += 1; - continue; - } - - // (B) 그룹 구간 처리 - const gKey = c.groupKey ?? c.group; - if (gKey) { - let j = i + 1; - while (j < cols.length) { - const cj = cols[j]; - const rsj = cj.headRowSpan ?? 1; - const gKeyJ = cj.groupKey ?? cj.group; - - // rowspan=2가 섞이면 그룹 머지 끊음(안정성) - if (rsj === 2) break; - if (gKeyJ !== gKey) break; - - j += 1; - } - - const span = j - i; - - row1.push({ - text: c.group ?? "", - styleKey: "group", - colSpan: span, - align: "center", - }); - - // 2행: 그룹 구간의 각 컬럼 header - for (let k = i; k < j; k++) { - const ck = cols[k]; - row2.push({ - text: ck.header ?? "", - styleKey: "header", - colSpan: 1, - align: ck.align ?? "center", - }); - } - - i = j; - continue; - } - - // (C) 그룹도 없고 rowspan도 아니면: 1행에 빈 group 셀 1개, 2행에 header - row1.push({ - text: "", - styleKey: "group", - colSpan: 1, - align: "center", - }); - row2.push({ - text: c.header ?? "", - styleKey: "header", - colSpan: 1, - align: c.align ?? "center", - }); - i += 1; - } - - return { - headerRows: [row1, row2], - leafKeys, - totalCols: cols.length, - }; + return buildHeaderBlockFromColumns(cols); } - /** * (3) BANNER_GROUP + BANNER_KEY_MAP: * - A1: "" (rowspan2) @@ -681,34 +576,23 @@ export function buildHeader_DataColumn(cols: DataColumn[]): HeaderBlock { * - 2행: 각 key의 라벨(BANNER_KEY_MAP[key]) */ export function buildHeader_Banner( - bannerGroup: Record, + bannerGroup: Record, bannerKeyMap: Record, rowHeadKey = "rowLabel", totalKey = "total" ): HeaderBlock { - const groups = Object.values(bannerGroup); - - const row1: HeaderCell[] = [ - { text: "", styleKey: "header", rowSpan: 2, colSpan: 1, align: "center" }, - { text: "전체", styleKey: "header", rowSpan: 2, colSpan: 1, align: "center" }, + const columns: DataColumn>[] = [ + { key: rowHeadKey, header: "" }, + { key: totalKey, header: "전체" }, + ...Object.entries(bannerGroup).map(([groupKey, group]) => ({ + id: `banner-${groupKey}`, + header: group.label, + children: buildBannerGroupColumns>(group, bannerKeyMap), + })), ]; - const row2: HeaderCell[] = []; - const leafKeys: string[] = [rowHeadKey, totalKey]; - - for (const g of groups) { - row1.push({ text: g.label, styleKey: "group", colSpan: g.keys.length, align: "center" }); - - for (const k of g.keys) { - row2.push({ text: bannerKeyMap[k] ?? k, styleKey: "header", colSpan: 1, align: "center" }); - leafKeys.push(k); - } - } - - const totalCols = 2 + groups.reduce((acc, g) => acc + g.keys.length, 0); - return { headerRows: [row1, row2], leafKeys, totalCols }; + return buildHeaderBlockFromColumns(columns); } - /* ========================================================= * 4) Export (one sheet, 섹션 간 1행 띄움) * ========================================================= */ @@ -722,7 +606,7 @@ export async function exportDashboardExcel>(opts: borderVar = "--lg-gray-300", } = opts; - // ExcelJS import (환경에 따라 min 빌드가 더 잘 먹는 경우가 있음) + // ExcelJS import (환경에 따라 min 빌드가 더 잘 동작하는 경우가 있음) const ExcelJS = await import("exceljs"); const wb = new ExcelJS.Workbook(); const ws = wb.addWorksheet(sheetName); @@ -740,7 +624,7 @@ export async function exportDashboardExcel>(opts: const gap = sec.rowGap ?? 1; const { header, rows } = sec; - // (선택) 섹션 타이틀 + // 섹션 타이틀 if (sec.title) { const r = ws.getRow(rowCursor); const c = r.getCell(1); @@ -832,4 +716,6 @@ export async function exportDashboardExcel>(opts: a.download = fileName; a.click(); URL.revokeObjectURL(url); -} \ No newline at end of file +} + + From dc9b2baeb159e340493e066439159606d943a736 Mon Sep 17 00:00:00 2001 From: kric_jspark Date: Tue, 31 Mar 2026 11:29:26 +0900 Subject: [PATCH 02/10] =?UTF-8?q?260331=5F03=5FENH:=20=EC=9D=BC=EB=B6=80?= =?UTF-8?q?=20=ED=97=A4=EB=8D=94=20=EC=9B=8C=EB=94=A9=EC=97=90=20=EC=A4=84?= =?UTF-8?q?=EB=B0=94=EA=BF=88=20=EB=B0=8F=20=EB=9D=84=EC=96=B4=EC=93=B0?= =?UTF-8?q?=EA=B8=B0=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/globals.css | 2 ++ src/const/lg-product.const.ts | 2 +- src/const/lg-schema.const.ts | 4 ++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/app/globals.css b/src/app/globals.css index 32dd539..40dec91 100644 --- a/src/app/globals.css +++ b/src/app/globals.css @@ -462,11 +462,13 @@ .lg-table thead tr.lg-table__group th { background: hsl(var(--lg-gray-400)); + white-space: pre-wrap; color: #fff; font-weight: 700; } .lg-table thead tr.lg-table__subhead th { background: hsl(var(--lg-gray-600)); + white-space: pre-wrap; color: #fff; font-weight: 700; } diff --git a/src/const/lg-product.const.ts b/src/const/lg-product.const.ts index 333d6a2..42cf81d 100644 --- a/src/const/lg-product.const.ts +++ b/src/const/lg-product.const.ts @@ -17,7 +17,7 @@ export const LIFE_STAGE_COLUMNS: GaugeColumn[] = [ ], }, { key: "KLIFEstAGE#6", header: "독립\n시니어", max: 100, align: "left" }, - { key: "KLIFEstAGE#7", header: "비혼중년", max: 100, align: "left" }, + { key: "KLIFEstAGE#7", header: "비혼 중년", max: 100, align: "left" }, { key: "KLIFEstAGE#8", header: "기타", max: 100, align: "left" }, ]; diff --git a/src/const/lg-schema.const.ts b/src/const/lg-schema.const.ts index 58d66db..da54363 100644 --- a/src/const/lg-schema.const.ts +++ b/src/const/lg-schema.const.ts @@ -27,8 +27,8 @@ export const BANNER_KEY_MAP = { "KLIFEstAGE#3": "미취학", "KLIFEstAGE#4": "취학자녀", "KLIFEstAGE#5": "성인자녀", - "KLIFEstAGE#6": "독립시니어", - "KLIFEstAGE#7": "비혼중년", + "KLIFEstAGE#6": "독립\n시니어", + "KLIFEstAGE#7": "비혼 중년", "KLIFEstAGE#8": "기타", // 가구원수 From 8540df72744c83617fa48f93ec78064c024e786f Mon Sep 17 00:00:00 2001 From: kric_jspark Date: Tue, 31 Mar 2026 11:33:05 +0900 Subject: [PATCH 03/10] =?UTF-8?q?260331=5F04=5FENH:=20=EC=9D=BC=EB=B6=80?= =?UTF-8?q?=20=ED=97=A4=EB=8D=94=20=EC=9B=8C=EB=94=A9=EC=97=90=20=EC=A4=84?= =?UTF-8?q?=EB=B0=94=EA=BF=88=20=EC=B6=94=EA=B0=802?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/const/lg-schema.const.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/const/lg-schema.const.ts b/src/const/lg-schema.const.ts index da54363..632874f 100644 --- a/src/const/lg-schema.const.ts +++ b/src/const/lg-schema.const.ts @@ -47,8 +47,8 @@ export const BANNER_KEY_MAP = { // 점유형태 "KDQ6#1": "자가", "KDQ6#2": "전세", - "KDQ6#3": "전+월세 (보증금有)", - "KDQ6#4": "월세 (보증금無)", + "KDQ6#3": "전+월세\n(보증금有)", + "KDQ6#4": "월세\n(보증금無)", "KDQ6#5": "기타", // 주거형태 From 882a5f046a7862a87fb548a45000d7abdebca488 Mon Sep 17 00:00:00 2001 From: kric_jspark Date: Tue, 31 Mar 2026 14:46:50 +0900 Subject: [PATCH 04/10] =?UTF-8?q?260331=5F05=5FENH:=20=EC=B0=A8=ED=8A=B8?= =?UTF-8?q?=EC=97=90=20=EC=82=AC=EB=A1=80=EC=88=98=20=ED=9D=98=EB=9F=AC?= =?UTF-8?q?=EB=93=A4=EC=96=B4=EA=B0=80=EC=A7=80=20=EC=95=8A=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EC=A1=B0=EC=B9=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib/lg-dashboard.ts | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/lib/lg-dashboard.ts b/src/lib/lg-dashboard.ts index 6130998..a228993 100644 --- a/src/lib/lg-dashboard.ts +++ b/src/lib/lg-dashboard.ts @@ -192,6 +192,9 @@ export function buildOverlayBarData + excludeRowLabels.some((el) => label.includes(el)); + type Opts = { /** 기본: ["사례수", "gap"] 제외 */ excludeRowLabels?: string[]; @@ -210,25 +213,22 @@ export function buildYearSeriesChartData(rows: BannerRow[], opts: Opts = {}): Ch const years = Array.from(new Set(rows.map((r) => r.year))).sort((a, b) => Number(a) - Number(b)); - // rowLabel 순서: 첫 연도 기준으로 고정(없으면 전체 unique) const baseYear = years[0]; const baseLabels = rows - .filter((r) => r.year === baseYear) - .map((r) => r.rowLabel) - .filter((l) => !excludeRowLabels.includes(l)); + .filter((r) => r.year === baseYear) + .map((r) => r.rowLabel) + .filter((l) => !shouldExcludeLabel(excludeRowLabels, l)); const labels = baseLabels.length > 0 ? baseLabels - : Array.from( - new Set(rows.map((r) => r.rowLabel).filter((l) => !excludeRowLabels.includes(l))) - ); + : Array.from(new Set(rows.map((r) => r.rowLabel).filter((l) => !shouldExcludeLabel(excludeRowLabels, l)))); - // 빠른 조회용: year -> (rowLabel -> total) const map = new Map>(); for (const y of years) map.set(y, new Map()); + for (const r of rows) { - if (excludeRowLabels.includes(r.rowLabel)) continue; + if (shouldExcludeLabel(excludeRowLabels, r.rowLabel)) continue; map.get(r.year)?.set(r.rowLabel, Number(r.total ?? 0)); } @@ -237,7 +237,7 @@ export function buildYearSeriesChartData(rows: BannerRow[], opts: Opts = {}): Ch series: years.map((y) => ({ name: yearLabel(y), data: labels.map((lbl) => map.get(y)?.get(lbl) ?? null), - ...(splitStackByYear ? { stack: String(y) } : {}), // 같은 stack이면 "연도끼리 스택"되어버리니 방지용 + ...(splitStackByYear ? { stack: String(y) } : {}), })), }; } @@ -258,13 +258,13 @@ export function buildRowLabelSeriesChartData( const baseRowLabels = rows .filter((r) => r.year === baseYear) .map((r) => r.rowLabel) - .filter((l) => !excludeRowLabels.includes(l)); + .filter((l) => !shouldExcludeLabel(excludeRowLabels, l)); const rowLabels = baseRowLabels.length > 0 ? baseRowLabels : Array.from( - new Set(rows.map((r) => r.rowLabel).filter((l) => !excludeRowLabels.includes(l))) + new Set(rows.map((r) => r.rowLabel).filter((l) => !shouldExcludeLabel(excludeRowLabels, l))) ); // (year -> (rowLabel -> total)) 맵 @@ -272,7 +272,7 @@ export function buildRowLabelSeriesChartData( for (const y of years) valueMap.set(y, new Map()); for (const r of rows) { - if (excludeRowLabels.includes(r.rowLabel)) continue; + if (shouldExcludeLabel(excludeRowLabels, r.rowLabel)) continue; valueMap.get(r.year)!.set(r.rowLabel, Number(r.total ?? 0)); } From c67971f803630586638822b46bd9199bafc2ec7b Mon Sep 17 00:00:00 2001 From: kric_jspark Date: Tue, 31 Mar 2026 15:58:58 +0900 Subject: [PATCH 05/10] =?UTF-8?q?260331=5F06=5FENH:=20=EB=B3=B4=EA=B8=89?= =?UTF-8?q?=EB=A5=A0=20=EB=B3=80=ED=99=94=20=ED=8E=98=EC=9D=B4=EC=A7=80=20?= =?UTF-8?q?=ED=95=98=EB=8B=A8=EC=97=90=20Gap=EC=97=90=20=EB=8C=80=ED=95=9C?= =?UTF-8?q?=20=EB=AC=B8=EA=B5=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../category-page/PenetrationChange.tsx | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/app/(pages)/(main)/category/sub-page/category-page/PenetrationChange.tsx b/src/app/(pages)/(main)/category/sub-page/category-page/PenetrationChange.tsx index d8026c6..4ba8a0a 100644 --- a/src/app/(pages)/(main)/category/sub-page/category-page/PenetrationChange.tsx +++ b/src/app/(pages)/(main)/category/sub-page/category-page/PenetrationChange.tsx @@ -55,12 +55,17 @@ const PenetrationChange = ({ }; return( - + <> + +
+ 전년 대비 Gap ±3%p 이상 수치 강조 : 상승 / 하락 +
+ ); } From 59943b2e456e3a08a8aeeaa40f1b794f11f9f318 Mon Sep 17 00:00:00 2001 From: kric_jspark Date: Tue, 31 Mar 2026 16:43:35 +0900 Subject: [PATCH 06/10] =?UTF-8?q?260331=5F07=5FENH:=20=EB=B3=B4=EA=B8=89?= =?UTF-8?q?=EB=A5=A0=20=EB=B3=80=ED=99=94=20=ED=8E=98=EC=9D=B4=EC=A7=80=20?= =?UTF-8?q?=ED=95=98=EB=8B=A8=EC=97=90=20Gap=EB=8C=80=EB=AC=B8=EC=9E=90?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../category/sub-page/category-page/PenetrationChange.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/(pages)/(main)/category/sub-page/category-page/PenetrationChange.tsx b/src/app/(pages)/(main)/category/sub-page/category-page/PenetrationChange.tsx index 4ba8a0a..718c89b 100644 --- a/src/app/(pages)/(main)/category/sub-page/category-page/PenetrationChange.tsx +++ b/src/app/(pages)/(main)/category/sub-page/category-page/PenetrationChange.tsx @@ -63,7 +63,7 @@ const PenetrationChange = ({ getCellClassName={getCellClassName} />
- 전년 대비 Gap ±3%p 이상 수치 강조 : 상승 / 하락 + 전년 대비 GAP ±3%p 이상 수치 강조 : 상승 / 하락
); From f6b5b21cb27324f15a49b7660c86dc21eb057615 Mon Sep 17 00:00:00 2001 From: kric_jspark Date: Tue, 31 Mar 2026 17:57:11 +0900 Subject: [PATCH 07/10] =?UTF-8?q?260331=5F08=5FENH:=20=EB=88=84=EB=9D=BD?= =?UTF-8?q?=20=EB=82=B4=EC=9A=A9=20=EC=A3=BC=EC=84=9D=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80(=EA=B3=A0=EA=B0=9D=EC=82=AC=20=EC=9A=94?= =?UTF-8?q?=EC=B2=AD=20=EC=8B=9C=20=ED=92=80=EA=B2=83)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../(main)/category/sub-page/CategoryPage.tsx | 57 ++++++++++++++++++- .../sub-page/category-page/CategoryDetail.tsx | 8 ++- 2 files changed, 59 insertions(+), 6 deletions(-) diff --git a/src/app/(pages)/(main)/category/sub-page/CategoryPage.tsx b/src/app/(pages)/(main)/category/sub-page/CategoryPage.tsx index 2386623..ec5feb0 100644 --- a/src/app/(pages)/(main)/category/sub-page/CategoryPage.tsx +++ b/src/app/(pages)/(main)/category/sub-page/CategoryPage.tsx @@ -6,7 +6,7 @@ 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 {buildCategoryFilter, buildPageModeConfig} from "@/lib/lg-dashboard"; +import {buildCategoryFilter, buildGapRow, buildPageModeConfig} from "@/lib/lg-dashboard"; 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"; @@ -18,6 +18,7 @@ export type CategoryPageProps = { fields: CategoryResolvedField[]; variableIdMap: Record; dataMap:Record | undefined; + fillGreaterThan5?: boolean; } const PAGE_COMPONENTS: Partial>> = { @@ -50,10 +51,60 @@ const CategoryPage = () => { const { data } = useBannerStatisticsQuery(req); const dataMap = data?.statisticsDataMap; const target = debouncedFilterValue.target; - const Comp = PAGE_COMPONENTS[target.value] + + //고객사 요청 시에 아래 주석 풀고 false 대신 넘기기 + const fillGreaterThan5 = false//target.value === CategoryTargetData.BRAND && !!dataMap; + + //고객사 요청 시에 아래 주석 풀고 dataMap대신 processedDataMap로 넘기기 + /* + const processedDataMap = useMemo(() => { + if (!dataMap || target.value !== CategoryTargetData.BRAND) { + return dataMap; + } + + const nextMap: Record = { ...dataMap }; + + fields.forEach((f) => { + const rows = dataMap[f.requestKeyResolved]; + if (!rows?.length) return; + + const years = Array.from(new Set(rows.map((row) => Number(row.year)))) + .filter((year) => Number.isFinite(year)) + .sort((a, b) => b - a) + .slice(0, 2); + + if (years.length < 2) { + nextMap[f.requestKeyResolved] = rows; + return; + } + + const [currentYear, prevYear] = years; + const gapRow = buildGapRow(rows, prevYear, currentYear, "LG"); + + if (!gapRow) { + nextMap[f.requestKeyResolved] = rows; + return; + } + + const nextRows: BannerRow[] = []; + rows.forEach((row) => { + nextRows.push(row); + + if (Number(row.year) === currentYear && row.rowLabel === "LG") { + nextRows.push(gapRow); + } + }); + + nextMap[f.requestKeyResolved] = nextRows; + }); + + return nextMap; + }, [dataMap, fields, target.value]); +*/ + const Comp = PAGE_COMPONENTS[target.value]; if(isTotal) return null; - return Comp ? : null; + return Comp ? : null; } export default CategoryPage; diff --git a/src/app/(pages)/(main)/category/sub-page/category-page/CategoryDetail.tsx b/src/app/(pages)/(main)/category/sub-page/category-page/CategoryDetail.tsx index f739155..118e5cc 100644 --- a/src/app/(pages)/(main)/category/sub-page/category-page/CategoryDetail.tsx +++ b/src/app/(pages)/(main)/category/sub-page/category-page/CategoryDetail.tsx @@ -13,9 +13,10 @@ import {CategoryByData} from "@/components/lge-dashboard"; import {wrapSampleRow} from "@/lib/lg-dashboard"; const CategoryDetail = ({ - fields, - dataMap - }:CategoryPageProps) => { + fields, + dataMap, + fillGreaterThan5 + }:CategoryPageProps) => { const {filterValue, registerExcelExporter} = useLayoutFilter(); const debouncedFilterValue = useDebouncedValue(filterValue as CategoryFilterValue, 500); @@ -87,6 +88,7 @@ const CategoryDetail = ({ allTableData={tableData.data} chartHeight={tableData.chartHeight} chartWidth={tableData.chartWidth} + fillGreaterThan5={fillGreaterThan5} /> ))}
From ebc72e57c2c85d9ee0a189416b4dbeb5ba86ba3f Mon Sep 17 00:00:00 2001 From: kric_jspark Date: Wed, 1 Apr 2026 09:30:41 +0900 Subject: [PATCH 08/10] =?UTF-8?q?260401=5F01=5FENH:=20=EB=88=84=EB=9D=BD?= =?UTF-8?q?=20=EB=82=B4=EC=9A=A9=20=EC=A3=BC=EC=84=9D=20=ED=92=80=EA=B3=A0?= =?UTF-8?q?=20=EC=9D=8C=EC=98=81=20=ED=91=9C=EC=8B=9C=EC=9D=98=20=EA=B2=BD?= =?UTF-8?q?=EC=9A=B0=20Brand=20=EB=BF=90=EB=A7=8C=EC=95=84=EB=8B=88?= =?UTF-8?q?=EB=9D=BC=20=EB=8B=A4=EB=A5=B8=20=ED=8E=98=EC=9D=B4=EC=A7=80?= =?UTF-8?q?=EC=97=90=EB=8F=84=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../(pages)/(main)/category/sub-page/CategoryPage.tsx | 11 +++-------- src/components/lge-dashboard/combo/CategoryByData.tsx | 6 +++++- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/app/(pages)/(main)/category/sub-page/CategoryPage.tsx b/src/app/(pages)/(main)/category/sub-page/CategoryPage.tsx index ec5feb0..6514e7c 100644 --- a/src/app/(pages)/(main)/category/sub-page/CategoryPage.tsx +++ b/src/app/(pages)/(main)/category/sub-page/CategoryPage.tsx @@ -51,12 +51,9 @@ const CategoryPage = () => { const { data } = useBannerStatisticsQuery(req); const dataMap = data?.statisticsDataMap; const target = debouncedFilterValue.target; + const Comp = PAGE_COMPONENTS[target.value]; + const fillGreaterThan5 = Comp === CategoryDetail && !!dataMap; - //고객사 요청 시에 아래 주석 풀고 false 대신 넘기기 - const fillGreaterThan5 = false//target.value === CategoryTargetData.BRAND && !!dataMap; - - //고객사 요청 시에 아래 주석 풀고 dataMap대신 processedDataMap로 넘기기 - /* const processedDataMap = useMemo(() => { if (!dataMap || target.value !== CategoryTargetData.BRAND) { return dataMap; @@ -100,11 +97,9 @@ const CategoryPage = () => { return nextMap; }, [dataMap, fields, target.value]); -*/ - const Comp = PAGE_COMPONENTS[target.value]; if(isTotal) return null; - return Comp ? : null; + return Comp ? : null; } export default CategoryPage; diff --git a/src/components/lge-dashboard/combo/CategoryByData.tsx b/src/components/lge-dashboard/combo/CategoryByData.tsx index b9d329b..c04a7e3 100644 --- a/src/components/lge-dashboard/combo/CategoryByData.tsx +++ b/src/components/lge-dashboard/combo/CategoryByData.tsx @@ -1,4 +1,7 @@ -import { bannerType, type DataColumn, DataTable, HorizontalBar, SectionTitle, SignStyle, StackBar } from "@/components/lge-dashboard"; +import { + bannerType, + BottomDescription, type DataColumn, DataTable, HorizontalBar, SectionTitle, SignStyle, StackBar +} from "@/components/lge-dashboard"; import BannerButtons from "@/components/lge-dashboard/BannerButtons"; import { categoryByDataBanner } from "@/const/filter.const"; import React, { useMemo, useState } from "react"; @@ -151,6 +154,7 @@ const CategoryByData = ({ fillGreaterThan5={fillGreaterThan5} starUnder30Sample={true} /> +
{surveyTitle}
From 3a42ac867c04f726ffee47557cf366fedc4f4b07 Mon Sep 17 00:00:00 2001 From: kric_jspark Date: Wed, 1 Apr 2026 09:49:17 +0900 Subject: [PATCH 09/10] =?UTF-8?q?260401=5F02=5FENH:=20=EB=B8=8C=EB=9E=9C?= =?UTF-8?q?=EB=93=9C=EC=9D=98=20gap=20=EB=B6=80=EB=B6=84=202=EA=B0=9C=20?= =?UTF-8?q?=EC=97=B0=EB=8F=84=20=EB=82=98=EC=98=AC=EC=88=98=20=EC=9E=88?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../(main)/category/sub-page/CategoryPage.tsx | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/app/(pages)/(main)/category/sub-page/CategoryPage.tsx b/src/app/(pages)/(main)/category/sub-page/CategoryPage.tsx index 6514e7c..6072fe1 100644 --- a/src/app/(pages)/(main)/category/sub-page/CategoryPage.tsx +++ b/src/app/(pages)/(main)/category/sub-page/CategoryPage.tsx @@ -68,26 +68,31 @@ const CategoryPage = () => { const years = Array.from(new Set(rows.map((row) => Number(row.year)))) .filter((year) => Number.isFinite(year)) .sort((a, b) => b - a) - .slice(0, 2); + .slice(0, -1); - if (years.length < 2) { + if(years.length === 0) { nextMap[f.requestKeyResolved] = rows; return; } - const [currentYear, prevYear] = years; - const gapRow = buildGapRow(rows, prevYear, currentYear, "LG"); + const gapRowsByYear = new Map(); - if (!gapRow) { - nextMap[f.requestKeyResolved] = rows; - return; - } + years.forEach((year) => { + const currentYear = year; + const prevYear = year - 1; + const gapRow = buildGapRow(rows, prevYear, currentYear, "LG"); + + if(gapRow !== null){ + gapRowsByYear.set(currentYear, gapRow); + } + }); const nextRows: BannerRow[] = []; rows.forEach((row) => { nextRows.push(row); - if (Number(row.year) === currentYear && row.rowLabel === "LG") { + const gapRow = gapRowsByYear.get(Number(row.year)); + if (row.rowLabel === "LG" && gapRow) { nextRows.push(gapRow); } }); From 26848901cf92be48da1ee5d9af43c8cceba20b03 Mon Sep 17 00:00:00 2001 From: kric_jspark Date: Wed, 1 Apr 2026 09:59:29 +0900 Subject: [PATCH 10/10] =?UTF-8?q?260401=5F03=5FENH:=20fillGreaterThan5=205?= =?UTF-8?q?=20=EC=B4=88=EA=B3=BC=EA=B0=80=20=EC=95=84=EB=8B=8C=20=EC=9D=B4?= =?UTF-8?q?=EC=83=81=EC=9C=BC=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/lge-dashboard/table/BaseDataTable.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/lge-dashboard/table/BaseDataTable.tsx b/src/components/lge-dashboard/table/BaseDataTable.tsx index bec8e16..68408ad 100644 --- a/src/components/lge-dashboard/table/BaseDataTable.tsx +++ b/src/components/lge-dashboard/table/BaseDataTable.tsx @@ -139,7 +139,7 @@ export default function BaseDataTable>({ ); } - const shouldFillCell = fillGreaterThan5 && rowTotal !== null && numericValue > rowTotal + 5; + const shouldFillCell = fillGreaterThan5 && rowTotal !== null && numericValue >= rowTotal + 5; const shouldMarkSample = starUnder30Sample && sampleRow && numericValue < 30; const displayContent = shouldMarkSample ? appendCellMarker(defaultContent, "*") : defaultContent;