Multi setNodes
Change the nodes as many times as you like in one event handler - move them, recolour them, relabel them - and the canvas draws the result once, after the handler, the way several setNodes calls in one React tick apply together. A change made outside a render of the page, such as on a timer, is drawn when the page calls Refresh.
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
- Shuffle, recolour and relabel makes three passes over the nodes - new positions, new colours, new labels - and you see them land together, with the edges following, in one redraw.
- Drift for 2 seconds nudges every node ten times a second from a timer. With Call Refresh while drifting ticked the nodes glide; untick it and run it again: nothing moves until the timer stops, then every node jumps to where it ended up.
- Reset puts the row back and fits it in view.
How it works
- The canvas edits and draws the page's own
List<BlowNode>, so the handler simply assignsPosition,StyleandLabelon the nodes, pass after pass. Nothing is drawn in between: Blazor renders the page once the handler returns, the page hands the canvas its parameters again, and the canvas re-reads the lists and re-measures the nodes, whose labels may have changed their size. - So a change made inside an event handler of the page needs no call at all.
FitView()after the shuffle only brings the scattered nodes back into view. - The drift runs on a
PeriodicTimerinside the handler. Blazor renders an async handler when it first waits and when it finishes, not after each tick, so the changes in between are invisible until something renders the canvas. Refresh(remeasure: false)renders the canvas on its own, re-reading the lists, without rendering the page. Passremeasure: truewhen the change can alter a node's size or handles, so they are measured again first. A change from a real timer callback or a message from a server, outside the renderer's context, goes throughInvokeAsyncfirst.- Reset rebuilds the lists in place -
ClearandAddRange- rather than assigning new ones, and fits the view to the row.