trassel
Version:
Graph computing in JavaScript
95 lines (94 loc) • 4.16 kB
TypeScript
/**
* Main layout class
*/
export default class Layout {
/**
* @param {import("./model/ibasicnode").IBasicNode[]=} nodes - Initial nodes
* @param {import("./model/ibasicedge").IBasicEdge[]=} edges - Initial edges
* @param {import("./model/ioptions").ILayoutOptions} options - options
*/
constructor(nodes?: import("./model/ibasicnode").IBasicNode[] | undefined, edges?: import("./model/ibasicedge").IBasicEdge[] | undefined, options?: import("./model/ioptions").ILayoutOptions);
nodes: import("./model/ibasicnode").IBasicNode[];
edges: import("./model/ibasicedge").IBasicEdge[];
alpha: number;
alphaMin: number;
alphaDecay: number;
alphaTarget: number;
velocityDecay: number;
/** @type {Map<string, import("./model/ilayoutcomponentobject").ILayoutComponentObject>} */
components: Map<string, import("./model/ilayoutcomponentobject").ILayoutComponentObject>;
listeners: Map<string, Set<any>>;
loop: Loop;
quadtree: Quadtree;
isAnimating: boolean;
/**
* Registers an event listener
* @param {string} name - Event name to listen for
* @param {() => any} fn - Callback on event
*/
on(name: string, fn: () => any): void;
triggerEvent(name: any): void;
/**
* This is the main loop function.
* Each time the loop instance triggers an update this will execute.
*/
runLoop(): void;
updateNodesAndEdges(nodes: any, edges: any): void;
initializeNodesAndEdges(): void;
initializeComponent(component: any): any;
/**
* Starts the layout loop
*/
start(): void;
/**
* Stops the layout loop
*/
stop(): void;
/**
* Sets the update cap (per second) for the layout loop
* @param {number} newCap - new cap
*/
setUpdateCap(newCap: number): void;
/**
* Adds a component to the layout
* @param {string} id
* @param {import("./model/ilayoutcomponent").ILayoutComponent} component - A layout component compatible class instance
* @param {(any) => boolean=} nodeBindings - Function that computes if a node should be affected by the component. Blank means true for all.
* @param {(any) => boolean=} edgeBindings - Function that computes if an edge should be affected by the component. Blank means true for all.
* @returns {Layout} - this
*/
addLayoutComponent(id: string, component: import("./model/ilayoutcomponent").ILayoutComponent, nodeBindings?: ((any: any) => boolean) | undefined, edgeBindings?: ((any: any) => boolean) | undefined): Layout;
/**
* Removes a compnent with the specified ID
* @param {string} id
*/
removeComponent(id: string): void;
/**
* Finds the node closest to the provided coordinates
* @param {number} x
* @param {number} y
* @returns {any} - The node
*/
findClosestNodeByCoordinates(x: number, y: number): any;
/**
* Animates nodes from source positions to target positions within a duration provided.
* This function can be used to transition the graph between states or layouts.
* Once triggered the animation cannot be stopped. All other updates and components will be frozen until the animation completes.
* There should *never* be more than one animation running simultaneously.
* @param {import("./model/itargetnodestate").ITargetNodeState[]} targetNodeStates
* @param {number} duration - Animation duration in milliseconds
* @param {boolean} shouldFixateOnEnd - If true then the graph will fixate the nodes when the animation ends
*/
animateState(targetNodeStates?: import("./model/itargetnodestate").ITargetNodeState[], duration?: number, shouldFixateOnEnd?: boolean): void;
nodeMap: {} | undefined;
/**
* Main update function.
* This executes all components in the layout and computes node positions.
* Note that the update function can be executed without the looper.
* @param {boolean} sendEvent - Should an update event be fired?
*/
update(sendEvent?: boolean): void;
iteration: any;
}
import Loop from "./loop";
import Quadtree from "./util/quadtree";