This is an automated email from the ASF dual-hosted git repository.

sushuang pushed a commit to branch fix/contain-label-name
in repository https://gitbox.apache.org/repos/asf/echarts.git

commit 54de7f048beaa2bf864457c8002cdea334b227cb
Author: 100pah <[email protected]>
AuthorDate: Tue Jun 24 12:37:59 2025 +0800

    fix(grid layout): fix maxMargin introduced by previous commits.
---
 src/label/LabelManager.ts      |  1 +
 src/label/labelLayoutHelper.ts |  2 +-
 src/util/graphic.ts            | 28 +++++++++++++---------------
 src/util/number.ts             |  3 ++-
 4 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/src/label/LabelManager.ts b/src/label/LabelManager.ts
index 9fe50efc4..2f262c4eb 100644
--- a/src/label/LabelManager.ts
+++ b/src/label/LabelManager.ts
@@ -71,6 +71,7 @@ interface LabelDesc extends LabelLayoutInfoRaw {
     dataType?: SeriesDataType
 
     layoutOptionOrCb: LabelLayoutOptionCallback | LabelLayoutOption
+    // Computed (cb called) layout option.
     layoutOption: LabelLayoutOption
 
     hostRect: RectLike
diff --git a/src/label/labelLayoutHelper.ts b/src/label/labelLayoutHelper.ts
index 6c9001c7a..10321d915 100644
--- a/src/label/labelLayoutHelper.ts
+++ b/src/label/labelLayoutHelper.ts
@@ -141,7 +141,7 @@ function prepareLabelLayoutInfo(
     if (!ignoreMargin && (label.style as LabelExtendedTextStyle).__marginType 
=== LabelMarginType.minMargin) {
         // `minMargin` only support number value.
         const halfMinMargin = ((label.style.margin as number) || 0) / 2;
-        expandOrShrinkRect(globalRect, halfMinMargin, true, true);
+        expandOrShrinkRect(globalRect, halfMinMargin, false, false);
     }
 
     const computed = layoutInfo as LabelLayoutInfoComputed;
diff --git a/src/util/graphic.ts b/src/util/graphic.ts
index a965b1200..99b1c0e26 100644
--- a/src/util/graphic.ts
+++ b/src/util/graphic.ts
@@ -80,6 +80,7 @@ import {
     isElementRemoved
 } from '../animation/basicTransition';
 import { ExtendedElement } from '../core/ExtendedElement';
+import { mathMin, mathMax, mathAbs } from './number';
 
 /**
  * @deprecated export for compatitable reason
@@ -87,9 +88,6 @@ import { ExtendedElement } from '../core/ExtendedElement';
 export {updateProps, initProps, removeElement, removeElementWithFadeOut, 
isElementRemoved};
 
 
-const mathMax = Math.max;
-const mathMin = Math.min;
-
 const _customShapeMap: Dictionary<{ new(): Path }> = {};
 
 type ExtendShapeOpt = Parameters<typeof Path.extend>[0];
@@ -367,9 +365,9 @@ export function transformDirection(
 
     // Pick a base, ensure that transform result will not be (0, 0).
     const hBase = (transform[4] === 0 || transform[5] === 0 || transform[0] 
=== 0)
-        ? 1 : Math.abs(2 * transform[4] / transform[0]);
+        ? 1 : mathAbs(2 * transform[4] / transform[0]);
     const vBase = (transform[4] === 0 || transform[5] === 0 || transform[2] 
=== 0)
-        ? 1 : Math.abs(2 * transform[4] / transform[2]);
+        ? 1 : mathAbs(2 * transform[4] / transform[2]);
 
     let vertex: vector.VectorArray = [
         direction === 'left' ? -hBase : direction === 'right' ? hBase : 0,
@@ -378,7 +376,7 @@ export function transformDirection(
 
     vertex = applyTransform(vertex, transform, invert);
 
-    return Math.abs(vertex[0]) > Math.abs(vertex[1])
+    return mathAbs(vertex[0]) > mathAbs(vertex[1])
         ? (vertex[0] > 0 ? 'right' : 'left')
         : (vertex[1] > 0 ? 'bottom' : 'top');
 }
@@ -614,10 +612,10 @@ export function expandOrShrinkRect<TRect extends 
RectLike>(
         _tmpExpandRectDelta[3] = delta[3];
     }
     if (noNegative) {
-        _tmpExpandRectDelta[0] = Math.max(0, _tmpExpandRectDelta[0]);
-        _tmpExpandRectDelta[1] = Math.max(0, _tmpExpandRectDelta[1]);
-        _tmpExpandRectDelta[2] = Math.max(0, _tmpExpandRectDelta[2]);
-        _tmpExpandRectDelta[3] = Math.max(0, _tmpExpandRectDelta[3]);
+        _tmpExpandRectDelta[0] = mathMax(0, _tmpExpandRectDelta[0]);
+        _tmpExpandRectDelta[1] = mathMax(0, _tmpExpandRectDelta[1]);
+        _tmpExpandRectDelta[2] = mathMax(0, _tmpExpandRectDelta[2]);
+        _tmpExpandRectDelta[3] = mathMax(0, _tmpExpandRectDelta[3]);
     }
     if (shrinkOrExpand) {
         _tmpExpandRectDelta[0] = -_tmpExpandRectDelta[0];
@@ -643,7 +641,7 @@ function expandRectOnOneDimension(
         rect[xy] += (
             delta[ltIdx] >= 0 ? -delta[ltIdx]
             : delta[rbIdx] >= 0 ? oldSize + delta[rbIdx]
-            : Math.abs(deltaSum) > 1e-8 ? oldSize * delta[ltIdx] / deltaSum
+            : mathAbs(deltaSum) > 1e-8 ? oldSize * delta[ltIdx] / deltaSum
             : 0
         );
     }
@@ -729,8 +727,8 @@ export function traverseElements(els: Element | Element[] | 
undefined | null, cb
  */
 export function isBoundingRectAxisAligned(transform: matrix.MatrixArray | 
NullUndefined): boolean {
     return !transform
-        || (Math.abs(transform[1]) < AXIS_ALIGN_EPSILON && 
Math.abs(transform[2]) < AXIS_ALIGN_EPSILON)
-        || (Math.abs(transform[0]) < AXIS_ALIGN_EPSILON && 
Math.abs(transform[3]) < AXIS_ALIGN_EPSILON);
+        || (mathAbs(transform[1]) < AXIS_ALIGN_EPSILON && 
mathAbs(transform[2]) < AXIS_ALIGN_EPSILON)
+        || (mathAbs(transform[0]) < AXIS_ALIGN_EPSILON && 
mathAbs(transform[3]) < AXIS_ALIGN_EPSILON);
 }
 const AXIS_ALIGN_EPSILON = 1e-5;
 
@@ -821,7 +819,7 @@ function doUpdateZ(
         // set z & zlevel of children elements of Group
         const children = (el as Group).childrenRef();
         for (let i = 0; i < children.length; i++) {
-            maxZ2 = Math.max(
+            maxZ2 = mathMax(
                 doUpdateZ(
                     children[i],
                     z,
@@ -836,7 +834,7 @@ function doUpdateZ(
         (el as Displayable).z = z;
         (el as Displayable).zlevel = zlevel;
 
-        maxZ2 = Math.max((el as Displayable).z2 || 0, maxZ2);
+        maxZ2 = mathMax((el as Displayable).z2 || 0, maxZ2);
     }
 
     // always set z and zlevel if label/labelLine exists
diff --git a/src/util/number.ts b/src/util/number.ts
index 85807cb3c..648c2d996 100644
--- a/src/util/number.ts
+++ b/src/util/number.ts
@@ -39,6 +39,7 @@ function _trim(str: string): string {
 
 export const mathMin = Math.min;
 export const mathMax = Math.max;
+export const mathAbs = Math.abs;
 
 /**
  * Linear mapping a value from domain to range
@@ -229,7 +230,7 @@ export function getPixelPrecision(dataExtent: [number, 
number], pixelExtent: [nu
     const log = Math.log;
     const LN10 = Math.LN10;
     const dataQuantity = Math.floor(log(dataExtent[1] - dataExtent[0]) / LN10);
-    const sizeQuantity = Math.round(log(Math.abs(pixelExtent[1] - 
pixelExtent[0])) / LN10);
+    const sizeQuantity = Math.round(log(mathAbs(pixelExtent[1] - 
pixelExtent[0])) / LN10);
     // toFixed() digits argument must be between 0 and 20.
     const precision = Math.min(Math.max(-dataQuantity + sizeQuantity, 0), 20);
     return !isFinite(precision) ? 20 : precision;


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to