Skip to content

Commit

Permalink
Fix binary treemap pivot.
Browse files Browse the repository at this point in the history
We were doing binary search, but we weren’t checking whether the previous pivot
is closer to the target value than the following pivot. Related #71.
  • Loading branch information
mbostock committed Mar 2, 2017
1 parent 3b5ea84 commit 3c9c4e6
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/treemap/binary.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export default function(parent, x0, y0, x1, y1) {
else hi = mid;
}

if ((valueTarget - sums[k - 1]) < (sums[k] - valueTarget) && i + 1 < k) --k;

var valueLeft = sums[k] - valueOffset,
valueRight = value - valueLeft;

Expand Down

0 comments on commit 3c9c4e6

Please sign in to comment.