Skip to content

Commit 7643e22

Browse files
committed
d3.geom.voronoi: return the configured size.
1 parent 7c73661 commit 7643e22

4 files changed

Lines changed: 19 additions & 7 deletions

File tree

d3.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4150,8 +4150,8 @@ d3 = function() {
41504150
if (_ == null) {
41514151
clip = null;
41524152
} else {
4153-
var w = +_[0], h = +_[1];
4154-
clip = d3.geom.polygon([ [ 0, 0 ], [ 0, h ], [ w, h ], [ w, 0 ] ]).clip;
4153+
size = [ +_[0], +_[1] ];
4154+
clip = d3.geom.polygon([ [ 0, 0 ], [ 0, size[1] ], size, [ size[0], 0 ] ]).clip;
41554155
}
41564156
return voronoi;
41574157
};
@@ -4483,6 +4483,8 @@ d3 = function() {
44834483
});
44844484
}
44854485
} else {
4486+
x1 = y1 = Infinity;
4487+
x2 = y2 = -Infinity;
44864488
while (++i < n) {
44874489
points.push(d = {
44884490
x: +fx.call(this, d = data[i], i),
@@ -4543,9 +4545,12 @@ d3 = function() {
45434545
if (!arguments.length) return x1 == null ? null : [ [ x1, y1 ], [ x2, y2 ] ];
45444546
if (_ == null) {
45454547
x1 = y1 = x2 = y2 = null;
4546-
} else {
4548+
} else if (Array.isArray(_[0])) {
45474549
x1 = +_[0][0], y1 = +_[0][1];
45484550
x2 = +_[1][0], y2 = +_[1][1];
4551+
} else {
4552+
x1 = y1 = 0;
4553+
x2 = +_[0], y2 = +_[1];
45494554
}
45504555
return quadtree;
45514556
};

d3.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/geom/voronoi.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ d3.geom.voronoi = function(vertices) {
143143
if (_ == null) {
144144
clip = null;
145145
} else {
146-
var w = +_[0], h = +_[1];
147-
clip = d3.geom.polygon([[0, 0], [0, h], [w, h], [w, 0]]).clip;
146+
size = [+_[0], +_[1]];
147+
clip = d3.geom.polygon([[0, 0], [0, size[1]], size, [size[0], 0]]).clip;
148148
}
149149
return voronoi;
150150
};

test/geom/voronoi-test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ suite.addBatch({
1515
"has no defined size": function(v) {
1616
assert.isNull(v.size());
1717
},
18+
"returns the configured size": function(v) {
19+
try {
20+
assert.deepEqual(v.size([100, 100]).size(), [100, 100]);
21+
} finally {
22+
v.size(null);
23+
}
24+
},
1825
"has the default x-accessor, d[0]": function(v) {
1926
assert.strictEqual(v.x()([42, 43]), 42);
2027
},

0 commit comments

Comments
 (0)