简体   繁体   English

带有退化树的d3径向树错误

[英]d3 radial tree bug with degenerate trees

I am building a program that displays trees using d3's radial tree ( http://bl.ocks.org/mbostock/4063550 ). 我正在构建一个使用d3的放射状树显示树的程序( http://bl.ocks.org/mbostock/4063550 )。 I have no control over the incoming trees. 我无法控制传入的树。 I have a problem that if the incoming tree has only a single node (the root), then I get an error like this: 我有一个问题,如果传入的树只有一个节点(根),那么我会得到如下错误:

Error: Invalid value for <g> attribute transform="rotate(NaN)translate(0)"

I get the even more errors if the root has a single child, and so on (like a singly linked list of nodes). 如果根只有一个孩子,我会遇到更多错误,依此类推(例如节点的单链接列表)。 Here are the errors for two nodes: 这是两个节点的错误:

Error: Invalid value for <path> attribute d="MNaN,NaNCNaN,NaN NaN,NaN NaN,NaN"
Error: Invalid value for <g> attribute transform="rotate(NaN)translate(0)"
Error: Invalid value for <g> attribute transform="rotate(NaN)translate(180)"
Error: Invalid value for <g> attribute transform="rotate(NaN)translate(360)"

The problem seems to be that the x value of the node gets set to NaN. 问题似乎是该节点的x值设置为NaN。 Does anyone know of a fix for this? 有谁知道修复此问题?

I implemented your a.depth fix in the separation function, and it seems to be drawing properly: http://jsfiddle.net/1Ljaajpf/1/ 我在分离功能中实现了您的a.depth修复,它似乎可以正确绘制: http : //jsfiddle.net/1Ljaajpf/1/

var tree = d3.layout.tree()
.size([360, diameter / 2 - 80])
.separation(function(a, b) { 
    // Added protection for degenerate case of one child
    if (a.depth == 0)
       return 1;

  return (a.parent == b.parent ? 1 : 10) / a.depth; 
});

Maybe there is something else in your code which is causing drawing of the child to fail? 也许您的代码中还有其他原因导致绘制孩子失败? For example, an issue with the translate/rotate/scale functions that could cause the child node to move out of visible area (or the child node is too small) 例如,平移/旋转/缩放功能存在问题,可能导致子节点移出可见区域(或子节点太小)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM