Skip to content

Commit 93a1d0e

Browse files
hustcc逍为
andauthored
feat: add tree layouts and simplify public exports (#296)
* feat: add tree layouts and simplify public exports * chore: migrate tests to vitest and update docs * feat: add live layout demos to documentation --------- Co-authored-by: 逍为 <xiaowei.wzw@antgroup.com>
1 parent 2d0d554 commit 93a1d0e

267 files changed

Lines changed: 4428 additions & 1107 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.changeset/README.md‎

Lines changed: 0 additions & 8 deletions
This file was deleted.

‎.changeset/config.json‎

Lines changed: 0 additions & 11 deletions
This file was deleted.

‎.github/workflows/build.yml‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
name: build
22

3-
on: ["push", "pull_request"]
3+
on: ['push', 'pull_request']
44

55
jobs:
6-
ci:
6+
build:
77
runs-on: macos-latest
88
steps:
99
- uses: actions/checkout@v3
1010
- name: Install Node.js
1111
uses: actions/setup-node@v3
1212
with:
13-
node-version: 20
13+
node-version: 24
1414

1515
- name: Install Dependencies
1616
run: npm install
@@ -24,5 +24,5 @@ jobs:
2424
- name: Upload coverage reports to Codecov
2525
uses: codecov/codecov-action@v5
2626
with:
27-
token: ${{ secrets.CODECOV_TOKEN }}
28-
slug: antvis/layout
27+
token: ${{ secrets.CODECOV_TOKEN }}
28+
slug: antvis/layout

‎README.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ Basic layout algorithms for visualization
5353
| <img alt="Force" src="https://img.shields.io/badge/Force-2F54EB?style=flat-square"> [D3Force3D](https://layout.antv.vision/guide/api/force/d3-force-3d) | <img alt="D3Force3D" src="https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*4mbSTJLOXkgAAAAAAAAAAAAADmJ7AQ/original" width="240" /> | 3D force layout based on d3-force-3d with z-axis forces and z output. |
5454
| <img alt="Hierarchy" src="https://img.shields.io/badge/Hierarchy-722ED1?style=flat-square"> [Dagre](https://layout.antv.vision/guide/api/hierarchy/dagre) | <img alt="Dagre" src="https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*v5mBSopYr_wAAAAAAAAAAAAADmJ7AQ/original" width="240" /> | Layered directed layout for DAGs, workflows, and dependency graphs. |
5555
| <img alt="Hierarchy" src="https://img.shields.io/badge/Hierarchy-722ED1?style=flat-square"> [AntVDagre](https://layout.antv.vision/guide/api/hierarchy/antv-dagre) | <img alt="AntVDagre" src="https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*gQGOTYlN6BMAAAAAAAAAAAAADmJ7AQ/original" width="240" /> | Production-oriented hierarchical layout with spacing, alignment, and path info. |
56+
| <img alt="Hierarchy" src="https://img.shields.io/badge/Hierarchy-722ED1?style=flat-square"> [Fishbone](https://layout.antv.vision/guide/api/hierarchy/fishbone) | — | Arrange root, categories, and items in a fishbone diagram. |
57+
| <img alt="Hierarchy" src="https://img.shields.io/badge/Hierarchy-722ED1?style=flat-square"> [Indented](https://layout.antv.vision/guide/api/hierarchy/indented) | — | Display tree nodes in DFS order with depth-based indentation. |
58+
| <img alt="Hierarchy" src="https://img.shields.io/badge/Hierarchy-722ED1?style=flat-square"> [Mindmap](https://layout.antv.vision/guide/api/hierarchy/mindmap) | — | Arrange branches on one or both sides of a central root. |
5659
| <img alt="Radial" src="https://img.shields.io/badge/Radial-13C2C2?style=flat-square"> [Circular](https://layout.antv.vision/guide/api/radial/circular) | <img alt="Circular" src="https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*qJi5Q4qg6W8AAAAAAAAAAAAADmJ7AQ/original" width="240" /> | Place nodes on a circle (or spiral) with ordering, angle, and radius controls. |
5760
| <img alt="Radial" src="https://img.shields.io/badge/Radial-13C2C2?style=flat-square"> [Concentric](https://layout.antv.vision/guide/api/radial/concentric) | <img alt="Concentric" src="https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*KXunQKOLCSAAAAAAAAAAAAAADmJ7AQ/original" width="240" /> | Layer nodes by an importance score (default: degree), pulling higher scores inward. |
5861
| <img alt="Radial" src="https://img.shields.io/badge/Radial-13C2C2?style=flat-square"> [Radial](https://layout.antv.vision/guide/api/radial/radial) | <img alt="Radial" src="https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*vpXjTIFKy1QAAAAAAAAAAAAADmJ7AQ/original" width="240" /> | Focus-centered rings based on shortest-path distance for relationship exploration. |

‎__tests__/demos/antv-dagre.ts‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { AntVDagreLayout } from '@/src';
2+
import { parseSize } from '@/src/util';
23
import { Canvas } from '@antv/g';
34
import { Renderer } from '@antv/g-canvas';
45
import type { GUI } from 'lil-gui';
@@ -171,11 +172,12 @@ export function render(gui?: GUI) {
171172
});
172173

173174
dagre.forEachNode((node) => {
175+
const [nodeWidth, nodeHeight] = parseSize(node.size);
174176
renderer.updateNodeAttributes(node.id, {
175-
x: node.x - node.size[0] / 2,
176-
y: node.y - node.size[1] / 2,
177-
width: node.size[0],
178-
height: node.size[1],
177+
x: node.x - nodeWidth / 2,
178+
y: node.y - nodeHeight / 2,
179+
width: nodeWidth,
180+
height: nodeHeight,
179181
zIndex: node._original.isCombo ? 0 : 1,
180182
fillOpacity: node._original.isCombo ? 0.3 : 1,
181183
});

‎__tests__/demos/circular.ts‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
1-
import { CircularLayout } from '@/src';
1+
import { CircularLayout, type CircularLayoutOptions } from '@/src';
22
import type { GUI } from 'lil-gui';
33
import { radial as data } from '../dataset';
44
import { GraphRenderer } from '../utils/renderer';
55

6+
type CircularOrdering = NonNullable<CircularLayoutOptions['ordering']>;
7+
68
export function render(gui?: GUI) {
79
const renderer = new GraphRenderer();
810

911
const circular = new CircularLayout({
1012
center: [250, 250],
1113
radius: 200,
1214
nodeSize: 20,
13-
startAngle: Math.PI / 4,
14-
endAngle: Math.PI,
15-
divisions: 5,
16-
ordering: 'degree',
15+
startAngle: Math.PI / 4,
16+
endAngle: Math.PI,
17+
divisions: 5,
18+
ordering: 'degree',
1719
});
1820

1921
const relayout = async (options = {}) => {
@@ -39,7 +41,7 @@ export function render(gui?: GUI) {
3941
endAngle: 2 * Math.PI,
4042
clockwise: true,
4143
divisions: 1,
42-
ordering: 'original',
44+
ordering: 'original' as CircularOrdering,
4345
};
4446
folder.add(config, 'centerX', 0, 500).onChange((centerX: number) => {
4547
relayout({ ...config, center: [centerX, config.centerY] });
@@ -94,7 +96,7 @@ export function render(gui?: GUI) {
9496
'topology',
9597
'topology-directed',
9698
])
97-
.onChange((ordering) => {
99+
.onChange((ordering: CircularOrdering) => {
98100
relayout({ ...config, ordering });
99101
});
100102
}

‎__tests__/demos/combo-combined.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { ComboCombinedLayout } from '@/src';
2+
import { parseSize } from '@/src/util';
23
import { Canvas } from '@antv/g';
34
import { Renderer } from '@antv/g-canvas';
45
import type { GUI } from 'lil-gui';
@@ -12,7 +13,7 @@ data.combos.forEach((combo: any) => {
1213
isCombo: true,
1314
});
1415
});
15-
delete data.combos;
16+
Reflect.deleteProperty(data, 'combos');
1617
console.log('combo combined data:', data);
1718

1819
export function render(gui?: GUI) {
@@ -47,7 +48,7 @@ export function render(gui?: GUI) {
4748
renderer.updateNodeAttributes(node.id, {
4849
cx: node.x,
4950
cy: node.y,
50-
r: Math.max(...node.size) / 2,
51+
r: Math.max(...parseSize(node.size)) / 2,
5152
zIndex: node.isCombo ? 0 : 1,
5253
fillOpacity: node.isCombo ? 0.3 : 1,
5354
fill: node.isCombo ? '#91D5FF' : '#FFD666',

‎__tests__/demos/combo-combined2.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ data.combos.forEach((combo: any) => {
141141
isCombo: true,
142142
});
143143
});
144-
delete data.combos;
144+
Reflect.deleteProperty(data, 'combos');
145145
console.log('combo combined data:', data);
146146

147147
export function render(gui?: GUI) {

‎__tests__/demos/d3-force-3d.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { D3Force3DLayout } from '@/src';
2-
import { Layout } from '@/src/core/types';
2+
import type { Layout } from '@/src/algorithm/types';
33
import { Canvas } from '@antv/g';
44
import { Renderer } from '@antv/g-canvas';
55
import type { GUI } from 'lil-gui';

‎__tests__/demos/d3-force.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { D3ForceLayout } from '@/src';
2+
import type { NodeData } from '@/src/types';
23
import { Canvas } from '@antv/g';
34
import { Renderer } from '@antv/g-canvas';
45
import type { GUI } from 'lil-gui';
@@ -21,7 +22,7 @@ export async function render(gui?: GUI) {
2122
layout.execute(data, {
2223
width,
2324
height,
24-
nodeSize: (d) => d.size || 10,
25+
nodeSize: (d: NodeData) => d.size || 10,
2526
x: {},
2627
y: {},
2728
// linkDistance: 100,

0 commit comments

Comments
 (0)