Usage guidesLayout

Grid layout

Arrange nodes in a grid of rows and columns.

Overview

Arrange nodes in a grid of rows and columns.

When to use it

Use it for device panels or resource lists that need aligned nodes.

Basic usage

Set the layout type with layout.type.

const graph = new Graph({
  container,
  data,
  layout: { type: 'grid' },
});

Options

OptionDescriptionTypeDefault
rowsNumber of rows.numberComputed automatically
colsNumber of columns.numberComputed automatically
width, heightWidth and height of the layout area.numberCanvas dimensions
sortBySort nodes by ID or degree, or supply a comparator.'id' | 'degree' | comparator'degree'

Common layout options · Layout reference

Code example

Six nodes form two rows of three.

Loading example…
Drag to pan or scroll to zoom.
const layout = { type: 'grid', rows: 2, cols: 3, width: 360, height: 160 };

Compare Grid, Circular, and Dagre