我正在尝试添加此系统发育树视图 https://observablehq.com/@d3/tree-of-life 进入仪表板。完整的代码可以在那里找到,并在页面上提供下载链接。
我可以输入并解析我自己的数据。但是,我无法显示树。 最具体地说,我不明白数据点的
x
和 y
坐标是在哪里设置的。这一定是一些隐式过程吗?
function linkExtensionConstant(d) {
return linkStep(d.target.x, d.target.y, d.target.x, innerRadius);
}
function _linkStep(){return(
function linkStep(startAngle, startRadius, endAngle, endRadius) {
const c0 = Math.cos(startAngle = (startAngle - 90) / 180 * Math.PI);
const s0 = Math.sin(startAngle);
const c1 = Math.cos(endAngle = (endAngle - 90) / 180 * Math.PI);
const s1 = Math.sin(endAngle);
return "M" + startRadius * c0 + "," + startRadius * s0
+ (endAngle === startAngle ? "" : "A" + startRadius + "," + startRadius + " 0 0 " + (endAngle > startAngle ? 1 : 0) + " " + startRadius * c1 + "," + startRadius * s1)
+ "L" + endRadius * c1 + "," + endRadius * s1;
}
)}
像上面一样,应该设置
d.target.x
。然而,当我运行这个d.target.x
(和y
)时,是undefined
。我不明白这些属性在代码中的何处附加到项目上。
所有设置都是由解析函数及之后的radius, length, depth
设置的。
根据我目前的理解,代码“不应该”工作,因为接受这些参数的
linkStep
中的几何变换返回NaN
,因此它创建的海龟路径被破坏了。或者可下载的代码可能无法工作?但不太可能,我猜是我......
任何人都可以看一下并尝试帮助我理解这个库吗?
我想我已经明白了。分配坐标的是
d3.cluster
函数。仍在搞乱它,但现在更进一步了。