You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
4.0 KiB

4 months ago
import type { GraphData, NodeData } from '../spec';
import type { Padding, Size } from '../types';
import { BaseLayout } from './base-layout';
import type { BaseLayoutOptions } from './types';
export interface SnakeLayoutOptions extends BaseLayoutOptions {
/**
* <zh/>
*
* <en/> Node size
*/
nodeSize?: Size | ((node: NodeData) => Size);
/**
* <zh/>
*
* <en/> Padding, the distance between the layout area and the canvas boundary
* @defaultValue 0
*/
padding?: Padding;
/**
* <zh/>
*
* <en/> Node sorting method
*/
sortBy?: (nodeA: NodeData, nodeB: NodeData) => -1 | 0 | 1;
/**
* <zh/>
*
* <en/> Number of node columns
* @defaultValue 5
*/
cols?: number;
/**
* <zh/>
*
* <en/> The size of the gap between a node's rows
*/
rowGap?: number;
/**
* <zh/>
*
* <en/> The size of the gap between a node's columns
*/
colGap?: number;
/**
* <zh/>
*
* <en/> Whether the node arrangement direction is clockwise
* @defaultValue true
* @remarks
* <zh/> S S
*
* <en/> When arranged clockwise, the nodes start from the upper left corner, the first row is arranged from left to right, the second row is arranged from right to left, and so on, forming an S-shaped path. When arranged counterclockwise, the nodes start from the upper right corner, the first row is arranged from right to left, the second row is arranged from left to right, and so on, forming a reverse S-shaped path.
*/
clockwise?: boolean;
}
/**
* <zh/>
*
* <en/> Snake layout
* @remarks
* <zh/> Snake Layout线
*
* <zh/> S
*
* <en/> The Snake layout is a special way of graph layout that can more effectively display long chain structures in a smaller space. Note that the graph data needs to ensure that the nodes are linearly arranged in the order from the source node to the sink node to form a clear path.
*
* <en/> The nodes are arranged in an S-shaped pattern, with the first node at the beginning of the first row, and the following nodes arranged to the right until the end of the row. After reaching the end of the row, the nodes in the next row are arranged in reverse from right to left. This process is repeated until all nodes are arranged.
*/
export declare class SnakeLayout extends BaseLayout {
id: string;
static defaultOptions: Partial<SnakeLayoutOptions>;
private formatSize;
/**
* Validates the graph data to ensure it meets the requirements for linear arrangement.
* @param data - Graph data
* @returns false if the graph is not connected, has more than one source or sink node, or contains cycles.
*/
private validate;
execute(model: GraphData, options?: SnakeLayoutOptions): Promise<GraphData>;
}