Drag and Drop
A palette beside the canvas: drag a node type onto the flow and it lands under the cursor, because the drop's screen position is turned into flow coordinates with ScreenToFlowPosition. FlowToScreenPosition goes the other way, and clicking an item adds it without dragging 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 Input Node, Default Node or Output Node from the palette and drop it on the canvas: the new node is centred on the pointer.
- Pan and zoom first, then drop again: it still lands under the pointer, since the conversion uses the current viewport. The toolbar shows the drop point on screen, the same point in the flow, and the new node's corner converted back to the screen.
- Click a palette item, or Tab to it and press Enter, to add it in the middle of the view instead; each further one is set a little lower and to the right so they do not stack.
- Connect the new nodes by dragging from their handles, as with any other node.
How it works
- The palette items are plain HTML with
draggable="true";@ondragstartremembers which type is on its way. - The element round the canvas has
@ondragover:preventDefault- without it the browser refuses the drop - and@ondropreceives aDragEventArgswith the pointer'sClientXandClientY. ScreenToFlowPositionAsync(clientX, clientY)turns that client point into flow coordinates through the current pan and zoom, reading where the pane is on the page again first if dragging scrolled it (ScreenToFlowPositionis the synchronous form). Half the node's size is taken off, so its centre rather than its corner lands on the pointer.FlowToScreenPosition(point)is the reverse, from flow back to client coordinates - what you would use to place page-level HTML, a popup or a tooltip, beside a node.- A click adds at the middle of the view:
PaneSizeis the pane's size in pixels andGetViewport().ScreenToFlow(x, y)converts a point measured from the pane's top-left corner. AddNodes(node)appends to theNodeslist, measures the new node, raisesNodesChangedand records an undo step when history is on.