-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathguess-zoom-percentile.js
70 lines (61 loc) · 1.06 KB
/
guess-zoom-percentile.js
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
let _ = require('lodash-firecloud');
let _zoomPercentiles = _.map([
-3.75,
-3.35,
-2.5,
-1.65,
-1.25,
-0.5,
-0.25,
0,
0.25,
0.5,
1.25,
2.5,
3.75,
5,
7.5,
10,
15,
20
], function(level) {
return 100 + 20 * level;
});
let guessZoomPercentile = function({
client = {},
osZoomFactor = 1
} = {}) {
if (window !== window.top) {
return 100;
}
_.defaults(client, {
x: 0,
y: 0,
width: window.innerWidth * osZoomFactor,
height: window.innerHeight * osZoomFactor
});
let exactZoomH =
100 *
(window.outerWidth - client.x) /
client.width;
let exactZoomV =
100 *
(window.outerHeight - client.y) /
client.height;
let exactZoom = _.min([
exactZoomH,
exactZoomV
]);
let closestZoom = _.reduce(exports._zoomPercentiles, function(acc, zoom) {
let abs = Math.abs(zoom - exactZoom);
return abs < acc.abs ? {
abs,
zoom
} : acc;
}, {
abs: Number.MAX_VALUE,
zoom: 100
}).zoom;
return closestZoom;
};
module.exports = guessZoomPercentile;