Commit db8d3058 authored by Mike Bostock's avatar Mike Bostock

Merge branch 'fix-hierarchy-revalue'

parents 61c568f8 6b489696
{
"name": "d3",
"version": "3.4.7",
"version": "3.4.8",
"main": "d3.js",
"scripts": [
"d3.js"
......
......@@ -10,7 +10,7 @@
"animation",
"canvas"
],
"version": "3.4.7",
"version": "3.4.8",
"main": "d3.js",
"scripts": [
"d3.js"
......
!function() {
var d3 = {
version: "3.4.7"
version: "3.4.8"
};
if (!Date.now) Date.now = function() {
return +new Date();
......@@ -6377,11 +6377,16 @@
return hierarchy;
};
hierarchy.revalue = function(root) {
if (value) d3_layout_hierarchyVisitAfter(root, function(node) {
var parent;
node.value = node.children ? 0 : +value.call(hierarchy, node, node.depth) || 0;
if (parent = node.parent) parent.value += node.value;
});
if (value) {
d3_layout_hierarchyVisitBefore(root, function(node) {
if (node.children) node.value = 0;
});
d3_layout_hierarchyVisitAfter(root, function(node) {
var parent;
if (!node.children) node.value = +value.call(hierarchy, node, node.depth) || 0;
if (parent = node.parent) parent.value += node.value;
});
}
return root;
};
return hierarchy;
......
This source diff could not be displayed because it is too large. You can view the blob instead.
{
"name": "d3",
"version": "3.4.7",
"version": "3.4.8",
"description": "A small, free JavaScript library for manipulating documents based on data.",
"keywords": [
"dom",
......
......@@ -60,11 +60,16 @@ d3.layout.hierarchy = function() {
// Re-evaluates the `value` property for the specified hierarchy.
hierarchy.revalue = function(root) {
if (value) d3_layout_hierarchyVisitAfter(root, function(node) {
var parent;
node.value = node.children ? 0 : +value.call(hierarchy, node, node.depth) || 0;
if (parent = node.parent) parent.value += node.value;
});
if (value) {
d3_layout_hierarchyVisitBefore(root, function(node) {
if (node.children) node.value = 0;
});
d3_layout_hierarchyVisitAfter(root, function(node) {
var parent;
if (!node.children) node.value = +value.call(hierarchy, node, node.depth) || 0;
if (parent = node.parent) parent.value += node.value;
});
}
return root;
};
......
!function(){
var d3 = {version: "3.4.7"}; // semver
var d3 = {version: "3.4.8"}; // semver
......@@ -26,6 +26,13 @@ suite.addBatch({
nodes = h.children(function() { return null; }).nodes({children: [{}]});
assert.equal(nodes[0].value, 0);
assert.isUndefined(nodes[0].children);
},
"revalue": function(hierarchy) {
var h = hierarchy().sticky(true),
nodes = h.nodes({children: [{children: [{value: 1}, {value: 2}]}, {value: 3}]});
assert.equal(nodes[0].value, 6);
h(nodes[0]); // calls hierarchy.revalue
assert.equal(nodes[0].value, 6);
}
}
});
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment