Interactions Playground
The canvas parameters that change its gestures - snapping, click-to-connect, drag-to-select, scroll-to-pan,
double-click zoom and culling - as live switches, the methods you call on a captured BlowCanvas as
buttons, and an event log of what the canvas raises while you work.
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 BlowEvent log · selected: 0
Try it
- Tick Snap to grid and drag a node: it jumps from dot to dot of the background, and each arrow-key press moves a selected node one dot.
- Tick Connect on click, then click a handle and click another node's handle: the two are connected without a drag. Clicking empty space or pressing Escape abandons it.
- Tick Selection on drag: a plain drag on the background now draws a selection box; hold Space while dragging to pan instead. Without it, Shift+drag draws the box.
- Tick Pan on scroll: the wheel or trackpad now pans the view (Shift turns it sideways), and Ctrl+wheel still zooms.
- Untick Zoom on double-click: double-clicking the background no longer zooms in.
- Tick Cull off-screen and pan a node out of view: it is no longer rendered at all - the browser's element inspector shows it gone - and comes back as soon as it is in view again.
- Click an edge to select it, then drag the dot at either end onto another handle to reconnect it.
- Double-click or right-click a node (or focus it and press Shift+F10), drag one, connect two or change the selection, and watch each event arrive at the top of the log; the log's title counts what is selected.
- Add node, Delete selected, Fit view, Zoom 1.5× and Export call the canvas from code; Export logs how many nodes and edges a snapshot holds and its zoom.
How it works
SnapToGridsnaps dragged positions to aSnapGridXbySnapGridYgrid (15 by 15 by default; 20 here, the background'sGap, so the dots show the grid). The same grid sets the arrow keys' step.ConnectOnClick(off) adds click-a-handle, click-another to dragging.SelectionOnDrag(off) makes a plain pane drag box-select, withPanActivationKey(Space) to pan;SelectionKey(Shift) box-selects either way.PanOnScroll(off) makes the wheel pan instead of zoom;ZoomOnDoubleClickis on by default;OnlyRenderVisibleElements(off) renders only the nodes and edges in view, for large graphs.- An edge is reconnectable while
EdgesReconnectable(on) and its ownReconnectableare;OnReconnectreports the new wiring and the edge keeps its id. - The log comes from
OnConnectStart,OnConnectandOnConnectEnd,OnReconnect,OnSelectionChange,OnNodeDoubleClick,OnNodeContextMenu(handling it suppresses the browser's menu),OnNodeDragStopandOnDelete, which reports a deletion by key and by button alike. - The buttons use the canvas captured with
@ref:AddNodes,DeleteElementsAsyncwith the selected nodes and edges,FitView(),ZoomTo(1.5)andToObject(), which returns aBlowSnapshotof the nodes, edges and viewport. - Both control groups are
BlowPanels inside the canvas, so they stay put while the graph pans and zooms, and the minimap isPannable(its default): click or drag in it to move the view. The edges showAnimated, an arrowhead at each end (MarkerStartwithArrowClosed) and aSmoothSteppath.