MCPcopy Create free account
hub / github.com/microsoft/SandDance / tree

Function tree

docs/tests/v2/es6/js/sanddance.js:121953–121980  ·  view source on GitHub ↗
(root)

Source from the content-addressed store, hash-verified

121951 nodeSize = null;
121952
121953 function tree(root) {
121954 var t = treeRoot(root); // Compute the layout using Buchheim et al.’s algorithm.
121955
121956 t.eachAfter(firstWalk), t.parent.m = -t.z;
121957 t.eachBefore(secondWalk); // If a fixed node size is specified, scale x and y.
121958
121959 if (nodeSize) root.eachBefore(sizeNode); // If a fixed tree size is specified, scale x and y based on the extent.
121960 // Compute the left-most, right-most, and depth-most nodes for extents.
121961 else {
121962 var left = root,
121963 right = root,
121964 bottom = root;
121965 root.eachBefore(function (node) {
121966 if (node.x < left.x) left = node;
121967 if (node.x > right.x) right = node;
121968 if (node.depth > bottom.depth) bottom = node;
121969 });
121970 var s = left === right ? 1 : separation(left, right) / 2,
121971 tx = s - left.x,
121972 kx = dx / (right.x + s + tx),
121973 ky = dy / (bottom.depth || 1);
121974 root.eachBefore(function (node) {
121975 node.x = (node.x + tx) * kx;
121976 node.y = node.depth * ky;
121977 });
121978 }
121979 return root;
121980 } // Computes a preliminary x-coordinate for v. Before that, FIRST WALK is
121981 // applied recursively to the children of v, as well as the function
121982 // APPORTION. After spacing out the children by calling EXECUTE SHIFTS, the
121983 // node v is placed to the midpoint of its outermost children.

Callers

nothing calls this directly

Calls 1

treeRootFunction · 0.70

Tested by

no test coverage detected