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
8 changes: 0 additions & 8 deletions .changeset/README.md

This file was deleted.

11 changes: 0 additions & 11 deletions .changeset/config.json

This file was deleted.

10 changes: 5 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
name: build

on: ["push", "pull_request"]
on: ['push', 'pull_request']

jobs:
ci:
build:
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: 20
node-version: 24

- name: Install Dependencies
run: npm install
Expand All @@ -24,5 +24,5 @@ jobs:
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
slug: antvis/layout
token: ${{ secrets.CODECOV_TOKEN }}
slug: antvis/layout
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ Basic layout algorithms for visualization
| <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. |
| <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. |
| <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. |
| <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. |
| <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. |
| <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. |
| <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. |
| <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. |
| <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. |
Expand Down
10 changes: 6 additions & 4 deletions __tests__/demos/antv-dagre.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { AntVDagreLayout } from '@/src';
import { parseSize } from '@/src/util';
import { Canvas } from '@antv/g';
import { Renderer } from '@antv/g-canvas';
import type { GUI } from 'lil-gui';
Expand Down Expand Up @@ -171,11 +172,12 @@ export function render(gui?: GUI) {
});

dagre.forEachNode((node) => {
const [nodeWidth, nodeHeight] = parseSize(node.size);
renderer.updateNodeAttributes(node.id, {
x: node.x - node.size[0] / 2,
y: node.y - node.size[1] / 2,
width: node.size[0],
height: node.size[1],
x: node.x - nodeWidth / 2,
y: node.y - nodeHeight / 2,
width: nodeWidth,
height: nodeHeight,
zIndex: node._original.isCombo ? 0 : 1,
fillOpacity: node._original.isCombo ? 0.3 : 1,
});
Expand Down
16 changes: 9 additions & 7 deletions __tests__/demos/circular.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import { CircularLayout } from '@/src';
import { CircularLayout, type CircularLayoutOptions } from '@/src';
import type { GUI } from 'lil-gui';
import { radial as data } from '../dataset';
import { GraphRenderer } from '../utils/renderer';

type CircularOrdering = NonNullable<CircularLayoutOptions['ordering']>;

export function render(gui?: GUI) {
const renderer = new GraphRenderer();

const circular = new CircularLayout({
center: [250, 250],
radius: 200,
nodeSize: 20,
startAngle: Math.PI / 4,
endAngle: Math.PI,
divisions: 5,
ordering: 'degree',
startAngle: Math.PI / 4,
endAngle: Math.PI,
divisions: 5,
ordering: 'degree',
});

const relayout = async (options = {}) => {
Expand All @@ -39,7 +41,7 @@ export function render(gui?: GUI) {
endAngle: 2 * Math.PI,
clockwise: true,
divisions: 1,
ordering: 'original',
ordering: 'original' as CircularOrdering,
};
folder.add(config, 'centerX', 0, 500).onChange((centerX: number) => {
relayout({ ...config, center: [centerX, config.centerY] });
Expand Down Expand Up @@ -94,7 +96,7 @@ export function render(gui?: GUI) {
'topology',
'topology-directed',
])
.onChange((ordering) => {
.onChange((ordering: CircularOrdering) => {
relayout({ ...config, ordering });
});
}
Expand Down
5 changes: 3 additions & 2 deletions __tests__/demos/combo-combined.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ComboCombinedLayout } from '@/src';
import { parseSize } from '@/src/util';
import { Canvas } from '@antv/g';
import { Renderer } from '@antv/g-canvas';
import type { GUI } from 'lil-gui';
Expand All @@ -12,7 +13,7 @@ data.combos.forEach((combo: any) => {
isCombo: true,
});
});
delete data.combos;
Reflect.deleteProperty(data, 'combos');
console.log('combo combined data:', data);

export function render(gui?: GUI) {
Expand Down Expand Up @@ -47,7 +48,7 @@ export function render(gui?: GUI) {
renderer.updateNodeAttributes(node.id, {
cx: node.x,
cy: node.y,
r: Math.max(...node.size) / 2,
r: Math.max(...parseSize(node.size)) / 2,
zIndex: node.isCombo ? 0 : 1,
fillOpacity: node.isCombo ? 0.3 : 1,
fill: node.isCombo ? '#91D5FF' : '#FFD666',
Expand Down
2 changes: 1 addition & 1 deletion __tests__/demos/combo-combined2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ data.combos.forEach((combo: any) => {
isCombo: true,
});
});
delete data.combos;
Reflect.deleteProperty(data, 'combos');
console.log('combo combined data:', data);

export function render(gui?: GUI) {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/demos/d3-force-3d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { D3Force3DLayout } from '@/src';
import { Layout } from '@/src/core/types';
import type { Layout } from '@/src/algorithm/types';
import { Canvas } from '@antv/g';
import { Renderer } from '@antv/g-canvas';
import type { GUI } from 'lil-gui';
Expand Down
3 changes: 2 additions & 1 deletion __tests__/demos/d3-force.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { D3ForceLayout } from '@/src';
import type { NodeData } from '@/src/types';
import { Canvas } from '@antv/g';
import { Renderer } from '@antv/g-canvas';
import type { GUI } from 'lil-gui';
Expand All @@ -21,7 +22,7 @@ export async function render(gui?: GUI) {
layout.execute(data, {
width,
height,
nodeSize: (d) => d.size || 10,
nodeSize: (d: NodeData) => d.size || 10,
x: {},
y: {},
// linkDistance: 100,
Expand Down
10 changes: 6 additions & 4 deletions __tests__/demos/dagre.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { DagreLayout } from '@/src';
import { parseSize } from '@/src/util';
import { Canvas } from '@antv/g';
import { Renderer } from '@antv/g-canvas';
import type { GUI } from 'lil-gui';
Expand Down Expand Up @@ -58,11 +59,12 @@ export function render(gui?: GUI) {
});

dagre.forEachNode((node) => {
const [nodeWidth, nodeHeight] = parseSize(node.size);
renderer.updateNodeAttributes(node.id, {
x: node.x - node.size[0] / 2,
y: node.y - node.size[1] / 2,
width: node.size[0],
height: node.size[1],
x: node.x - nodeWidth / 2,
y: node.y - nodeHeight / 2,
width: nodeWidth,
height: nodeHeight,
zIndex: node._original.isCombo ? 0 : 1,
fillOpacity: node._original.isCombo ? 0.3 : 1,
});
Expand Down
2 changes: 0 additions & 2 deletions __tests__/demos/force-atlas2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ export async function render(gui?: GUI) {
// },
// });

console.log('Total ticks:', tickCount2);

renderer.setDragCallbacks({
onDragStart: (nodeId, position) => {
console.log(`🎯 Start dragging node: ${nodeId}`);
Expand Down
6 changes: 3 additions & 3 deletions __tests__/demos/force.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,17 @@ export async function render(gui?: GUI) {
renderer.setDragCallbacks({
onDragStart: (nodeId, position) => {
console.log(`🎯 Start dragging node: ${nodeId}`);
layout.setFixedPosition(nodeId, [position.x, position.y]);
layout.setFixedPosition(String(nodeId), [position.x, position.y]);
},

onDrag: (nodeId, position) => {
console.log(`🚚 Dragging node: ${position}`);
layout.setFixedPosition(nodeId, [position.x, position.y]);
layout.setFixedPosition(String(nodeId), [position.x, position.y]);
layout.tick(10);
},

onDragEnd: (nodeId) => {
layout.setFixedPosition(nodeId, null);
layout.setFixedPosition(String(nodeId), null);
},
});

Expand Down
12 changes: 6 additions & 6 deletions __tests__/demos/grid.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GridLayout } from '@/src';
import { GridLayout, type GridLayoutOptions } from '@/src';
import type { GUI } from 'lil-gui';
import { GraphRenderer } from '../utils/renderer';

Expand All @@ -14,11 +14,11 @@ export function render(gui?: GUI) {
preventOverlap: true,
preventOverlapPadding: 10,
condense: false,
rows: undefined,
cols: undefined,
sortBy: 'degree',
rows: undefined as number | undefined,
cols: undefined as number | undefined,
sortBy: 'degree' as 'degree' | 'id',
nodeSize: 30,
nodeSpacing: undefined,
nodeSpacing: undefined as number | undefined,
};

let options = { ...defaultOptions };
Expand All @@ -38,7 +38,7 @@ export function render(gui?: GUI) {
});

const relayout = async () => {
const _options = {
const _options: Partial<GridLayoutOptions> = {
width: options.width,
height: options.height,
begin: [options.beginX, options.beginY],
Expand Down
2 changes: 1 addition & 1 deletion __tests__/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as lil from 'lil-gui';
import * as demos from './demos';

// GUI
const $container = document.getElementById('container');
const $container = document.getElementById('container')!;
let gui = new lil.GUI({ autoPlace: false });
$container.appendChild(gui.domElement);

Expand Down
2 changes: 1 addition & 1 deletion __tests__/setup.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import 'jest-canvas-mock';
import 'vitest-canvas-mock';
import './utils/use-snapshot-matchers';
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion __tests__/snapshots/circular/custom-center.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion __tests__/snapshots/circular/default.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion __tests__/snapshots/circular/divisions-5.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion __tests__/snapshots/circular/endRadius-only.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion __tests__/snapshots/circular/nodeSize-nodeSpacing-fn.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion __tests__/snapshots/circular/ordering-degree.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion __tests__/snapshots/circular/ordering-original.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion __tests__/snapshots/circular/ordering-topology.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion __tests__/snapshots/circular/radius-180.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading