|
|
|
|
@@ -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>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|