Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Remove the children array for childless nodes.

If data is updated so that some nodes no longer have children, and a
custom children accessor is used, then the children array was not being
removed for such nodes, which meant that hierarchical layouts were
incorrectly taking into account these children.

Fixes #1579.
commit 7b4a772f49caa04aa4f68c4dfa8242065b19a673 1 parent bfcdc04
@jasondavies jasondavies authored
View
7 d3.js
@@ -6118,8 +6118,11 @@ d3 = function() {
}
if (sort) c.sort(sort);
if (value) node.value = v;
- } else if (value) {
- node.value = +value.call(hierarchy, node, depth) || 0;
+ } else {
+ delete node.children;
+ if (value) {
+ node.value = +value.call(hierarchy, node, depth) || 0;
+ }
}
return node;
}
View
2  d3.min.js
1 addition, 1 deletion not shown
View
7 src/layout/hierarchy.js
@@ -28,8 +28,11 @@ d3.layout.hierarchy = function() {
}
if (sort) c.sort(sort);
if (value) node.value = v;
- } else if (value) {
- node.value = +value.call(hierarchy, node, depth) || 0;
+ } else {
+ delete node.children;
+ if (value) {
+ node.value = +value.call(hierarchy, node, depth) || 0;
+ }
}
return node;
}
View
6 test/layout/hierarchy-test.js
@@ -20,6 +20,12 @@ suite.addBatch({
assert.equal(nodes[0].value, 0);
h.nodes(nodes[0]);
assert.equal(nodes[0].value, 0);
+ },
+ "removes the children array for a node that has no children": function(hierarchy) {
+ var h = hierarchy(),
+ nodes = h.children(function() { return null; }).nodes({children: [{}]});
+ assert.equal(nodes[0].value, 0);
+ assert.isUndefined(nodes[0].children);
}
}
});
Please sign in to comment.
Something went wrong with that request. Please try again.