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

Function hierarchy

docs/app/js/sanddance-app.js:137551–137571  ·  view source on GitHub ↗
(data, children)

Source from the content-addressed store, hash-verified

137549var _iteratorJs = require("./iterator.js");
137550var _iteratorJsDefault = parcelHelpers.interopDefault(_iteratorJs);
137551function hierarchy(data, children) {
137552 if (data instanceof Map) {
137553 data = [
137554 undefined,
137555 data
137556 ];
137557 if (children === undefined) children = mapChildren;
137558 } else if (children === undefined) children = objectChildren;
137559 var root = new Node(data), node, nodes = [
137560 root
137561 ], child, childs, i, n;
137562 while(node = nodes.pop())if ((childs = children(node.data)) && (n = (childs = Array.from(childs)).length)) {
137563 node.children = childs;
137564 for(i = n - 1; i >= 0; --i){
137565 nodes.push(child = childs[i] = new Node(childs[i]));
137566 child.parent = node;
137567 child.depth = node.depth + 1;
137568 }
137569 }
137570 return root.eachBefore(computeHeight);
137571}
137572exports.default = hierarchy;
137573function node_copy() {
137574 return hierarchy(this).eachBefore(copyData);

Callers 1

node_copyFunction · 0.70

Calls 2

childrenFunction · 0.70
fromMethod · 0.45

Tested by

no test coverage detected