|
5082 | 5082 | return vim._tree.ancestor.parent == node.parent ? vim._tree.ancestor : ancestor; |
5083 | 5083 | } |
5084 | 5084 | d3.layout.treemap = function() { |
5085 | | - var hierarchy = d3.layout.hierarchy(), round = Math.round, size = [ 1, 1 ], padding = null, pad = d3_layout_treemapPadNull, sticky = false, stickies, ratio = .5 * (1 + Math.sqrt(5)); |
| 5085 | + var hierarchy = d3.layout.hierarchy(), round = Math.round, size = [ 1, 1 ], padding = null, pad = d3_layout_treemapPadNull, sticky = false, stickies, mode = "squarify", ratio = .5 * (1 + Math.sqrt(5)); |
5086 | 5086 | function scale(children, k) { |
5087 | 5087 | var i = -1, n = children.length, child, area; |
5088 | 5088 | while (++i < n) { |
|
5093 | 5093 | function squarify(node) { |
5094 | 5094 | var children = node.children; |
5095 | 5095 | if (children && children.length) { |
5096 | | - var rect = pad(node), row = [], remaining = children.slice(), child, best = Infinity, score, u = Math.min(rect.dx, rect.dy), n; |
| 5096 | + var rect = pad(node), row = [], remaining = children.slice(), child, best = Infinity, score, u = mode === "squarify" ? Math.min(rect.dx, rect.dy) : mode === "dice" || mode === "slice-dice" && node.depth & 1 ? rect.dy : rect.dx, n; |
5097 | 5097 | scale(remaining, rect.dx * rect.dy / node.value); |
5098 | 5098 | row.area = 0; |
5099 | 5099 | while ((n = remaining.length) > 0) { |
5100 | 5100 | row.push(child = remaining[n - 1]); |
5101 | 5101 | row.area += child.area; |
5102 | | - if ((score = worst(row, u)) <= best) { |
| 5102 | + if (mode !== "squarify" || (score = worst(row, u)) <= best) { |
5103 | 5103 | remaining.pop(); |
5104 | 5104 | best = score; |
5105 | 5105 | } else { |
|
5222 | 5222 | ratio = x; |
5223 | 5223 | return treemap; |
5224 | 5224 | }; |
| 5225 | + treemap.mode = function(x) { |
| 5226 | + if (!arguments.length) return mode; |
| 5227 | + mode = x + ""; |
| 5228 | + return treemap; |
| 5229 | + }; |
5225 | 5230 | return d3_layout_hierarchyRebind(treemap, hierarchy); |
5226 | 5231 | }; |
5227 | 5232 | function d3_layout_treemapPadNull(node) { |
|
0 commit comments