Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(echarts#16611): the text rich align error #897

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/graphic/Text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,14 @@ class ZRText extends Displayable<TextProps> implements GroupLike {
leftIndex++;
}

while (leftIndex < tokenCount
&& (token = tokens[leftIndex], !token.align || token.align === 'right')) {
remainedWidth -= token.width;
lineXLeft += token.width;
this._placeToken(token, style, lineHeight, lineTop, lineXLeft, 'right', bgColorDrawn);
leftIndex++;
}

while (
rightIndex >= 0
&& (token = tokens[rightIndex], token.align === 'right')
Expand All @@ -684,7 +692,14 @@ class ZRText extends Displayable<TextProps> implements GroupLike {
lineXRight -= token.width;
rightIndex--;
}

while (rightIndex >= 0
&& (token = tokens[rightIndex], token.align === 'left')) {
lineXRight -= token.width;
this._placeToken(token, style, lineHeight, lineTop, lineXRight, 'left', bgColorDrawn);
remainedWidth -= token.width;
rightIndex--;
}

// The other tokens are placed as textAlign 'center' if there is enough space.
lineXLeft += (contentWidth - (lineXLeft - xLeft) - (xRight - lineXRight) - remainedWidth) / 2;
while (leftIndex <= rightIndex) {
Expand Down