Skip to content

Commit

Permalink
Accept iterables.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Nov 16, 2019
1 parent 7408800 commit 6a9d6db
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/array.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
export var slice = Array.prototype.slice;
export default function(x) {
return typeof x === "object" && "length" in x
? x // Array, TypedArray, NodeList, array-like
: Array.from(x); // Map, Set, iterable, string, or anything else
}

export function shuffle(array) {
var m = array.length,
Expand Down
4 changes: 2 additions & 2 deletions src/pack/enclose.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {shuffle, slice} from "../array.js";
import {shuffle} from "../array.js";

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

while (i < n) {
p = circles[i];
Expand Down
3 changes: 2 additions & 1 deletion src/pack/siblings.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import array from "../array.js";
import enclose from "./enclose.js";

function place(b, a, c) {
Expand Down Expand Up @@ -45,7 +46,7 @@ function Node(circle) {
}

export function packEnclose(circles) {
if (!(n = circles.length)) return 0;
if (!(n = (circles = array(circles)).length)) return 0;

var a, b, c, n, aa, ca, i, j, k, sj, sk;

Expand Down

0 comments on commit 6a9d6db

Please sign in to comment.