Skip to content

Commit

Permalink
Remap map data to {name, value}.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Nov 18, 2019
1 parent 139d13b commit 222f40e
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/hierarchy/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,8 @@ import node_links from "./links.js";
import node_iterator from "./iterator.js";

export default function hierarchy(data, children) {
if (data instanceof Map) {
data = [undefined, data];
if (children === undefined) children = mapChildren;
} else if (children === undefined) {
children = objectChildren;
}
if (data instanceof Map) return hierarchy([undefined, data], children === undefined ? mapChildren : children).each(mapData);
if (children === undefined) children = objectChildren;

var root = new Node(data),
node,
Expand All @@ -39,11 +35,11 @@ export default function hierarchy(data, children) {
}
}

return root.eachBefore(computeHeight);
return root.each(computeHeight);
}

function node_copy() {
return hierarchy(this).eachBefore(copyData);
return hierarchy(this).each(copyData);
}

function objectChildren(d) {
Expand All @@ -54,6 +50,12 @@ function mapChildren(d) {
return Array.isArray(d) ? d[1] : null;
}

function mapData(node) {
if (Array.isArray(node.data)) {
node.data = {name: node.data[0], value: node.data[1]};
}
}

function copyData(node) {
if (node.data.value !== undefined) node.value = node.data.value;
node.data = node.data.data;
Expand Down

0 comments on commit 222f40e

Please sign in to comment.