Custom Connection Lines & Live Connection State
The line drawn while you make a connection, three ways: the built-in line, the built-in line restyled with
ConnectionLineStyle and ConnectionLineClass, or SVG of your own from
ConnectionLineTemplate. OnConnectionChange reports the live
BlowConnectionLineContext - where the line runs, and whether it could connect where it ends.
Connection state
idle - drag from a handle
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 the bottom handle of Drag from here: a dashed gradient line follows the pointer, and its end dot turns green over a handle that would accept the connection. Release on the top handle of an Open target to connect.
- Watch Connection state as you drag: where the line starts and ends, whether it could connect, and why not - RejectedByRule over the Locked node, SameHandleType over an Open target's bottom handle (another source), Duplicate over a target you have already connected, and no handle in reach out on the empty pane.
- Press Escape while dragging: the line disappears, nothing connects and the panel goes back to idle.
- Switch Line to Restyled built-in line for a thicker amber line with marching dashes, or to Built-in line for the plain line in the theme's connection colour.
- Pick another Path - Straight, Step, SmoothStep, SimpleBezier - and the line takes that shape, in all three modes.
- Raise Drag threshold to 40, press a handle and move slowly: no line is drawn, and the panel's to point stays put, until the pointer has travelled 40 pixels.
How it works
ConnectionLineType(defaultBezier) is the built-in line's path; the template hands the sameBlowEdgeTypetoBlowEdgePath.Compute, so the Path select shapes both.ConnectionLineStyleis an inline style for the built-in line - herestroke:#f59e0b;stroke-width:3- andConnectionLineClassadds classes to it - here one whose CSS animates the dashes. Both are ignored while a template draws the line.ConnectionLineTemplateis aRenderFragment<BlowConnectionLineContext>drawn in the canvas's edge layer, so it renders SVG in flow coordinates. This page passes a Razor template only while Custom template is chosen; otherwise the parameter is null and the built-in line is drawn.BlowConnectionLineContextcarriesFromNode,FromHandle,FromHandleType,FromPosition,From,To,ToPosition,IsValidandRejection.OnConnectionChangeis raised when a connection starts, on every move while it is dragged, and once with null when it ends.IsValidis true when the line ends on a handle that would accept it, or withinConnectionRadius(20 screen pixels) of one.Rejection, aBlowConnectionRejection, says why the nearest handle would refuse it:RejectedByRulewhenIsValidConnectionreturned false,SameHandleTypebecauseConnectionModeisStrictby default,DuplicatebecausePreventDuplicateEdgesis on by default. It isNonewhen no handle is near.IsValidConnectionrefuses every connection whose target node'sDatais"locked".ConnectionDragThreshold(default 1) is how far, in screen pixels, the pointer has to travel before the line is drawn and its moves reported, so a click on a handle does not flash a line.- Escape abandons the gesture in progress - nothing to wire up.