diff --git a/.env.development b/.env.development index 2a94de4..ac4d44c 100644 --- a/.env.development +++ b/.env.development @@ -1,4 +1,4 @@ NEXT_PUBLIC_ENV=development ENV=development API_SERVER=http://127.0.0.1:6107/api/v1 -NEXT_PUBLIC_FILE_ORIGIN=http://127.0.0.1:6107 +BACK_SERVER=http://127.0.0.1:6107 diff --git a/.env.local b/.env.local index 7ac7c80..6ec6066 100644 --- a/.env.local +++ b/.env.local @@ -1,4 +1,4 @@ NEXT_PUBLIC_ENV=local ENV=local API_SERVER=http://localhost:6107/api/v1 -NEXT_PUBLIC_FILE_ORIGIN=http://localhost:6107 +BACK_SERVER=http://localhost:6107 diff --git a/.env.production b/.env.production index 82a8f44..e614a6a 100644 --- a/.env.production +++ b/.env.production @@ -1,4 +1,4 @@ NEXT_PUBLIC_ENV=production ENV=production API_SERVER=http://127.0.0.1:6107/api/v1 -NEXT_PUBLIC_FILE_ORIGIN=http://127.0.0.1:6107 +BACK_SERVER=http://127.0.0.1:6107 diff --git a/AGENTS.md b/AGENTS.md index 158fa34..24da8b8 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -251,6 +251,17 @@ When implementation is complete, report in Korean: - Validate external data at runtime; a shared TypeScript type alone does not validate an API response or persisted value. - Prefer named public exports and retain the consumer project's current module system and bundler conventions. +### React Compiler and Manual Memoization + +- `createKriNextConfig` enables `reactCompiler: true` unless the project overrides it; confirm the effective configuration. +- When enabled, rely on React Compiler instead of adding `useMemo`, `useCallback`, or `React.memo` as a routine performance precaution. +- Use manual memoization only for required reference stability, an Effect or third-party contract, compiler-incompatible code, or a measured performance problem. +- Preserve existing memoization unless approved and verified for removal. Use `"use memo"` or `"use no memo"` only for a documented compiler boundary. + +### Project Instruction Budget + +- Keep `.agent/project.md` at or below 8 KiB (8,192 bytes) as the normal target. Do not delete material rules merely to meet the budget; move schemas, endpoint inventories, examples, and temporary issue history to linked project documentation, and keep concise read-routing instructions here. + ### Change Safety - Pin or constrain the package version according to the consumer repository's dependency policy and commit its lockfile changes. diff --git a/next.config.ts b/next.config.ts index 7d7957e..fe4a907 100644 --- a/next.config.ts +++ b/next.config.ts @@ -1,6 +1,20 @@ import type { NextConfig } from "next"; -import { createKriNextConfig } from "@kri/common/config"; +import {createEnv, createKriNextConfig, env} from "@kri/common/config"; -const nextConfig = createKriNextConfig({}) satisfies NextConfig; +const nextEnv = createEnv({ + API_SERVER: env.required("API_SERVER", process.env.API_SERVER), + BACK_SERVER: env.required("BACK_SERVER", process.env.BACK_SERVER), +}); + +const nextConfig = createKriNextConfig({ + async rewrites() { + return [ + { + source: "/files/:path*", + destination: `${nextEnv.BACK_SERVER}/files/:path*`, + }, + ]; + }, +}) satisfies NextConfig; export default nextConfig; diff --git a/src/app/(pages)/(main)/dashboard/[waveCd]/[partCd]/page.tsx b/src/app/(pages)/(main)/dashboard/[waveCd]/[partCd]/page.tsx index 4c50fef..6c60e64 100644 --- a/src/app/(pages)/(main)/dashboard/[waveCd]/[partCd]/page.tsx +++ b/src/app/(pages)/(main)/dashboard/[waveCd]/[partCd]/page.tsx @@ -2,15 +2,24 @@ import { ChevronDown } from "lucide-react"; import { useParams, useRouter } from "next/navigation"; -import { useEffect, useState } from "react"; +import { useEffect, useRef, useState } from "react"; +import type { CSSProperties } 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 { + CHART_BAR_MAX_WIDTH, + CHART_FONT_DEFAULT, + CHART_FONT_SIZE, + CHART_GAP_MARKER_BG_COLOR, + CHART_GAP_MARKER_TEXT_COLOR, + CHART_HEIGHT, CHART_LEGEND_FONT_SIZE, + SUBITEM_NEGATIVE_COLOR, +} from "@/const/epolicy-dash.const"; import { cn } from "@/lib/utils"; -import { toChartData } from "@/lib/chart-utils"; +import { getGapPoints, getHighlightedIndexes, isNegativeCategory, 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"; @@ -26,6 +35,17 @@ function findAudienceColor(item: Item): string | undefined { return undefined; } +// 서브 탭 hover 배경처럼 색상에 알파를 입힌 은은한 톤이 필요한 곳에서 사용한다. +function hexToRgba(hex: string, alpha: number): string { + const normalized = hex.replace("#", ""); + const isShorthand = normalized.length === 3; + const r = parseInt(isShorthand ? normalized[0] + normalized[0] : normalized.slice(0, 2), 16); + const g = parseInt(isShorthand ? normalized[1] + normalized[1] : normalized.slice(2, 4), 16); + const b = parseInt(isShorthand ? normalized[2] + normalized[2] : normalized.slice(4, 6), 16); + if ([r, g, b].some((channel) => Number.isNaN(channel))) return hex; + return `rgba(${r}, ${g}, ${b}, ${alpha})`; +} + function seriesLegendName(label: string, baseCount: number | null) { return baseCount === null ? label : `${label} (N=${formatThousands(baseCount)})`; } @@ -58,35 +78,146 @@ function buildHiddenCategoryNote(group: ResultGroup): string | null { return `※ ${parts.join(isSingleSeries ? ", " : " | ")}`; } -function ResultGroupChart({ group }: { group: ResultGroup }) { +// x축 카테고리 라벨 폭을 컨테이너 실측 폭 기준으로 계산한다(카테고리당 슬롯 폭에 여유를 둔 값). +// 고정값을 쓰면 화면이 넓을 때는 불필요하게 줄바꿈되고, 좁을 때는 라벨이 겹치는 문제가 생긴다. +const MIN_AXIS_LABEL_WIDTH = 48; + +// echarts axisLabel의 overflow:'break'는 한글을 알파벳 "단어"로 인식하지 못해 음절 단위로 강제 개행한다 +// (zrender wrapText의 isWordBreakChar가 비알파벳 문자를 전부 break 지점으로 취급함). +// 그래서 공백 기준으로 단어를 유지한 채 줄바꿈 문자열을 직접 만들고, 단어 하나가 라인 폭을 넘을 때만 강제로 자른다. +function wrapLabelByWord(value: string, maxWidth: number, charWidth: number) { + const maxChars = Math.max(1, Math.floor(maxWidth / charWidth)); + const words = value.split(" "); + const lines: string[] = []; + let currentLine = ""; + + for (const word of words) { + const candidate = currentLine ? `${currentLine} ${word}` : word; + + if (candidate.length > maxChars && currentLine) { + lines.push(currentLine); + currentLine = word; + } else { + currentLine = candidate; + } + + while (currentLine.length > maxChars) { + lines.push(currentLine.slice(0, maxChars)); + currentLine = currentLine.slice(maxChars); + } + } + if (currentLine) lines.push(currentLine); + + return lines.join("\n"); +} + +function ResultGroupChart({ group, item }: { group: ResultGroup; item: Item }) { const chartData = toChartData(group.categories, group.series); + const visibleCategories = group.categories.filter((category) => category.chartVisible); + const negativeMode = group.subItem === null ? item.negativeMode : group.subItem.negativeMode; + const negativeOrder = group.subItem === null ? item.negativeOrder : group.subItem.negativeOrder; 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), +
+ { + const highlightedIndexes = series.chartHighlightMode + ? getHighlightedIndexes(group.categories, series) + : []; + const gapPoints = getGapPoints(group.categories, series); + + return { + name: seriesLegendName(series.label, series.baseCount), + data: series.values.map((value, index) => { + const category = visibleCategories[index]; + const isNegative = category ? isNegativeCategory(negativeMode, negativeOrder, category) : false; + const isHighlighted = highlightedIndexes.includes(index); + const color = isNegative + ? isHighlighted + ? series.negativeHighlightColor + : series.negativeColor + : isHighlighted + ? series.highlightColor + : series.color; + + return { value: round1(value), itemStyle: { color } }; + }), + color: negativeMode === "NEGATIVE" ? series.negativeColor : series.color, + option: { + label: { + show: true, + position: "top", + ...CHART_FONT_DEFAULT, + formatter: (params: { value: number }) => formatDecimal1(params.value), + }, + ...(gapPoints.length + ? { + markPoint: { + // 점 마커 없이, 라운딩된 사각형 배경을 가진 라벨 자체를 도형처럼 사용한다. + symbol: "circle", + symbolSize: 0, + label: { + show: true, + position: "top", + // 막대 자체의 값 라벨(position:"top")과 겹치지 않도록 그 위로 띄운다. + distance: 30, + color: CHART_GAP_MARKER_TEXT_COLOR, + backgroundColor: CHART_GAP_MARKER_BG_COLOR, + borderRadius: 20, + padding: [10, 10, 7, 10], + fontWeight: "bold", + ...CHART_FONT_DEFAULT, + formatter: ({ value }: { value: number }) => + `${value >= 0 ? "▲" : "▼"} ${formatDecimal1(Math.abs(value))}%p`, + }, + // ALL: 각 현재 막대 위치. LAST_VISIBLE: 마지막 표시 막대 위치에 표시한다. + data: gapPoints.map(({ index, value, gap }) => ({ + coord: [index, value], + value: gap, + })), + }, + } + : {}), + }, + }; + })} + legend={{ right: 0, top: 0, textStyle: { fontSize: CHART_LEGEND_FONT_SIZE } }} + grid={{ top: 85, right: 25, bottom: 5, left: 0, containLabel: true }} + xAxis={{ + axisLabel: { + ...CHART_FONT_DEFAULT, + interval: 0, + ...(axisLabelWidth + ? { formatter: (value: string) => wrapLabelByWord(value, axisLabelWidth, CHART_FONT_SIZE) } + : {}), }, - }, - }))} - 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} - /> + }} + yAxis={{ min: 0, max: 100, interval: 25, axisLabel: { show: false } }} + barMaxWidth={CHART_BAR_MAX_WIDTH} + height={CHART_HEIGHT} + /> +
); } @@ -135,11 +266,13 @@ function ItemCard({ item }: { item: Item }) { const hasSubItems = item.resultGroups.some((group) => group.subItem !== null); const activeGroup = item.resultGroups[activeGroupIndex] ?? item.resultGroups[0]; const hiddenCategoryNote = activeGroup ? buildHiddenCategoryNote(activeGroup) : null; + // subItem 코멘트가 있으면 그것을 우선 표시하고, 없으면 문항 공통 코멘트로 대체한다. + const activeComment = activeGroup?.subItem?.partItemSubComment || item.comment || null; return (
-

{item.title}

+

{item.title}

+ {activeComment && +

{activeComment}

+ } + {hasSubItems || activeComment ? ( +
+ {hasSubItems ? ( +
+ {item.resultGroups.map((group, index) => { + const isActive = index === activeGroupIndex; + const isNegativeSubItem = group.subItem?.negativeMode === "NEGATIVE"; - {hasSubItems ? ( -
-
- {item.resultGroups.map((group, index) => ( - - ))} -
+ return ( + + ); + })} +
+ ) : null}
) : null} {activeGroup ? (
- + {hiddenCategoryNote ?

{hiddenCategoryNote}

: null} {showTable ? (
@@ -187,8 +343,6 @@ function ItemCard({ item }: { item: Item }) { ) : null}
) : null} - - {item.comment ?

{item.comment}

: null}
); } @@ -221,7 +375,7 @@ export default function PartDetailPage() { } return ( -
+
{data.items.map((item) => ( diff --git a/src/app/(pages)/(main)/dashboard/[waveCd]/page.tsx b/src/app/(pages)/(main)/dashboard/[waveCd]/page.tsx index 647bc03..4970c80 100644 --- a/src/app/(pages)/(main)/dashboard/[waveCd]/page.tsx +++ b/src/app/(pages)/(main)/dashboard/[waveCd]/page.tsx @@ -48,14 +48,14 @@ export default function WaveOverviewPage() { ) : null} {data.surveys.length ? ( -
+
= 3 ? "md:grid-cols-3" : "md:grid-cols-2"}`}> {data.surveys.map((survey) => (
-

{survey.title}

+

{survey.title}

{survey.items.map((item) => (
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..e532699 100644 --- a/src/components/layout/KriSidebar.tsx +++ b/src/components/layout/KriSidebar.tsx @@ -36,7 +36,7 @@ export function KriSidebar({