Skip to content
D
Documentation

Canvas — interfaces

reference
7 min readUpdated

Interfaces

Import these from @grafloria/renderer.

Interfaces

Bounds

ts
interface Bounds

Properties

NameTypeDefaultDescription
minXnumber
minYnumber
maxXnumber
maxYnumber

CanvasFrameStats

Per-frame numbers the dirty-redraw path actually produces.

ts
interface CanvasFrameStats

Properties

NameTypeDefaultDescription
paintednumberElements drawn this frame.
cullednumberElements skipped because they fell outside every dirty rect.
dirtyRectsnumberDirty rects this frame; 0 means a full repaint.
fullRepaintbooleanTrue when the whole canvas was repainted.
changedEntitiesnumberEntities whose VNode changed.

CanvasLike

A canvas element, structurally — so tests can hand in a fake.

ts
interface CanvasLike

Properties

NameTypeDefaultDescription
widthnumber
heightnumber
style?{ width?: string; height?: string; [key: string]: unknown }

Members

  • getContext(id: '2d', options?: unknown): Canvas2DLike | null
  • toDataURL?(type?: string, quality?: number): string

CanvasPick

What was under the cursor.

ts
interface CanvasPick

Properties

NameTypeDefaultDescription
kindHitRecord['kind']
idstring
vnodeVNode

CanvasRefusedEvent

ts
interface CanvasRefusedEvent

Properties

NameTypeDefaultDescription
hazardsreadonly CanvasHazard[]
explanationstring

CanvasRendererOptions

ts
interface CanvasRendererOptions

Properties

NameTypeDefaultDescription
canvas?CanvasLike | nullThe visible canvas. Required to paint; omit only for pure measurement.
hitCanvas?CanvasLike | nullThe offscreen picking canvas. Created from canvas's document when absent. Pass null (with enableHitDetection: false) to run without one.
devicePixelRatio?numberDefault: globalThis.devicePixelRatio ?? 1. Overridable for tests.
theme?Theme
producerConfig?SVGRendererConfigConfig for the VNode producer. Defaults match the SVG backend exactly.
producer?SVGRendererReuse an existing VNode producer — this is how a live diagram switches backends without rebuilding its scene (render-backend.ts).
enableHitDetection?booleanEnable the colour-keyed hit canvas. Default true.
hitCanvasScale?numberSub-sampling factor for the hit canvas. 1 = pixel-exact picking (default). 0.5 halves its memory at the cost of ~1px of picking slop.
enableDirtyRegions?booleanEnable dirty-rectangle partial redraw. Default true.
styleHost?Element | nullElement whose computed --grafloria-* custom properties override the theme — normally the canvas's host. This is what lets a host theme canvas mode with the same CSS variables it uses for SVG mode.

CanvasSafety

ts
interface CanvasSafety

Properties

NameTypeDefaultDescription
safebooleanTrue when nothing would be lost by drawing this diagram on a canvas.
hazardsCanvasHazard[]Everything that would be lost. Empty iff safe.

CanvasSafetyInput

ts
interface CanvasSafetyInput

Properties

NameTypeDefaultDescription
a11yActiveboolean
focusInsideboolean
hasForeignObjectboolean

ComputedStyle

Everything the painter needs to know to draw one element.

ts
interface ComputedStyle

Properties

