@@ -27,7 +27,9 @@ import ZRText from 'zrender/src/graphic/Text';
27
27
import BoundingRect , { RectLike } from 'zrender/src/core/BoundingRect' ;
28
28
import { each , isNumber } from 'zrender/src/core/util' ;
29
29
import { limitTurnAngle , limitSurfaceAngle } from '../../label/labelGuideHelper' ;
30
- import { shiftLayoutOnY } from '../../label/labelLayoutHelper' ;
30
+ import {
31
+ computeLabelGeometry , LabelGeometry , shiftLayoutOnXY
32
+ } from '../../label/labelLayoutHelper' ;
31
33
32
34
const RADIAN = Math . PI / 180 ;
33
35
@@ -139,7 +141,7 @@ function adjustSingleSide(
139
141
}
140
142
}
141
143
142
- if ( shiftLayoutOnY ( list , viewTop , viewTop + viewHeight ) ) {
144
+ if ( shiftLayoutOnXY ( list , 1 , viewTop , viewTop + viewHeight ) ) {
143
145
recalculateX ( list ) ;
144
146
}
145
147
}
@@ -212,7 +214,7 @@ function avoidOverlap(
212
214
}
213
215
layout . targetTextWidth = targetTextWidth ;
214
216
215
- constrainTextWidth ( layout , targetTextWidth ) ;
217
+ constrainTextWidth ( layout , targetTextWidth , false ) ;
216
218
}
217
219
}
218
220
@@ -267,7 +269,7 @@ function avoidOverlap(
267
269
function constrainTextWidth (
268
270
layout : LabelLayout ,
269
271
availableWidth : number ,
270
- forceRecalculate : boolean = false
272
+ forceRecalculate : boolean
271
273
) {
272
274
if ( layout . labelStyleWidth != null ) {
273
275
// User-defined style.width has the highest priority.
@@ -285,7 +287,7 @@ function constrainTextWidth(
285
287
// textRect.width already contains paddingH if bgColor is set
286
288
const oldOuterWidth = textRect . width + ( bgColor ? 0 : paddingH ) ;
287
289
if ( availableWidth < oldOuterWidth || forceRecalculate ) {
288
- const oldHeight = textRect . height ;
290
+
289
291
if ( overflow && overflow . match ( 'break' ) ) {
290
292
// Temporarily set background to be null to calculate
291
293
// the bounding box without background.
@@ -325,14 +327,20 @@ function constrainTextWidth(
325
327
label . setStyle ( 'width' , newWidth ) ;
326
328
}
327
329
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 ) ;
333
331
}
334
332
}
335
333
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
+
336
344
function isPositionCenter ( sectorShape : LabelLayout ) {
337
345
// Not change x for center label
338
346
return sectorShape . position === 'center' ;
@@ -502,12 +510,9 @@ export default function pieLabelLayout(
502
510
503
511
// Not sectorShape the inside label
504
512
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 ) ;
511
516
512
517
labelLayoutList . push ( {
513
518
label,
0 commit comments