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)
}
}See Also
Developer's Guide
API
- findIntersections
Members
Constructors
Creates a new Intersections instance with default settings.
Parameters
Properties
Gets or sets the graph items that must be involved in each intersection.
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.intersectionCountSee Also
Developer's Guide
Gets or sets the graph item types that are taken into consideration when calculating the intersections.
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.
See Also
Developer's Guide
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.
See Also
Developer's Guide
Gets or sets the type of items that are considered independently of their owning element when calculating the IntersectionsResult.
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.LABELSee Also
Developer's Guide
Gets or sets the collection of edges which define a subset of the graph for the algorithms to work on.
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)See Also
Developer's Guide
Gets or sets the collection of nodes which define a subset of the graph for the algorithms to work on.
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)See Also
Developer's Guide
Methods
Calculates intersections between the items for the given graph.
Parameters
- graph: IGraph
- The input graph to run the algorithm on.
Return Value
- 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.