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.
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
- 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
TypeisBlowEdgeType.Routedleaves 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
Routingparameter takes the router. ABlowRoutingOptionstunes the built-in one:Margin(16),StubLength(24),BendPenalty(60, what a bend costs in length),BorderRadius(6, the corner radius) andMaxObstacles(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
IBlowEdgeRoutercan replace the built-in one: it gets aBlowRouteRequest(the edge, its two anchors and sides, and the boxes of the nodes near it) and returns aBlowPathResult, or null for a smooth step. The custom one here takes its corners fromBlowEdgeRouting.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.BlowSvgExportOptionssets theTitle,Background(null for transparent),Padding,NodeFill,NodeStroke,TextColor,GroupFill,GroupStroke,EdgeStroke,FontFamilyandFontSize, andRouting, 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.