Skip to content
Open
Show file tree
Hide file tree
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
26 changes: 19 additions & 7 deletions src/chart/pie/labelLayout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,17 +289,29 @@ function constrainTextWidth(
if (availableWidth < oldOuterWidth || forceRecalculate) {

if (overflow && overflow.match('break')) {
// Temporarily set background to be null to calculate
// the bounding box without background.
label.setStyle('backgroundColor', null);
// Set constraining width
label.setStyle('width', availableWidth - paddingH);
// Temporarily remove everything that makes zrender add a
// background rect (backgroundColor, lineHeight, border), because
// that rect takes the constraining width rather than the width of
// the wrapped text, and would be included in the bounding box.
const lineHeight = style.lineHeight;
const borderWidth = style.borderWidth;
label.setStyle({
backgroundColor: null,
lineHeight: null,
borderWidth: null,
// Set constraining width
width: availableWidth - paddingH
});

// This is the real bounding box of the text without padding.
const innerRect = label.getBoundingRect();

label.setStyle('width', Math.ceil(innerRect.width));
label.setStyle('backgroundColor', bgColor);
label.setStyle({
width: Math.ceil(innerRect.width),
backgroundColor: bgColor,
lineHeight,
borderWidth
});
}
else {
const availableInnerWidth = availableWidth - paddingH;
Expand Down
82 changes: 82 additions & 0 deletions test/ut/spec/series/pie.test.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.