Skip to content

@fabwcie/free-drawing / utils/binding

utils/binding ​

Variables ​

anchorAttrs ​

const anchorAttrs: readonly ["startAnchor", "endAnchor"]

Defined in: packages/free-drawing/src/utils/binding.ts:20

Sides arrow ends are fixed to, same order as bindingAttrs


anchors ​

const anchors: Anchor[]

Defined in: packages/free-drawing/src/utils/binding.ts:23

Sides of a shape an arrow end can be fixed to, clockwise from top


bindingAttrs ​

const bindingAttrs: readonly ["startBinding", "endBinding"]

Defined in: packages/free-drawing/src/utils/binding.ts:17

Arrows linked to shapes: their start and end stay on outline of shapes (startBinding / endBinding attributes: ids of shapes) when shapes move or change, fixed to a side (startAnchor / endAnchor) or aiming at their center


bindingMargin ​

const bindingMargin: 12 = 12

Defined in: packages/free-drawing/src/utils/binding.ts:29

Distance from a shape on screen (px, divided by the zoom) under which an arrow end is linked to it

Functions ​

findBindingTarget() ​

findBindingTarget(shapes, point, exclude?, margin?): DrawingShape | null

Defined in: packages/free-drawing/src/utils/binding.ts:338

Shape an arrow end can be linked to at a point: smallest visible shape around it (rectangles, ellipses, texts, freehand drawings, groups, shapes of frames), not arrows nor lines. Rectangles, ellipses and path shapes as drawn (not their box: an empty corner of the box of a triangle is out of it) near their outline, inside with a background (as their hit region: an empty inside is a free place, far from the outline of a big shape); a frame only near its border (an arrow drawn in a frame links to its shapes, or to nothing); other shapes in their box

Parameters

shapes

DrawingShape[]

Drawing shapes (with shapes of frames, see withFrameShapes)

point

Vector2d

arrow end, in coordinates of the layer of shapes

exclude?

Node<NodeConfig>

Arrow being drawn

margin?

number = bindingMargin

Distance from shapes (layer units) under which the end is linked: bindingMargin divided by the zoom

Returns

DrawingShape | null

smallest shape near the point, null when none


getAnchorAt() ​

getAnchorAt(shape, layer, point, tolerance): Anchor | undefined

Defined in: packages/free-drawing/src/utils/binding.ts:224

Side of a shape whose middle is near a point, undefined when none

Parameters

shape

Node

shape or group

layer

Container

layer of the shape

point

Vector2d

point in layer coordinates (pointer, arrow end)

tolerance

number

Distance (layer units)

Returns

Anchor | undefined

side whose middle is the nearest, if within tolerance


getAnchorPoints() ​

getAnchorPoints(shape, layer): Record<Anchor, Vector2d>

Defined in: packages/free-drawing/src/utils/binding.ts:198

Middle of each side of a shape in its layer (rotated with it), on the outline of path shapes: where the way from their center to the middle of a side of their box crosses it (side of a triangle, dip of a heart)

Parameters

shape

Node

shape or group

layer

Container

layer of the shape

Returns

Record<Anchor, Vector2d>

points by side, in layer coordinates


getArrowEnds() ​

getArrowEnds(arrow, layer, find?): ArrowEnds | null

Defined in: packages/free-drawing/src/utils/binding.ts:481

Ends of an arrow: on its linked shapes, else its own first and last points

Parameters

arrow

Arrow

Arrow

layer

Container

Layer of the arrow and its shapes

find?

(id) => Node<NodeConfig> | undefined

Shape of an id (default: searched in the layer)

Returns

ArrowEnds | null

Ends in coordinates of the arrow (see toArrowEnds), null when an end on outline aims at the center of its own shape


getBoundEnds() ​

getBoundEnds(layer, from, to, elbow?): BoundEnds | null

Defined in: packages/free-drawing/src/utils/binding.ts:385

Ends of an arrow from its linked shapes (layer coordinates): at their side, or on their outline aiming at the other end (its side, its shape center or its point); an end of an elbow arrow without side leaves the side of its shape facing the other end: across the space between them (the axis they are the farthest apart on), between their centers when they overlap

