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/04/18 07:55:27 UTC

[incubator-echarts] branch master updated: fix node reorder of the sankey view when resize the diagram

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


The following commit(s) were added to refs/heads/master by this push:
     new a6da144  fix node reorder of the sankey view when resize the diagram
     new bf0a02c  Merge branch 'master' of https://github.com/apache/incubator-echarts
a6da144 is described below

commit a6da14409985bf6a6c09ab004c5a52039ade5263
Author: deqingli <an...@gmail.com>
AuthorDate: Wed Apr 18 15:53:49 2018 +0800

    fix node reorder of the sankey view when resize the diagram
---
 src/chart/sankey/SankeyView.js   |  1 -
 src/chart/sankey/sankeyLayout.js |  2 +-
 src/chart/sankey/sankeyVisual.js | 17 +++++++++++------
 test/sankey-test.html            | 15 +++++++++------
 4 files changed, 21 insertions(+), 14 deletions(-)

diff --git a/src/chart/sankey/SankeyView.js b/src/chart/sankey/SankeyView.js
index 2c92f27..639a424 100644
--- a/src/chart/sankey/SankeyView.js
+++ b/src/chart/sankey/SankeyView.js
@@ -60,7 +60,6 @@ export default echarts.extendChartView({
         // generate a bezire Curve for each edge
         graph.eachEdge(function (edge) {
             var curve = new SankeyShape();
-
             curve.dataIndex = edge.dataIndex;
             curve.seriesIndex = seriesModel.seriesIndex;
             curve.dataType = 'edge';
diff --git a/src/chart/sankey/sankeyLayout.js b/src/chart/sankey/sankeyLayout.js
index a280414..0266998 100644
--- a/src/chart/sankey/sankeyLayout.js
+++ b/src/chart/sankey/sankeyLayout.js
@@ -395,7 +395,7 @@ function ascendingDepth(a, b) {
 }
 
 function ascending(a, b) {
-    return a < b ? -1 : a > b ? 1 : a === b ? 0 : NaN;
+    return a - b;
 }
 
 function getEdgeValue(edge) {
diff --git a/src/chart/sankey/sankeyVisual.js b/src/chart/sankey/sankeyVisual.js
index 5462658..72b5175 100644
--- a/src/chart/sankey/sankeyVisual.js
+++ b/src/chart/sankey/sankeyVisual.js
@@ -11,13 +11,18 @@ export default function (ecModel, payload) {
         var graph = seriesModel.getGraph();
         var nodes = graph.nodes;
         if (nodes.length) {
-            nodes.sort(function (a, b) {
-                return a.getLayout().value - b.getLayout().value;
+            var minValue = Infinity;
+            var maxValue = -Infinity;
+            zrUtil.each(nodes, function (node) {
+                var nodeValue = node.getLayout().value;
+                if (nodeValue < minValue) {
+                    minValue = nodeValue;
+                }
+                if (nodeValue > maxValue) {
+                    maxValue = nodeValue;
+                }
             });
-    
-            var minValue = nodes[0].getLayout().value;
-            var maxValue = nodes[nodes.length - 1].getLayout().value;
-    
+            
             zrUtil.each(nodes, function (node) {
                 var mapping = new VisualMapping({
                     type: 'color',
diff --git a/test/sankey-test.html b/test/sankey-test.html
index 3ecdaa7..aa17c35 100644
--- a/test/sankey-test.html
+++ b/test/sankey-test.html
@@ -119,6 +119,9 @@
                             },
                             {
                                 name: 'c'
+                            },
+                            {
+                                name: 'e'
                             }
                         ],
                         links: [
@@ -128,16 +131,11 @@
                                 value: 5
                             },
                             {
-                                source: 'a',
+                                source: 'e',
                                 target: 'b',
                                 value: 3
                             },
                             {
-                                source: 'b',
-                                target: 'a',
-                                value: 8
-                            }, 
-                            {
                                 source: 'a',
                                 target: 'b1',
                                 value: 3
@@ -151,6 +149,11 @@
                                 source: 'b1',
                                 target: 'c',
                                 value: 2
+                            },
+                            {
+                                source: 'b',
+                                target: 'c',
+                                value: 1
                             }
                         ]
                     };

-- 
To stop receiving notification emails like this one, please contact
deqingli@apache.org.

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