Rev | Line | |
---|
[76] | 1 | d3.layout.partition = function() { |
---|
| 2 | var hierarchy = d3.layout.hierarchy(), |
---|
| 3 | size = [1, 1]; // width, height |
---|
| 4 | |
---|
| 5 | function position(node, x, dx, dy) { |
---|
| 6 | var children = node.children; |
---|
| 7 | node.x = x; |
---|
| 8 | node.y = node.depth * dy; |
---|
| 9 | node.dx = dx; |
---|
| 10 | node.dy = dy; |
---|
| 11 | if (children) { |
---|
| 12 | var i = -1, |
---|
| 13 | n = children.length, |
---|
| 14 | c, |
---|
| 15 | d; |
---|
| 16 | dx /= node.value; |
---|
| 17 | while (++i < n) { |
---|
| 18 | position(c = children[i], x, d = c.value * dx, dy); |
---|
| 19 | x += d; |
---|
| 20 | } |
---|
| 21 | } |
---|
| 22 | } |
---|
| 23 | |
---|
| 24 | function depth(node) { |
---|
| 25 | var children = node.children, |
---|
| 26 | d = 0; |
---|
| 27 | if (children) { |
---|
| 28 | var i = -1, |
---|
| 29 | n = children.length; |
---|
| 30 | while (++i < n) d = Math.max(d, depth(children[i])); |
---|
| 31 | } |
---|
| 32 | return 1 + d; |
---|
| 33 | } |
---|
| 34 | |
---|
| 35 | function partition(d, i) { |
---|
| 36 | var nodes = hierarchy.call(this, d, i); |
---|
| 37 | position(nodes[0], 0, size[0], size[1] / depth(nodes[0])); |
---|
| 38 | return nodes; |
---|
| 39 | } |
---|
| 40 | |
---|
| 41 | partition.size = function(x) { |
---|
| 42 | if (!arguments.length) return size; |
---|
| 43 | size = x; |
---|
| 44 | return partition; |
---|
| 45 | }; |
---|
| 46 | |
---|
| 47 | return d3_layout_hierarchyRebind(partition, hierarchy); |
---|
| 48 | }; |
---|
Note: See
TracBrowser
for help on using the repository browser.