Theming, Node Origin, Portal, Resize Control & Graph Utils
Canvas-wide options and small add-ons in one flow: ColorMode, ConnectionMode and
NodeOrigin on the canvas, a BlowViewportPortal that draws in flow space, a single
BlowNodeResizeControl, and the pure BlowGraphUtils helpers that answer questions
about the graph and the viewport.
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
- Pick a Colour mode: Light and Dark force the canvas's palette whatever the site's theme, System follows the operating system's light or dark setting, and Site theme leaves it to this site's theme toggle.
- Drag from the bottom handle of Own origin onto the bottom handle of Resize me: both are source handles, so the canvas refuses it. Tick Loose connections and the same drag connects.
- Change Node origin: the red dots mark each node's
Position, and the nodes move round them so the dot names their top-left corner, centre or bottom-right corner. Own origin stays centred on its dot whatever you pick. - Move the "bit Blow" badge to the top-right corner, or hide it, with Attribution.
- Click the green node and drag the small green square at its bottom-right corner to resize it, between 120 × 60 and 320 × 160; the node shows its size as it changes. Tick Resize keeps aspect ratio and each drag keeps the shape the node had when it began; tick Grip always visible to show the square without selecting the node.
- Drag the background and scroll: the dashed note and the dots pan and zoom with the graph, and a dot follows its node when you drag the node.
- Click one node and press Neighbours to list the nodes feeding it, the nodes it feeds and how many edges touch it.
- Select a node or two (Shift+click adds to the selection) and press Fit selection: the view eases to frame them, and the line beside the buttons shows their bounds and the zoom. With nothing selected it frames every node.
- Press Add edge Source → Sink: an edge appears with the id
bit-blow-1--4. Press it again and nothing is added, because that connection already exists. - Press Reconnect edge e3-4 to move the edge from Own origin to Sink over to Resize me, and again to move it back. It keeps its id both ways.
How it works
ColorModeisLight(the default),DarkorSystem, which followsprefers-color-scheme. Site theme is this demo's own wiring rather than a library feature: the canvas staysLightand the site's stylesheet copies the library's dark palette in under its dark theme. Theown-color-modeclass keeps that rule off a canvas that picks its own mode.ConnectionModeisStrictby default, which only joins a source handle to a target handle;Looselets any handle connect to any other.NodeOriginon the canvas (default(0, 0), the top-left corner) says which point of a node itsPositionnames. A node's ownBlowNode.Originoverrides it: Own origin sets(0.5, 0.5). The layout, align and clipboard helpers honour both.HideAttributionremoves the badge andAttributionPosition(defaultBottomRight) moves it.BlowViewportPortalrenders its content inside the canvas's zoomed layer, so you place it with flow coordinates - here a CSStransform- and it pans and zooms with the nodes. The dots are drawn from each node'sPosition, so they move as the canvas moves the nodes.BlowNodeResizeControlis a single resize control, whereBlowNodeResizerrenders all eight.Positionpicks the corner or side (BottomRightby default);MinWidth/MinHeight(default 40 × 30) andMaxWidth/MaxHeight(unbounded by default) limit the size;KeepAspectRatiomakes the dragged axis drive the other;Colorpaints the square (var(--bit-blow-node-selected)by default); andVisibleis null by default, which shows the control only while the node is selected. Resizing writes the node'sWidthandHeight.OnSelectionChangehands the page the selected nodes and edges whenever the selection changes; the buttons act on what it last reported.BlowGraphUtils.GetIncomers,GetOutgoersandGetConnectedEdgesread the neighbourhood straight from the two lists.BlowGraphUtils.GetNodesBoundsreturns the rectangle round the nodes, andGetViewportForBounds(bounds, paneWidth, paneHeight, minZoom, maxZoom, padding)the viewport that frames it in a pane of the canvas'sPaneSize;SetViewportAsync(viewport, 300)eases there.FitBoundsAsyncdoes the same in one call - the helpers are for when you need the numbers, or have no canvas at all.BlowGraphUtils.AddEdge(connection, edges)appends an edge for aBlowConnectionunless an equivalent one exists, with the idBuildEdgeIdderives from the wiring - the same id the canvas gives a connection you drag.BlowGraphUtils.ReconnectEdge(oldEdge, newConnection, edges)rewires an edge in place and keeps itsId, as the canvas does when you drag the end of a selected edge.- The helpers are pure functions over the lists the canvas renders: an edit made in a button's handler is drawn when the page re-renders after it.