Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ English | [简体中文](./README.zh-CN.md)
<p align="center">
<a href="https://www.npmjs.com/package/@antv/g6-lite/v/0.1.0"><img alt="npm version" src="https://img.shields.io/badge/version-0.1.0-blue"></a>
<a href="https://github.com/antvis/G6Lite/actions/workflows/build.yml"><img alt="build" src="https://github.com/antvis/G6Lite/actions/workflows/build.yml/badge.svg"></a>
<a href="https://bundlephobia.com/package/@antv/g6-lite@0.1.0"><img alt="0.1.0 npm entry, minified and gzipped: 91.5 kB" src="https://img.shields.io/badge/minzip-91.5_kB-blue"></a>
<a href="https://unpkg.com/@antv/g6-lite@0.1.0/dist/g6-lite.min.js"><img alt="UMD gzip size" src="https://img.badgesize.io/https://unpkg.com/@antv/g6-lite@0.1.0/dist/g6-lite.min.js?compression=gzip&amp;label=UMD%20gzip"></a>
<a href="https://unpkg.com/@antv/g6-lite/dist/g6-lite.min.js"><img alt="UMD gzip size" src="https://img.badgesize.io/https://unpkg.com/@antv/g6-lite/dist/g6-lite.min.js?compression=gzip&amp;label=UMD%20gzip"></a>
<a href="./LICENSE"><img alt="MIT license" src="https://img.shields.io/npm/l/@antv/g6-lite.svg"></a>
</p>

Expand Down Expand Up @@ -75,7 +74,7 @@ const graph = new Graph({
},
},
edge: { type: 'line', style: { lineWidth: 2 } },
layout: { type: 'circular', radius: 140 },
layout: { type: 'force', linkDistance: 120 },
behaviors: ['zoom-canvas', 'drag-canvas', 'drag-node', 'hover-highlight'],
});

Expand All @@ -86,7 +85,7 @@ Only package-root exports from `@antv/g6-lite` and `package.json#exports` are pu

## CDN / UMD