NameTypeDefaultDescription
fill?string
stroke?string
strokeWidthnumber
strokeDasharray?number[]
opacitynumberElement opacity, already multiplied down the group chain.
fillOpacity?number
strokeOpacity?number
fontFamilystring
fontSizenumber
fontWeightstring
fontStylestring
textAnchor'start' | 'middle' | 'end'
dominantBaselinestring
visiblebooleandisplay: none / visibility: hidden → not painted at all.
filter?stringCSS filter string (e.g. blur(4px)), passed through when supported.
clipPathId?stringclip-path: url(#id) → the referenced clip id.

DirtyDiff

ts
interface DirtyDiff

Properties

NameTypeDefaultDescription
rectsBounds[] | nullWorld rects to repaint, or null for "repaint everything" (first frame, camera move, theme swap, or too much changed to be worth clipping).
changedstring[]Entities whose VNode object is new this frame.
removedstring[]Entities that disappeared.

EntityScope

The entity a subtree belongs to.

ts
interface EntityScope

Properties

NameTypeDefaultDescription
kindHitKind
idstring
keystringThe VNode key — node-n1, and therefore the dirty tracker's entity key.

EntitySnapshot

The bounds of one top-level entity, and the VNode that produced them.

ts
interface EntitySnapshot

Properties

NameTypeDefaultDescription
vnodeVNode
boundsBounds | null

HitRecord

One pickable region, in WORLD coordinates.

Produced by the paint pass, consumed by both picking strategies (the colour- keyed hit canvas and the geometric fallback). zIndex is paint order, so the last-painted region under the cursor is the topmost one — which is the same rule DiagramModel.getNodeAtPosition applies when it iterates nodes in reverse.

ts
interface HitRecord

Properties

NameTypeDefaultDescription
kindHitKind
idstringEntity id (node id / link id / port id).
cmdsPathCmd[]World-space geometry — the exact path that was drawn.
filledbooleanTrue when the region is the filled interior; false when it is the stroke.
tolerancenumberPick tolerance for stroke regions (world units, half-width).
zIndexnumberPaint order.
vnodeVNodeThe VNode that produced the region (the IRenderer.hitTest return value).
colorKeystringColour key for the offscreen picking canvas (#rrggbb).
boundsBounds | null

Matrix

A 2D affine transform, in the order a canvas setTransform(a,b,c,d,e,f) takes.

ts
interface Matrix

Properties

NameTypeDefaultDescription
anumber
bnumber
cnumber
dnumber
enumber
fnumber

PaintOptions

ts
interface PaintOptions

Properties

NameTypeDefaultDescription
worldToDeviceMatrixWorld → device matrix (viewBox + zoom + devicePixelRatio, composed).
dirtyWorld?Bounds[]Only repaint elements intersecting these WORLD rects. Omit for a full repaint. The caller is responsible for having clipped/cleared them.
pickingPass?booleanPaint the colour-key silhouettes instead of the real styles (hit canvas).
measureOnly?booleanCompute bounds and hit regions, draw nothing. Used to measure a changed entity's extent before deciding what to repaint.
allocateColorKey?(stableId: string) => stringColour-key allocator, keyed by a STABLE per-element id.

PaintResult

ts
interface PaintResult

Properties

NameTypeDefaultDescription
hitRecordsHitRecord[]Every pickable region produced this frame, in paint order.
colorKeyIndexMap<string, HitRecord>colour key → record, for the offscreen picking canvas.
unpaintableNodesVNode[]Elements the canvas cannot draw (foreignObject) — the host may overlay them.
boundsBounds | nullWorld bounds of everything painted.
entityBoundsMap<string, Bounds | null>Per-entity world bounds (node-n1 → its extent), for the dirty tracker.
paintedCountnumberElements actually painted (after dirty-rect culling).
culledCountnumberElements skipped because they fell outside the dirty region.

RenderBackendOptions

ts
interface RenderBackendOptions

Properties

NameTypeDefaultDescription
mode?BackendModeInitial backend. Default 'svg' — the historical behaviour.
theme?Theme
producerConfig?SVGRendererConfigConfig for the shared VNode producer.
devicePixelRatio?number
enableHitDetection?boolean
enableDirtyRegions?boolean
guardCanvas?booleanREFUSE a switch to canvas that would take something away.
onCanvasRefused?(event: CanvasRefusedEvent) => voidTold when the backend refuses a canvas switch, and what it would have cost.

StyleResolverOptions

ts
interface StyleResolverOptions

Properties

NameTypeDefaultDescription
themeTheme
varOverrides?Record<string, string>CSS custom-property overrides — normally read off the diagram's host element with {@link readCssVarOverrides}, so a host that redefines --grafloria-* in its own stylesheet gets the same paint on canvas as it does on SVG.

SubPath

One flattened sub-path: a polyline, plus whether it was explicitly closed.

ts
interface SubPath

Properties

NameTypeDefaultDescription
pointsPoint[]
closedboolean

TextLine

One drawn line of text, already positioned in the element's local space.

ts
interface TextLine

Properties

NameTypeDefaultDescription
textstring
xnumber
ynumber

Was this page helpful?

Canvas — interfaces — Grafloria