| 6162 | } |
| 6163 | } |
| 6164 | function squarify(node) { |
| 6165 | var children = node.children; |
| 6166 | if (children && children.length) { |
| 6167 | 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; |
| 6168 | scale(remaining, rect.dx * rect.dy / node.value); |
| 6169 | row.area = 0; |
| 6170 | while ((n = remaining.length) > 0) { |
| 6171 | row.push(child = remaining[n - 1]); |
| 6172 | row.area += child.area; |
| 6173 | if (mode !== "squarify" || (score = worst(row, u)) <= best) { |
| 6174 | remaining.pop(); |
| 6175 | best = score; |
| 6176 | } else { |
| 6177 | row.area -= row.pop().area; |
| 6178 | position(row, u, rect, false); |
| 6179 | u = Math.min(rect.dx, rect.dy); |
| 6180 | row.length = row.area = 0; |
| 6181 | best = Infinity; |
| 6182 | } |
| 6183 | } |
| 6184 | if (row.length) { |
| 6185 | position(row, u, rect, true); |
| 6186 | row.length = row.area = 0; |
| 6187 | } |
| 6188 | children.forEach(squarify); |
| 6189 | } |
| 6190 | } |
| 6191 | function stickify(node) { |
| 6192 | var children = node.children; |
| 6193 | if (children && children.length) { |