Skip to content

Custom Edges

An EdgeTemplate draws every edge itself, here with BlowBaseEdge: each edge's colour comes from its Data, a selected edge thickens, and the label is drawn with BlowEdgeText on a plate tinted to match. Whatever the template leaves out - the arrowheads, say - the edge does not have.

warm cool ok ok
Start
Path A
Path B
End
Arrow keys move the view, Home shows the whole flow.
bit Blow

Try it

  • Each edge is drawn in the colour its data names, with its label on a plate tinted to match.
  • Click an edge: it thickens to 4 pixels and takes the selection colour.
  • Untick Arrowheads: the template stops passing the arrowhead on, and every edge loses it, although each edge still asks for one.
  • Untick Tinted labels: the labels fall back to the plain plate BlowBaseEdge draws.
  • Drag from a node's bottom dot to another node's top dot: the new edge is a smooth step, drawn by the same template in the theme's edge colour, since it carries no data.

How it works

  • EdgeTemplate replaces how every edge is drawn. It receives a BlowEdgeContext: the Edge, its computed Path, LabelX and LabelY, its two anchors and sides, and MarkerStartUrl / MarkerEndUrl.
  • BlowBaseEdge draws the standard edge from a Path: the visible line with its Stroke and StrokeWidth (1.5 by default), the arrowheads given as MarkerStart and MarkerEnd, an optional plain Label at LabelX, LabelY, and an invisible InteractionWidth-wide path (14) that takes the clicks.
  • The colour is the edge's Data - any object of yours, here a CSS colour string - with var(--bit-blow-edge-stroke) for an edge without one. Edge.Selected picks the width; the canvas's selection colour still overrides the stroke.
  • MarkerEndUrl is a ready-made url(#...) to the arrowhead the edge's MarkerEnd, MarkerType and colour settings ask for, so the template never needs the generated marker ids. Passing null leaves the edge without one.
  • BlowEdgeText draws a label on its own plate at any point: X, Y, Label, Style for the text, BgStyle for the plate, PaddingX, PaddingY, BorderRadius and ShowBg.
  • DefaultEdgeType and ConnectionLineType make new edges, and the line drawn while connecting, smooth steps like the edges already there. Around the template's markup the canvas still draws the selectable, focusable edge group.
An unhandled error has occurred. Reload 🗙