From 76d7cc3d48aba44d59bdabb13f1351b115cefd2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=80=8D=E4=B8=BA?= Date: Thu, 26 Nov 2026 16:36:36 +0800 Subject: [PATCH 1/3] feat: add tree layouts and simplify public exports --- __tests__/unit/antv-dagre/acyclic.test.ts | 2 +- __tests__/unit/antv-dagre/layout.test.ts | 3 +- __tests__/unit/dagre.test.ts | 3 +- __tests__/unit/fishbone.test.ts | 51 +++++ __tests__/unit/grid.test.ts | 3 +- __tests__/unit/indented.test.ts | 49 +++++ __tests__/unit/mindmap.test.ts | 80 ++++++++ src/algorithm/fishbone/index.ts | 161 +++++++++++++++ src/algorithm/fishbone/types.ts | 19 ++ src/algorithm/indented/index.ts | 111 ++++++++++ src/algorithm/indented/types.ts | 16 ++ src/algorithm/index.ts | 3 + src/algorithm/mindmap/index.ts | 234 ++++++++++++++++++++++ src/algorithm/mindmap/types.ts | 19 ++ src/index.ts | 43 +++- 15 files changed, 787 insertions(+), 10 deletions(-) create mode 100644 __tests__/unit/fishbone.test.ts create mode 100644 __tests__/unit/indented.test.ts create mode 100644 __tests__/unit/mindmap.test.ts create mode 100644 src/algorithm/fishbone/index.ts create mode 100644 src/algorithm/fishbone/types.ts create mode 100644 src/algorithm/indented/index.ts create mode 100644 src/algorithm/indented/types.ts create mode 100644 src/algorithm/mindmap/index.ts create mode 100644 src/algorithm/mindmap/types.ts diff --git a/__tests__/unit/antv-dagre/acyclic.test.ts b/__tests__/unit/antv-dagre/acyclic.test.ts index dc7d180f..657efe76 100644 --- a/__tests__/unit/antv-dagre/acyclic.test.ts +++ b/__tests__/unit/antv-dagre/acyclic.test.ts @@ -1,5 +1,5 @@ -import { EdgeData } from '@/src'; import { run, undo } from '@/src/algorithm/antv-dagre/acyclic'; +import type { EdgeData } from '@/src/types'; import { DagreGraph as Graph } from '@/src/algorithm/antv-dagre/graph'; import { findCycles } from '../../utils'; diff --git a/__tests__/unit/antv-dagre/layout.test.ts b/__tests__/unit/antv-dagre/layout.test.ts index 0556dd62..b09bf372 100644 --- a/__tests__/unit/antv-dagre/layout.test.ts +++ b/__tests__/unit/antv-dagre/layout.test.ts @@ -1,4 +1,5 @@ -import { DagreRankdir, PointObject } from '@/src'; +import type { DagreRankdir } from '@/src/algorithm/antv-dagre/types'; +import type { PointObject } from '@/src/types'; import { DagreGraph as Graph } from '@/src/algorithm/antv-dagre/graph'; import { layout } from '@/src/algorithm/antv-dagre/layout'; import type { ID } from '@/src/types/id'; diff --git a/__tests__/unit/dagre.test.ts b/__tests__/unit/dagre.test.ts index c8178af6..76071895 100644 --- a/__tests__/unit/dagre.test.ts +++ b/__tests__/unit/dagre.test.ts @@ -1,4 +1,5 @@ -import { DagreLayout, Point } from '@/src'; +import { DagreLayout } from '@/src'; +import type { Point } from '@/src/types'; import { createCanvas } from '@@/utils/create'; import type { Canvas } from '@antv/g'; import { clear as clearMockRandom, mock as mockRandom } from 'jest-random-mock'; diff --git a/__tests__/unit/fishbone.test.ts b/__tests__/unit/fishbone.test.ts new file mode 100644 index 00000000..9a47081d --- /dev/null +++ b/__tests__/unit/fishbone.test.ts @@ -0,0 +1,51 @@ +import { FishboneLayout } from '@/src/algorithm/fishbone'; + +const createData = () => ({ + nodes: [ + { id: 'root' }, + { id: 'category-1' }, + { id: 'category-2' }, + { id: 'item-1' }, + { id: 'item-2' }, + ], + edges: [ + { source: 'root', target: 'category-1' }, + { source: 'root', target: 'category-2' }, + { source: 'category-1', target: 'item-1' }, + { source: 'category-2', target: 'item-2' }, + ], +}); + +async function getPositions(direction?: 'LR' | 'RL') { + const layout = new FishboneLayout({ direction }); + await layout.execute(createData()); + + const positions: Record = {}; + layout.forEachNode((node) => { + positions[node.id] = { x: node.x, y: node.y }; + }); + return positions; +} + +describe('layout fishbone', () => { + it('should layout categories and items in LR direction', async () => { + await expect(getPositions()).resolves.toEqual({ + root: { x: 620, y: 280 }, + 'category-1': { x: 110, y: 80 }, + 'category-2': { x: 290, y: 480 }, + 'item-1': { x: 150, y: 180 }, + 'item-2': { x: 330, y: 380 }, + }); + }); + + it('should mirror x coordinates in RL direction', async () => { + const [lr, rl] = await Promise.all([ + getPositions('LR'), + getPositions('RL'), + ]); + + Object.entries(lr).forEach(([id, position]) => { + expect(rl[id]).toEqual({ x: 660 - position.x, y: position.y }); + }); + }); +}); diff --git a/__tests__/unit/grid.test.ts b/__tests__/unit/grid.test.ts index 418c617d..bd6ea62b 100644 --- a/__tests__/unit/grid.test.ts +++ b/__tests__/unit/grid.test.ts @@ -1,4 +1,5 @@ -import { GridLayout, type NodeData } from '@/src'; +import { GridLayout } from '@/src'; +import type { NodeData } from '@/src/types'; import { createCanvas } from '@@/utils/create'; import type { Canvas } from '@antv/g'; import { deepMix } from '@antv/util'; diff --git a/__tests__/unit/indented.test.ts b/__tests__/unit/indented.test.ts new file mode 100644 index 00000000..a41ddeea --- /dev/null +++ b/__tests__/unit/indented.test.ts @@ -0,0 +1,49 @@ +import { IndentedLayout } from '@/src/algorithm/indented'; +import type { GraphData } from '@/src/types'; + +describe('layout indented', () => { + it('should layout DFS rows with depth metadata', async () => { + const data: GraphData = { + nodes: [ + { id: 'root', data: {} }, + { id: 'a', data: {} }, + { id: 'a-1', data: {} }, + { id: 'b', data: {} }, + { id: 'b-1', data: {} }, + ], + edges: [ + { source: 'root', target: 'a' }, + { source: 'a', target: 'a-1' }, + { source: 'root', target: 'b' }, + { source: 'b', target: 'b-1' }, + ], + }; + const layout = new IndentedLayout({ + rootId: 'root', + direction: 'RL', + indent: 100, + rowHeight: 50, + }); + + await layout.execute(data); + + const positions: Record = {}; + layout.forEachNode((node) => { + positions[node.id] = { x: node.x === 0 ? 0 : node.x, y: node.y }; + }); + expect(positions).toEqual({ + root: { x: 0, y: 0 }, + a: { x: -100, y: 50 }, + 'a-1': { x: -200, y: 100 }, + b: { x: -100, y: 150 }, + 'b-1': { x: -200, y: 200 }, + }); + expect(data.nodes.map((node) => [node.id, node.data?.depth, node.data?._isRoot])).toEqual([ + ['root', 0, true], + ['a', 1, false], + ['a-1', 2, false], + ['b', 1, false], + ['b-1', 2, false], + ]); + }); +}); diff --git a/__tests__/unit/mindmap.test.ts b/__tests__/unit/mindmap.test.ts new file mode 100644 index 00000000..35629a04 --- /dev/null +++ b/__tests__/unit/mindmap.test.ts @@ -0,0 +1,80 @@ +import { MindmapLayout } from '@/src/algorithm/mindmap'; +import type { GraphData } from '@/src/types'; + +const createData = (): GraphData => ({ + nodes: [ + { id: 'root', data: {} }, + { id: 'left', data: {} }, + { id: 'right', data: {} }, + { id: 'left-leaf', data: {} }, + { id: 'right-leaf', data: {} }, + ], + edges: [ + { source: 'root', target: 'left' }, + { source: 'root', target: 'right' }, + { source: 'left', target: 'left-leaf' }, + { source: 'right', target: 'right-leaf' }, + ], +}); + +function getPositions(layout: MindmapLayout) { + const positions: Record = {}; + layout.forEachNode((node) => { + positions[node.id] = { x: node.x, y: node.y }; + }); + return positions; +} + +describe('layout mindmap', () => { + it('should assign sides and inherit branch colors', async () => { + const data = createData(); + const layout = new MindmapLayout({ + branchColors: ['red', 'blue'], + getSide: (_node, index, parentSide) => + parentSide ?? (index === 0 ? 'left' : 'right'), + }); + + await layout.execute(data); + + expect(getPositions(layout)).toEqual({ + root: { x: 0, y: 0 }, + left: { x: -220, y: 0 }, + right: { x: 220, y: 0 }, + 'left-leaf': { x: -440, y: 0 }, + 'right-leaf': { x: 440, y: 0 }, + }); + expect(data.nodes.map((node) => [node.id, node.data?._branchColor])).toEqual([ + ['root', undefined], + ['left', 'red'], + ['right', 'blue'], + ['left-leaf', 'red'], + ['right-leaf', 'blue'], + ]); + }); + + it('should respect node sizes and gaps in LR and RL directions', async () => { + for (const direction of ['LR', 'RL'] as const) { + const layout = new MindmapLayout({ + direction, + levelGap: 100, + nodeGap: 10, + getWidth: (node) => (node.id === 'root' ? 80 : 40), + getHeight: (node) => (node.id === 'root' ? 60 : 20), + }); + await layout.execute({ + nodes: [{ id: 'root' }, { id: 'a' }, { id: 'b' }], + edges: [ + { source: 'root', target: 'a' }, + { source: 'root', target: 'b' }, + ], + }); + + const sign = direction === 'LR' ? 1 : -1; + expect(getPositions(layout)).toEqual({ + root: { x: 0, y: 0 }, + a: { x: sign * 160, y: -15 }, + b: { x: sign * 160, y: 15 }, + }); + } + }); +}); diff --git a/src/algorithm/fishbone/index.ts b/src/algorithm/fishbone/index.ts new file mode 100644 index 00000000..fb98003e --- /dev/null +++ b/src/algorithm/fishbone/index.ts @@ -0,0 +1,161 @@ +import type { GraphNode } from '../../types'; +import { BaseLayout } from '../base-layout'; +import type { FishboneLayoutOptions } from './types'; + +export type { FishboneLayoutOptions }; + +interface TreeNode { + id: string; + children: TreeNode[]; + x: number; + y: number; + width: number; + height: number; + original: GraphNode; +} + +/** + * 鱼骨图布局:根 → 分类 → 条目的三层结构。 + * + * Fishbone layout (Ishikawa diagram): head -> categories -> items. + */ +export class FishboneLayout extends BaseLayout { + id = 'fishbone'; + + protected getDefaultOptions(): Partial { + return { + direction: 'LR', + categoryGap: 180, + itemHStep: 20, + categoryDistance: 200, + getWidth: () => 80, + getHeight: () => 30, + }; + } + + protected async layout(): Promise { + const { + direction = 'LR', + categoryGap = 180, + itemHStep = 20, + categoryDistance = 200, + getWidth = () => 80, + getHeight = () => 30, + } = this.options; + + const nodeMap = new Map(); + const childrenMap = new Map(); + const hasParent = new Set(); + + this.model.forEachNode((node) => { + const id = String(node.id); + nodeMap.set(id, { + id, + children: [], + x: 0, + y: 0, + width: getWidth(node), + height: getHeight(node), + original: node, + }); + }); + + this.model.forEachEdge((edge) => { + const source = String(edge.source); + const target = String(edge.target); + if (!nodeMap.has(source) || !nodeMap.has(target)) return; + const childIds = childrenMap.get(source) ?? []; + childIds.push(target); + childrenMap.set(source, childIds); + hasParent.add(target); + }); + + let rootId: string | undefined; + this.model.forEachNode((node) => { + if (rootId === undefined && !hasParent.has(String(node.id))) rootId = String(node.id); + }); + const root = rootId ? nodeMap.get(rootId) : undefined; + if (!root) return; + + const visited = new Set([root.id]); + const stack: Array<{ node: TreeNode; childIndex: number }> = [{ node: root, childIndex: 0 }]; + + while (stack.length > 0) { + const frame = stack[stack.length - 1]; + const childIds = childrenMap.get(frame.node.id) ?? []; + if (frame.childIndex >= childIds.length) { + stack.pop(); + continue; + } + + const childId = childIds[frame.childIndex]; + frame.childIndex += 1; + const child = nodeMap.get(childId); + if (!child || visited.has(childId)) continue; + + visited.add(childId); + frame.node.children.push(child); + stack.push({ node: child, childIndex: 0 }); + } + + const categories = root.children; + const categoryCount = categories.length; + + if (categoryCount === 0) { + root.x = 450; + root.y = 300; + } else { + const centerY = categoryDistance + 80; + const leftMargin = categoryDistance + 20; + const spineLength = categoryCount * categoryGap; + + root.x = leftMargin + spineLength + root.width / 2; + root.y = centerY; + + for (let index = 0; index < categoryCount; index += 1) { + const category = categories[index]; + const verticalDirection = index % 2 === 0 ? -1 : 1; + const spineX = leftMargin + (index + 0.5) * categoryGap; + + category.x = spineX - categoryDistance; + category.y = centerY + verticalDirection * categoryDistance; + + const itemCount = category.children.length; + for (let itemIndex = 0; itemIndex < itemCount; itemIndex += 1) { + const item = category.children[itemIndex]; + const ratio = (itemIndex + 1) / (itemCount + 1); + const yOffset = ratio * categoryDistance; + const meetX = category.x + yOffset; + item.x = meetX - itemHStep - item.width / 2; + item.y = category.y - verticalDirection * yOffset; + } + } + + if (direction === 'RL') { + const totalWidth = leftMargin + spineLength + root.width; + const pending = [root]; + while (pending.length > 0) { + const node = pending.pop(); + if (!node) break; + node.x = totalWidth - node.x; + pending.push(...node.children); + } + } + } + + const applyResult = (node: TreeNode): void => { + node.original.x = node.x; + node.original.y = node.y; + node.children.forEach(applyResult); + }; + + applyResult(root); + + this.model.forEachNode((node) => { + if (!visited.has(String(node.id))) { + node.x = 0; + node.y = 0; + } + }); + } +} diff --git a/src/algorithm/fishbone/types.ts b/src/algorithm/fishbone/types.ts new file mode 100644 index 00000000..b2ce8e13 --- /dev/null +++ b/src/algorithm/fishbone/types.ts @@ -0,0 +1,19 @@ +import type { BaseLayoutOptions } from '../types'; +import type { GraphNode } from '../../types'; + +export interface FishboneLayoutOptions extends BaseLayoutOptions { + /** Layout direction. Defaults to 'LR'. */ + direction?: 'LR' | 'RL'; + /** Gap between categories along the spine. Defaults to 180. */ + categoryGap?: number; + /** Declared for compatibility; currently not used by the layout. */ + itemGap?: number; + /** Extra horizontal offset for items. Defaults to 20. */ + itemHStep?: number; + /** Distance between category and spine. Defaults to 200. */ + categoryDistance?: number; + /** Node width callback. Defaults to 80. */ + getWidth?: (node: GraphNode) => number; + /** Node height callback. Defaults to 30. */ + getHeight?: (node: GraphNode) => number; +} diff --git a/src/algorithm/indented/index.ts b/src/algorithm/indented/index.ts new file mode 100644 index 00000000..97d92c9b --- /dev/null +++ b/src/algorithm/indented/index.ts @@ -0,0 +1,111 @@ +import { BaseLayout } from '../base-layout'; +import type { IndentedLayoutOptions } from './types'; + +export type { IndentedLayoutOptions }; + +const DEFAULT_PALETTE = [ + '#1783FF', + '#00C9C9', + '#F08F56', + '#D580FF', + '#7863FF', + '#DB9D0D', + '#60C42D', + '#FF80CA', + '#2491B3', + '#17C76F', +]; + +/** + * 缩进树布局:x 由深度决定,y 由 DFS 遍历顺序决定。 + * + * Indented tree layout: x is determined by depth, y by DFS order. + */ +export class IndentedLayout extends BaseLayout { + id = 'indented'; + + protected getDefaultOptions(): Partial { + return { + indent: 80, + rowHeight: 40, + direction: 'LR', + }; + } + + protected async layout(): Promise { + const { indent = 80, rowHeight = 40, direction = 'LR', rootId, nodeColors, edgeColors } = + this.options; + const children = new Map(); + const hasParent = new Set(); + const nodeIds = new Set(); + + this.model.forEachNode((node) => nodeIds.add(String(node.id))); + this.model.forEachEdge((edge) => { + const source = String(edge.source); + const target = String(edge.target); + if (!nodeIds.has(source) || !nodeIds.has(target)) return; + const childIds = children.get(source) ?? []; + childIds.push(target); + children.set(source, childIds); + hasParent.add(target); + }); + + let root = rootId; + if (!root) { + this.model.forEachNode((node) => { + if (root === undefined && !hasParent.has(String(node.id))) root = String(node.id); + }); + } + if (root === undefined) { + this.model.forEachNode((node) => { + if (root === undefined) root = String(node.id); + }); + } + if (root === undefined) return; + + const nPalette = nodeColors ?? (nodeColors === undefined ? undefined : DEFAULT_PALETTE); + const ePalette = edgeColors ?? (edgeColors === undefined ? undefined : DEFAULT_PALETTE); + const positions = new Map(); + const visited = new Set(); + const stack: Array<{ id: string; depth: number }> = [{ id: root, depth: 0 }]; + let rowIndex = 0; + + while (stack.length > 0) { + const current = stack.pop(); + if (!current) break; + if (!nodeIds.has(current.id) || visited.has(current.id)) continue; + visited.add(current.id); + + const x = direction === 'LR' ? current.depth * indent : -(current.depth * indent); + const y = rowIndex * rowHeight; + rowIndex += 1; + positions.set(current.id, { x, y, depth: current.depth }); + + const childIds = children.get(current.id) ?? []; + for (let index = childIds.length - 1; index >= 0; index -= 1) { + stack.push({ id: childIds[index], depth: current.depth + 1 }); + } + } + + this.model.forEachNode((node) => { + const position = positions.get(String(node.id)); + if (!position) { + node.x = 0; + node.y = 0; + return; + } + + node.x = position.x; + node.y = position.y; + const original = node._original as Record; + original.data = { + ...(original.data as Record | undefined), + depth: position.depth, + _isRoot: position.depth === 0, + }; + const data = original.data as Record; + if (nPalette) data._nodeColor = nPalette[position.depth % nPalette.length]; + if (ePalette) data._edgeColor = ePalette[position.depth % ePalette.length]; + }); + } +} diff --git a/src/algorithm/indented/types.ts b/src/algorithm/indented/types.ts new file mode 100644 index 00000000..cfa817b4 --- /dev/null +++ b/src/algorithm/indented/types.ts @@ -0,0 +1,16 @@ +import type { BaseLayoutOptions } from '../types'; + +export interface IndentedLayoutOptions extends BaseLayoutOptions { + /** Horizontal offset per depth. Defaults to 80. */ + indent?: number; + /** Vertical gap between DFS rows. Defaults to 40. */ + rowHeight?: number; + /** Layout direction. Defaults to 'LR'. */ + direction?: 'LR' | 'RL'; + /** Explicit root node id. */ + rootId?: string; + /** Palette written to data._nodeColor by depth. */ + nodeColors?: string[]; + /** Palette written to data._edgeColor by depth. */ + edgeColors?: string[]; +} diff --git a/src/algorithm/index.ts b/src/algorithm/index.ts index e18bc2a5..a176e598 100644 --- a/src/algorithm/index.ts +++ b/src/algorithm/index.ts @@ -23,6 +23,9 @@ export { type FruchtermanLayoutOptions, } from './fruchterman'; export { GridLayout, type GridLayoutOptions } from './grid'; +export { IndentedLayout, type IndentedLayoutOptions } from './indented'; +export { MindmapLayout, type MindmapLayoutOptions } from './mindmap'; +export { FishboneLayout, type FishboneLayoutOptions } from './fishbone'; export { MDSLayout, type MDSLayoutOptions } from './mds'; export { RadialLayout, type RadialLayoutOptions } from './radial'; export { RandomLayout, type RandomLayoutOptions } from './random'; diff --git a/src/algorithm/mindmap/index.ts b/src/algorithm/mindmap/index.ts new file mode 100644 index 00000000..52524402 --- /dev/null +++ b/src/algorithm/mindmap/index.ts @@ -0,0 +1,234 @@ +import type { GraphNode } from '../../types'; +import { BaseLayout } from '../base-layout'; +import type { MindmapLayoutOptions } from './types'; + +export type { MindmapLayoutOptions }; + +const DEFAULT_PALETTE = [ + '#1783FF', + '#00C9C9', + '#F08F56', + '#D580FF', + '#7863FF', + '#DB9D0D', + '#60C42D', + '#FF80CA', + '#2491B3', + '#17C76F', +]; + +interface TreeNode { + id: string; + data?: Record; + children: TreeNode[]; + x: number; + y: number; + width: number; + height: number; + side?: 'left' | 'right'; + depth: number; + original: GraphNode; +} + +/** + * 脑图布局:根节点居中,子树向左右两侧展开。 + * + * Mind map layout: root at center, children expand to left/right. + */ +export class MindmapLayout extends BaseLayout { + id = 'mindmap'; + + protected getDefaultOptions(): Partial { + return { + direction: 'H', + levelGap: 120, + nodeGap: 30, + branchColors: DEFAULT_PALETTE, + getWidth: () => 100, + getHeight: () => 40, + getSide: () => 'right', + }; + } + + protected async layout(): Promise { + const { + direction = 'H', + levelGap = 120, + nodeGap = 30, + branchColors = DEFAULT_PALETTE, + getWidth = () => 100, + getHeight = () => 40, + getSide = () => 'right', + } = this.options; + + const nodeMap = new Map(); + const childrenMap = new Map(); + const hasParent = new Set(); + + this.model.forEachNode((node) => { + const id = String(node.id); + if (nodeMap.has(id)) return; + nodeMap.set(id, { + id, + data: (node._original as Record).data as Record | undefined, + children: [], + x: 0, + y: 0, + width: 0, + height: 0, + depth: 0, + original: node, + }); + }); + + this.model.forEachEdge((edge) => { + const source = String(edge.source); + const target = String(edge.target); + if (source === target || !nodeMap.has(source) || !nodeMap.has(target)) return; + if (hasParent.has(target)) return; + const children = childrenMap.get(source) ?? []; + if (children.includes(target)) return; + children.push(target); + childrenMap.set(source, children); + hasParent.add(target); + }); + + let rootId: string | undefined; + this.model.forEachNode((node) => { + if (rootId === undefined && !hasParent.has(String(node.id))) rootId = String(node.id); + }); + if (rootId === undefined) { + this.model.forEachNode((node) => { + if (rootId === undefined) rootId = String(node.id); + }); + } + const rootNode = rootId ? nodeMap.get(rootId) : undefined; + if (!rootNode) return; + + const visited = new Set(); + const visiting = new Set(); + + const buildChildren = (node: TreeNode, depth: number): void => { + if (visiting.has(node.id) || visited.has(node.id)) return; + visiting.add(node.id); + visited.add(node.id); + node.depth = depth; + + for (const childId of childrenMap.get(node.id) ?? []) { + if (visiting.has(childId) || visited.has(childId)) continue; + const child = nodeMap.get(childId); + if (!child) continue; + node.children.push(child); + buildChildren(child, depth + 1); + } + + visiting.delete(node.id); + }; + + buildChildren(rootNode, 0); + + const toCallbackNode = (node: TreeNode): GraphNode => node.original; + + const calculateSizes = (node: TreeNode): void => { + const graphNode = toCallbackNode(node); + node.width = getWidth(graphNode); + node.height = getHeight(graphNode); + node.children.forEach(calculateSizes); + }; + + const assignSides = (node: TreeNode, parentSide?: 'left' | 'right'): void => { + if (node.children.length === 0) return; + + if (node.depth === 0) { + if (direction === 'H') { + node.children.forEach((child, index) => { + child.side = getSide(toCallbackNode(child), index, undefined); + }); + } else { + const side = direction === 'LR' ? 'right' : 'left'; + node.children.forEach((child) => { + child.side = side; + }); + } + } else { + node.children.forEach((child, index) => { + child.side = getSide(toCallbackNode(child), index, parentSide); + }); + } + + node.children.forEach((child) => assignSides(child, child.side)); + }; + + const assignBranchColor = (node: TreeNode, colorIndex: number): void => { + if (branchColors.length > 0) { + const color = branchColors[colorIndex % branchColors.length]; + node.data = { ...(node.data ?? {}), _branchColor: color }; + } + node.children.forEach((child) => assignBranchColor(child, colorIndex)); + }; + + const getChildrenHeight = (children: TreeNode[]): number => { + if (children.length === 0) return 0; + return children.reduce( + (total, child, index) => total + child.height + (index < children.length - 1 ? nodeGap : 0), + 0, + ); + }; + + const calculatePositions = (node: TreeNode): void => { + if (node.children.length === 0) return; + + const leftChildren: TreeNode[] = []; + const rightChildren: TreeNode[] = []; + for (const child of node.children) { + (child.side === 'left' ? leftChildren : rightChildren).push(child); + } + + if (rightChildren.length > 0) { + let yOffset = node.y - getChildrenHeight(rightChildren) / 2; + for (const child of rightChildren) { + child.x = node.x + node.width / 2 + levelGap + child.width / 2; + child.y = yOffset + child.height / 2; + yOffset += child.height + nodeGap; + assignBranchColor(child, 1); + calculatePositions(child); + } + } + + if (leftChildren.length > 0) { + let yOffset = node.y - getChildrenHeight(leftChildren) / 2; + for (const child of leftChildren) { + child.x = node.x - node.width / 2 - levelGap - child.width / 2; + child.y = yOffset + child.height / 2; + yOffset += child.height + nodeGap; + assignBranchColor(child, 0); + calculatePositions(child); + } + } + }; + + rootNode.x = 0; + rootNode.y = 0; + calculateSizes(rootNode); + assignSides(rootNode); + calculatePositions(rootNode); + + const applyResult = (node: TreeNode): void => { + node.original.x = node.x; + node.original.y = node.y; + if (node.data) { + (node.original._original as Record).data = node.data; + } + node.children.forEach(applyResult); + }; + + applyResult(rootNode); + + this.model.forEachNode((node) => { + if (!visited.has(String(node.id))) { + node.x = 0; + node.y = 0; + } + }); + } +} diff --git a/src/algorithm/mindmap/types.ts b/src/algorithm/mindmap/types.ts new file mode 100644 index 00000000..d4708b69 --- /dev/null +++ b/src/algorithm/mindmap/types.ts @@ -0,0 +1,19 @@ +import type { BaseLayoutOptions } from '../types'; +import type { GraphNode } from '../../types'; + +export interface MindmapLayoutOptions extends BaseLayoutOptions { + /** Branch direction. Defaults to 'H'. */ + direction?: 'H' | 'LR' | 'RL'; + /** Horizontal gap between parent and child boundaries. Defaults to 120. */ + levelGap?: number; + /** Vertical gap between adjacent children. Defaults to 30. */ + nodeGap?: number; + /** Palette written to data._branchColor. */ + branchColors?: string[]; + /** Node width callback. Defaults to 100. */ + getWidth?: (node: GraphNode) => number; + /** Node height callback. Defaults to 40. */ + getHeight?: (node: GraphNode) => number; + /** Side assignment callback for 'H' direction. */ + getSide?: (node: GraphNode, index: number, parentSide?: 'left' | 'right') => 'left' | 'right'; +} diff --git a/src/index.ts b/src/index.ts index b9aa9068..41191beb 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,37 @@ -export * from './algorithm'; -export * from './model'; -export * from './registry'; -export * from './runtime'; -export * from './types'; -export * from './util'; +export { + AntVDagreLayout, + type AntVDagreLayoutOptions, + type BaseLayoutOptions, + CircularLayout, + type CircularLayoutOptions, + ComboCombinedLayout, + type ComboCombinedLayoutOptions, + ConcentricLayout, + type ConcentricLayoutOptions, + D3ForceLayout, + type D3ForceLayoutOptions, + D3Force3DLayout, + type D3Force3DLayoutOptions, + DagreLayout, + type DagreLayoutOptions, + FishboneLayout, + type FishboneLayoutOptions, + ForceLayout, + type ForceLayoutOptions, + ForceAtlas2Layout, + type ForceAtlas2LayoutOptions, + FruchtermanLayout, + type FruchtermanLayoutOptions, + GridLayout, + type GridLayoutOptions, + IndentedLayout, + type IndentedLayoutOptions, + MindmapLayout, + type MindmapLayoutOptions, + MDSLayout, + type MDSLayoutOptions, + RadialLayout, + type RadialLayoutOptions, + RandomLayout, + type RandomLayoutOptions, +} from './algorithm'; From c8c6e8321ace7bd313f4a6be9974d8dd8ef72b65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=80=8D=E4=B8=BA?= Date: Thu, 26 Nov 2026 20:56:28 +0800 Subject: [PATCH 2/3] chore: migrate tests to vitest and update docs --- .changeset/README.md | 8 - .changeset/config.json | 11 - .github/workflows/build.yml | 10 +- README.md | 3 + __tests__/demos/antv-dagre.ts | 10 +- __tests__/demos/circular.ts | 16 +- __tests__/demos/combo-combined.ts | 5 +- __tests__/demos/combo-combined2.ts | 2 +- __tests__/demos/d3-force-3d.ts | 2 +- __tests__/demos/d3-force.ts | 3 +- __tests__/demos/dagre.ts | 10 +- __tests__/demos/force-atlas2.ts | 2 - __tests__/demos/force.ts | 6 +- __tests__/demos/grid.ts | 12 +- __tests__/main.ts | 2 +- __tests__/setup.ts | 2 +- .../counterclockwise-radius-range.svg | 2 +- .../snapshots/circular/custom-center.svg | 2 +- __tests__/snapshots/circular/default.svg | 2 +- __tests__/snapshots/circular/divisions-5.svg | 2 +- .../snapshots/circular/endRadius-only.svg | 2 +- .../circular/nodeSize-nodeSpacing-fn.svg | 2 +- .../snapshots/circular/ordering-degree.svg | 2 +- .../snapshots/circular/ordering-original.svg | 2 +- .../circular/ordering-topology-directed.svg | 2 +- .../snapshots/circular/ordering-topology.svg | 2 +- __tests__/snapshots/circular/radius-180.svg | 2 +- .../circular/startAngle-PI-endAngle-2PI.svg | 2 +- .../startRadius-100-endRadius-200.svg | 2 +- .../snapshots/circular/startRadius-only.svg | 2 +- .../snapshots/combo-combined/demo-combo2.svg | 2 +- .../combo-combined/demo-dagre-rect.svg | 66 ++--- .../snapshots/concentric/combined-options.svg | 2 +- .../snapshots/concentric/counterclockwise.svg | 2 +- .../snapshots/concentric/custom-center.svg | 2 +- __tests__/snapshots/concentric/default.svg | 2 +- .../concentric/equidistant-preventOverlap.svg | 2 +- .../snapshots/concentric/equidistant.svg | 2 +- .../concentric/function-nodeSize.svg | 2 +- .../snapshots/concentric/maxLevelDiff-05.svg | 2 +- .../snapshots/concentric/minimal-graph.svg | 2 +- .../concentric/node-size-from-data.svg | 2 +- .../concentric/node-size-object-data.svg | 2 +- .../preventOverlap-array-nodeSize.svg | 2 +- .../preventOverlap-array-nodeSpacing.svg | 2 +- .../preventOverlap-fn-nodeSpacing.svg | 2 +- .../preventOverlap-large-nodeSize.svg | 2 +- .../snapshots/concentric/preventOverlap.svg | 2 +- .../snapshots/concentric/sortBy-degree.svg | 2 +- .../concentric/sortBy-equal-values.svg | 2 +- .../concentric/sortBy-negative-values.svg | 2 +- .../snapshots/concentric/startAngle-0.svg | 2 +- .../startAngle-PI-2-counterclockwise.svg | 2 +- __tests__/snapshots/concentric/sweep-PI.svg | 2 +- .../snapshots/concentric/sweep-startAngle.svg | 2 +- .../snapshots/d3-force/clustering-force.svg | 2 +- .../snapshots/d3-force/collide-radius.svg | 2 +- .../snapshots/d3-force/custom-simulation.svg | 2 +- __tests__/snapshots/d3-force/default.svg | 2 +- .../snapshots/d3-force/disabled-forces.svg | 2 +- .../snapshots/d3-force/force-options.svg | 2 +- .../snapshots/d3-force/function-options.svg | 2 +- __tests__/snapshots/d3-force/lattice.svg | 2 +- .../snapshots/d3-force/link-distance.svg | 2 +- .../snapshots/d3-force/manyBody-strength.svg | 2 +- __tests__/snapshots/d3-force/radial-force.svg | 2 +- .../snapshots/d3-force/specified-viewport.svg | 2 +- __tests__/snapshots/d3-force/star-graph.svg | 2 +- __tests__/snapshots/d3-force/xy-forces.svg | 2 +- __tests__/snapshots/dagre/align-DL.svg | 42 ++-- __tests__/snapshots/dagre/align-DR.svg | 42 ++-- __tests__/snapshots/dagre/align-UL.svg | 42 ++-- __tests__/snapshots/dagre/align-UR.svg | 42 ++-- __tests__/snapshots/dagre/compound-groups.svg | 62 ++--- .../dagre/custom-edge-properties.svg | 42 ++-- __tests__/snapshots/dagre/cyclic-graph.svg | 18 +- __tests__/snapshots/dagre/default.svg | 42 ++-- .../dagre/disconnected-components.svg | 18 +- .../snapshots/dagre/edge-labels-function.svg | 42 ++-- __tests__/snapshots/dagre/edge-labels.svg | 42 ++-- .../dagre/edge-properties-function.svg | 42 ++-- __tests__/snapshots/dagre/edgesep-30.svg | 42 ++-- __tests__/snapshots/dagre/margins-50.svg | 42 ++-- __tests__/snapshots/dagre/multigraph.svg | 10 +- .../snapshots/dagre/nodeSize-function.svg | 42 ++-- __tests__/snapshots/dagre/nodesep-20.svg | 42 ++-- __tests__/snapshots/dagre/rankdir-BT.svg | 42 ++-- __tests__/snapshots/dagre/rankdir-LR.svg | 42 ++-- __tests__/snapshots/dagre/rankdir-RL.svg | 42 ++-- __tests__/snapshots/dagre/rankdir-TB.svg | 42 ++-- .../snapshots/dagre/ranker-longest-path.svg | 42 ++-- .../snapshots/dagre/ranker-tight-tree.svg | 42 ++-- __tests__/snapshots/dagre/ranksep-20.svg | 42 ++-- __tests__/snapshots/dagre/simple-chain.svg | 14 +- __tests__/snapshots/dagre/tree-structure.svg | 18 +- __tests__/snapshots/dagre/undirected.svg | 42 ++-- __tests__/snapshots/force-atlas2/default.svg | 2 +- .../snapshots/force/cluster-strength-40.svg | 2 +- __tests__/snapshots/force/clustering.svg | 2 +- __tests__/snapshots/force/custom-center.svg | 2 +- .../snapshots/force/custom-dimensions.svg | 2 +- __tests__/snapshots/force/damping-0.5.svg | 2 +- __tests__/snapshots/force/default.svg | 2 +- .../force/disconnected-components.svg | 2 +- .../snapshots/force/edgeStrength-100.svg | 2 +- __tests__/snapshots/force/factor-2.svg | 2 +- __tests__/snapshots/force/gravity-1.svg | 2 +- __tests__/snapshots/force/gravity-20.svg | 2 +- .../snapshots/force/linkDistance-100.svg | 2 +- .../snapshots/force/max-iteration-10.svg | 2 +- .../snapshots/force/nodeStrength-2000.svg | 2 +- __tests__/snapshots/force/path-graph.svg | 2 +- .../snapshots/force/preventOverlap-false.svg | 2 +- __tests__/snapshots/force/self-loop.svg | 2 +- __tests__/snapshots/force/star-graph.svg | 2 +- __tests__/snapshots/force/threshold-max.svg | 2 +- __tests__/snapshots/force/threshold-min.svg | 2 +- .../fruchterman/clustering-enabled.svg | 2 +- .../snapshots/fruchterman/custom-gravity.svg | 2 +- .../snapshots/fruchterman/custom-speed.svg | 2 +- __tests__/snapshots/fruchterman/default.svg | 2 +- .../snapshots/grid/cols-more-than-nodes.svg | 2 +- .../grid/complex-cell-occupation.svg | 2 +- .../snapshots/grid/condense-fixed-cols.svg | 2 +- .../grid/condense-preventOverlap.svg | 2 +- __tests__/snapshots/grid/condense.svg | 2 +- __tests__/snapshots/grid/custom-begin.svg | 2 +- .../snapshots/grid/custom-width-height.svg | 2 +- __tests__/snapshots/grid/default.svg | 2 +- __tests__/snapshots/grid/fixed-cols-5.svg | 2 +- __tests__/snapshots/grid/fixed-rows-5.svg | 2 +- .../snapshots/grid/fixed-rows-cols-6.svg | 2 +- .../snapshots/grid/function-nodeSize.svg | 2 +- __tests__/snapshots/grid/minimal-data.svg | 2 +- .../snapshots/grid/node-size-from-data.svg | 2 +- .../snapshots/grid/position-function.svg | 2 +- .../snapshots/grid/position-undefined-col.svg | 2 +- .../snapshots/grid/position-undefined-row.svg | 2 +- .../grid/preventOverlap-array-nodeSize.svg | 2 +- .../snapshots/grid/preventOverlap-false.svg | 2 +- .../grid/preventOverlap-large-nodeSize.svg | 2 +- .../snapshots/grid/reduce-small-side.svg | 2 +- .../snapshots/grid/rows-cols-less-nodes.svg | 2 +- .../snapshots/grid/rows-more-than-nodes.svg | 2 +- __tests__/snapshots/grid/skip-used-cells.svg | 2 +- .../snapshots/grid/sortBy-custom-property.svg | 2 +- __tests__/snapshots/grid/sortBy-degree.svg | 2 +- .../snapshots/grid/sortBy-id-numbers.svg | 2 +- .../snapshots/grid/sortBy-id-strings.svg | 2 +- __tests__/snapshots/grid/sortBy-id.svg | 2 +- __tests__/snapshots/mds/complete-graph.svg | 2 +- __tests__/snapshots/mds/custom-center.svg | 2 +- __tests__/snapshots/mds/default.svg | 2 +- .../snapshots/mds/disconnected-components.svg | 2 +- __tests__/snapshots/mds/linkDistance-20.svg | 2 +- __tests__/snapshots/mds/linkDistance-60.svg | 2 +- __tests__/snapshots/mds/path-graph.svg | 2 +- __tests__/snapshots/mds/star-graph.svg | 2 +- .../snapshots/radial/combined-options.svg | 2 +- __tests__/snapshots/radial/custom-center.svg | 2 +- __tests__/snapshots/radial/default.svg | 2 +- .../radial/disconnected-components.svg | 2 +- .../snapshots/radial/exact-same-position.svg | 2 +- __tests__/snapshots/radial/focusNode-1.svg | 2 +- .../snapshots/radial/inexistent-focusNode.svg | 2 +- .../snapshots/radial/linkDistance-30.svg | 2 +- .../snapshots/radial/maxIteration-2000.svg | 2 +- __tests__/snapshots/radial/minimal-graph.svg | 2 +- .../radial/overlapping-same-position.svg | 2 +- .../radial/preventOverlap-enabled.svg | 2 +- .../radial/preventOverlap-large-nodeSize.svg | 2 +- .../radial/preventOverlap-with-sortBy.svg | 2 +- __tests__/snapshots/radial/sortBy-data.svg | 2 +- __tests__/snapshots/radial/sortBy-id.svg | 2 +- .../snapshots/radial/sortStrength-50.svg | 2 +- .../snapshots/radial/strictRadial-false.svg | 2 +- .../snapshots/radial/strictRadial-true.svg | 2 +- __tests__/snapshots/radial/unitRadius-100.svg | 2 +- __tests__/snapshots/random/default.svg | 2 +- .../snapshots/random/disconnected-graph.svg | 2 +- __tests__/snapshots/tree-layouts/fishbone.svg | 180 ++++++++++++++ __tests__/snapshots/tree-layouts/indented.svg | 162 ++++++++++++ __tests__/snapshots/tree-layouts/mindmap.svg | 234 ++++++++++++++++++ __tests__/unit/antv-dagre/acyclic.test.ts | 7 +- .../antv-dagre/rank/network-simplex.test.ts | 14 +- __tests__/unit/combo-combined.test.ts | 19 +- __tests__/unit/concentric.test.ts | 5 +- __tests__/unit/d3-force-3d.test.ts | 2 +- __tests__/unit/d3-force.test.ts | 30 ++- __tests__/unit/dagre.test.ts | 22 +- __tests__/unit/force.test.ts | 23 +- __tests__/unit/fruchterman.test.ts | 15 +- __tests__/unit/tree-layouts.test.ts | 190 ++++++++++++++ __tests__/unit/util/format.test.ts | 62 ++--- __tests__/unit/util/math.test.ts | 8 +- __tests__/unit/util/viewport.test.ts | 2 +- __tests__/utils/renderer.ts | 60 ++--- __tests__/utils/svg-transformer.js | 7 - __tests__/utils/to-match-svg-snapshot.ts | 17 +- __tests__/utils/use-snapshot-matchers.ts | 28 +-- __tests__/xmlserializer.d.ts | 3 + jest.config.js | 49 ---- package.json | 16 +- site/docs/en/guide/api/hierarchy/_meta.json | 2 +- site/docs/en/guide/api/hierarchy/fishbone.mdx | 26 ++ site/docs/en/guide/api/hierarchy/indented.mdx | 28 +++ site/docs/en/guide/api/hierarchy/mindmap.mdx | 29 +++ site/docs/zh/guide/api/hierarchy/_meta.json | 2 +- site/docs/zh/guide/api/hierarchy/fishbone.mdx | 26 ++ site/docs/zh/guide/api/hierarchy/indented.mdx | 28 +++ site/docs/zh/guide/api/hierarchy/mindmap.mdx | 29 +++ src/algorithm/antv-dagre/graph.ts | 16 +- tsconfig.json | 2 +- vitest.config.ts | 24 ++ 214 files changed, 1863 insertions(+), 968 deletions(-) delete mode 100644 .changeset/README.md delete mode 100644 .changeset/config.json create mode 100644 __tests__/snapshots/tree-layouts/fishbone.svg create mode 100644 __tests__/snapshots/tree-layouts/indented.svg create mode 100644 __tests__/snapshots/tree-layouts/mindmap.svg create mode 100644 __tests__/unit/tree-layouts.test.ts delete mode 100644 __tests__/utils/svg-transformer.js create mode 100644 __tests__/xmlserializer.d.ts delete mode 100644 jest.config.js create mode 100644 site/docs/en/guide/api/hierarchy/fishbone.mdx create mode 100644 site/docs/en/guide/api/hierarchy/indented.mdx create mode 100644 site/docs/en/guide/api/hierarchy/mindmap.mdx create mode 100644 site/docs/zh/guide/api/hierarchy/fishbone.mdx create mode 100644 site/docs/zh/guide/api/hierarchy/indented.mdx create mode 100644 site/docs/zh/guide/api/hierarchy/mindmap.mdx create mode 100644 vitest.config.ts diff --git a/.changeset/README.md b/.changeset/README.md deleted file mode 100644 index e5b6d8d6..00000000 --- a/.changeset/README.md +++ /dev/null @@ -1,8 +0,0 @@ -# Changesets - -Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works -with multi-package repos, or single-package repos to help you version and publish your code. You can -find the full documentation for it [in our repository](https://github.com/changesets/changesets) - -We have a quick list of common questions to get you started engaging with this project in -[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md) diff --git a/.changeset/config.json b/.changeset/config.json deleted file mode 100644 index bdf0c312..00000000 --- a/.changeset/config.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "$schema": "https://unpkg.com/@changesets/config@2.3.0/schema.json", - "changelog": "@changesets/cli/changelog", - "commit": false, - "fixed": [], - "linked": [], - "access": "restricted", - "baseBranch": "v5", - "updateInternalDependencies": "patch", - "ignore": [] -} diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 29883c83..e377f869 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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 @@ -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 diff --git a/README.md b/README.md index f3e07980..89b3167e 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,9 @@ Basic layout algorithms for visualization | Force [D3Force3D](https://layout.antv.vision/guide/api/force/d3-force-3d) | D3Force3D | 3D force layout based on d3-force-3d with z-axis forces and z output. | | Hierarchy [Dagre](https://layout.antv.vision/guide/api/hierarchy/dagre) | Dagre | Layered directed layout for DAGs, workflows, and dependency graphs. | | Hierarchy [AntVDagre](https://layout.antv.vision/guide/api/hierarchy/antv-dagre) | AntVDagre | Production-oriented hierarchical layout with spacing, alignment, and path info. | +| Hierarchy [Fishbone](https://layout.antv.vision/guide/api/hierarchy/fishbone) | — | Arrange root, categories, and items in a fishbone diagram. | +| Hierarchy [Indented](https://layout.antv.vision/guide/api/hierarchy/indented) | — | Display tree nodes in DFS order with depth-based indentation. | +| Hierarchy [Mindmap](https://layout.antv.vision/guide/api/hierarchy/mindmap) | — | Arrange branches on one or both sides of a central root. | | Radial [Circular](https://layout.antv.vision/guide/api/radial/circular) | Circular | Place nodes on a circle (or spiral) with ordering, angle, and radius controls. | | Radial [Concentric](https://layout.antv.vision/guide/api/radial/concentric) | Concentric | Layer nodes by an importance score (default: degree), pulling higher scores inward. | | Radial [Radial](https://layout.antv.vision/guide/api/radial/radial) | Radial | Focus-centered rings based on shortest-path distance for relationship exploration. | diff --git a/__tests__/demos/antv-dagre.ts b/__tests__/demos/antv-dagre.ts index b56dcc5e..626fdd0d 100644 --- a/__tests__/demos/antv-dagre.ts +++ b/__tests__/demos/antv-dagre.ts @@ -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'; @@ -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, }); diff --git a/__tests__/demos/circular.ts b/__tests__/demos/circular.ts index c55a864a..e5a8a515 100644 --- a/__tests__/demos/circular.ts +++ b/__tests__/demos/circular.ts @@ -1,8 +1,10 @@ -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; + export function render(gui?: GUI) { const renderer = new GraphRenderer(); @@ -10,10 +12,10 @@ export function render(gui?: GUI) { 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 = {}) => { @@ -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] }); @@ -94,7 +96,7 @@ export function render(gui?: GUI) { 'topology', 'topology-directed', ]) - .onChange((ordering) => { + .onChange((ordering: CircularOrdering) => { relayout({ ...config, ordering }); }); } diff --git a/__tests__/demos/combo-combined.ts b/__tests__/demos/combo-combined.ts index e838d162..8aed60c6 100644 --- a/__tests__/demos/combo-combined.ts +++ b/__tests__/demos/combo-combined.ts @@ -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'; @@ -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) { @@ -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', diff --git a/__tests__/demos/combo-combined2.ts b/__tests__/demos/combo-combined2.ts index c71be899..f98768a9 100644 --- a/__tests__/demos/combo-combined2.ts +++ b/__tests__/demos/combo-combined2.ts @@ -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) { diff --git a/__tests__/demos/d3-force-3d.ts b/__tests__/demos/d3-force-3d.ts index 9cd5abdc..71120616 100644 --- a/__tests__/demos/d3-force-3d.ts +++ b/__tests__/demos/d3-force-3d.ts @@ -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'; diff --git a/__tests__/demos/d3-force.ts b/__tests__/demos/d3-force.ts index 831a966e..50c9e642 100644 --- a/__tests__/demos/d3-force.ts +++ b/__tests__/demos/d3-force.ts @@ -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'; @@ -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, diff --git a/__tests__/demos/dagre.ts b/__tests__/demos/dagre.ts index 2eb581b3..003f7a7d 100644 --- a/__tests__/demos/dagre.ts +++ b/__tests__/demos/dagre.ts @@ -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'; @@ -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, }); diff --git a/__tests__/demos/force-atlas2.ts b/__tests__/demos/force-atlas2.ts index cb59689b..b6237454 100644 --- a/__tests__/demos/force-atlas2.ts +++ b/__tests__/demos/force-atlas2.ts @@ -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}`); diff --git a/__tests__/demos/force.ts b/__tests__/demos/force.ts index 98cfa1c6..90be9327 100644 --- a/__tests__/demos/force.ts +++ b/__tests__/demos/force.ts @@ -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); }, }); diff --git a/__tests__/demos/grid.ts b/__tests__/demos/grid.ts index 420012f6..e96d0ecb 100644 --- a/__tests__/demos/grid.ts +++ b/__tests__/demos/grid.ts @@ -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'; @@ -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 }; @@ -38,7 +38,7 @@ export function render(gui?: GUI) { }); const relayout = async () => { - const _options = { + const _options: Partial = { width: options.width, height: options.height, begin: [options.beginX, options.beginY], diff --git a/__tests__/main.ts b/__tests__/main.ts index c50dd61f..df57cab6 100644 --- a/__tests__/main.ts +++ b/__tests__/main.ts @@ -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); diff --git a/__tests__/setup.ts b/__tests__/setup.ts index 5a365be9..50edf248 100644 --- a/__tests__/setup.ts +++ b/__tests__/setup.ts @@ -1,2 +1,2 @@ -import 'jest-canvas-mock'; +import 'vitest-canvas-mock'; import './utils/use-snapshot-matchers'; diff --git a/__tests__/snapshots/circular/counterclockwise-radius-range.svg b/__tests__/snapshots/circular/counterclockwise-radius-range.svg index 1deed5ca..bc8f67c1 100644 --- a/__tests__/snapshots/circular/counterclockwise-radius-range.svg +++ b/__tests__/snapshots/circular/counterclockwise-radius-range.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/circular/custom-center.svg b/__tests__/snapshots/circular/custom-center.svg index 73625df2..2c945638 100644 --- a/__tests__/snapshots/circular/custom-center.svg +++ b/__tests__/snapshots/circular/custom-center.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/circular/default.svg b/__tests__/snapshots/circular/default.svg index 8a076b52..c913a9bc 100644 --- a/__tests__/snapshots/circular/default.svg +++ b/__tests__/snapshots/circular/default.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/circular/divisions-5.svg b/__tests__/snapshots/circular/divisions-5.svg index 466e8ec0..21f65740 100644 --- a/__tests__/snapshots/circular/divisions-5.svg +++ b/__tests__/snapshots/circular/divisions-5.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/circular/endRadius-only.svg b/__tests__/snapshots/circular/endRadius-only.svg index 8a076b52..c913a9bc 100644 --- a/__tests__/snapshots/circular/endRadius-only.svg +++ b/__tests__/snapshots/circular/endRadius-only.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/circular/nodeSize-nodeSpacing-fn.svg b/__tests__/snapshots/circular/nodeSize-nodeSpacing-fn.svg index 9854400e..ea50b22e 100644 --- a/__tests__/snapshots/circular/nodeSize-nodeSpacing-fn.svg +++ b/__tests__/snapshots/circular/nodeSize-nodeSpacing-fn.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/circular/ordering-degree.svg b/__tests__/snapshots/circular/ordering-degree.svg index 491f6e50..ec9451ac 100644 --- a/__tests__/snapshots/circular/ordering-degree.svg +++ b/__tests__/snapshots/circular/ordering-degree.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/circular/ordering-original.svg b/__tests__/snapshots/circular/ordering-original.svg index 8a076b52..c913a9bc 100644 --- a/__tests__/snapshots/circular/ordering-original.svg +++ b/__tests__/snapshots/circular/ordering-original.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/circular/ordering-topology-directed.svg b/__tests__/snapshots/circular/ordering-topology-directed.svg index cea79acd..814cd681 100644 --- a/__tests__/snapshots/circular/ordering-topology-directed.svg +++ b/__tests__/snapshots/circular/ordering-topology-directed.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/circular/ordering-topology.svg b/__tests__/snapshots/circular/ordering-topology.svg index 42367954..cb8468fb 100644 --- a/__tests__/snapshots/circular/ordering-topology.svg +++ b/__tests__/snapshots/circular/ordering-topology.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/circular/radius-180.svg b/__tests__/snapshots/circular/radius-180.svg index e2359678..5322acb6 100644 --- a/__tests__/snapshots/circular/radius-180.svg +++ b/__tests__/snapshots/circular/radius-180.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/circular/startAngle-PI-endAngle-2PI.svg b/__tests__/snapshots/circular/startAngle-PI-endAngle-2PI.svg index f55693e2..bb4ca420 100644 --- a/__tests__/snapshots/circular/startAngle-PI-endAngle-2PI.svg +++ b/__tests__/snapshots/circular/startAngle-PI-endAngle-2PI.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/circular/startRadius-100-endRadius-200.svg b/__tests__/snapshots/circular/startRadius-100-endRadius-200.svg index 206606bf..92974999 100644 --- a/__tests__/snapshots/circular/startRadius-100-endRadius-200.svg +++ b/__tests__/snapshots/circular/startRadius-100-endRadius-200.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/circular/startRadius-only.svg b/__tests__/snapshots/circular/startRadius-only.svg index 8a076b52..c913a9bc 100644 --- a/__tests__/snapshots/circular/startRadius-only.svg +++ b/__tests__/snapshots/circular/startRadius-only.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/combo-combined/demo-combo2.svg b/__tests__/snapshots/combo-combined/demo-combo2.svg index 1bf60bc0..bf656117 100644 --- a/__tests__/snapshots/combo-combined/demo-combo2.svg +++ b/__tests__/snapshots/combo-combined/demo-combo2.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/combo-combined/demo-dagre-rect.svg b/__tests__/snapshots/combo-combined/demo-dagre-rect.svg index f58edd10..b89ae222 100644 --- a/__tests__/snapshots/combo-combined/demo-dagre-rect.svg +++ b/__tests__/snapshots/combo-combined/demo-dagre-rect.svg @@ -1,4 +1,4 @@ - + @@ -36,97 +36,97 @@ - + A - + B - + C - + 0 - + 1 - + 2 - + 3 - + 4 - + 5 - + 6 - + 7 - + 8 - + 9 - + 10 - + 11 - + 12 @@ -165,97 +165,97 @@ - + A - + B - + C - + 0 - + 1 - + 2 - + 3 - + 4 - + 5 - + 6 - + 7 - + 8 - + 9 - + 10 - + 11 - + 12 diff --git a/__tests__/snapshots/concentric/combined-options.svg b/__tests__/snapshots/concentric/combined-options.svg index 161e11df..570b6e19 100644 --- a/__tests__/snapshots/concentric/combined-options.svg +++ b/__tests__/snapshots/concentric/combined-options.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/concentric/counterclockwise.svg b/__tests__/snapshots/concentric/counterclockwise.svg index f89ec206..5209ab54 100644 --- a/__tests__/snapshots/concentric/counterclockwise.svg +++ b/__tests__/snapshots/concentric/counterclockwise.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/concentric/custom-center.svg b/__tests__/snapshots/concentric/custom-center.svg index 2633e550..25dae2a4 100644 --- a/__tests__/snapshots/concentric/custom-center.svg +++ b/__tests__/snapshots/concentric/custom-center.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/concentric/default.svg b/__tests__/snapshots/concentric/default.svg index 535aec6e..199da1ab 100644 --- a/__tests__/snapshots/concentric/default.svg +++ b/__tests__/snapshots/concentric/default.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/concentric/equidistant-preventOverlap.svg b/__tests__/snapshots/concentric/equidistant-preventOverlap.svg index 615307af..cc5ed8ab 100644 --- a/__tests__/snapshots/concentric/equidistant-preventOverlap.svg +++ b/__tests__/snapshots/concentric/equidistant-preventOverlap.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/concentric/equidistant.svg b/__tests__/snapshots/concentric/equidistant.svg index fdbf2125..215bde07 100644 --- a/__tests__/snapshots/concentric/equidistant.svg +++ b/__tests__/snapshots/concentric/equidistant.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/concentric/function-nodeSize.svg b/__tests__/snapshots/concentric/function-nodeSize.svg index 53490eeb..9ad6b794 100644 --- a/__tests__/snapshots/concentric/function-nodeSize.svg +++ b/__tests__/snapshots/concentric/function-nodeSize.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/concentric/maxLevelDiff-05.svg b/__tests__/snapshots/concentric/maxLevelDiff-05.svg index af49c792..a561670c 100644 --- a/__tests__/snapshots/concentric/maxLevelDiff-05.svg +++ b/__tests__/snapshots/concentric/maxLevelDiff-05.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/concentric/minimal-graph.svg b/__tests__/snapshots/concentric/minimal-graph.svg index d8da746c..09416d2e 100644 --- a/__tests__/snapshots/concentric/minimal-graph.svg +++ b/__tests__/snapshots/concentric/minimal-graph.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/concentric/node-size-from-data.svg b/__tests__/snapshots/concentric/node-size-from-data.svg index 53490eeb..9ad6b794 100644 --- a/__tests__/snapshots/concentric/node-size-from-data.svg +++ b/__tests__/snapshots/concentric/node-size-from-data.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/concentric/node-size-object-data.svg b/__tests__/snapshots/concentric/node-size-object-data.svg index c98ffadd..66224fdc 100644 --- a/__tests__/snapshots/concentric/node-size-object-data.svg +++ b/__tests__/snapshots/concentric/node-size-object-data.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/concentric/preventOverlap-array-nodeSize.svg b/__tests__/snapshots/concentric/preventOverlap-array-nodeSize.svg index c98ffadd..66224fdc 100644 --- a/__tests__/snapshots/concentric/preventOverlap-array-nodeSize.svg +++ b/__tests__/snapshots/concentric/preventOverlap-array-nodeSize.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/concentric/preventOverlap-array-nodeSpacing.svg b/__tests__/snapshots/concentric/preventOverlap-array-nodeSpacing.svg index c13b049d..b7194969 100644 --- a/__tests__/snapshots/concentric/preventOverlap-array-nodeSpacing.svg +++ b/__tests__/snapshots/concentric/preventOverlap-array-nodeSpacing.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/concentric/preventOverlap-fn-nodeSpacing.svg b/__tests__/snapshots/concentric/preventOverlap-fn-nodeSpacing.svg index c13b049d..b7194969 100644 --- a/__tests__/snapshots/concentric/preventOverlap-fn-nodeSpacing.svg +++ b/__tests__/snapshots/concentric/preventOverlap-fn-nodeSpacing.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/concentric/preventOverlap-large-nodeSize.svg b/__tests__/snapshots/concentric/preventOverlap-large-nodeSize.svg index c13b049d..b7194969 100644 --- a/__tests__/snapshots/concentric/preventOverlap-large-nodeSize.svg +++ b/__tests__/snapshots/concentric/preventOverlap-large-nodeSize.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/concentric/preventOverlap.svg b/__tests__/snapshots/concentric/preventOverlap.svg index 139e154a..fe280d2e 100644 --- a/__tests__/snapshots/concentric/preventOverlap.svg +++ b/__tests__/snapshots/concentric/preventOverlap.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/concentric/sortBy-degree.svg b/__tests__/snapshots/concentric/sortBy-degree.svg index 535aec6e..199da1ab 100644 --- a/__tests__/snapshots/concentric/sortBy-degree.svg +++ b/__tests__/snapshots/concentric/sortBy-degree.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/concentric/sortBy-equal-values.svg b/__tests__/snapshots/concentric/sortBy-equal-values.svg index f79cb934..001c3171 100644 --- a/__tests__/snapshots/concentric/sortBy-equal-values.svg +++ b/__tests__/snapshots/concentric/sortBy-equal-values.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/concentric/sortBy-negative-values.svg b/__tests__/snapshots/concentric/sortBy-negative-values.svg index f3065546..69742232 100644 --- a/__tests__/snapshots/concentric/sortBy-negative-values.svg +++ b/__tests__/snapshots/concentric/sortBy-negative-values.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/concentric/startAngle-0.svg b/__tests__/snapshots/concentric/startAngle-0.svg index a40fc326..b29e097b 100644 --- a/__tests__/snapshots/concentric/startAngle-0.svg +++ b/__tests__/snapshots/concentric/startAngle-0.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/concentric/startAngle-PI-2-counterclockwise.svg b/__tests__/snapshots/concentric/startAngle-PI-2-counterclockwise.svg index dac9a3e3..2275bd64 100644 --- a/__tests__/snapshots/concentric/startAngle-PI-2-counterclockwise.svg +++ b/__tests__/snapshots/concentric/startAngle-PI-2-counterclockwise.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/concentric/sweep-PI.svg b/__tests__/snapshots/concentric/sweep-PI.svg index 834e9622..52273d74 100644 --- a/__tests__/snapshots/concentric/sweep-PI.svg +++ b/__tests__/snapshots/concentric/sweep-PI.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/concentric/sweep-startAngle.svg b/__tests__/snapshots/concentric/sweep-startAngle.svg index 9896f4c7..2a99bea1 100644 --- a/__tests__/snapshots/concentric/sweep-startAngle.svg +++ b/__tests__/snapshots/concentric/sweep-startAngle.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/d3-force/clustering-force.svg b/__tests__/snapshots/d3-force/clustering-force.svg index b9873ecc..56492dab 100644 --- a/__tests__/snapshots/d3-force/clustering-force.svg +++ b/__tests__/snapshots/d3-force/clustering-force.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/d3-force/collide-radius.svg b/__tests__/snapshots/d3-force/collide-radius.svg index b3396f72..3efc4840 100644 --- a/__tests__/snapshots/d3-force/collide-radius.svg +++ b/__tests__/snapshots/d3-force/collide-radius.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/d3-force/custom-simulation.svg b/__tests__/snapshots/d3-force/custom-simulation.svg index f8ae8eda..f92c9422 100644 --- a/__tests__/snapshots/d3-force/custom-simulation.svg +++ b/__tests__/snapshots/d3-force/custom-simulation.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/d3-force/default.svg b/__tests__/snapshots/d3-force/default.svg index f8ae8eda..f92c9422 100644 --- a/__tests__/snapshots/d3-force/default.svg +++ b/__tests__/snapshots/d3-force/default.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/d3-force/disabled-forces.svg b/__tests__/snapshots/d3-force/disabled-forces.svg index b8a9ea5d..3a1df96c 100644 --- a/__tests__/snapshots/d3-force/disabled-forces.svg +++ b/__tests__/snapshots/d3-force/disabled-forces.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/d3-force/force-options.svg b/__tests__/snapshots/d3-force/force-options.svg index 7f6c3e1f..40aa86de 100644 --- a/__tests__/snapshots/d3-force/force-options.svg +++ b/__tests__/snapshots/d3-force/force-options.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/d3-force/function-options.svg b/__tests__/snapshots/d3-force/function-options.svg index 8b5a726d..b0fe04d9 100644 --- a/__tests__/snapshots/d3-force/function-options.svg +++ b/__tests__/snapshots/d3-force/function-options.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/d3-force/lattice.svg b/__tests__/snapshots/d3-force/lattice.svg index 60f319f0..f706e622 100644 --- a/__tests__/snapshots/d3-force/lattice.svg +++ b/__tests__/snapshots/d3-force/lattice.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/d3-force/link-distance.svg b/__tests__/snapshots/d3-force/link-distance.svg index 823b757b..02ed57f7 100644 --- a/__tests__/snapshots/d3-force/link-distance.svg +++ b/__tests__/snapshots/d3-force/link-distance.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/d3-force/manyBody-strength.svg b/__tests__/snapshots/d3-force/manyBody-strength.svg index 4f29870f..047189ae 100644 --- a/__tests__/snapshots/d3-force/manyBody-strength.svg +++ b/__tests__/snapshots/d3-force/manyBody-strength.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/d3-force/radial-force.svg b/__tests__/snapshots/d3-force/radial-force.svg index 22b42971..1a4c8aa0 100644 --- a/__tests__/snapshots/d3-force/radial-force.svg +++ b/__tests__/snapshots/d3-force/radial-force.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/d3-force/specified-viewport.svg b/__tests__/snapshots/d3-force/specified-viewport.svg index f8ae8eda..f92c9422 100644 --- a/__tests__/snapshots/d3-force/specified-viewport.svg +++ b/__tests__/snapshots/d3-force/specified-viewport.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/d3-force/star-graph.svg b/__tests__/snapshots/d3-force/star-graph.svg index 4d41bc23..048bd748 100644 --- a/__tests__/snapshots/d3-force/star-graph.svg +++ b/__tests__/snapshots/d3-force/star-graph.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/d3-force/xy-forces.svg b/__tests__/snapshots/d3-force/xy-forces.svg index 306908c9..b285b865 100644 --- a/__tests__/snapshots/d3-force/xy-forces.svg +++ b/__tests__/snapshots/d3-force/xy-forces.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/dagre/align-DL.svg b/__tests__/snapshots/dagre/align-DL.svg index 9e0fc47b..b3b918b4 100644 --- a/__tests__/snapshots/dagre/align-DL.svg +++ b/__tests__/snapshots/dagre/align-DL.svg @@ -1,4 +1,4 @@ - + @@ -39,61 +39,61 @@ - + 0 - + 1 - + 2 - + 3 - + 4 - + 5 - + 6 - + 7 - + 8 - + 9 @@ -135,61 +135,61 @@ - + 0 - + 1 - + 2 - + 3 - + 4 - + 5 - + 6 - + 7 - + 8 - + 9 diff --git a/__tests__/snapshots/dagre/align-DR.svg b/__tests__/snapshots/dagre/align-DR.svg index 53b6b944..1e221da3 100644 --- a/__tests__/snapshots/dagre/align-DR.svg +++ b/__tests__/snapshots/dagre/align-DR.svg @@ -1,4 +1,4 @@ - + @@ -39,61 +39,61 @@ - + 0 - + 1 - + 2 - + 3 - + 4 - + 5 - + 6 - + 7 - + 8 - + 9 @@ -135,61 +135,61 @@ - + 0 - + 1 - + 2 - + 3 - + 4 - + 5 - + 6 - + 7 - + 8 - + 9 diff --git a/__tests__/snapshots/dagre/align-UL.svg b/__tests__/snapshots/dagre/align-UL.svg index 79f12995..9697ba03 100644 --- a/__tests__/snapshots/dagre/align-UL.svg +++ b/__tests__/snapshots/dagre/align-UL.svg @@ -1,4 +1,4 @@ - + @@ -39,61 +39,61 @@ - + 0 - + 1 - + 2 - + 3 - + 4 - + 5 - + 6 - + 7 - + 8 - + 9 @@ -135,61 +135,61 @@ - + 0 - + 1 - + 2 - + 3 - + 4 - + 5 - + 6 - + 7 - + 8 - + 9 diff --git a/__tests__/snapshots/dagre/align-UR.svg b/__tests__/snapshots/dagre/align-UR.svg index 6930fd64..79f299e4 100644 --- a/__tests__/snapshots/dagre/align-UR.svg +++ b/__tests__/snapshots/dagre/align-UR.svg @@ -1,4 +1,4 @@ - + @@ -39,61 +39,61 @@ - + 0 - + 1 - + 2 - + 3 - + 4 - + 5 - + 6 - + 7 - + 8 - + 9 @@ -135,61 +135,61 @@ - + 0 - + 1 - + 2 - + 3 - + 4 - + 5 - + 6 - + 7 - + 8 - + 9 diff --git a/__tests__/snapshots/dagre/compound-groups.svg b/__tests__/snapshots/dagre/compound-groups.svg index 4054cfad..9d03a99b 100644 --- a/__tests__/snapshots/dagre/compound-groups.svg +++ b/__tests__/snapshots/dagre/compound-groups.svg @@ -1,4 +1,4 @@ - + @@ -39,91 +39,91 @@ - + 0 - + 1 - + 2 - + 3 - + 4 - + 5 - + 6 - + 7 - + 8 - + 9 - + 10 - + 11 - + A - + B - + C @@ -165,91 +165,91 @@ - + 0 - + 1 - + 2 - + 3 - + 4 - + 5 - + 6 - + 7 - + 8 - + 9 - + 10 - + 11 - + A - + B - + C diff --git a/__tests__/snapshots/dagre/custom-edge-properties.svg b/__tests__/snapshots/dagre/custom-edge-properties.svg index 11dd4535..5c14334e 100644 --- a/__tests__/snapshots/dagre/custom-edge-properties.svg +++ b/__tests__/snapshots/dagre/custom-edge-properties.svg @@ -1,4 +1,4 @@ - + @@ -39,61 +39,61 @@ - + 0 - + 1 - + 2 - + 3 - + 4 - + 5 - + 6 - + 7 - + 8 - + 9 @@ -135,61 +135,61 @@ - + 0 - + 1 - + 2 - + 3 - + 4 - + 5 - + 6 - + 7 - + 8 - + 9 diff --git a/__tests__/snapshots/dagre/cyclic-graph.svg b/__tests__/snapshots/dagre/cyclic-graph.svg index e3dd4e4d..e4e405b1 100644 --- a/__tests__/snapshots/dagre/cyclic-graph.svg +++ b/__tests__/snapshots/dagre/cyclic-graph.svg @@ -1,4 +1,4 @@ - + @@ -15,25 +15,25 @@ - + a - + b - + c - + d @@ -51,25 +51,25 @@ - + a - + b - + c - + d diff --git a/__tests__/snapshots/dagre/default.svg b/__tests__/snapshots/dagre/default.svg index 6aedcbb1..cd2e2232 100644 --- a/__tests__/snapshots/dagre/default.svg +++ b/__tests__/snapshots/dagre/default.svg @@ -1,4 +1,4 @@ - + @@ -39,61 +39,61 @@ - + 0 - + 1 - + 2 - + 3 - + 4 - + 5 - + 6 - + 7 - + 8 - + 9 @@ -135,61 +135,61 @@ - + 0 - + 1 - + 2 - + 3 - + 4 - + 5 - + 6 - + 7 - + 8 - + 9 diff --git a/__tests__/snapshots/dagre/disconnected-components.svg b/__tests__/snapshots/dagre/disconnected-components.svg index b29b5d11..30fcec1a 100644 --- a/__tests__/snapshots/dagre/disconnected-components.svg +++ b/__tests__/snapshots/dagre/disconnected-components.svg @@ -1,4 +1,4 @@ - + @@ -9,25 +9,25 @@ - + a - + b - + c - + d @@ -39,25 +39,25 @@ - + a - + b - + c - + d diff --git a/__tests__/snapshots/dagre/edge-labels-function.svg b/__tests__/snapshots/dagre/edge-labels-function.svg index 5f6b763c..1a5e39c9 100644 --- a/__tests__/snapshots/dagre/edge-labels-function.svg +++ b/__tests__/snapshots/dagre/edge-labels-function.svg @@ -1,4 +1,4 @@ - + @@ -39,61 +39,61 @@ - + 0 - + 1 - + 2 - + 3 - + 4 - + 5 - + 6 - + 7 - + 8 - + 9 @@ -135,61 +135,61 @@ - + 0 - + 1 - + 2 - + 3 - + 4 - + 5 - + 6 - + 7 - + 8 - + 9 diff --git a/__tests__/snapshots/dagre/edge-labels.svg b/__tests__/snapshots/dagre/edge-labels.svg index 84c9b891..7df46ead 100644 --- a/__tests__/snapshots/dagre/edge-labels.svg +++ b/__tests__/snapshots/dagre/edge-labels.svg @@ -1,4 +1,4 @@ - + @@ -39,61 +39,61 @@ - + 0 - + 1 - + 2 - + 3 - + 4 - + 5 - + 6 - + 7 - + 8 - + 9 @@ -135,61 +135,61 @@ - + 0 - + 1 - + 2 - + 3 - + 4 - + 5 - + 6 - + 7 - + 8 - + 9 diff --git a/__tests__/snapshots/dagre/edge-properties-function.svg b/__tests__/snapshots/dagre/edge-properties-function.svg index 6aedcbb1..cd2e2232 100644 --- a/__tests__/snapshots/dagre/edge-properties-function.svg +++ b/__tests__/snapshots/dagre/edge-properties-function.svg @@ -1,4 +1,4 @@ - + @@ -39,61 +39,61 @@ - + 0 - + 1 - + 2 - + 3 - + 4 - + 5 - + 6 - + 7 - + 8 - + 9 @@ -135,61 +135,61 @@ - + 0 - + 1 - + 2 - + 3 - + 4 - + 5 - + 6 - + 7 - + 8 - + 9 diff --git a/__tests__/snapshots/dagre/edgesep-30.svg b/__tests__/snapshots/dagre/edgesep-30.svg index 15dd0d88..865e0330 100644 --- a/__tests__/snapshots/dagre/edgesep-30.svg +++ b/__tests__/snapshots/dagre/edgesep-30.svg @@ -1,4 +1,4 @@ - + @@ -39,61 +39,61 @@ - + 0 - + 1 - + 2 - + 3 - + 4 - + 5 - + 6 - + 7 - + 8 - + 9 @@ -135,61 +135,61 @@ - + 0 - + 1 - + 2 - + 3 - + 4 - + 5 - + 6 - + 7 - + 8 - + 9 diff --git a/__tests__/snapshots/dagre/margins-50.svg b/__tests__/snapshots/dagre/margins-50.svg index 5fb120df..4d3abfb0 100644 --- a/__tests__/snapshots/dagre/margins-50.svg +++ b/__tests__/snapshots/dagre/margins-50.svg @@ -1,4 +1,4 @@ - + @@ -39,61 +39,61 @@ - + 0 - + 1 - + 2 - + 3 - + 4 - + 5 - + 6 - + 7 - + 8 - + 9 @@ -135,61 +135,61 @@ - + 0 - + 1 - + 2 - + 3 - + 4 - + 5 - + 6 - + 7 - + 8 - + 9 diff --git a/__tests__/snapshots/dagre/multigraph.svg b/__tests__/snapshots/dagre/multigraph.svg index f182254b..0f03c072 100644 --- a/__tests__/snapshots/dagre/multigraph.svg +++ b/__tests__/snapshots/dagre/multigraph.svg @@ -1,4 +1,4 @@ - + @@ -12,13 +12,13 @@ - + a - + b @@ -33,13 +33,13 @@ - + a - + b diff --git a/__tests__/snapshots/dagre/nodeSize-function.svg b/__tests__/snapshots/dagre/nodeSize-function.svg index 07c6468b..f63f27ca 100644 --- a/__tests__/snapshots/dagre/nodeSize-function.svg +++ b/__tests__/snapshots/dagre/nodeSize-function.svg @@ -1,4 +1,4 @@ - + @@ -39,61 +39,61 @@ - + 0 - + 1 - + 2 - + 3 - + 4 - + 5 - + 6 - + 7 - + 8 - + 9 @@ -135,61 +135,61 @@ - + 0 - + 1 - + 2 - + 3 - + 4 - + 5 - + 6 - + 7 - + 8 - + 9 diff --git a/__tests__/snapshots/dagre/nodesep-20.svg b/__tests__/snapshots/dagre/nodesep-20.svg index aca3fd46..460c1ab0 100644 --- a/__tests__/snapshots/dagre/nodesep-20.svg +++ b/__tests__/snapshots/dagre/nodesep-20.svg @@ -1,4 +1,4 @@ - + @@ -39,61 +39,61 @@ - + 0 - + 1 - + 2 - + 3 - + 4 - + 5 - + 6 - + 7 - + 8 - + 9 @@ -135,61 +135,61 @@ - + 0 - + 1 - + 2 - + 3 - + 4 - + 5 - + 6 - + 7 - + 8 - + 9 diff --git a/__tests__/snapshots/dagre/rankdir-BT.svg b/__tests__/snapshots/dagre/rankdir-BT.svg index a4ceffda..40ccbf81 100644 --- a/__tests__/snapshots/dagre/rankdir-BT.svg +++ b/__tests__/snapshots/dagre/rankdir-BT.svg @@ -1,4 +1,4 @@ - + @@ -39,61 +39,61 @@ - + 0 - + 1 - + 2 - + 3 - + 4 - + 5 - + 6 - + 7 - + 8 - + 9 @@ -135,61 +135,61 @@ - + 0 - + 1 - + 2 - + 3 - + 4 - + 5 - + 6 - + 7 - + 8 - + 9 diff --git a/__tests__/snapshots/dagre/rankdir-LR.svg b/__tests__/snapshots/dagre/rankdir-LR.svg index 37bb151b..57ae3e63 100644 --- a/__tests__/snapshots/dagre/rankdir-LR.svg +++ b/__tests__/snapshots/dagre/rankdir-LR.svg @@ -1,4 +1,4 @@ - + @@ -39,61 +39,61 @@ - + 0 - + 1 - + 2 - + 3 - + 4 - + 5 - + 6 - + 7 - + 8 - + 9 @@ -135,61 +135,61 @@ - + 0 - + 1 - + 2 - + 3 - + 4 - + 5 - + 6 - + 7 - + 8 - + 9 diff --git a/__tests__/snapshots/dagre/rankdir-RL.svg b/__tests__/snapshots/dagre/rankdir-RL.svg index 86dbe488..5af4cd44 100644 --- a/__tests__/snapshots/dagre/rankdir-RL.svg +++ b/__tests__/snapshots/dagre/rankdir-RL.svg @@ -1,4 +1,4 @@ - + @@ -39,61 +39,61 @@ - + 0 - + 1 - + 2 - + 3 - + 4 - + 5 - + 6 - + 7 - + 8 - + 9 @@ -135,61 +135,61 @@ - + 0 - + 1 - + 2 - + 3 - + 4 - + 5 - + 6 - + 7 - + 8 - + 9 diff --git a/__tests__/snapshots/dagre/rankdir-TB.svg b/__tests__/snapshots/dagre/rankdir-TB.svg index 6aedcbb1..cd2e2232 100644 --- a/__tests__/snapshots/dagre/rankdir-TB.svg +++ b/__tests__/snapshots/dagre/rankdir-TB.svg @@ -1,4 +1,4 @@ - + @@ -39,61 +39,61 @@ - + 0 - + 1 - + 2 - + 3 - + 4 - + 5 - + 6 - + 7 - + 8 - + 9 @@ -135,61 +135,61 @@ - + 0 - + 1 - + 2 - + 3 - + 4 - + 5 - + 6 - + 7 - + 8 - + 9 diff --git a/__tests__/snapshots/dagre/ranker-longest-path.svg b/__tests__/snapshots/dagre/ranker-longest-path.svg index 1e19da49..d416c7fa 100644 --- a/__tests__/snapshots/dagre/ranker-longest-path.svg +++ b/__tests__/snapshots/dagre/ranker-longest-path.svg @@ -1,4 +1,4 @@ - + @@ -39,61 +39,61 @@ - + 0 - + 1 - + 2 - + 3 - + 4 - + 5 - + 6 - + 7 - + 8 - + 9 @@ -135,61 +135,61 @@ - + 0 - + 1 - + 2 - + 3 - + 4 - + 5 - + 6 - + 7 - + 8 - + 9 diff --git a/__tests__/snapshots/dagre/ranker-tight-tree.svg b/__tests__/snapshots/dagre/ranker-tight-tree.svg index 6aedcbb1..cd2e2232 100644 --- a/__tests__/snapshots/dagre/ranker-tight-tree.svg +++ b/__tests__/snapshots/dagre/ranker-tight-tree.svg @@ -1,4 +1,4 @@ - + @@ -39,61 +39,61 @@ - + 0 - + 1 - + 2 - + 3 - + 4 - + 5 - + 6 - + 7 - + 8 - + 9 @@ -135,61 +135,61 @@ - + 0 - + 1 - + 2 - + 3 - + 4 - + 5 - + 6 - + 7 - + 8 - + 9 diff --git a/__tests__/snapshots/dagre/ranksep-20.svg b/__tests__/snapshots/dagre/ranksep-20.svg index 642144cd..f30a9522 100644 --- a/__tests__/snapshots/dagre/ranksep-20.svg +++ b/__tests__/snapshots/dagre/ranksep-20.svg @@ -1,4 +1,4 @@ - + @@ -39,61 +39,61 @@ - + 0 - + 1 - + 2 - + 3 - + 4 - + 5 - + 6 - + 7 - + 8 - + 9 @@ -135,61 +135,61 @@ - + 0 - + 1 - + 2 - + 3 - + 4 - + 5 - + 6 - + 7 - + 8 - + 9 diff --git a/__tests__/snapshots/dagre/simple-chain.svg b/__tests__/snapshots/dagre/simple-chain.svg index 656dda9b..360ec92d 100644 --- a/__tests__/snapshots/dagre/simple-chain.svg +++ b/__tests__/snapshots/dagre/simple-chain.svg @@ -1,4 +1,4 @@ - + @@ -9,19 +9,19 @@ - + a - + b - + c @@ -33,19 +33,19 @@ - + a - + b - + c diff --git a/__tests__/snapshots/dagre/tree-structure.svg b/__tests__/snapshots/dagre/tree-structure.svg index 64b9b06a..4dd37aaa 100644 --- a/__tests__/snapshots/dagre/tree-structure.svg +++ b/__tests__/snapshots/dagre/tree-structure.svg @@ -1,4 +1,4 @@ - + @@ -12,25 +12,25 @@ - + root - + child1 - + child2 - + child3 @@ -45,25 +45,25 @@ - + root - + child1 - + child2 - + child3 diff --git a/__tests__/snapshots/dagre/undirected.svg b/__tests__/snapshots/dagre/undirected.svg index 6aedcbb1..cd2e2232 100644 --- a/__tests__/snapshots/dagre/undirected.svg +++ b/__tests__/snapshots/dagre/undirected.svg @@ -1,4 +1,4 @@ - + @@ -39,61 +39,61 @@ - + 0 - + 1 - + 2 - + 3 - + 4 - + 5 - + 6 - + 7 - + 8 - + 9 @@ -135,61 +135,61 @@ - + 0 - + 1 - + 2 - + 3 - + 4 - + 5 - + 6 - + 7 - + 8 - + 9 diff --git a/__tests__/snapshots/force-atlas2/default.svg b/__tests__/snapshots/force-atlas2/default.svg index 649b9252..f96e14f7 100644 --- a/__tests__/snapshots/force-atlas2/default.svg +++ b/__tests__/snapshots/force-atlas2/default.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/force/cluster-strength-40.svg b/__tests__/snapshots/force/cluster-strength-40.svg index bf0a5f0b..11edd5e4 100644 --- a/__tests__/snapshots/force/cluster-strength-40.svg +++ b/__tests__/snapshots/force/cluster-strength-40.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/force/clustering.svg b/__tests__/snapshots/force/clustering.svg index 85d963d3..812511d3 100644 --- a/__tests__/snapshots/force/clustering.svg +++ b/__tests__/snapshots/force/clustering.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/force/custom-center.svg b/__tests__/snapshots/force/custom-center.svg index 7069afe7..36534b30 100644 --- a/__tests__/snapshots/force/custom-center.svg +++ b/__tests__/snapshots/force/custom-center.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/force/custom-dimensions.svg b/__tests__/snapshots/force/custom-dimensions.svg index 210cf929..9ad6c53f 100644 --- a/__tests__/snapshots/force/custom-dimensions.svg +++ b/__tests__/snapshots/force/custom-dimensions.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/force/damping-0.5.svg b/__tests__/snapshots/force/damping-0.5.svg index 28234c58..d8e4c3dd 100644 --- a/__tests__/snapshots/force/damping-0.5.svg +++ b/__tests__/snapshots/force/damping-0.5.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/force/default.svg b/__tests__/snapshots/force/default.svg index 3df80c10..e189677f 100644 --- a/__tests__/snapshots/force/default.svg +++ b/__tests__/snapshots/force/default.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/force/disconnected-components.svg b/__tests__/snapshots/force/disconnected-components.svg index 5e80cc09..e7120a8e 100644 --- a/__tests__/snapshots/force/disconnected-components.svg +++ b/__tests__/snapshots/force/disconnected-components.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/force/edgeStrength-100.svg b/__tests__/snapshots/force/edgeStrength-100.svg index b8258329..7e3835a8 100644 --- a/__tests__/snapshots/force/edgeStrength-100.svg +++ b/__tests__/snapshots/force/edgeStrength-100.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/force/factor-2.svg b/__tests__/snapshots/force/factor-2.svg index 817b4012..b95856bf 100644 --- a/__tests__/snapshots/force/factor-2.svg +++ b/__tests__/snapshots/force/factor-2.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/force/gravity-1.svg b/__tests__/snapshots/force/gravity-1.svg index e2138669..049d488a 100644 --- a/__tests__/snapshots/force/gravity-1.svg +++ b/__tests__/snapshots/force/gravity-1.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/force/gravity-20.svg b/__tests__/snapshots/force/gravity-20.svg index fcb94320..2012cdfa 100644 --- a/__tests__/snapshots/force/gravity-20.svg +++ b/__tests__/snapshots/force/gravity-20.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/force/linkDistance-100.svg b/__tests__/snapshots/force/linkDistance-100.svg index 68f881c4..7578a5c5 100644 --- a/__tests__/snapshots/force/linkDistance-100.svg +++ b/__tests__/snapshots/force/linkDistance-100.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/force/max-iteration-10.svg b/__tests__/snapshots/force/max-iteration-10.svg index 80d5a3c3..01420f5d 100644 --- a/__tests__/snapshots/force/max-iteration-10.svg +++ b/__tests__/snapshots/force/max-iteration-10.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/force/nodeStrength-2000.svg b/__tests__/snapshots/force/nodeStrength-2000.svg index 0d354826..21bc6e4c 100644 --- a/__tests__/snapshots/force/nodeStrength-2000.svg +++ b/__tests__/snapshots/force/nodeStrength-2000.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/force/path-graph.svg b/__tests__/snapshots/force/path-graph.svg index 777083b2..fa2095a7 100644 --- a/__tests__/snapshots/force/path-graph.svg +++ b/__tests__/snapshots/force/path-graph.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/force/preventOverlap-false.svg b/__tests__/snapshots/force/preventOverlap-false.svg index 210cf929..9ad6c53f 100644 --- a/__tests__/snapshots/force/preventOverlap-false.svg +++ b/__tests__/snapshots/force/preventOverlap-false.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/force/self-loop.svg b/__tests__/snapshots/force/self-loop.svg index 06d455f8..56f65d1b 100644 --- a/__tests__/snapshots/force/self-loop.svg +++ b/__tests__/snapshots/force/self-loop.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/force/star-graph.svg b/__tests__/snapshots/force/star-graph.svg index 88e04448..d89e0b10 100644 --- a/__tests__/snapshots/force/star-graph.svg +++ b/__tests__/snapshots/force/star-graph.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/force/threshold-max.svg b/__tests__/snapshots/force/threshold-max.svg index 210cf929..9ad6c53f 100644 --- a/__tests__/snapshots/force/threshold-max.svg +++ b/__tests__/snapshots/force/threshold-max.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/force/threshold-min.svg b/__tests__/snapshots/force/threshold-min.svg index 210cf929..9ad6c53f 100644 --- a/__tests__/snapshots/force/threshold-min.svg +++ b/__tests__/snapshots/force/threshold-min.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/fruchterman/clustering-enabled.svg b/__tests__/snapshots/fruchterman/clustering-enabled.svg index 12542501..2e2b74de 100644 --- a/__tests__/snapshots/fruchterman/clustering-enabled.svg +++ b/__tests__/snapshots/fruchterman/clustering-enabled.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/fruchterman/custom-gravity.svg b/__tests__/snapshots/fruchterman/custom-gravity.svg index ed3528f3..26d9ea8d 100644 --- a/__tests__/snapshots/fruchterman/custom-gravity.svg +++ b/__tests__/snapshots/fruchterman/custom-gravity.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/fruchterman/custom-speed.svg b/__tests__/snapshots/fruchterman/custom-speed.svg index 7ac2a2bc..ff3a3d6d 100644 --- a/__tests__/snapshots/fruchterman/custom-speed.svg +++ b/__tests__/snapshots/fruchterman/custom-speed.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/fruchterman/default.svg b/__tests__/snapshots/fruchterman/default.svg index ed3528f3..26d9ea8d 100644 --- a/__tests__/snapshots/fruchterman/default.svg +++ b/__tests__/snapshots/fruchterman/default.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/grid/cols-more-than-nodes.svg b/__tests__/snapshots/grid/cols-more-than-nodes.svg index 75eddb8e..47b56a17 100644 --- a/__tests__/snapshots/grid/cols-more-than-nodes.svg +++ b/__tests__/snapshots/grid/cols-more-than-nodes.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/grid/complex-cell-occupation.svg b/__tests__/snapshots/grid/complex-cell-occupation.svg index 1645860b..7be2139a 100644 --- a/__tests__/snapshots/grid/complex-cell-occupation.svg +++ b/__tests__/snapshots/grid/complex-cell-occupation.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/grid/condense-fixed-cols.svg b/__tests__/snapshots/grid/condense-fixed-cols.svg index fd961d8f..10d862b4 100644 --- a/__tests__/snapshots/grid/condense-fixed-cols.svg +++ b/__tests__/snapshots/grid/condense-fixed-cols.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/grid/condense-preventOverlap.svg b/__tests__/snapshots/grid/condense-preventOverlap.svg index eed4a02b..cfcd2346 100644 --- a/__tests__/snapshots/grid/condense-preventOverlap.svg +++ b/__tests__/snapshots/grid/condense-preventOverlap.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/grid/condense.svg b/__tests__/snapshots/grid/condense.svg index eed4a02b..cfcd2346 100644 --- a/__tests__/snapshots/grid/condense.svg +++ b/__tests__/snapshots/grid/condense.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/grid/custom-begin.svg b/__tests__/snapshots/grid/custom-begin.svg index 231e910e..34c3a0e0 100644 --- a/__tests__/snapshots/grid/custom-begin.svg +++ b/__tests__/snapshots/grid/custom-begin.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/grid/custom-width-height.svg b/__tests__/snapshots/grid/custom-width-height.svg index eed4a02b..cfcd2346 100644 --- a/__tests__/snapshots/grid/custom-width-height.svg +++ b/__tests__/snapshots/grid/custom-width-height.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/grid/default.svg b/__tests__/snapshots/grid/default.svg index 64a21b81..557a3869 100644 --- a/__tests__/snapshots/grid/default.svg +++ b/__tests__/snapshots/grid/default.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/grid/fixed-cols-5.svg b/__tests__/snapshots/grid/fixed-cols-5.svg index d2aeaf1c..a4b99f32 100644 --- a/__tests__/snapshots/grid/fixed-cols-5.svg +++ b/__tests__/snapshots/grid/fixed-cols-5.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/grid/fixed-rows-5.svg b/__tests__/snapshots/grid/fixed-rows-5.svg index c8fd2940..0d796b3f 100644 --- a/__tests__/snapshots/grid/fixed-rows-5.svg +++ b/__tests__/snapshots/grid/fixed-rows-5.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/grid/fixed-rows-cols-6.svg b/__tests__/snapshots/grid/fixed-rows-cols-6.svg index d0073642..b0101413 100644 --- a/__tests__/snapshots/grid/fixed-rows-cols-6.svg +++ b/__tests__/snapshots/grid/fixed-rows-cols-6.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/grid/function-nodeSize.svg b/__tests__/snapshots/grid/function-nodeSize.svg index 035b6bce..11a3d2c4 100644 --- a/__tests__/snapshots/grid/function-nodeSize.svg +++ b/__tests__/snapshots/grid/function-nodeSize.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/grid/minimal-data.svg b/__tests__/snapshots/grid/minimal-data.svg index 78326df9..b70454ec 100644 --- a/__tests__/snapshots/grid/minimal-data.svg +++ b/__tests__/snapshots/grid/minimal-data.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/grid/node-size-from-data.svg b/__tests__/snapshots/grid/node-size-from-data.svg index 215e5f83..4df7ae17 100644 --- a/__tests__/snapshots/grid/node-size-from-data.svg +++ b/__tests__/snapshots/grid/node-size-from-data.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/grid/position-function.svg b/__tests__/snapshots/grid/position-function.svg index 8969735e..c8f52e47 100644 --- a/__tests__/snapshots/grid/position-function.svg +++ b/__tests__/snapshots/grid/position-function.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/grid/position-undefined-col.svg b/__tests__/snapshots/grid/position-undefined-col.svg index d7f6bd97..bcbc9627 100644 --- a/__tests__/snapshots/grid/position-undefined-col.svg +++ b/__tests__/snapshots/grid/position-undefined-col.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/grid/position-undefined-row.svg b/__tests__/snapshots/grid/position-undefined-row.svg index 2b768532..d007bcdf 100644 --- a/__tests__/snapshots/grid/position-undefined-row.svg +++ b/__tests__/snapshots/grid/position-undefined-row.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/grid/preventOverlap-array-nodeSize.svg b/__tests__/snapshots/grid/preventOverlap-array-nodeSize.svg index 42158bc8..eed0af79 100644 --- a/__tests__/snapshots/grid/preventOverlap-array-nodeSize.svg +++ b/__tests__/snapshots/grid/preventOverlap-array-nodeSize.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/grid/preventOverlap-false.svg b/__tests__/snapshots/grid/preventOverlap-false.svg index 5b97a688..94cc05e7 100644 --- a/__tests__/snapshots/grid/preventOverlap-false.svg +++ b/__tests__/snapshots/grid/preventOverlap-false.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/grid/preventOverlap-large-nodeSize.svg b/__tests__/snapshots/grid/preventOverlap-large-nodeSize.svg index f0be8a9d..acded716 100644 --- a/__tests__/snapshots/grid/preventOverlap-large-nodeSize.svg +++ b/__tests__/snapshots/grid/preventOverlap-large-nodeSize.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/grid/reduce-small-side.svg b/__tests__/snapshots/grid/reduce-small-side.svg index 507b0a44..91906b12 100644 --- a/__tests__/snapshots/grid/reduce-small-side.svg +++ b/__tests__/snapshots/grid/reduce-small-side.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/grid/rows-cols-less-nodes.svg b/__tests__/snapshots/grid/rows-cols-less-nodes.svg index d2aeaf1c..a4b99f32 100644 --- a/__tests__/snapshots/grid/rows-cols-less-nodes.svg +++ b/__tests__/snapshots/grid/rows-cols-less-nodes.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/grid/rows-more-than-nodes.svg b/__tests__/snapshots/grid/rows-more-than-nodes.svg index e826745c..4203a2b6 100644 --- a/__tests__/snapshots/grid/rows-more-than-nodes.svg +++ b/__tests__/snapshots/grid/rows-more-than-nodes.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/grid/skip-used-cells.svg b/__tests__/snapshots/grid/skip-used-cells.svg index 951dd7b2..8d530aac 100644 --- a/__tests__/snapshots/grid/skip-used-cells.svg +++ b/__tests__/snapshots/grid/skip-used-cells.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/grid/sortBy-custom-property.svg b/__tests__/snapshots/grid/sortBy-custom-property.svg index 9c2cf2fb..1634c442 100644 --- a/__tests__/snapshots/grid/sortBy-custom-property.svg +++ b/__tests__/snapshots/grid/sortBy-custom-property.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/grid/sortBy-degree.svg b/__tests__/snapshots/grid/sortBy-degree.svg index 64a21b81..557a3869 100644 --- a/__tests__/snapshots/grid/sortBy-degree.svg +++ b/__tests__/snapshots/grid/sortBy-degree.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/grid/sortBy-id-numbers.svg b/__tests__/snapshots/grid/sortBy-id-numbers.svg index 39c39794..83dc7922 100644 --- a/__tests__/snapshots/grid/sortBy-id-numbers.svg +++ b/__tests__/snapshots/grid/sortBy-id-numbers.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/grid/sortBy-id-strings.svg b/__tests__/snapshots/grid/sortBy-id-strings.svg index 202c5c22..ea94874e 100644 --- a/__tests__/snapshots/grid/sortBy-id-strings.svg +++ b/__tests__/snapshots/grid/sortBy-id-strings.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/grid/sortBy-id.svg b/__tests__/snapshots/grid/sortBy-id.svg index d0073642..b0101413 100644 --- a/__tests__/snapshots/grid/sortBy-id.svg +++ b/__tests__/snapshots/grid/sortBy-id.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/mds/complete-graph.svg b/__tests__/snapshots/mds/complete-graph.svg index 5a4d6f87..21e3527c 100644 --- a/__tests__/snapshots/mds/complete-graph.svg +++ b/__tests__/snapshots/mds/complete-graph.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/mds/custom-center.svg b/__tests__/snapshots/mds/custom-center.svg index f3176fa4..e5e7ba99 100644 --- a/__tests__/snapshots/mds/custom-center.svg +++ b/__tests__/snapshots/mds/custom-center.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/mds/default.svg b/__tests__/snapshots/mds/default.svg index 7bd44aa2..f3229e96 100644 --- a/__tests__/snapshots/mds/default.svg +++ b/__tests__/snapshots/mds/default.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/mds/disconnected-components.svg b/__tests__/snapshots/mds/disconnected-components.svg index 479106b4..f1c731d4 100644 --- a/__tests__/snapshots/mds/disconnected-components.svg +++ b/__tests__/snapshots/mds/disconnected-components.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/mds/linkDistance-20.svg b/__tests__/snapshots/mds/linkDistance-20.svg index 5dfdbdd8..96b4b092 100644 --- a/__tests__/snapshots/mds/linkDistance-20.svg +++ b/__tests__/snapshots/mds/linkDistance-20.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/mds/linkDistance-60.svg b/__tests__/snapshots/mds/linkDistance-60.svg index 11df40c0..832a3bf5 100644 --- a/__tests__/snapshots/mds/linkDistance-60.svg +++ b/__tests__/snapshots/mds/linkDistance-60.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/mds/path-graph.svg b/__tests__/snapshots/mds/path-graph.svg index 8013b530..9c6bfa50 100644 --- a/__tests__/snapshots/mds/path-graph.svg +++ b/__tests__/snapshots/mds/path-graph.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/mds/star-graph.svg b/__tests__/snapshots/mds/star-graph.svg index 20f46ca1..469e26d5 100644 --- a/__tests__/snapshots/mds/star-graph.svg +++ b/__tests__/snapshots/mds/star-graph.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/radial/combined-options.svg b/__tests__/snapshots/radial/combined-options.svg index fb0bc015..cfb2abd2 100644 --- a/__tests__/snapshots/radial/combined-options.svg +++ b/__tests__/snapshots/radial/combined-options.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/radial/custom-center.svg b/__tests__/snapshots/radial/custom-center.svg index 8d1bf255..0f90c735 100644 --- a/__tests__/snapshots/radial/custom-center.svg +++ b/__tests__/snapshots/radial/custom-center.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/radial/default.svg b/__tests__/snapshots/radial/default.svg index 38b90d78..6157b332 100644 --- a/__tests__/snapshots/radial/default.svg +++ b/__tests__/snapshots/radial/default.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/radial/disconnected-components.svg b/__tests__/snapshots/radial/disconnected-components.svg index 871dcda5..8676f45f 100644 --- a/__tests__/snapshots/radial/disconnected-components.svg +++ b/__tests__/snapshots/radial/disconnected-components.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/radial/exact-same-position.svg b/__tests__/snapshots/radial/exact-same-position.svg index bc68b9d2..966c8cfa 100644 --- a/__tests__/snapshots/radial/exact-same-position.svg +++ b/__tests__/snapshots/radial/exact-same-position.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/radial/focusNode-1.svg b/__tests__/snapshots/radial/focusNode-1.svg index 9e5b125e..90ee4d1a 100644 --- a/__tests__/snapshots/radial/focusNode-1.svg +++ b/__tests__/snapshots/radial/focusNode-1.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/radial/inexistent-focusNode.svg b/__tests__/snapshots/radial/inexistent-focusNode.svg index 38b90d78..6157b332 100644 --- a/__tests__/snapshots/radial/inexistent-focusNode.svg +++ b/__tests__/snapshots/radial/inexistent-focusNode.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/radial/linkDistance-30.svg b/__tests__/snapshots/radial/linkDistance-30.svg index f5d10dc8..1afd4d15 100644 --- a/__tests__/snapshots/radial/linkDistance-30.svg +++ b/__tests__/snapshots/radial/linkDistance-30.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/radial/maxIteration-2000.svg b/__tests__/snapshots/radial/maxIteration-2000.svg index 893c14de..b36bfa14 100644 --- a/__tests__/snapshots/radial/maxIteration-2000.svg +++ b/__tests__/snapshots/radial/maxIteration-2000.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/radial/minimal-graph.svg b/__tests__/snapshots/radial/minimal-graph.svg index 286e2786..1a12f06c 100644 --- a/__tests__/snapshots/radial/minimal-graph.svg +++ b/__tests__/snapshots/radial/minimal-graph.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/radial/overlapping-same-position.svg b/__tests__/snapshots/radial/overlapping-same-position.svg index 0b51fa8f..c6173f58 100644 --- a/__tests__/snapshots/radial/overlapping-same-position.svg +++ b/__tests__/snapshots/radial/overlapping-same-position.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/radial/preventOverlap-enabled.svg b/__tests__/snapshots/radial/preventOverlap-enabled.svg index ba645ed1..55f59617 100644 --- a/__tests__/snapshots/radial/preventOverlap-enabled.svg +++ b/__tests__/snapshots/radial/preventOverlap-enabled.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/radial/preventOverlap-large-nodeSize.svg b/__tests__/snapshots/radial/preventOverlap-large-nodeSize.svg index aa5e9774..88fd1361 100644 --- a/__tests__/snapshots/radial/preventOverlap-large-nodeSize.svg +++ b/__tests__/snapshots/radial/preventOverlap-large-nodeSize.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/radial/preventOverlap-with-sortBy.svg b/__tests__/snapshots/radial/preventOverlap-with-sortBy.svg index c2676822..4b4f2df5 100644 --- a/__tests__/snapshots/radial/preventOverlap-with-sortBy.svg +++ b/__tests__/snapshots/radial/preventOverlap-with-sortBy.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/radial/sortBy-data.svg b/__tests__/snapshots/radial/sortBy-data.svg index 360639af..3ac57fdb 100644 --- a/__tests__/snapshots/radial/sortBy-data.svg +++ b/__tests__/snapshots/radial/sortBy-data.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/radial/sortBy-id.svg b/__tests__/snapshots/radial/sortBy-id.svg index e02ecc98..26562ad7 100644 --- a/__tests__/snapshots/radial/sortBy-id.svg +++ b/__tests__/snapshots/radial/sortBy-id.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/radial/sortStrength-50.svg b/__tests__/snapshots/radial/sortStrength-50.svg index bab320d9..970a3100 100644 --- a/__tests__/snapshots/radial/sortStrength-50.svg +++ b/__tests__/snapshots/radial/sortStrength-50.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/radial/strictRadial-false.svg b/__tests__/snapshots/radial/strictRadial-false.svg index 797bb79a..70fd7d37 100644 --- a/__tests__/snapshots/radial/strictRadial-false.svg +++ b/__tests__/snapshots/radial/strictRadial-false.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/radial/strictRadial-true.svg b/__tests__/snapshots/radial/strictRadial-true.svg index c906b253..e8037962 100644 --- a/__tests__/snapshots/radial/strictRadial-true.svg +++ b/__tests__/snapshots/radial/strictRadial-true.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/radial/unitRadius-100.svg b/__tests__/snapshots/radial/unitRadius-100.svg index 4de01ca2..7447e8cd 100644 --- a/__tests__/snapshots/radial/unitRadius-100.svg +++ b/__tests__/snapshots/radial/unitRadius-100.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/random/default.svg b/__tests__/snapshots/random/default.svg index 85f833d6..e9cabac2 100644 --- a/__tests__/snapshots/random/default.svg +++ b/__tests__/snapshots/random/default.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/random/disconnected-graph.svg b/__tests__/snapshots/random/disconnected-graph.svg index bf3a04ec..ea184070 100644 --- a/__tests__/snapshots/random/disconnected-graph.svg +++ b/__tests__/snapshots/random/disconnected-graph.svg @@ -1,4 +1,4 @@ - + diff --git a/__tests__/snapshots/tree-layouts/fishbone.svg b/__tests__/snapshots/tree-layouts/fishbone.svg new file mode 100644 index 00000000..4423885d --- /dev/null +++ b/__tests__/snapshots/tree-layouts/fishbone.svg @@ -0,0 +1,180 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Delivery Risk + + + + + + People + + + + + + Process + + + + + + Tools + + + + + + Skill gaps + + + + + + Late reviews + + + + + + Unclear scope + + + + + + Late changes + + + + + + Missing tests + + + + + + Build failures + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Delivery Risk + + + + + + People + + + + + + Process + + + + + + Tools + + + + + + Skill gaps + + + + + + Late reviews + + + + + + Unclear scope + + + + + + Late changes + + + + + + Missing tests + + + + + + Build failures + + + + + diff --git a/__tests__/snapshots/tree-layouts/indented.svg b/__tests__/snapshots/tree-layouts/indented.svg new file mode 100644 index 00000000..16566ffc --- /dev/null +++ b/__tests__/snapshots/tree-layouts/indented.svg @@ -0,0 +1,162 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Design System + + + + + + Foundations + + + + + + Colors + + + + + + Typography + + + + + + Components + + + + + + Buttons + + + + + + Forms + + + + + + Guidelines + + + + + + Accessibility + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Design System + + + + + + Foundations + + + + + + Colors + + + + + + Typography + + + + + + Components + + + + + + Buttons + + + + + + Forms + + + + + + Guidelines + + + + + + Accessibility + + + + + diff --git a/__tests__/snapshots/tree-layouts/mindmap.svg b/__tests__/snapshots/tree-layouts/mindmap.svg new file mode 100644 index 00000000..ca35a299 --- /dev/null +++ b/__tests__/snapshots/tree-layouts/mindmap.svg @@ -0,0 +1,234 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Product Strategy + + + + + + Research + + + + + + Design + + + + + + Delivery + + + + + + Engineering + + + + + + Quality + + + + + + Growth + + + + + + Interviews + + + + + + Prototypes + + + + + + Milestones + + + + + + Architecture + + + + + + Automation + + + + + + Activation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Product Strategy + + + + + + Research + + + + + + Design + + + + + + Delivery + + + + + + Engineering + + + + + + Quality + + + + + + Growth + + + + + + Interviews + + + + + + Prototypes + + + + + + Milestones + + + + + + Architecture + + + + + + Automation + + + + + + Activation + + + + + diff --git a/__tests__/unit/antv-dagre/acyclic.test.ts b/__tests__/unit/antv-dagre/acyclic.test.ts index 657efe76..8d1e4d44 100644 --- a/__tests__/unit/antv-dagre/acyclic.test.ts +++ b/__tests__/unit/antv-dagre/acyclic.test.ts @@ -1,6 +1,9 @@ import { run, undo } from '@/src/algorithm/antv-dagre/acyclic'; +import { + DagreGraph as Graph, + type GraphEdge, +} from '@/src/algorithm/antv-dagre/graph'; import type { EdgeData } from '@/src/types'; -import { DagreGraph as Graph } from '@/src/algorithm/antv-dagre/graph'; import { findCycles } from '../../utils'; describe('acyclic', function () { @@ -370,7 +373,7 @@ describe('acyclic', function () { }); }); -function stripLabel(edge: Edge) { +function stripLabel(edge: GraphEdge) { let c = { ...edge }; delete c.data.label; return c; diff --git a/__tests__/unit/antv-dagre/rank/network-simplex.test.ts b/__tests__/unit/antv-dagre/rank/network-simplex.test.ts index 511aa3b4..e4c590f3 100644 --- a/__tests__/unit/antv-dagre/rank/network-simplex.test.ts +++ b/__tests__/unit/antv-dagre/rank/network-simplex.test.ts @@ -976,7 +976,11 @@ describe('network simplex', function () { describe('initLowLimValues', function () { it('assigns low, lim, and parent for each node in a tree', function () { - let g = new Graph({ + let g = new Graph<{ + low?: number; + lim?: number; + parent?: string; + }>({ nodes: [ { id: 'a', @@ -1058,17 +1062,17 @@ describe('network simplex', function () { expect(a.data.lim).toEqual(5); expect(b.data.parent).toEqual('a'); - expect(b.data.lim).toBeLessThan(a.data.lim); + expect(b.data.lim).toBeLessThan(a.data.lim!); expect(c.data.parent).toEqual('a'); - expect(c.data.lim).toBeLessThan(a.data.lim); + expect(c.data.lim).toBeLessThan(a.data.lim!); expect(c.data.lim).not.toEqual(b.data.lim); expect(d.data.parent).toEqual('c'); - expect(d.data.lim).toBeLessThan(c.data.lim); + expect(d.data.lim).toBeLessThan(c.data.lim!); expect(e.data.parent).toEqual('c'); - expect(e.data.lim).toBeLessThan(c.data.lim); + expect(e.data.lim).toBeLessThan(c.data.lim!); expect(e.data.lim).not.toEqual(d.data.lim); }); }); diff --git a/__tests__/unit/combo-combined.test.ts b/__tests__/unit/combo-combined.test.ts index 1c11c732..ae911e78 100644 --- a/__tests__/unit/combo-combined.test.ts +++ b/__tests__/unit/combo-combined.test.ts @@ -1,5 +1,6 @@ import { ComboCombinedLayout } from '@/src'; import { registry } from '@/src/registry'; +import { parseSize } from '@/src/util'; import { createCanvas } from '@@/utils/create'; import type { Canvas } from '@antv/g'; import { clear as clearMockRandom, mock as mockRandom } from 'jest-random-mock'; @@ -72,10 +73,12 @@ describe('layout combo-combined', () => { const comboA = nodesById.get('combo-a')!; const comboA1 = nodesById.get('combo-a1')!; + const [aWidth, aHeight] = parseSize(comboA.size); + const [a1Width, a1Height] = parseSize(comboA1.size); expect(comboA.isCombo).toBeTruthy(); expect(comboA1.isCombo).toBeTruthy(); - expect(comboA.size[0]).toBeGreaterThan(comboA1.size[0]); - expect(comboA.size[1]).toBeGreaterThan(comboA1.size[1]); + expect(aWidth).toBeGreaterThan(a1Width); + expect(aHeight).toBeGreaterThan(a1Height); const assertCombo = (comboId: string, leafNodeIds: string[]) => { const combo = nodesById.get(comboId); @@ -260,12 +263,16 @@ describe('layout combo-combined', () => { const inner1 = byId1.get('inner')!; const loose1 = byId1.get('loose')!; - expect(mix1.size[0]).toBeGreaterThan(mix0.size[0]); - expect(mix1.size[1]).toBeGreaterThan(mix0.size[1]); + const [mix0Width, mix0Height] = parseSize(mix0.size); + const [mix1Width, mix1Height] = parseSize(mix1.size); + const [inner0Width, inner0Height] = parseSize(inner0.size); + const [inner1Width, inner1Height] = parseSize(inner1.size); + expect(mix1Width).toBeGreaterThan(mix0Width); + expect(mix1Height).toBeGreaterThan(mix0Height); // inner contains only nodes, so it should expand with comboPadding. - expect(inner1.size[0]).toBeGreaterThan(inner0.size[0]); - expect(inner1.size[1]).toBeGreaterThan(inner0.size[1]); + expect(inner1Width).toBeGreaterThan(inner0Width); + expect(inner1Height).toBeGreaterThan(inner0Height); }); it('returns empty output for empty graph', async () => { diff --git a/__tests__/unit/concentric.test.ts b/__tests__/unit/concentric.test.ts index c7d11fb4..dcd48d1e 100644 --- a/__tests__/unit/concentric.test.ts +++ b/__tests__/unit/concentric.test.ts @@ -2,8 +2,7 @@ import { ConcentricLayout } from '@/src'; import { createCanvas } from '@@/utils/create'; import type { Canvas } from '@antv/g'; import { countries as data } from '../dataset'; -import { GraphRenderer, RenderOptions } from '../utils'; -import { calculatePositions } from '../utils'; +import { calculatePositions, GraphRenderer, RenderOptions } from '../utils'; describe('layout concentric', () => { let canvas: Canvas; @@ -25,7 +24,7 @@ describe('layout concentric', () => { canvas = createCanvas(); const { width, height } = canvas.getConfig(); concentricLayout = new ConcentricLayout({ - center: [width / 2, height / 2], + center: [width! / 2, height! / 2], }); renderer = new GraphRenderer(canvas); }); diff --git a/__tests__/unit/d3-force-3d.test.ts b/__tests__/unit/d3-force-3d.test.ts index 15dcc966..2885b0bc 100644 --- a/__tests__/unit/d3-force-3d.test.ts +++ b/__tests__/unit/d3-force-3d.test.ts @@ -21,7 +21,7 @@ describe('d3 force 3d', () => { test('tick layout', async () => { const d3Force3D = new D3Force3DLayout(); - const onTick = jest.fn(); + const onTick = vi.fn(); await d3Force3D.execute(data, { onTick, diff --git a/__tests__/unit/d3-force.test.ts b/__tests__/unit/d3-force.test.ts index ac6cacea..cb82ffe5 100644 --- a/__tests__/unit/d3-force.test.ts +++ b/__tests__/unit/d3-force.test.ts @@ -1,4 +1,7 @@ -import { D3ForceLayout } from '@/src'; +import { D3ForceLayout, type D3ForceLayoutOptions } from '@/src'; +import type { Layout } from '@/src/algorithm/types'; +import type { EdgeData, NodeData } from '@/src/types'; +import { parseSize } from '@/src/util'; import { createCanvas } from '@@/utils/create'; import type { Canvas } from '@antv/g'; import { clear as clearMockRandom, mock as mockRandom } from 'jest-random-mock'; @@ -22,8 +25,8 @@ describe('layout d3-force', () => { mockRandom(); canvas = createCanvas(null, 700, 700); renderer = new GraphRenderer(canvas); - width = canvas.getConfig().width; - height = canvas.getConfig().height; + width = canvas.getConfig().width!; + height = canvas.getConfig().height!; }); afterEach(() => { @@ -47,7 +50,7 @@ describe('layout d3-force', () => { it('should render inside specified viewport', async () => { const constrainBox = { x: 60, y: 50, width: 500, height: 150 }; - const onTick = (layout) => { + const onTick = (layout: Layout) => { let minx = 99999999; let maxx = -99999999; let miny = 99999999; @@ -66,8 +69,9 @@ describe('layout d3-force', () => { if (maxy < node.y) { maxy = node.y; } - if (maxsize < node.size) { - maxsize = node.size; + const [size] = parseSize(node.size); + if (maxsize < size) { + maxsize = size; } }); const scalex = (constrainBox.width - maxsize) / (maxx - minx); @@ -278,7 +282,7 @@ describe('layout d3-force', () => { }; const d3Force = new D3ForceLayout(); await d3Force.execute(positionGraph, { - node: (d) => ({ + node: (d: NodeData) => ({ id: d.id, x: d.data.x, y: d.data.y, @@ -396,7 +400,7 @@ describe('layout d3-force', () => { }); it('should handle disabled forces', async () => { - const d3Force = new D3ForceLayout({ + const d3Force = new D3ForceLayout({ width, height, center: false, @@ -416,11 +420,11 @@ describe('layout d3-force', () => { const d3Force = new D3ForceLayout({ width, height, - nodeSize: (d) => (d.id === 'a' ? 20 : 10), - nodeSpacing: (d) => (d.id === 'a' ? 5 : 2), - nodeStrength: (d) => (d.id === 'a' ? -50 : -30), - linkDistance: (d) => (d.source === 'a' ? 100 : 50), - edgeStrength: (d) => (d.source === 'a' ? 0.8 : 0.5), + nodeSize: (d: NodeData) => (d.id === 'a' ? 20 : 10), + nodeSpacing: (d: NodeData) => (d.id === 'a' ? 5 : 2), + nodeStrength: (d: NodeData) => (d.id === 'a' ? -50 : -30), + linkDistance: (d: EdgeData) => (d.source === 'a' ? 100 : 50), + edgeStrength: (d: EdgeData) => (d.source === 'a' ? 0.8 : 0.5), x: {}, y: {}, }); diff --git a/__tests__/unit/dagre.test.ts b/__tests__/unit/dagre.test.ts index 76071895..01c9491f 100644 --- a/__tests__/unit/dagre.test.ts +++ b/__tests__/unit/dagre.test.ts @@ -1,11 +1,11 @@ import { DagreLayout } from '@/src'; import type { Point } from '@/src/types'; +import { parseSize } from '@/src/util'; import { createCanvas } from '@@/utils/create'; import type { Canvas } from '@antv/g'; import { clear as clearMockRandom, mock as mockRandom } from 'jest-random-mock'; import { combo as comboData, dagre as data } from '../dataset'; -import { GraphRenderer } from '../utils'; -import { calculatePositions } from '../utils'; +import { calculatePositions, GraphRenderer } from '../utils'; describe('layout dagre', () => { let canvas: Canvas; @@ -25,11 +25,12 @@ describe('layout dagre', () => { // Apply rect positioning for dagre layout.forEachNode((node) => { if (node.size) { + 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, }); } }); @@ -429,9 +430,9 @@ describe('layout dagre', () => { expect(positions.edges).toHaveLength(2); // In TB direction, y positions should increase - const nodeA = positions.nodes.find((n) => n.id === 'a'); - const nodeB = positions.nodes.find((n) => n.id === 'b'); - const nodeC = positions.nodes.find((n) => n.id === 'c'); + const nodeA = positions.nodes.find((n) => n.id === 'a')!; + const nodeB = positions.nodes.find((n) => n.id === 'b')!; + const nodeC = positions.nodes.find((n) => n.id === 'c')!; expect(nodeA.y).toBeLessThan(nodeB.y); expect(nodeB.y).toBeLessThan(nodeC.y); @@ -505,8 +506,7 @@ describe('layout dagre', () => { positions.nodes.forEach((node) => { expect(Number.isFinite(node.x)).toBe(true); expect(Number.isFinite(node.y)).toBe(true); - if (node.size) { - expect(Array.isArray(node.size)).toBe(true); + if (Array.isArray(node.size)) { expect(node.size.length).toBe(2); expect(Number.isFinite(node.size[0])).toBe(true); expect(Number.isFinite(node.size[1])).toBe(true); diff --git a/__tests__/unit/force.test.ts b/__tests__/unit/force.test.ts index 67dd2b8c..a744abac 100644 --- a/__tests__/unit/force.test.ts +++ b/__tests__/unit/force.test.ts @@ -1,17 +1,22 @@ import { ForceLayout } from '@/src'; +import type { Layout } from '@/src/algorithm/types'; +import type { GraphData } from '@/src/types'; import { createCanvas } from '@@/utils/create'; import type { Canvas } from '@antv/g'; import { clear as clearMockRandom, mock as mockRandom } from 'jest-random-mock'; import { cluster } from '../dataset'; -import { GraphRenderer, preprocessGraphData } from '../utils'; -import { calculatePositions } from '../utils'; +import { + calculatePositions, + GraphRenderer, + preprocessGraphData, +} from '../utils'; describe('layout force', () => { let canvas: Canvas; let width: number; let height: number; let renderer: GraphRenderer; - let data; + let data: GraphData; beforeEach(() => { mockRandom(); @@ -228,7 +233,7 @@ describe('layout force', () => { it('should handle onTick callback', async () => { let tickCount = 0; - const onTick = (layout: any) => { + const onTick = (layout: Layout) => { layout.forEachNode((node) => { expect(node.x).toBeDefined(); expect(node.y).toBeDefined(); @@ -393,7 +398,7 @@ describe('layout force', () => { it('should handle fixed node positions', async () => { const fixedGraph = { nodes: [ - { id: 'a', data: { fx: 100, fy: 100 } }, + { id: 'a', fx: 100, fy: 100, data: {} }, { id: 'b', data: {} }, { id: 'c', data: {} }, ], @@ -402,13 +407,7 @@ describe('layout force', () => { { id: 'e2', source: 'b', target: 'c', data: {} }, ], }; - const layout = new ForceLayout({ - node: (d) => ({ - fx: d.data.fx, - fy: d.data.fy, - }), - maxIteration: 100, - }); + const layout = new ForceLayout({ maxIteration: 100 }); layout.execute(fixedGraph); layout.stop(); layout.tick(100); diff --git a/__tests__/unit/fruchterman.test.ts b/__tests__/unit/fruchterman.test.ts index 065bc1e6..9a0d4ccd 100644 --- a/__tests__/unit/fruchterman.test.ts +++ b/__tests__/unit/fruchterman.test.ts @@ -2,9 +2,12 @@ import { FruchtermanLayout } from '@/src'; import { Canvas } from '@antv/g'; import { clear as clearMockRandom, mock as mockRandom } from 'jest-random-mock'; import { fruchterman as fruchtermanData } from '../dataset'; -import { createCanvas, getEuclideanDistance } from '../utils'; +import { + calculatePositions, + createCanvas, + getEuclideanDistance, +} from '../utils'; import { preprocessGraphData } from '../utils/preprocess'; -import { calculatePositions } from '../utils'; import { GraphRenderer } from '../utils/renderer'; describe('FruchtermanLayout', () => { @@ -96,7 +99,7 @@ describe('FruchtermanLayout', () => { fruchterman.setFixedPosition('n1', [100, 200]); fruchterman.tick(10); const positions = calculatePositions(fruchterman); - const node = positions.nodes.find((node) => node.id === 'n1'); + const node = positions.nodes.find((node) => node.id === 'n1')!; expect(node.x).toBe(100); expect(node.y).toBe(200); }); @@ -112,7 +115,7 @@ describe('FruchtermanLayout', () => { fruchterman.tick(10); const positions = calculatePositions(fruchterman); - const node = positions.nodes.find((node) => node.id === 'n1'); + const node = positions.nodes.find((node) => node.id === 'n1')!; expect(node.x).toBe(100); expect(node.y).toBe(200); expect(node.z).toBe(300); @@ -148,7 +151,7 @@ describe('FruchtermanLayout', () => { const positions = calculatePositions(fruchterman); // z 轴有变化 - const before = graph.nodes.find((n) => n.id === 'n1').data.z; + const before = graph.nodes.find((n) => n.id === 'n1')!.data.z; expect(positions.nodes[0].z).not.toBe(before); }); @@ -461,7 +464,7 @@ describe('FruchtermanLayout', () => { fruchterman.stop(); fruchterman.tick(1); const positions = calculatePositions(fruchterman); - const node1 = positions.nodes.find((n) => n.id === 'n1'); + const node1 = positions.nodes.find((n) => n.id === 'n1')!; expect(node1.z).toBe(3); }); diff --git a/__tests__/unit/tree-layouts.test.ts b/__tests__/unit/tree-layouts.test.ts new file mode 100644 index 00000000..c484613a --- /dev/null +++ b/__tests__/unit/tree-layouts.test.ts @@ -0,0 +1,190 @@ +import { FishboneLayout } from '@/src/algorithm/fishbone'; +import { IndentedLayout } from '@/src/algorithm/indented'; +import { MindmapLayout } from '@/src/algorithm/mindmap'; +import type { Layout } from '@/src/algorithm/types'; +import type { GraphData } from '@/src/types'; +import { createCanvas } from '@@/utils/create'; +import type { Canvas } from '@antv/g'; +import { GraphRenderer } from '../utils'; + +let canvas: Canvas; + +function createRenderer(width: number, height: number) { + canvas = createCanvas(null, width, height); + return new GraphRenderer(canvas); +} + +function renderLayout( + renderer: GraphRenderer, + layout: Layout, + data: GraphData, +) { + renderer.render( + layout, + { + nodeShape: 'rect', + nodeSize: { width: 140, height: 40 }, + nodeStyle: { + fill: '#F8FAFC', + stroke: '#CBD5E1', + lineWidth: 1.2, + rx: 9, + ry: 9, + }, + edgeStyle: { stroke: '#CBD5E1', lineWidth: 1.2 }, + showLabel: true, + labelStyle: { fontSize: 12, fill: '#334155', fontWeight: 500 }, + enableDrag: false, + }, + data, + ); +} + +function offsetNodes(layout: Layout, dx: number, dy: number) { + layout.forEachNode((node) => { + node.x += dx; + node.y += dy; + }); +} + +describe('tree layout snapshots', () => { + afterEach(() => { + canvas.destroy(); + }); + + it('should render a fishbone diagram', async () => { + const renderer = createRenderer(1000, 600); + const layout = new FishboneLayout({ + categoryGap: 190, + categoryDistance: 200, + itemHStep: 30, + getWidth: () => 140, + getHeight: () => 40, + }); + const data: GraphData = { + nodes: [ + { id: 'Delivery Risk', style: { fill: '#FEF3C7', stroke: '#F59E0B' } }, + { id: 'People', style: { fill: '#DBEAFE', stroke: '#60A5FA' } }, + { id: 'Process', style: { fill: '#D1FAE5', stroke: '#34D399' } }, + { id: 'Tools', style: { fill: '#EDE9FE', stroke: '#A78BFA' } }, + { id: 'Skill gaps', style: { fill: '#DBEAFE' } }, + { id: 'Late reviews', style: { fill: '#EFF6FF' } }, + { id: 'Unclear scope', style: { fill: '#D1FAE5' } }, + { id: 'Late changes', style: { fill: '#ECFDF5' } }, + { id: 'Missing tests', style: { fill: '#F3E8FF' } }, + { id: 'Build failures', style: { fill: '#FAF5FF' } }, + ], + edges: [ + { source: 'Delivery Risk', target: 'People' }, + { source: 'Delivery Risk', target: 'Process' }, + { source: 'Delivery Risk', target: 'Tools' }, + { source: 'People', target: 'Skill gaps' }, + { source: 'People', target: 'Late reviews' }, + { source: 'Process', target: 'Unclear scope' }, + { source: 'Process', target: 'Late changes' }, + { source: 'Tools', target: 'Missing tests' }, + { source: 'Tools', target: 'Build failures' }, + ], + }; + await layout.execute(data); + + renderLayout(renderer, layout, data); + await expect(canvas).toMatchSnapshot(__filename, 'fishbone'); + }); + + it('should render an indented design-system tree', async () => { + const renderer = createRenderer(600, 540); + const data: GraphData = { + nodes: [ + { + id: 'Design System', + data: {}, + style: { fill: '#C7D2FE', stroke: '#818CF8' }, + }, + { id: 'Foundations', data: {}, style: { fill: '#DDD6FE' } }, + { id: 'Colors', data: {} }, + { id: 'Typography', data: {} }, + { id: 'Components', data: {}, style: { fill: '#DDD6FE' } }, + { id: 'Buttons', data: {} }, + { id: 'Forms', data: {} }, + { id: 'Guidelines', data: {}, style: { fill: '#DDD6FE' } }, + { id: 'Accessibility', data: {} }, + ], + edges: [ + { source: 'Design System', target: 'Foundations' }, + { source: 'Foundations', target: 'Colors' }, + { source: 'Foundations', target: 'Typography' }, + { source: 'Design System', target: 'Components' }, + { source: 'Components', target: 'Buttons' }, + { source: 'Components', target: 'Forms' }, + { source: 'Design System', target: 'Guidelines' }, + { source: 'Guidelines', target: 'Accessibility' }, + ], + }; + const layout = new IndentedLayout({ + rootId: 'Design System', + indent: 180, + rowHeight: 54, + nodeColors: ['#C7D2FE', '#DDD6FE', '#EDE9FE'], + edgeColors: ['#4F46E5', '#8B5CF6', '#C4B5FD'], + }); + await layout.execute(data); + offsetNodes(layout, 80, 60); + + renderLayout(renderer, layout, data); + await expect(canvas).toMatchSnapshot(__filename, 'indented'); + }); + + it('should render a balanced mindmap', async () => { + const renderer = createRenderer(1100, 520); + const layout = new MindmapLayout({ + levelGap: 90, + nodeGap: 36, + branchColors: ['#BFDBFE', '#FBCFE8'], + getWidth: () => 140, + getHeight: () => 40, + getSide: (_node, index, parentSide) => + parentSide ?? (index % 2 === 0 ? 'left' : 'right'), + }); + const data: GraphData = { + nodes: [ + { + id: 'Product Strategy', + data: {}, + style: { fill: '#FEF3C7', stroke: '#D97706' }, + }, + { id: 'Research', data: {} }, + { id: 'Design', data: {} }, + { id: 'Delivery', data: {} }, + { id: 'Engineering', data: {} }, + { id: 'Quality', data: {} }, + { id: 'Growth', data: {} }, + { id: 'Interviews', data: {}, style: { fill: '#EFF6FF' } }, + { id: 'Prototypes', data: {}, style: { fill: '#FFF1F2' } }, + { id: 'Milestones', data: {}, style: { fill: '#EFF6FF' } }, + { id: 'Architecture', data: {}, style: { fill: '#FFF1F2' } }, + { id: 'Automation', data: {}, style: { fill: '#EFF6FF' } }, + { id: 'Activation', data: {}, style: { fill: '#FFF1F2' } }, + ], + edges: [ + { source: 'Product Strategy', target: 'Research' }, + { source: 'Product Strategy', target: 'Design' }, + { source: 'Product Strategy', target: 'Delivery' }, + { source: 'Product Strategy', target: 'Engineering' }, + { source: 'Product Strategy', target: 'Quality' }, + { source: 'Product Strategy', target: 'Growth' }, + { source: 'Research', target: 'Interviews' }, + { source: 'Design', target: 'Prototypes' }, + { source: 'Delivery', target: 'Milestones' }, + { source: 'Engineering', target: 'Architecture' }, + { source: 'Quality', target: 'Automation' }, + { source: 'Growth', target: 'Activation' }, + ], + }; + await layout.execute(data); + offsetNodes(layout, 550, 260); + + renderLayout(renderer, layout, data); + await expect(canvas).toMatchSnapshot(__filename, 'mindmap'); + }); +}); diff --git a/__tests__/unit/util/format.test.ts b/__tests__/unit/util/format.test.ts index 03e00460..38096651 100644 --- a/__tests__/unit/util/format.test.ts +++ b/__tests__/unit/util/format.test.ts @@ -9,12 +9,12 @@ describe('format', () => { describe('formatNumberFn', () => { test('should return function that returns default value when value is undefined', () => { const result = formatNumberFn(undefined, 10); - expect(result()).toBe(10); + expect(result({})).toBe(10); }); test('should return function that returns number when value is number', () => { const result = formatNumberFn(20, 10); - expect(result()).toBe(20); + expect(result({})).toBe(20); expect(result({ id: 'test' } as any)).toBe(20); }); @@ -26,52 +26,52 @@ describe('format', () => { test('should return default value for invalid types', () => { const result = formatNumberFn('invalid' as any, 10); - expect(result()).toBe(10); + expect(result({})).toBe(10); }); test('should handle zero as valid number', () => { const result = formatNumberFn(0, 10); - expect(result()).toBe(0); + expect(result({})).toBe(0); }); test('should handle negative numbers', () => { const result = formatNumberFn(-5, 10); - expect(result()).toBe(-5); + expect(result({})).toBe(-5); }); test('should handle fractional numbers', () => { const result = formatNumberFn(3.14, 10); - expect(result()).toBe(3.14); + expect(result({})).toBe(3.14); }); test('should handle function returning zero', () => { const customFn = () => 0; const result = formatNumberFn(customFn, 10); - expect(result()).toBe(0); + expect(result({})).toBe(0); }); test('should handle function receiving undefined data', () => { const customFn = (d?: any) => d?.value || 5; const result = formatNumberFn(customFn, 10); - expect(result()).toBe(5); + expect(result({})).toBe(5); expect(result(undefined)).toBe(5); }); test('should handle null value', () => { const result = formatNumberFn(null as any, 10); - expect(result()).toBe(10); + expect(result({})).toBe(10); }); }); describe('formatSizeFn', () => { test('should use default value when value is undefined', () => { const result = formatSizeFn(undefined, 10); - expect(result()).toBe(10); + expect(result({})).toBe(10); }); test('should return number when value is number', () => { const result = formatSizeFn(15, 10); - expect(result()).toBe(15); + expect(result({})).toBe(15); }); test('should return function result when value is function', () => { @@ -82,12 +82,12 @@ describe('format', () => { test('should handle array value and return array', () => { const result = formatSizeFn([20, 30], 10); - expect(result()).toEqual([20, 30]); + expect(result({})).toEqual([20, 30]); }); test('should return default value when value is undefined and no node provided', () => { const result = formatSizeFn(undefined, 10); - expect(result()).toBe(10); + expect(result({})).toBe(10); }); test('should return default value when value is undefined and node has data but no data field', () => { @@ -101,7 +101,7 @@ describe('format', () => { test('should handle number zero as valid size', () => { const result = formatSizeFn(0, 10); - expect(result()).toBe(0); + expect(result({})).toBe(0); }); test('should return default value when data has no size', () => { @@ -115,23 +115,23 @@ describe('format', () => { test('should handle single element array', () => { const result = formatSizeFn([25], 10); - expect(result()).toEqual([25]); + expect(result({})).toEqual([25]); }); test('should handle negative sizes in array', () => { const result = formatSizeFn([-10, -5], 10); - expect(result()).toEqual([-10, -5]); + expect(result({})).toEqual([-10, -5]); }); test('should handle function returning array', () => { const customFn = () => [15, 25]; const result = formatSizeFn(customFn, 10); - expect(result()).toEqual([15, 25]); + expect(result({})).toEqual([15, 25]); }); test('should handle null value', () => { const result = formatSizeFn(null as any, 10); - expect(result()).toBe(10); + expect(result({})).toBe(10); }); test('should prioritize provided value over node data', () => { @@ -147,27 +147,27 @@ describe('format', () => { describe('formatNodeSizeFn', () => { test('should return node size plus spacing', () => { const result = formatNodeSizeFn(20, 5, 10); - expect(result()).toEqual([25, 25, 25]); + expect(result({})).toEqual([25, 25, 25]); }); test('should use default node size when nodeSize is undefined', () => { const result = formatNodeSizeFn(undefined, 5, 15); - expect(result()).toEqual([20, 20, 20]); // 15 + 5 + expect(result({})).toEqual([20, 20, 20]); // 15 + 5 }); test('should handle zero spacing', () => { const result = formatNodeSizeFn(20, 0, 10); - expect(result()).toEqual([20, 20, 20]); + expect(result({})).toEqual([20, 20, 20]); }); test('should handle undefined spacing', () => { const result = formatNodeSizeFn(20, undefined, 10); - expect(result()).toEqual([20, 20, 20]); + expect(result({})).toEqual([20, 20, 20]); }); test('should handle nodeSize as array', () => { const result = formatNodeSizeFn([30, 40], 5, 10); - expect(result()).toEqual([35, 45, 35]); + expect(result({})).toEqual([35, 45, 35]); }); test('should handle nodeSize as function', () => { @@ -210,29 +210,29 @@ describe('format', () => { test('should handle negative spacing', () => { const result = formatNodeSizeFn(20, -5, 10); - expect(result()).toEqual([15, 15, 15]); // 20 + (-5) + expect(result({})).toEqual([15, 15, 15]); // 20 + (-5) }); test('should handle fractional sizes and spacing', () => { const result = formatNodeSizeFn(20.5, 3.2, 10); - expect(result()[0]).toBeCloseTo(23.7); - expect(result()[1]).toBeCloseTo(23.7); - expect(result()[2]).toBeCloseTo(23.7); + expect(result({})[0]).toBeCloseTo(23.7); + expect(result({})[1]).toBeCloseTo(23.7); + expect(result({})[2]).toBeCloseTo(23.7); }); test('should handle number zero node size', () => { const result = formatNodeSizeFn(0, 5, 10); - expect(result()).toEqual([5, 5, 5]); + expect(result({})).toEqual([5, 5, 5]); }); test('should handle large sizes', () => { const result = formatNodeSizeFn(1000, 100, 10); - expect(result()).toEqual([1100, 1100, 1100]); + expect(result({})).toEqual([1100, 1100, 1100]); }); test('should use default when all values are undefined', () => { const result = formatNodeSizeFn(undefined, undefined, 12); - expect(result()).toEqual([12, 12, 12]); + expect(result({})).toEqual([12, 12, 12]); }); test('should handle node data without spacing function', () => { @@ -246,7 +246,7 @@ describe('format', () => { test('should handle single element array size', () => { const result = formatNodeSizeFn([35], 5, 10); - expect(result()).toEqual([40, 40, 40]); // max(35) + 5 + expect(result({})).toEqual([40, 40, 40]); // max(35) + 5 }); }); }); diff --git a/__tests__/unit/util/math.test.ts b/__tests__/unit/util/math.test.ts index 7cc56486..1f530654 100644 --- a/__tests__/unit/util/math.test.ts +++ b/__tests__/unit/util/math.test.ts @@ -1,3 +1,4 @@ +import { GraphLib } from '@/src/model/data'; import type { EdgeData, NodeData, PointObject } from '@/src/types'; import { floydWarshall, @@ -8,7 +9,6 @@ import { johnson, scaleMatrix, } from '@/src/util/math'; -import { GraphLib } from '@/src/model/data'; describe('getAdjMatrix', () => { test('should create adjacency matrix for undirected graph', () => { @@ -63,7 +63,7 @@ describe('getAdjMatrix', () => { const model = new GraphLib({ nodes, edges }); const matrix = getAdjMatrix(model, false); - expect(matrix).toEqual([[], []]); + expect(matrix).toEqual([Array(2), Array(2)]); }); test('should handle single node', () => { @@ -73,7 +73,7 @@ describe('getAdjMatrix', () => { const model = new GraphLib({ nodes, edges }); const matrix = getAdjMatrix(model, false); - expect(matrix).toEqual([[]]); + expect(matrix).toEqual([Array(1)]); }); test('should handle self-loop edge', () => { @@ -123,7 +123,7 @@ describe('getAdjMatrix', () => { const model = new GraphLib({ nodes, edges: undefined as any }); const matrix = getAdjMatrix(model, false); - expect(matrix).toEqual([[], []]); + expect(matrix).toEqual([Array(2), Array(2)]); }); test('should handle empty nodes', () => { diff --git a/__tests__/unit/util/viewport.test.ts b/__tests__/unit/util/viewport.test.ts index 75caff07..e8d36438 100644 --- a/__tests__/unit/util/viewport.test.ts +++ b/__tests__/unit/util/viewport.test.ts @@ -1,5 +1,5 @@ /** - * @jest-environment node + * @vitest-environment node */ import { normalizeViewport } from '@/src/util/viewport'; diff --git a/__tests__/utils/renderer.ts b/__tests__/utils/renderer.ts index 91cba0e6..e04a7259 100644 --- a/__tests__/utils/renderer.ts +++ b/__tests__/utils/renderer.ts @@ -1,43 +1,12 @@ -import { Layout } from '@/src/core/types'; -import { Point } from '@/src/types'; -import { LayoutEdge, LayoutNode } from '@/src/types/data'; +import type { Layout } from '@/src/algorithm/types'; +import type { Point } from '@/src/types'; +import type { GraphData, LayoutEdge, LayoutNode } from '@/src/types/data'; +import type { TextStyleProps } from '@antv/g'; import { Canvas, Circle, Line, Polyline, Rect, Text } from '@antv/g'; import { Renderer } from '@antv/g-canvas'; import { deepMix } from '@antv/util'; import interact from 'interactjs'; -export interface GraphNode { - id: string | number; - data?: { - x: number; - y: number; - shape?: 'circle' | 'rect'; - width?: number; - height?: number; - [key: string]: any; - }; - style?: { - fill?: string; - stroke?: string; - lineWidth?: number; - radius?: number; - [key: string]: any; - }; - [key: string]: any; -} - -export interface GraphEdge { - id: string | number; - source: string | number; - target: string | number; - [key: string]: any; -} - -export interface GraphData { - nodes: GraphNode[]; - edges?: GraphEdge[]; -} - export interface RenderOptions { nodeRadius?: number; nodeShape?: 'circle' | 'rect'; @@ -46,6 +15,8 @@ export interface RenderOptions { fill?: string; stroke?: string; lineWidth?: number; + rx?: number; + ry?: number; }; edgeShape?: 'line' | 'polyline'; edgeStyle?: { @@ -55,7 +26,7 @@ export interface RenderOptions { labelStyle?: { fontSize?: number; fill?: string; - fontWeight?: CSSStyleDeclaration['fontWeight']; + fontWeight?: TextStyleProps['fontWeight']; [key: string]: any; }; showLabel?: boolean; @@ -196,6 +167,8 @@ export class GraphRenderer { data?: GraphData, ): Circle | Rect { const nodeData = data?.nodes.find((n) => n.id === node.id); + const nodeColor = + nodeData?.data?._branchColor || nodeData?.data?._nodeColor; const shape = options.nodeShape; let elem; @@ -212,6 +185,10 @@ export class GraphRenderer { width, height, ...options.nodeStyle, + ...nodeData?.style, + fill: nodeData?.style?.fill || nodeColor || options.nodeStyle.fill, + stroke: + nodeData?.style?.stroke || nodeColor || options.nodeStyle.stroke, cursor: options.enableDrag ? 'grab' : 'default', }, }); @@ -222,8 +199,9 @@ export class GraphRenderer { cx: node.x, cy: node.y, r: options.nodeRadius, - fill: nodeData?.style?.fill || options.nodeStyle.fill, - stroke: nodeData?.style?.stroke || options.nodeStyle.stroke, + fill: nodeData?.style?.fill || nodeColor || options.nodeStyle.fill, + stroke: + nodeData?.style?.stroke || nodeColor || options.nodeStyle.stroke, lineWidth: nodeData?.style?.lineWidth || options.nodeStyle.lineWidth, cursor: options.enableDrag ? 'grab' : 'default', }, @@ -233,8 +211,8 @@ export class GraphRenderer { if (options.showLabel) { const label = new Text({ style: { - x: 0, - y: 0, + x: shape === 'rect' ? options.nodeSize.width / 2 : 0, + y: shape === 'rect' ? options.nodeSize.height / 2 : 0, text: String(node.id), textAlign: 'center', textBaseline: 'middle', @@ -438,7 +416,7 @@ export class GraphRenderer { } export function calculatePositions(layout: Layout) { - const results: any = { + const results: { nodes: LayoutNode[]; edges: LayoutEdge[] } = { nodes: [], edges: [], }; diff --git a/__tests__/utils/svg-transformer.js b/__tests__/utils/svg-transformer.js deleted file mode 100644 index 73d1fb5b..00000000 --- a/__tests__/utils/svg-transformer.js +++ /dev/null @@ -1,7 +0,0 @@ -module.exports = { - process() { - return { - code: `module.exports = {};`, - }; - }, -}; diff --git a/__tests__/utils/to-match-svg-snapshot.ts b/__tests__/utils/to-match-svg-snapshot.ts index b1c572f6..380abb97 100644 --- a/__tests__/utils/to-match-svg-snapshot.ts +++ b/__tests__/utils/to-match-svg-snapshot.ts @@ -86,7 +86,7 @@ export type ToMatchSVGSnapshotOptions = { fileFormat?: string; }; -// @see https://jestjs.io/docs/26.x/expect#expectextendmatchers +// @see https://vitest.dev/api/expect.html#expect-extend export async function toMatchSVGSnapshot( canvas: Canvas, dir: string, @@ -107,8 +107,6 @@ export async function toMatchSVGSnapshot( canvas.getContextService().getDomElement() as unknown as SVGElement ).cloneNode(true) as SVGElement; const gRoot = svg.querySelector('#g-root'); - // remove css style - svg.style.gridArea = ''; const dom = ( canvas.getContextService().getDomElement() as unknown as SVGElement @@ -135,6 +133,17 @@ export async function toMatchSVGSnapshot( encoding: 'utf8', flag: 'r', }); + if ( + process.env.UPDATE_SNAPSHOTS === 'true' && + process.env.CI !== 'true' + ) { + writeFileSync(expectedPath, actual); + if (existsSync(actualPath)) unlinkSync(actualPath); + return { + message: () => `update ${namePath}`, + pass: true, + }; + } if (actual === expected) { if (existsSync(actualPath)) unlinkSync(actualPath); return { @@ -146,7 +155,7 @@ export async function toMatchSVGSnapshot( // Perverse actual file. if (actual) writeFileSync(actualPath, actual); - const formatPath = (p: string) => p.split('/g6/')[1]; + const formatPath = (p: string) => p.replace(`${process.cwd()}/`, ''); return { message: () => `mismatch: \n expected: ${chalk.green( diff --git a/__tests__/utils/use-snapshot-matchers.ts b/__tests__/utils/use-snapshot-matchers.ts index a3be89e1..3f8f01bf 100644 --- a/__tests__/utils/use-snapshot-matchers.ts +++ b/__tests__/utils/use-snapshot-matchers.ts @@ -1,25 +1,21 @@ +import { expect } from 'vitest'; import { toMatchSnapshot, toMatchSVGSnapshot, ToMatchSVGSnapshotOptions, } from './to-match-svg-snapshot'; -declare global { - // eslint-disable - // -next-line @typescript-eslint/no-namespace - namespace jest { - interface Matchers { - toMatchSVGSnapshot( - dir: string, - name: string, - options?: ToMatchSVGSnapshotOptions, - ): Promise; - toMatchSnapshot( - dir: string, - detail?: string, - options?: ToMatchSVGSnapshotOptions, - ): Promise; - } +declare module 'vitest' { + interface SnapshotMatcher, T = unknown> { + (dir: string, detail?: string, options?: ToMatchSVGSnapshotOptions): R; + } + + interface Assertion { + toMatchSVGSnapshot( + dir: string, + name: string, + options?: ToMatchSVGSnapshotOptions, + ): Promise; } } diff --git a/__tests__/xmlserializer.d.ts b/__tests__/xmlserializer.d.ts new file mode 100644 index 00000000..485b6197 --- /dev/null +++ b/__tests__/xmlserializer.d.ts @@ -0,0 +1,3 @@ +declare module 'xmlserializer' { + export function serializeToString(node: Node): string; +} diff --git a/jest.config.js b/jest.config.js deleted file mode 100644 index cbabf84b..00000000 --- a/jest.config.js +++ /dev/null @@ -1,49 +0,0 @@ -// Installing third-party modules by tnpm or cnpm will name modules with underscore as prefix. -// In this case _{module} is also necessary. -const esm = ['internmap', 'd3-*', 'lodash-es', 'chalk'].map((d) => `_${d}|${d}`).join('|'); - -module.exports = { - testTimeout: 100000, - testEnvironment: 'jsdom', - setupFilesAfterEnv: ['./__tests__/setup.ts'], - transform: { - '^.+\\.[tj]s$': [ - '@swc/jest', - { - jsc: { - parser: { - syntax: 'typescript', - decorators: true, - }, - transform: { - // 处理 import.meta - optimizer: { - globals: { - vars: { - 'import.meta': '{}', - }, - }, - }, - }, - }, - }, - ], - '^.+\\.svg$': ['/__tests__/utils/svg-transformer.js'], - }, - collectCoverageFrom: ['src/**/*.ts'], - coveragePathIgnorePatterns: [], - moduleFileExtensions: ['ts', 'tsx', 'js', 'json'], - collectCoverage: true, - testRegex: '(/__tests__/.*\\.(test|spec))\\.(ts|tsx|js)$', - transformIgnorePatterns: [`/node_modules/(?!(${esm}))`], - testPathIgnorePatterns: ['/(lib|esm)/__tests__/'], - moduleNameMapper: { - '^@@/(.*)$': '/__tests__/$1', - '^@/(.*)$': '/$1', - }, - globals: { - 'import.meta': { - url: 'file:///test/index.js', - }, - }, -}; diff --git a/package.json b/package.json index 62f1f1ef..2b840532 100644 --- a/package.json +++ b/package.json @@ -58,11 +58,11 @@ "@rollup/plugin-node-resolve": "^16.0.3", "@rollup/plugin-terser": "^0.4.4", "@rollup/plugin-typescript": "^12.3.0", - "@swc/jest": "^0.2.39", "@types/d3-force": "^3.0.4", "@types/d3-quadtree": "^2.0.6", "@types/dagre": "^0.7.52", - "@types/jest": "^30.0.0", + "@types/node": "^24.19.4", + "@vitest/coverage-v8": "^5.1.2", "babel-loader": "^8.0.6", "eslint": "^7.32.0", "eslint-config-airbnb-base": "^14.2.1", @@ -71,10 +71,8 @@ "gh-pages": "^6.3.0", "husky": "^7.0.4", "interactjs": "^1.10.27", - "jest": "^30.2.0", - "jest-canvas-mock": "^2.5.2", - "jest-environment-jsdom": "^30.2.0", "jest-random-mock": "^1.0.0", + "jsdom": "^31.0.1", "lil-gui": "^0.21.0", "limit-size": "^0.1.4", "lint-staged": "^10.5.4", @@ -86,8 +84,10 @@ "rollup-plugin-dts": "^6.3.0", "svgo": "^4.0.0", "ts-loader": "^7.0.3", - "typescript": "^4.0.3", + "typescript": "^5.9.3", "vite": "^7.3.0", + "vitest": "^5.1.2", + "vitest-canvas-mock": "^1.2.0", "webpack": "^5.38.1", "webpack-cli": "^5.0.2", "workerize-loader": "^2.0.2", @@ -103,8 +103,8 @@ "publish:alpha": "npm publish --tag alpha", "size": "limit-size", "test:coverage:open": "open-cli coverage/lcov-report/index.html", - "test:coverage": "jest --coverage", - "test": "jest", + "test:coverage": "vitest run --coverage", + "test": "vitest run", "deploy": "npm --prefix site run build && gh-pages -d site/doc_build", "lint": "tsc --noEmit" }, diff --git a/site/docs/en/guide/api/hierarchy/_meta.json b/site/docs/en/guide/api/hierarchy/_meta.json index d9bb26a7..36307e89 100644 --- a/site/docs/en/guide/api/hierarchy/_meta.json +++ b/site/docs/en/guide/api/hierarchy/_meta.json @@ -1 +1 @@ -["dagre", "antv-dagre"] +["dagre", "antv-dagre", "fishbone", "indented", "mindmap"] diff --git a/site/docs/en/guide/api/hierarchy/fishbone.mdx b/site/docs/en/guide/api/hierarchy/fishbone.mdx new file mode 100644 index 00000000..96f943c7 --- /dev/null +++ b/site/docs/en/guide/api/hierarchy/fishbone.mdx @@ -0,0 +1,26 @@ +import { Badge } from '@theme'; + +# Fishbone Layout + +Arrange a root, categories, and items as a fishbone diagram for category-based analysis. + +## Usage + +```ts +import { FishboneLayout } from '@antv/layout'; + +const layout = new FishboneLayout({ direction: 'LR' }); +await layout.execute(data); +``` + +Provide tree data whose edges express the root → category → item hierarchy. + +## Main options + +| Option | Description | Type | Default | +| ------------------------ | ------------------------------------- | ------------------ | ----------- | +| `direction` | Layout direction | `'LR' \| 'RL'` | `'LR'` | +| `categoryGap` | Horizontal gap between categories | `number` | `180` | +| `categoryDistance` | Distance from a category to the spine | `number` | `200` | +| `itemHStep` | Extra horizontal offset for items | `number` | `20` | +| `getWidth` / `getHeight` | Get node width or height | `(node) => number` | `80` / `30` | diff --git a/site/docs/en/guide/api/hierarchy/indented.mdx b/site/docs/en/guide/api/hierarchy/indented.mdx new file mode 100644 index 00000000..bdc643c8 --- /dev/null +++ b/site/docs/en/guide/api/hierarchy/indented.mdx @@ -0,0 +1,28 @@ +import { Badge } from '@theme'; + +# Indented Layout + +Place tree nodes in DFS order with depth-based indentation for outlines and hierarchical lists. + +## Usage + +```ts +import { IndentedLayout } from '@antv/layout'; + +const layout = new IndentedLayout({ direction: 'LR', indent: 80 }); +await layout.execute(data); +``` + +Provide tree data. The root is inferred unless `rootId` is specified. + +## Main options + +| Option | Description | Type | Default | +| --------------------------- | ------------------------------- | -------------- | ----------- | +| `direction` | Indentation direction | `'LR' \| 'RL'` | `'LR'` | +| `rootId` | Root node ID | `string` | Inferred | +| `indent` | Indentation per depth | `number` | `80` | +| `rowHeight` | Row height | `number` | `40` | +| `nodeColors` / `edgeColors` | Color palettes indexed by depth | `string[]` | `undefined` | + +The layout writes `depth` and `_isRoot` to `node.data`, plus `_nodeColor` and `_edgeColor` when palettes are provided. diff --git a/site/docs/en/guide/api/hierarchy/mindmap.mdx b/site/docs/en/guide/api/hierarchy/mindmap.mdx new file mode 100644 index 00000000..71ebdc4a --- /dev/null +++ b/site/docs/en/guide/api/hierarchy/mindmap.mdx @@ -0,0 +1,29 @@ +import { Badge } from '@theme'; + +# Mindmap Layout + +Expand branches to one or both sides of a central root for mind maps and topic relationships. + +## Usage + +```ts +import { MindmapLayout } from '@antv/layout'; + +const layout = new MindmapLayout({ direction: 'H', levelGap: 120 }); +await layout.execute(data); +``` + +Provide tree data. `H` assigns sides with `getSide`; `LR` and `RL` expand to the right and left. + +## Main options + +| Option | Description | Type | Default | +| ------------------------ | --------------------------------------- | ------------------------------------------------ | ---------------- | +| `direction` | Branch direction | `'H' \| 'LR' \| 'RL'` | `'H'` | +| `levelGap` | Gap between parent and child boundaries | `number` | `120` | +| `nodeGap` | Gap between adjacent children | `number` | `30` | +| `branchColors` | Branch color palette | `string[]` | Built-in palette | +| `getWidth` / `getHeight` | Get node width or height | `(node) => number` | `100` / `40` | +| `getSide` | Get the side of a child | `(node, index, parentSide) => 'left' \| 'right'` | Always right | + +The selected branch color is written to `node.data._branchColor`. diff --git a/site/docs/zh/guide/api/hierarchy/_meta.json b/site/docs/zh/guide/api/hierarchy/_meta.json index d9bb26a7..36307e89 100644 --- a/site/docs/zh/guide/api/hierarchy/_meta.json +++ b/site/docs/zh/guide/api/hierarchy/_meta.json @@ -1 +1 @@ -["dagre", "antv-dagre"] +["dagre", "antv-dagre", "fishbone", "indented", "mindmap"] diff --git a/site/docs/zh/guide/api/hierarchy/fishbone.mdx b/site/docs/zh/guide/api/hierarchy/fishbone.mdx new file mode 100644 index 00000000..dd3dd9ff --- /dev/null +++ b/site/docs/zh/guide/api/hierarchy/fishbone.mdx @@ -0,0 +1,26 @@ +import { Badge } from '@theme'; + +# Fishbone 鱼骨图布局 + +将根节点、分类和条目组织为鱼骨图,适合按类别分析问题原因。 + +## 用法 + +```ts +import { FishboneLayout } from '@antv/layout'; + +const layout = new FishboneLayout({ direction: 'LR' }); +await layout.execute(data); +``` + +输入为树形数据,通过 `edges` 表达“根节点 → 分类 → 条目”的关系。 + +## 核心配置 + +| 配置项 | 说明 | 类型 | 默认值 | +| ------------------------ | ---------------------- | ------------------ | ----------- | +| `direction` | 布局方向 | `'LR' \| 'RL'` | `'LR'` | +| `categoryGap` | 分类节点之间的水平间距 | `number` | `180` | +| `categoryDistance` | 分类节点到主干的距离 | `number` | `200` | +| `itemHStep` | 条目节点的额外水平偏移 | `number` | `20` | +| `getWidth` / `getHeight` | 获取节点宽高 | `(node) => number` | `80` / `30` | diff --git a/site/docs/zh/guide/api/hierarchy/indented.mdx b/site/docs/zh/guide/api/hierarchy/indented.mdx new file mode 100644 index 00000000..191490ab --- /dev/null +++ b/site/docs/zh/guide/api/hierarchy/indented.mdx @@ -0,0 +1,28 @@ +import { Badge } from '@theme'; + +# Indented 缩进树布局 + +按 DFS 顺序排列树节点,并根据深度设置缩进,适合目录和层级列表。 + +## 用法 + +```ts +import { IndentedLayout } from '@antv/layout'; + +const layout = new IndentedLayout({ direction: 'LR', indent: 80 }); +await layout.execute(data); +``` + +输入为树形数据;未指定 `rootId` 时自动选择根节点。 + +## 核心配置 + +| 配置项 | 说明 | 类型 | 默认值 | +| --------------------------- | -------------------- | -------------- | ----------- | +| `direction` | 缩进方向 | `'LR' \| 'RL'` | `'LR'` | +| `rootId` | 根节点 ID | `string` | 自动推断 | +| `indent` | 每层缩进距离 | `number` | `80` | +| `rowHeight` | 行高 | `number` | `40` | +| `nodeColors` / `edgeColors` | 按深度写入的颜色序列 | `string[]` | `undefined` | + +布局后会在 `node.data` 中写入 `depth` 和 `_isRoot`;配置颜色时还会写入 `_nodeColor` 和 `_edgeColor`。 diff --git a/site/docs/zh/guide/api/hierarchy/mindmap.mdx b/site/docs/zh/guide/api/hierarchy/mindmap.mdx new file mode 100644 index 00000000..095d5a76 --- /dev/null +++ b/site/docs/zh/guide/api/hierarchy/mindmap.mdx @@ -0,0 +1,29 @@ +import { Badge } from '@theme'; + +# Mindmap 脑图布局 + +以根节点为中心向单侧或双侧展开分支,适合脑图和主题关系展示。 + +## 用法 + +```ts +import { MindmapLayout } from '@antv/layout'; + +const layout = new MindmapLayout({ direction: 'H', levelGap: 120 }); +await layout.execute(data); +``` + +输入为树形数据。`H` 通过 `getSide` 分配左右分支,`LR` 和 `RL` 分别向右侧和左侧展开。 + +## 核心配置 + +| 配置项 | 说明 | 类型 | 默认值 | +| ------------------------ | ---------------- | ------------------------------------------------ | ------------ | +| `direction` | 分支方向 | `'H' \| 'LR' \| 'RL'` | `'H'` | +| `levelGap` | 父子节点边界间距 | `number` | `120` | +| `nodeGap` | 相邻子节点间距 | `number` | `30` | +| `branchColors` | 分支颜色序列 | `string[]` | 内置色板 | +| `getWidth` / `getHeight` | 获取节点宽高 | `(node) => number` | `100` / `40` | +| `getSide` | 获取子节点所在侧 | `(node, index, parentSide) => 'left' \| 'right'` | 始终右侧 | + +配置 `branchColors` 后,会在 `node.data._branchColor` 中写入对应分支颜色。 diff --git a/src/algorithm/antv-dagre/graph.ts b/src/algorithm/antv-dagre/graph.ts index 27b9a559..952795be 100644 --- a/src/algorithm/antv-dagre/graph.ts +++ b/src/algorithm/antv-dagre/graph.ts @@ -10,6 +10,11 @@ export interface GraphNode { data: N; } +export interface GraphTreeNode + extends GraphNode { + children?: GraphTreeNode[]; +} + /** * 图中的边 * @@ -31,7 +36,7 @@ export interface GraphOptions< N extends NodeData = NodeData, E extends EdgeData = EdgeData, > { - tree?: string[] | (GraphNode & { children?: GraphNode[] })[]; + tree?: string[] | GraphTreeNode[]; nodes?: GraphNode[]; edges?: GraphEdge[]; } @@ -360,9 +365,7 @@ export class DagreGraph< * Add tree structure (recursively add nodes and their children) */ addTree( - tree: - | (GraphNode & { children?: GraphNode[] }) - | (GraphNode & { children?: GraphNode[] })[], + tree: GraphTreeNode | GraphTreeNode[], treeName?: string, ): void { const actualTreeName = @@ -374,10 +377,7 @@ export class DagreGraph< const trees = Array.isArray(tree) ? tree : [tree]; - const addTreeNode = ( - node: GraphNode & { children?: GraphNode[] }, - parentId?: ID, - ) => { + const addTreeNode = (node: GraphTreeNode, parentId?: ID) => { // Add the node itself this.addNode({ id: node.id, data: node.data }); diff --git a/tsconfig.json b/tsconfig.json index eef5ba23..38d30f47 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -20,7 +20,7 @@ "sourceRoot": "src", "strict": true, "target": "es2015", - "types": ["@types/jest", "node"], + "types": ["vitest/globals", "node"], "paths": { "@/*": ["./*"], "@@/*": ["__tests__/*"] diff --git a/vitest.config.ts b/vitest.config.ts new file mode 100644 index 00000000..794e7e9c --- /dev/null +++ b/vitest.config.ts @@ -0,0 +1,24 @@ +import path from 'path'; +import { defineConfig } from 'vitest/config'; + +export default defineConfig({ + resolve: { + alias: { + '@': path.resolve(__dirname, '.'), + '@@': path.resolve(__dirname, './__tests__'), + }, + }, + test: { + globals: true, + environment: 'jsdom', + setupFiles: ['./__tests__/setup.ts'], + include: ['__tests__/**/*.{test,spec}.{ts,tsx,js}'], + exclude: ['node_modules/**', 'dist/**', 'lib/**', 'esm/**'], + testTimeout: 100000, + coverage: { + provider: 'v8', + include: ['src/**/*.ts'], + reporter: ['text', 'json', 'lcov', 'clover'], + }, + }, +}); From fdb3bdea56267d8a6c0b48a937884e8160ad8898 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=80=8D=E4=B8=BA?= Date: Fri, 27 Nov 2026 12:29:59 +0800 Subject: [PATCH 3/3] feat: add live layout demos to documentation --- __tests__/unit/d3-force.test.ts | 12 + site/docs/components/LayoutDemo.tsx | 388 ++++++++++ site/docs/components/ThreeForceDemo.tsx | 267 +++++++ site/docs/components/layoutDemoConfigs.ts | 731 ++++++++++++++++++ site/docs/en/guide/api/api/introduction.mdx | 6 +- .../en/guide/api/combo/combo-combined.mdx | 12 +- site/docs/en/guide/api/force/d3-force-3d.mdx | 9 +- site/docs/en/guide/api/force/d3-force.mdx | 9 +- site/docs/en/guide/api/force/force-atlas2.mdx | 12 +- site/docs/en/guide/api/force/force.mdx | 9 +- site/docs/en/guide/api/force/fruchterman.mdx | 12 +- .../en/guide/api/hierarchy/antv-dagre.mdx | 12 +- site/docs/en/guide/api/hierarchy/dagre.mdx | 9 +- site/docs/en/guide/api/hierarchy/fishbone.mdx | 9 +- site/docs/en/guide/api/hierarchy/indented.mdx | 9 +- site/docs/en/guide/api/hierarchy/mindmap.mdx | 9 +- site/docs/en/guide/api/others/mds.mdx | 9 +- site/docs/en/guide/api/radial/circular.mdx | 22 +- site/docs/en/guide/api/radial/concentric.mdx | 12 +- site/docs/en/guide/api/radial/radial.mdx | 12 +- site/docs/en/guide/api/regular/grid.mdx | 12 +- site/docs/en/guide/api/regular/random.mdx | 9 +- site/docs/en/guide/start/webworker.mdx | 6 +- site/docs/zh/guide/api/api/introduction.mdx | 6 +- .../zh/guide/api/combo/combo-combined.mdx | 12 +- site/docs/zh/guide/api/force/d3-force-3d.mdx | 9 +- site/docs/zh/guide/api/force/d3-force.mdx | 9 +- site/docs/zh/guide/api/force/force-atlas2.mdx | 12 +- site/docs/zh/guide/api/force/force.mdx | 9 +- site/docs/zh/guide/api/force/fruchterman.mdx | 12 +- .../zh/guide/api/hierarchy/antv-dagre.mdx | 12 +- site/docs/zh/guide/api/hierarchy/dagre.mdx | 9 +- site/docs/zh/guide/api/hierarchy/fishbone.mdx | 9 +- site/docs/zh/guide/api/hierarchy/indented.mdx | 9 +- site/docs/zh/guide/api/hierarchy/mindmap.mdx | 9 +- site/docs/zh/guide/api/others/mds.mdx | 9 +- site/docs/zh/guide/api/radial/circular.mdx | 22 +- site/docs/zh/guide/api/radial/concentric.mdx | 12 +- site/docs/zh/guide/api/radial/radial.mdx | 12 +- site/docs/zh/guide/api/regular/grid.mdx | 12 +- site/docs/zh/guide/api/regular/random.mdx | 9 +- site/docs/zh/guide/start/webworker.mdx | 6 +- site/global.css | 92 +++ site/package.json | 10 +- site/rspress.config.ts | 1 + site/tsconfig.json | 1 + src/algorithm/d3-force/index.ts | 5 + src/index.ts | 14 + 48 files changed, 1784 insertions(+), 135 deletions(-) create mode 100644 site/docs/components/LayoutDemo.tsx create mode 100644 site/docs/components/ThreeForceDemo.tsx create mode 100644 site/docs/components/layoutDemoConfigs.ts diff --git a/__tests__/unit/d3-force.test.ts b/__tests__/unit/d3-force.test.ts index cb82ffe5..fe1b4ba5 100644 --- a/__tests__/unit/d3-force.test.ts +++ b/__tests__/unit/d3-force.test.ts @@ -473,4 +473,16 @@ describe('layout d3-force', () => { await renderLayout(d3Force); await expect(canvas).toMatchSnapshot(__filename, 'lattice'); }); + + it('should stop simulation when destroyed during execution', () => { + vi.useFakeTimers(); + try { + const layout = new D3ForceLayout(); + void layout.execute(data); + layout.destroy(); + expect(() => vi.runAllTicks()).not.toThrow(); + } finally { + vi.useRealTimers(); + } + }); }); diff --git a/site/docs/components/LayoutDemo.tsx b/site/docs/components/LayoutDemo.tsx new file mode 100644 index 00000000..af97bfe1 --- /dev/null +++ b/site/docs/components/LayoutDemo.tsx @@ -0,0 +1,388 @@ +import type { Layout } from '@antv/layout/lib/algorithm/types.js'; +import type { GraphEdge, GraphNode } from '@antv/layout/lib/types/data.js'; +import { select } from 'd3-selection'; +import { useEffect, useRef, useState } from 'react'; +import { + layoutDemoConfigs, + type LayoutDemoConfig, + type LayoutDemoType, +} from './layoutDemoConfigs'; +import { ThreeForceDemo } from './ThreeForceDemo'; + +const WIDTH = 640; +const HEIGHT = 360; +const PADDING = 48; +const PALETTE = [ + '#93C5FD', + '#86EFAC', + '#C4B5FD', + '#F9A8D4', + '#FCD34D', + '#67E8F9', +]; + +function getNodeSize(node: GraphNode, config: LayoutDemoConfig) { + const fallback = + config.displaySize ?? (config.shape === 'rect' ? [110, 32] : [16, 16]); + if (!node.isCombo && config.displaySize) return config.displaySize; + if (typeof node.size === 'number') return [node.size, node.size] as const; + if (Array.isArray(node.size)) { + return [ + node.size[0] ?? fallback[0], + node.size[1] ?? node.size[0] ?? fallback[1], + ] as const; + } + return fallback; +} + +function getPosition(node: GraphNode, config: LayoutDemoConfig) { + if (!config.project3d) return [node.x, node.y] as const; + const z = node.z ?? 0; + return [node.x + z * 0.35, node.y - z * 0.2] as const; +} + +function getRadius(node: GraphNode, config: LayoutDemoConfig) { + const [width, height] = getNodeSize(node, config); + return Math.max(5, Math.min(10, Math.min(width, height) / 2)); +} + +function getLabel(node: GraphNode) { + return String(node._original.label ?? node.id); +} + +function getView(nodes: GraphNode[], config: LayoutDemoConfig) { + let minX = Infinity; + let minY = Infinity; + let maxX = -Infinity; + let maxY = -Infinity; + nodes.forEach((node) => { + const [x, y] = getPosition(node, config); + const [width, height] = getNodeSize(node, config); + minX = Math.min(minX, x - width / 2); + minY = Math.min(minY, y - height / 2); + maxX = Math.max(maxX, x + width / 2); + maxY = Math.max(maxY, y + height / 2); + }); + const scale = Math.min( + (WIDTH - PADDING * 2) / Math.max(maxX - minX, 1), + (HEIGHT - PADDING * 2) / Math.max(maxY - minY, 1), + 1.5, + ); + const centerX = (minX + maxX) / 2; + const centerY = (minY + maxY) / 2; + return { + scale, + transform: `translate(${WIDTH / 2 - centerX * scale}, ${ + HEIGHT / 2 - centerY * scale + }) scale(${scale})`, + }; +} + +function getEdgePath(edge: GraphEdge, config: LayoutDemoConfig) { + if (edge.points?.length) { + return edge.points + .map(([x, y], index) => `${index === 0 ? 'M' : 'L'}${x},${y}`) + .join(' '); + } + if (!edge.sourceNode || !edge.targetNode) return ''; + const [x1, y1] = getPosition(edge.sourceNode, config); + const [x2, y2] = getPosition(edge.targetNode, config); + if (config.curve === 'horizontal') { + const middle = (x1 + x2) / 2; + return `M${x1},${y1} C${middle},${y1} ${middle},${y2} ${x2},${y2}`; + } + if (config.curve === 'soft') { + const dx = x2 - x1; + const dy = y2 - y1; + const length = Math.hypot(dx, dy) || 1; + const offset = Math.min(18, length * 0.08); + const cx = (x1 + x2) / 2 - (dy / length) * offset; + const cy = (y1 + y2) / 2 + (dx / length) * offset; + return `M${x1},${y1} Q${cx},${cy} ${x2},${y2}`; + } + return `M${x1},${y1} L${x2},${y2}`; +} + +function isCrossComboEdge(edge: GraphEdge) { + const sourceParent = edge.sourceNode?._original.parentId; + const targetParent = edge.targetNode?._original.parentId; + return Boolean(sourceParent && targetParent && sourceParent !== targetParent); +} + +function renderNodes( + root: any, + nodes: GraphNode[], + className: string, + config: LayoutDemoConfig, + viewScale: number, +) { + const groups = root + .selectAll(`g.${className}`) + .data(nodes, (node: GraphNode) => String(node.id)) + .join( + (enter: any) => { + const group = enter.append('g').attr('class', className); + group.each(function createNode( + this: SVGGElement, + node: GraphNode, + index: number, + ) { + const current = select(this); + const original = node._original; + const semanticColor = + original.data?._branchColor || original.data?._nodeColor; + const fill = + original.style?.fill || + semanticColor || + PALETTE[index % PALETTE.length]; + const stroke = original.style?.stroke || semanticColor || '#64748B'; + + if (config.shape === 'rect') { + const [width, height] = getNodeSize(node, config); + current + .append('rect') + .attr('x', -width / 2) + .attr('y', -height / 2) + .attr('width', width) + .attr('height', height) + .attr('rx', node.isCombo ? 14 : 7) + .attr('fill', fill) + .attr('fill-opacity', node.isCombo ? 0.8 : 1) + .attr('stroke', stroke) + .attr('stroke-width', node.isCombo ? 1.2 : 1.1) + .attr('vector-effect', 'non-scaling-stroke'); + } else { + current + .append('circle') + .attr('r', getRadius(node, config) / viewScale) + .attr('fill', fill) + .attr('stroke', stroke) + .attr('stroke-width', 1.2 / viewScale); + } + + if (config.showLabels) { + const isCircle = config.shape !== 'rect'; + current + .append('text') + .attr('text-anchor', node.isCombo ? 'start' : 'middle') + .attr('dominant-baseline', 'central') + .attr( + 'x', + node.isCombo ? -getNodeSize(node, config)[0] / 2 + 16 : 0, + ) + .attr( + 'y', + node.isCombo + ? -getNodeSize(node, config)[1] / 2 + 18 + : isCircle + ? (getRadius(node, config) + 12) / viewScale + : 0, + ) + .attr('fill', isCircle ? 'var(--rp-c-text-2)' : '#334155') + .attr( + 'font-size', + (node.isCombo ? 12 : isCircle ? 9 : 10) / viewScale, + ) + .attr('font-weight', node.isCombo ? 600 : 500) + .attr('pointer-events', 'none') + .text(getLabel(node)); + } + current.append('title').text(getLabel(node)); + }); + return group; + }, + (update: any) => update, + (exit: any) => exit.remove(), + ); + + groups.attr('transform', (node: GraphNode) => { + const [x, y] = getPosition(node, config); + return `translate(${x}, ${y})`; + }); + groups + .select('circle') + .attr('r', (node: GraphNode) => getRadius(node, config) / viewScale) + .attr('stroke-width', 1.2 / viewScale); + groups + .select('text') + .attr('y', (node: GraphNode) => + node.isCombo + ? -getNodeSize(node, config)[1] / 2 + 18 + : config.shape === 'rect' + ? 0 + : (getRadius(node, config) + 12) / viewScale, + ) + .attr( + 'font-size', + (node: GraphNode) => + (node.isCombo ? 12 : config.shape === 'rect' ? 10 : 9) / viewScale, + ); +} + +function renderGraph( + svgElement: SVGSVGElement, + nodes: GraphNode[], + edges: GraphEdge[], + config: LayoutDemoConfig, + type: LayoutDemoType, +) { + const svg = select(svgElement).attr('viewBox', `0 0 ${WIDTH} ${HEIGHT}`); + const view = getView(nodes, config); + const root = svg + .selectAll('g.layout-demo-root') + .data([null]) + .join('g') + .attr('class', 'layout-demo-root') + .attr('transform', view.transform); + + renderNodes( + root, + nodes.filter((node) => node.isCombo), + 'layout-demo-combo', + config, + view.scale, + ); + + if (config.directed) { + const marker = svg + .selectAll('marker') + .data([null]) + .join('marker') + .attr('id', `layout-demo-arrow-${type}`) + .attr('viewBox', '0 0 10 10') + .attr('refX', 9) + .attr('refY', 5) + .attr('markerWidth', 6) + .attr('markerHeight', 6) + .attr('orient', 'auto-start-reverse'); + marker + .selectAll('path') + .data([null]) + .join('path') + .attr('d', 'M 0 0 L 10 5 L 0 10 z') + .attr('fill', '#94A3B8'); + } + + root + .selectAll('path.layout-demo-edge') + .data(edges, (edge) => String((edge as GraphEdge).id)) + .join('path') + .attr('class', 'layout-demo-edge') + .attr('d', (edge: GraphEdge) => getEdgePath(edge, config)) + .attr('fill', 'none') + .attr('stroke', (edge: GraphEdge) => + isCrossComboEdge(edge) ? '#A78BFA' : '#CBD5E1', + ) + .attr('stroke-width', (edge: GraphEdge) => + isCrossComboEdge(edge) ? 1.3 : 1, + ) + .attr('stroke-opacity', (edge: GraphEdge) => + isCrossComboEdge(edge) ? 0.8 : 0.65, + ) + .attr('stroke-dasharray', (edge: GraphEdge) => + isCrossComboEdge(edge) ? '5 4' : null, + ) + .attr('stroke-linecap', 'round') + .attr('stroke-linejoin', 'round') + .attr('vector-effect', 'non-scaling-stroke') + .attr( + 'marker-end', + config.directed ? `url(#layout-demo-arrow-${type})` : null, + ); + + renderNodes( + root, + nodes.filter((node) => !node.isCombo), + 'layout-demo-node', + config, + view.scale, + ); +} + +function SvgLayoutDemo({ type }: { type: LayoutDemoType }) { + const svgRef = useRef(null); + const [runId, setRunId] = useState(0); + const [status, setStatus] = useState<'loading' | 'ready' | 'error'>( + 'loading', + ); + const [error, setError] = useState(''); + const config: LayoutDemoConfig = layoutDemoConfigs[type]; + + useEffect(() => { + let cancelled = false; + setStatus('loading'); + setError(''); + if (svgRef.current) select(svgRef.current).selectAll('*').remove(); + + const draw = (currentLayout: Layout) => { + if (cancelled || !svgRef.current) return; + const nodes: GraphNode[] = []; + const edges: GraphEdge[] = []; + currentLayout.forEachNode((node) => nodes.push(node)); + currentLayout.forEachEdge((edge) => edges.push(edge)); + renderGraph(svgRef.current, nodes, edges, config, type); + }; + const layout = config.createLayout(draw); + + layout + .execute(structuredClone(config.data)) + .then(() => { + if (cancelled) return; + draw(layout); + setStatus('ready'); + }) + .catch((reason: unknown) => { + if (cancelled) return; + setStatus('error'); + setError( + reason instanceof Error ? reason.message : 'Unable to run layout.', + ); + }); + + return () => { + cancelled = true; + layout.destroy(); + }; + }, [config, runId, type]); + + return ( +
+
+
+ {config.title} + + {status === 'loading' + ? config.animated + ? 'Converging…' + : 'Computing…' + : config.animated + ? 'Live simulation' + : 'Live layout'} + +
+ +
+
+ + {status === 'error' &&
{error}
} +
+
+ ); +} + +export function LayoutDemo({ type }: { type: LayoutDemoType }) { + if (type === 'd3-force-3d') { + return ; + } + return ; +} diff --git a/site/docs/components/ThreeForceDemo.tsx b/site/docs/components/ThreeForceDemo.tsx new file mode 100644 index 00000000..3405bf3c --- /dev/null +++ b/site/docs/components/ThreeForceDemo.tsx @@ -0,0 +1,267 @@ +import type { Layout } from '@antv/layout/lib/algorithm/types.js'; +import type { GraphEdge, GraphNode } from '@antv/layout/lib/types/data.js'; +import { useEffect, useRef, useState } from 'react'; +import type { LayoutDemoConfig } from './layoutDemoConfigs'; + +const PALETTE = [0x93c5fd, 0x86efac, 0xc4b5fd, 0xf9a8d4, 0xfcd34d, 0x67e8f9]; + +export function ThreeForceDemo({ config }: { config: LayoutDemoConfig }) { + const containerRef = useRef(null); + const [runId, setRunId] = useState(0); + const [status, setStatus] = useState<'loading' | 'ready' | 'error'>( + 'loading', + ); + const [error, setError] = useState(''); + + useEffect(() => { + let cancelled = false; + let dispose = () => {}; + setStatus('loading'); + setError(''); + if (containerRef.current) containerRef.current.replaceChildren(); + + const setup = async () => { + const [THREE, { OrbitControls }] = await Promise.all([ + import('three'), + import('three/addons/controls/OrbitControls.js'), + ]); + if (cancelled || !containerRef.current) return; + + const container = containerRef.current; + const scene = new THREE.Scene(); + const root = new THREE.Group(); + scene.add(root); + const camera = new THREE.PerspectiveCamera(42, 16 / 9, 0.1, 2000); + const renderer = new THREE.WebGLRenderer({ + antialias: true, + alpha: true, + }); + renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2)); + renderer.outputColorSpace = THREE.SRGBColorSpace; + renderer.setClearColor(0x000000, 0); + container.appendChild(renderer.domElement); + + const controls = new OrbitControls(camera, renderer.domElement); + controls.enableDamping = true; + controls.dampingFactor = 0.08; + controls.autoRotate = true; + controls.autoRotateSpeed = 0.55; + controls.addEventListener('start', () => { + controls.autoRotate = false; + }); + + scene.add(new THREE.HemisphereLight(0xffffff, 0x334155, 2.2)); + const directional = new THREE.DirectionalLight(0xffffff, 2.4); + directional.position.set(80, 120, 100); + scene.add(directional); + + const sphere = new THREE.SphereGeometry(4, 20, 14); + const disposables: Array<{ dispose: () => void }> = [sphere]; + const nodes = new Map(); + const labels = new Map(); + const edgeLines: any[] = []; + + const createLabel = (text: string) => { + const canvas = document.createElement('canvas'); + canvas.width = 256; + canvas.height = 64; + const context = canvas.getContext('2d')!; + context.font = '500 24px sans-serif'; + context.textAlign = 'center'; + context.textBaseline = 'middle'; + context.fillStyle = '#334155'; + context.fillText(text, 128, 32); + const texture = new THREE.CanvasTexture(canvas); + const material = new THREE.SpriteMaterial({ + map: texture, + transparent: true, + depthTest: false, + }); + const sprite = new THREE.Sprite(material); + sprite.scale.set(30, 7.5, 1); + disposables.push(texture, material); + return sprite; + }; + + const render = (layoutNodes: GraphNode[], layoutEdges: GraphEdge[]) => { + const ids = new Set(layoutNodes.map((node) => String(node.id))); + layoutNodes.forEach((node, index) => { + const id = String(node.id); + if (!nodes.has(id)) { + const material = new THREE.MeshStandardMaterial({ + color: PALETTE[index % PALETTE.length], + roughness: 0.45, + metalness: 0.08, + }); + const mesh = new THREE.Mesh(sphere, material); + root.add(mesh); + nodes.set(id, mesh); + disposables.push(material); + } + if (!labels.has(id)) { + const label = createLabel(String(node._original.label ?? node.id)); + root.add(label); + labels.set(id, label); + } + nodes.get(id).position.set(node.x, node.y, node.z ?? 0); + labels.get(id).position.set(node.x, node.y + 8, node.z ?? 0); + }); + for (const [id, mesh] of nodes) { + if (!ids.has(id)) { + root.remove(mesh); + nodes.delete(id); + } + } + for (const [id, label] of labels) { + if (!ids.has(id)) { + root.remove(label); + labels.delete(id); + } + } + + edgeLines.forEach((line) => { + root.remove(line); + line.geometry.dispose(); + line.material.dispose(); + }); + edgeLines.length = 0; + layoutEdges.forEach((edge) => { + if (!edge.sourceNode || !edge.targetNode) return; + const geometry = new THREE.BufferGeometry().setFromPoints([ + new THREE.Vector3( + edge.sourceNode.x, + edge.sourceNode.y, + edge.sourceNode.z ?? 0, + ), + new THREE.Vector3( + edge.targetNode.x, + edge.targetNode.y, + edge.targetNode.z ?? 0, + ), + ]); + const material = new THREE.LineBasicMaterial({ + color: 0x94a3b8, + transparent: true, + opacity: 0.5, + }); + const line = new THREE.Line(geometry, material); + edgeLines.push(line); + root.add(line); + }); + }; + + const fitCamera = (layoutNodes: GraphNode[]) => { + if (!layoutNodes.length) return; + const bounds = new THREE.Box3(); + layoutNodes.forEach((node) => { + bounds.expandByPoint(new THREE.Vector3(node.x, node.y, node.z ?? 0)); + }); + const center = bounds.getCenter(new THREE.Vector3()); + const size = bounds.getSize(new THREE.Vector3()); + const radius = Math.max(size.length() / 2, 35); + camera.near = Math.max(radius / 100, 0.1); + camera.far = radius * 12; + camera.updateProjectionMatrix(); + camera.position.set( + center.x + radius * 1.15, + center.y + radius * 0.75, + center.z + radius * 1.65, + ); + controls.target.copy(center); + controls.minDistance = radius * 0.45; + controls.maxDistance = radius * 5; + controls.update(); + }; + + const resize = () => { + const width = container.clientWidth; + const height = container.clientHeight; + if (!width || !height) return; + renderer.setSize(width, height, false); + camera.aspect = width / height; + camera.updateProjectionMatrix(); + }; + const observer = new ResizeObserver(resize); + observer.observe(container); + resize(); + + let frame = 0; + const animate = () => { + frame = requestAnimationFrame(animate); + controls.update(); + renderer.render(scene, camera); + }; + animate(); + + const draw = (layout: Layout) => { + if (cancelled) return; + const layoutNodes: GraphNode[] = []; + const layoutEdges: GraphEdge[] = []; + layout.forEachNode((node) => layoutNodes.push(node)); + layout.forEachEdge((edge) => layoutEdges.push(edge)); + render(layoutNodes, layoutEdges); + }; + const layout = config.createLayout(draw); + dispose = () => { + cancelAnimationFrame(frame); + observer.disconnect(); + controls.dispose(); + layout.destroy(); + edgeLines.forEach((line) => { + line.geometry.dispose(); + line.material.dispose(); + }); + disposables.forEach((item) => item.dispose()); + renderer.dispose(); + renderer.domElement.remove(); + }; + + await layout.execute(structuredClone(config.data)); + if (cancelled) return; + draw(layout); + const finalNodes: GraphNode[] = []; + layout.forEachNode((node) => finalNodes.push(node)); + fitCamera(finalNodes); + setStatus('ready'); + }; + + setup().catch((reason: unknown) => { + if (cancelled) return; + dispose(); + setStatus('error'); + setError( + reason instanceof Error + ? reason.message + : 'Unable to initialize WebGL.', + ); + }); + + return () => { + cancelled = true; + dispose(); + }; + }, [config, runId]); + + return ( +
+
+
+ 3D knowledge space · WebGL + + {status === 'loading' ? 'Converging…' : 'Live 3D simulation'} + +
+ +
+
+ {status === 'error' &&
{error}
} +
+
+ ); +} diff --git a/site/docs/components/layoutDemoConfigs.ts b/site/docs/components/layoutDemoConfigs.ts new file mode 100644 index 00000000..46a9117e --- /dev/null +++ b/site/docs/components/layoutDemoConfigs.ts @@ -0,0 +1,731 @@ +import { + AntVDagreLayout, + CircularLayout, + ComboCombinedLayout, + ConcentricLayout, + D3Force3DLayout, + D3ForceLayout, + DagreLayout, + FishboneLayout, + ForceAtlas2Layout, + ForceLayout, + FruchtermanLayout, + GridLayout, + IndentedLayout, + MDSLayout, + MindmapLayout, + RadialLayout, + RandomLayout, +} from '@antv/layout'; +import type { Layout } from '@antv/layout/lib/algorithm/types.js'; +import type { GraphData, NodeData } from '@antv/layout/lib/types/data.js'; + +export type LayoutCallback = (layout: Layout) => void; + +export type LayoutDemoConfig = { + title: string; + data: GraphData; + createLayout: (onTick: LayoutCallback) => Layout & { destroy(): void }; + shape?: 'circle' | 'rect'; + showLabels?: boolean; + animated?: boolean; + displaySize?: [number, number]; + curve?: 'soft' | 'horizontal'; + directed?: boolean; + project3d?: boolean; +}; + +function makeGraph( + nodes: (string | NodeData)[], + edges: [string, string][] = [], +): GraphData { + return { + nodes: nodes.map((node) => + typeof node === 'string' ? { id: node, data: {} } : { data: {}, ...node }, + ), + edges: edges.map(([source, target]) => ({ source, target })), + }; +} + +const forceStyle: Pick = + { + displaySize: [16, 16], + directed: true, + curve: 'soft', + }; + +const services = makeGraph( + [ + 'Gateway', + 'Auth', + 'Users', + 'Orders', + 'Billing', + 'Inventory', + 'Search', + 'Cache', + 'Events', + 'Analytics', + ], + [ + ['Gateway', 'Auth'], + ['Gateway', 'Users'], + ['Gateway', 'Orders'], + ['Users', 'Billing'], + ['Orders', 'Billing'], + ['Orders', 'Inventory'], + ['Search', 'Cache'], + ['Users', 'Cache'], + ['Orders', 'Events'], + ['Billing', 'Events'], + ['Events', 'Analytics'], + ], +); + +const communities = makeGraph( + [ + 'Gateway', + 'Auth', + 'Users', + 'Orders', + 'Products', + 'Stock', + 'Search', + 'Cache', + 'Docs', + 'UI', + 'Charts', + 'Forms', + ].map((id, index) => ({ id, data: {}, group: Math.floor(index / 3) })), + [ + ['Gateway', 'Auth'], + ['Auth', 'Users'], + ['Users', 'Gateway'], + ['Orders', 'Products'], + ['Products', 'Stock'], + ['Stock', 'Orders'], + ['Search', 'Cache'], + ['Cache', 'Docs'], + ['Docs', 'Search'], + ['UI', 'Charts'], + ['Charts', 'Forms'], + ['Forms', 'UI'], + ['Gateway', 'Orders'], + ['Orders', 'Search'], + ['Search', 'UI'], + ['Users', 'Forms'], + ], +); + +const collaboration = makeGraph( + ['Mia', 'Chen', 'Lu', 'Sam', 'Iris', 'Kai', 'Nora', 'Leo'], + [ + ['Mia', 'Chen'], + ['Mia', 'Lu'], + ['Chen', 'Sam'], + ['Lu', 'Iris'], + ['Sam', 'Kai'], + ['Iris', 'Nora'], + ['Kai', 'Leo'], + ['Nora', 'Mia'], + ['Chen', 'Iris'], + ['Lu', 'Leo'], + ], +); + +const packages = makeGraph( + [ + 'App', + 'Router', + 'Store', + 'API', + 'UI', + 'Forms', + 'Table', + 'Charts', + 'Utils', + 'i18n', + ], + [ + ['App', 'Router'], + ['App', 'Store'], + ['App', 'UI'], + ['Router', 'API'], + ['Store', 'API'], + ['UI', 'Forms'], + ['UI', 'Table'], + ['UI', 'Charts'], + ['Forms', 'Utils'], + ['Table', 'Utils'], + ['Charts', 'Utils'], + ['App', 'i18n'], + ], +); + +const knowledge = makeGraph( + [ + 'AI', + 'Models', + 'Agents', + 'Search', + 'Vector DB', + 'Graph', + 'NLP', + 'Vision', + 'Tools', + 'Evals', + ], + [ + ['AI', 'Models'], + ['AI', 'Agents'], + ['Models', 'NLP'], + ['Models', 'Vision'], + ['Agents', 'Tools'], + ['Agents', 'Evals'], + ['Search', 'Vector DB'], + ['Search', 'Graph'], + ['NLP', 'Search'], + ['Tools', 'Search'], + ], +); + +const permissions = makeGraph( + [ + 'Admin', + 'Editor', + 'Viewer', + 'Audit', + 'Billing', + 'Reports', + 'Projects', + 'Teams', + 'Files', + 'Comments', + ], + [ + ['Admin', 'Audit'], + ['Admin', 'Billing'], + ['Admin', 'Projects'], + ['Editor', 'Projects'], + ['Editor', 'Files'], + ['Editor', 'Comments'], + ['Viewer', 'Reports'], + ['Viewer', 'Files'], + ['Viewer', 'Comments'], + ['Projects', 'Teams'], + ], +); + +const influence = makeGraph( + [ + 'Key account', + 'Champion', + 'Decision', + 'Finance', + 'Legal', + 'Users', + 'Partner', + 'Support', + 'Press', + ], + [ + ['Key account', 'Champion'], + ['Key account', 'Decision'], + ['Champion', 'Finance'], + ['Champion', 'Legal'], + ['Champion', 'Users'], + ['Decision', 'Partner'], + ['Decision', 'Press'], + ['Users', 'Support'], + ], +); + +const people = makeGraph( + [ + 'Alex', + 'Design', + 'Engineering', + 'Product', + 'Data', + 'Sales', + 'Support', + 'Marketing', + 'HR', + 'Finance', + 'Operations', + ], + [ + ['Alex', 'Design'], + ['Alex', 'Engineering'], + ['Alex', 'Product'], + ['Design', 'Product'], + ['Engineering', 'Data'], + ['Product', 'Sales'], + ['Sales', 'Marketing'], + ['Support', 'Sales'], + ['HR', 'Operations'], + ['Operations', 'Finance'], + ['HR', 'Alex'], + ], +); + +const checklist = makeGraph([ + 'API', + 'Auth', + 'Docs', + 'Tests', + 'Build', + 'Deploy', + 'Monitor', + 'Alerts', +]); + +const observations = makeGraph( + [ + 'Feedback', + 'Reviews', + 'Search', + 'Sessions', + 'Tickets', + 'Surveys', + 'Clicks', + 'Errors', + 'Notes', + 'Metrics', + ], + [ + ['Feedback', 'Reviews'], + ['Feedback', 'Tickets'], + ['Reviews', 'Surveys'], + ['Search', 'Sessions'], + ['Sessions', 'Clicks'], + ['Tickets', 'Errors'], + ['Surveys', 'Metrics'], + ['Notes', 'Search'], + ], +); + +const similarity = makeGraph( + [ + 'Analytics', + 'Automation', + 'CRM', + 'Email', + 'Forms', + 'Reports', + 'Search', + 'Support', + ], + [ + ['Analytics', 'Reports'], + ['Reports', 'Search'], + ['CRM', 'Email'], + ['CRM', 'Support'], + ['Email', 'Support'], + ['Forms', 'CRM'], + ['Automation', 'Email'], + ['Automation', 'Forms'], + ], +); + +const release = makeGraph( + [ + 'Commit', + 'Lint', + 'Unit tests', + 'Build', + 'Review', + 'Package', + 'Staging', + 'E2E tests', + 'Preview', + 'Deploy', + ], + [ + ['Commit', 'Lint'], + ['Commit', 'Unit tests'], + ['Commit', 'Build'], + ['Lint', 'Review'], + ['Unit tests', 'Review'], + ['Build', 'Package'], + ['Package', 'Staging'], + ['Review', 'Staging'], + ['Staging', 'E2E tests'], + ['Staging', 'Preview'], + ['E2E tests', 'Deploy'], + ['Preview', 'Deploy'], + ], +); + +const approval = makeGraph( + ['Request', 'Manager', 'Finance', 'Legal', 'Approve', 'Reject', 'Archive'], + [ + ['Request', 'Manager'], + ['Manager', 'Finance'], + ['Manager', 'Legal'], + ['Finance', 'Approve'], + ['Legal', 'Approve'], + ['Manager', 'Reject'], + ['Approve', 'Archive'], + ['Reject', 'Archive'], + ], +); + +const fishbone = makeGraph( + ['Risk', 'People', 'Process', 'Tools', 'Skills', 'Scope', 'Builds'], + [ + ['Risk', 'People'], + ['Risk', 'Process'], + ['Risk', 'Tools'], + ['People', 'Skills'], + ['Process', 'Scope'], + ['Tools', 'Builds'], + ], +); + +const indented = makeGraph( + [ + 'System', + 'Foundations', + 'Colors', + 'Typography', + 'Components', + 'Buttons', + 'Forms', + 'Guidelines', + 'Accessibility', + ], + [ + ['System', 'Foundations'], + ['Foundations', 'Colors'], + ['Foundations', 'Typography'], + ['System', 'Components'], + ['Components', 'Buttons'], + ['Components', 'Forms'], + ['System', 'Guidelines'], + ['Guidelines', 'Accessibility'], + ], +); + +const mindmap = makeGraph( + [ + 'Product', + 'Research', + 'Design', + 'Engineering', + 'Growth', + 'Interviews', + 'Prototypes', + 'Architecture', + 'Activation', + ], + [ + ['Product', 'Research'], + ['Product', 'Design'], + ['Product', 'Engineering'], + ['Product', 'Growth'], + ['Research', 'Interviews'], + ['Design', 'Prototypes'], + ['Engineering', 'Architecture'], + ['Growth', 'Activation'], + ], +); + +const combo = makeGraph( + [ + { + id: 'Commerce', + data: {}, + isCombo: true, + style: { fill: '#EFF6FF', stroke: '#93C5FD' }, + }, + { + id: 'Orders', + data: {}, + parentId: 'Commerce', + style: { fill: '#DBEAFE', stroke: '#60A5FA' }, + }, + { + id: 'Payments', + data: {}, + parentId: 'Commerce', + style: { fill: '#DBEAFE', stroke: '#60A5FA' }, + }, + { + id: 'Inventory', + data: {}, + parentId: 'Commerce', + style: { fill: '#DBEAFE', stroke: '#60A5FA' }, + }, + { + id: 'Engagement', + data: {}, + isCombo: true, + style: { fill: '#F5F3FF', stroke: '#C4B5FD' }, + }, + { + id: 'Users', + data: {}, + parentId: 'Engagement', + style: { fill: '#EDE9FE', stroke: '#A78BFA' }, + }, + { + id: 'Messages', + data: {}, + parentId: 'Engagement', + style: { fill: '#EDE9FE', stroke: '#A78BFA' }, + }, + { + id: 'Rewards', + data: {}, + parentId: 'Engagement', + style: { fill: '#EDE9FE', stroke: '#A78BFA' }, + }, + ], + [ + ['Orders', 'Payments'], + ['Orders', 'Inventory'], + ['Users', 'Messages'], + ['Messages', 'Rewards'], + ['Orders', 'Users'], + ['Inventory', 'Messages'], + ], +); + +export const layoutDemoConfigs = { + 'antv-dagre': { + title: 'Approval workflow', + data: approval, + createLayout: () => + new AntVDagreLayout({ + rankdir: 'LR', + nodeSize: [110, 32], + nodesep: 24, + ranksep: 60, + }), + shape: 'rect', + showLabels: true, + directed: true, + }, + circular: { + title: 'Roles and permissions', + data: permissions, + createLayout: () => new CircularLayout({ radius: 120 }), + showLabels: true, + }, + 'combo-combined': { + title: 'Domain modules', + data: combo, + createLayout: () => + new ComboCombinedLayout({ + layout: (comboId) => + comboId + ? { + type: 'grid', + rows: 2, + cols: 2, + width: 232, + height: 112, + nodeSize: [88, 28], + nodeSpacing: 28, + } + : { + type: 'grid', + rows: 1, + cols: 2, + width: 528, + height: 160, + nodeSpacing: 64, + }, + node: (node) => ({ parentId: node.parentId, isCombo: node.isCombo }), + comboPadding: 36, + comboSpacing: 90, + }), + shape: 'rect', + showLabels: true, + displaySize: [88, 28], + curve: 'soft', + }, + concentric: { + title: 'Account influence', + data: influence, + createLayout: () => + new ConcentricLayout({ nodeSize: 16, preventOverlap: true }), + showLabels: true, + }, + 'd3-force': { + title: 'Package dependencies', + data: packages, + createLayout: (onTick) => + new D3ForceLayout({ width: 400, height: 280, alphaDecay: 0.04, onTick }), + showLabels: true, + animated: true, + ...forceStyle, + }, + 'd3-force-3d': { + title: '3D knowledge space · projection', + data: knowledge, + createLayout: (onTick) => + new D3Force3DLayout({ + width: 400, + height: 280, + alphaDecay: 0.04, + onTick, + }), + showLabels: true, + animated: true, + project3d: true, + ...forceStyle, + }, + dagre: { + title: 'Release pipeline', + data: release, + createLayout: () => + new DagreLayout({ + rankdir: 'LR', + nodeSize: [110, 32], + nodesep: 24, + ranksep: 60, + }), + shape: 'rect', + showLabels: true, + directed: true, + }, + fishbone: { + title: 'Delivery risk analysis', + data: fishbone, + createLayout: () => + new FishboneLayout({ + categoryGap: 150, + categoryDistance: 120, + itemHStep: 20, + getWidth: () => 110, + getHeight: () => 32, + }), + shape: 'rect', + showLabels: true, + directed: true, + }, + force: { + title: 'Service dependencies', + data: services, + createLayout: (onTick) => + new ForceLayout({ + width: 400, + height: 280, + animate: true, + maxIteration: 180, + nodeSize: 16, + preventOverlap: true, + onTick, + }), + showLabels: true, + animated: true, + ...forceStyle, + }, + 'force-atlas2': { + title: 'Community discovery', + data: communities, + createLayout: (onTick) => + new ForceAtlas2Layout({ + width: 400, + height: 280, + animate: true, + maxIteration: 220, + nodeSize: 16, + preventOverlap: true, + onTick, + }), + showLabels: true, + animated: true, + ...forceStyle, + }, + fruchterman: { + title: 'Team collaboration', + data: collaboration, + createLayout: (onTick) => + new FruchtermanLayout({ + width: 400, + height: 280, + animate: true, + maxIteration: 240, + nodeSize: 16, + preventOverlap: true, + onTick, + }), + showLabels: true, + animated: true, + ...forceStyle, + }, + grid: { + title: 'Release checklist', + data: checklist, + createLayout: () => + new GridLayout({ + rows: 2, + cols: 4, + nodeSize: [90, 32], + preventOverlap: true, + }), + shape: 'rect', + showLabels: true, + displaySize: [90, 32], + }, + indented: { + title: 'Design-system hierarchy', + data: indented, + createLayout: () => + new IndentedLayout({ + rootId: 'System', + indent: 150, + rowHeight: 42, + nodeColors: ['#C7D2FE', '#DDD6FE', '#EDE9FE'], + }), + shape: 'rect', + showLabels: true, + }, + mds: { + title: 'Product similarity', + data: similarity, + createLayout: () => new MDSLayout({ linkDistance: 100 }), + showLabels: true, + curve: 'soft', + }, + mindmap: { + title: 'Product strategy', + data: mindmap, + createLayout: () => + new MindmapLayout({ + levelGap: 70, + nodeGap: 24, + branchColors: ['#BFDBFE', '#FBCFE8'], + getWidth: () => 110, + getHeight: () => 32, + getSide: (_node, index, parentSide) => + parentSide ?? (index % 2 === 0 ? 'left' : 'right'), + }), + shape: 'rect', + showLabels: true, + curve: 'horizontal', + }, + radial: { + title: 'People around Alex', + data: people, + createLayout: () => + new RadialLayout({ + focusNode: 'Alex', + unitRadius: 60, + nodeSize: 16, + preventOverlap: true, + }), + showLabels: true, + }, + random: { + title: 'Unstructured observations', + data: observations, + createLayout: () => new RandomLayout({ width: 400, height: 280 }), + showLabels: true, + }, +} satisfies Record; + +export type LayoutDemoType = keyof typeof layoutDemoConfigs; diff --git a/site/docs/en/guide/api/api/introduction.mdx b/site/docs/en/guide/api/api/introduction.mdx index 4869b2eb..06eda9fd 100644 --- a/site/docs/en/guide/api/api/introduction.mdx +++ b/site/docs/en/guide/api/api/introduction.mdx @@ -1,7 +1,11 @@ +--- +title: Common API +--- import { Badge } from '@theme'; import { DocCards } from '../../../../components/DocCards'; -# Common API +# Common API + This page explains the shared usage of `@antv/layout`: prepare data, execute a layout, read results, and optionally control iterations and lifecycle methods. Differences across layouts are mainly in their `LayoutOptions`. diff --git a/site/docs/en/guide/api/combo/combo-combined.mdx b/site/docs/en/guide/api/combo/combo-combined.mdx index 9fcb4b96..9f8fc943 100644 --- a/site/docs/en/guide/api/combo/combo-combined.mdx +++ b/site/docs/en/guide/api/combo/combo-combined.mdx @@ -1,15 +1,17 @@ +--- +title: ComboCombined Composite Combo Layout +--- import { Badge } from '@theme'; import { DocCards } from '../../../../components/DocCards'; +import { LayoutDemo } from '../../../../components/LayoutDemo'; import CommonLayoutOptions from '../../../partials/common-layout-options.mdx'; -# ComboCombined Composite Combo Layout +# ComboCombined Composite Combo Layout + Designed for composite scenes with combos or subgraphs. You can assign different layout strategies per hierarchy level, while handling combo bounds and spacing consistently. - + ## When to use diff --git a/site/docs/en/guide/api/force/d3-force-3d.mdx b/site/docs/en/guide/api/force/d3-force-3d.mdx index 7dc42d80..09541ba6 100644 --- a/site/docs/en/guide/api/force/d3-force-3d.mdx +++ b/site/docs/en/guide/api/force/d3-force-3d.mdx @@ -1,13 +1,18 @@ +--- +title: D3Force3D (3D force) +--- import { Badge } from '@theme'; import { DocCards } from '../../../../components/DocCards'; +import { LayoutDemo } from '../../../../components/LayoutDemo'; import D3Force3DOptions from '../../../partials/d3-force-3d-options.mdx'; import D3ForceOptions from '../../../partials/d3-force-options.mdx'; -# D3Force3D (3D force) +# D3Force3D (3D force) + `D3Force3DLayout` is based on `d3-force-3d`, adding z-axis forces on top of 2D. It is suitable for 3D scenes or depth-layered views. -![d3-force](https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*4mbSTJLOXkgAAAAAAAAAAAAADmJ7AQ/original) + ## When to use diff --git a/site/docs/en/guide/api/force/d3-force.mdx b/site/docs/en/guide/api/force/d3-force.mdx index 724a39ae..3283de17 100644 --- a/site/docs/en/guide/api/force/d3-force.mdx +++ b/site/docs/en/guide/api/force/d3-force.mdx @@ -1,12 +1,17 @@ +--- +title: D3Force (d3-force based) +--- import { Badge } from '@theme'; import { DocCards } from '../../../../components/DocCards'; +import { LayoutDemo } from '../../../../components/LayoutDemo'; import D3ForceOptions from '../../../partials/d3-force-options.mdx'; -# D3Force (d3-force based) +# D3Force (d3-force based) + `D3ForceLayout` wraps the simulation capabilities of `d3-force`. It is ideal if you want to reuse the d3 force configuration style, combining `link`, `manyBody`, `collide`, `x`, `y`, and more. -![d3-force](https://gw.alipayobjects.com/mdn/rms_f8c6a0/afts/img/A*9VXcQLLyzHgAAAAAAAAAAABkARQnAQ) + ## When to use diff --git a/site/docs/en/guide/api/force/force-atlas2.mdx b/site/docs/en/guide/api/force/force-atlas2.mdx index 4980c0e7..0c6d50bf 100644 --- a/site/docs/en/guide/api/force/force-atlas2.mdx +++ b/site/docs/en/guide/api/force/force-atlas2.mdx @@ -1,16 +1,18 @@ +--- +title: ForceAtlas2 Layout +--- import { Badge } from '@theme'; import { DocCards } from '../../../../components/DocCards'; +import { LayoutDemo } from '../../../../components/LayoutDemo'; import CommonLayoutOptions from '../../../partials/common-layout-options.mdx'; import ForceIterativeOptions from '../../../partials/force-iterative-options.mdx'; -# ForceAtlas2 Layout +# ForceAtlas2 Layout + ForceAtlas2 is designed for graph visualization, especially large graphs with community/cluster structures, and offers acceleration options like Barnes–Hut. - + ## When to use diff --git a/site/docs/en/guide/api/force/force.mdx b/site/docs/en/guide/api/force/force.mdx index f4630306..f6d803b5 100644 --- a/site/docs/en/guide/api/force/force.mdx +++ b/site/docs/en/guide/api/force/force.mdx @@ -1,13 +1,18 @@ +--- +title: Force Layout +--- import { Badge } from '@theme'; import { DocCards } from '../../../../components/DocCards'; +import { LayoutDemo } from '../../../../components/LayoutDemo'; import CommonLayoutOptions from '../../../partials/common-layout-options.mdx'; import ForceIterativeOptions from '../../../partials/force-iterative-options.mdx'; -# Force Layout +# Force Layout + Force layout offers a highly configurable force-directed model, including link distance, repulsion/attraction, centripetal force, and clustering. It is ideal when you need fine-grained tuning and process control. - + ## When to use diff --git a/site/docs/en/guide/api/force/fruchterman.mdx b/site/docs/en/guide/api/force/fruchterman.mdx index 2cd2f6b3..b0165529 100644 --- a/site/docs/en/guide/api/force/fruchterman.mdx +++ b/site/docs/en/guide/api/force/fruchterman.mdx @@ -1,16 +1,18 @@ +--- +title: Fruchterman Layout +--- import { Badge } from '@theme'; import { DocCards } from '../../../../components/DocCards'; +import { LayoutDemo } from '../../../../components/LayoutDemo'; import CommonLayoutOptions from '../../../partials/common-layout-options.mdx'; import ForceIterativeOptions from '../../../partials/force-iterative-options.mdx'; -# Fruchterman Layout +# Fruchterman Layout + Fruchterman-Reingold is a classic force-directed layout. It uses repulsion, attraction, and gravity to reach a balanced distribution on the plane. - + ## When to use diff --git a/site/docs/en/guide/api/hierarchy/antv-dagre.mdx b/site/docs/en/guide/api/hierarchy/antv-dagre.mdx index 253e08d5..edf4e5e9 100644 --- a/site/docs/en/guide/api/hierarchy/antv-dagre.mdx +++ b/site/docs/en/guide/api/hierarchy/antv-dagre.mdx @@ -1,15 +1,17 @@ +--- +title: AntVDagre Hierarchical Layout +--- import { Badge } from '@theme'; +import { LayoutDemo } from '../../../../components/LayoutDemo'; import { DocCards } from '../../../../components/DocCards'; import CommonLayoutOptions from '../../../partials/common-layout-options.mdx'; -# AntVDagre Hierarchical Layout +# AntVDagre Hierarchical Layout + A hierarchical layout for flowcharts and dependency graphs, with direct options for direction, spacing, alignment, and edge control points. - + ## When to use diff --git a/site/docs/en/guide/api/hierarchy/dagre.mdx b/site/docs/en/guide/api/hierarchy/dagre.mdx index 7930a110..922bb811 100644 --- a/site/docs/en/guide/api/hierarchy/dagre.mdx +++ b/site/docs/en/guide/api/hierarchy/dagre.mdx @@ -1,12 +1,17 @@ +--- +title: Dagre Hierarchical Layout +--- import { Badge } from '@theme'; +import { LayoutDemo } from '../../../../components/LayoutDemo'; import { DocCards } from '../../../../components/DocCards'; import CommonLayoutOptions from '../../../partials/common-layout-options.mdx'; -# Dagre Hierarchical Layout +# Dagre Hierarchical Layout + Arrange directed graphs in layers, emphasizing direction and hierarchy. Common for DAGs, workflows, and dependency graphs. - + ## When to use diff --git a/site/docs/en/guide/api/hierarchy/fishbone.mdx b/site/docs/en/guide/api/hierarchy/fishbone.mdx index 96f943c7..783a9967 100644 --- a/site/docs/en/guide/api/hierarchy/fishbone.mdx +++ b/site/docs/en/guide/api/hierarchy/fishbone.mdx @@ -1,9 +1,16 @@ +--- +title: Fishbone Layout +--- import { Badge } from '@theme'; +import { LayoutDemo } from '../../../../components/LayoutDemo'; -# Fishbone Layout +# Fishbone Layout + Arrange a root, categories, and items as a fishbone diagram for category-based analysis. + + ## Usage ```ts diff --git a/site/docs/en/guide/api/hierarchy/indented.mdx b/site/docs/en/guide/api/hierarchy/indented.mdx index bdc643c8..adaa01c8 100644 --- a/site/docs/en/guide/api/hierarchy/indented.mdx +++ b/site/docs/en/guide/api/hierarchy/indented.mdx @@ -1,9 +1,16 @@ +--- +title: Indented Layout +--- import { Badge } from '@theme'; +import { LayoutDemo } from '../../../../components/LayoutDemo'; -# Indented Layout +# Indented Layout + Place tree nodes in DFS order with depth-based indentation for outlines and hierarchical lists. + + ## Usage ```ts diff --git a/site/docs/en/guide/api/hierarchy/mindmap.mdx b/site/docs/en/guide/api/hierarchy/mindmap.mdx index 71ebdc4a..fbe50d84 100644 --- a/site/docs/en/guide/api/hierarchy/mindmap.mdx +++ b/site/docs/en/guide/api/hierarchy/mindmap.mdx @@ -1,9 +1,16 @@ +--- +title: Mindmap Layout +--- import { Badge } from '@theme'; +import { LayoutDemo } from '../../../../components/LayoutDemo'; -# Mindmap Layout +# Mindmap Layout + Expand branches to one or both sides of a central root for mind maps and topic relationships. + + ## Usage ```ts diff --git a/site/docs/en/guide/api/others/mds.mdx b/site/docs/en/guide/api/others/mds.mdx index 6877fc1a..71d2f326 100644 --- a/site/docs/en/guide/api/others/mds.mdx +++ b/site/docs/en/guide/api/others/mds.mdx @@ -1,12 +1,17 @@ +--- +title: MDS Layout +--- import { Badge } from '@theme'; import { DocCards } from '../../../../components/DocCards'; +import { LayoutDemo } from '../../../../components/LayoutDemo'; import CommonLayoutOptions from '../../../partials/common-layout-options.mdx'; -# MDS Layout +# MDS Layout + MDS stands for Multidimensional Scaling. It maps ideal distance relationships onto a 2D plane, useful when you want a balanced global structure and edge lengths close to expected values. - + ## When to use diff --git a/site/docs/en/guide/api/radial/circular.mdx b/site/docs/en/guide/api/radial/circular.mdx index ab77d314..a89b3e46 100644 --- a/site/docs/en/guide/api/radial/circular.mdx +++ b/site/docs/en/guide/api/radial/circular.mdx @@ -1,25 +1,17 @@ +--- +title: Circular Layout +--- import { Badge } from '@theme'; import { DocCards } from '../../../../components/DocCards'; +import { LayoutDemo } from '../../../../components/LayoutDemo'; import CommonLayoutOptions from '../../../partials/common-layout-options.mdx'; -# Circular Layout +# Circular Layout + Place nodes on a circle, or configure a spiral distribution. Supports ordering, grouping, start/end angles, and radius control. Algorithm reference: [A framework and algorithms for circular drawings of graphs](https://www.sciencedirect.com/science/article/pii/S1570866705000031). -
- - - -
+ ## When to use diff --git a/site/docs/en/guide/api/radial/concentric.mdx b/site/docs/en/guide/api/radial/concentric.mdx index 2ddc320c..95eab45a 100644 --- a/site/docs/en/guide/api/radial/concentric.mdx +++ b/site/docs/en/guide/api/radial/concentric.mdx @@ -1,15 +1,17 @@ +--- +title: Concentric Layout +--- import { Badge } from '@theme'; import { DocCards } from '../../../../components/DocCards'; +import { LayoutDemo } from '../../../../components/LayoutDemo'; import CommonLayoutOptions from '../../../partials/common-layout-options.mdx'; -# Concentric Layout +# Concentric Layout + Layer nodes by a concentric value: higher values are closer to the center. By default, the concentric value is node degree. - + ## When to use diff --git a/site/docs/en/guide/api/radial/radial.mdx b/site/docs/en/guide/api/radial/radial.mdx index 2daa76e7..67f69ec4 100644 --- a/site/docs/en/guide/api/radial/radial.mdx +++ b/site/docs/en/guide/api/radial/radial.mdx @@ -1,15 +1,17 @@ +--- +title: Radial Layout +--- import { Badge } from '@theme'; import { DocCards } from '../../../../components/DocCards'; +import { LayoutDemo } from '../../../../components/LayoutDemo'; import CommonLayoutOptions from '../../../partials/common-layout-options.mdx'; -# Radial Layout +# Radial Layout + Centers on a focus node and places others on rings by shortest-path distance. Use it to highlight relationships around a core entity. - + ## When to use diff --git a/site/docs/en/guide/api/regular/grid.mdx b/site/docs/en/guide/api/regular/grid.mdx index 8569c8af..11bd099b 100644 --- a/site/docs/en/guide/api/regular/grid.mdx +++ b/site/docs/en/guide/api/regular/grid.mdx @@ -1,15 +1,17 @@ +--- +title: Grid Layout +--- import { Badge } from '@theme'; import { DocCards } from '../../../../components/DocCards'; +import { LayoutDemo } from '../../../../components/LayoutDemo'; import CommonLayoutOptions from '../../../partials/common-layout-options.mdx'; -# Grid Layout +# Grid Layout + Arrange nodes in a regular grid. Great for stable, predictable structures like matrix views or card lists. - + ## When to use diff --git a/site/docs/en/guide/api/regular/random.mdx b/site/docs/en/guide/api/regular/random.mdx index e804c499..15c77c17 100644 --- a/site/docs/en/guide/api/regular/random.mdx +++ b/site/docs/en/guide/api/regular/random.mdx @@ -1,11 +1,18 @@ +--- +title: Random Layout +--- import { Badge } from '@theme'; import { DocCards } from '../../../../components/DocCards'; +import { LayoutDemo } from '../../../../components/LayoutDemo'; import CommonLayoutOptions from '../../../partials/common-layout-options.mdx'; -# Random Layout +# Random Layout + Generate random coordinates for each node within a given area. Useful for placeholders, debugging, or as a starting point for other layouts. + + ## When to use - Need quick renderable coordinates diff --git a/site/docs/en/guide/start/webworker.mdx b/site/docs/en/guide/start/webworker.mdx index 8934e380..de058263 100644 --- a/site/docs/en/guide/start/webworker.mdx +++ b/site/docs/en/guide/start/webworker.mdx @@ -1,6 +1,10 @@ +--- +title: Using WebWorker +--- import { Badge } from '@theme'; -# Using WebWorker +# Using WebWorker + WebWorker is a browser capability that runs JavaScript in a **separate thread**, helping you avoid main-thread jank caused by heavy computations. diff --git a/site/docs/zh/guide/api/api/introduction.mdx b/site/docs/zh/guide/api/api/introduction.mdx index cc7df02c..8dd62be2 100644 --- a/site/docs/zh/guide/api/api/introduction.mdx +++ b/site/docs/zh/guide/api/api/introduction.mdx @@ -1,7 +1,11 @@ +--- +title: 通用 API +--- import { Badge } from '@theme'; import { DocCards } from '../../../../components/DocCards'; -# 通用 API +# 通用 API + 本页用例子说明 `@antv/layout` 的通用调用方式:准备数据、执行布局、读取结果,以及可选的迭代控制与生命周期方法。不同布局算法的差异主要体现在各自的 `LayoutOptions` 配置项。 diff --git a/site/docs/zh/guide/api/combo/combo-combined.mdx b/site/docs/zh/guide/api/combo/combo-combined.mdx index 721a08e2..fe3beeb7 100644 --- a/site/docs/zh/guide/api/combo/combo-combined.mdx +++ b/site/docs/zh/guide/api/combo/combo-combined.mdx @@ -1,15 +1,17 @@ +--- +title: ComboCombined 复合 Combo 布局 +--- import { Badge } from '@theme'; import { DocCards } from '../../../../components/DocCards'; +import { LayoutDemo } from '../../../../components/LayoutDemo'; import CommonLayoutOptions from '../../../partials/common-layout-options.mdx'; -# ComboCombined 复合 Combo 布局 +# ComboCombined 复合 Combo 布局 + 用于包含 Combo 或子图的复合场景。你可以为不同层级选择不同布局策略,并统一处理 Combo 的包围盒与间距。 - + ## 适用场景 diff --git a/site/docs/zh/guide/api/force/d3-force-3d.mdx b/site/docs/zh/guide/api/force/d3-force-3d.mdx index 04bd351e..b21561ec 100644 --- a/site/docs/zh/guide/api/force/d3-force-3d.mdx +++ b/site/docs/zh/guide/api/force/d3-force-3d.mdx @@ -1,13 +1,18 @@ +--- +title: D3Force3D 3D 力导向 +--- import { Badge } from '@theme'; import { DocCards } from '../../../../components/DocCards'; +import { LayoutDemo } from '../../../../components/LayoutDemo'; import D3Force3DOptions from '../../../partials/d3-force-3d-options.mdx'; import D3ForceOptions from '../../../partials/d3-force-options.mdx'; -# D3Force3D 3D 力导向 +# D3Force3D 3D 力导向 + `D3Force3DLayout` 基于 `d3-force-3d`,在二维力导向的基础上增加 z 轴计算,适用于 3D 场景或需要深度分层的表达。 -![d3-force](https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*4mbSTJLOXkgAAAAAAAAAAAAADmJ7AQ/original) + ## 适用场景 diff --git a/site/docs/zh/guide/api/force/d3-force.mdx b/site/docs/zh/guide/api/force/d3-force.mdx index 7417cbb5..9d5ddf69 100644 --- a/site/docs/zh/guide/api/force/d3-force.mdx +++ b/site/docs/zh/guide/api/force/d3-force.mdx @@ -1,12 +1,17 @@ +--- +title: D3Force 基于 d3-force +--- import { Badge } from '@theme'; import { DocCards } from '../../../../components/DocCards'; +import { LayoutDemo } from '../../../../components/LayoutDemo'; import D3ForceOptions from '../../../partials/d3-force-options.mdx'; -# D3Force 基于 d3-force +# D3Force 基于 d3-force + `D3ForceLayout` 封装了 `d3-force` 的仿真能力,适合希望复用 d3 生态 force 配置方式的项目,例如组合 `link`、`manyBody`、`collide`、`x`、`y` 等力模型。 -![d3-force](https://gw.alipayobjects.com/mdn/rms_f8c6a0/afts/img/A*9VXcQLLyzHgAAAAAAAAAAABkARQnAQ) + ## 适用场景 diff --git a/site/docs/zh/guide/api/force/force-atlas2.mdx b/site/docs/zh/guide/api/force/force-atlas2.mdx index bbe662d6..84b8473c 100644 --- a/site/docs/zh/guide/api/force/force-atlas2.mdx +++ b/site/docs/zh/guide/api/force/force-atlas2.mdx @@ -1,16 +1,18 @@ +--- +title: ForceAtlas2 力导向布局 +--- import { Badge } from '@theme'; import { DocCards } from '../../../../components/DocCards'; +import { LayoutDemo } from '../../../../components/LayoutDemo'; import CommonLayoutOptions from '../../../partials/common-layout-options.mdx'; import ForceIterativeOptions from '../../../partials/force-iterative-options.mdx'; -# ForceAtlas2 力导向布局 +# ForceAtlas2 力导向布局 + ForceAtlas2 面向图可视化场景,适用于较大规模图的社区/聚类结构展示,并提供 Barnes–Hut 等加速选项。 - + ## 适用场景 diff --git a/site/docs/zh/guide/api/force/force.mdx b/site/docs/zh/guide/api/force/force.mdx index 4710139e..19b22fa1 100644 --- a/site/docs/zh/guide/api/force/force.mdx +++ b/site/docs/zh/guide/api/force/force.mdx @@ -1,13 +1,18 @@ +--- +title: Force 力导向布局 +--- import { Badge } from '@theme'; import { DocCards } from '../../../../components/DocCards'; +import { LayoutDemo } from '../../../../components/LayoutDemo'; import CommonLayoutOptions from '../../../partials/common-layout-options.mdx'; import ForceIterativeOptions from '../../../partials/force-iterative-options.mdx'; -# Force 力导向布局 +# Force 力导向布局 + Force 布局提供可配置程度较高的力导向能力,包括边长度、节点斥力与引力、向心力与聚类等。适合需要细粒度调参与过程控制的场景。 - + ## 适用场景 diff --git a/site/docs/zh/guide/api/force/fruchterman.mdx b/site/docs/zh/guide/api/force/fruchterman.mdx index fa735fde..63bf5289 100644 --- a/site/docs/zh/guide/api/force/fruchterman.mdx +++ b/site/docs/zh/guide/api/force/fruchterman.mdx @@ -1,16 +1,18 @@ +--- +title: Fruchterman 力导布局 +--- import { Badge } from '@theme'; import { DocCards } from '../../../../components/DocCards'; +import { LayoutDemo } from '../../../../components/LayoutDemo'; import CommonLayoutOptions from '../../../partials/common-layout-options.mdx'; import ForceIterativeOptions from '../../../partials/force-iterative-options.mdx'; -# Fruchterman 力导布局 +# Fruchterman 力导布局 + Fruchterman-Reingold 是经典力导向布局之一,使用斥力/引力/重力使图结构在平面上达到相对均衡的分布。 - + ## 适用场景 diff --git a/site/docs/zh/guide/api/hierarchy/antv-dagre.mdx b/site/docs/zh/guide/api/hierarchy/antv-dagre.mdx index d518c18d..5a738b0c 100644 --- a/site/docs/zh/guide/api/hierarchy/antv-dagre.mdx +++ b/site/docs/zh/guide/api/hierarchy/antv-dagre.mdx @@ -1,15 +1,17 @@ +--- +title: AntVDagre 层次布局 +--- import { Badge } from '@theme'; +import { LayoutDemo } from '../../../../components/LayoutDemo'; import { DocCards } from '../../../../components/DocCards'; import CommonLayoutOptions from '../../../partials/common-layout-options.mdx'; -# AntVDagre 层次布局 +# AntVDagre 层次布局 + 面向流程图与依赖图等场景的层次布局实现,提供方向、间距、对齐与边控制点等更直接的配置项。 - + ## 适用场景 diff --git a/site/docs/zh/guide/api/hierarchy/dagre.mdx b/site/docs/zh/guide/api/hierarchy/dagre.mdx index d51dd5c6..8ed3c729 100644 --- a/site/docs/zh/guide/api/hierarchy/dagre.mdx +++ b/site/docs/zh/guide/api/hierarchy/dagre.mdx @@ -1,12 +1,17 @@ +--- +title: Dagre 层次布局 +--- import { Badge } from '@theme'; +import { LayoutDemo } from '../../../../components/LayoutDemo'; import { DocCards } from '../../../../components/DocCards'; import CommonLayoutOptions from '../../../partials/common-layout-options.mdx'; -# Dagre 层次布局 +# Dagre 层次布局 + 用于有向图的分层排列,强调边的方向性与层级关系,常用于 DAG、流程编排与依赖关系等可视化。 - + ## 适用场景 diff --git a/site/docs/zh/guide/api/hierarchy/fishbone.mdx b/site/docs/zh/guide/api/hierarchy/fishbone.mdx index dd3dd9ff..d2a8a74d 100644 --- a/site/docs/zh/guide/api/hierarchy/fishbone.mdx +++ b/site/docs/zh/guide/api/hierarchy/fishbone.mdx @@ -1,9 +1,16 @@ +--- +title: Fishbone 鱼骨图布局 +--- import { Badge } from '@theme'; +import { LayoutDemo } from '../../../../components/LayoutDemo'; -# Fishbone 鱼骨图布局 +# Fishbone 鱼骨图布局 + 将根节点、分类和条目组织为鱼骨图,适合按类别分析问题原因。 + + ## 用法 ```ts diff --git a/site/docs/zh/guide/api/hierarchy/indented.mdx b/site/docs/zh/guide/api/hierarchy/indented.mdx index 191490ab..75252700 100644 --- a/site/docs/zh/guide/api/hierarchy/indented.mdx +++ b/site/docs/zh/guide/api/hierarchy/indented.mdx @@ -1,9 +1,16 @@ +--- +title: Indented 缩进树布局 +--- import { Badge } from '@theme'; +import { LayoutDemo } from '../../../../components/LayoutDemo'; -# Indented 缩进树布局 +# Indented 缩进树布局 + 按 DFS 顺序排列树节点,并根据深度设置缩进,适合目录和层级列表。 + + ## 用法 ```ts diff --git a/site/docs/zh/guide/api/hierarchy/mindmap.mdx b/site/docs/zh/guide/api/hierarchy/mindmap.mdx index 095d5a76..4f7f7c96 100644 --- a/site/docs/zh/guide/api/hierarchy/mindmap.mdx +++ b/site/docs/zh/guide/api/hierarchy/mindmap.mdx @@ -1,9 +1,16 @@ +--- +title: Mindmap 脑图布局 +--- import { Badge } from '@theme'; +import { LayoutDemo } from '../../../../components/LayoutDemo'; -# Mindmap 脑图布局 +# Mindmap 脑图布局 + 以根节点为中心向单侧或双侧展开分支,适合脑图和主题关系展示。 + + ## 用法 ```ts diff --git a/site/docs/zh/guide/api/others/mds.mdx b/site/docs/zh/guide/api/others/mds.mdx index 83dbbabf..34281010 100644 --- a/site/docs/zh/guide/api/others/mds.mdx +++ b/site/docs/zh/guide/api/others/mds.mdx @@ -1,12 +1,17 @@ +--- +title: MDS 多维尺度降维布局 +--- import { Badge } from '@theme'; import { DocCards } from '../../../../components/DocCards'; +import { LayoutDemo } from '../../../../components/LayoutDemo'; import CommonLayoutOptions from '../../../partials/common-layout-options.mdx'; -# MDS 多维尺度降维布局 +# MDS 多维尺度降维布局 + MDS 是 Multidimensional Scaling 的缩写。该算法将理想距离关系映射到二维平面,适用于希望整体结构更均衡、边长更接近期望值的场景。 - + ## 适用场景 diff --git a/site/docs/zh/guide/api/radial/circular.mdx b/site/docs/zh/guide/api/radial/circular.mdx index 5fdc62d7..add61f3d 100644 --- a/site/docs/zh/guide/api/radial/circular.mdx +++ b/site/docs/zh/guide/api/radial/circular.mdx @@ -1,25 +1,17 @@ +--- +title: Circular 圆形布局 +--- import { Badge } from '@theme'; import { DocCards } from '../../../../components/DocCards'; +import { LayoutDemo } from '../../../../components/LayoutDemo'; import CommonLayoutOptions from '../../../partials/common-layout-options.mdx'; -# Circular 圆形布局 +# Circular 圆形布局 + 将节点排列在圆周上,也可以配置为螺旋分布。支持节点排序、分组、起止角度与半径控制等能力。算法参考论文:[A framework and algorithms for circular drawings of graphs](https://www.sciencedirect.com/science/article/pii/S1570866705000031)。 -
- - - -
+ ## 适用场景 diff --git a/site/docs/zh/guide/api/radial/concentric.mdx b/site/docs/zh/guide/api/radial/concentric.mdx index 152714c8..8390596b 100644 --- a/site/docs/zh/guide/api/radial/concentric.mdx +++ b/site/docs/zh/guide/api/radial/concentric.mdx @@ -1,15 +1,17 @@ +--- +title: Concentric 同心圆布局 +--- import { Badge } from '@theme'; import { DocCards } from '../../../../components/DocCards'; +import { LayoutDemo } from '../../../../components/LayoutDemo'; import CommonLayoutOptions from '../../../partials/common-layout-options.mdx'; -# Concentric 同心圆布局 +# Concentric 同心圆布局 + 根据节点的同心值将节点分层。同心值越高越靠近中心。默认的同心值来自节点度数。 - + ## 适用场景 diff --git a/site/docs/zh/guide/api/radial/radial.mdx b/site/docs/zh/guide/api/radial/radial.mdx index 15433c87..b87bc33d 100644 --- a/site/docs/zh/guide/api/radial/radial.mdx +++ b/site/docs/zh/guide/api/radial/radial.mdx @@ -1,15 +1,17 @@ +--- +title: Radial 辐射布局 +--- import { Badge } from '@theme'; import { DocCards } from '../../../../components/DocCards'; +import { LayoutDemo } from '../../../../components/LayoutDemo'; import CommonLayoutOptions from '../../../partials/common-layout-options.mdx'; -# Radial 辐射布局 +# Radial 辐射布局 + 以指定焦点节点为中心,将节点按最短路径层级分布到不同半径的圆环上,用于突出某个核心实体的关系结构。 - + ## 适用场景 diff --git a/site/docs/zh/guide/api/regular/grid.mdx b/site/docs/zh/guide/api/regular/grid.mdx index aab319ff..f19cadde 100644 --- a/site/docs/zh/guide/api/regular/grid.mdx +++ b/site/docs/zh/guide/api/regular/grid.mdx @@ -1,15 +1,17 @@ +--- +title: Grid 网格布局 +--- import { Badge } from '@theme'; import { DocCards } from '../../../../components/DocCards'; +import { LayoutDemo } from '../../../../components/LayoutDemo'; import CommonLayoutOptions from '../../../partials/common-layout-options.mdx'; -# Grid 网格布局 +# Grid 网格布局 + 将节点按行列排列到规则网格上,适用于需要稳定、可预测结构的场景,例如矩阵视图或卡片式列表布局。 - + ## 适用场景 diff --git a/site/docs/zh/guide/api/regular/random.mdx b/site/docs/zh/guide/api/regular/random.mdx index 5a8be759..2f882a81 100644 --- a/site/docs/zh/guide/api/regular/random.mdx +++ b/site/docs/zh/guide/api/regular/random.mdx @@ -1,11 +1,18 @@ +--- +title: Random 随机布局 +--- import { Badge } from '@theme'; import { DocCards } from '../../../../components/DocCards'; +import { LayoutDemo } from '../../../../components/LayoutDemo'; import CommonLayoutOptions from '../../../partials/common-layout-options.mdx'; -# Random 随机布局 +# Random 随机布局 + 在给定布局区域内为每个节点生成随机坐标。常用于占位、调试,或作为其他布局的初始位置。 + + ## 适用场景 - 需要快速得到可渲染坐标 diff --git a/site/docs/zh/guide/start/webworker.mdx b/site/docs/zh/guide/start/webworker.mdx index db4e8fef..8840e878 100644 --- a/site/docs/zh/guide/start/webworker.mdx +++ b/site/docs/zh/guide/start/webworker.mdx @@ -1,6 +1,10 @@ +--- +title: 使用 WebWorker +--- import { Badge } from '@theme'; -# 使用 WebWorker +# 使用 WebWorker + WebWorker 是浏览器提供的一种并行能力:它可以在**独立线程**里执行 JavaScript,从而避免在主线程做大量计算导致的卡顿。 diff --git a/site/global.css b/site/global.css index f5b51c6c..ce533971 100644 --- a/site/global.css +++ b/site/global.css @@ -137,6 +137,98 @@ } } +/* Live layout demos */ +.layoutDemo { + margin: 16px 0 24px; + overflow: hidden; + border: 1px solid var(--rp-c-divider-light); + border-radius: 12px; + background: var(--rp-c-bg); +} + +.layoutDemoToolbar { + display: flex; + align-items: center; + justify-content: space-between; + padding: 8px 12px; + border-bottom: 1px solid var(--rp-c-divider-light); + color: var(--rp-c-text-3); + font-size: 12px; +} + +.layoutDemoMeta { + display: flex; + align-items: baseline; + gap: 8px; +} + +.layoutDemoMeta strong { + color: var(--rp-c-text-2); + font-weight: 500; +} + +.layoutDemoMeta span { + color: var(--rp-c-text-3); + font-size: 11px; +} + +.layoutDemoToolbar button { + padding: 3px 10px; + border: 1px solid var(--rp-c-divider-light); + border-radius: 6px; + background: var(--rp-c-bg-soft); + color: var(--rp-c-text-2); + font-size: 12px; + cursor: pointer; +} + +.layoutDemoToolbar button:hover:not(:disabled) { + border-color: var(--rp-c-brand); + color: var(--rp-c-brand); +} + +.layoutDemoToolbar button:disabled { + cursor: wait; + opacity: 0.55; +} + +.layoutDemoCanvas { + position: relative; + background: var(--rp-c-bg-soft); +} + +.layoutDemoCanvas svg { + display: block; + width: 100%; + height: auto; + transition: opacity 150ms ease; +} + +.layoutDemo[data-status='loading'] svg { + opacity: 0.5; +} + +.layoutThreeCanvas { + aspect-ratio: 16 / 9; +} + +.layoutThreeCanvas canvas { + display: block; + width: 100%; + height: 100%; +} + +.layoutDemoError { + position: absolute; + inset: 0; + display: grid; + place-items: center; + padding: 24px; + color: var(--rp-c-text-2); + background: var(--rp-c-bg-soft); + text-align: center; +} + /* Perf dashboard */ .rspress-sidebar-menu-container.no-toc + .rspress-doc-container .rspress-doc { max-width: 1240px; diff --git a/site/package.json b/site/package.json index 08ba3208..774700b3 100644 --- a/site/package.json +++ b/site/package.json @@ -13,10 +13,14 @@ "keywords": [], "author": "yvonneyx", "devDependencies": { - "@rspress/plugin-playground": "^1.47.0", - "rspress": "^1.47.0", "@antv/g-canvas": "^1.11.27", "@antv/g-lite": "^2.5.1", - "@antv/layout": "file:../" + "@antv/layout": "file:../", + "@rspress/plugin-playground": "^1.47.0", + "@types/d3-selection": "^3.0.13", + "@types/three": "^0.187.0", + "d3-selection": "^3.0.1", + "rspress": "^1.47.0", + "three": "^0.187.0" } } diff --git a/site/rspress.config.ts b/site/rspress.config.ts index b6d538b1..c3251bef 100644 --- a/site/rspress.config.ts +++ b/site/rspress.config.ts @@ -20,6 +20,7 @@ export default defineConfig({ route: { cleanUrls: true, + exclude: ['components/**'], }, // 默认语言 diff --git a/site/tsconfig.json b/site/tsconfig.json index 6d35550a..140eb167 100644 --- a/site/tsconfig.json +++ b/site/tsconfig.json @@ -10,6 +10,7 @@ "isolatedModules": true, "resolveJsonModule": true, "moduleResolution": "bundler", + "types": ["vite/client"], "useDefineForClassFields": true, "allowImportingTsExtensions": true }, diff --git a/src/algorithm/d3-force/index.ts b/src/algorithm/d3-force/index.ts index c2d2b197..a229b02b 100644 --- a/src/algorithm/d3-force/index.ts +++ b/src/algorithm/d3-force/index.ts @@ -95,6 +95,11 @@ export class D3ForceLayout< return this; } + public destroy(): void { + this.stop(); + super.destroy(); + } + public tick(iterations: number = 1): this { if (this.simulation) { for (let i = 0; i < iterations; i++) { diff --git a/src/index.ts b/src/index.ts index 41191beb..43ede5bf 100644 --- a/src/index.ts +++ b/src/index.ts @@ -34,4 +34,18 @@ export { type RadialLayoutOptions, RandomLayout, type RandomLayoutOptions, + // Others + isLayoutWithIterations, } from './algorithm'; + +// Types +export { + type GraphData, + type GraphEdge, + type GraphNode, +} from './types'; + +export { + type Layout, + type LayoutWithIterations +} from './algorithm/types';