【发布时间】:2016-09-26 11:27:46
【问题描述】:
我将 D3 折叠树作为here 并想在节点之间绘制一些路径。问题是当树枝折叠时,旧路径没有被删除。类似的解决方案是here,但我做错了。您能否建议我应该如何更新 SVG 路径?
初始化代码,更新路径:
var path = svg.selectAll('path.sce').data(nodes);
path.attr('d', lineFunction(nodes))
.style('stroke-width', 2)
.style('stroke', 'black')
.attr('class', 'arrow')
.attr('fill', 'none')
.attr('marker-end', 'url(#arrow)');
path.enter().append('svg:path').attr('d', lineFunction(nodes))
.style('stroke-width', 2)
.style('stroke', 'black')
.attr('class', 'arrow')
.attr('fill', 'none')
.attr('marker-end', 'url(#arrow)');
path.exit().remove();
完整代码 - jsfiddle
【问题讨论】:
标签: javascript d3.js svg