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

Function stratify

external/.d3.js:13691–13788  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

13689}
13690
13691function stratify() {
13692 var id = defaultId,
13693 parentId = defaultParentId,
13694 path;
13695
13696 function stratify(data) {
13697 var nodes = Array.from(data),
13698 currentId = id,
13699 currentParentId = parentId,
13700 n,
13701 d,
13702 i,
13703 root,
13704 parent,
13705 node,
13706 nodeId,
13707 nodeKey,
13708 nodeByKey = new Map;
13709
13710 if (path != null) {
13711 const I = nodes.map((d, i) => normalize$1(path(d, i, data)));
13712 const P = I.map(parentof);
13713 const S = new Set(I).add("");
13714 for (const i of P) {
13715 if (!S.has(i)) {
13716 S.add(i);
13717 I.push(i);
13718 P.push(parentof(i));
13719 nodes.push(imputed);
13720 }
13721 }
13722 currentId = (_, i) => I[i];
13723 currentParentId = (_, i) => P[i];
13724 }
13725
13726 for (i = 0, n = nodes.length; i < n; ++i) {
13727 d = nodes[i], node = nodes[i] = new Node$1(d);
13728 if ((nodeId = currentId(d, i, data)) != null && (nodeId += "")) {
13729 nodeKey = node.id = nodeId;
13730 nodeByKey.set(nodeKey, nodeByKey.has(nodeKey) ? ambiguous : node);
13731 }
13732 if ((nodeId = currentParentId(d, i, data)) != null && (nodeId += "")) {
13733 node.parent = nodeId;
13734 }
13735 }
13736
13737 for (i = 0; i < n; ++i) {
13738 node = nodes[i];
13739 if (nodeId = node.parent) {
13740 parent = nodeByKey.get(nodeId);
13741 if (!parent) throw new Error("missing: " + nodeId);
13742 if (parent === ambiguous) throw new Error("ambiguous: " + nodeId);
13743 if (parent.children) parent.children.push(node);
13744 else parent.children = [node];
13745 node.parent = parent;
13746 } else {
13747 if (root) throw new Error("multiple roots");
13748 root = node;

Callers

nothing calls this directly

Calls 10

normalize$1Function · 0.85
pathFunction · 0.85
parentofFunction · 0.85
optionalFunction · 0.85
mapMethod · 0.80
fromMethod · 0.45
addMethod · 0.45
hasMethod · 0.45
setMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected