Skip to content

Commit

Permalink
Shuffle before enclose.
Browse files Browse the repository at this point in the history
Fixes d3#83.
  • Loading branch information
mbostock committed Jun 1, 2017
1 parent d4ffc60 commit 4401b72
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/array.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export var slice = Array.prototype.slice;

export function shuffle(array) {
var m = array.length,
i0 = 0,
t,
i;

while (m) {
i = Math.random() * m-- | 0;
t = array[m + i0];
array[m + i0] = array[i + i0];
array[i + i0] = t;
}

return array;
}
4 changes: 3 additions & 1 deletion src/pack/enclose.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import {shuffle, slice} from "../array";

export default function(circles) {
var i = 0, n = circles.length, B = [], p, e;
var i = 0, n = (circles = shuffle(slice.call(circles))).length, B = [], p, e;

while (i < n) {
p = circles[i];
Expand Down

0 comments on commit 4401b72

Please sign in to comment.