new Graph()
Constructs a new graph.
Members
-
digraph :Boolean
-
Whether this graph is directed or not.
- Default Value:
- false
Methods
-
addEdge(edge) → {Graph}
-
Adds an edge to the graph. If the graph is undirected, the method automatically creates the opponent edge.
Parameters:
Name Type Description edge
Edge The edge to add.
-
addNode(node) → {Graph}
-
Adds a node to the graph.
Parameters:
Name Type Description node
Node The node to add.
-
clear() → {Graph}
-
Removes all nodes and edges from this graph.
-
fromJSON(json) → {Graph}
-
Restores this instance from the given JSON object.
Parameters:
Name Type Description json
Object The JSON object.
-
getEdge(from, to) → {Edge}
-
Returns an edge for the given from and to node indices. If no node is found, null is returned.
Parameters:
Name Type Description from
Number The index of the from node.
to
Number The index of the to node.
-
getEdgeCount() → {number}
-
Returns the edge count of the graph.
Returns:
number -The amount of edges.
-
getEdgesOfNode(index, result) → {Array.<Edge>}
-
Gathers all edges leading from the given node index and stores them into the given array.
Parameters:
Name Type Description index
Number The node index.
result
Array.<Edge> The result array.
-
getNode(index) → {Node}
-
Returns a node for the given node index. If no node is found, null is returned.
Parameters:
Name Type Description index
Number The index of the node.
-
getNodeCount() → {number}
-
Returns the node count of the graph.
Returns:
number -The amount of nodes.
-
getNodes(result) → {Array.<Node>}
-
Gathers all nodes of the graph and stores them into the given array.
Parameters:
Name Type Description result
Array.<Node> The result array.
-
hasEdge(from, to) → {Boolean}
-
Return true if the graph has an edge connecting the given from and to node indices.
Parameters:
Name Type Description from
Number The index of the from node.
to
Number The index of the to node.
Returns:
Boolean -Whether this graph has the edge or not.
-
hasNode(index) → {Boolean}
-
Return true if the graph has the given node index.
Parameters:
Name Type Description index
Number The node index to test.
Returns:
Boolean -Whether this graph has the node or not.
-
removeEdge(edge) → {Graph}
-
Removes the given edge from the graph. If the graph is undirected, the method also removes the opponent edge.
Parameters:
Name Type Description edge
Edge The edge to remove.
-
removeNode(node) → {Graph}
-
Removes the given node from the graph and all edges which are connected with this node.
Parameters:
Name Type Description node
Node The node to remove.
-
toJSON() → {Object}
-
Transforms this instance into a JSON object.
Returns:
Object -The JSON object.