Skip to content

Align & Distribute

Line up and space out the selected nodes - the tidy-up pass every drawing tool has - with AlignSelectionAsync and DistributeSelectionAsync. Each writes nothing but the nodes' positions and is one undo step.

Align Distribute Pack 4 selected
Ingest
Validate
Transform
Score
Publish
bit Blow

Try it

  • Four nodes start selected. Select others with Shift+drag (a box round them), Shift+click (one at a time), Select all or Ctrl+A; the count at the end of the toolbar follows.
  • The six Align buttons line the selection up on its left edges, horizontal centres, right edges, top edges, vertical centres or bottom edges. The nodes differ in size, so lining up by an edge and by the centre give different results.
  • Distribute spaces three or more selected nodes evenly: the two outermost stay where they are and the gaps between all of them are made equal. If the nodes do not fit in that span, they are packed edge to edge from the first.
  • Drag Gap, then press Pack → or Pack ↓: two or more selected nodes are laid out from the first one at exactly that gap, whatever span they had.
  • Press Undo (or Ctrl+Z, and Ctrl+Y to redo) to take a step back; each align or distribute is one step. Scatter puts the nodes back where they started - as an undo step of its own.

How it works

  • AlignSelectionAsync(edge) takes a BlowAlignEdge - Left, CenterX, Right, Top, CenterY or Bottom. Edges line up with the outermost node; centres with the middle of the selection's bounding box. It needs two movable nodes.
  • DistributeSelectionAsync(horizontal) evens out the gaps across the span the nodes already cover, keeping their order, and needs three; DistributeSelectionAsync(horizontal, gap) sets a fixed gap from the first node instead, and needs two.
  • Hidden nodes and nodes that cannot be dragged are left alone, and nothing moves while NodesDraggable is off. Each node is kept inside its extent and grows a parent that expands, and screen readers hear how many nodes moved.
  • With HistoryEnabled each call is one undo step, labelled "align" or "distribute"; OnHistoryChanged feeds the Undo button, which calls UndoAsync(). Scatter refills the lists inside EditAsync(edit, "scatter"), so it is a step too.
  • SelectAllAsync() selects every selectable, visible node and edge, as Ctrl+A does, and OnSelectionChange reports the new selection for the count.
  • The arithmetic is public on BlowAlign - Align, DistributeHorizontally, DistributeVertically and Distribute - as pure functions over any list of nodes, returning the ones that moved. They take no selection and record no undo step, so they suit code that tidies a graph before it is shown. Positions are parent-relative, so pass siblings.
An unhandled error has occurred. Reload 🗙