Skip to Content
Vue Flow v2 is here and joins xyflow! Read more here →
ReferenceUtils

getViewportForBounds()

Source on GitHub 

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:
NameTypeDefault
boundsRect

Bounds to fit inside viewport.

widthnumber

Width of the viewport.

heightnumber

Height of the viewport.

minZoomnumber

Minimum zoom level of the resulting viewport.

maxZoomnumber

Maximum zoom level of the resulting viewport.

paddingPadding

Padding around the bounds.

Returns:

A transformed Viewport that encloses the given bounds which you can pass to e.g. setViewport .

NameType
xnumber
ynumber
zoomnumber