-
daddarFebruary 17, 2017 at 3:08 am #7306
Hi Tom!
Thanks for your great work. I’m trying to modify your example of weighted tree. I have two questions, could you please answer me or give a tip/advice.
1) I want to change the position of the tree from horizontal to vertical. I found an example on the forum how to do it, but the tree goes from top to bottom (root node on the top and child nodes are going down). However, I need to position it from bottom to top, as root node be on the bottom and children are on the top. Is there any way to change the start point of the axis or are there other ways to do that?
2) Where is determined the initial position of the root node, and how can I change it ?
Thank you,
daddar.vizulyFebruary 17, 2017 at 9:40 am #7311Hello Daddar,
You can easily translate the vertical layout position in the
src/viz/weighted_tree.js
file by modifying the updateNode() function. Each place where a .attr(“transform”,”translate…”) call is occurring you can modify the translate to use the current height measurement AND y position. Something like this:.attr("transform", function(d) { return "translate(" + d.x + "," + (height - d.y) + ")"; });
This should have the nodes start at the bottom.
As for the root node position, check out the positionNodes() function. The root node starts at the boundary of the layout and is set here:
nodes.forEach(function(d) { // if (tree.nodeSize()) d.x= d.x + size.height/2; d.y = d.depth * depthSpan; //Adjust y position to accomodate offset d.x = d.x + offsetY - tree.nodeSize()[0]; });
I hope this helps.
– Tom
-
|
You must be logged in to reply to this topic.