我使用的是D3树,我的节点可以是1型或2型。我希望如果一个节点被标记为1型,则指向它的链接要短得多。我该怎么办?我正在使用此示例树:https://observablehq.com/@d3/collapsible-tree
我刚刚玩过Observable链接,看起来需要更改3个代码段以使链接更短:
// Enter any new nodes at the parent's previous position.
const nodeEnter = node.enter().append("g")
.attr("transform", d => `translate(${source.y0/2},${source.x0})`)
// Transition nodes to their new position.
const nodeUpdate = node.merge(nodeEnter).transition(transition)
.attr("transform", d => `translate(${d.y/2},${d.x})`)
diagonal = d3.linkHorizontal().x(d => d.y/2).y(d => d.x)
我将“ / 2”添加到链接的一半宽度。
因此,要使其成为条件,您可以尝试在上述3个地方添加if语句?