New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Link positions are off, If a node is dynamically added. #37
Comments
If you expand and collapse the root node, it seems as if the children of root form a separate force layout and the root nodes is not draggable. |
Another fiddle with simple force layout. https://jsfiddle.net/n4m1r8nb/1/ Adding nodes dynamically on click. Same issue occurs. |
In You can fix this by merging enter and update after doing the data join. For example: link = svg.selectAll(".link").data(links, function(d) { return d.target.id; })
var linkEnter = link.enter().append("line").attr("class", "link");
link = linkEnter.merge(link); A fixed example: http://bl.ocks.org/mbostock/a270e536f0f4e44c0bc765bf951893eb I noticed another bug in your code which is that you initialize the new link’s source and target using the numeric id rather than references to the node objects. That’s fine, but the problem is you refer to function click(d) {
var target = {id: index, name: "server " + index};
nodes.push(target);
links.push({source: d, target: target});
index++;
update();
} |
@mbostock , Thank you very much. :) And, Good luck for v4! |
Hi,
I tried to create a collapsible force layout using d3v4. Collapsing and expanding nodes works properly.
But, the link positions are off.
Check this fiddle:
https://jsfiddle.net/t4vzg650/5/
Children nodes' link x1, y1 values are not updated, causing them to not align with parent node.
The text was updated successfully, but these errors were encountered: