SearchGraph
The SearchGraph
is a subclass of the dia.Graph
class, specifically designed to optimize spatial queries for cells.
It uses a quadtree to index cells by their bounding boxes and overrides dia.Graph
methods to enable more efficient search capabilities.
import { dia, shapes } from '@joint/plus';
const graph = new dia.SearchGraph({}, { cellNamespace: shapes });
Check out our learn section to see how to use the SearchGraph
in practice.
Methodsβ
The class has all the methods of the parent class and provides a few additional methods to fine-tune the quadtree indexing.
invalidateQuadTree()β
invalidateQuadTree(): void;
Invalidate the quadtree. This will force the quadtree to be rebuilt on the next search query.
setQuadTreeBoundary()β
setQuadTreeBoundary(boundary: dia.BBox, autoGrow: boolean = false): void;
Set the initial boundary of the quadtree.
If autoGrow
is true
, the boundary is automatically expanded when a cell is added outside of the boundary.
setQuadTreeBoundary(boundary: null): void;
If the boundary is null
, the boundary is automatically computed from the cells in the graph and the autoGrow
parameter is ignored.
This is the default behavior of the search graph.
setQuadTreeCapacity()β
setQuadTreeCapacity(capacity: number): void;
Set the capacity of the quadtree. The capacity is the maximum number of cells in a quadtree node before it splits into four subnodes.
The default node capacity is 16
.
setQuadTreeLazyMode()β
setQuadTreeLazyMode(lazyMode: boolean): void;
Set the lazy mode of the quadtree. In lazy mode, the quadtree is not updated automatically when cells are added or removed. Instead, the quadtree is updated only when the first search is performed.
setQuadTreeMaxDepth()β
setQuadTreeMaxDepth(maxDepth: number): void;
Set the maximum depth of the quadtree. The maximum depth is the maximum number of levels the quadtree can have.
The default maximum depth is 6
.