MCPcopy Create free account
hub / github.com/breck7/scroll / tree

Function tree

external/.d3.js:13919–14056  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

13917
13918// Node-link tree diagram using the Reingold-Tilford "tidy" algorithm
13919function tree() {
13920 var separation = defaultSeparation,
13921 dx = 1,
13922 dy = 1,
13923 nodeSize = null;
13924
13925 function tree(root) {
13926 var t = treeRoot(root);
13927
13928 // Compute the layout using Buchheim et al.’s algorithm.
13929 t.eachAfter(firstWalk), t.parent.m = -t.z;
13930 t.eachBefore(secondWalk);
13931
13932 // If a fixed node size is specified, scale x and y.
13933 if (nodeSize) root.eachBefore(sizeNode);
13934
13935 // If a fixed tree size is specified, scale x and y based on the extent.
13936 // Compute the left-most, right-most, and depth-most nodes for extents.
13937 else {
13938 var left = root,
13939 right = root,
13940 bottom = root;
13941 root.eachBefore(function(node) {
13942 if (node.x < left.x) left = node;
13943 if (node.x > right.x) right = node;
13944 if (node.depth > bottom.depth) bottom = node;
13945 });
13946 var s = left === right ? 1 : separation(left, right) / 2,
13947 tx = s - left.x,
13948 kx = dx / (right.x + s + tx),
13949 ky = dy / (bottom.depth || 1);
13950 root.eachBefore(function(node) {
13951 node.x = (node.x + tx) * kx;
13952 node.y = node.depth * ky;
13953 });
13954 }
13955
13956 return root;
13957 }
13958
13959 // Computes a preliminary x-coordinate for v. Before that, FIRST WALK is
13960 // applied recursively to the children of v, as well as the function
13961 // APPORTION. After spacing out the children by calling EXECUTE SHIFTS, the
13962 // node v is placed to the midpoint of its outermost children.
13963 function firstWalk(v) {
13964 var children = v.children,
13965 siblings = v.parent.children,
13966 w = v.i ? siblings[v.i - 1] : null;
13967 if (children) {
13968 executeShifts(v);
13969 var midpoint = (children[0].z + children[children.length - 1].z) / 2;
13970 if (w) {
13971 v.z = w.z + separation(v._, w._);
13972 v.m = v.z - midpoint;
13973 } else {
13974 v.z = midpoint;
13975 }
13976 } else if (w) {

Callers

nothing calls this directly

Calls 1

treeRootFunction · 0.85

Tested by

no test coverage detected