Connection Rules
The canvas refuses a connection that would touch a node that takes none, duplicate an edge, join a node to itself or - when asked to - close a cycle, and every refusal has a reason. The same rules answer from code: CheckConnection on the canvas while a connection is dragged, and BlowConnectionRules.Check with no canvas at all.
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
- Drag from A's output (right): B's input is red because A already feeds B, A's own input is red because a node may not connect to itself, Locked's is red because it takes no connections, and C's is green. The list under the canvas names each reason.
- Untick Prevent duplicate edges and drag A to B again: a second, parallel edge is made.
- Tick Allow self-connections: A's own input turns green, and a release there draws a loop.
- Tick Prevent cycles and drag from C's output to A's input: refused, because A already leads to C through B. A self-connection is a cycle too, so this also overrides Allow self-connections.
- Try to drag from Locked's handles: nothing starts. The table under the canvas checks every output against every input with the same rules, without a drag, and changes as you tick the boxes, connect, or delete an edge (select it, then Delete). Reset edges starts over.
How it works
- The rules run in a fixed order and the first that fails is the
BlowConnectionRejection:NotConnectable(a node withConnectable = false, or hidden),SameHandleType(in strict mode),SelfConnection,Duplicate, the ports' data types and limits,Cycle, and last your own rules (RejectedByRule). PreventDuplicateEdgesis on by default;AllowSelfConnectionsis off, and even on it needs two different handles;PreventCyclesis off.ConnectionRadius="30"snaps a release within 30 screen pixels to the nearest handle that accepts it.CheckConnection(nodeId, handleId, type)is the canvas's verdict on one handle for the connection being dragged - every rule, the handles' own included - andDescribeConnectiontheBlowConnectioncompleting there would make. Outside a drag,CheckConnectionanswersNotConnectable; this page asks it on eachOnConnectionChange.CanStartConnection(nodeId, handleId, type)is false for Locked, which is why its handles ignore presses;CountConnections(nodeId, type, handleId)gives the counts under each node.BlowConnectionRules.Check(nodes, edges, connection, policy)is the same decision as a pure function, for a server, a test or an import; here theBlowConnectionPolicy(PreventDuplicates,AllowSelfConnections,PreventCycles,Mode,TypeCompatibility,IsValidConnection) mirrors the checkboxes. It knows nothing of rules written on aBlowHandle, andBlowConnectionRules.Beginbinds it to one starting handle to check many candidates cheaply.