Use the UMD build directly in a browser without a bundler. It exposes `window.G6Lite` and includes the runtime dependencies and built-in layouts. See [Optional layouts](https://g6lite.antv.vision/en/docs/guides/layout-overview#optional-layouts) for additional layouts.
Use the UMD build in a browser to access `window.G6Lite`. This example uses the built-in `force` layout in `0.1.0`. See the [layout overview](https://g6lite.antv.vision/en/docs/guides/layout-overview) for layout options by version.

```html
<div id="container" style="width: 100%; height: 500px"></div>
Expand All @@ -101,17 +100,17 @@ Use the UMD build directly in a browser without a bundler. It exposes `window.G6
{ source: 'gateway', target: 'inventory' },
],
},
layout: { type: 'circular', radius: 140 },
layout: { type: 'force', linkDistance: 120 },
behaviors: ['zoom-canvas', 'drag-canvas', 'drag-node'],
});
graph.render().catch(console.error);
</script>
```

- [jsDelivr](https://cdn.jsdelivr.net/npm/@antv/g6-lite@0.1.0/dist/g6-lite.min.js)
- [UNPKG](https://unpkg.com/@antv/g6-lite@0.1.0/dist/g6-lite.min.js)
- [jsDelivr](https://cdn.jsdelivr.net/npm/@antv/g6-lite/dist/g6-lite.min.js)
- [UNPKG](https://unpkg.com/@antv/g6-lite/dist/g6-lite.min.js)

The minzip badge records Bundlephobia's measurement of the 0.1.0 npm entry (91,468 bytes gzip). The UMD badge measures the complete CDN download via UNPKG.
The UMD gzip badge measures the complete UMD file served by UNPKG.

## Learn More

Expand Down
15 changes: 7 additions & 8 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
<p align="center">
<a href="https://www.npmjs.com/package/@antv/g6-lite/v/0.1.0"><img alt="npm 版本" src="https://img.shields.io/badge/version-0.1.0-blue"></a>
<a href="https://github.com/antvis/G6Lite/actions/workflows/build.yml"><img alt="构建" src="https://github.com/antvis/G6Lite/actions/workflows/build.yml/badge.svg"></a>
<a href="https://bundlephobia.com/package/@antv/g6-lite@0.1.0"><img alt="0.1.0 npm 入口压缩后体积:91.5 kB" src="https://img.shields.io/badge/minzip-91.5_kB-blue"></a>
<a href="https://unpkg.com/@antv/g6-lite@0.1.0/dist/g6-lite.min.js"><img alt="UMD gzip 体积" src="https://img.badgesize.io/https://unpkg.com/@antv/g6-lite@0.1.0/dist/g6-lite.min.js?compression=gzip&amp;label=UMD%20gzip"></a>
<a href="https://unpkg.com/@antv/g6-lite/dist/g6-lite.min.js"><img alt="UMD gzip 体积" src="https://img.badgesize.io/https://unpkg.com/@antv/g6-lite/dist/g6-lite.min.js?compression=gzip&amp;label=UMD%20gzip"></a>
<a href="./LICENSE"><img alt="MIT 许可证" src="https://img.shields.io/npm/l/@antv/g6-lite.svg"></a>
</p>

Expand Down Expand Up @@ -75,7 +74,7 @@ const graph = new Graph({
},
},
edge: { type: 'line', style: { lineWidth: 2 } },
layout: { type: 'circular', radius: 140 },
layout: { type: 'force', linkDistance: 120 },
behaviors: ['zoom-canvas', 'drag-canvas', 'drag-node', 'hover-highlight'],
});

Expand All @@ -86,7 +85,7 @@ await graph.render();

## CDN / UMD

无需构建工具,在浏览器中直接加载 UMD 包即可使用 `window.G6Lite`。主脚本包含运行时依赖和内置布局。可选布局的接入方式见[布局总览](https://g6lite.antv.vision/docs/guides/layout-overview#optional-layouts)。
无需构建工具,在浏览器中直接加载 UMD 包即可使用 `window.G6Lite`。以下示例使用 `0.1.0` 中内置的 `force`。其他算法的接入方式随 G6Lite 版本变化,见[布局总览](https://g6lite.antv.vision/docs/guides/layout-overview)。

```html
<div id="container" style="width: 100%; height: 500px"></div>
Expand All @@ -101,17 +100,17 @@ await graph.render();
{ source: 'gateway', target: 'inventory' },
],
},
layout: { type: 'circular', radius: 140 },
layout: { type: 'force', linkDistance: 120 },
behaviors: ['zoom-canvas', 'drag-canvas', 'drag-node'],
});
graph.render().catch(console.error);
</script>
```

- [jsDelivr](https://cdn.jsdelivr.net/npm/@antv/g6-lite@0.1.0/dist/g6-lite.min.js)
- [UNPKG](https://unpkg.com/@antv/g6-lite@0.1.0/dist/g6-lite.min.js)
- [jsDelivr](https://cdn.jsdelivr.net/npm/@antv/g6-lite/dist/g6-lite.min.js)
- [UNPKG](https://unpkg.com/@antv/g6-lite/dist/g6-lite.min.js)

minzip 徽章记录 Bundlephobia 对 0.1.0 版本 npm 入口的测量值(gzip 后 91,468 字节);UMD 徽章通过 UNPKG 测量完整 CDN 文件的下载体积。
UMD gzip 徽章测量 UNPKG 提供的完整 UMD 文件体积。

## 继续阅读

Expand Down
26 changes: 1 addition & 25 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,6 @@
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.js"
},
"./layouts/mds": {
"types": "./dist/layouts/mds.d.ts",
"import": "./dist/layouts/mds.js"
},
"./layouts/radial": {
"types": "./dist/layouts/radial.d.ts",
"import": "./dist/layouts/radial.js"
},
"./layouts/indented": {
"types": "./dist/layouts/indented.d.ts",
"import": "./dist/layouts/indented.js"
},
"./layouts/mindmap": {
"types": "./dist/layouts/mindmap.d.ts",
"import": "./dist/layouts/mindmap.js"
},
"./layouts/fishbone": {
"types": "./dist/layouts/fishbone.d.ts",
"import": "./dist/layouts/fishbone.js"
},
"./layouts/random": {
"types": "./dist/layouts/random.d.ts",
"import": "./dist/layouts/random.js"
}
},
"files": [
Expand Down Expand Up @@ -97,7 +73,7 @@
},
"dependencies": {
"@antv/event-emitter": "^0.1.3",
"@antv/layout": "^2.0.0",
"@antv/layout": "^2.1.0",
"regl": "^2.1.1"
},
"engines": {
Expand Down
22 changes: 1 addition & 21 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,6 @@ const ts = () =>
},
});

const optionalLayouts = Object.fromEntries(
['mds', 'radial', 'indented', 'mindmap', 'fishbone', 'random'].map((type) => [
`layouts/${type}`,
`src/layout/optional/${type}.ts`,
]),
);

export default [
// npm 产物:ESM bundle + 独立 layout worker chunk。
{
Expand All @@ -34,7 +27,6 @@ export default [
// workerLayout.ts 以 `new URL('./layoutWorker.js', import.meta.url)` 引用
// worker,入口必须保持扁平文件名,落在 dist 根目录。
layoutWorker: 'src/layout/layoutWorker.ts',
...optionalLayouts,
},
external,
output: {
Expand All @@ -46,9 +38,8 @@ export default [
},
plugins: [ts()],
},
// Share declarations between the main entry and the optional layouts.
{
input: { index: 'src/index.ts', ...optionalLayouts },
input: 'src/index.ts',
external,
output: {
dir: 'dist',
Expand All @@ -71,15 +62,4 @@ export default [
},
plugins: [resolve({ browser: true, preferBuiltins: false }), commonjs(), ts()],
},
{
input: 'src/layout/optional/index.ts',
output: {
file: 'dist/g6-lite-layouts.min.js',
format: 'umd',
name: 'G6LiteLayouts',
sourcemap: true,
plugins: [terser()],
},
plugins: [resolve({ browser: true, preferBuiltins: false }), commonjs(), ts()],
},
];
13 changes: 8 additions & 5 deletions site/content/docs/en/api/graph.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -762,9 +762,9 @@ console.log(client, point);

### setLayout() [#setlayout]

`graph.setLayout(config: LayoutConfig): void`
`graph.setLayout(config: LayoutConfig | LayoutConstructor): void`

Replaces the layout configuration. To rearrange an existing graph with the new configuration, call [layout()](#graph-layout-layout).
Replaces the layout configuration. Pass a layout class directly, as in `graph.setLayout(CircularLayout)`, or set it as `config.type` alongside algorithm options. See [Built-in and external layouts](/en/docs/guides/layout-overview#builtin-and-external-layouts) for imports and version requirements. Call [layout()](#graph-layout-layout) to rearrange the graph.

### layout() [#graph-layout-layout]

Expand All @@ -775,7 +775,9 @@ After the first render, recalculates and updates node positions using the curren
<span id="graph-layout-code-and-rendered-result" style={{ display: 'block', scrollMarginTop: '8rem' }} />

```ts
graph.setLayout({ type: 'circular' });
import { CircularLayout } from '@antv/layout';

