diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2020-07-02 00:35:06 +0200 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2020-07-02 00:35:06 +0200 |
| commit | 3e2c1d432d73823e66e19d0081b498ace467b231 (patch) | |
| tree | 67a8b66eb8334b97e031f2c91da668591132ede3 /animism-align/frontend/views/align/align.util.js | |
| parent | 250527589e003420a84f36c4191d2e574f1ad28c (diff) | |
display the form
Diffstat (limited to 'animism-align/frontend/views/align/align.util.js')
| -rw-r--r-- | animism-align/frontend/views/align/align.util.js | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/animism-align/frontend/views/align/align.util.js b/animism-align/frontend/views/align/align.util.js new file mode 100644 index 0000000..32cbc35 --- /dev/null +++ b/animism-align/frontend/views/align/align.util.js @@ -0,0 +1,28 @@ +import { ZOOM_STEPS } from './constants' +import { clamp } from '../../util' + +export const positionToTime = (y, { start_ts, zoom, duration }) => { + const secondsPerPixel = ZOOM_STEPS[zoom] * 0.1 + const widthTimeDuration = window.innerHeight * secondsPerPixel + const timeMin = start_ts + const timeMax = Math.min(start_ts + widthTimeDuration, duration) + const timeWidth = timeMax - timeMin + return clamp(y * secondsPerPixel + start_ts, 0, timeMax) +} + +export const timeToPosition = (ts, { start_ts, zoom, duration }) => { + const height = window.innerHeight + const secondsPerPixel = ZOOM_STEPS[zoom] * 0.1 + const widthTimeDuration = height * secondsPerPixel + const timeMin = start_ts + const timeMax = Math.min(start_ts + widthTimeDuration, duration) + const timeWidth = timeMax - timeMin + const timeHalfHeight = height * secondsPerPixel / 2 + if (ts < timeMin - timeHalfHeight) { + return -9999 + } + if (ts > timeMax) { + return -9999 + } + return (ts - timeMin) / timeWidth * height +} |
