Commit 764307a9 authored by Mike Bostock's avatar Mike Bostock
Browse files


parent 7e074abd
......@@ -578,20 +578,41 @@ The d3.geom.hull operator has been simplified: instead of an operator with *hull
## [Quadtrees (d3-quadtree)](
The d3.geom.quadtree method has been replaced by [d3.quadtree]( 4.0 removes the concept of “quadtree operators” (which builds a quadtree from an array of data); there’s now just quadtrees, which you can create via d3.quadtree, and add data to via [*quadtree*.add]( and [*quadtree*.addAll]( This code in 3.x:
var quadtree = d3.geom.quadtree()
.extent([[0, 0], [width, height]])
Can be rewritten in 4.0 as:
var quadtree = d3.quadtree()
.extent([[0, 0], [width, height]])
The new quadtree implementation is vastly improved! It is now non-recursive, avoiding stack overflows when there are large numbers of coincident points. The internal storage is now more efficient, and the implementation is also faster; constructing a quadtree of 1M normally-distributed points takes about one second in 4.0, as compared to three seconds in 3.x.
The change in [internal *node* structure]( affects [*quadtree*.visit]( use *node*.length to distinguish leaf nodes from internal nodes. For example, to iterate over all data in a quadtree:
quadtree.visit(function(node) {
if (!node.length) {
do {
} while (node =
There’s a new [*quadtree*.visitAfter]( method for visiting nodes in post-order traversal. This is used, for example, in [d3-force](#forces-d3-force) to implement the [Barnes–Hut approximation](–Hut_simulation).
You can now remove data from a quadtree using [*quadtree*.remove]( and [*quadtree*.removeAll]( When adding data to a quadtree, the quadtree can now expand its extent by repeated doubling if the new point is outside the existing extent of the quadtree. There are also [*quadtree*.extent]( and [*quadtree*.cover]( methods for explicitly expanding the extent of the quadtree after creation.
* d3.geom.quadtree ↦ d3.quadtree
* new non-recursive implementation!
* coincident points are now stored more efficiently
* internal nodes are now represented more efficiently
* use *node*.length to distinguish between leaf and internal nodes
* there’s no longer a quadtree operator and a quadtree; there’s just a mutable quadtree
* new *quadtree*.remove - remove points from the quadtree!
* new *quadtree*.extent, *quadtree*.cover - increase the extent of the quadtree after creation!
* new *quadtree*.addAll, *quadtree*.removeAll - bulk methods for adding and remove points
* new *quadtree*.copy
* *quadtree*.find now takes a search radius
* new *quadtree*.visitAll for post-order traversal
Quadtrees support several new utility methods: [*quadtree*.copy]( returns a copy of the quadtree sharing the same data; [*quadtree*.data]( generates an array of all data in the quadtree; [*quadtree*.size]( returns the number of data points in the quadtree; and [*quadtree*.root]( returns the root node, which is useful for manual traversal of the quadtree. The [*quadtree*.find]( method now takes an optional search radius, which is especially useful for pointer-based selection in [force-directed graphs](
## [Queues (d3-queue)](
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment