diff --git a/src/hooks/useZoomPanHelper.ts b/src/hooks/useZoomPanHelper.ts index 42ff28824..4de2f128e 100644 --- a/src/hooks/useZoomPanHelper.ts +++ b/src/hooks/useZoomPanHelper.ts @@ -13,7 +13,7 @@ const initialZoomPanHelper: ZoomPanHelperFunctions = { zoomTo: (_: number) => {}, transform: (_: FlowTransform) => {}, fitView: (_: FitViewParams = { padding: DEFAULT_PADDING, includeHiddenNodes: false }) => {}, - fitViewToDimensions: (_: FitViewToDimensionsParams = { height: 0, width: 0, padding: DEFAULT_PADDING, includeHiddenNodes: false }) => {}, + fitViewToDimensions: (_: FitViewToDimensionsParams = { height: 0, width: 0, nodes: [], padding: DEFAULT_PADDING, includeHiddenNodes: false }) => {}, setCenter: (_: number, __: number) => {}, fitBounds: (_: Rect) => {}, project: (position: XYPosition) => position, @@ -55,14 +55,14 @@ const useZoomPanHelper = (): ZoomPanHelperFunctions => { d3Zoom.transform(d3Selection, transform); }, - fitViewToDimensions: (options: FitViewToDimensionsParams = { height: 0, width: 0, padding: DEFAULT_PADDING, includeHiddenNodes: false }) => { - const { nodes, minZoom, maxZoom } = store.getState(); + fitViewToDimensions: (options: FitViewToDimensionsParams = { height: 0, width: 0, nodes: [], padding: DEFAULT_PADDING, includeHiddenNodes: false }) => { + const { minZoom, maxZoom } = store.getState(); - if (!nodes.length) { + if (!options.nodes.length) { return; } - const bounds = getRectOfNodes(options.includeHiddenNodes ? nodes : nodes.filter((node) => !node.isHidden)); + const bounds = getRectOfNodes(options.includeHiddenNodes ? options.nodes : options.nodes.filter((node) => !node.isHidden)); const [x, y, zoom] = getTransformForBounds( bounds, options.width, diff --git a/src/types/index.ts b/src/types/index.ts index 3401f2a1a..c89081e32 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -255,6 +255,7 @@ export type FitViewParams = { export type FitViewToDimensionsParams = { width: number, height: number, + nodes: Array, padding?: number; includeHiddenNodes?: boolean; minZoom?: number;