| Layout | Preview | When to use it |
@@ -583,10 +586,11 @@ Branches extend horizontally from a central topic. This example uses ID prefixes
```ts
import type { GraphNode, LayoutConfig } from '@antv/g6-lite';
+import { MindmapLayout } from '@antv/layout';
const leftBranches = new Set(['A', 'C']);
const layout: LayoutConfig = {
- type: 'mindmap',
+ type: MindmapLayout,
direction: 'H',
levelGap: 100,
nodeGap: 24,
@@ -604,14 +608,16 @@ const layout: LayoutConfig = {
| `branchColors` | Writes the branch color to `data._branchColor` for style functions to read. | `string[]` | Built-in palette of 10 colors |
| `getWidth` | Gets the node width. | `(node: GraphNode) => number` | Returns `100` |
| `getHeight` | Gets the node height. | `(node: GraphNode) => number` | Returns `40` |
-| `getSide` | Chooses the side for a branch. The callback's node contains only `id` and `data`. | `(node: GraphNode, index: number, parentSide?: 'left' \| 'right') => 'left' \| 'right'` | Returns `'right'` |
+| `getSide` | Chooses the side for a branch. To access application data, look up the original node by `id`. | `(node: GraphNode, index: number, parentSide?: 'left' \| 'right') => 'left' \| 'right'` | Returns `'right'` |
#### Indented tree (indented) [#config-layout-indented]
Each node occupies a row. Children appear below their parents and indent farther at each level. Use `indent` for horizontal spacing and `rowHeight` for vertical spacing.
```ts
-const layout: LayoutConfig = { type: 'indented', indent: 72, rowHeight: 30 };
+import { IndentedLayout } from '@antv/layout';
+
+const layout: LayoutConfig = { type: IndentedLayout, indent: 72, rowHeight: 30 };
const edge: EdgeConfig = { type: 'polyline', style: { router: 'indented', endArrow: false } };
```
@@ -629,7 +635,9 @@ const edge: EdgeConfig = { type: 'polyline', style: { router: 'indented', endArr
Use three levels for a problem, categories of causes, and individual causes. `categoryGap` spaces the categories along the spine and `categoryDistance` moves them away from it.
```ts
-const layout: LayoutConfig = { type: 'fishbone', categoryGap: 156, categoryDistance: 130, itemHStep: 54 };
+import { FishboneLayout } from '@antv/layout';
+
+const layout: LayoutConfig = { type: FishboneLayout, categoryGap: 156, categoryDistance: 130, itemHStep: 54 };
const edge: EdgeConfig = { type: 'polyline', style: { router: 'fishbone', endArrow: false } };
```
@@ -645,7 +653,7 @@ const edge: EdgeConfig = { type: 'polyline', style: { router: 'fishbone', endArr
### Layout options [#config-library-layout-fields]
-Set the layout `type` and its options in `layout`. For example, `layout: { type: 'dagre', rankdir: 'LR' }` arranges a flow from left to right.
+Set the layout `type` and its options in `layout`. For example, `layout: { type: DagreLayout, rankdir: 'LR' }` arranges a flow from left to right.
| Layout type | Example options | Effect |
| --- | --- | --- |
diff --git a/site/content/docs/en/compatibility/g6-v5-migration.mdx b/site/content/docs/en/compatibility/g6-v5-migration.mdx
index 481972c93..5ffd7a526 100644
--- a/site/content/docs/en/compatibility/g6-v5-migration.mdx
+++ b/site/content/docs/en/compatibility/g6-v5-migration.mdx
@@ -34,7 +34,7 @@ export async function mountGraph(container: HTMLElement) {
edges: [{ id: 'a-b', source: 'a', target: 'b' }],
},
node: { style: { label: (node) => node.id } },
- layout: { type: 'circular', radius: 100 },
+ layout: { type: 'force', linkDistance: 100 },
behaviors: ['zoom-canvas', 'drag-canvas', 'drag-node', 'click-select'],
});
try {
diff --git a/site/content/docs/en/getting-started/quick-start.mdx b/site/content/docs/en/getting-started/quick-start.mdx
index 280035db1..644f7bfea 100644
--- a/site/content/docs/en/getting-started/quick-start.mdx
+++ b/site/content/docs/en/getting-started/quick-start.mdx
@@ -188,7 +188,7 @@ Save the HTML below as `index.html` and open it in your browser.
### Use the UMD script [#cdn-umd]
-The UMD script includes runtime dependencies and built-in layouts. Once loaded, create a graph with `G6Lite.Graph`. This minimal example draws two nodes and one edge:
+The UMD script includes runtime dependencies and built-in layouts. This `0.1.0` example uses the built-in `force` layout to draw two nodes and one edge with `G6Lite.Graph`:
```html
@@ -200,7 +200,7 @@ The UMD script includes runtime dependencies and built-in layouts. Once loaded,
nodes: [{ id: 'Alice' }, { id: 'Bob' }],
edges: [{ source: 'Alice', target: 'Bob' }],
},
- layout: { type: 'circular', radius: 80 },
+ layout: { type: 'force', linkDistance: 80 },
node: { style: { label: (node) => node.id } },
behaviors: ['zoom-canvas', 'drag-canvas', 'drag-node'],
});
@@ -212,7 +212,7 @@ The UMD script includes runtime dependencies and built-in layouts. Once loaded,
```
-ESM integrations support on-demand layout loading through a bundler; the UMD script bundles built-in layouts. Both integrations require [importing and registering optional layouts](/en/docs/guides/layout-overview#optional-layouts) before use. See the [Worker guide](/en/docs/guides/layout-worker) for Worker deployment requirements.
+ESM integrations support on-demand layout loading through a bundler. The UMD script bundles built-in layouts. See the [layout overview](/en/docs/guides/layout-overview#builtin-and-external-layouts) for the layout options available in each version and the [Worker guide](/en/docs/guides/layout-worker) for Worker deployment requirements.
The standalone HTML examples above destroy their instances on `pagehide`. Recreate them if the browser restores the page from its back/forward cache.
diff --git a/site/content/docs/en/getting-started/react.mdx b/site/content/docs/en/getting-started/react.mdx
index 7f7fd5bdd..9285e1667 100644
--- a/site/content/docs/en/getting-started/react.mdx
+++ b/site/content/docs/en/getting-started/react.mdx
@@ -57,7 +57,7 @@ export default function GraphView() {
const graph = new Graph({
container: containerRef.current,
data: basicData,
- layout: { type: 'circular', radius: 120 },
+ layout: { type: 'force', linkDistance: 120 },
node: { style: { size: 24, label: (node) => node.id, labelPlacement: 'bottom' } },
edge: { style: { endArrow: true } },
autoFit: fitView,
diff --git a/site/content/docs/en/getting-started/vue.mdx b/site/content/docs/en/getting-started/vue.mdx
index ee13a9886..d4022feb0 100644
--- a/site/content/docs/en/getting-started/vue.mdx
+++ b/site/content/docs/en/getting-started/vue.mdx
@@ -56,7 +56,7 @@ onMounted(async () => {
const instance = new Graph({
container: containerRef.value,
data: basicData,
- layout: { type: 'circular', radius: 120 },
+ layout: { type: 'force', linkDistance: 120 },
node: { style: { size: 24, label: (node) => node.id, labelPlacement: 'bottom' } },
edge: { style: { endArrow: true } },
autoFit: fitView,
diff --git a/site/content/docs/en/graph/overview.mdx b/site/content/docs/en/graph/overview.mdx
index 654be5882..2a798a6ff 100644
--- a/site/content/docs/en/graph/overview.mdx
+++ b/site/content/docs/en/graph/overview.mdx
@@ -60,7 +60,7 @@ After the first render, you can focus a node or update the data. For method timi
| `edge` | `EdgeConfig` | Straight edges | Sets edge shapes, arrowheads, and states. |
| `combo` | `ComboConfig` | Built-in styles | Sets group appearance, labels, and collapsed shapes. |
| `label` | `LabelOptions` | Built-in policy | Controls label scaling and visibility. |
-| `layout` | `LayoutConfig` | Input coordinates | Chooses the algorithm and options for positioning nodes. |
+| `layout` | `LayoutConfig` or `LayoutConstructor` | Input coordinates | Configures an algorithm and its options, or accepts a layout class directly. |
| `behaviors` | `BehaviorOption[]` | Canvas zoom and drag | Configures interactions such as zooming, dragging, and selection. |
| `theme` | `ThemeOption` | `'light'` | Sets default styles for the canvas and elements. |
| `transforms` | `TransformOption[]` | None | Processes input data in order before layout. |
diff --git a/site/content/docs/en/guides/custom-layout.mdx b/site/content/docs/en/guides/custom-layout.mdx
index 9a1bff011..a8d452360 100644
--- a/site/content/docs/en/guides/custom-layout.mdx
+++ b/site/content/docs/en/guides/custom-layout.mdx
@@ -7,6 +7,8 @@ import { NodeDocExample } from '@/components/node-doc-example';
Use a `LayoutExtension` to calculate node positions from graph data. This example arranges nodes in a row with equal spacing. See the [Layout overview](/en/docs/guides/layout-overview) for built-in layouts.
+Existing layout classes imported from `@antv/layout` can be passed directly as `layout.type` without registration. Only a custom `LayoutExtension` needs to be registered with `register`.
+
## Implement and execute
Read current data and runtime.options, retain node IDs/business fields, and return finite x/y. Reading options from runtime also supports standalone execution without init.
diff --git a/site/content/docs/en/guides/data.mdx b/site/content/docs/en/guides/data.mdx
index 42cf2cacf..abcd334a0 100644
--- a/site/content/docs/en/guides/data.mdx
+++ b/site/content/docs/en/guides/data.mdx
@@ -191,11 +191,12 @@ If the endpoint returns a complete dataset, render an empty graph first, then lo
```ts
import { Graph, type GraphData } from '@antv/g6-lite';
+import { GridLayout } from '@antv/layout';
const graph = new Graph({
container: '#container',
data: { nodes: [], edges: [] },
- layout: { type: 'grid' },
+ layout: { type: GridLayout },
});
await graph.render();
diff --git a/site/content/docs/en/guides/edge.mdx b/site/content/docs/en/guides/edge.mdx
index 10ce72bbd..7b06d323b 100644
--- a/site/content/docs/en/guides/edge.mdx
+++ b/site/content/docs/en/guides/edge.mdx
@@ -282,7 +282,9 @@ For text-only child nodes, use `right` to extend the line to the end of the text
Polylines follow the layout direction. For Dagre, `rankdir: 'LR'` goes left to right and `rankdir: 'TB'` goes top to bottom. Use **Direction** in the [orthogonal connections example](#orthogonal-connections-and-rounding) to compare them.
```ts
-graph.setLayout({ type: 'dagre', rankdir: 'TB', nodeSize: [84, 32] });
+import { DagreLayout } from '@antv/layout';
+
+graph.setLayout({ type: DagreLayout, rankdir: 'TB', nodeSize: [84, 32] });
await graph.render();
```
diff --git a/site/content/docs/en/guides/layout-arrangements.mdx b/site/content/docs/en/guides/layout-arrangements.mdx
index 630d77181..fe1371de5 100644
--- a/site/content/docs/en/guides/layout-arrangements.mdx
+++ b/site/content/docs/en/guides/layout-arrangements.mdx
@@ -9,9 +9,17 @@ import { NodeDocExample } from '@/components/node-doc-example';
| Type | Description | Example configuration |
| --- | --- | --- |
-| [`grid`](/en/docs/guides/layout-grid) | Arrange nodes in two rows and three columns. | `{ type: 'grid', rows: 2, cols: 3 }` |
-| [`circular`](/en/docs/guides/layout-circular) | Arrange nodes in a ring with radius 100. | `{ type: 'circular', radius: 100 }` |
-| [`dagre`](/en/docs/guides/layout-dagre) | Arrange dependency layers from left to right. | `{ type: 'dagre', rankdir: 'LR' }` |
+| [`grid`](/en/docs/guides/layout-grid) | Arrange nodes in two rows and three columns. | `{ type: GridLayout, rows: 2, cols: 3 }` |
+| [`circular`](/en/docs/guides/layout-circular) | Arrange nodes in a ring with radius 100. | `{ type: CircularLayout, radius: 100 }` |
+| [`dagre`](/en/docs/guides/layout-dagre) | Arrange dependency layers from left to right. | `{ type: DagreLayout, rankdir: 'LR' }` |
+
+Import the layout classes used by the example configurations:
+
+```ts
+import { GridLayout } from '@antv/layout';
+import { CircularLayout } from '@antv/layout';
+import { DagreLayout } from '@antv/layout';
+```
## Compare layouts
diff --git a/site/content/docs/en/guides/layout-circular.mdx b/site/content/docs/en/guides/layout-circular.mdx
index 31cff9cdf..ffbfd7059 100644
--- a/site/content/docs/en/guides/layout-circular.mdx
+++ b/site/content/docs/en/guides/layout-circular.mdx
@@ -18,10 +18,12 @@ Use a circle for networks without a hierarchy, or a spiral for ordered nodes.
Set the layout type with `layout.type`.
```ts
+import { CircularLayout } from '@antv/layout';
+
const graph = new Graph({
container,
data,
- layout: { type: 'circular' },
+ layout: { type: CircularLayout },
});
```
@@ -47,7 +49,9 @@ Eight nodes sit on a circle with a radius of 100.
Set `startRadius` and `endRadius` to different values and omit `radius`.
```ts
-const layout = { type: 'circular', startRadius: 30, endRadius: 140 };
+import { CircularLayout } from '@antv/layout';
+
+const layout = { type: CircularLayout, startRadius: 30, endRadius: 140 };
```
[Compare Grid, Circular, and Dagre](/en/docs/guides/layout-arrangements)
diff --git a/site/content/docs/en/guides/layout-concentric.mdx b/site/content/docs/en/guides/layout-concentric.mdx
index f2abf22a6..5e6d5b784 100644
--- a/site/content/docs/en/guides/layout-concentric.mdx
+++ b/site/content/docs/en/guides/layout-concentric.mdx
@@ -18,10 +18,12 @@ Use it to emphasize hubs by their number of connections.
Set the layout type with `layout.type`.
```ts
+import { ConcentricLayout } from '@antv/layout';
+
const graph = new Graph({
container,
data,
- layout: { type: 'concentric' },
+ layout: { type: ConcentricLayout },
});
```
diff --git a/site/content/docs/en/guides/layout-dagre.mdx b/site/content/docs/en/guides/layout-dagre.mdx
index 1d454bd6b..e6864a00d 100644
--- a/site/content/docs/en/guides/layout-dagre.mdx
+++ b/site/content/docs/en/guides/layout-dagre.mdx
@@ -18,10 +18,12 @@ Use it for workflows, call chains, and dependency graphs.
Set the layout type with `layout.type`.
```ts
+import { DagreLayout } from '@antv/layout';
+
const graph = new Graph({
container,
data,
- layout: { type: 'dagre' },
+ layout: { type: DagreLayout },
});
```
diff --git a/site/content/docs/en/guides/layout-fishbone.mdx b/site/content/docs/en/guides/layout-fishbone.mdx
index db4f52677..23d48cab1 100644
--- a/site/content/docs/en/guides/layout-fishbone.mdx
+++ b/site/content/docs/en/guides/layout-fishbone.mdx
@@ -15,18 +15,16 @@ Use it for three-level structures such as a problem, cause categories, and speci
## Basic usage
-This layout is optional. Import and register it before setting `layout.type`. For CDN usage, see [Optional layouts](/en/docs/guides/layout-overview#optional-layouts).
+This is an external layout. Import its class from `@antv/layout` and pass it as `layout.type`; no registration is required. See [Built-in and external layouts](/en/docs/guides/layout-overview#builtin-and-external-layouts).
```ts
-import { Graph, register } from '@antv/g6-lite';
-import fishbone from '@antv/g6-lite/layouts/fishbone';
-
-register('layout', 'fishbone', fishbone);
+import { Graph } from '@antv/g6-lite';
+import { FishboneLayout } from '@antv/layout';
const graph = new Graph({
container,
data,
- layout: { type: 'fishbone' },
+ layout: { type: FishboneLayout },
edge: { type: 'polyline', style: { router: 'fishbone', endArrow: false } },
});
```
diff --git a/site/content/docs/en/guides/layout-grid.mdx b/site/content/docs/en/guides/layout-grid.mdx
index d59802ed7..e62c6040a 100644
--- a/site/content/docs/en/guides/layout-grid.mdx
+++ b/site/content/docs/en/guides/layout-grid.mdx
@@ -18,10 +18,12 @@ Use it for device panels or resource lists that need aligned nodes.
Set the layout type with `layout.type`.
```ts
+import { GridLayout } from '@antv/layout';
+
const graph = new Graph({
container,
data,
- layout: { type: 'grid' },
+ layout: { type: GridLayout },
});
```
diff --git a/site/content/docs/en/guides/layout-indented.mdx b/site/content/docs/en/guides/layout-indented.mdx
index cab74c4b5..45ac01a09 100644
--- a/site/content/docs/en/guides/layout-indented.mdx
+++ b/site/content/docs/en/guides/layout-indented.mdx
@@ -15,18 +15,16 @@ Use it for file directories, navigation menus, and taxonomies.
## Basic usage
-This layout is optional. Import and register it before setting `layout.type`. For CDN usage, see [Optional layouts](/en/docs/guides/layout-overview#optional-layouts).
+This is an external layout. Import its class from `@antv/layout` and pass it as `layout.type`; no registration is required. See [Built-in and external layouts](/en/docs/guides/layout-overview#builtin-and-external-layouts).
```ts
-import { Graph, register } from '@antv/g6-lite';
-import indented from '@antv/g6-lite/layouts/indented';
-
-register('layout', 'indented', indented);
+import { Graph } from '@antv/g6-lite';
+import { IndentedLayout } from '@antv/layout';
const graph = new Graph({
container,
data,
- layout: { type: 'indented' },
+ layout: { type: IndentedLayout },
});
```
diff --git a/site/content/docs/en/guides/layout-mds.mdx b/site/content/docs/en/guides/layout-mds.mdx
index d0c15a434..1e9f81f58 100644
--- a/site/content/docs/en/guides/layout-mds.mdx
+++ b/site/content/docs/en/guides/layout-mds.mdx
@@ -15,18 +15,16 @@ Use it to examine how close or far apart nodes are in a network.
## Basic usage
-This layout is optional. Import and register it before setting `layout.type`. For CDN usage, see [Optional layouts](/en/docs/guides/layout-overview#optional-layouts).
+This is an external layout. Import its class from `@antv/layout` and pass it as `layout.type`; no registration is required. See [Built-in and external layouts](/en/docs/guides/layout-overview#builtin-and-external-layouts).
```ts
-import { Graph, register } from '@antv/g6-lite';
-import mds from '@antv/g6-lite/layouts/mds';
-
-register('layout', 'mds', mds);
+import { Graph } from '@antv/g6-lite';
+import { MDSLayout } from '@antv/layout';
const graph = new Graph({
container,
data,
- layout: { type: 'mds' },
+ layout: { type: MDSLayout },
});
```
diff --git a/site/content/docs/en/guides/layout-mindmap.mdx b/site/content/docs/en/guides/layout-mindmap.mdx
index 7d867260b..944e49ce3 100644
--- a/site/content/docs/en/guides/layout-mindmap.mdx
+++ b/site/content/docs/en/guides/layout-mindmap.mdx
@@ -15,18 +15,16 @@ Use it to organize ideas, knowledge, and categories.
## Basic usage
-This layout is optional. Import and register it before setting `layout.type`. For CDN usage, see [Optional layouts](/en/docs/guides/layout-overview#optional-layouts).
+This is an external layout. Import its class from `@antv/layout` and pass it as `layout.type`; no registration is required. See [Built-in and external layouts](/en/docs/guides/layout-overview#builtin-and-external-layouts).
```ts
-import { Graph, register } from '@antv/g6-lite';
-import mindmap from '@antv/g6-lite/layouts/mindmap';
-
-register('layout', 'mindmap', mindmap);
+import { Graph } from '@antv/g6-lite';
+import { MindmapLayout } from '@antv/layout';
const graph = new Graph({
container,
data,
- layout: { type: 'mindmap' },
+ layout: { type: MindmapLayout },
});
```
diff --git a/site/content/docs/en/guides/layout-networks.mdx b/site/content/docs/en/guides/layout-networks.mdx
index b9dc9a3ee..e6c129fb0 100644
--- a/site/content/docs/en/guides/layout-networks.mdx
+++ b/site/content/docs/en/guides/layout-networks.mdx
@@ -18,7 +18,7 @@ import { NodeDocExample } from '@/components/node-doc-example';
The example starts with a radial layout. Set `focusNode` to `0` to choose its center and `unitRadius` to 68 to space the rings. Use **Layout** to compare all seven layouts on the same network.
-Register Radial and MDS before using them. [Optional layouts](/en/docs/guides/layout-overview#optional-layouts)
+Import `RadialLayout` and `MDSLayout` from `@antv/layout` and pass the class as `layout.type`. [Built-in and external layouts](/en/docs/guides/layout-overview#builtin-and-external-layouts)
diff --git a/site/content/docs/en/guides/layout-overview.mdx b/site/content/docs/en/guides/layout-overview.mdx
index 4dbbd1df3..8f428a657 100644
--- a/site/content/docs/en/guides/layout-overview.mdx
+++ b/site/content/docs/en/guides/layout-overview.mdx
@@ -13,47 +13,59 @@ A layout determines where nodes go. A workflow can run left to right, while a fo
| Type | Description | Example configuration |
| --- | --- | --- |
-| [`grid`](/en/docs/guides/layout-grid) | Arrange nodes in rows and columns. | `{ type: 'grid', cols: 3 }` |
-| [`circular`](/en/docs/guides/layout-circular) | Arrange nodes along a circle. | `{ type: 'circular', radius: 100 }` |
-| [`dagre`](/en/docs/guides/layout-dagre) | Arrange steps or dependencies in layers. | `{ type: 'dagre', rankdir: 'LR', ranksep: 80 }` |
| [`force`](/en/docs/guides/layout-force) | Bring linked nodes closer while spacing nodes apart. | `{ type: 'force', linkDistance: 100 }` |
| [`d3-force`](/en/docs/guides/layout-d3-force) | Arrange a network with D3 force simulation. | `{ type: 'd3-force', linkDistance: 100 }` |
| [`force-atlas2`](/en/docs/guides/layout-force-atlas2) | Use force simulation to reveal network clusters. | `{ type: 'force-atlas2', kr: 12, kg: 0.5 }` |
| [`fruchterman`](/en/docs/guides/layout-fruchterman) | Spread nodes using attraction and repulsion. | `{ type: 'fruchterman', gravity: 4 }` |
-| [`radial`](/en/docs/guides/layout-radial) | **Optional.** Arrange nodes in rings by graph distance from a focal node. | `{ type: 'radial', focusNode: '0', unitRadius: 68 }` |
-| [`concentric`](/en/docs/guides/layout-concentric) | Arrange nodes in concentric rings by degree. | `{ type: 'concentric', sortBy: 'degree' }` |
-| [`mds`](/en/docs/guides/layout-mds) | **Optional.** Approximate graph distances in two dimensions. | `{ type: 'mds', linkDistance: 80 }` |
-| [`indented`](/en/docs/guides/layout-indented) | **Optional.** Arrange a tree as an indented list. | `{ type: 'indented', indent: 80, rowHeight: 40 }` |
-| [`mindmap`](/en/docs/guides/layout-mindmap) | **Optional.** Arrange a tree as mind map branches. | `{ type: 'mindmap', levelGap: 120, nodeGap: 30 }` |
-| [`fishbone`](/en/docs/guides/layout-fishbone) | **Optional.** Arrange categories and items along a fishbone spine. | `{ type: 'fishbone', categoryGap: 180 }` |
-| [`random`](/en/docs/guides/layout-random) | **Optional.** Scatter nodes randomly within an area. | `{ type: 'random', width: 800, height: 600, center: [400, 300] }` |
+| [`grid`](/en/docs/guides/layout-grid) | **External.** Arrange nodes in rows and columns. | `{ type: GridLayout, cols: 3 }` |
+| [`circular`](/en/docs/guides/layout-circular) | **External.** Arrange nodes along a circle. | `{ type: CircularLayout, radius: 100 }` |
+| [`dagre`](/en/docs/guides/layout-dagre) | **External.** Arrange steps or dependencies in layers. | `{ type: DagreLayout, rankdir: 'LR', ranksep: 80 }` |
+| [`concentric`](/en/docs/guides/layout-concentric) | **External.** Arrange nodes in concentric rings by degree. | `{ type: ConcentricLayout, sortBy: 'degree' }` |
+| [`radial`](/en/docs/guides/layout-radial) | **External.** Arrange nodes in rings by graph distance from a focal node. | `{ type: RadialLayout, focusNode: '0', unitRadius: 68 }` |
+| [`mds`](/en/docs/guides/layout-mds) | **External.** Approximate graph distances in two dimensions. | `{ type: MDSLayout, linkDistance: 80 }` |
+| [`indented`](/en/docs/guides/layout-indented) | **External.** Arrange a tree as an indented list. | `{ type: IndentedLayout, indent: 80, rowHeight: 40 }` |
+| [`mindmap`](/en/docs/guides/layout-mindmap) | **External.** Arrange a tree as mind map branches. | `{ type: MindmapLayout, levelGap: 120, nodeGap: 30 }` |
+| [`fishbone`](/en/docs/guides/layout-fishbone) | **External.** Arrange categories and items along a fishbone spine. | `{ type: FishboneLayout, categoryGap: 180 }` |
+| [`random`](/en/docs/guides/layout-random) | **External.** Scatter nodes randomly within an area. | `{ type: RandomLayout, width: 800, height: 600, center: [400, 300] }` |
Pass these configuration objects to `layout`. See [Common layout options](/en/docs/guides/layout) for more parameters and previews.
-## Optional layouts [#optional-layouts]
+## Built-in and external layouts [#builtin-and-external-layouts]
-Indented, Mindmap, Fishbone, Radial, MDS, and Random require registration. With npm, import the layout from its own subpath, register it, and set `layout.type`.
+The external layout class examples on this page require a G6Lite build that includes the layout refactor. The published `0.1.0` uses built-in string names such as `type: 'dagre'`. Optional layouts such as mind maps are imported from `@antv/g6-lite/layouts/*` and registered before use.
-```ts
-import { register } from '@antv/g6-lite';
-import radial from '@antv/g6-lite/layouts/radial';
+G6Lite bundles only four force-directed layouts for large-scale graph analysis: `force`, `force-atlas2`, `d3-force`, and `fruchterman`. Use their string names directly.
-register('layout', 'radial', radial);
+With a G6Lite build that accepts layout classes, install `@antv/layout` directly in your app. Import the layout class and pass it as `layout.type`.
-const layout = { type: 'radial', focusNode: '0', unitRadius: 68 };
+```bash
+npm install @antv/layout@^2.1.0
```
-When using UMD from a CDN, load the same version of `dist/g6-lite-layouts.min.js` after the main script. The layout extensions are available on `G6LiteLayouts`.
+```ts
+import { Graph } from '@antv/g6-lite';
+import { DagreLayout } from '@antv/layout';
-```html
-
-
-
+const graph = new Graph({
+ container: '#container',
+ data,
+ layout: { type: DagreLayout, rankdir: 'LR', ranksep: 80 },
+});
```
-Registered layouts run on the main thread.
+You can also pass the class directly without an options object: `layout: DagreLayout`.
+
+External layout classes manage their own execution. `layout.worker` controls the G6Lite Worker for string-named built-in layouts.
+
+## Other layouts [#optional-layouts]
+
+Indented, Mindmap, Fishbone, Radial, MDS, and Random are also external layouts. Import their classes directly from `@antv/layout`; no registration is required. This example uses Radial:
+
+```ts
+import { RadialLayout } from '@antv/layout';
+
+const layout = { type: RadialLayout, focusNode: '0', unitRadius: 68 };
+```
## Configuration and example
@@ -61,6 +73,7 @@ Set the algorithm with `layout.type`. This example uses Dagre to arrange three s
```ts
import { Graph } from '@antv/g6-lite';
+import { DagreLayout } from '@antv/layout';
const graph = new Graph({
container: '#container',
@@ -71,7 +84,7 @@ const graph = new Graph({
{ source: 'Review', target: 'Publish' },
],
},
- layout: { type: 'dagre', rankdir: 'LR', ranksep: 80 },
+ layout: { type: DagreLayout, rankdir: 'LR', ranksep: 80 },
node: { style: { label: (node) => node.id } },
});
diff --git a/site/content/docs/en/guides/layout-radial.mdx b/site/content/docs/en/guides/layout-radial.mdx
index f45f8c34e..fa4e22922 100644
--- a/site/content/docs/en/guides/layout-radial.mdx
+++ b/site/content/docs/en/guides/layout-radial.mdx
@@ -15,18 +15,16 @@ Use it to see the direct and indirect relationships of an account, service, or d
## Basic usage
-This layout is optional. Import and register it before setting `layout.type`. For CDN usage, see [Optional layouts](/en/docs/guides/layout-overview#optional-layouts).
+This is an external layout. Import its class from `@antv/layout` and pass it as `layout.type`; no registration is required. See [Built-in and external layouts](/en/docs/guides/layout-overview#builtin-and-external-layouts).
```ts
-import { Graph, register } from '@antv/g6-lite';
-import radial from '@antv/g6-lite/layouts/radial';
-
-register('layout', 'radial', radial);
+import { Graph } from '@antv/g6-lite';
+import { RadialLayout } from '@antv/layout';
const graph = new Graph({
container,
data,
- layout: { type: 'radial' },
+ layout: { type: RadialLayout },
});
```
diff --git a/site/content/docs/en/guides/layout-random.mdx b/site/content/docs/en/guides/layout-random.mdx
index 081cb1f8e..b085d2235 100644
--- a/site/content/docs/en/guides/layout-random.mdx
+++ b/site/content/docs/en/guides/layout-random.mdx
@@ -15,18 +15,16 @@ 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](/en/docs/guides/layout-overview#optional-layouts).
+This is an external layout. Import its class from `@antv/layout` and pass it as `layout.type`; no registration is required. See [Built-in and external layouts](/en/docs/guides/layout-overview#builtin-and-external-layouts).
```ts
-import { Graph, register } from '@antv/g6-lite';
-import random from '@antv/g6-lite/layouts/random';
-
-register('layout', 'random', random);
+import { Graph } from '@antv/g6-lite';
+import { RandomLayout } from '@antv/layout';
const graph = new Graph({
container,
data,
- layout: { type: 'random' },
+ layout: { type: RandomLayout },
});
```
diff --git a/site/content/docs/en/guides/layout-trees.mdx b/site/content/docs/en/guides/layout-trees.mdx
index dc5039b1d..5d2cf5adf 100644
--- a/site/content/docs/en/guides/layout-trees.mdx
+++ b/site/content/docs/en/guides/layout-trees.mdx
@@ -19,7 +19,7 @@ Express parent-child relationships as edges with the parent as `source` and the
Use **Tree layout** to compare the three arrangements. The example also changes the edge routing. Indented trees use elbow connectors, while the fishbone layout uses angled branches.
-Register each tree layout before using it. [Optional layouts](/en/docs/guides/layout-overview#optional-layouts)
+Import each tree layout class from `@antv/layout` and pass it as `layout.type`; no registration is required. See [Built-in and external layouts](/en/docs/guides/layout-overview#builtin-and-external-layouts).
diff --git a/site/content/docs/en/guides/layout-worker.mdx b/site/content/docs/en/guides/layout-worker.mdx
index 412b407e4..27afa7d32 100644
--- a/site/content/docs/en/guides/layout-worker.mdx
+++ b/site/content/docs/en/guides/layout-worker.mdx
@@ -15,11 +15,11 @@ layout: { type: 'force-atlas2', worker: true, maxIteration: 100 },
| layout.worker | Graph behavior |
| --- | --- |
-| Omitted | Attempts a Worker at ≥ 1000 nodes; main thread below that threshold |
-| true | Attempts a Worker for built-in library layouts; registered extensions, including all six optional layouts, execute on the main thread |
-| false | Explicitly disables Workers, including for large graphs |
+| Omitted | Attempts a G6Lite Worker at 1,000 nodes or more for string-named built-in layouts |
+| true | Attempts a G6Lite Worker for string-named built-in layouts |
+| false | Disables the G6Lite Worker at any graph size |
-Standalone runLayout has no node-count-based automatic switch. Worker failures fall back to the same main-thread algorithm. See the [layout reference](/en/docs/guides/layout#worker) for execution order and iteration defaults.
+A registered extension with a matching name takes precedence. Registered extensions and imported layout classes manage their own execution. Standalone `runLayout` uses a G6Lite Worker when explicitly requested. Worker failures fall back to the same main-thread algorithm. See the [layout reference](/en/docs/guides/layout#worker) for execution order and iteration defaults.
## Code and rendered result
@@ -39,7 +39,7 @@ Creation, asset loading, postMessage cloning, or computation failures can trigge
## Cancellation and cleanup
-After rendering, graph.cancelLayout() can terminate that instance's active Worker and discard results. It neither rolls back completed layouts nor affects another Graph's Worker. To continue, setLayout again and await layout.
+After rendering, `graph.cancelLayout()` can terminate the instance's G6Lite Worker and discard the pending layout result. Custom layouts manage their own background tasks and resources. To continue, call `setLayout()` and await `layout()`.
The example's generation check also protects application-side completion messages and fitView from stale calls. Call graph.destroy() on unmount, and clean up your own controls, timers, and subscriptions.
diff --git a/site/content/docs/en/guides/layout.mdx b/site/content/docs/en/guides/layout.mdx
index 4fa1fb608..a33a821a3 100644
--- a/site/content/docs/en/guides/layout.mdx
+++ b/site/content/docs/en/guides/layout.mdx
@@ -11,7 +11,7 @@ Configure the layout in `new Graph()` through `layout`. See the [Layout overview
| Field | Purpose |
| --- | --- |
-| `type` | Algorithm name, such as `dagre` |
+| `type` | Algorithm name for built-in layouts (such as `force`) or a layout class imported from `@antv/layout` (such as `DagreLayout`) |
| `width`, `height` | Computation bounds, defaulting to canvas dimensions |
| `center` | Layout center for algorithms that use it |
| `worker` | Whether to try computing in a Worker |
@@ -24,23 +24,23 @@ Direction and spacing depend on the algorithm. See the [layout reference](/en/do
The thumbnails show 11 layouts on the same data. Try them in the [layout gallery](/en/docs/examples/layout-gallery) or see the [AntV Layout documentation](https://layout.antv.vision/) for more options.
-Layouts marked **Optional** must be imported and registered. See [Optional layouts](/en/docs/guides/layout-overview#optional-layouts).
+Layouts marked **External** must be imported from `@antv/layout` and passed as classes through `layout.type`; no registration is required. See [Built-in and external layouts](/en/docs/guides/layout-overview#builtin-and-external-layouts).
| type | Preview | Purpose | Common algorithm options |
| --- | --- | --- | --- |
-| [`circular`](/en/docs/guides/layout-circular) |  | Circle or spiral | radius, startRadius, endRadius, startAngle, endAngle, clockwise |
-| [`concentric`](/en/docs/guides/layout-concentric) |  | Rings by importance | sortBy, maxLevelDiff, nodeSize, nodeSpacing, preventOverlap |
-| [`grid`](/en/docs/guides/layout-grid) |  | Rows and columns | rows, cols, begin, sortBy, nodeSize, nodeSpacing, preventOverlap |
-| [`random`](/en/docs/guides/layout-random) |  | **Optional.** Random positions | width, height, center |
-| [`dagre`](/en/docs/guides/layout-dagre) |  | Directed layers | rankdir: TB/BT/LR/RL, nodesep, ranksep, edgesep, nodeSize, ranker |
+| [`circular`](/en/docs/guides/layout-circular) |  | **External.** Circle or spiral | radius, startRadius, endRadius, startAngle, endAngle, clockwise |
+| [`concentric`](/en/docs/guides/layout-concentric) |  | **External.** Rings by importance | sortBy, maxLevelDiff, nodeSize, nodeSpacing, preventOverlap |
+| [`grid`](/en/docs/guides/layout-grid) |  | **External.** Rows and columns | rows, cols, begin, sortBy, nodeSize, nodeSpacing, preventOverlap |
+| [`random`](/en/docs/guides/layout-random) |  | **External.** Random positions | width, height, center |
+| [`dagre`](/en/docs/guides/layout-dagre) |  | **External.** Directed layers | rankdir: TB/BT/LR/RL, nodesep, ranksep, edgesep, nodeSize, ranker |
| [`force`](/en/docs/guides/layout-force) |  | Force-directed network | linkDistance, nodeStrength, edgeStrength, maxIteration, minMovement |
| [`d3-force`](/en/docs/guides/layout-d3-force) |  | D3 simulation | linkDistance, nodeStrength, alphaDecay, alphaMin; use nodeStrength, not charge |
| [`force-atlas2`](/en/docs/guides/layout-force-atlas2) |  | ForceAtlas2 network | kr, kg, barnesHut, prune, maxIteration |
| [`fruchterman`](/en/docs/guides/layout-fruchterman) |  | Fruchterman network | gravity, speed, maxIteration, minMovement |
-| [`radial`](/en/docs/guides/layout-radial) |  | **Optional.** Rings around a focus | focusNode, unitRadius, linkDistance, preventOverlap |
-| [`mds`](/en/docs/guides/layout-mds) |  | **Optional.** Positions from graph distances | linkDistance, center |
+| [`radial`](/en/docs/guides/layout-radial) |  | **External.** Rings around a focus | focusNode, unitRadius, linkDistance, preventOverlap |
+| [`mds`](/en/docs/guides/layout-mds) |  | **External.** Positions from graph distances | linkDistance, center |
@@ -48,7 +48,7 @@ Rendered node sizes are not automatically passed to algorithms. For overlap avoi
### Computation defaults [#computation-defaults]
-G6Lite injects or rewrites the following options; explicit values win. These rules apply to library layouts, not the three functional tree layouts.
+G6Lite injects or rewrites the following options; explicit values win. These rules apply to the library layouts above, including tree layout classes imported from `@antv/layout`.
| Algorithm / option | Default or rule |
| --- | --- |
@@ -74,7 +74,7 @@ Use **Layout** to compare Grid, Circular, and Dagre on the same data. The code s
Set parent-child relationships in `edges`, with the parent as `source` and the child as `target`. Compare mind map, indented, and fishbone layouts in the [tree layout example](/en/docs/guides/layout-trees#configuration-and-example).
-### Functional tree layouts [#functional-tree-layouts]
+### Tree layouts [#functional-tree-layouts]
Use a connected tree with one root and no cycles.
@@ -82,9 +82,9 @@ Use a connected tree with one root and no cycles.
| type | Preview | Purpose |
| --- | --- | --- |
-| [`mindmap`](/en/docs/guides/layout-mindmap) |  | **Optional.** Organize a hierarchy into branches |
-| [`indented`](/en/docs/guides/layout-indented) |  | **Optional.** Show a tree as a list |
-| [`fishbone`](/en/docs/guides/layout-fishbone) |  | **Optional.** Group categories and items along a spine |
+| [`mindmap`](/en/docs/guides/layout-mindmap) |  | **External.** Organize a hierarchy into branches |
+| [`indented`](/en/docs/guides/layout-indented) |  | **External.** Show a tree as a list |
+| [`fishbone`](/en/docs/guides/layout-fishbone) |  | **External.** Group categories and items along a spine |
@@ -98,7 +98,7 @@ Use a connected tree with one root and no cycles.
| `branchColors` | `string[]` | Built-in 10 colors; writes data._branchColor, which needs an explicit style function to affect colors |
| `getWidth` | `(node: GraphNode) => number` | Returns 100 |
| `getHeight` | `(node: GraphNode) => number` | Returns 40 |
-| `getSide` | `(node: GraphNode, index: number, parentSide?: 'left' \| 'right') => 'left' \| 'right'` | Returns right; node contains only id and data |
+| `getSide` | `(node: GraphNode, index: number, parentSide?: 'left' \| 'right') => 'left' \| 'right'` | Defaults to right. To access application data, look up the original node by ID. |
The first parentless input node becomes root; otherwise the first node does. Root position is (0, 0). Use levelGap/nodeGap; legacy hGap/vGap names are not supported.
@@ -136,7 +136,9 @@ For root → category → item structures. Deeper nodes do not receive a complet
For a graph that has completed render: setLayout replaces the entire configuration. Fit the graph after layout only when needed:
```ts
-graph.setLayout({ type: 'dagre', rankdir: 'LR', nodesep: 32, ranksep: 64 });
+import { DagreLayout } from '@antv/layout';
+
+graph.setLayout({ type: DagreLayout, rankdir: 'LR', nodesep: 32, ranksep: 64 });
await graph.layout();
graph.fitView({ padding: 48, maxZoom: 1 });
```
@@ -149,7 +151,7 @@ Layout may change existing x/y. Graph's fx/fy override the corresponding final a
## Worker
-Graph supplies worker: true when node count ≥ 1000 and worker is omitted, without filtering by algorithm name. Standalone runLayout has no automatic switch. Execution order is registered extension → built-in tree → Worker → main-thread library. Worker creation, cloning, or execution failures fall back to the same main-thread algorithm, which may block again.
+Graph attempts a G6Lite Worker for string-named built-in layouts when `worker` is omitted and the graph has 1,000 nodes or more. Registered extensions take precedence, and they manage their own execution, as do imported layout classes. Standalone `runLayout` requires an explicit Worker request. Worker creation, cloning, or execution failures fall back to the same main-thread algorithm.
Prefer explicit worker: false for function-valued options. See [layout methods](/en/docs/api/graph#layout) for cancellation. Successful configuration does not prove a Worker actually ran.
diff --git a/site/content/docs/en/metrics/bundle-size.mdx b/site/content/docs/en/metrics/bundle-size.mdx
index 25b95bf35..b7f01b9a5 100644
--- a/site/content/docs/en/metrics/bundle-size.mdx
+++ b/site/content/docs/en/metrics/bundle-size.mdx
@@ -5,7 +5,7 @@ description: See the consolidated performance results
This content has moved to [Performance comparison](/en/docs/metrics/performance#bundle-size).
--