Skip to content

Edge Routing

Edges of type Routed go round the nodes in their way, in horizontal and vertical segments that keep a margin from every node and prefer few bends, and follow as the nodes move. A BlowRoutingOptions tunes the built-in router, a router of your own can replace it, and ToSvg exports the graph, routes included, as an image.

16 24 60 6 Export SVG
bypass
Input A
Input B
Block
Block
Transform
Block
Outputs
Output A
Output B
bit Blow

Try it

  • Drag the blocks about: the edges re-route round them as they move, and the edges into Output A and B run inside the Outputs group instead of round it.
  • Untick Route round nodes: the same edges become plain smooth steps and run straight through the blocks.
  • Move Margin: the routes keep further from the nodes, or hug them at 0.
  • Move Stub: each route runs further straight out of its handle before its first turn.
  • Move Bend cost: at 0 a route takes the shortest way however many turns it makes; raise it and routes trade length for fewer bends.
  • Move Corners: the built-in router's corners turn square at 0 or round off.
  • Set Max obstacles to 4 or 2: an edge with more nodes near it than that is given up on and falls back to a smooth step, straight through the blocks.
  • Switch Router to Custom: the page's own router bends each route round wide curves, still clear of the blocks; Margin, Stub, Bend cost and Max obstacles still apply, Corners does not.
  • Pick an Image style and watch the preview under the canvas redraw; Export SVG downloads that image.

How it works

  • An edge whose Type is BlowEdgeType.Routed leaves each handle straight, keeps a margin from every node near it - its own two included - and takes the route with the fewest bends that is not much longer. With no route at all it falls back to a smooth step.
  • The canvas's Routing parameter takes the router. A BlowRoutingOptions tunes the built-in one: Margin (16), StubLength (24), BendPenalty (60, what a bend costs in length), BorderRadius (6, the corner radius) and MaxObstacles (100). The sliders change this page's options in place: the canvas compares the settings, so it routes again at the next render.
  • A route runs inside the groups its ends are in rather than round them, which is how the edges reach Output A and B inside Outputs.
  • Any IBlowEdgeRouter can replace the built-in one: it gets a BlowRouteRequest (the edge, its two anchors and sides, and the boxes of the nodes near it) and returns a BlowPathResult, or null for a smooth step. The custom one here takes its corners from BlowEdgeRouting.Orthogonal - the built-in router as a pure function - and draws a curve through each. A router of your own is replaced with a new instance whenever its settings change.
  • ToSvg(options) draws the graph as it is on screen into a standalone SVG document, routes included. BlowSvgExportOptions sets the Title, Background (null for transparent), Padding, NodeFill, NodeStroke, TextColor, GroupFill, GroupStroke, EdgeStroke, FontFamily and FontSize, and Routing, the router to draw routed edges with - here the one the canvas is about to get, so the image never lags a change behind.
  • The image is safe to embed: labels are written as escaped text, and a colour is only written when it is a plain colour value.
An unhandled error has occurred. Reload 🗙