@lumina-study/graph
Version:
Graph library for Lumina Study
61 lines • 1.7 kB
TypeScript
import { Node, Edge } from '@xyflow/react';
import { TreeNodeData } from '../types';
export type LayoutDirection = 'vertical' | 'horizontal';
export interface LayoutOptions {
/**
* Direction of the tree layout
* @default 'vertical'
*/
direction?: LayoutDirection;
/**
* Horizontal spacing between nodes
* @default 300
*/
horizontalSpacing?: number;
/**
* Vertical spacing between nodes
* @default 150
*/
verticalSpacing?: number;
}
/**
* Calculate positions for tree nodes using a simple hierarchical layout
*
* @example
* ```typescript
* const nodes = [
* { id: '1', data: { label: 'Root' } },
* { id: '2', data: { label: 'Child 1' } },
* { id: '3', data: { label: 'Child 2' } }
* ];
* const edges = [
* { id: 'e1-2', source: '1', target: '2' },
* { id: 'e1-3', source: '1', target: '3' }
* ];
*
* const layoutedNodes = autoLayout(nodes, edges);
* ```
*/
export declare function autoLayout<T extends TreeNodeData = TreeNodeData>(nodes: Omit<Node<T>, 'position'>[], edges: Edge[], options?: LayoutOptions): Node<T>[];
/**
* Helper to create a tree from a simple parent-child structure
*
* @example
* ```typescript
* const tree = createTreeFromHierarchy([
* { id: '1', data: { label: 'Root' } },
* { id: '2', parentId: '1', data: { label: 'Child 1' } },
* { id: '3', parentId: '1', data: { label: 'Child 2' } }
* ]);
* // Returns { nodes, edges }
* ```
*/
export declare function createTreeFromHierarchy<T extends TreeNodeData>(items: Array<{
id: string;
parentId?: string;
data: T;
}>): {
nodes: Node<T>[];
edges: Edge[];
};
//# sourceMappingURL=autoLayout.d.ts.map