diff --git a/src/app/(pages)/(main)/dashboard/[waveCd]/[partCd]/page.tsx b/src/app/(pages)/(main)/dashboard/[waveCd]/[partCd]/page.tsx index 6b0f3c1..4c50fef 100644 --- a/src/app/(pages)/(main)/dashboard/[waveCd]/[partCd]/page.tsx +++ b/src/app/(pages)/(main)/dashboard/[waveCd]/[partCd]/page.tsx @@ -1,69 +1,194 @@ "use client"; +import { ChevronDown } from "lucide-react"; import { useParams, useRouter } from "next/navigation"; -import { useEffect } from "react"; +import { useEffect, useState } from "react"; import { KriBarChart } from "@/components/chart"; import { AppPageTitle } from "@/components/app-shell/AppPageTitle"; import { Badge } from "@/components/ui/badge"; +import { Button } from "@/components/ui/button"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"; +import { CHART_BAR_MAX_WIDTH, CHART_FONT_SIZE, CHART_HEIGHT } from "@/const/epolicy-dash.const"; +import { cn } from "@/lib/utils"; import { toChartData } from "@/lib/chart-utils"; +import { formatDecimal1, formatThousands, round1 } from "@/lib/format"; import { isSessionInvalid, resolveApiErrorMessage } from "@/lib/api-error-message"; import { usePartDetailQuery } from "@/query/waves"; -import type { ResultGroup } from "@/types/wave"; +import type { Item, ResultGroup } from "@/types/wave"; -function ResultGroupBlock({ group }: { group: ResultGroup }) { +// audience.type이 SURVEY인 문항의 대표 색상은 실제 응답에 포함된 series[].color를 그대로 사용한다. +// surveyCd/label 기준으로 색상을 별도 매핑하지 않는다. +function findAudienceColor(item: Item): string | undefined { + for (const group of item.resultGroups) { + const withColor = group.series.find((series) => series.color); + if (withColor) return withColor.color; + } + return undefined; +} + +function seriesLegendName(label: string, baseCount: number | null) { + return baseCount === null ? label : `${label} (N=${formatThousands(baseCount)})`; +} + +// 차트에서 숨겨진(chartVisible=false) 카테고리를 각주로 만든다. 값이 0인 항목은 무시한다. +// 시리즈(설문)가 하나뿐이면 "※ 기타 0.9%, 모름·무응답 2.3%"처럼 시리즈명을 생략하고, +// 여러 개면 "※ 기타 : 일반국민 0.9%, 전문가 3.8% | 모름·무응답 : 일반국민 2.5%"처럼 구분해서 표기한다. +function buildHiddenCategoryNote(group: ResultGroup): string | null { + const isSingleSeries = group.series.length === 1; + + const parts = group.categories + .map((category, index) => { + if (category.chartVisible) return null; + + const entries = group.series + .map((series) => ({ label: series.label, value: series.values[index] })) + .filter((entry) => entry.value !== 0); + if (!entries.length) return null; + + if (isSingleSeries) { + return `${category.label} ${formatDecimal1(entries[0].value)}%`; + } + + const valueText = entries.map((entry) => `${entry.label} ${formatDecimal1(entry.value)}%`).join(", "); + return `${category.label} : ${valueText}`; + }) + .filter((part): part is string => part !== null); + + if (!parts.length) return null; + return `※ ${parts.join(isSingleSeries ? ", " : " | ")}`; +} + +function ResultGroupChart({ group }: { group: ResultGroup }) { const chartData = toChartData(group.categories, group.series); const hasChartData = chartData.categories.length > 0 && chartData.series.length > 0; - return ( -
{group.subItem.title}
: null} + if (!hasChartData) return null; - {hasChartData ? ( -데이터가 없습니다.
; + } + + return ( +{item.title}
+{hiddenCategoryNote}
: null} + {showTable ? ( +데이터가 없습니다.
- )} + ) : null} + + {item.comment ?{item.comment}
: null}{item.title}
-{item.comment}
: null} -{survey.title}
+{survey.title}