Parameters

layer

Container

layer of the arrow and its shapes

from

Vector2d | BoundEnd

Start linked to a shape, or start point

to

Vector2d | BoundEnd

End linked to a shape, or end point

elbow?

boolean = false

Elbow arrow: ends on sides, boxes of the linked shapes given

Returns

BoundEnds | null

start and end points, the sides they are fixed to and the boxes of their shapes, null when an end on outline aims at the center of its own shape


getMovedIds() ​

getMovedIds(moved): Set<string>

Defined in: packages/free-drawing/src/utils/binding.ts:525

Ids of nodes moved together (drag, transform) and of their shapes (groups, frames): what follows them while they move (updateBindings, updateBoundTexts)

Parameters

moved

Node<NodeConfig>[]

Nodes moved

Returns

Set<string>

Their ids and the ids of their descendants


getOutlineDistance() ​

getOutlineDistance(shape, layer, point): number

Defined in: packages/free-drawing/src/utils/binding.ts:285

Distance from the outline of a shape to a point: rectangles to their nearest side as drawn (rotation, scale), ellipses on the way from their center, path shapes to their outline, other shapes to their box

Parameters

shape

Node

shape or group

layer

Container

layer of the shape

point

Vector2d

point in layer coordinates (arrow end)

Returns

number

distance in layer units, negative inside (-Infinity at the center of an ellipse)


getOutlinePoint() ​

getOutlinePoint(shape, layer, towards): Vector2d | null

Defined in: packages/free-drawing/src/utils/binding.ts:271

Point of shape outline on the way from its center to a point (layer coordinates), gap outside of it. Null when the point is the center

Parameters

shape

Node

shape or group

layer

Container

layer of the shape

towards

Vector2d

point the outline point aims at, in layer coordinates

Returns

Vector2d | null

point in layer coordinates, null when towards is the center


getShapeCenter() ​

getShapeCenter(shape, layer): Vector2d

Defined in: packages/free-drawing/src/utils/binding.ts:185

Center of a shape in its layer

Parameters

shape

Node

shape or group

layer

Container

layer of the shape

Returns

Vector2d

center in layer coordinates (rectangles and ellipses: center of their own rect)


rerouteArrow() ​

rerouteArrow(arrow, layer, find?): void

Defined in: packages/free-drawing/src/utils/binding.ts:513

Path of an arrow drawn again between its ends (see getArrowEnds): after a change of its path, its bend or its middle segment

Parameters

arrow

Arrow

Arrow

layer

Container

Layer of the arrow and its shapes

find?

(id) => Node<NodeConfig> | undefined

Shape of an id (default: searched in the layer)

Returns

void


toArrowEnds() ​

toArrowEnds(arrow, layer, ends): ArrowEnds

Defined in: packages/free-drawing/src/utils/binding.ts:445

Ends of an arrow in its own coordinates, boxes of its shapes as bounding boxes there

Parameters

arrow

Arrow

Arrow

layer

Container

Layer of the arrow, coordinates of the ends

ends

BoundEnds

Ends in layer coordinates (see getBoundEnds)

Returns

ArrowEnds

Ends to route the arrow with (see routeArrow)


unbindMoved() ​

unbindMoved(moved): void

Defined in: packages/free-drawing/src/utils/binding.ts:571

Arrows moved (dragged, transformed) without their linked shapes are unlinked from them

Parameters

moved

Node<NodeConfig>[]

Nodes moved together

Returns

void


updateBindings() ​

updateBindings(layer, moved?): boolean

Defined in: packages/free-drawing/src/utils/binding.ts:538

Arrows follow their linked shapes, links to removed shapes are removed

Parameters

layer

Container

Draw layer

moved?

Set<string>

Ids of the nodes moved (drag, transform: getMovedIds): only the arrows moved or linked to them, whose ids are added to it (their labels follow them), every arrow by default

Returns

boolean

true if an arrow changed