При добавлении polygon в схему не получается обновлять ветки, новые ветки наслаиваются на старые. Как решить эту проблему? Код веток
// Update the links…
var link = vis.selectAll("path.link")
.data(tree.links(nodes), function(d) { return d.target.id; });
// Enter any new links at the parent's previous position.
link.enter().insert("svg:polygon", "g")
.attr("class", "link")
.attr("points", function(d){
console.log(d.target);
var y1 = d.source.x + linkWidth(d.target);
var y2 = d.source.x - linkWidth(d.target);
return d.source.y +" "+ y1 + ", " + d.source.y +" "+ y2 + ", " + d.target.y +" "+ d.target.x;
/*var w1 = 50;
var retur = "";
var x3;
x3 = d.source.x;
//y = d.sourse.y;
while( (x3 != d.target.x) && (d.source.y != d.target.y)){
if((d.source.x - d.target.x) > 0) {
var y1 = d.source.y + w1;
var y2 = d.source.y - w1;
retur = retur + " " + y1 + " " + x3 + ", " + y2 + " " + x3 + ", ";
x3 = x3 - 1;
w1--;
} else {
var y1 = d.source.y + w1;
var y2 = d.source.y - w1;
retur = retur + " " + y1 + " " + x3 + ", " + y2 + " " + x3 + ", ";
x3 = x3 + 1;
w1--;
}
}
//console.log(retur + "11111111111111111111111111");
return retur;*/
})
/*.attr("d", function(d) {
var o = {x: source.x0, y: source.y0};
return connector({source: o, target: o});
})*/
.style("fill","#AAA")
.style("stroke", self.settings.lineColor)
.transition()
.duration(duration);
function linkWidth(d) {
var depth = d.depth;
if (d.name !== '' && d.children && d.children.length === 1 && d.children[0].name === '') {
depth += 1;
}
return Math.max(5 - 2*depth, 1.5);
}
// Transition links to their new position.
link.transition()
.duration(duration);
// Transition exiting nodes to the parent's new position.
link.exit().transition()
.duration(duration)
.attr("points", function(d) {
var y1 = d.source.x + linkWidth(d.target);
var y2 = d.source.x - linkWidth(d.target);
return d.source.y +" "+ y1 + ", " + d.source.y +" "+ y2 + ", " + d.target.y +" "+ d.target.x;
})
.remove();