Skip to content

Commit b1091b9

Browse files
committed
Add quadtree.extent. Fixes d3#1207.
1 parent 9f25c5f commit b1091b9

4 files changed

Lines changed: 22 additions & 16 deletions

File tree

d3.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4590,14 +4590,14 @@ d3 = function() {
45904590
quadtree.y = function(_) {
45914591
return arguments.length ? (y = _, quadtree) : y;
45924592
};
4593+
quadtree.extent = function(_) {
4594+
if (!arguments.length) return x1 == null ? null : [ [ x1, y1 ], [ x2, y2 ] ];
4595+
if (_ == null) x1 = null; else x1 = +_[0][0], y1 = +_[0][1], x2 = +_[1][0], y2 = +_[1][1];
4596+
return quadtree;
4597+
};
45934598
quadtree.size = function(_) {
4594-
if (!arguments.length) return x1 == null ? null : [ x2, y2 ];
4595-
if (_ == null) {
4596-
x1 = y1 = x2 = y2 = null;
4597-
} else {
4598-
x1 = y1 = 0;
4599-
x2 = +_[0], y2 = +_[1];
4600-
}
4599+
if (!arguments.length) return x1 == null ? null : [ x2 - x1, y2 - y1 ];
4600+
if (_ == null) x1 = null; else x1 = y1 = 0, x2 = +_[0], y2 = +_[1];
46014601
return quadtree;
46024602
};
46034603
return quadtree;

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/quadtree.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,14 +147,17 @@ d3.geom.quadtree = function(points, x1, y1, x2, y2) {
147147
return arguments.length ? (y = _, quadtree) : y;
148148
};
149149

150+
quadtree.extent = function(_) {
151+
if (!arguments.length) return x1 == null ? null : [[x1, y1], [x2, y2]];
152+
if (_ == null) x1 = y1 = x2 = y2 = null;
153+
else x1 = +_[0][0], y1 = +_[0][1], x2 = +_[1][0], y2 = +_[1][1];
154+
return quadtree;
155+
};
156+
150157
quadtree.size = function(_) {
151-
if (!arguments.length) return x1 == null ? null : [x2, y2];
152-
if (_ == null) {
153-
x1 = y1 = x2 = y2 = null;
154-
} else {
155-
x1 = y1 = 0;
156-
x2 = +_[0], y2 = +_[1];
157-
}
158+
if (!arguments.length) return x1 == null ? null : [x2 - x1, y2 - y1];
159+
if (_ == null) x1 = y1 = x2 = y2 = null;
160+
else x1 = y1 = 0, x2 = +_[0], y2 = +_[1];
158161
return quadtree;
159162
};
160163

test/geom/quadtree-test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ suite.addBatch({
1414
"has no defined size": function(q) {
1515
assert.isNull(q.size());
1616
},
17+
"has no defined extent": function(q) {
18+
assert.isNull(q.extent());
19+
},
1720
"has the default x-accessor, d[0]": function(q) {
1821
assert.strictEqual(q.x()([42, 43]), 42);
1922
},

0 commit comments

Comments
 (0)