!!!###!!!title=Grid——VisActor/VGraph tutorial documents!!!###!!!!!!###!!!description=Grid is an internal data structure component in vGraph used by components such as intelligent Router, EdgeEditor, NodeMover, and Background. These components usually rely on the grid defined by the Grid component to work. Grid does not handle specific rendering, but provides a grid data structure for internal calculations within the components. The rendering of the grid is handled by Background.The following is a simple example of using the Grid component.```javascriptimport { Graph, Grid } from "@visactor/vgraph";const grid = new Grid(this.graph, { step: 10, // Grid step size. extraWidth: 5, // Extra width of the node boundary, which can effectively avoid routing that sticks to the edge.});const router = new Router(grid, {...} as RouterOptions);```!!!###!!!

Grid Component

Grid is an internal data structure component in vGraph used by components such as intelligent Router, EdgeEditor, NodeMover, and Background. These components usually rely on the grid defined by the Grid component to work. Grid does not handle specific rendering, but provides a grid data structure for internal calculations within the components. The rendering of the grid is handled by Background.

The following is a simple example of using the Grid component.

import { Graph, Grid } from "@visactor/vgraph";
const grid = new Grid(this.graph, {
    step: 10, // Grid step size.
    extraWidth: 5, // Extra width of the node boundary, which can effectively avoid routing that sticks to the edge.
});
const router = new Router(grid, {...} as RouterOptions);

Configuration Items

FieldTypeDescription
stepnumberGrid step size. Default is 10.
extraWidthnumberExtra width of the node boundary, which can effectively avoid routing that sticks to the edge. Default is 0.
ignoreGroupTitlebooleanWhether to ignore the group title. Default is true. If false, the intelligent router will not cross the group title.

Instance Methods

Instance MethodReturn ValueDescription
refresh(alignGrid = false)voidRefresh the internal data structure of the Grid according to the graph data. If alignGrid is true, it will fine-tune the node coordinates to align the node with the center of the grid.
getStep()numberGet the grid step size.
getIndexByCoord()[number, number]Convert graph coordinates to grid subscripts, returns [col,row].
isWalkable(col: number, row: number)booleanReturns whether the grid at this subscript is empty.
getValueByCoord()numberGet the number of entities (nodes or non-ignored group titles) at this graph coordinate.
destroy()voidDestroy the component.