This class implements a directed graph structure.
Remarks
Basically, a directed graph consists of a set of objects called "nodes" (represented by instances of class YNode) and a set of node pairs which are called "edges" (represented by instances of class Edge).
The directed stems from the fact that all edges in the graph have direction, i.e., they have a distinct source node and a distinct target node. Using the aforementioned pair notation, an edge would be written as (<source node>, <target node>).
Class Graph presents a proper data type that provides support for all essential operations like element creation, removal, access, and iteration.
Important: Class Graph is the single authority for any structural changes to the graph data type. Specifically, this means that there is no way to create or delete a node or an edge without using an actual Graph instance.
Furthermore, this class is also responsible for providing access to its elements. This is done by means of bidirectional cursors that present a read-only view on the node set (interface INodeCursor) and edge set (interface IEdgeCursor).
This class provides direct support for the notion of data accessors. It allows to register so-called data providers (implementations of interface IDataProvider) that hold arbitrary data which is associated to its nodes and/or edges.
Also, it serves as a factory to create so-called maps (INodeMap, IEdgeMap) that can be utilized to bind arbitrary data to nodes and edges.
Type Details
- yfiles module
- algorithms
- yfiles-umd modules
- All layout modules, view-layout-bridge
- Legacy UMD name
- yfiles.algorithms.Graph
See Also
Constructors
Instantiates an empty Graph object.
Instantiates a new Graph object as a partial copy of the given graph.
Remarks
graph
. Only references to these values are copied.Parameters
A map of options to pass to the method.
Properties
Gets the number of edges in this graph.
Remarks
Yields a dynamic IEnumerable<T> for Edges that can be used to iterate over the edges that are contained in this instance.
Remarks
Gets the first edge in this graph.
Preconditions
edgeCount() > 0
Gets the first node in this graph.
Preconditions
!isEmpty()
Gets the last edge in this graph.
Preconditions
edgeCount() > 0
Gets the last node in this graph.
Preconditions
!isEmpty()
Gets the number of nodes in this graph.
Remarks
Yields a dynamic IEnumerable<T> for YNodes that can be used to iterate over the nodes that are contained in this instance.
Remarks
Gets all edge maps that have been created by this graph but have not yet been disposed.
See Also
Gets all node maps that have been created by this graph but have not yet been disposed.
See Also
Methods
Registers the given data provider using the given look-up key.
Remarks
Redefines an edge's end points.
Remarks
Edge e
has source node v := e1.source()
and target node w := e2.target()
.
Edge e
is inserted in such a way that an iteration over the edges at v
returns e
- after
e1
, ifd1 == AFTER
- before
e1
, ifd1 == BEFORE
,
and an iteration over the edges at w
returns e
- after
e2
, ifd2 == AFTER
- before
e2
, ifd2 == BEFORE
.
Preconditions
- Edges
e
,e1
, ande2
must belong to this graph.
Parameters
A map of options to pass to the method.
- e - Edge
- The edge to be changed.
- e1 - Edge
- Reference edge for insertion at a new source node.
- e2 - Edge
- Reference edge for insertion at a new target node.
- d1 - GraphElementInsertion
- d2 - GraphElementInsertion
changeEdge
(e: Edge, newSource: YNode, sourceReference: Edge, sourceD: GraphElementInsertion, newTarget: YNode, targetReference: Edge, targetD: GraphElementInsertion)Redefines an edge's end points.
Remarks
Edge e
has source node v := sourceReference.source()
or v := newSource
, if sourceReference == null
and target node w := targetReference.target()
or w := newTarget
, if targetReference == null
.
Edge e
is inserted in such a way that an iteration over the edges at v
returns e
- after
sourceReference
, ifsourceD == AFTER
- before
sourceReference
, ifsourceD == BEFORE
,
and an iteration over the edges at w
returns e
- after
targetReference
, iftargetD == AFTER
- before
targetReference
, iftargetD == BEFORE
.
Preconditions
- Edge
e
must belong to this graph. Also, eithersourceReference
ornewSource
must be non-null and belong to this graph, and eithertargetReference
ornewTarget
must be non-null and belong to this graph.
Parameters
A map of options to pass to the method.
- e - Edge
- The edge to be changed.
- newSource - YNode
- The new source node.
- sourceReference - Edge
- Reference edge for insertion at the new source node.
- sourceD - GraphElementInsertion
- newTarget - YNode
- The new target node.
- targetReference - Edge
- Reference edge for insertion at the new target node.
- targetD - GraphElementInsertion
Redefines an edge's end points.
Remarks
Preconditions
newSource
andnewTarget
must belong to this graph.
Parameters
A map of options to pass to the method.
Whether or not this graph contains the given node.
Whether or not this graph contains the given edge.
Returns whether or not this graph contains an edge that connects the given nodes.
Parameters
A map of options to pass to the method.
See Also
Creates a new edge in this graph.
Remarks
The new edge has source node v
and target node w
, i.e., would be written as edge e = (v, w)
.
The edge is appended to the lists of incoming and outgoing edges at the source node and target node, respectively.
Parameters
A map of options to pass to the method.
Returns
- ↪Edge
- The newly created Edge object.
createEdge
(v: YNode, e1: Edge, w: YNode, e2: Edge, d1: GraphElementInsertion, d2: GraphElementInsertion) : EdgeCreates a new edge in this graph to be ordered before or after a given edge.
Remarks
The new edge e
has source node v
and target node w
, i.e., would be written as edge e = (v, w)
.
Edge e
is inserted in such a way that an iteration over the edges at node v
returns e
- after
e1
, ifd1 == AFTER
- before
e1
, ifd1 == BEFORE
,
and an iteration over the edges at w
returns e
- after
e2
, ifd2 == AFTER
- before
e2
, ifd2 == BEFORE
.
Preconditions
- Edge
e1
must have source nodev
and edgee2
must have target nodew
.
Parameters
A map of options to pass to the method.
- v - YNode
- The source node of the edge.
- e1 - Edge
- An edge with source node
v
. - w - YNode
- The target node of the edge.
- e2 - Edge
- An edge with target node
w
. - d1 - GraphElementInsertion
- d2 - GraphElementInsertion
Returns
- ↪Edge
- The newly created Edge object.
Returns a newly created edge map that is valid for the edges in this graph.
Remarks
The implementation returned by this method can be used for any edge that is part of this Graph instance at any point of time, i.e., it is safe to modify the graph structure (add and remove nodes and edges) freely.
The implementation returned uses O(m)
memory at all times and provides true O(1)
read and write access for each edge.
In order to release the resources held by this map, disposeEdgeMap has to be called.
Creates an empty base object of the same type as this graph.
Remarks
Returns a newly created node map that is valid for the nodes in this graph.
Remarks
The implementation returned by this method can be used for any node that is part of this Graph instance at any point of time, i.e., it is safe to modify the graph structure (add and remove nodes and edges) freely.
The implementation returned uses O(n)
memory at all times and provides true O(1)
read and write access for each node.
In order to release the resources held by this map, disposeNodeMap has to be called.
Informs the graph that the given edge map is no longer needed.
Remarks
This method is used for EdgeMap implementations that have been obtained using the createEdgeMap factory method.
Calling this method will destroy the edge map and associated resources can be freed. It is strongly recommended to dispose of all edge maps that are not needed anymore using this method.
Informs the graph that the given node map is no longer needed.
Remarks
This method is used for NodeMap implementations that have been obtained using the createNodeMap factory method.
Calling this method will destroy the node map and associated resources can be freed. It is strongly recommended to dispose of all node maps that are not needed anymore using this method.
Returns the data provider that is registered with the graph using the given look-up key.
Remarks
Returns an array containing all edges of this graph.
Provides access to the edges of the graph.
Returns
- ↪IEdgeCursor
- An EdgeCursor to iterate over the edges in the graph.
Returns an array containing all nodes of this graph.
Provides access to the nodes of the graph.
Returns
- ↪INodeCursor
- A NodeCursor to iterate over the nodes in the graph.
Hides the given edge from this graph.
Remarks
Hiding an edge means to (temporarily) remove the edge from the graph.
Generally, hiding should only be used in the sense of temporarily removing an object that will be reinserted shortly after.
To reinsert a hidden edge use unhide.
See Also
Hides the given node from this graph.
Remarks
Hiding a node means to (temporarily) remove the node from the graph.
Generally, hiding should only be used in the sense of temporarily removing an object that will be reinserted shortly after.
To reinsert a hidden node use unhide.
See Also
Moves the given node to the first position within the sequence of nodes in this graph.
Moves the given edge to the first position within the sequence of edges in this graph.
Moves the given node to the last position within the sequence of nodes in this graph.
Moves the given edge to the last position within the sequence of edges in this graph.
Reinserts a formerly removed edge into this graph.
Remarks
The reinserted edge is appended to the sequence of edges in this graph, i.e., normally, its new position does not match the position before its removal. The same holds for the edge's positions in the list of incoming and outgoing edges at its source node and target node, respectively.
Note that reinserting an edge whose source/target is not in the graph (e.g., because it's currently hidden/removed) causes an exception. Hence, in such cases, you first have to unhide/reinsert the corresponding endpoints.
Parameters
A map of options to pass to the method.
- e - Edge
- The edge to be reinserted.
See Also
Reinserts a formerly removed node into this graph.
Remarks
Parameters
A map of options to pass to the method.
- v - YNode
- The node to be reinserted.
See Also
Removes the data provider that is registered using the given look-up key.
Removes the given node from this graph.
Remarks
All edges connecting to the given node are removed as well (preceding the actual node removal).
The node will be deselected before it gets removed.
Parameters
A map of options to pass to the method.
- v - YNode
- The node to be removed from this graph.
Reverses the given edge.
Remarks
Sorts the internally held list of edges.
Remarks
null
, then the edges will not be sorted. This list determines the order of the edges as returned by getEdgeCursor.Parameters
A map of options to pass to the method.
- comparer - IComparer<Object>
- The comparator used for the edges.
Sorts incoming and outgoing edges at each node of the graph.
Remarks
null
, then the corresponding edges (i.e., incoming/outgoing) will not be sorted. This sorts the order of the edges as returned by getOutEdgeCursor and getInEdgeCursor respectively.Parameters
A map of options to pass to the method.
- inComparer - IComparer<Object>
- The comparator used for the incoming edges at each node.
- outComparer - IComparer<Object>
- The comparator used for the outgoing edges at each node.
Sorts the internally held list of nodes.
Remarks
null
, then the nodes will not be sorted. This list determines the order of the nodes as returned by getNodeCursor.Parameters
A map of options to pass to the method.
- comparer - IComparer<Object>
- The comparator used for the nodes.
Unhides the given edge in this graph.
Remarks
Unhiding an edge means to reinsert an edge that was formerly hidden from this graph by a call to hide.
Note that unhiding an edge whose source/target is not in the graph (e.g., because it's currently hidden/removed) causes an exception. Hence, in such cases, you first have to unhide/reinsert the corresponding endpoints.