getViewportForBounds()
The getViewportForBounds util computes the Viewport
(x, y, zoom) needed to fit a given bounding rectangle into the flow area,
respecting the min/max zoom and padding. It’s the math behind fitView / fitBounds.
import { getViewportForBounds } from '@xyflow/vue';
const viewport = getViewportForBounds(bounds, width, height, minZoom, maxZoom, padding);Signature
Parameters:| Name | Type | Default |
|---|---|---|
bounds | RectBounds to fit inside viewport. | |
width | numberWidth of the viewport. | |
height | numberHeight of the viewport. | |
minZoom | numberMinimum zoom level of the resulting viewport. | |
maxZoom | numberMaximum zoom level of the resulting viewport. | |
padding | PaddingPadding around the bounds. |
A transformed Viewport that encloses the given bounds which you can pass to e.g. setViewport .
| Name | Type |
|---|---|
x | number |
y | number |
zoom | number |