graph.setLayout({ type: CircularLayout });
await graph.layout();
graph.fitView();
```
Expand Down Expand Up @@ -824,14 +826,15 @@ declare function runLayout(

```ts
import { runLayout } from '@antv/g6-lite';
import { DagreLayout } from '@antv/layout';

const { nodes } = await runLayout(data, { type: 'dagre', rankdir: 'LR' });
const { nodes } = await runLayout(data, { type: DagreLayout, rankdir: 'LR' });
console.log(nodes);
```

<Callout type="warn" title="Standalone calculation boundaries">

Execution order follows the configuration reference: registered names, built-in functional trees, Worker, then library algorithm. With viewport, extension execute context width/height prefer viewport values; explicit config.width/height remain in context.options. Without viewport, context dimensions fall back to config or 800×600.
For a string name, G6Lite checks for a registered extension first. Built-in algorithms can use a G6Lite Worker and fall back to the main-thread algorithm. A layout class manages its own execution. With viewport, extension execute context width/height prefer viewport values; explicit config.width/height remain in context.options. Without viewport, context dimensions fall back to config or 800×600.

Standalone runLayout does not perform Graph's final fx/fy override, execute Graph transforms, or emit Graph layout events. Use results in your own renderer; use instance layout for Graph's writeback, state, and event sequence.

Expand Down
26 changes: 17 additions & 9 deletions site/content/docs/en/api/options.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { NodeDocExample } from '@/components/node-doc-example';
| `node` | Sets node shapes, appearance, state styles, labels, and decorations. | [`NodeConfig`](#options-node) | `circle` with theme and built-in styles |
| `edge` | Sets edge shapes, line styles, arrowheads, labels, and state styles. | [`EdgeConfig`](#options-edge) | `line` with theme and built-in styles |
| `combo` | Sets the appearance, labels, and collapsed shapes of all Combos. Define membership through `data.combos` and each node's `comboId`. | [`ComboConfig`](#options-combo) | Default Combo styles |
| `layout` | Sets the algorithm and parameters used to position nodes. | [`LayoutConfig`](#options-layout) | Existing `x` and `y`, with missing axes set to `0` |
| `layout` | Sets the algorithm and its parameters. Pass a layout class directly to use its defaults. | [`LayoutConfig`](#options-layout) or `LayoutConstructor` | Existing `x` and `y`, with missing axes set to `0` |
| `behaviors` | Configures interactions such as zoom, drag, and selection. An explicit array replaces the defaults. Pass `[]` to disable all behaviors. | [`BehaviorOption[]`](#options-behaviors) | `['zoom-canvas', 'drag-canvas']` |
| `transforms` | Enables custom transforms or parallel edge separation. | [`TransformOption[]`](#transforms) | — |
| `plugins` | Configures registered plugins to mount in the graph container. | [`PluginOption[]`](#plugins) | No plugins |
Expand Down Expand Up @@ -101,6 +101,7 @@ Use distinct IDs for nodes, edges, and Combos, and keep them stable across updat

```ts
import { Graph, type GraphNode } from '@antv/g6-lite';
import { CircularLayout } from '@antv/layout';

