Skip to content

Commit 7f5fa42

Browse files
committed
Add inline property to hierarchy layout.
This allows you to disable the default behavior which wraps the input data. I am investigating whether we can disable automatic wrapping, which causes confusion between "data" and "nodes".
1 parent a42e4e1 commit 7f5fa42

3 files changed

Lines changed: 25 additions & 7 deletions

File tree

d3.layout.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,13 +1027,15 @@ function d3_layout_histogramRange(values) {
10271027
d3.layout.hierarchy = function() {
10281028
var sort = d3_layout_hierarchySort,
10291029
children = d3_layout_hierarchyChildren,
1030-
value = d3_layout_hierarchyValue;
1030+
value = d3_layout_hierarchyValue,
1031+
inline = false;
10311032

10321033
// Recursively compute the node depth and value.
10331034
// Also converts the data representation into a standard hierarchy structure.
10341035
function recurse(data, depth, nodes) {
10351036
var datas = children.call(hierarchy, data, depth),
1036-
node = {depth: depth, data: data};
1037+
node = inline ? data : {data: data};
1038+
node.depth = depth;
10371039
nodes.push(node);
10381040
if (datas) {
10391041
var i = -1,
@@ -1065,7 +1067,7 @@ d3.layout.hierarchy = function() {
10651067
j = depth + 1;
10661068
while (++i < n) v += revalue(children[i], j);
10671069
} else if (value) {
1068-
v = value.call(hierarchy, node.data, depth);
1070+
v = value.call(hierarchy, inline ? node : node.data, depth);
10691071
}
10701072
if (value) node.value = v;
10711073
return v;
@@ -1077,6 +1079,12 @@ d3.layout.hierarchy = function() {
10771079
return nodes;
10781080
}
10791081

1082+
hierarchy.inline = function(x) {
1083+
if (!arguments.length) return inline;
1084+
inline = x;
1085+
return hierarchy;
1086+
};
1087+
10801088
hierarchy.sort = function(x) {
10811089
if (!arguments.length) return sort;
10821090
sort = x;
@@ -1108,6 +1116,7 @@ d3.layout.hierarchy = function() {
11081116
function d3_layout_hierarchyRebind(object, hierarchy) {
11091117
object.sort = d3.rebind(object, hierarchy.sort);
11101118
object.children = d3.rebind(object, hierarchy.children);
1119+
object.inline = d3.rebind(object, hierarchy.inline);
11111120
object.links = d3_layout_hierarchyLinks;
11121121
object.value = d3.rebind(object, hierarchy.value);
11131122
return object;

0 commit comments

Comments
 (0)