Skip to content

@fabwcie/free-drawing / utils/boundText

utils/boundText ​

Variables ​

containerShapes ​

const containerShapes: string[]

Defined in: packages/free-drawing/src/utils/boundText.ts:18

Texts of shapes: a text with a containerId attribute (id of a rectangle, an ellipse, a path shape or an arrow) is placed in its shape (updateBoundTexts): centered in it as wide as its inside and turned with it, or centered on the middle of an arrow (label). It is selected, moved, styled and removed with its shape

Functions ​

findContainerAt() ​

findContainerAt(shapes, layer, point): Shape<ShapeConfig> | null

Defined in: packages/free-drawing/src/utils/boundText.ts:290

Shape whose text is edited at a point: smallest rectangle, ellipse or path shape around it (also without background: its empty inside)

Parameters

shapes

Node<NodeConfig>[]

Drawing shapes (shapes of frames too)

layer

Container

Draw layer

point

Vector2d

Point in layer coordinates (double click)

Returns

Shape<ShapeConfig> | null

Smallest shape around the point, null when none


getBoundText() ​

getBoundText(container, layer, index?): Text | null

Defined in: packages/free-drawing/src/utils/boundText.ts:82

Text of a shape

Parameters

container

Node

Rectangle, ellipse, path shape or arrow

layer

Container

Draw layer

index?

LayerIndex

Index of the layer (indexLayer), else the layer is searched

Returns

Text | null

Its text, null without text


getContainer() ​

getContainer(text, layer, index?): Shape<ShapeConfig> | null

Defined in: packages/free-drawing/src/utils/boundText.ts:68

Shape holding a text

Parameters

text

Node

Text of a shape

layer

Container

Draw layer

index?

LayerIndex

Index of the layer (indexLayer), else the layer is searched

Returns

Shape<ShapeConfig> | null

Its shape, null when removed


indexLayer() ​

indexLayer(layer): LayerIndex

Defined in: packages/free-drawing/src/utils/boundText.ts:47

Nodes of a layer by id and texts of shapes by the id of their shape, found in one walk: for an operation looking up many shapes (a search of the layer for each one would take the square of the number of shapes)

Parameters

layer

Container

Draw layer

Returns

LayerIndex

Index of the layer as it is now


isBoundText() ​

isBoundText(node): node is Text

Defined in: packages/free-drawing/src/utils/boundText.ts:39

Text of a shape (containerId attribute)

Parameters

node

Node

Node of the drawing

Returns

node is Text

True for a text placed in a shape


isContainer() ​

isContainer(node): node is Shape<ShapeConfig>

Defined in: packages/free-drawing/src/utils/boundText.ts:31

Shape that can hold a text

Parameters

node

Node

Node of the drawing

Returns

node is Shape<ShapeConfig>

True for rectangles, ellipses, path shapes and arrows


placeBoundText() ​

placeBoundText(text, container, background): boolean

Defined in: packages/free-drawing/src/utils/boundText.ts:173

Place a text in its shape: centered in it, as wide as its inside (inner rectangle of ellipses, 70 % of path shapes) and turned with it, never scaled (a resize of the shape changes its width, not its letters), readable in a flipped shape or group; label of an arrow: centered on its middle, as wide as its lines, halo of the background color. Hidden with its shape

Parameters

text

Text

Text of the shape

container

Shape

Its shape

background

string

Background color of the drawing (halo of arrow labels)

Returns

boolean

True when the text changed


updateBoundTexts() ​

updateBoundTexts(layer, background, moved?): boolean

Defined in: packages/free-drawing/src/utils/boundText.ts:262

Texts of shapes placed in their shapes (after a move, a resize, a change); a text whose shape was removed is no longer bound to it (a free text)

Parameters

layer

Container

Draw layer

background

string

Background color of the drawing (halo of arrow labels)

moved?

Set<string>

Ids of the nodes moved (drag, transform: see getMovedIds of utils/binding): only their texts and the texts moved, every text by default

Returns

boolean

True when a text changed


withBoundTexts() ​

withBoundTexts<T>(nodes, layer): T[]

Defined in: packages/free-drawing/src/utils/boundText.ts:96

Shapes with the texts they hold and the shapes holding them: selected, moved, styled and removed together

Type Parameters

T

T extends Node<NodeConfig>

Parameters

nodes

T[]

Shapes (selection...)

layer

Container

Draw layer

Returns

T[]

Shapes and their partners, each one once, in their order


withoutBoundTexts() ​

withoutBoundTexts<T>(nodes): T[]

Defined in: packages/free-drawing/src/utils/boundText.ts:111

Shapes arranged by themselves (align, distribute, stack): texts of shapes and labels of arrows given with their shape follow it, they are not counted

Type Parameters

T

T extends Node<NodeConfig>

Parameters

nodes

T[]

Shapes (selection...)

Returns

T[]

Shapes without the texts whose shape is given too