260819_01_ENH: 사이트 타이틀 폰트 사이즈 키움, 차트 레이블 가변 줄바꿈 처리, 네비게이션 파트 가변 줄바꿈 적용
This commit is contained in:
@@ -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<HTMLDivElement>(null);
|
||||
const [axisLabelWidth, setAxisLabelWidth] = useState<number>();
|
||||
|
||||
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 (
|
||||
<KriBarChart
|
||||
categories={chartData.categories}
|
||||
series={chartData.series.map((item) => ({
|
||||
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),
|
||||
<div ref={chartWrapperRef}>
|
||||
<KriBarChart
|
||||
categories={chartData.categories}
|
||||
series={chartData.series.map((item) => ({
|
||||
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}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ export function AppHeader({ menuOpen, showMenuButton, activeMenuId, topMenus, us
|
||||
className="h-6 w-auto object-contain brightness-0 invert"
|
||||
priority
|
||||
/>
|
||||
<span className="text-lg font-bold tracking-tight text-white">2026년 에너지 국민인식조사</span>
|
||||
<span className="text-2xl font-bold tracking-tight text-white">2026년 에너지 국민인식조사</span>
|
||||
</div>
|
||||
}
|
||||
menus={topMenus}
|
||||
|
||||
@@ -85,7 +85,7 @@ export function KriSidebar({
|
||||
onClick={() => item.path && onNavigate?.(item.path, item)}
|
||||
>
|
||||
{Icon ? <Icon className="size-4 shrink-0" /> : null}
|
||||
<span className="min-w-0 flex-1">{item.label}</span>
|
||||
<span className="min-w-0 flex-1 whitespace-normal break-keep break-words">{item.label}</span>
|
||||
<span className="shrink-0 text-xs whitespace-nowrap text-muted-foreground">{questionCount}문항</span>
|
||||
<ChevronDown className={cn('size-4 shrink-0 transition-transform', opened && 'rotate-180')} />
|
||||
</Button>
|
||||
|
||||
Reference in New Issue
Block a user