diff --git a/src/app/(pages)/(main)/dashboard/[waveCd]/[partCd]/page.tsx b/src/app/(pages)/(main)/dashboard/[waveCd]/[partCd]/page.tsx index 4c50fef..17f4111 100644 --- a/src/app/(pages)/(main)/dashboard/[waveCd]/[partCd]/page.tsx +++ b/src/app/(pages)/(main)/dashboard/[waveCd]/[partCd]/page.tsx @@ -2,7 +2,7 @@ import { ChevronDown } from "lucide-react"; import { useParams, useRouter } from "next/navigation"; -import { useEffect, useState } from "react"; +import { useEffect, useRef, useState } from "react"; import { KriBarChart } from "@/components/chart"; import { AppPageTitle } from "@/components/app-shell/AppPageTitle"; import { Badge } from "@/components/ui/badge"; @@ -58,35 +58,64 @@ function buildHiddenCategoryNote(group: ResultGroup): string | null { return `※ ${parts.join(isSingleSeries ? ", " : " | ")}`; } +// x축 카테고리 라벨 폭을 컨테이너 실측 폭 기준으로 계산한다(카테고리당 슬롯 폭에 여유를 둔 값). +// 고정값을 쓰면 화면이 넓을 때는 불필요하게 줄바꿈되고, 좁을 때는 라벨이 겹치는 문제가 생긴다. +const MIN_AXIS_LABEL_WIDTH = 48; + function ResultGroupChart({ group }: { group: ResultGroup }) { const chartData = toChartData(group.categories, group.series); const hasChartData = chartData.categories.length > 0 && chartData.series.length > 0; + const chartWrapperRef = useRef(null); + const [axisLabelWidth, setAxisLabelWidth] = useState(); + + useEffect(() => { + const el = chartWrapperRef.current; + if (!el || chartData.categories.length === 0) return; + + const updateAxisLabelWidth = () => { + const width = (el.clientWidth / chartData.categories.length) * 0.85; + setAxisLabelWidth(Math.max(MIN_AXIS_LABEL_WIDTH, width)); + }; + + updateAxisLabelWidth(); + const observer = new ResizeObserver(updateAxisLabelWidth); + observer.observe(el); + return () => observer.disconnect(); + }, [chartData.categories.length]); if (!hasChartData) return null; return ( - ({ - name: seriesLegendName(item.label, item.baseCount), - data: item.values.map(round1), - color: item.color, - option: { - label: { - show: true, - position: "top", - fontSize: CHART_FONT_SIZE, - formatter: (params: { value: number }) => formatDecimal1(params.value), +
+ ({ + name: seriesLegendName(item.label, item.baseCount), + data: item.values.map(round1), + color: item.color, + option: { + label: { + show: true, + position: "top", + fontSize: CHART_FONT_SIZE, + formatter: (params: { value: number }) => formatDecimal1(params.value), + }, }, - }, - }))} - legend={{ left: 0, top: 0, textStyle: { fontSize: CHART_FONT_SIZE } }} - grid={{ top: 55, right: 25, bottom: 5, left: 0, containLabel: true }} - xAxis={{ axisLabel: { fontSize: CHART_FONT_SIZE, interval: 0 } }} - yAxis={{ min: 0, max: 100, interval: 25, axisLabel: { fontSize: CHART_FONT_SIZE } }} - barMaxWidth={CHART_BAR_MAX_WIDTH} - height={CHART_HEIGHT} - /> + }))} + legend={{ left: 0, top: 0, textStyle: { fontSize: CHART_FONT_SIZE } }} + grid={{ top: 55, right: 25, bottom: 5, left: 0, containLabel: true }} + xAxis={{ + axisLabel: { + fontSize: CHART_FONT_SIZE, + interval: 0, + ...(axisLabelWidth ? { width: axisLabelWidth, overflow: "break" as const } : {}), + }, + }} + yAxis={{ min: 0, max: 100, interval: 25, axisLabel: { fontSize: CHART_FONT_SIZE } }} + barMaxWidth={CHART_BAR_MAX_WIDTH} + height={CHART_HEIGHT} + /> +
); } diff --git a/src/components/app-shell/AppHeader.tsx b/src/components/app-shell/AppHeader.tsx index c3b1ef7..14f8c63 100644 --- a/src/components/app-shell/AppHeader.tsx +++ b/src/components/app-shell/AppHeader.tsx @@ -30,7 +30,7 @@ export function AppHeader({ menuOpen, showMenuButton, activeMenuId, topMenus, us className="h-6 w-auto object-contain brightness-0 invert" priority /> - 2026년 에너지 국민인식조사 + 2026년 에너지 국민인식조사 } menus={topMenus} diff --git a/src/components/layout/KriSidebar.tsx b/src/components/layout/KriSidebar.tsx index d206860..9f22a2f 100644 --- a/src/components/layout/KriSidebar.tsx +++ b/src/components/layout/KriSidebar.tsx @@ -85,7 +85,7 @@ export function KriSidebar({ onClick={() => item.path && onNavigate?.(item.path, item)} > {Icon ? : null} - {item.label} + {item.label} {questionCount}문항