Use Flow API
Capture the canvas in a component reference and drive it from your own controls through its imperative API - the counterpart of React Flow's useReactFlow hook. Each button is a call or two on the BlowCanvas reference, and the log under the canvas shows what each call returned.
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
- Zoom in and Zoom out zoom one step about the middle of the view; the log reads the zoom back. Press either a few times to see it stop at the limits.
- Fit view brings the whole graph into view and logs the viewport it ended on.
- Add node puts a node in the middle of what you are looking at. Select one node first and the new one is connected to it.
- Click or Shift+drag to select nodes and edges, then Delete selected removes them, the edges of a removed node with it.
- Snapshot copies the graph and the viewport and logs what the copy holds; drag a node afterwards and take another to compare.
- Type or pick an id in Id (a node such as
2, or an edge such ase1-2) and press Look up: the view glides to it and the log describes it. An id that is in neither list logs that nothing was found.
How it works
@refcaptures theBlowCanvasinto a field once it has rendered. It is null before that, so every handler checks it first;OnInithands over the same reference once the canvas has rendered and measured, for code that has to run as soon as it can.ZoomIn()andZoomOut()multiply or divide the zoom by 1.2 about the centre of the pane, clamped toMinZoomandMaxZoom(0.2 and 2.5).GetZoom()reads the zoom back straight away: the calls apply at once.FitView()pans and zooms so the graph fills the pane with a 10% margin.GetViewport()returns the resultingBlowViewport:X,YandZoom, where screen = flow × zoom + (x, y).- Add node turns the middle of the pane into flow coordinates with
GetViewport().ScreenToFlow(...)overPaneSize, then callsAddNodes(node)and, with one node selected,AddEdges(edge). Both append to the bound lists and raiseNodesChangedandEdgesChanged. DeleteElementsAsync(nodes, edges)removes what it is given together with the edges and child nodes that go with a removed node. It skips anything withDeletable = false, andOnBeforeDeletecan veto it, as it can a Delete key press.ToObject()returns aBlowSnapshotofNodes,EdgesandViewportas deep copies, so it keeps describing the graph as it was;ToObject(deep: false)hands back the live instances.GetNode(id)andGetEdge(id)look an element up by id through the canvas's own index and return null for an id they do not know. Look up then centres on it withSetCenterAsync(x, y, zoom, durationMs), which eases the view there over 300 ms.