ElbowLine
import { ElbowLine } from "cx-diagrams"The ElbowLine component connects two shapes with horizontal and vertical segments and figures out the number of segments on its own. You only tell it where the line should leave the first shape (startDirection) and in which direction it should be traveling when it enters the second shape (endDirection).
The line starts in the middle of the side that startDirection points to and ends in the middle of the side that endDirection points into. For example, endDirection="right" enters the shape on its left side and endDirection="down" enters it at the top.
Depending on the directions and the position of the shapes, the result is a straight line, an L-shaped, Z-shaped or U-shaped line, or a line with four or five segments which goes around the shapes. The route with the fewest corners is always used and it never crosses either of the two shapes. Other shapes in the diagram are not taken into account.
The shapes in the example below are wrapped in Draggable. Drag them around to see how the lines change.
Lines start and end in the middle of the side. Use startOffset and endOffset to move the endpoints along the side, e.g. to separate lines which share the same side of a shape, like the two lines leaving the bottom of shape 2 in the example.
When a shape is only a few pixels off, the first or the last segment can get too short to fit an arrow head. To prevent this, both segments are kept at least 8 pixels long and the line takes a small detour instead. Use minStartLength and minEndLength to change that, e.g. for larger arrow heads.
Use cornerRadius to round the corners, or set smooth to draw a curve which leaves and enters the shapes in the given directions.