Skip to content

Instantly share code, notes, and snippets.

@wernerdegroot
Created June 12, 2019 19:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wernerdegroot/2db60d91dc68f9c7d4dcd9ee47a43a69 to your computer and use it in GitHub Desktop.
Save wernerdegroot/2db60d91dc68f9c7d4dcd9ee47a43a69 to your computer and use it in GitHub Desktop.
Blog "Leibniz equality in TypeScript", aside `zoom`
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