You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by GitBox <gi...@apache.org> on 2021/03/31 02:24:16 UTC

[GitHub] [echarts] plainheart commented on a change in pull request #14542: fix(label): fix labels are not on the top bug.

plainheart commented on a change in pull request #14542:
URL: https://github.com/apache/echarts/pull/14542#discussion_r604550009



##########
File path: src/core/echarts.ts
##########
@@ -2157,34 +2157,44 @@ class ECharts extends Eventful<ECEventDefinition> {
             if (model.preventAutoZ) {
                 return;
             }
-            const z = model.get('z');
-            const zlevel = model.get('zlevel');
             // Set z and zlevel
-            view.group.traverse(function (el: Displayable) {
-                if (!el.isGroup) {
-                    z != null && (el.z = z);
-                    zlevel != null && (el.zlevel = zlevel);
-
-                    // TODO if textContent is on group.
-                    const label = el.getTextContent();
-                    const labelLine = el.getTextGuideLine();
-                    if (label) {
-                        label.z = el.z;
-                        label.zlevel = el.zlevel;
-                        // lift z2 of text content
-                        // TODO if el.emphasis.z2 is spcefied, what about textContent.
-                        label.z2 = el.z2 + 2;
-                    }
-                    if (labelLine) {
-                        const showAbove = el.textGuideLineConfig && el.textGuideLineConfig.showAbove;
-                        labelLine.z = el.z;
-                        labelLine.zlevel = el.zlevel;
-                        labelLine.z2 = el.z2 + (showAbove ? 1 : -1);
-                    }
-                }
-            });
+            _updateZ(view.group, model.get('z'), model.get('zlevel'));
         };
 
+        function _updateZ(el: Element, z: number, zlevel: number) {
+            // Group may also have textContent
+            const label = el.getTextContent();
+            const labelLine = el.getTextGuideLine();
+            const isGroup = el.isGroup;
+
+            // always set z and zlevel if label/labelLine exists
+            if (label || labelLine) {
+                if (label) {
+                    label.z = z + 1;
+                    label.zlevel = zlevel;
+                    // lift z2 of text content
+                    // TODO if el.emphasis.z2 is spcefied, what about textContent.
+                    isGroup || (label.z2 = (el as Displayable).z2 + 2);
+                }
+                if (labelLine) {
+                    const showAbove = el.textGuideLineConfig && el.textGuideLineConfig.showAbove;
+                    labelLine.z = z;
+                    labelLine.zlevel = zlevel;
+                    isGroup || (labelLine.z2 = (el as Displayable).z2 + (showAbove ? 1 : -1));
+                }
+            }
+
+            if (isGroup) {
+                // set z & zlevel of children elements of Group
+                el.traverse((childEl: Element) => _updateZ(childEl, z, zlevel));

Review comment:
       Thanks a lot for the guide. For more comprehensive consideration in more cases, it would be greater if you could help do this work.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org