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/08/15 14:21:08 UTC

[incubator-echarts] branch master updated: refactor(tree): modify the code style

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 1b90792  refactor(tree): modify the code style
1b90792 is described below

commit 1b907924c0359c94ddb1eaf1ecd76db7550e7dc8
Author: deqingli <an...@gmail.com>
AuthorDate: Wed Aug 15 22:20:58 2018 +0800

    refactor(tree): modify the code style
---
 src/chart/tree/TreeSeries.js      |  2 +-
 src/chart/tree/TreeView.js        | 69 +++++++++++++++++++++------------------
 src/chart/tree/layoutHelper.js    |  9 +++--
 src/chart/tree/traversalHelper.js |  4 +--
 src/chart/tree/treeAction.js      |  2 +-
 src/chart/tree/treeLayout.js      |  8 ++---
 6 files changed, 52 insertions(+), 42 deletions(-)

diff --git a/src/chart/tree/TreeSeries.js b/src/chart/tree/TreeSeries.js
index fb60bdd..8dece1f 100644
--- a/src/chart/tree/TreeSeries.js
+++ b/src/chart/tree/TreeSeries.js
@@ -123,7 +123,7 @@ export default SeriesModel.extend({
         zlevel: 0,
         z: 2,
         coordinateSystem: 'view',
-        
+
         // the position of the whole view
         left: '12%',
         top: '12%',
diff --git a/src/chart/tree/TreeView.js b/src/chart/tree/TreeView.js
index fb8e89c..86b022a 100644
--- a/src/chart/tree/TreeView.js
+++ b/src/chart/tree/TreeView.js
@@ -440,12 +440,16 @@ function getEdgeShape(seriesScope, sourceLayout, targetLayout) {
     var cpx2;
     var cpy2;
     var orient = seriesScope.orient;
+    var x1;
+    var x2;
+    var y1;
+    var y2;
 
     if (seriesScope.layout === 'radial') {
-        var x1 = sourceLayout.rawX;
-        var y1 = sourceLayout.rawY;
-        var x2 = targetLayout.rawX;
-        var y2 = targetLayout.rawY;
+        x1 = sourceLayout.rawX;
+        y1 = sourceLayout.rawY;
+        x2 = targetLayout.rawX;
+        y2 = targetLayout.rawY;
 
         var radialCoor1 = radialCoordinate(x1, y1);
         var radialCoor2 = radialCoordinate(x1, y1 + (y2 - y1) * seriesScope.curvature);
@@ -463,33 +467,34 @@ function getEdgeShape(seriesScope, sourceLayout, targetLayout) {
             cpy2: radialCoor3.y
         };
     }
-    else {
-        var x1 = sourceLayout.x;
-        var y1 = sourceLayout.y;
-        var x2 = targetLayout.x;
-        var y2 = targetLayout.y;
-
-        if (orient === 'LR' || orient === 'RL') {
-            cpx1 = x1 + (x2 - x1) * seriesScope.curvature;
-            cpy1 = y1;
-            cpx2 = x2 + (x1 - x2) * seriesScope.curvature;
-            cpy2 = y2;
-        }
-        if (orient === 'TB' || orient === 'BT') {
-            cpx1 = x1;
-            cpy1 = y1 + (y2 - y1) * seriesScope.curvature;
-            cpx2 = x2;
-            cpy2 = y2 + (y1 - y2) * seriesScope.curvature;
-        }
-        return {
-            x1: x1,
-            y1: y1,
-            x2: x2,
-            y2: y2,
-            cpx1: cpx1,
-            cpy1: cpy1,
-            cpx2: cpx2,
-            cpy2: cpy2
-        };
+
+    x1 = sourceLayout.x;
+    y1 = sourceLayout.y;
+    x2 = targetLayout.x;
+    y2 = targetLayout.y;
+
+    if (orient === 'LR' || orient === 'RL') {
+        cpx1 = x1 + (x2 - x1) * seriesScope.curvature;
+        cpy1 = y1;
+        cpx2 = x2 + (x1 - x2) * seriesScope.curvature;
+        cpy2 = y2;
+    }
+    if (orient === 'TB' || orient === 'BT') {
+        cpx1 = x1;
+        cpy1 = y1 + (y2 - y1) * seriesScope.curvature;
+        cpx2 = x2;
+        cpy2 = y2 + (y1 - y2) * seriesScope.curvature;
     }
+
+    return {
+        x1: x1,
+        y1: y1,
+        x2: x2,
+        y2: y2,
+        cpx1: cpx1,
+        cpy1: cpy1,
+        cpx2: cpx2,
+        cpy2: cpy2
+    };
+
 }
\ No newline at end of file
diff --git a/src/chart/tree/layoutHelper.js b/src/chart/tree/layoutHelper.js
index 1e06c18..f7f94d8 100644
--- a/src/chart/tree/layoutHelper.js
+++ b/src/chart/tree/layoutHelper.js
@@ -85,7 +85,7 @@ export function init(root) {
 export function firstWalk(node, separation) {
     var children = node.isExpand ? node.children : [];
     var siblings = node.parentNode.children;
-    var subtreeW = node.hierNode.i ? siblings[node.hierNode.i -1] : null;
+    var subtreeW = node.hierNode.i ? siblings[node.hierNode.i - 1] : null;
     if (children.length) {
         executeShifts(node);
         var midPoint = (children[0].hierNode.prelim + children[children.length - 1].hierNode.prelim) / 2;
@@ -100,7 +100,12 @@ export function firstWalk(node, separation) {
     else if (subtreeW) {
         node.hierNode.prelim = subtreeW.hierNode.prelim + separation(node, subtreeW);
     }
-    node.parentNode.hierNode.defaultAncestor = apportion(node, subtreeW, node.parentNode.hierNode.defaultAncestor || siblings[0], separation);
+    node.parentNode.hierNode.defaultAncestor = apportion(
+        node,
+        subtreeW,
+        node.parentNode.hierNode.defaultAncestor || siblings[0],
+        separation
+    );
 }
 
 
diff --git a/src/chart/tree/traversalHelper.js b/src/chart/tree/traversalHelper.js
index e6b9d76..b06ad69 100644
--- a/src/chart/tree/traversalHelper.js
+++ b/src/chart/tree/traversalHelper.js
@@ -23,7 +23,7 @@
  * @param  {module:echarts/data/Tree~TreeNode} root  The real root of the tree
  * @param  {Function} callback
  */
-function eachAfter (root, callback, separation) {
+function eachAfter(root, callback, separation) {
     var nodes = [root];
     var next = [];
     var node;
@@ -50,7 +50,7 @@ function eachAfter (root, callback, separation) {
  * @param  {module:echarts/data/Tree~TreeNode} root  The real root of the tree
  * @param  {Function} callback
  */
-function eachBefore (root, callback) {
+function eachBefore(root, callback) {
     var nodes = [root];
     var node;
     while (node = nodes.pop()) { // jshint ignore:line
diff --git a/src/chart/tree/treeAction.js b/src/chart/tree/treeAction.js
index f81c51c..3b9ca49 100644
--- a/src/chart/tree/treeAction.js
+++ b/src/chart/tree/treeAction.js
@@ -54,7 +54,7 @@ echarts.registerAction({
 
         seriesModel.setCenter
             && seriesModel.setCenter(res.center);
-        
+
         seriesModel.setZoom
             && seriesModel.setZoom(res.zoom);
     });
diff --git a/src/chart/tree/treeLayout.js b/src/chart/tree/treeLayout.js
index d4f2d79..0957d1c 100644
--- a/src/chart/tree/treeLayout.js
+++ b/src/chart/tree/treeLayout.js
@@ -43,7 +43,7 @@ function commonLayout(seriesModel, api) {
     var width = 0;
     var height = 0;
     var separation = null;
-    
+
     if (layout === 'radial') {
         width = 2 * Math.PI;
         height = Math.min(layoutInfo.height, layoutInfo.width) / 2;
@@ -63,7 +63,7 @@ function commonLayout(seriesModel, api) {
     if (realRoot) {
         init(virtualRoot);
         eachAfter(realRoot, firstWalk, separation);
-        virtualRoot.hierNode.modifier = - realRoot.hierNode.prelim;
+        virtualRoot.hierNode.modifier = -realRoot.hierNode.prelim;
         eachBefore(realRoot, secondWalk);
 
         var left = realRoot;
@@ -100,7 +100,7 @@ function commonLayout(seriesModel, api) {
             });
         }
         else {
-            var orient = seriesModel.getOrient(); 
+            var orient = seriesModel.getOrient();
             if (orient === 'RL' || orient === 'LR') {
                 ky = height / (right.getLayout().x + delta + tx);
                 kx = width / ((bottom.depth - 1) || 1);
@@ -124,5 +124,5 @@ function commonLayout(seriesModel, api) {
                 });
             }
         }
-    } 
+    }
 }
\ No newline at end of file


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