Class: Graph

Kekule. Graph

new Graph()

A class to represent a abstract graph.
Properties:
Name Type Description
vertexes Array All nodes in this graph.
edges Array Connectors in this graph.
Source:

Extends

  • ObjectEx

Methods

addEdge(edge, vertex1, vertex2)

Add an edge to graph and connect it to vertex1 and vertex2.
Parameters:
Name Type Description
edge Kekule.GraphEdge
vertex1 Kekule.GraphVertex
vertex2 Kekule.GraphVertex
Source:

addVertex(vertex)

Add a new vertex to graph.
Parameters:
Name Type Description
vertex Kekule.GraphVertex
Source:

newEdge(vertex1, vertex2) → {Kekule.GraphEdge}

Create a new edge in graph and connect it to vertex1 and vertex2.
Parameters:
Name Type Description
vertex1 Kekule.GraphVertex
vertex2 Kekule.GraphVertex
Source:
Returns:
Type
Kekule.GraphEdge

newVertex() → {Kekule.GraphVertex}

Create a new vertex in graph.
Source:
Returns:
Type
Kekule.GraphVertex

removeEdge(edge)

Remove an edge from graph.
Parameters:
Name Type Description
edge Kekule.GraphEdge
Source:

removeVertex(vertex)

Remove a vertex (and its connected edges) from graph.
Parameters:
Name Type Description
vertex Kekule.GraphVertex
Source:

traverse(callback, startingVertex, mode) → {Array}

Traverse the whole graph. Each vertex or edge traversed will be passed in callback function.
Parameters:
Name Type Description
callback Func Callback(currObj, isEdge).
startingVertex Kekule.GraphVertex If not set, first vertex of graph will be used as starting point.
mode Int Traverse mode, depth or breadth first, value from Kekule.GraphTraverseMode.
Source:
Returns:
Items are hash object containing the following fields: { vertexes: Array, edges: Array } which stores the traverse sequence. As the graph may not be a connected one, so several sequence may be returned.
Type
Array

Kekule. Graph

new Graph()

Source:

Methods

addEdge(edge, vertex1, vertex2)

Add an edge to graph and connect it to vertex1 and vertex2.
Parameters:
Name Type Description
edge Kekule.GraphEdge
vertex1 Kekule.GraphVertex
vertex2 Kekule.GraphVertex
Source:

addVertex(vertex)

Add a new vertex to graph.
Parameters:
Name Type Description
vertex Kekule.GraphVertex
Source:

newEdge(vertex1, vertex2) → {Kekule.GraphEdge}

Create a new edge in graph and connect it to vertex1 and vertex2.
Parameters:
Name Type Description
vertex1 Kekule.GraphVertex
vertex2 Kekule.GraphVertex
Source:
Returns:
Type
Kekule.GraphEdge

newVertex() → {Kekule.GraphVertex}

Create a new vertex in graph.
Source:
Returns:
Type
Kekule.GraphVertex

removeEdge(edge)

Remove an edge from graph.
Parameters:
Name Type Description
edge Kekule.GraphEdge
Source:

removeVertex(vertex)

Remove a vertex (and its connected edges) from graph.
Parameters:
Name Type Description
vertex Kekule.GraphVertex
Source:

traverse(callback, startingVertex, mode) → {Array}

Traverse the whole graph. Each vertex or edge traversed will be passed in callback function.
Parameters:
Name Type Description
callback Func Callback(currObj, isEdge).
startingVertex Kekule.GraphVertex If not set, first vertex of graph will be used as starting point.
mode Int Traverse mode, depth or breadth first, value from Kekule.GraphTraverseMode.
Source:
Returns:
Items are hash object containing the following fields: { vertexes: Array, edges: Array } which stores the traverse sequence. As the graph may not be a connected one, so several sequence may be returned.
Type
Array