| 6624 | // Recursively resizes the specified node's children into existing rows. |
| 6625 | // Preserves the existing layout! |
| 6626 | function stickify(node) { |
| 6627 | var children = node.children; |
| 6628 | if (children && children.length) { |
| 6629 | var rect = pad(node), |
| 6630 | remaining = children.slice(), // copy-on-write |
| 6631 | child, |
| 6632 | row = []; |
| 6633 | scale(remaining, rect.dx * rect.dy / node.value); |
| 6634 | row.area = 0; |
| 6635 | while (child = remaining.pop()) { |
| 6636 | row.push(child); |
| 6637 | row.area += child.area; |
| 6638 | if (child.z != null) { |
| 6639 | position(row, child.z ? rect.dx : rect.dy, rect, !remaining.length); |
| 6640 | row.length = row.area = 0; |
| 6641 | } |
| 6642 | } |
| 6643 | children.forEach(stickify); |
| 6644 | } |
| 6645 | } |
| 6646 | |
| 6647 | // Computes the score for the specified row, as the worst aspect ratio. |
| 6648 | function worst(row, u) { |