Skip to content

Commit

Permalink
Added nodes argument to fitViewToDimensions function
Browse files Browse the repository at this point in the history
  • Loading branch information
Paweł Jaśpiński committed Sep 14, 2021
1 parent 74b0d4c commit 8163591
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/hooks/useZoomPanHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ export type FitViewParams = {
export type FitViewToDimensionsParams = {
width: number,
height: number,
nodes: Array<Node>,
padding?: number;
includeHiddenNodes?: boolean;
minZoom?: number;
Expand Down

0 comments on commit 8163591

Please sign in to comment.