-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathline.js
61 lines (49 loc) · 1.7 KB
/
line.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
// import {path} from "d3-path";
import {path, pathRound} from "../path/withFormat";
import constant from "./constant";
import curveLinear from "./curve/linear";
import {x as pointX, y as pointY} from "./point";
export default function() {
var x = pointX,
y = pointY,
defined = constant(true),
context = null,
curve = curveLinear,
output = null,
precision = null;
function line(data) {
var i,
n = data.length,
d,
defined0 = false,
buffer;
if (context == null) output = curve(buffer = precision === null ? path() : pathRound(precision));
for (i = 0; i <= n; ++i) {
if (!(i < n && defined(d = data[i], i, data)) === defined0) {
if (defined0 = !defined0) output.lineStart();
else output.lineEnd();
}
if (defined0) output.point(+x(d, i, data), +y(d, i, data));
}
if (buffer) return output = null, buffer + "" || null;
}
line.precision = function(_) {
return arguments.length ? (precision = _, line) : precision;
};
line.x = function(_) {
return arguments.length ? (x = typeof _ === "function" ? _ : constant(+_), line) : x;
};
line.y = function(_) {
return arguments.length ? (y = typeof _ === "function" ? _ : constant(+_), line) : y;
};
line.defined = function(_) {
return arguments.length ? (defined = typeof _ === "function" ? _ : constant(!!_), line) : defined;
};
line.curve = function(_) {
return arguments.length ? (curve = _, context != null && (output = curve(context)), line) : curve;
};
line.context = function(_) {
return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), line) : context;
};
return line;
}