From 7557c6a2b1fabab685c21a66738b284851b40de2 Mon Sep 17 00:00:00 2001 From: "yilin.qyl" Date: Tue, 12 Feb 2019 18:51:26 +0800 Subject: [PATCH] fix(util): fix radial layout when tree has root only --- demos/tree-graph.html | 11 +++++++++-- src/util/graphic.js | 3 +++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/demos/tree-graph.html b/demos/tree-graph.html index fab86abdad..282f1e0825 100644 --- a/demos/tree-graph.html +++ b/demos/tree-graph.html @@ -3,7 +3,6 @@ Title - @@ -27,7 +26,14 @@ rankSep: 100 })}, compactBox: function(data) { - return Hierarchy.compactBox(data, { direction: 'LR' }); + return Hierarchy.compactBox(data, { + direction: 'LR', + getId(d) { return d.id; }, + getHeight() { return 16 }, + getWidth() { return 16 }, + getVGap() { return 50 }, + getHGap() { return 50 } + }); } }; const graph = new G6.TreeGraph({ @@ -122,6 +128,7 @@ if (e.target.checked) { graph.set('layout', (data) => { data = layouts[currentLayout](data); + console.log(data.x, data.y); G6.Util.radialLayout(data); return data; }); diff --git a/src/util/graphic.js b/src/util/graphic.js index f86d3f2739..e73115fcda 100644 --- a/src/util/graphic.js +++ b/src/util/graphic.js @@ -83,6 +83,9 @@ const GraphicUtil = { }); const avgRad = Math.PI * 2 / count; const radDiff = max[radScale] - min[radScale]; + if (radDiff === 0) { + return data; + } this.traverseTree(data, node => { const radial = (node[radScale] - min[radScale]) / radDiff * (Math.PI * 2 - avgRad) + avgRad; const r = node[rScale];