You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by su...@apache.org on 2020/04/21 20:25:07 UTC

[incubator-echarts] branch fix/sankey-zero created (now 21283bf)

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

sushuang pushed a change to branch fix/sankey-zero
in repository https://gitbox.apache.org/repos/asf/incubator-echarts.git.


      at 21283bf  fix: tweak #12191 (when edge value sum is 0, edge and node disappear)

This branch includes the following new commits:

     new 21283bf  fix: tweak #12191 (when edge value sum is 0, edge and node disappear)

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



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


[incubator-echarts] 01/01: fix: tweak #12191 (when edge value sum is 0, edge and node disappear)

Posted by su...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 21283bf403c25964e72e52ff422b5ea8ea2a6f41
Author: 100pah <su...@gmail.com>
AuthorDate: Wed Apr 22 04:24:37 2020 +0800

    fix: tweak #12191 (when edge value sum is 0, edge and node disappear)
---
 src/chart/sankey/sankeyLayout.js | 24 +++++++++++++++++++++---
 test/sankey-depth.html           | 14 +++++++++++---
 2 files changed, 32 insertions(+), 6 deletions(-)

diff --git a/src/chart/sankey/sankeyLayout.js b/src/chart/sankey/sankeyLayout.js
index 3cca626..387b8ed 100644
--- a/src/chart/sankey/sankeyLayout.js
+++ b/src/chart/sankey/sankeyLayout.js
@@ -400,7 +400,13 @@ function relaxRightToLeft(nodesByBreadth, alpha, orient) {
         zrUtil.each(nodes, function (node) {
             if (node.outEdges.length) {
                 var y = sum(node.outEdges, weightedTarget, orient)
-                        / sum(node.outEdges, getEdgeValue, orient);
+                    / sum(node.outEdges, getEdgeValue, orient);
+
+                if (isNaN(y)) {
+                    var len = node.outEdges.length;
+                    y = len ? sum(node.outEdges, centerTarget, orient) / len : 0;
+                }
+
                 if (orient === 'vertical') {
                     var nodeX = node.getLayout().x + (y - center(node, orient)) * alpha;
                     node.setLayout({x: nodeX}, true);
@@ -417,10 +423,16 @@ function relaxRightToLeft(nodesByBreadth, alpha, orient) {
 function weightedTarget(edge, orient) {
     return center(edge.node2, orient) * edge.getValue();
 }
+function centerTarget(edge, orient) {
+    return center(edge.node2, orient);
+}
 
 function weightedSource(edge, orient) {
     return center(edge.node1, orient) * edge.getValue();
 }
+function centerSource(edge, orient) {
+    return center(edge.node1, orient);
+}
 
 function center(node, orient) {
     return orient === 'vertical'
@@ -456,9 +468,15 @@ function relaxLeftToRight(nodesByBreadth, alpha, orient) {
     zrUtil.each(nodesByBreadth, function (nodes) {
         zrUtil.each(nodes, function (node) {
             if (node.inEdges.length) {
+
                 var y = sum(node.inEdges, weightedSource, orient)
-                        / sum(node.inEdges, getEdgeValue, orient);
-                isNaN(y) && (y = 0);
+                    / sum(node.inEdges, getEdgeValue, orient);
+
+                if (isNaN(y)) {
+                    var len = node.inEdges.length;
+                    y = len ? sum(node.inEdges, centerSource, orient) / len : 0;
+                }
+
                 if (orient === 'vertical') {
                     var nodeX = node.getLayout().x + (y - center(node, orient)) * alpha;
                     node.setLayout({x: nodeX}, true);
diff --git a/test/sankey-depth.html b/test/sankey-depth.html
index 4d5e2c7..3da6b7c 100644
--- a/test/sankey-depth.html
+++ b/test/sankey-depth.html
@@ -83,7 +83,7 @@ under the License.
                         {
                             source: 'a',
                             target: 'b1',
-                            value: 3
+                            value: 0
                         },
                         {
                             source: 'b1',
@@ -93,16 +93,24 @@ under the License.
                         {
                             source: 'b1',
                             target: 'c',
-                            value: 2
+                            value: 3
                         },
                         {
                             source: 'b',
                             target: 'c',
-                            value: 1
+                            value: 3
                         }
                     ]
                 };
 
+                for (var i = 0; i < testData.nodes.length; i++) {
+                    testData.nodes[i].tooltip = {
+                        formatter: function () {
+                            return 'hello';
+                        }
+                    }
+                }
+
                 chart.setOption({
                     color: ['#67001f', '#b2182b', '#d6604d', '#f4a582', '#fddbc7', '#d1e5f0', '#92c5de', '#4393c3', '#2166ac', '#053061'],
                     tooltip: {


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