| 6498 | } |
| 6499 | } |
| 6500 | function squarify(node) { |
| 6501 | var children = node.children; |
| 6502 | if (children && children.length) { |
| 6503 | var rect = pad(node), row = [], remaining = children.slice(), child, best = Infinity, score, u = mode === "slice" ? rect.dx : mode === "dice" ? rect.dy : mode === "slice-dice" ? node.depth & 1 ? rect.dy : rect.dx : Math.min(rect.dx, rect.dy), n; |
| 6504 | scale(remaining, rect.dx * rect.dy / node.value); |
| 6505 | row.area = 0; |
| 6506 | while ((n = remaining.length) > 0) { |
| 6507 | row.push(child = remaining[n - 1]); |
| 6508 | row.area += child.area; |
| 6509 | if (mode !== "squarify" || (score = worst(row, u)) <= best) { |
| 6510 | remaining.pop(); |
| 6511 | best = score; |
| 6512 | } else { |
| 6513 | row.area -= row.pop().area; |
| 6514 | position(row, u, rect, false); |
| 6515 | u = Math.min(rect.dx, rect.dy); |
| 6516 | row.length = row.area = 0; |
| 6517 | best = Infinity; |
| 6518 | } |
| 6519 | } |
| 6520 | if (row.length) { |
| 6521 | position(row, u, rect, true); |
| 6522 | row.length = row.area = 0; |
| 6523 | } |
| 6524 | children.forEach(squarify); |
| 6525 | } |
| 6526 | } |
| 6527 | function stickify(node) { |
| 6528 | var children = node.children; |
| 6529 | if (children && children.length) { |