Reference · Framing, geometry and quiz tools
insetTransformfunction
What to do to a region's own geometry to seat it in its box: shrink it to fit if it is too big, centre it in the frame, and leave it at its own size unless the box says it may be magnified.
Import it
import { insetTransform } from "@johnmorrisdotca/chizu";
Definition
function insetTransform(bbox: readonly [number, number, number, number], box: MapBox, magnify?: boolean): InsetTransform
Parameters
| Name | Type | Description |
|---|---|---|
bbox | readonly [number, number, number, number] | The native left, top, right and bottom bounds of the geometry. |
box | MapBox | The window in native map units, or the inset destination specified by this signature. |
magnify (optional) | boolean | Whether the inset may enlarge its geometry instead of only shrinking it. |
Returns
InsetTransform
What to do to a region's own geometry to seat it in its box: shrink it to fit if it is too big, centre it in the frame, and leave it at its own size unless the box says it may be magnified.
Examples
import { insetTransform } from "@johnmorrisdotca/chizu";
// A region 400 wide seated in a box 200 wide is halved and centred.
console.log(insetTransform([0, 0, 400, 100], { x: 10, y: 10, width: 200, height: 100 }));
// { scale: 0.5, x: 10, y: 35 }{ scale: 0.5, x: 10, y: 35 }What it prints (run when this page was built)