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.
Press Tab to move between the nodes and edges of the diagram.
Press Enter or Space to select it, Shift with Enter to add it to the selection, the arrow keys to move the selected nodes, Delete to remove them and Escape to clear the selection. Press C to start a connection from it.
Press Enter or Space to select it, Delete to remove it and Escape to clear the selection. Press C to move its end to another node.
bit BlowTry 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 aBlowAlignEdge-Left,CenterX,Right,Top,CenterYorBottom. 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
NodesDraggableis off. Each node is kept inside its extent and grows a parent that expands, and screen readers hear how many nodes moved. - With
HistoryEnabledeach call is one undo step, labelled "align" or "distribute";OnHistoryChangedfeeds the Undo button, which callsUndoAsync(). Scatter refills the lists insideEditAsync(edit, "scatter"), so it is a step too. SelectAllAsync()selects every selectable, visible node and edge, as Ctrl+A does, andOnSelectionChangereports the new selection for the count.- The arithmetic is public on
BlowAlign-Align,DistributeHorizontally,DistributeVerticallyandDistribute- 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.