documentationfor yFiles for HTML 3.0.0.3

Finding Adjacent Nodes and Edges

It is often important to find the edges that connect to a given node and the nodes that connect to the opposite ends of these edges.

graph model neighborhood
Example graph

IGraph provides a set of methods for counting and finding both incoming and outgoing edges of a port owner, as well as all incident edges regardless of their direction.

Counting and retrieving incident edges of a port owner
degree(owner: IPortOwner): number

Counts the edges which start or end at the given port owner (node or edge). In the example, node A has a degree of 3.

edgesAt(owner: IPortOwner, type: AdjacencyTypes): IListEnumerable<IEdge>

Returns an enumerable with all edges which start or end at the given port owner (node or edge). In the example, edges at node A are Edge 1, Edge 2, and Edge 3.

inDegree(owner: IPortOwner): number

Counts the edges which end at the given port owner (node or edge). In the example, node A has an in-degree of 1.

inEdgesAt(owner: IPortOwner): IListEnumerable<IEdge>

Returns an enumerable with all edges which end at the given port owner (node or edge). In the example, the incoming edge of node A is Edge 1.

outDegree(owner: IPortOwner): number

Counts the edges which start at the given port owner (node or edge). In the example, node A has an out-degree of 2.

outEdgesAt(owner: IPortOwner): IListEnumerable<IEdge>

Returns an enumerable with all edges which start at the given port owner (node or edge). In the example, the outgoing edges at node A are Edge 2 and Edge 3.

The same methods are also available for ports:

Counting and retrieving adjacent edges of a port
outDegree(port: IPort): number
inDegree(port: IPort): number
degree(port: IPort): number

Counts the edges which start, end, or start or end at the given port.

outEdgesAt(port: IPort): IListEnumerable<IEdge>
inEdgesAt(port: IPort): IListEnumerable<IEdge>
edgesAt(port: IPort, type: AdjacencyTypes): IListEnumerable<IEdge>

Returns an enumerable with all edges which start, end, or start or end at the given port owner (node or edge).

You can perform further analysis using the following methods, which find the nodes that connect to the other end of incident edges at a given node:

Retrieving neighbor elements
neighbors(node: INode): IEnumerable<INode>

Returns an enumerable with the owners of the opposite ports of all edges which start or end at the given port owner. The neighbors of node A are the nodes B, C, and D.

successors(node: INode): IEnumerable<INode>

Returns an enumerable with the owners of the target ports of all edges which start at the given port owner. The successors of node A are the nodes C and D.

predecessors(node: INode): IEnumerable<INode>

Returns an enumerable with the owners of the source ports of all edges which end at the given port owner. The predecessor of node A is node B.

Tip
yFiles for HTML Complete provides support for more sophisticated graph analysis like DFS and connectivity analysis. Chapter Graph Analysis introduces the graph analysis algorithms provided by yFiles for HTML.