Home Reference Source Test Repository
public class | source

Graph

Data representation of a graph.

Constructor Summary

Public Constructor
public

constructor(nodes: Set<Node>, edges: Set<Edge>)

Constructs a Graph instance.

Member Summary

Public Members
public

edges: *

public

nodes: *

Method Summary

Public Methods
public

addEdge(edge: Edge)

Add an edge to the graph.

public

addNode(node: Node)

Add a node to the graph.

public

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

hasComponent(x: number, y: number, ignore: Node | Edge | Label): boolean

Check if the graph has a component at the given point.

public

hasEdge(start: Node, dest: Node): boolean

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 constructor(nodes: Set<Node>, edges: Set<Edge>) source

Constructs a Graph instance.

Params:

NameTypeAttributeDescription
nodes Set<Node>

Iterable containing nodes to add.

edges Set<Edge>

Iterable containing edges to add.

Public Members

public edges: * source

public nodes: * source

Public Methods

public addEdge(edge: Edge) source

Add an edge to the graph.

Params:

NameTypeAttributeDescription
edge Edge

The edge to add.

public addNode(node: Node) source

Add a node to the graph.

Params:

NameTypeAttributeDescription
node Node

The node to add.

public draw(context: CanvasRenderingContext2D) source

Draw the graph on the given canvas context.

Params:

NameTypeAttributeDescription
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.

Params:

NameTypeAttributeDescription
callback function(edge: Edge): boolean

Called once for each edge, with the edge as a parameter. Return false to skip remaining edges.

public forEachNode(callback: function(node: Node): boolean) source

Iterator for all graph nodes. Remaining nodes are skipped if the callback returns false.

Params:

NameTypeAttributeDescription
callback function(node: Node): boolean

Called once for each node, with the node as a parameter. Return false to skip remaining nodes.

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.

Params:

NameTypeAttributeDescription
x number

x-coordinate of the point.

y number

y-coordinate of the point.

Return:

Node | Edge | Label

Object at the given point if it exists, null otherwise.

public hasComponent(x: number, y: number, ignore: Node | Edge | Label): boolean source

Check if the graph has a component at the given point.

Params:

NameTypeAttributeDescription
x number

x-coordinate of the point.

y number

y-coordinate of the point.

ignore Node | Edge | Label

Object to ignore checking. This is to prevent returning true when dragging items.

Return:

boolean

Whether or not the graph has a component at the point.

public hasEdge(start: Node, dest: Node): boolean source

Check if the graph has an edge from start to dest.

Params:

NameTypeAttributeDescription
start Node

The start node.

dest Node

The dest node.

Return:

boolean

Whether or not the graph contains 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

Params:

NameTypeAttributeDescription
testNode Node

The node to check collisions for.

x number

x-coordinate of the node.

y number

y-coordinate of the node.

Return:

boolean

Whether or not there is a collision.

public removeEdge(edge: Edge) source

Remove an edge from the graph.

Params:

NameTypeAttributeDescription
edge Edge

The edge to remove.

public removeNode(node: Node) source

Remove a node from the graph.

Params:

NameTypeAttributeDescription
node Node

The node to remove.

public validate(): boolean source

Validate the graph. Called to check if imported graph is valid.

Return:

boolean

Whether or not the graph is valid.