blob: 32cbc35227e2c68893c27b6332bd83f210aaa24d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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
}
|