forked from observablehq/plot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdefined.js
More file actions
40 lines (32 loc) · 772 Bytes
/
defined.js
File metadata and controls
40 lines (32 loc) · 772 Bytes
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
import {ascending, descending} from "d3";
export function defined(x) {
return x != null && !Number.isNaN(x);
}
export function ascendingDefined(a, b) {
return defined(b) - defined(a) || ascending(a, b);
}
export function descendingDefined(a, b) {
return defined(b) - defined(a) || descending(a, b);
}
export function nonempty(x) {
return x != null && (x + "") !== "";
}
export function filter(index, ...channels) {
for (const c of channels) {
if (c) index = index.filter(i => defined(c[i]));
}
return index;
}
export function positive(x) {
return x > 0 ? x : NaN;
}
export function negative(x) {
return x < 0 ? x : NaN;
}
export function firstof(...values) {
for (const v of values) {
if (v !== undefined) {
return v;
}
}
}