Created
April 11, 2017 15:19
-
-
Save bernatfortet/e474d171ba1dfef7035aa2ccaeb8b27f to your computer and use it in GitHub Desktop.
Zoom Problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Zoom an increment towards the position of my mouse | |
export function zoomIn(mousePosition: Object) { return (dispatch, getState) => { | |
const currentZoom = getState().graphEditor.zoom | |
const nextZoom = currentZoom+ZOOM_INCREMENT < MAX_ZOOM ? currentZoom+ZOOM_INCREMENT : MAX_ZOOM | |
dispatch( storeZoom(nextZoom) ) | |
const currentPan = selectors.getPan(getState()) | |
const graphElement = document.getElementById("graph") | |
const graphOffset = { | |
x: graphElement.getBoundingClientRect().left, | |
y: graphElement.getBoundingClientRect().top, | |
} | |
// current pan + mouse position/zoom gives me the relative position of | |
const scaleChange = nextZoom - currentZoom | |
const nextPan = { | |
x: currentPan.x + (mousePosition.x/currentZoom) * scaleChange, | |
y: currentPan.y + (mousePosition.y/currentZoom) * scaleChange, | |
} | |
dispatch( storePan(nextPan) ) | |
}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment