diff --git a/src/chart/treemap/TreemapView.ts b/src/chart/treemap/TreemapView.ts index 02c8f3bcee..b9224c98b2 100644 --- a/src/chart/treemap/TreemapView.ts +++ b/src/chart/treemap/TreemapView.ts @@ -58,6 +58,7 @@ import { ColorString, ECElement } from '../../util/types'; import { windowOpen } from '../../util/format'; import { TextStyleProps } from 'zrender/src/graphic/Text'; import { setLabelStyle, getLabelStatesModels } from '../../label/labelStyle'; +import { calculateTextPosition, TextPositionCalculationResult } from 'zrender/src/contain/text'; const Group = graphic.Group; const Rect = graphic.Rect; @@ -1001,10 +1002,14 @@ function renderNode( (upperLabelRect ? upperLabelRect.height : rectEl.shape.height) - textPadding[0] - textPadding[2], 0 ); if (textStyle.width !== width || textStyle.height !== height) { - textEl.setStyle({ - width, - height - }); + const {textConfig} = rectEl; + const res = calculateTextPosition( + {} as TextPositionCalculationResult, + textConfig, + textConfig.layoutRect ?? new BoundingRect(0, 0, 0, 0) + ); + + textEl.setStyle(res); } }; diff --git a/test/treemap-option-label-position-with-rich.html b/test/treemap-option-label-position-with-rich.html new file mode 100644 index 0000000000..28bf0fe3f5 --- /dev/null +++ b/test/treemap-option-label-position-with-rich.html @@ -0,0 +1,97 @@ + + + + +
+ + + + + + + + + + + + + + +