C

Intersections

Finds all intersections between nodes, edges, and labels.
Inheritance Hierarchy

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

Finding and highlighting the edges that intersect with some other item
// 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

No filters for this type

Constructors

Creates a new Intersections instance with default settings.

Parameters

Properties

Gets or sets the graph items that must be involved in each intersection.
If nothing is specified explicitly, all nodes, edges, and labels are considered.
To find all intersections of a specific item (e.g. node) with all other graph items, specify that item as the single affected and specify ALL (see snippet).
conversionfinal

Examples

Get all intersections of a single node
// 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

See 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.

conversionfinal

See Also

Developer's Guide
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.

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.

Enabling this additional geometric path intersection increases the runtime of the algorithm.
The intersectionPoints are always based on the bounds, even when enabling this property. Therefore, this feature is useful if only testing whether items intersect while the actual intersection points are not important.
final

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.

conversionfinal

Examples

Different combinations of independent items
// 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

See 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.

The edges provided here must be part of the graph which is passed to the run method.
conversionfinal

Examples

Calculating all intersections on a subset of the graph
// 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.

The nodes provided here must be part of the graph which is passed to the run method.
conversionfinal

Examples

Calculating all intersections on a subset of the graph
// 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.
The result obtained from this algorithm is a snapshot which is no longer valid once the graph has changed, e.g. by adding or removing nodes or edges.
final

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.