forked from ColinEberhardt/d3fc-webgl-hathi-explorer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.js
More file actions
22 lines (18 loc) · 605 Bytes
/
util.js
File metadata and controls
22 lines (18 loc) · 605 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
export const distance = (x1, y1, x2, y2) => {
const dx = x1 - x2,
dy = y1 - y2;
return Math.sqrt(dx * dx + dy * dy);
};
export const trunc = (str, len) =>
str.length > len ? str.substr(0, len - 1) + "..." : str;
export const hashCode = s =>
s.split("").reduce((a, b) => {
a = (a << 5) - a + b.charCodeAt(0);
return a & a;
}, 0);
export const webglColor = color => {
const { r, g, b, opacity } = d3.color(color).rgb();
return [r / 255, g / 255, b / 255, opacity];
};
export const iterateElements = (selector, fn) =>
[].forEach.call(document.querySelectorAll(selector), fn);