From d902e30c10a2e26eaf7b86750df2738733310703 Mon Sep 17 00:00:00 2001 From: kric_jspark Date: Wed, 19 Aug 2026 15:13:00 +0900 Subject: [PATCH] =?UTF-8?q?260819=5F01=5FENH:=20=EC=82=AC=EC=9D=B4?= =?UTF-8?q?=ED=8A=B8=20=ED=83=80=EC=9D=B4=ED=8B=80=20=ED=8F=B0=ED=8A=B8=20?= =?UTF-8?q?=EC=82=AC=EC=9D=B4=EC=A6=88=20=ED=82=A4=EC=9B=80,=20=EC=B0=A8?= =?UTF-8?q?=ED=8A=B8=20=EB=A0=88=EC=9D=B4=EB=B8=94=20=EA=B0=80=EB=B3=80=20?= =?UTF-8?q?=EC=A4=84=EB=B0=94=EA=BF=88=20=EC=B2=98=EB=A6=AC,=20=EB=84=A4?= =?UTF-8?q?=EB=B9=84=EA=B2=8C=EC=9D=B4=EC=85=98=20=ED=8C=8C=ED=8A=B8=20?= =?UTF-8?q?=EA=B0=80=EB=B3=80=20=EC=A4=84=EB=B0=94=EA=BF=88=20=EC=A0=81?= =?UTF-8?q?=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dashboard/[waveCd]/[partCd]/page.tsx | 73 +++++++++++++------ src/components/app-shell/AppHeader.tsx | 2 +- src/components/layout/KriSidebar.tsx | 2 +- 3 files changed, 53 insertions(+), 24 deletions(-) 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}문항