Skip to content
Apexify.jsDocs
Apexify.js version v5.4.5

Node / Lines Connectors · guide

Path2D — create, draw & command reference

Current Apexify.js 6.0.0 documentation for Path2D — create, draw & command reference.

apexify.jsRuntime: nodeCURRENTSince 6.0.0

painter.path2d (PainterPath2D facet):

MethodSignatureRole
create(commands: PathCommand[]) => Path2DbuildPath2DFromCommands via appendPathCommands.
draw(canvasBuffer, path: Path2D | PathCommand[], options?) => Promise<Buffer>Raster composite onto existing PNG (Path2DCreator.drawPath).
custom(options, canvasBuffer)Styled connectors (previous chapters).

Drawing pipeline (drawPath / drawPathOntoContext)

  1. Decode canvasBuffer dimensions.
  2. ctx.drawImage snapshot → save().
  3. Optional transform (origin-centred rotation/scale or translate-first ordering — mirrors path2d-creator).
  4. Optional shadow (colour or gradient via createGradientFill + gradientBounds).
  5. Optional stroke — stroke(path) with dash presets (dashed ⇒ [10,6], dotted ⇒ [2,5]) unless dashArray supplied.
  6. Optional fill — fill(path[, rule]) (rule nonzero/evenodd).
  7. restore().

Opacity: root options.opacity clamps [0,1] and multiplies stroke/fill alphas independently (**per-channel multiply against stroke.opacity / fill.opacity).


Path2DDrawOptions quick reference

BlockFields
strokecolor, gradient, width, lineCap, lineJoin, miterLimit, style (solid/dashed/dotted), dashArray, dashOffset, opacity
fillcolor, gradient, opacity, rule
shadowcolor, gradient, blur, offsetX, offsetY
transformtranslateX/Y, rotate, scaleX/Y, originX/Y
Rootopacity, globalCompositeOperation, gradientBounds (bbox for paints)

PathCommand[] primitives

Commands append in order (foundation/path-cmd.ts):

typePayload
moveTox, y
lineTox, y
arcx, y, radius, startAngle, endAngle, optional counterclockwise — angles radians (Canvas convention)
arcTox1, y1, x2, y2, radius
quadraticCurveTocpx, cpy, x, y
bezierCurveTocp1x, cp1y, cp2x, cp2y, x, y
rectx, y, width, height
ellipsex, y, radiusX, radiusY, optional rotation, startAngle, endAngle, counterclockwise — angles radians
closePathcloses current contour
circlex, y, radius (full circle)
roundedRectx, y, width, height, radius (number or { tl, tr, br, bl })
polygonpoints — auto closePath
starx, y, outerRadius, innerRadius, points (tip count)
arrowx, y, length, angle (degrees), optional headLength, headAngle (degrees)

Composite diagrams by interleaving moveTo segments so strokes don’t unintentionally close.


Example — rounded badge + arrow axis

SOURCEtypescript
typescript
Studio
const badge = painter.path2d.create([  { type: 'roundedRect', x: 48, y: 48, width: 240, height: 96, radius: 18 },]); await painter.path2d.draw(buffer, badge, {  fill: { color: '#1e293b', opacity: 0.85 },  stroke: { color: '#94a3b8', width: 2 },}); const axis = painter.path2d.create([  { type: 'moveTo', x: 320, y: 120 },  { type: 'lineTo', x: 520, y: 120 },  {    type: 'arrow',    x: 520,    y: 120,    length: 40,    angle: 0,    headLength: 14,    headAngle: 40,  },]); await painter.path2d.draw(buffer, axis, {  stroke: { color: '#cbd5e1', width: 3, lineCap: 'round' },});

Scenes

{ type: 'path', path: PathCommand[], options?: Path2DDrawOptions } paints via drawPathOntoContext with canvas width/height.


Next steps