Skip to content

PathContext

Defined in: core/path-context.ts:10

PathContext is the seam of d3gl: the subset of CanvasRenderingContext2D’s path API that d3 path-emitting generators (d3-geo geoPath, d3-shape, d3-chord, d3-hierarchy links) actually call. Implement this once per backend and any of those generators can render to that backend unchanged.

The signatures intentionally match CanvasRenderingContext2D so a real 2D context satisfies this interface structurally.

arc(x, y, radius, startAngle, endAngle, counterclockwise?): void

Defined in: core/path-context.ts:36

number

number

number

number

number

boolean

void


arcTo(x1, y1, x2, y2, radius): void

Defined in: core/path-context.ts:44

number

number

number

number

number

void


beginPath(): void

Defined in: core/path-context.ts:11

void


bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y): void

Defined in: core/path-context.ts:28

number

number

number

number

number

number

void


closePath(): void

Defined in: core/path-context.ts:46

void


lineTo(x, y): void

Defined in: core/path-context.ts:26

number

number

void


moveTo(x, y): void

Defined in: core/path-context.ts:25

number

number

void


quadraticCurveTo(cpx, cpy, x, y): void

Defined in: core/path-context.ts:27

number

number

number

number

void


rect(x, y, w, h): void

Defined in: core/path-context.ts:45

number

number

number

number

void


translate(dx, dy): void

Defined in: core/path-context.ts:24

Shift all subsequent path coordinates by (dx, dy), accumulating like CanvasRenderingContext2D.translate. The canonical d3 idiom for placing an origin-centred generator (radial trees, chords, …) at an offset: call translate(cx, cy) once, then run the generator into this context unchanged.

This is the only transform in the seam — no rotate/scale/save/restore. Radial generators bake angle into their coordinates, so a translation is all they need; a richer transform stack would complicate every backend for no current consumer. The offset is part of context state (not reset by beginPath) and, in retained backends, lives only for the single drawable the callback is recording.

number

number

void