Graph
Data representation of a graph.
Constructor Summary
Public Constructor | ||
public |
constructor(nodes: Set<Node>, edges: Set<Edge>) Constructs a Graph instance. |
Method Summary
Public Methods | ||
public |
Add an edge to the graph. |
|
public |
Add a node to the graph. |
|
public |
draw(context: CanvasRenderingContext2D) Draw the graph on the given canvas context. |
|
public |
forEachEdge(callback: function(edge: Edge): boolean) Iterator for all graph edges. |
|
public |
forEachNode(callback: function(node: Node): boolean) Iterator for all graph nodes. |
|
public |
Get the graph component at the given point, if it exists. |
|
public |
Check if the graph has a component at the given point. |
|
public |
Check if the graph has an edge from start to dest. |
|
public |
isNodeCollision(testNode: Node, x: number, y: number): boolean Checks if there is a node collision by moving a node |
|
public |
removeEdge(edge: Edge) Remove an edge from the graph. |
|
public |
removeNode(node: Node) Remove a node from the graph. |
|
public |
Validate the graph. |
Public Constructors
Public Methods
public addEdge(edge: Edge) source
Add an edge to the graph.
Params:
Name | Type | Attribute | Description |
edge | Edge | The edge to add. |
public addNode(node: Node) source
Add a node to the graph.
Params:
Name | Type | Attribute | Description |
node | Node | The node to add. |
public draw(context: CanvasRenderingContext2D) source
Draw the graph on the given canvas context.
Params:
Name | Type | Attribute | Description |
context | CanvasRenderingContext2D | Canvas 2D context. |
public forEachEdge(callback: function(edge: Edge): boolean) source
Iterator for all graph edges. Remaining edges are skipped if the callback returns false.
public forEachNode(callback: function(node: Node): boolean) source
Iterator for all graph nodes. Remaining nodes are skipped if the callback returns false.
public getComponent(x: number, y: number): Node | Edge | Label source
Get the graph component at the given point, if it exists. If multiple objects overlap, the priority is (highest to lowest): Label, Node, Edge.
public hasComponent(x: number, y: number, ignore: Node | Edge | Label): boolean source
Check if the graph has a component at the given point.
public hasEdge(start: Node, dest: Node): boolean source
Check if the graph has an edge from start to dest.
public isNodeCollision(testNode: Node, x: number, y: number): boolean source
Checks if there is a node collision by moving a node
public removeEdge(edge: Edge) source
Remove an edge from the graph.
Params:
Name | Type | Attribute | Description |
edge | Edge | The edge to remove. |