Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Zoom Problem
// 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
You can’t perform that action at this time.