documentationfor yFiles for HTML 2.6

Finding Adjacent Nodes and Edges

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

Example graph
graph model neighborhood

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 without respect to their direction.

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 available for ports, too:

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 do further analysis using the following methods which find the nodes that connect to the other end of incident edges at a given node:

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.

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.