Skip to content

Commit

Permalink
Avoid divide by zero.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Aug 11, 2020
1 parent b022f21 commit 39f420c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/treemap/binary.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ export default function(parent, x0, y0, x1, y1) {
valueRight = value - valueLeft;

if ((x1 - x0) > (y1 - y0)) {
var xk = (x0 * valueRight + x1 * valueLeft) / value;
var xk = value ? (x0 * valueRight + x1 * valueLeft) / value : x1;
partition(i, k, valueLeft, x0, y0, xk, y1);
partition(k, j, valueRight, xk, y0, x1, y1);
} else {
var yk = (y0 * valueRight + y1 * valueLeft) / value;
var yk = value ? (y0 * valueRight + y1 * valueLeft) / value : y1;
partition(i, k, valueLeft, x0, y0, x1, yk);
partition(k, j, valueRight, x0, yk, x1, y1);
}
Expand Down
4 changes: 2 additions & 2 deletions src/treemap/resquarify.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ export default (function custom(ratio) {
while (++j < m) {
row = rows[j], nodes = row.children;
for (i = row.value = 0, n = nodes.length; i < n; ++i) row.value += nodes[i].value;
if (row.dice) treemapDice(row, x0, y0, x1, y0 += (y1 - y0) * row.value / value);
else treemapSlice(row, x0, y0, x0 += (x1 - x0) * row.value / value, y1);
if (row.dice) treemapDice(row, x0, y0, x1, value ? y0 += (y1 - y0) * row.value / value : y1);
else treemapSlice(row, x0, y0, value ? x0 += (x1 - x0) * row.value / value : x1, y1);
value -= row.value;
}
} else {
Expand Down

0 comments on commit 39f420c

Please sign in to comment.