Javascript d3.j混合径向树与连接(直)树
关于这个例子(),我想知道是否可以在d3.js中混合使用径向树和直线树 对于我的Javascript d3.j混合径向树与连接(直)树,javascript,d3.js,tree,radial,Javascript,D3.js,Tree,Radial,关于这个例子(),我想知道是否可以在d3.js中混合使用径向树和直线树 对于我的jsFiddle示例:我希望父级(level0)与第一个子级(level1)有一条直线,然后是径向曲线树(现在就是这样) 这可能吗 我找不到任何与此相关的内容,但由于我对d3.js/js相对较新,我可能只是错过了正确的关键字。希望有人有一个工作的例子,或可以指出我在正确的方向-无论如何,我感谢任何提示和意见 如果链接的源深度为0,则可以从链接的源和目标的x和y生成SVG路径,类似于使用三角法计算节点位置的方式,其中x
jsFiddle
示例:我希望父级(level0)与第一个子级(level1)有一条直线,然后是径向曲线树(现在就是这样)
这可能吗
我找不到任何与此相关的内容,但由于我对d3.js/js相对较新,我可能只是错过了正确的关键字。希望有人有一个工作的例子,或可以指出我在正确的方向-无论如何,我感谢任何提示和意见 如果链接的源深度为0,则可以从链接的源和目标的x和y生成SVG路径,类似于使用三角法计算节点位置的方式,其中x是旋转角度,y是半径
//create the linkRadial function for use later in the 'd' generation
const radialPath = d3.linkRadial()
.angle(l => l.x)
.radius(l => l.y)
const link = svg.append("g")
.attr("fill", "none")
.attr("stroke-opacity", 0.4)
.attr("stroke-width", 1.5)
.selectAll("path")
.data(root.links())
.enter()
.append("path")
link.attr("d", function(d){
let adjust = 1.5708 //90 degrees in radians
// calculate the start and end points of the path, using trig
let sourceX = (d.source.y * Math.cos(d.source.x - adjust));
let sourceY = (d.source.y * Math.sin(d.source.x - adjust));
let targetX = (d.target.y * Math.cos(d.target.x - adjust));
let targetY = (d.target.y * Math.sin(d.target.x -adjust));
// if the source node is at the centre, depth = 0, then create a straight path using the L (lineto) SVG path. Else, use the radial path
if (d.source.depth==0){
return "M" + sourceX + " " + sourceY + " "
+ "L" + targetX + " " + targetY
} else {
return radialPath(d)
}
})