Permalink
Browse files

Fix treemap slice-dice mode.

For even depths, it was falling back to Math.min(rect.dx, rect.dy)
instead of always "dicing" (rect.dy).
  • Loading branch information...
1 parent 74582d8 commit 963a5e862e6abf34d3518f057c5dc5440032499c @jasondavies jasondavies committed Dec 25, 2012
Showing with 18 additions and 3 deletions.
  1. +1 −1 d3.js
  2. +1 −1 d3.min.js
  3. +2 −1 src/layout/treemap.js
  4. +14 −0 test/layout/treemap-test.js
View
2 d3.js
@@ -5092,7 +5092,7 @@
function squarify(node) {
var children = node.children;
if (children && children.length) {
- var rect = pad(node), row = [], remaining = children.slice(), child, best = Infinity, score, u = mode === "slice" ? rect.dx : mode === "dice" || mode === "slice-dice" && node.depth & 1 ? rect.dy : Math.min(rect.dx, rect.dy), n;
+ 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;
scale(remaining, rect.dx * rect.dy / node.value);
row.area = 0;
while ((n = remaining.length) > 0) {
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -34,7 +34,8 @@ d3.layout.treemap = function() {
best = Infinity, // the best row score so far
score, // the current row score
u = mode === "slice" ? rect.dx
- : mode === "dice" || mode === "slice-dice" && node.depth & 1 ? rect.dy
+ : mode === "dice" ? rect.dy
+ : mode === "slice-dice" ? node.depth & 1 ? rect.dy : rect.dx
: Math.min(rect.dx, rect.dy), // initial orientation
n;
scale(remaining, rect.dx * rect.dy / node.value);
@@ -154,6 +154,20 @@ suite.addBatch({
{x: 0, y: 0, dx: 0, dy: 1},
{x: 0, y: 0, dx: 1, dy: 1}
]);
+ },
+ "slice-dice": function(treemap) {
+ assert.deepEqual(treemap().size([100, 10]).mode("slice-dice").nodes({children: [
+ {children: [{value: 1}, {value: 1}]},
+ {children: [{value: 1}, {value: 1}]}
+ ]}).map(layout), [
+ {x: 0, y: 0, dx: 100, dy: 10},
+ {x: 50, y: 0, dx: 50, dy: 10},
+ {x: 50, y: 5, dx: 50, dy: 5},
+ {x: 50, y: 0, dx: 50, dy: 5},
+ {x: 0, y: 0, dx: 50, dy: 10},
+ {x: 0, y: 5, dx: 50, dy: 5},
+ {x: 0, y: 0, dx: 50, dy: 5}
+ ]);
}
}
});

0 comments on commit 963a5e8

Please sign in to comment.