Skip to content

Commit ecff1a8

Browse files
committed
fix: boundingRect.x of text is incorrect when overflow: 'truncate'.
memo info: This code used to be modified in commit bd2642e and bd2642e , where the `boundingRect.width` was modified from `style.width` to `innerWith` and then `outerWith`, but the `boundingRect.x` was not modified correspondingly. Related issue: apache/echarts#18306 . And #1091 located the problematic code successfully but the fix was not entirely correct.
1 parent e4766d8 commit ecff1a8

File tree

2 files changed

+14
-17
lines changed

2 files changed

+14
-17
lines changed

src/graphic/Text.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ class ZRText extends Displayable<TextProps> implements GroupLike {
602602

603603
if (fixedBoundingRect) {
604604
el.setBoundingRect(new BoundingRect(
605-
adjustTextX(subElStyle.x, style.width, subElStyle.textAlign as TextAlign),
605+
adjustTextX(subElStyle.x, contentWidth, subElStyle.textAlign as TextAlign),
606606
adjustTextY(subElStyle.y, calculatedLineHeight, subElStyle.textBaseline as TextVerticalAlign),
607607
/**
608608
* Text boundary should be the real text width.

test/text-overflow.html

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
fixedLineHeight: false,
3333
lineHeight: 14,
3434
rich: true,
35-
breakAll: false
35+
overflow: 'break'
3636
}
3737

3838

@@ -72,23 +72,20 @@
7272

7373
const TEXTS = [LARGE_TEXT_EN, LARGE_TEXT_ZH];
7474
function update() {
75-
enText.style.width = cnText.style.width = config.width;
76-
enText.style.height = cnText.style.height = config.height;
77-
78-
enText.style.overflow = config.breakAll ? 'breakAll' : 'break';
79-
8075
cnText.style.x = config.width + 100;
8176

82-
enText.style.rich = cnText.style.rich = config.rich ? {
83-
highlight: {
84-
// padding: 4,
85-
backgroundColor: 'yellow',
86-
fontSize: 20
87-
}
88-
} : null;
89-
9077
[enText, cnText].forEach((text, idx) => {
91-
text.style.fontSize = cnText.style.fontSize = config.fontSize;
78+
text.style.fontSize = config.fontSize;
79+
text.style.width = config.width;
80+
text.style.height = config.height;
81+
text.style.overflow = config.overflow;
82+
text.style.rich = config.rich ? {
83+
highlight: {
84+
// padding: 4,
85+
backgroundColor: 'yellow',
86+
fontSize: 20
87+
}
88+
} : null;
9289

9390
if (config.search) {
9491
text.style.text = TEXTS[idx].replace(
@@ -121,7 +118,7 @@
121118
gui.add(config, 'fixedLineHeight').onChange(update);
122119
gui.add(config, 'lineHeight', 12, 50).onChange(update);
123120
gui.add(config, 'rich').onChange(update);
124-
gui.add(config, 'breakAll').onChange(update);
121+
gui.add(config, 'overflow', ['break', 'breakAll', 'truncate', 'none']).onChange(update);
125122

126123
update();
127124
</script>

0 commit comments

Comments
 (0)