Skip to content

Commit

Permalink
[#850] [3.0] chart - seriesName, Axis Label 이 길어질 경우 예외 처리 (코드리뷰 피드백 반영)
Browse files Browse the repository at this point in the history
- testXXX -> temp 등으로 수정
  • Loading branch information
jhee564 committed Aug 4, 2021
1 parent 76d869e commit 7bfcf3c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
16 changes: 8 additions & 8 deletions src/components/chart/helpers/helpers.util.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,19 +244,19 @@ export default {
const ellipsis = '…';
const ellipsisWidth = ctx.measureText(ellipsis).width;

let testStr = str;
let testStrWidth = ctx.measureText(testStr).width;
let temp = str;
let tempWidth = ctx.measureText(temp).width;

if (testStrWidth <= maxWidth || testStrWidth <= ellipsisWidth) {
if (tempWidth <= maxWidth || tempWidth <= ellipsisWidth) {
return str;
}

let len = testStr.length;
while (testStrWidth >= maxWidth - ellipsisWidth && len-- > 0) {
testStr = direction === 'right' ? testStr.substring(0, len) : testStr.substring(1, testStr.length);
testStrWidth = ctx.measureText(testStr).width;
let len = temp.length;
while (tempWidth >= maxWidth - ellipsisWidth && len-- > 0) {
temp = direction === 'right' ? temp.substring(0, len) : temp.substring(1, temp.length);
tempWidth = ctx.measureText(temp).width;
}

return direction === 'right' ? testStr + ellipsis : ellipsis + testStr;
return direction === 'right' ? temp + ellipsis : ellipsis + temp;
},
};
12 changes: 6 additions & 6 deletions src/components/chart/plugins/plugins.tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ const modules = {
let line = '';
for (let jx = 0; jx < name.length; jx++) {
const char = name[jx];
const testText = `${line}${char}`;
if (ctx.measureText(testText).width > seriesNameSpaceWidth) {
const temp = `${line}${char}`;
if (ctx.measureText(temp).width > seriesNameSpaceWidth) {
line = char;
textLineCnt += 1;
} else {
line = testText;
line = temp;
}
}
}
Expand Down Expand Up @@ -281,15 +281,15 @@ const modules = {

for (let jx = 0; jx < name.length; jx++) {
const char = name[jx];
const testText = `${line}${char}`;
const temp = `${line}${char}`;

if (ctx.measureText(testText).width > seriesNameSpaceWidth) {
if (ctx.measureText(temp).width > seriesNameSpaceWidth) {
ctx.fillText(line, xPos, yPosWithWrap);
line = char;
textLineCnt += 1;
yPosWithWrap += TEXT_HEIGHT;
} else {
line = testText;
line = temp;
}
}
ctx.fillText(line, xPos, yPosWithWrap);
Expand Down

0 comments on commit 7bfcf3c

Please sign in to comment.