You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@echarts.apache.org by GitBox <gi...@apache.org> on 2018/09/03 08:24:11 UTC

[GitHub] jas0ncn closed pull request #8966: Add node align for the Sankey diagram

jas0ncn closed pull request #8966: Add node align for the Sankey diagram
URL: https://github.com/apache/incubator-echarts/pull/8966
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/extension/dataTool/prepareBoxplotData.js b/extension/dataTool/prepareBoxplotData.js
index d191d6a50..1dc4f7aca 100644
--- a/extension/dataTool/prepareBoxplotData.js
+++ b/extension/dataTool/prepareBoxplotData.js
@@ -18,8 +18,6 @@
 * under the License.
 */
 
-var quantile = require("./quantile");
-
 var numberUtil = require("../../lib/util/number");
 
 /*
@@ -78,9 +76,9 @@ function _default(rawData, opt) {
   for (var i = 0; i < rawData.length; i++) {
     axisData.push(i + '');
     var ascList = numberUtil.asc(rawData[i].slice());
-    var Q1 = quantile(ascList, 0.25);
-    var Q2 = quantile(ascList, 0.5);
-    var Q3 = quantile(ascList, 0.75);
+    var Q1 = numberUtil.quantile(ascList, 0.25);
+    var Q2 = numberUtil.quantile(ascList, 0.5);
+    var Q3 = numberUtil.quantile(ascList, 0.75);
     var min = ascList[0];
     var max = ascList[ascList.length - 1];
     var bound = (boundIQR == null ? 1.5 : boundIQR) * (Q3 - Q1);
diff --git a/src/chart/sankey/SankeySeries.js b/src/chart/sankey/SankeySeries.js
index e5acf52a1..ac8138412 100644
--- a/src/chart/sankey/SankeySeries.js
+++ b/src/chart/sankey/SankeySeries.js
@@ -106,6 +106,9 @@ var SankeySeries = SeriesModel.extend({
         // Value can be 'vertical'
         orient: 'horizontal',
 
+        // Value can be 'left'
+        align: 'justify',
+
         // The dx of the node
         nodeWidth: 20,
 
@@ -155,4 +158,4 @@ var SankeySeries = SeriesModel.extend({
 
 });
 
-export default SankeySeries;
\ No newline at end of file
+export default SankeySeries;
diff --git a/src/chart/sankey/sankeyLayout.js b/src/chart/sankey/sankeyLayout.js
index f37fb84bc..142fa5773 100644
--- a/src/chart/sankey/sankeyLayout.js
+++ b/src/chart/sankey/sankeyLayout.js
@@ -57,7 +57,9 @@ export default function (ecModel, api, payload) {
 
         var orient = seriesModel.get('orient');
 
-        layoutSankey(nodes, edges, nodeWidth, nodeGap, width, height, iterations, orient);
+        var align = seriesModel.get('align');
+
+        layoutSankey(nodes, edges, nodeWidth, nodeGap, width, height, iterations, orient, align);
     });
 }
 
@@ -77,8 +79,8 @@ function getViewRect(seriesModel, api) {
     );
 }
 
-function layoutSankey(nodes, edges, nodeWidth, nodeGap, width, height, iterations, orient) {
-    computeNodeBreadths(nodes, edges, nodeWidth, width, height, orient);
+function layoutSankey(nodes, edges, nodeWidth, nodeGap, width, height, iterations, orient, align) {
+    computeNodeBreadths(nodes, edges, nodeWidth, width, height, orient, align);
     computeNodeDepths(nodes, edges, height, width, nodeGap, iterations, orient);
     computeEdgeDepths(nodes, orient);
 }
@@ -107,7 +109,7 @@ function computeNodeValues(nodes) {
  * @param  {number} nodeWidth  the dx of the node
  * @param  {number} width  the whole width of the area to draw the view
  */
-function computeNodeBreadths(nodes, edges, nodeWidth, width, height, orient) {
+function computeNodeBreadths(nodes, edges, nodeWidth, width, height, orient, align) {
     // Used to mark whether the edge is deleted. if it is deleted,
     // the value is 0, otherwise it is 1.
     var remainEdges = [];
@@ -166,7 +168,10 @@ function computeNodeBreadths(nodes, edges, nodeWidth, width, height, orient) {
         }
     }
 
-    moveSinksRight(nodes, x);
+    // only 'justify' will align node in the last column.
+    if (align === 'justify') {
+        moveSinksRight(nodes, x);
+    }
 
     if (orient === 'vertical') {
         kx = (height - nodeWidth) / (x - 1);
@@ -514,4 +519,4 @@ function computeEdgeDepths(nodes, orient) {
             ty += edge.getLayout().dy;
         });
     });
-}
\ No newline at end of file
+}
diff --git a/test/sankey-align.html b/test/sankey-align.html
new file mode 100644
index 000000000..b2368fea4
--- /dev/null
+++ b/test/sankey-align.html
@@ -0,0 +1,103 @@
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<html>
+    <head>
+        <meta charset="utf-8">
+        <meta name="viewport" content="width=device-width, initial-scale=1" />
+        <script src="lib/esl.js"></script>
+        <script src="lib/config.js"></script>
+        <script src="lib/jquery.min.js"></script>
+    </head>
+    <body>
+        <style>
+            html, body, #main {
+                width: 100%;
+                height: 100%;
+                /*border: 1px solid #000;*/
+            }
+        </style>
+        <div id="main"><div>
+        <script>
+            require([
+                'echarts'
+                // 'echarts/chart/sankey',
+                // 'echarts/component/tooltip'
+                ], function (echarts) {
+
+                    var chart = echarts.init(document.getElementById('main'), null, {
+
+                    });
+
+                    window.onresize = function () {
+                        chart.resize();
+                    };
+
+                    chart.on('click', function (params) {
+                        console.log(params, params.data);
+                    });
+
+                    var data = {
+                        nodes: [
+                            { name: 'a' },
+                            { name: 'b' },
+                            { name: 'a1' },
+                            { name: 'b1' },
+                            { name: 'a2' },
+                            { name: 'b2' }
+                        ],
+                        links: [
+                            { source: 'a', target: 'a1', value: 1 },
+                            { source: 'a', target: 'b1', value: 2 },
+                            { source: 'b', target: 'a2', value: 2 },
+                            { source: 'b', target: 'b2', value: 2 },
+                            { source: 'b1', target: 'a2', value: 2 },
+                            { source: 'b1', target: 'b2', value: 2 },
+                            { source: 'b1', target: 'b2', value: 2 }
+                        ]
+                    }
+
+                    chart.setOption({
+                        tooltip: {
+                            trigger: 'item',
+                            triggerOn: 'mousemove'
+                        },
+                        animation: false,
+                        series: [
+                            {
+                                type: 'sankey',
+                                layout:'none',
+                                focusNodeAdjacency: 'allEdges',
+                                align: 'left',
+                                data: data.nodes,
+                                links: data.links,
+                                lineStyle: {
+                                    normal: {
+                                        color: 'source',
+                                        curveness: 0.5
+                                    }
+                                }
+                            }
+                        ]
+                    });
+                });
+        </script>
+    </body>
+</html>


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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


With regards,
Apache Git Services

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