Skip to content

@graphty/layout / positions / fitToBox

Function: fitToBox() ​

fitToBox(r, box): LayoutResult

Defined in: positions.ts:185

A layout result fitted into a rectangle, for a renderer that places nodes in its own units (pixels, a viewport): one factor scales every axis, so the drawing keeps its shape; the bounding box of the placed nodes fills the box along its tighter side and is centred along the other. In 3D, z is scaled by the same factor about its midpoint, so it ends centred on 0. Coincident nodes land on the box's centre, and an unplaced node (NaN) stays unplaced. The input is not modified.

Parameters ​

r ​

LayoutResult

the layout result, in layout units

box ​

Box

the target rectangle

Returns ​

LayoutResult

a new result with the same dim and n, in the box's units