Usage guidesLayoutRecommended optional layouts

Random layout

Scatter nodes randomly around the layout center.

Overview

Scatter nodes randomly around the layout center.

When to use it

Use it for a quick preview of graph data. Each run samples new positions.

Basic usage

This layout is optional. Import and register it before setting layout.type. For CDN usage, see Optional layouts.

import { Graph, register } from '@antv/g6-lite';
import random from '@antv/g6-lite/layouts/random';

register('layout', 'random', random);

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

Options

OptionDescriptionTypeDefault
widthControls the horizontal spread.numberCanvas width
heightControls the vertical spread.numberCanvas height
centerCenter of the spread in graph coordinates.[number, number]Center of the layout area

Common layout options · Layout reference

Code example

Nodes are scattered around [200, 120]. Reset the example to sample new positions.

Loading example…
Drag to pan or scroll to zoom.
import { register } from '@antv/g6-lite';

import random from '@antv/g6-lite/layouts/random';

register('layout', 'random', random);

const layout = { type: 'random', width: 400, height: 240, center: [200, 120] };

Browse the layout gallery