MCPcopy Create free account
hub / github.com/idank/explainshell / tree

Function tree

explainshell/web/static/js/d3.v3.js:5785–5871  ·  view source on GitHub ↗
(d, i)

Source from the content-addressed store, hash-verified

5783 d3.layout.tree = function() {
5784 var hierarchy = d3.layout.hierarchy().sort(null).value(null), separation = d3_layout_treeSeparation, size = [ 1, 1 ];
5785 function tree(d, i) {
5786 var nodes = hierarchy.call(this, d, i), root = nodes[0];
5787 function firstWalk(node, previousSibling) {
5788 var children = node.children, layout = node._tree;
5789 if (children && (n = children.length)) {
5790 var n, firstChild = children[0], previousChild, ancestor = firstChild, child, i = -1;
5791 while (++i < n) {
5792 child = children[i];
5793 firstWalk(child, previousChild);
5794 ancestor = apportion(child, previousChild, ancestor);
5795 previousChild = child;
5796 }
5797 d3_layout_treeShift(node);
5798 var midpoint = .5 * (firstChild._tree.prelim + child._tree.prelim);
5799 if (previousSibling) {
5800 layout.prelim = previousSibling._tree.prelim + separation(node, previousSibling);
5801 layout.mod = layout.prelim - midpoint;
5802 } else {
5803 layout.prelim = midpoint;
5804 }
5805 } else {
5806 if (previousSibling) {
5807 layout.prelim = previousSibling._tree.prelim + separation(node, previousSibling);
5808 }
5809 }
5810 }
5811 function secondWalk(node, x) {
5812 node.x = node._tree.prelim + x;
5813 var children = node.children;
5814 if (children && (n = children.length)) {
5815 var i = -1, n;
5816 x += node._tree.mod;
5817 while (++i < n) {
5818 secondWalk(children[i], x);
5819 }
5820 }
5821 }
5822 function apportion(node, previousSibling, ancestor) {
5823 if (previousSibling) {
5824 var vip = node, vop = node, vim = previousSibling, vom = node.parent.children[0], sip = vip._tree.mod, sop = vop._tree.mod, sim = vim._tree.mod, som = vom._tree.mod, shift;
5825 while (vim = d3_layout_treeRight(vim), vip = d3_layout_treeLeft(vip), vim && vip) {
5826 vom = d3_layout_treeLeft(vom);
5827 vop = d3_layout_treeRight(vop);
5828 vop._tree.ancestor = node;
5829 shift = vim._tree.prelim + sim - vip._tree.prelim - sip + separation(vim, vip);
5830 if (shift > 0) {
5831 d3_layout_treeMove(d3_layout_treeAncestor(vim, node, ancestor), node, shift);
5832 sip += shift;
5833 sop += shift;
5834 }
5835 sim += vim._tree.mod;
5836 sip += vip._tree.mod;
5837 som += vom._tree.mod;
5838 sop += vop._tree.mod;
5839 }
5840 if (vim && !d3_layout_treeRight(vop)) {
5841 vop._tree.thread = vim;
5842 vop._tree.mod += sim - sop;

Callers

nothing calls this directly

Calls 5

d3_layout_treeVisitAfterFunction · 0.85
firstWalkFunction · 0.85
secondWalkFunction · 0.85
d3_layout_treeSearchFunction · 0.85
callMethod · 0.45

Tested by

no test coverage detected