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

sushuang pushed a commit to branch fix/bar-race
in repository https://gitbox.apache.org/repos/asf/incubator-echarts.git

commit 9a85475676bbb2fe0fc3c07962dd810171c587cd
Author: 100pah <[email protected]>
AuthorDate: Wed Jan 6 16:33:14 2021 +0800

    fix: if a bar element is totally clipped (marked as `el.ignore: true`), 
place the element at the edge of the coordinate system bounding rect with 
width/height 0. Because if data changed and the element show again, the 
transition animation of this element will start at this place.
---
 src/chart/bar/BarView.ts | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)

diff --git a/src/chart/bar/BarView.ts b/src/chart/bar/BarView.ts
index 3e5c4c9..7c768e7 100644
--- a/src/chart/bar/BarView.ts
+++ b/src/chart/bar/BarView.ts
@@ -606,17 +606,24 @@ const clip: {
             layout.height = -layout.height;
         }
 
+        const coordSysX2 = coordSysBoundingRect.x + coordSysBoundingRect.width;
+        const coordSysY2 = coordSysBoundingRect.y + 
coordSysBoundingRect.height;
         const x = mathMax(layout.x, coordSysBoundingRect.x);
-        const x2 = mathMin(layout.x + layout.width, coordSysBoundingRect.x + 
coordSysBoundingRect.width);
+        const x2 = mathMin(layout.x + layout.width, coordSysX2);
         const y = mathMax(layout.y, coordSysBoundingRect.y);
-        const y2 = mathMin(layout.y + layout.height, coordSysBoundingRect.y + 
coordSysBoundingRect.height);
+        const y2 = mathMin(layout.y + layout.height, coordSysY2);
 
-        layout.x = x;
-        layout.y = y;
-        layout.width = x2 - x;
-        layout.height = y2 - y;
+        const xClipped = x2 < x;
+        const yClipped = y2 < y;
 
-        const clipped = layout.width < 0 || layout.height < 0;
+        // When xClipped or yClipped, the element will be marked as `ignore`.
+        // But we should also place the element at the edge of the coord sys 
bounding rect.
+        // Beause if data changed and the bar show again, its transition 
animaiton
+        // will begin at this place.
+        layout.x = (xClipped && x > coordSysX2) ? x2 : x;
+        layout.y = (yClipped && y > coordSysY2) ? y2 : y;
+        layout.width = xClipped ? 0 : x2 - x;
+        layout.height = yClipped ? 0 : y2 - y;
 
         // Reverse back
         if (signWidth < 0) {
@@ -628,7 +635,7 @@ const clip: {
             layout.height = -layout.height;
         }
 
-        return clipped;
+        return xClipped || yClipped;
     },
 
     polar(coordSysClipArea: PolarCoordArea, layout: Sector['shape']) {


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

Reply via email to