Skip to content

Commit

Permalink
Fix #68.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Nov 17, 2016
1 parent 7b0d3d1 commit a1a0399
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/treemap/squarify.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function squarifyRatio(ratio, parent, x0, y0, x1, y1) {
row,
nodeValue,
i0 = 0,
i1,
i1 = 0,
n = nodes.length,
dx, dy,
value = parent.value,
Expand All @@ -23,13 +23,16 @@ export function squarifyRatio(ratio, parent, x0, y0, x1, y1) {

while (i0 < n) {
dx = x1 - x0, dy = y1 - y0;
minValue = maxValue = sumValue = nodes[i0].value;

// Find the next non-empty node.
do sumValue = nodes[i1++].value; while (!sumValue && i1 < n);
minValue = maxValue = sumValue;
alpha = Math.max(dy / dx, dx / dy) / (value * ratio);
beta = sumValue * sumValue * alpha;
minRatio = Math.max(maxValue / beta, beta / minValue);

// Keep adding nodes while the aspect ratio maintains or improves.
for (i1 = i0 + 1; i1 < n; ++i1) {
for (; i1 < n; ++i1) {
sumValue += nodeValue = nodes[i1].value;
if (nodeValue < minValue) minValue = nodeValue;
if (nodeValue > maxValue) maxValue = nodeValue;
Expand Down

0 comments on commit a1a0399

Please sign in to comment.