class Reactive · Core
Attach
Keeps an object placed relative to a target: the first argument follows the target from then on.
Each function links the object in its first argument (a point, segment, rectangle, circle, polygon or polyline) to a target. The link runs right away and again whenever the target changes, or one of the options given as a reactive value. It goes one way: an object moved by other code keeps that position only until the next change of its target; the target never follows the object.
Use Attach only when the target can change, for example because it is dragged, animated or driven by a
value. Things that never change are placed once with the computations (Pins, Distribute, Rectangles,
…), without a link.
Every call adds a link: call it once while setting up the graphic, not inside Reactive.do. To change a
placement later, pass a Real as the option and change its value. A target shape built from reactive
points reports their moves only after Reactive.linkVertices.
The names say what is placed and what it follows; ShapeSegment means the side from vertex index to the
next one, ShapeVertices the line between two vertices given by index:
- points:
pointToPoint,pointToSegment,pointToShapeSegment,pointBetweenShapeVertices,pointToRectangle,pointToRectangleEdge,pointToCircle - segments:
segmentToPoint,segmentToSegment,segmentToShapeSegment,segmentToShapeVertices - rectangles:
rectangleToPoint,rectangleToSegment,rectangleToShapeSegment,rectangleToShapeVertices,rectanglesAlongPolyline,rectanglesAlignedAlongPolyline; size from values:rectangleSizeToValues,rectangleHeightToValue - circles:
circleToPoint,circleCenterToPoint,circleToCircle,circleRadiusToValue - other shapes:
shapeToPoint,polygonToCircle,polylineToCircle,polylineToSegment,polylineToShapeSegment,polylineToShapeVertices
Static methods
circleCenterToPointstatic
circleRadiusToValuestatic
circleToCirclestatic
static circleToCircle(circle: Circle, target: Circle, distance?: Real | number): voidAttaches a circle to another circle with a specified radial distance offset. The circle will reactively follow the target circle, maintaining the given distance from its edge.
circle- The circle to be positioned
target- The target circle to follow
distanceoptional- The radial distance offset from the target circle's edge (default: 0)
circleToPointstatic
static circleToPoint(circle: Circle, target: Point, options?: { offset?: Vector | VectorLike }): voidAttaches a circle's center to a point. The circle will reactively follow the point, maintaining its radius.
circle- The circle to be positioned
target- The target point to attach to
optionsoptional- Configuration options for positioning
pointBetweenShapeVerticesstatic
static pointBetweenShapeVertices(point: Point, target: Shape, index1: number, index2: number, options?: { distance?: Real | number; orientation?: "relative" | "absolute"; position?: "center" | "start" | "end" | number | Real; side?: "left" | "right" }): voidAttaches a point to a segment defined by two vertices of a shape. The point will reactively follow the segment between the two specified vertices. If the point is a pin and orientation is "relative", it will be oriented along the direction of the segment (from index1 to index2).
point- The point to be positioned
target- The target shape to attach to
index1- The index of the first vertex defining the segment
index2- The index of the second vertex defining the segment
optionsoptional- Configuration options for positioning
pointToCirclestatic
static pointToCircle(point: Point, target: Circle, options?: { angle?: Real | number; distance?: Real | number; orientation?: "relative" | "absolute" }): voidAttaches a point to a circle at a specified angle with optional radial distance offset. The point will reactively follow the circle. If the point is a pin, it will be oriented radially outward from the circle's center at the specified angle.
point- The point to be positioned
target- The target circle to attach to
optionsoptional- Configuration options for positioning
pointToPointstatic
static pointToPoint(point: Point, target: Point, options?: { offset?: Vector | VectorLike; orientation?: "relative" | "absolute" }): voidAttaches a point to another point with optional offset. The point will reactively follow the target point. If both points are pins and orientation is "relative", the source pin's direction will follow the target pin's direction.
point- The point to be positioned
target- The target point to attach to
optionsoptional- Configuration options for positioning
pointToRectanglestatic
static pointToRectangle(point: Point, target: Rectangle, options?: { anchorX?: "center" | "left" | "right" | Real | number; anchorY?: "center" | "bottom" | "top" | Real | number; offsetX?: number | Real; offsetY?: number | Real; orientation?: "x-oriented" | "y-oriented" | "absolute" }): voidAttaches a point to a rectangle at a specified anchor position. The point will reactively follow the rectangle with configurable orientation. If the point is a pin and orientation is not "absolute", it will be oriented either along the X-axis (pointing right) or Y-axis (pointing up) depending on the orientation setting.
point- The point to be positioned
target- The target rectangle to attach to
optionsoptional- Configuration options for positioning
pointToRectangleEdgestatic
static pointToRectangleEdge(point: Point, target: Rectangle, options?: { anchorPosition?: "center" | "start" | "end" | number | Real; distance?: Real | number; orientation?: "relative" | "absolute"; placement?: "top" | "bottom" | "left" | "right" }): voidAttaches a point to a rectangle's edge at a specified position. The point will reactively follow the rectangle, maintaining its relative position along the chosen edge. If the point is a pin and orientation is "relative", it will be oriented along the direction of the edge (clockwise around the rectangle).
point- The point to be positioned
target- The target rectangle to attach to
optionsoptional- Configuration options for positioning
pointToSegmentstatic
static pointToSegment(point: Point, target: Segment, options?: { distance?: Real | number; orientation?: "relative" | "absolute"; position?: "center" | "start" | "end" | Real | number; side?: "left" | "right" }): voidAttaches a point to a segment at a specified position with an optional offset distance. The point will reactively follow the segment, maintaining its relative position along the segment. If the point is a pin and orientation is "relative", it will be oriented along the direction of the segment.
point- The point to be positioned
target- The target segment to attach to
optionsoptional- Configuration options for positioning
pointToShapeSegmentstatic
static pointToShapeSegment(point: Point, target: Shape, index: number, options?: { distance?: Real | number; orientation?: "relative" | "absolute"; position?: "center" | "start" | "end" | number | Real; side?: "left" | "right" }): voidAttaches a point to a specific segment of a shape at a specified position with an optional offset distance. The point will reactively follow the segment between two consecutive vertices of the shape. If the point is a pin and orientation is "relative", it will be oriented along the direction of the segment.
point- The point to be positioned
target- The target shape to attach to
index- The index of the first vertex of the segment (segment is between index and index+1, wrapping around)
optionsoptional- Configuration options for positioning
polygonToCirclestatic
static polygonToCircle(polygon: Polygon, circle: Circle, options?: { angle?: Real | number; distance?: Real | number }): voidDistributes polygon vertices evenly around a circle. The polygon vertices will be reactively positioned on the circle's circumference with optional distance offset.
polygon- The polygon whose vertices will be positioned around the circle
circle- The target circle to distribute vertices around
optionsoptional- Configuration options for positioning
polylineToCirclestatic
static polylineToCircle(polyline: Polyline, circle: Circle, span: Real | number, options?: { anchorPosition?: "center" | "start" | "end" | number | Real; angle?: Real | number; distance?: Real | number }): voidDistributes polyline vertices along a circular arc. The polyline vertices will be reactively positioned on the arc with specified angular span and anchor position.
polyline- The polyline whose vertices will be positioned along the arc
circle- The target circle defining the arc's center and base radius
span- Angular span of the arc in radians
optionsoptional- Configuration options for arc positioning
polylineToSegmentstatic
static polylineToSegment(polyline: Polyline, target: Segment, options?: { distance?: Real | number; side?: "left" | "right" }): voidDistributes polyline vertices along a segment. The polyline vertices will be reactively positioned along the segment.
polyline- The polyline whose vertices will be positioned along the segment
target- The target segment to distribute vertices along
optionsoptional- Configuration options for positioning
polylineToShapeSegmentstatic
static polylineToShapeSegment(polyline: Polyline, target: Shape, index: number, options?: { distance?: Real | number; side?: "left" | "right" }): voidDistributes polyline vertices along a specific segment of a shape. The polyline vertices will be reactively positioned along the segment between vertex at index and the next vertex (index+1). The segment wraps around if the index reaches the end of the shape's vertices.
polyline- The polyline whose vertices will be positioned along the segment
target- The target shape to distribute vertices along
index- The index of the first vertex of the segment (segment is between index and index+1, wrapping around)
optionsoptional- Configuration options for positioning
polylineToShapeVerticesstatic
static polylineToShapeVertices(polyline: Polyline, target: Shape, index1: number, index2: number, options?: { distance?: Real | number; side?: "left" | "right" }): voidDistributes polyline vertices along a segment defined by two vertices of a shape. The polyline vertices will be reactively positioned along the segment between the two specified vertices.
polyline- The polyline whose vertices will be positioned along the segment
target- The target shape to distribute vertices along
index1- The index of the first vertex defining the segment
index2- The index of the second vertex defining the segment
optionsoptional- Configuration options for positioning
rectangleHeightToValuestatic
static rectangleHeightToValue(rectangle: Rectangle, value: Real, options?: { side?: "left" | "right" }): voidBinds a reactive value to the height of a rectangle. The rectangle will reactively update its height while maintaining its baseline position. The rectangle grows either leftwards or rightwards from its baseline.
rectangle- The target rectangle to update
value- The reactive value that controls the rectangle's height
optionsoptional- Configuration options for positioning
rectanglesAlignedAlongPolylinestatic
static rectanglesAlignedAlongPolyline(rectangles: Iterable<Rectangle>, target: Polyline, options: { align: "left" | "right" | "center"; barWidth: Real | number; distance?: Real | number }): voidDistributes rectangles along a polyline with simplified alignment options. This is a convenience wrapper around rectanglesAlongPolyline with preset anchor positions.
rectangles- An iterable collection of rectangles to be distributed
target- The target polyline to distribute rectangles along
options- Configuration options for positioning
rectanglesAlongPolylinestatic
static rectanglesAlongPolyline(rectangles: Iterable<Rectangle>, target: Polyline, options: { anchorPositionX?: "center" | "left" | "right" | Real | number; anchorPositionY?: "center" | "bottom" | "top" | Real | number; barWidth: Real | number; distance?: Real | number; positionOnSegment: "start" | "end" | "center" | Real | number }): voidDistributes multiple rectangles along a polyline path. Each rectangle is positioned at a segment of the polyline, with the specified width and anchor position. The rectangles will reactively follow the polyline when it changes.
rectangles- An iterable collection of rectangles to be distributed along the polyline
target- The target polyline to distribute rectangles along
options- Configuration options for rectangle positioning
rectangleSizeToValuesstatic
static rectangleSizeToValues(rectangle: Rectangle, width: Real | number, height: Real | number): voidBinds width and height values to a rectangle's dimensions. The rectangle will reactively update its size while maintaining its position.
rectangle- The target rectangle to update
width- The reactive value or number that controls the rectangle's width
height- The reactive value or number that controls the rectangle's height
rectangleToPointstatic
static rectangleToPoint(rectangle: Rectangle, target: Point, options?: { anchorX?: Real | number | "center" | "left" | "right"; anchorY?: Real | number | "center" | "bottom" | "top"; height?: Real | number; orientation?: "relative" | "absolute"; side?: "right" | "left"; width?: Real | number }): voidAttaches a rectangle to a point with configurable dimensions and anchor point. The rectangle will reactively follow the point. When the target is a pin and orientation is "relative", the rectangle will orient according to the pin's direction. When orientation is "absolute" or the target is a plain point, the rectangle maintains a fixed orientation.
rectangle- The rectangle to be positioned
target- The target point to attach to
optionsoptional- Configuration options for positioning
rectangleToSegmentstatic
static rectangleToSegment(rectangle: Rectangle, height: Real | number, target: Segment, options?: { distance?: Real | number; paddingLeft?: Real | number; paddingRight?: Real | number; side?: "left" | "right" }): voidAttaches a rectangle to a segment with specified height and optional padding and distance offset. The rectangle will reactively follow the segment, with its baseline aligned to the segment. The rectangle's width spans the segment with optional padding on each end.
- If left and right paddings exceed the length of the segment, the rectangle is placed with width 0 at the weighted ratio of the two paddings.
rectangle- The rectangle to be positioned
height- The height of the rectangle
target- The target segment to attach to
optionsoptional- Configuration options for positioning
rectangleToShapeSegmentstatic
static rectangleToShapeSegment(rectangle: Rectangle, height: Real | number, target: Shape, index: number, options?: { distance?: Real | number; paddingLeft?: Real | number; paddingRight?: Real | number; side?: "left" | "right" }): voidAttaches a rectangle to a specific segment of a shape with specified height and optional padding and distance offset. The rectangle will reactively follow the segment between vertex at index and the next vertex (index+1). The rectangle's width spans the segment with optional padding on each end. The segment wraps around if the index reaches the end of the shape's vertices.
If left and right paddings exceed the length of the segment, the rectangle is placed with width 0 at the weighted ratio of the two paddings.
rectangle- The rectangle to be positioned
height- The height of the rectangle
target- The target shape to attach to
index- The index of the first vertex of the segment (segment is between index and index+1, wrapping around)
optionsoptional- Configuration options for positioning
rectangleToShapeVerticesstatic
static rectangleToShapeVertices(rectangle: Rectangle, height: Real | number, target: Shape, index1: number, index2: number, options?: { distance?: Real | number; paddingLeft?: Real | number; paddingRight?: Real | number; side?: "left" | "right" }): voidAttaches a rectangle to a segment defined by two vertices of a shape with specified height and optional padding and distance offset. The rectangle will reactively follow the segment between the two specified vertices. The rectangle's width spans the segment with optional padding on each end. Unlike rectangleToShapeSegment which uses consecutive vertices, this method allows attaching to any two vertices of the shape.
If left and right paddings exceed the length of the segment, the rectangle is placed with width 0 at the weighted ratio of the two paddings.
rectangle- The rectangle to be positioned
height- The height of the rectangle
target- The target shape to attach to
index1- The index of the first vertex defining the segment
index2- The index of the second vertex defining the segment
optionsoptional- Configuration options for positioning
segmentToPointstatic
static segmentToPoint(segment: Segment, target: Point, options?: { anchorPosition?: "center" | "start" | "end" | number | Real; distance?: Real | number; orientation?: "relative" | "absolute"; side?: "left" | "right" }): voidAttaches a segment to a point with configurable anchor position and orientation. The segment will reactively follow the point, maintaining its length while rotating around the anchor position. If the target is a pin and orientation is "relative", the segment will orient according to the pin's direction. When orientation is "absolute" or the target is a plain point, the segment maintains its current direction.
segment- The segment to be positioned
target- The target point to attach to
optionsoptional- Configuration options for positioning
segmentToSegmentstatic
static segmentToSegment(segment: Segment, target: Segment, options?: { distance?: Real | number; paddingLeft?: Real | number; paddingRight?: Real | number; side?: "left" | "right" }): voidAttaches a segment to another segment with optional padding and distance offset. The segment will reactively follow the target segment. The segment's endpoints are positioned along the target segment with optional padding on each end.
If left and right paddings exceed the length of the segment, the segment is placed with zero length at the weighted ratio of the two paddings.
segment- The segment to be positioned
target- The target segment to attach to
optionsoptional- Configuration options for positioning
segmentToShapeSegmentstatic
static segmentToShapeSegment(segment: Segment, target: Shape, index: number, options?: { distance?: Real | number; paddingLeft?: Real | number; paddingRight?: Real | number; side?: "left" | "right" }): voidAttaches a segment to a specific segment of a shape with optional padding and distance offset. The segment will reactively follow the segment between vertex at index and the next vertex (index+1). The segment's endpoints are positioned along the segment with optional padding on each end. The segment wraps around if the index reaches the end of the shape's vertices.
If left and right paddings exceed the length of the segment, the segment is placed with zero length at the weighted ratio of the two paddings.
segment- The segment to be positioned
target- The target shape to attach to
index- The index of the first vertex of the segment (segment is between index and index+1, wrapping around)
optionsoptional- Configuration options for positioning
segmentToShapeVerticesstatic
static segmentToShapeVertices(segment: Segment, target: Shape, index1: number, index2: number, options?: { distance?: Real | number; paddingLeft?: Real | number; paddingRight?: Real | number; side?: "left" | "right" }): voidAttaches a segment to two vertices of a shape with optional padding and distance offset. The segment will reactively follow the segment between the two specified vertices. The segment's endpoints are positioned along the segment with optional padding on each end.
If left and right paddings exceed the length of the segment, the segment is placed with zero length at the weighted ratio of the two paddings.
segment- The segment to be positioned
target- The target shape to attach to
index1- The index of the first vertex defining the segment
index2- The index of the second vertex defining the segment
optionsoptional- Configuration options for positioning
shapeToPointstatic
static shapeToPoint(shape: Shape, point: Point, options?: { offset?: Vector | VectorLike; orientateInitially?: boolean; orientation?: "relative" | "absolute" }): voidAttaches a shape to a point, making it follow the point's position and orientation. The shape will reactively translate and rotate to match the point's movements. If the point is a pin and orientation is "relative", the shape will also rotate to match the pin's direction.
shape- The shape to be attached
point- The target point to attach to
optionsoptional- Configuration options for attachment
