Anchor Points and Patterns

Anchor Points

For each node you can define one or more points to which links should dock when connecting to that node. Such points are represented by instances of the AnchorPoint class. The position of an anchor point relative to node’s bounding rectangle is specified via the x and y properties. Their values are expressed as percentage of the node’s width and height to accommodate for moving and resizing. You can control whether an anchor point accepts incoming or outgoing links or both. That is done via the allowIncoming and allowOutgoing properties. When a link is drawn, its ends are aligned to the nearest anchor points allowing docking of the respective end type.

## Anchor Patterns

An AnchorPattern instance defines a set of anchor points to be used together. When creating an anchor pattern, pass to its constructor an array of AnchorPoint objects. The AnchorPattern class exposes several predefined patterns as static properties. An existing pattern can be assigned as a single entity to the anchorPattern property of nodes. The following example creates a pattern of four anchor points:

let apat1 = AnchorPattern(points: [
    AnchorPoint(x: 50, y: 0, allowIncoming: true, allowOutgoing: true),
    AnchorPoint(x: 100, y: 50, allowIncoming: true, allowOutgoing: true),
    AnchorPoint(x: 50, y: 100, allowIncoming: true, allowOutgoing: true),
    AnchorPoint(x: 0, y: 50, allowIncoming: true, allowOutgoing: true)
    ])

The points are located at the middles of bounding rectangle sides of nodes to which the pattern is assigned. All four points accept both incoming and outgoing links.