Skip to content

Commit dd118ea

Browse files
committed
Prevent SDCPN min zoom ratcheting on zoom-in
1 parent 8e98f0a commit dd118ea

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

libs/@hashintel/petrinaut/src/views/SDCPN/sdcpn-view.tsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const fitZoomToNodes = debounce(
5151
(
5252
instance: PetrinautReactFlowInstance | null,
5353
canvasContainer: React.RefObject<HTMLDivElement | null>,
54-
setMinZoom: (minZoom: number) => void,
54+
setMinZoom: React.Dispatch<React.SetStateAction<number>>,
5555
) => {
5656
const minMaxCoords = instance?.getNodesBounds(instance.getNodes());
5757
const viewportSize = canvasContainer.current?.getBoundingClientRect();
@@ -62,12 +62,17 @@ const fitZoomToNodes = debounce(
6262
viewportSize.width / minMaxCoords.width,
6363
);
6464
const currentZoom = instance?.getViewport().zoom;
65-
// Don't reduce the zoom level below the users current zoom
66-
const safeZoom = currentZoom
67-
? Math.min(currentZoom, newZoom * ZOOM_PADDING)
68-
: newZoom * ZOOM_PADDING;
65+
setMinZoom((currentMinZoom) => {
66+
// Don't increase min zoom beyond the currently configured minimum.
67+
// On first initialization (min zoom still 0), cap to the user's current zoom.
68+
if (currentMinZoom === 0) {
69+
return currentZoom
70+
? Math.min(currentZoom, newZoom * ZOOM_PADDING)
71+
: newZoom * ZOOM_PADDING;
72+
}
6973

70-
setMinZoom(safeZoom);
74+
return Math.min(currentMinZoom, newZoom * ZOOM_PADDING);
75+
});
7176
}
7277
},
7378
100,

0 commit comments

Comments
 (0)