refactor(props): merge defaultPosition and defaultZoom to defaultViewport #2313

This commit is contained in:
moklick
2022-07-25 16:03:42 +02:00
parent 0054dd3d61
commit 37b311851c
6 changed files with 31 additions and 32 deletions
@@ -45,8 +45,7 @@ const ZoomPane = ({
selectionKeyPressed,
elementsSelectable,
panOnDrag = true,
defaultPosition = [0, 0],
defaultZoom = 1,
defaultViewport,
zoomActivationKeyCode,
preventScrolling = true,
children,
@@ -68,9 +67,9 @@ const ZoomPane = ({
const d3ZoomInstance = zoom().scaleExtent([minZoom, maxZoom]).translateExtent(translateExtent);
const selection = select(zoomPane.current as Element).call(d3ZoomInstance);
const clampedX = clamp(defaultPosition[0], translateExtent[0][0], translateExtent[1][0]);
const clampedY = clamp(defaultPosition[1], translateExtent[0][1], translateExtent[1][1]);
const clampedZoom = clamp(defaultZoom, minZoom, maxZoom);
const clampedX = clamp(defaultViewport.x, translateExtent[0][0], translateExtent[1][0]);
const clampedY = clamp(defaultViewport.y, translateExtent[0][1], translateExtent[1][1]);
const clampedZoom = clamp(defaultViewport.zoom, minZoom, maxZoom);
const updatedTransform = zoomIdentity.translate(clampedX, clampedY).scale(clampedZoom);
d3ZoomInstance.transform(selection, updatedTransform);