From 816359157b174a5914d013bd01cb16c9ecb2377c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Ja=C5=9Bpi=C5=84ski?= Date: Tue, 14 Sep 2021 09:36:07 +0200 Subject: [PATCH] Added nodes argument to fitViewToDimensions function --- src/hooks/useZoomPanHelper.ts | 10 +++++----- src/types/index.ts | 1 + 2 files changed, 6 insertions(+), 5 deletions(-) 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;