source: node_modules/d3-shape/src/line.js@ e4c61dd

Last change on this file since e4c61dd was e4c61dd, checked in by istevanoska <ilinastevanoska@…>, 6 months ago

Prototype 1.1

  • Property mode set to 100644
File size: 1.7 KB
Line 
1import array from "./array.js";
2import constant from "./constant.js";
3import curveLinear from "./curve/linear.js";
4import {withPath} from "./path.js";
5import {x as pointX, y as pointY} from "./point.js";
6
7export default function(x, y) {
8 var defined = constant(true),
9 context = null,
10 curve = curveLinear,
11 output = null,
12 path = withPath(line);
13
14 x = typeof x === "function" ? x : (x === undefined) ? pointX : constant(x);
15 y = typeof y === "function" ? y : (y === undefined) ? pointY : constant(y);
16
17 function line(data) {
18 var i,
19 n = (data = array(data)).length,
20 d,
21 defined0 = false,
22 buffer;
23
24 if (context == null) output = curve(buffer = path());
25
26 for (i = 0; i <= n; ++i) {
27 if (!(i < n && defined(d = data[i], i, data)) === defined0) {
28 if (defined0 = !defined0) output.lineStart();
29 else output.lineEnd();
30 }
31 if (defined0) output.point(+x(d, i, data), +y(d, i, data));
32 }
33
34 if (buffer) return output = null, buffer + "" || null;
35 }
36
37 line.x = function(_) {
38 return arguments.length ? (x = typeof _ === "function" ? _ : constant(+_), line) : x;
39 };
40
41 line.y = function(_) {
42 return arguments.length ? (y = typeof _ === "function" ? _ : constant(+_), line) : y;
43 };
44
45 line.defined = function(_) {
46 return arguments.length ? (defined = typeof _ === "function" ? _ : constant(!!_), line) : defined;
47 };
48
49 line.curve = function(_) {
50 return arguments.length ? (curve = _, context != null && (output = curve(context)), line) : curve;
51 };
52
53 line.context = function(_) {
54 return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), line) : context;
55 };
56
57 return line;
58}
Note: See TracBrowser for help on using the repository browser.