UNPKG

@delove/reaflow

Version:

Node-based Visualizations for React

88 lines (87 loc) 3.08 kB
import { LayoutNodeData, NodeData } from '../types'; export declare function measureText(text: string): { height: number; width: number; }; export declare function parsePadding(padding: NodeData['nodePadding']): { top: number; right: number; bottom: number; left: number; }; export declare function formatText(node: NodeData): { text: any; originalText: any; width: number; height: number; nodePadding: { top: number; right: number; bottom: number; left: number; }; labelHeight: number; labelWidth: number; }; /** * Finds a node in a tree of nodes * @param nodes - The nodes to search through * @param nodeId - The id of the node to find * @returns The node if found, undefined otherwise */ export declare const findNode: (nodes: LayoutNodeData[], nodeId: string) => any | undefined; /** * Finds the number of nested children a node has * @param node - The node to search through * @returns The number of children */ export declare const getChildCount: (node: LayoutNodeData) => number; /** * Calculates the zoom for a group of nodes when fitting to the viewport * @param nodes - The nodes to calculate the zoom for * @param viewportWidth - The width of the viewport * @param viewportHeight - The height of the viewport * @param maxViewportCoverage - The maximum percentage of the viewport that the node group will take up * @param minViewportCoverage - The minimum percentage of the viewport that the node group will take up * @returns The zoom */ export declare const calculateZoom: ({ nodes, viewportWidth, viewportHeight, maxViewportCoverage, minViewportCoverage }: { nodes: LayoutNodeData[]; viewportWidth: number; viewportHeight: number; maxViewportCoverage?: number; minViewportCoverage?: number; }) => number; /** * Calculates the scroll position for the canvas when fitting nodes to the viewport - assumes the chart is centered * @param nodes - The nodes to calculate the zoom and position for * @param viewportWidth - The width of the viewport * @param viewportHeight - The height of the viewport * @param canvasWidth - The width of the canvas * @param canvasHeight - The height of the canvas * @param chartWidth - The width of the chart * @param chartHeight - The height of the chart * @param zoom - The zoom level of the canvas * @returns The scroll position */ export declare const calculateScrollPosition: ({ nodes, viewportWidth, viewportHeight, canvasWidth, canvasHeight, chartWidth, chartHeight, zoom }: { nodes: LayoutNodeData[]; viewportWidth: number; viewportHeight: number; canvasWidth: number; canvasHeight: number; chartWidth: number; chartHeight: number; zoom: number; }) => [number, number]; /** * Calculates the bounding box of a group of nodes * @param nodes - The nodes to calculate the bounding box for * @returns The bounding box */ export declare const getNodesBoundingBox: (nodes: LayoutNodeData[]) => { x0: number; y0: number; x1: number; y1: number; };