@types/d3-quadtree
- Version 3.0.6
- Published
- 11.6 kB
- No dependencies
- MIT license
Install
npm i @types/d3-quadtree
yarn add @types/d3-quadtree
pnpm add @types/d3-quadtree
Overview
TypeScript definitions for d3-quadtree
Index
Functions
function quadtree
quadtree: { <T = [number, number]>(data?: T[]): Quadtree<T>; <T = [number, number]>( data: T[], x: (d: T) => number, y: (d: T) => number ): Quadtree<T>;};
Creates a new, empty quadtree with an empty extent and the default x- and y-accessors. If data is specified, adds the specified array of data to the quadtree.
Creates a new, empty quadtree with an empty extent and the default x- and y-accessors. Adds the specified array of data to the quadtree. Sets the x- and y- accessors to the specified functions before adding the specified array of data to the quadtree.
Interfaces
interface Quadtree
interface Quadtree<T> {}
method add
add: (datum: T) => this;
Adds the specified datum to the quadtree, deriving its coordinates ⟨x,y⟩ using the current x- and y-accessors, and returns the quadtree. If the new point is outside the current extent of the quadtree, the quadtree is automatically expanded to cover the new point.
Parameter datum
The specified datum to add.
method addAll
addAll: (data: T[]) => this;
Adds the specified array of data to the quadtree, deriving each element’s coordinates ⟨x,y⟩ using the current x- and y-accessors, and return this quadtree. This is approximately equivalent to calling quadtree.add repeatedly. However, this method results in a more compact quadtree because the extent of the data is computed first before adding the data.
Parameter data
The specified array of data to add.
method copy
copy: () => Quadtree<T>;
Returns a copy of the quadtree. All nodes in the returned quadtree are identical copies of the corresponding node in the quadtree; however, any data in the quadtree is shared by reference and not copied.
method cover
cover: (x: number, y: number) => this;
Expands the quadtree to cover the specified point ⟨x,y⟩, and returns the quadtree. * If the quadtree’s extent already covers the specified point, this method does nothing. * If the quadtree has an extent, the extent is repeatedly doubled to cover the specified point, wrapping the root node as necessary. * If the quadtree is empty, the extent is initialized to the extent
[[⌊x⌋, ⌊y⌋], [⌈x⌉, ⌈y⌉]]
. Rounding is necessary such that if the extent is later doubled, the boundaries of existing quadrants do not change due to floating point error.Parameter x
The x-coordinate for the specified point to cover.
Parameter y
The y-coordinate for the specified point to cover.
method data
data: () => T[];
Returns an array of all data in the quadtree.
method extent
extent: { (): [[number, number], [number, number]] | undefined; (extend: [[number, number], [number, number]]): this;};
Returns the quadtree's current extent
[[x0, y0], [x1, y1]]
, wherex0
andy0
are the inclusive lower bounds andx1
andy1
are the inclusive upper bounds, orundefined
if the quadtree has no extent.Expands the quadtree to cover the specified points
[[x0, y0], [x1, y1]]
and returns the quadtree. The extent may also be expanded by callingquadtree.cover
orquadtree.add
.Parameter extend
The specified points to cover.
method find
find: (x: number, y: number, radius?: number) => T | undefined;
Returns the datum closest to the position ⟨x,y⟩ with the given search radius. If radius is not specified, it defaults to infinity. If there is no datum within the search area, returns undefined.
Parameter x
The x-coordinate for the search position.
Parameter y
The y-coordinate for the search position.
Parameter radius
The optional search radius.
method remove
remove: (datum: T) => this;
Removes the specified datum to the quadtree, deriving its coordinates ⟨x,y⟩ using the current x- and y-accessors, and returns the quadtree. If the specified datum does not exist in this quadtree, this method does nothing.
Parameter datum
The specified datum to remove.
method removeAll
removeAll: (data: T[]) => this;
Removes the specified data to the quadtree, deriving their coordinates ⟨x,y⟩ using the current x- and y-accessors, and returns the quadtree. If a specified datum does not exist in this quadtree, it is ignored.
Parameter data
The specified array of data to remove.
method root
root: () => QuadtreeInternalNode<T> | QuadtreeLeaf<T>;
Returns the root node of the quadtree.
method size
size: () => number;
Returns the total number of data in the quadtree.
method visit
visit: ( callback: ( node: QuadtreeInternalNode<T> | QuadtreeLeaf<T>, x0: number, y0: number, x1: number, y1: number ) => void | boolean) => this;
Visits each node in the quadtree in pre-order traversal, invoking the specified callback with arguments
node
,x0
,y0
,x1
,y1
for each node, wherenode
is the node being visited, ⟨x0, y0⟩ are the lower bounds of the node, and ⟨x1, y1⟩ are the upper bounds, and returns the quadtree.If the callback returns true for a given node, then the children of that node are not visited; otherwise, all child nodes are visited. This can be used to quickly visit only parts of the tree. Note, however, that child quadrants are always visited in sibling order: top-left, top-right, bottom-left, bottom-right. In cases such as search, visiting siblings in a specific order may be faster.
Parameter callback
The callback invoked for each node.
method visitAfter
visitAfter: ( callback: ( node: QuadtreeInternalNode<T> | QuadtreeLeaf<T>, x0: number, y0: number, x1: number, y1: number ) => void) => this;
Visits each node in the quadtree in post-order traversal, invoking the specified callback with arguments
node
,x0
,y0
,x1
,y1
for each node, wherenode
is the node being visited, ⟨x0, y0⟩ are the lower bounds of the node, and ⟨x1, y1⟩ are the upper bounds, and returns the quadtree.Parameter callback
The callback invoked for each node.
method x
x: { (): (d: T) => number; (x: (d: T) => number): this };
Returns the current x-accessor, which defaults to:
x(d) => d[0]
.Sets the current x-coordinate accessor and returns the quadtree. The x-accessors must be consistent, returning the same value given the same input.
Parameter x
The x-coordinate accessor.
method y
y: { (): (d: T) => number; (y: (d: T) => number): this };
Returns the current y-accessor, which defaults to:
y(d) => d[1]
.Sets the current y-coordinate accessor and returns the quadtree. The y-accessors must be consistent, returning the same value given the same input.
Parameter y
The y-coordinate accessor.
interface QuadtreeInternalNode
interface QuadtreeInternalNode<T> extends Array<QuadtreeInternalNode<T> | QuadtreeLeaf<T> | undefined> {}
Internal nodes of the quadtree are represented as four-element arrays in left-to-right, top-to-bottom order:
0 - the top-left quadrant, if any. 1 - the top-right quadrant, if any. 2 - the bottom-left quadrant, if any. 3 - the bottom-right quadrant, if any.
A child quadrant may be undefined if it is empty.
property length
length: 4;
The length property may be used to distinguish leaf nodes from internal nodes: it is undefined for leaf nodes, and 4 for internal nodes.
interface QuadtreeLeaf
interface QuadtreeLeaf<T> {}
Leaf node of the quadtree.
property data
data: T;
The data associated with this point, as passed to quadtree.add.
property length
length?: undefined;
The length property may be used to distinguish leaf nodes from internal nodes: it is undefined for leaf nodes, and 4 for internal nodes.
property next
next?: QuadtreeLeaf<T> | undefined;
The next datum in this leaf, if any.
Package Files (1)
Dependencies (0)
No dependencies.
Dev Dependencies (0)
No dev dependencies.
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@types/d3-quadtree
.
- Markdown[![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@types/d3-quadtree)
- HTML<a href="https://www.jsdocs.io/package/@types/d3-quadtree"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 3658 ms. - Missing or incorrect documentation? Open an issue for this package.