Skip to content

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.

Select a node, then use a button.
Source
Resize me 160 × 80
Own origin
Sink
Region A · drawn through BlowViewportPortal
Arrow keys move the view, Home shows the whole flow.
bit Blow

Try 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

  • ColorMode is Light (the default), Dark or System, which follows prefers-color-scheme. Site theme is this demo's own wiring rather than a library feature: the canvas stays Light and the site's stylesheet copies the library's dark palette in under its dark theme. The own-color-mode class keeps that rule off a canvas that picks its own mode.
  • ConnectionMode is Strict by default, which only joins a source handle to a target handle; Loose lets any handle connect to any other.
  • NodeOrigin on the canvas (default (0, 0), the top-left corner) says which point of a node its Position names. A node's own BlowNode.Origin overrides it: Own origin sets (0.5, 0.5). The layout, align and clipboard helpers honour both.
  • HideAttribution removes the badge and AttributionPosition (default BottomRight) moves it.
  • BlowViewportPortal renders its content inside the canvas's zoomed layer, so you place it with flow coordinates - here a CSS transform - and it pans and zooms with the nodes. The dots are drawn from each node's Position, so they move as the canvas moves the nodes.
  • BlowNodeResizeControl is a single resize control, where BlowNodeResizer renders all eight. Position picks the corner or side (BottomRight by default); MinWidth/MinHeight (default 40 × 30) and MaxWidth/MaxHeight (unbounded by default) limit the size; KeepAspectRatio makes the dragged axis drive the other; Color paints the square (var(--bit-blow-node-selected) by default); and Visible is null by default, which shows the control only while the node is selected. Resizing writes the node's Width and Height.
  • OnSelectionChange hands the page the selected nodes and edges whenever the selection changes; the buttons act on what it last reported.
  • BlowGraphUtils.GetIncomers, GetOutgoers and GetConnectedEdges read the neighbourhood straight from the two lists.
  • BlowGraphUtils.GetNodesBounds returns the rectangle round the nodes, and GetViewportForBounds(bounds, paneWidth, paneHeight, minZoom, maxZoom, padding) the viewport that frames it in a pane of the canvas's PaneSize; SetViewportAsync(viewport, 300) eases there. FitBoundsAsync does 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 a BlowConnection unless an equivalent one exists, with the id BuildEdgeId derives 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 its Id, 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.
An unhandled error has occurred. Reload 🗙