@@ -27,7 +27,9 @@ import ZRText from 'zrender/src/graphic/Text';
2727import BoundingRect , { RectLike } from 'zrender/src/core/BoundingRect' ;
2828import { each , isNumber } from 'zrender/src/core/util' ;
2929import { limitTurnAngle , limitSurfaceAngle } from '../../label/labelGuideHelper' ;
30- import { shiftLayoutOnY } from '../../label/labelLayoutHelper' ;
30+ import {
31+ computeLabelGeometry , LabelGeometry , shiftLayoutOnXY
32+ } from '../../label/labelLayoutHelper' ;
3133
3234const RADIAN = Math . PI / 180 ;
3335
@@ -139,7 +141,7 @@ function adjustSingleSide(
139141 }
140142 }
141143
142- if ( shiftLayoutOnY ( list , viewTop , viewTop + viewHeight ) ) {
144+ if ( shiftLayoutOnXY ( list , 1 , viewTop , viewTop + viewHeight ) ) {
143145 recalculateX ( list ) ;
144146 }
145147}
@@ -212,7 +214,7 @@ function avoidOverlap(
212214 }
213215 layout . targetTextWidth = targetTextWidth ;
214216
215- constrainTextWidth ( layout , targetTextWidth ) ;
217+ constrainTextWidth ( layout , targetTextWidth , false ) ;
216218 }
217219 }
218220
@@ -267,7 +269,7 @@ function avoidOverlap(
267269function constrainTextWidth (
268270 layout : LabelLayout ,
269271 availableWidth : number ,
270- forceRecalculate : boolean = false
272+ forceRecalculate : boolean
271273) {
272274 if ( layout . labelStyleWidth != null ) {
273275 // User-defined style.width has the highest priority.
@@ -285,7 +287,7 @@ function constrainTextWidth(
285287 // textRect.width already contains paddingH if bgColor is set
286288 const oldOuterWidth = textRect . width + ( bgColor ? 0 : paddingH ) ;
287289 if ( availableWidth < oldOuterWidth || forceRecalculate ) {
288- const oldHeight = textRect . height ;
290+
289291 if ( overflow && overflow . match ( 'break' ) ) {
290292 // Temporarily set background to be null to calculate
291293 // the bounding box without background.
@@ -325,14 +327,20 @@ function constrainTextWidth(
325327 label . setStyle ( 'width' , newWidth ) ;
326328 }
327329
328- const newRect = label . getBoundingRect ( ) ;
329- textRect . width = newRect . width ;
330- const margin = ( ( label . style . margin as number ) || 0 ) + 2.1 ;
331- textRect . height = newRect . height + margin ;
332- textRect . y -= ( textRect . height - oldHeight ) / 2 ;
330+ computeLabelGlobalRect ( textRect , label ) ;
333331 }
334332}
335333
334+ function computeLabelGlobalRect ( out : BoundingRect , label : ZRText ) : void {
335+ _tmpLabelGeometry . rect = out ;
336+ computeLabelGeometry ( _tmpLabelGeometry , label , _computeLabelGeometryOpt ) ;
337+ }
338+ const _computeLabelGeometryOpt = {
339+ minMarginForce : [ null , 0 , null , 0 ] ,
340+ marginDefault : [ 1 , 0 , 1 , 0 ] , // Arbitrary value
341+ } ;
342+ const _tmpLabelGeometry : Partial < LabelGeometry > = { } ;
343+
336344function isPositionCenter ( sectorShape : LabelLayout ) {
337345 // Not change x for center label
338346 return sectorShape . position === 'center' ;
@@ -502,12 +510,9 @@ export default function pieLabelLayout(
502510
503511 // Not sectorShape the inside label
504512 if ( ! isLabelInside ) {
505- const textRect = label . getBoundingRect ( ) . clone ( ) ;
506- textRect . applyTransform ( label . getComputedTransform ( ) ) ;
507- // Text has a default 1px stroke. Exclude this.
508- const margin = ( ( label . style . margin as number ) || 0 ) + 2.1 ;
509- textRect . y -= margin / 2 ;
510- textRect . height += margin ;
513+
514+ const textRect = new BoundingRect ( 0 , 0 , 0 , 0 ) ;
515+ computeLabelGlobalRect ( textRect , label ) ;
511516
512517 labelLayoutList . push ( {
513518 label,
0 commit comments