2016-09-26 100 views
1

我正在打折D3摺疊樹,因爲here 並且想要在節點之間繪製一些路徑。問題是當樹枝被摺疊時,舊路徑不會被刪除。類似的解決方案是here,但我做錯了什麼。你能否告訴我應該如何更新SVG路徑?在樹頂部繪製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

回答

1

你的問題很簡單:你的更新和退出的選擇工作,你必須選擇同一類,你在你進入選項設置:

var path = svg.selectAll('.arrow'); 

這裏是你的提琴:http://jsfiddle.net/odf3q84L/