fix: Visibility and zooming when canvas offset is not zero (#2534)

This commit is contained in:
João Forja 2020-12-14 14:14:56 +00:00 committed by GitHub
parent 60864ace54
commit 4c7b1a2269
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 53 additions and 19 deletions

View file

@ -3,6 +3,7 @@ import { NormalizedZoomValue, PointerCoords, Zoom } from "../types";
export const getNewZoom = (
newZoomValue: NormalizedZoomValue,
prevZoom: Zoom,
canvasOffset: { left: number; top: number },
zoomOnViewportPoint: PointerCoords = { x: 0, y: 0 },
): Zoom => {
return {
@ -10,11 +11,13 @@ export const getNewZoom = (
translation: {
x:
zoomOnViewportPoint.x -
(zoomOnViewportPoint.x - prevZoom.translation.x) *
canvasOffset.left -
(zoomOnViewportPoint.x - canvasOffset.left - prevZoom.translation.x) *
(newZoomValue / prevZoom.value),
y:
zoomOnViewportPoint.y -
(zoomOnViewportPoint.y - prevZoom.translation.y) *
canvasOffset.top -
(zoomOnViewportPoint.y - canvasOffset.top - prevZoom.translation.y) *
(newZoomValue / prevZoom.value),
},
};