UNPKG

trassel

Version:
274 lines (273 loc) 14.3 kB
/** * Main API for using the graph engine. */ export default class Graph { /** * @param {import("./model/ibasicnode").IBasicNode[]=} nodes - Initial nodes * @param {import("./model/ibasicedge").IBasicEdge[]=} edges - Initial edges * @param {import("./model/ioptions").IOptions} options - options */ constructor(nodes?: import("./model/ibasicnode").IBasicNode[] | undefined, edges?: import("./model/ibasicedge").IBasicEdge[] | undefined, options?: import("./model/ioptions").IOptions); /** @private */ private nodes; /** @private */ private edges; /** @private */ private options; /** @private */ private layout; /** @private */ private dataManager; /** * Sets the current alpha value in the layout. * @param {number} alpha - Alpha value * @returns {Graph} */ setLayoutAlpha(alpha: number): Graph; /** * Sets the minimum allowed alpha value in the layout. When this value is reached the loop will end. * @param {number} alphaMin - Minimum alpha value * @returns {Graph} */ setLayoutAlphaMin(alphaMin: number): Graph; /** * Sets the alpha decay rate in the layout. This determines how much the alpha value decreases on each update. * @param {number} alphaDecay - Alpha decay rate * @returns {Graph} */ setLayoutAlphaDecay(alphaDecay: number): Graph; /** * Sets the alpha target in the layout. This sets what alpha value the layout is trying to reach. * @param {number} alphaTarget - Target alpha value * @returns {Graph} */ setLayoutAlphaTarget(alphaTarget: number): Graph; /** * Sets the velocity decay rate in the layout. * @param {number} velocityDecay - Velocity decay rate * @returns {Graph} */ setLayoutVelocityDecay(velocityDecay: number): Graph; /** * Sets the update cap (per second) for the layout loop * @param {number} newCap - new cap */ setLayoutUpdateCap(newCap: number): void; /** * Computes communities (groups) based on nodes and edges in the graph * Returns an array of communities, containing nodes grouped by belonging * @returns {{communities: import("../model/nodeid").NodeID[][], communityTable: {[key: string]: any}}} */ computeCommunities(): { communities: any[][]; communityTable: { [key: string]: any; }; }; /** * Computes communities (groups) based on nodes and edges in the graph * Returns an array of communities, containing nodes grouped by belonging * @returns {{communities: import("../model/nodeid").NodeID[][], communityTable: {[key: string]: any}}} */ louvain(): { communities: any[][]; communityTable: { [key: string]: any; }; }; /** * Updates the nodes and edges in the graph * @param {import("./model/ibasicnode").IBasicNode[]} nodes * @param {import("./model/ibasicedge").IBasicEdge[]} edges * @returns {Graph} */ updateNodesAndEdges(nodes: import("./model/ibasicnode").IBasicNode[], edges: import("./model/ibasicedge").IBasicEdge[]): Graph; /** * Starts the layout engine's loop * @returns {Graph} */ startLayoutLoop(): Graph; /** * Stops the layout engine * @returns {Graph} */ stopLayoutLoop(): Graph; /** * Executes one update in the layout engine * @param {boolean} sendEvent - Should an update event be fired? * @returns {Graph} */ updateLayout(sendEvent?: boolean): Graph; /** * Registers an event listener * @param {(import("./model/events").EEvents} name - Event name to listen for * @param {(() => any)} fn - Callback on event * @returns {Graph} */ on(name: (import("./model/events").EEvents), fn: (() => any)): Graph; /** * 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 */ animateLayoutState(targetNodeStates?: import("./model/itargetnodestate").ITargetNodeState[], duration?: number, shouldFixateOnEnd?: boolean): void; /** * Adds a component to the layout engine * @param {string} id - Unique identifier for the component * @param {import("./model/ilayoutcomponent").ILayoutComponent} component - A layout component compatible class instance * @param {(node: import("./model/igraphnode").IGraphNode) => boolean=} nodeBindings - Function that computes if a node should be affected by the component. Blank means true for all. * @param {(edge: import("./model/igraphedge").IGraphEdge) => boolean=} edgeBindings - Function that computes if an edge should be affected by the component. Blank means true for all. * @returns {Graph} - this */ addLayoutComponent(id: string, component: import("./model/ilayoutcomponent").ILayoutComponent, nodeBindings?: ((node: import("./model/igraphnode").IGraphNode) => boolean) | undefined, edgeBindings?: ((edge: import("./model/igraphedge").IGraphEdge) => boolean) | undefined): Graph; /** * Removes a component with the specified ID * @param {string} id * @returns {Graph} */ removeLayoutComponent(id: string): Graph; /** * Finds the node closest to the provided coordinates in the graph * @param {number} x * @param {number} y * @returns {import("./model/igraphnode").IGraphNode} - The node */ findClosestNodeByCoordinates(x: number, y: number): import("./model/igraphnode").IGraphNode; /** * Computes online nodes * @returns {import("./model/ibasicnode").IBasicNode[]} node */ getOnlineNodes(): import("./model/ibasicnode").IBasicNode[]; /** * Computes offline nodes * @returns {import("./model/ibasicnode").IBasicNode[]} node */ getOfflineNodes(): import("./model/ibasicnode").IBasicNode[]; /** * Computes online edges * @returns {import("./model/ibasicedge").IBasicEdge[]} edge */ getOnlineEdges(): import("./model/ibasicedge").IBasicEdge[]; /** * Computes offline edges * @returns {import("./model/ibasicedge").IBasicEdge[]} edge */ getOfflineEdges(): import("./model/ibasicedge").IBasicEdge[]; /** * Checks if an edge is online * @param {import("./model/ibasicnode").IBasicEdge} edge * @returns {boolean} */ isEdgeOnline(edge: any): boolean; /** * Checks if a node is online * @param {string} nodeID * @returns {boolean} */ isNodeOnline(nodeID: string): boolean; /** * Brings the list of node IDs offline * @param {import("./model/nodeid").NodeID[]} nodeIDs */ bringNodesOffline(nodeIDs: import("./model/nodeid").NodeID[]): void; /** * Brings the list of node IDs online * @param {import("./model/nodeid").NodeID[]} nodeIDs */ bringNodesOnline(nodeIDs: import("./model/nodeid").NodeID[]): void; bringAllNodesOffline(): void; bringAllNodesOnline(): void; /** * Retrieves all neighbors for a given nodeID * @param {import("./model/nodeid").NodeID} nodeID - ID od the node neighbors should be retrieved for * @param {boolean} isDirected - Only traverse edges where the input node is the sourceNode * @param {boolean} useOnlyOnline - Only traverse neighbors that are online * @param {boolean} ignoreInternalEdges - Ignore self-edges * @returns {import("./model/nodeid").NodeID[]} */ getNeighbors(nodeID: import("./model/nodeid").NodeID, isDirected?: boolean, useOnlyOnline?: boolean, ignoreInternalEdges?: boolean): import("./model/nodeid").NodeID[]; /** * Computes collateral nodes in implodes or explode operations from a root node (I.e. bringing connected neighbors online/offline) * This function will not apply any changes, but return an array with affected nodes * The function exists specifically to help applications that implement implode/explode functionality in graphs * and need to compute what nodes should be brough online/offline. * @param {import("./model/nodeid").NodeID} nodeID * @param {boolean} isBringOnline - If true neighbors will be brought online otherwise offline * @param {boolean} isDirected - If true then operation will be directed * @param {"single"|"recursive"|"leafs"} mode - Single means all neighbors are affected, leafs means only neighbors with no other neighbors are affected, recursive means neighbors recursively are affected. * @returns {import("./model/nodeid").NodeID[]} - Affected nodes */ computeImplodeOrExplodeNode(nodeID: import("./model/nodeid").NodeID, isBringOnline?: boolean, isDirected?: boolean, mode?: "single" | "recursive" | "leafs"): import("./model/nodeid").NodeID[]; /** * Specifically meant to support renderers in determining optimal target positions for nodes that are being brough online. * Accepts an array of node IDs and origin coordinates where the nodes should be animated from. * Returns an array of vertices with optimal positions based on other neighbors present in the graph, or in the case of leafs a circle around the origin. * Note(!) that this function expects all nodes and edges to have been initialized into GraphNodes and GraphEdges in order to compute this information. * @param {import("./model/nodeid").NodeID[]} nodeIDs - Array of node IDs * @param {number} distance - Default distance from origin position to put nodes (for non-average values only!) * @param {number} originX - Start position for the transition * @param {number} originY - Start position for the transition * @returns {{id: import("./model/nodeid").NodeID, x: number, y: numer}[]} - Target coordinates */ stageNodePositions(nodeIDs?: import("./model/nodeid").NodeID[], distance?: number, originX?: number, originY?: number): { id: import("./model/nodeid").NodeID; x: number; y: numer; }[]; /** * Computes the shortest path from one node to another. Returns an array with the nodeIDs, or null if there is no path. * @param {import("./model/nodeid").NodeID} startNode - Node ID where the road starts * @param {import("./model/nodeid").NodeID} endNode - Node ID where the road ends * @param {boolean} useOnlyOnline - If true the shortest path will only be computed for live nodes * @param {boolean} isDirected - If true then operation will be directed * @return {import("./model/nodeid").NodeID[]} - Array of node IDs from startnode to endnode containing the (a) shortest path */ findShortestPathUnweighted(startNode: import("./model/nodeid").NodeID, endNode: import("./model/nodeid").NodeID, useOnlyOnline?: boolean, isDirected?: boolean): import("./model/nodeid").NodeID[]; /** * Computes the shortest path from one node to another. Returns an array with the nodeIDs, or null if there is no path. * This is basically Dijkstra's algorithm: * https://en.wikipedia.org/wiki/Dijkstra's_algorithm * @param {import("./model/nodeid").NodeID} startNode - Node ID where the road starts * @param {import("./model/nodeid").NodeID} endNode - Node ID where the road ends * @param {boolean} useOnlyOnline - If true the shortest path will only be computed for live nodes * @param {boolean} isDirected - If true then operation will be directed * @param {boolean} aggregateEdgeWeights - If true then weights for all edges between a set of nodes are aggregated and treated as a single edge * @return {{id: import("./model/nodeid").NodeID, cost: number}[]} - Array of nodes and costs from startnode to endnode containing the (a) cheapest path */ findShortestPathWeighted(startNode: import("./model/nodeid").NodeID, endNode: import("./model/nodeid").NodeID, useOnlyOnline?: boolean, isDirected?: boolean, aggregateEdgeWeights?: boolean): { id: import("./model/nodeid").NodeID; cost: number; }[]; /** * Computes strongly connected components in the graph. * Basically an implementation of Kosoraju's algorithm. * https://en.wikipedia.org/wiki/Kosaraju%27s_algorithm * @param {boolean} useOnlyOnline - If true the shortest path will only be computed for live nodes * @return {("./model/nodeid").NodeID[][]} - Strongly connected components. */ computeStronglyConnectedComponents(useOnlyOnline?: boolean): ("./model/nodeid"); /** * Executes a breadth-first search in the graph given a start node. * Each node encountered will be handed off to a callback function provided, * If the callback function returns true then that branch will be terminated. * @param {import("./model/nodeid").NodeID} startNode * @param {(import("./model/nodeid").NodeID) => void|true} callback * @param {boolean} useOnlyOnline - If true only online nodes will be processed * @param {boolean} isDirected - If true then traversal will be directed */ BFS(startNode: import("./model/nodeid").NodeID, callback: any, useOnlyOnline?: boolean, isDirected?: boolean): void; /** * Executes a depth-first search in the graph given a start node. * Each node encountered will be handed off to a callback function provided, * If the callback function returns true then that branch will be terminated. * @param {import("./model/nodeid").NodeID} startNode * @param {(import("./model/nodeid").NodeID) => void|true} callback * @param {boolean} useOnlyOnline - If true only online nodes will be processed * @param {boolean} isDirected - If true then traversal will be directed */ DFS(startNode: import("./model/nodeid").NodeID, callback: any, useOnlyOnline?: boolean, isDirected?: boolean): void; }