You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by de...@apache.org on 2018/10/19 08:26:56 UTC

[incubator-echarts] 01/02: feat(sankey): support specify the node depth with constant y position

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

deqingli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-echarts.git

commit 7fa2572129a3bd76b6eadd6267499a957adc5c30
Author: deqingli <an...@gmail.com>
AuthorDate: Thu Oct 18 21:20:26 2018 +0800

    feat(sankey): support specify the node depth with constant y position
---
 src/chart/sankey/sankeyLayout.js | 35 ++++++++++++++++++++++-------------
 1 file changed, 22 insertions(+), 13 deletions(-)

diff --git a/src/chart/sankey/sankeyLayout.js b/src/chart/sankey/sankeyLayout.js
index 37fde87..8ea5020 100644
--- a/src/chart/sankey/sankeyLayout.js
+++ b/src/chart/sankey/sankeyLayout.js
@@ -80,8 +80,9 @@ function getViewRect(seriesModel, api) {
 }
 
 function layoutSankey(nodes, edges, nodeWidth, nodeGap, width, height, iterations, orient, nodeAlign) {
-    computeNodeBreadths(nodes, edges, nodeWidth, width, height, orient, nodeAlign);
+    var kx = computeNodeBreadths(nodes, edges, nodeWidth, width, height, orient, nodeAlign);
     computeNodeDepths(nodes, edges, height, width, nodeGap, iterations, orient);
+    scaleNodeBreadths(nodes, kx, orient);
     computeEdgeDepths(nodes, orient);
 }
 
@@ -227,12 +228,7 @@ function computeNodeBreadths(nodes, edges, nodeWidth, width, height, orient, nod
             if (item.depth > maxDepth) {
                 maxDepth = item.depth;
             }
-            if (orient === 'vertical') {
-                node.setLayout({y: item.depth}, true);
-            }
-            else {
-                node.setLayout({x: item.depth}, true);
-            }
+            node.setLayout({skDepth: item.depth}, true);
         }
     });
 
@@ -242,7 +238,9 @@ function computeNodeBreadths(nodes, edges, nodeWidth, width, height, orient, nod
     else {
         kx = (width - nodeWidth) / maxDepth;
     }
-    scaleNodeBreadths(nodes, kx, orient);
+    return kx;
+
+    // scaleNodeBreadths(nodes, kx, orient);
 }
 
 /**
@@ -274,13 +272,24 @@ function moveSinksRight(nodes, x, orient) {
  */
 function scaleNodeBreadths(nodes, kx, orient) {
     zrUtil.each(nodes, function (node) {
-        if (orient === 'vertical') {
-            var nodeY = node.getLayout().y * kx;
-            node.setLayout({y: nodeY}, true);
+        if (node.getLayout().skDepth) {
+            var depth = node.getLayout().skDepth * kx;
+            if (orient === 'vertical') {
+                node.setLayout({y: depth}, true);
+            }
+            else {
+                node.setLayout({x: depth}, true);
+            }
         }
         else {
-            var nodeX = node.getLayout().x * kx;
-            node.setLayout({x: nodeX}, true);
+            if (orient === 'vertical') {
+                var nodeY = node.getLayout().y * kx;
+                node.setLayout({y: nodeY}, true);
+            }
+            else {
+                var nodeX = node.getLayout().x * kx;
+                node.setLayout({x: nodeX}, true);
+            }
         }
     });
 }


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