// Without a layout, x and y position each node.
const nodes: GraphNode[] = [
Expand All @@ -115,7 +116,7 @@ const graph = new Graph({
await graph.render();

// Enable circular layout and pass fx through setData() to fix A's x coordinate.
graph.setLayout({ type: 'circular' });
graph.setLayout({ type: CircularLayout });
await graph.setData({
nodes: [{ id: 'A', fx: 100 }, { id: 'B' }],
edges: [],
Expand Down Expand Up @@ -550,8 +551,8 @@ See the [Labels and icons guide](/en/docs/guides/label#global-label-policies) fo

| Property | Description | Type | Default |
| --- | --- | --- | --- |
| `type` | Required. A built-in or registered layout name, such as `'dagre'` or `'grid'`. Unknown names use random placement. Register optional layouts before use. | `string` | — |
| `worker` | Set to `false` to disable. See the [layout guide](/en/docs/guides/layout#worker) for execution order and fallback behavior. | `boolean` | Graph attempts to use a Worker by default at 1,000 nodes or more |
| `type` | Required. A built-in layout name (`'force'`, `'force-atlas2'`, `'d3-force'`, `'fruchterman'`), a registered layout name, or a layout class imported from `@antv/layout` (such as `DagreLayout`). Unknown names use random placement. | `string \| LayoutConstructor` | — |
| `worker` | Controls whether a string-named built-in layout attempts to use a G6Lite Worker. See the [layout guide](/en/docs/guides/layout#worker) for execution order and fallback. | `boolean` | Graph attempts a Worker at 1,000 nodes or more for string-named built-in layouts |
| `width` | Width used for layout computation. | `number` | Current canvas width |
| `height` | Height used for layout computation. | `number` | Current canvas height |
| `center` | Layout center. Each algorithm decides whether to use it. | `[number, number]` | `[width / 2, height / 2]` |
Expand All @@ -563,6 +564,8 @@ See the [Labels and icons guide](/en/docs/guides/label#global-label-policies) fo

The same tree can appear as a mind map, an indented list, or a fishbone diagram. Declare nodes in `nodes` and express each parent-to-child relationship as an edge from `source` to `target`. Use a connected tree with one root.

All three are external layouts. Import `MindmapLayout`, `IndentedLayout`, or `FishboneLayout` from `@antv/layout` and pass the class as `layout.type`; no registration is required.

<div className="effect-table">

| Layout | Preview | When to use it |
Expand All @@ -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,
Expand All @@ -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 } };
```

Expand All @@ -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 } };
```

Expand All @@ -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 |
| --- | --- | --- |
Expand Down
2 changes: 1 addition & 1 deletion site/content/docs/en/compatibility/g6-v5-migration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions site/content/docs/en/getting-started/quick-start.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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
<div id="container" style="width: 100%; height: 360px"></div>
Expand All @@ -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'],
});
Expand All @@ -212,7 +212,7 @@ The UMD script includes runtime dependencies and built-in layouts. Once loaded,
</script>
```
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.
Expand Down
Loading
Loading