260819_02_ENH: 차트 레이블 가변 줄바꿈 단어 기반으로 처리되게 수정
This commit is contained in:
@@ -62,6 +62,35 @@ function buildHiddenCategoryNote(group: ResultGroup): string | null {
|
|||||||
// 고정값을 쓰면 화면이 넓을 때는 불필요하게 줄바꿈되고, 좁을 때는 라벨이 겹치는 문제가 생긴다.
|
// 고정값을 쓰면 화면이 넓을 때는 불필요하게 줄바꿈되고, 좁을 때는 라벨이 겹치는 문제가 생긴다.
|
||||||
const MIN_AXIS_LABEL_WIDTH = 48;
|
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 }: { group: ResultGroup }) {
|
function ResultGroupChart({ group }: { group: ResultGroup }) {
|
||||||
const chartData = toChartData(group.categories, group.series);
|
const chartData = toChartData(group.categories, group.series);
|
||||||
const hasChartData = chartData.categories.length > 0 && chartData.series.length > 0;
|
const hasChartData = chartData.categories.length > 0 && chartData.series.length > 0;
|
||||||
@@ -108,7 +137,9 @@ function ResultGroupChart({ group }: { group: ResultGroup }) {
|
|||||||
axisLabel: {
|
axisLabel: {
|
||||||
fontSize: CHART_FONT_SIZE,
|
fontSize: CHART_FONT_SIZE,
|
||||||
interval: 0,
|
interval: 0,
|
||||||
...(axisLabelWidth ? { width: axisLabelWidth, overflow: "break" as const } : {}),
|
...(axisLabelWidth
|
||||||
|
? { formatter: (value: string) => wrapLabelByWord(value, axisLabelWidth, CHART_FONT_SIZE) }
|
||||||
|
: {}),
|
||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
yAxis={{ min: 0, max: 100, interval: 25, axisLabel: { fontSize: CHART_FONT_SIZE } }}
|
yAxis={{ min: 0, max: 100, interval: 25, axisLabel: { fontSize: CHART_FONT_SIZE } }}
|
||||||
|
|||||||
Reference in New Issue
Block a user