fix(util): fix radial layout when tree has root only

This commit is contained in:
yilin.qyl 2019-02-12 18:51:26 +08:00
parent 004cb3ce56
commit 7557c6a2b1
2 changed files with 12 additions and 2 deletions

View File

@ -3,7 +3,6 @@
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="../test/unit/graph/tree-graph-spec.js"></script>
</head>
<style>
</style>
@ -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;
});

View File

@ -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];