Finds all intersections between nodes, edges, and labels.
Remarks
It provides means to limit the algorithm to a specific graph subset or to only consider certain item types or specific items.
The IntersectionsResult computed by this algorithm contains pairwise intersections, i.e. each Intersection object is an intersection/overlap between two graph items.
Note that if two elements "touch" in a single coordinate, this is considered as an intersection as well. For example, two nodes directly next to each other where the right border of the left node is on the same coordinate as the left border of the right node. The Intersection, in consequence, contains only two points. Testing for the number of points is a way to manually filter and ignore these kinds of intersection results.
Examples
// run intersection algorithm with default settings
const result = new Intersections().run(graph)
// highlight the edges involved in an intersection by setting a distinct edge style for them
// (other graph items could be highlighted as well)
for (const intersection of result.intersections) {
if (intersection.item1 instanceof IEdge) {
graph.setStyle(intersection.item1, highlightEdgeStyle)
}
if (intersection.item2 instanceof IEdge) {
graph.setStyle(intersection.item2, highlightEdgeStyle)
}
}
Type Details
- yFiles module
- view-layout-bridge
See Also
Constructors
Creates a new Intersections instance with default settings.
Parameters
A map of options to pass to the method.
- independentItems - GraphItemTypes
- The type of items that are considered independently of their owning element when calculating the IntersectionsResult. This option sets the independentItems property on the created object.
- considerItemGeometry - boolean
- Whether the intersections are based on the actual geometry of the items defined by their visualization or by simplified rectangular bounds for nodes, oriented rectangular bounds for labels, and line segments for edges. This option sets the considerItemGeometry property on the created object.
- consideredItemTypes - IntersectionItemTypes
- The graph item types that are taken into consideration when calculating the intersections. This option sets the consideredItemTypes property on the created object.
- affectedItems - ItemCollection<IModelItem>
- The graph items that must be involved in each intersection. This option either sets the value directly or recursively sets properties to the instance of the affectedItems property on the created object.
- subgraphNodes - ItemCollection<INode>
- The collection of nodes which define a subset of the graph for the algorithms to work on. This option either sets the value directly or recursively sets properties to the instance of the subgraphNodes property on the created object.
- subgraphEdges - ItemCollection<IEdge>
- The collection of edges which define a subset of the graph for the algorithms to work on. This option either sets the value directly or recursively sets properties to the instance of the subgraphEdges property on the created object.
Properties
Gets or sets the graph items that must be involved in each intersection.
Remarks
Examples
// run intersection algorithm with only a single affected node
const result = new Intersections({
affectedItems: { item: affectedNode },
}).run(graph)
// query the number of intersections of that node
const intersectionCountOfNode = result.intersectionCount
Gets or sets the graph item types that are taken into consideration when calculating the intersections.
Remarks
Internally, port labels are represented as NODE_LABEL, so when looking for intersections with port labels, use either ALL, NODE_LABEL or LABEL.
Default is ALL.
Gets or sets whether the intersections are based on the actual geometry of the items defined by their visualization or by simplified rectangular bounds for nodes, oriented rectangular bounds for labels, and line segments for edges.
Remarks
If enabled, the IShapeGeometry of a nodes and the IPathGeometry of edge paths are queried, and it is tested if their outline paths actually intersect. The resulting intersectionPoints are, however, still based on the bounds. Note that by default the edge path is cropped at the node's outline. If the edge has an arrow at this point, the edge is also shortened by the length of the arrow. In this case, the algorithm does not find an intersection between the edge and the node.
For labels, in any case, an oriented rectangular bound is used to detect intersections.
Default is true
.
Gets or sets the type of items that are considered independently of their owning element when calculating the IntersectionsResult.
Remarks
The default value is NONE. This means that intersections between depending items are omitted in the IntersectionsResult and only intersections between unrelated items are reported.
Item dependency is defined as follows: Labels depend on their owner, edges depend on their source/target node, and for grouped graphs the node's grouping hierarchy is considered.
Examples
// include all label intersections, even between labels and their owner
intersections.independentItems = GraphItemTypes.LABEL
// include intersections of node labels with their owner, but omit edge label owner intersections
intersections.independentItems = GraphItemTypes.NODE_LABEL
// include intersections of edge labels with their owner, but omit node label owner intersections
intersections.independentItems = GraphItemTypes.EDGE_LABEL
// include intersections of nested nodes with their parent (considers all ancestors)
intersections.independentItems = GraphItemTypes.NODE
// include intersections of edges with their source / target node
intersections.independentItems = GraphItemTypes.EDGE
// include intersections of edges with their source / target node,
// as well as all intersections between labels and their owners
intersections.independentItems =
GraphItemTypes.EDGE | GraphItemTypes.LABEL
Gets or sets the collection of edges which define a subset of the graph for the algorithms to work on.
Remarks
If nothing is set, all edges of the graph will be processed.
If only the excludes are set, all edges in the graph except those provided in the excludes are processed.
Note that edges which start or end at nodes which are not in the subgraphNodes are automatically not considered by the algorithm.
ItemCollection<T> instances may be shared among algorithm instances and will be (re-)evaluated upon (re-)execution of the algorithm.
Examples
// run intersection algorithm, keeping only a subset of edges
const result = new Intersections({
// ignore edges without target arrow heads
subgraphEdges: {
excludes: (edge: IEdge): boolean =>
edge.style instanceof PolylineEdgeStyle &&
edge.style.targetArrow instanceof Arrow &&
edge.style.targetArrow.type === ArrowType.NONE,
},
}).run(graph)
Gets or sets the collection of nodes which define a subset of the graph for the algorithms to work on.
Remarks
If nothing is set, all nodes of the graph will be processed.
If only the excludes are set, all nodes in the graph except those provided in the excludes are processed.
ItemCollection<T> instances may be shared among algorithm instances and will be (re-)evaluated upon (re-)execution of the algorithm.
Examples
// run intersection algorithm, keeping only a subset of nodes
const result = new Intersections({
// only consider elliptical nodes in the graph
subgraphNodes: {
delegate: (node) =>
node.style instanceof ShapeNodeStyle &&
node.style.shape === ShapeNodeShape.ELLIPSE,
// but ignore the first node, regardless of its shape
excludes: graph.nodes.first()!,
},
}).run(graph)
Methods
Calculates intersections between the items for the given graph.
Parameters
A map of options to pass to the method.
- graph - IGraph
- The input graph to run the algorithm on.
Returns
- ↪IntersectionsResult
- A IntersectionsResult containing the intersections.
Throws
- Exception({ name: 'InvalidOperationError' })
- If the algorithm can't create a valid result due to an invalid graph structure or wrongly configured properties.