Created
June 12, 2019 19:30
-
-
Save wernerdegroot/2db60d91dc68f9c7d4dcd9ee47a43a69 to your computer and use it in GitHub Desktop.
Blog "Leibniz equality in TypeScript", aside `zoom`
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
function zoom(dayStart: number, dayEnd: number, zoomFactor: number): [number, number] { | |
// What is the middle of the time range? | |
// When zooming in or out, the middle of the time range should stay the middle. | |
const dayMiddle = (dayEnd + dayStart) / 2 | |
// Determine what the new time range should be using the `zoomFactor`. | |
const oldTimeRange = dayEnd - dayStart | |
const newTimeRange = oldTimeRange * zoomFactor | |
// Calculate the new boundaries of the time range: | |
const newDayStart = dayMiddle - newTimeRange / 2 | |
const newDayEnd = dayMiddle + newTimeRange / 2 | |
return [newDayStart, newDayEnd] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment