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 37839c0 resolve the error when the data in tree diagram is empty 37839c0 is described below commit 37839c09b388d1cf925260cf7ca8b5d1c8e29a29 Author: deqingli <annong...@gmail.com> AuthorDate: Wed Apr 11 21:17:29 2018 +0800 resolve the error when the data in tree diagram is empty --- src/chart/tree/treeLayout.js | 113 ++++++++++++++++++++++--------------------- test/tree-addNode.html | 4 +- 2 files changed, 60 insertions(+), 57 deletions(-) diff --git a/src/chart/tree/treeLayout.js b/src/chart/tree/treeLayout.js index 75dc7c6..1a55e4e 100644 --- a/src/chart/tree/treeLayout.js +++ b/src/chart/tree/treeLayout.js @@ -18,14 +18,13 @@ export default function (ecModel, api) { } function commonLayout(seriesModel, api) { - var layoutInfo = getViewRect(seriesModel, api); seriesModel.layoutInfo = layoutInfo; - var layout = seriesModel.get('layout'); var width = 0; var height = 0; var separation = null; + if (layout === 'radial') { width = 2 * Math.PI; height = Math.min(layoutInfo.height, layoutInfo.width) / 2; @@ -42,67 +41,69 @@ function commonLayout(seriesModel, api) { var virtualRoot = seriesModel.getData().tree.root; var realRoot = virtualRoot.children[0]; - init(virtualRoot); - eachAfter(realRoot, firstWalk, separation); - virtualRoot.hierNode.modifier = - realRoot.hierNode.prelim; - eachBefore(realRoot, secondWalk); - - var left = realRoot; - var right = realRoot; - var bottom = realRoot; - eachBefore(realRoot, function (node) { - var x = node.getLayout().x; - if (x < left.getLayout().x) { - left = node; - } - if (x > right.getLayout().x) { - right = node; - } - if (node.depth > bottom.depth) { - bottom = node; - } - }); + if (realRoot) { + init(virtualRoot); + eachAfter(realRoot, firstWalk, separation); + virtualRoot.hierNode.modifier = - realRoot.hierNode.prelim; + eachBefore(realRoot, secondWalk); - var delta = left === right ? 1 : separation(left, right) / 2; - var tx = delta - left.getLayout().x; - var kx = 0; - var ky = 0; - var coorX = 0; - var coorY = 0; - if (layout === 'radial') { - kx = width / (right.getLayout().x + delta + tx); - // here we use (node.depth - 1), bucause the real root's depth is 1 - ky = height / ((bottom.depth - 1) || 1); + var left = realRoot; + var right = realRoot; + var bottom = realRoot; eachBefore(realRoot, function (node) { - coorX = (node.getLayout().x + tx) * kx; - coorY = (node.depth - 1) * ky; - var finalCoor = radialCoordinate(coorX, coorY); - node.setLayout({x: finalCoor.x, y: finalCoor.y, rawX: coorX, rawY: coorY}, true); + var x = node.getLayout().x; + if (x < left.getLayout().x) { + left = node; + } + if (x > right.getLayout().x) { + right = node; + } + if (node.depth > bottom.depth) { + bottom = node; + } }); - } - else { - var orient = seriesModel.getOrient(); - if (orient === 'RL' || orient === 'LR') { - ky = height / (right.getLayout().x + delta + tx); - kx = width / ((bottom.depth - 1) || 1); - eachBefore(realRoot, function (node) { - coorY = (node.getLayout().x + tx) * ky; - coorX = orient === 'LR' - ? (node.depth - 1) * kx - : width - (node.depth - 1) * kx; - node.setLayout({x: coorX, y: coorY}, true); - }); - } - else if (orient === 'TB' || orient === 'BT') { + + var delta = left === right ? 1 : separation(left, right) / 2; + var tx = delta - left.getLayout().x; + var kx = 0; + var ky = 0; + var coorX = 0; + var coorY = 0; + if (layout === 'radial') { kx = width / (right.getLayout().x + delta + tx); + // here we use (node.depth - 1), bucause the real root's depth is 1 ky = height / ((bottom.depth - 1) || 1); eachBefore(realRoot, function (node) { coorX = (node.getLayout().x + tx) * kx; - coorY = orient === 'TB' - ? (node.depth - 1) * ky - : height - (node.depth - 1) * ky; - node.setLayout({x: coorX, y: coorY}, true); + coorY = (node.depth - 1) * ky; + var finalCoor = radialCoordinate(coorX, coorY); + node.setLayout({x: finalCoor.x, y: finalCoor.y, rawX: coorX, rawY: coorY}, true); }); } - } + else { + var orient = seriesModel.getOrient(); + if (orient === 'RL' || orient === 'LR') { + ky = height / (right.getLayout().x + delta + tx); + kx = width / ((bottom.depth - 1) || 1); + eachBefore(realRoot, function (node) { + coorY = (node.getLayout().x + tx) * ky; + coorX = orient === 'LR' + ? (node.depth - 1) * kx + : width - (node.depth - 1) * kx; + node.setLayout({x: coorX, y: coorY}, true); + }); + } + else if (orient === 'TB' || orient === 'BT') { + kx = width / (right.getLayout().x + delta + tx); + ky = height / ((bottom.depth - 1) || 1); + eachBefore(realRoot, function (node) { + coorX = (node.getLayout().x + tx) * kx; + coorY = orient === 'TB' + ? (node.depth - 1) * ky + : height - (node.depth - 1) * ky; + node.setLayout({x: coorX, y: coorY}, true); + }); + } + } + } } \ No newline at end of file diff --git a/test/tree-addNode.html b/test/tree-addNode.html index f2a8ed2..9a0e750 100644 --- a/test/tree-addNode.html +++ b/test/tree-addNode.html @@ -84,6 +84,8 @@ id: '2', name: 'tree1', data: [data], + // Used to test when the data is null whether it is work well. + // data: [], top: '20%', left: '30%', @@ -114,7 +116,7 @@ ] }); - setTimeout(function() { + setTimeout(function() { var cloneData = echarts.util.clone(data); var appendNode = cloneData.children[1].children.splice(2, 1); cloneData.children.push(appendNode[0]); -- To stop receiving notification emails like this one, please contact deqin...@apache.org. --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@echarts.apache.org For additional commands, e-mail: commits-h...@echarts.apache.org