Skip to content
  1. API
  2. Ogma

Ogma.algorithms

Algorithms namespace of Ogma, everything to calculate metrics and run analysis on the graph.

ogma.algorithms.betweenness([options])

Returns the betweenness score for the given nodes

Arguments

ogma.algorithms.bfs(options)

Breadth first search.

Arguments

ogma.algorithms.circlePack(options)

Arguments

  • options object
    • duration(optional) number[=0] Animation duration
    • easing(optional) Easing[='linear'] Animation easing
    • margin(optional) number[=0] Margin between nodes
    • nodes NodeList Nodes to pack
    • origin(optional) Point[={x: 0, y: 0}] Origin of the circle pack
    • sort(optional) function(a: Node, b: Node): number | 'asc' | 'desc' Sorting comparator function or 'asc' or 'desc' to sort by radius in ascending or descending order from the center

Returns

  • Promise<NodeList> A promise resolving to the nodes with their new positions.

ogma.algorithms.detectCycle([options])

Returns the first cycle found as a NodeList.

Arguments

  • options(optional) object
    • edges(optional) EdgeList If omitted, adjacent edges of the provided nodes are going to be used.
    • nodes(optional) NodeList If omitted, the whole graph will be taken as input.

Returns

ogma.algorithms.dfs(options)

Depth first search.

Arguments

ogma.algorithms.getAllSimpleCycles([options])

Implements Tarjan's algorithm of finding all simple cycles in the directed graph.

Arguments

  • options(optional) object
    • edges(optional) EdgeList If omitted, adjacent edges of the provided nodes are going to be used.
    • nodes(optional) NodeList If omitted, the whole graph will be taken as input.

Returns

ogma.algorithms.getMinimumEnclosingCircle(nodes)

Calculates the minimum enclosing circle for the given nodes. It will throw an error if no nodes are provided.

Arguments

Returns

  • { x: number, y: number, radius: number } The center and radius of the circle.

ogma.algorithms.hasCycle([options])

Checks whether the given graph has cycles in it.

Arguments

  • options(optional) object
    • edges(optional) EdgeList If omitted, adjacent edges of the provided nodes are going to be used.
    • nodes(optional) NodeList If omitted, the whole graph will be taken as input.

Returns

  • Boolean

ogma.algorithms.minimumSpanningTree([nodes][, edges][, edgeCostFunction])

Kruskal's minimum-spanning-tree algorithm. It finds the edge set for the graph of the least possible edge cost that connects all the nodes of the graph.

Arguments

  • nodes(optional) NodeList Nodes of the subgraph to analyze. By default uses all the visible nodes.
  • edges(optional) EdgeList Edges of the subgraph to analyze. By default all the visible edges.
  • edgeCostFunction(optional) function(edge: Edge):number Function to get the weight of the edge, for instance it can take it from the data fields.

Returns

  • Array<{nodes: NodeList, edges: EdgeList}> List of minimum spanning trees of the graph

ogma.algorithms.shortestPath(options)

Compute the shortest path between the specified source and target nodes.

Arguments

  • options object
    • directed(optional) boolean[=false] Indicates if the graph should be considered as directed.
    • edgeCostFunction(optional) function(edge: Edge): number Function retrieving the cost of an edge. By default, returns 1 for all edges.
    • edges(optional) EdgeList[=undefined] Indicates on which elements to perform the algorithm. If not specified, allow all visible edges.
    • heuristicFunction(optional) function(source: Node, target: Node): number Function retrieving an estimation of the distance between two nodes. By default no heuristic is used.
    • nodes(optional) NodeList[=undefined] Indicates on which elements to perform the algorithm. If not specified, allow all visible nodes.
    • source Node|NodeId
    • target Node|NodeId

Returns

  • Promise<null|{nodes: NodeList, edges: EdgeList}> Shortest path. nodes has exactly one more node than edges has edges. If there is no path, returns null.