| 12956 | } |
| 12957 | |
| 12958 | function cluster() { |
| 12959 | var separation = defaultSeparation$1, |
| 12960 | dx = 1, |
| 12961 | dy = 1, |
| 12962 | nodeSize = false; |
| 12963 | |
| 12964 | function cluster(root) { |
| 12965 | var previousNode, |
| 12966 | x = 0; |
| 12967 | |
| 12968 | // First walk, computing the initial x & y values. |
| 12969 | root.eachAfter(function(node) { |
| 12970 | var children = node.children; |
| 12971 | if (children) { |
| 12972 | node.x = meanX(children); |
| 12973 | node.y = maxY(children); |
| 12974 | } else { |
| 12975 | node.x = previousNode ? x += separation(node, previousNode) : 0; |
| 12976 | node.y = 0; |
| 12977 | previousNode = node; |
| 12978 | } |
| 12979 | }); |
| 12980 | |
| 12981 | var left = leafLeft(root), |
| 12982 | right = leafRight(root), |
| 12983 | x0 = left.x - separation(left, right) / 2, |
| 12984 | x1 = right.x + separation(right, left) / 2; |
| 12985 | |
| 12986 | // Second walk, normalizing x & y to the desired size. |
| 12987 | return root.eachAfter(nodeSize ? function(node) { |
| 12988 | node.x = (node.x - root.x) * dx; |
| 12989 | node.y = (root.y - node.y) * dy; |
| 12990 | } : function(node) { |
| 12991 | node.x = (node.x - x0) / (x1 - x0) * dx; |
| 12992 | node.y = (1 - (root.y ? node.y / root.y : 1)) * dy; |
| 12993 | }); |
| 12994 | } |
| 12995 | |
| 12996 | cluster.separation = function(x) { |
| 12997 | return arguments.length ? (separation = x, cluster) : separation; |
| 12998 | }; |
| 12999 | |
| 13000 | cluster.size = function(x) { |
| 13001 | return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? null : [dx, dy]); |
| 13002 | }; |
| 13003 | |
| 13004 | cluster.nodeSize = function(x) { |
| 13005 | return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? [dx, dy] : null); |
| 13006 | }; |
| 13007 | |
| 13008 | return cluster; |
| 13009 | } |
| 13010 | |
| 13011 | function count(node) { |
| 13012 | var sum = 0, |