Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

d3-shape

Package Overview
Dependencies
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

d3-shape - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

src/interpolate/basis-closed.js

2

build/bundle.js

@@ -1,1 +0,1 @@

var version = "0.0.1"; export * from "../index"; export {version};
var version = "0.0.2"; export * from "../index"; export {version};

@@ -7,301 +7,597 @@ (function (global, factory) {

function Cardinal(context, tension) {
this._context = context;
this._k = (1 - (tension == null ? .7 : tension)) / 2; // TODO
function point(basis, x, y) {
basis._context.bezierCurveTo(
(2 * basis._x0 + basis._x1) / 3,
(2 * basis._y0 + basis._y1) / 3,
(basis._x0 + 2 * basis._x1) / 3,
(basis._y0 + 2 * basis._y1) / 3,
(basis._x0 + 4 * basis._x1 + x) / 6,
(basis._y0 + 4 * basis._y1 + y) / 6
);
};
Cardinal.prototype.lineStart = function() {
this._x0 = this._x1 = this._x2 =
this._y0 = this._y1 = this._y2 = null;
};
function basis(context) {
return new Basis(context);
}
Cardinal.prototype.lineEnd = function() {
if (this._x0 != null) {
this._context.quadraticCurveTo(
this._x1 + this._k * (this._x2 - this._x0) * 2 / 3,
this._y1 + this._k * (this._y2 - this._y0) * 2 / 3,
this._x2,
this._y2
);
} else if (this._x1 != null) {
this._context.lineTo(this._x2, this._y2);
}
};
function Basis(context) {
this._context = context;
}
Cardinal.prototype.point = function(x, y) {
x = +x, y = +y;
if (this._x0 != null) {
this._context.bezierCurveTo(
this._x1 + this._k * (this._x2 - this._x0),
this._y1 + this._k * (this._y2 - this._y0),
this._x2 - this._k * (x - this._x1),
this._y2 - this._k * (y - this._y1),
this._x2,
this._y2
);
} else if (this._x1 != null) {
this._context.quadraticCurveTo(
this._x2 - this._k * (x - this._x1) * 2 / 3,
this._y2 - this._k * (y - this._y1) * 2 / 3,
this._x2,
this._y2
);
} else if (this._x2 == null) {
this._context.moveTo(x, y);
Basis.prototype = {
lineStart: function() {
this._x0 = this._x1 =
this._y0 = this._y1 = NaN;
this._state = 0;
},
lineEnd: function() {
switch (this._state) {
case 1: this._context.closePath(); break;
case 3: point(this, this._x1, this._y1); // proceed
case 2: this._context.lineTo(this._x1, this._y1); break;
}
},
point: function(x, y) {
x = +x, y = +y;
switch (this._state) {
case 0: this._state = 1; this._context.moveTo(x, y); break;
case 1: this._state = 2; this._context.lineTo((5 * this._x1 + x) / 6, (5 * this._y1 + y) / 6); break;
case 2: this._state = 3; // proceed
default: point(this, x, y); break;
}
this._x0 = this._x1, this._x1 = x;
this._y0 = this._y1, this._y1 = y;
}
this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
};
function CardinalOpen(context, tension) {
function basisClosed(context) {
return new BasisClosed(context);
}
function BasisClosed(context) {
this._context = context;
this._k = (1 - (tension == null ? .7 : tension)) / 2; // TODO
};
}
CardinalOpen.prototype.lineStart = function() {
this._x0 = this._x1 = this._x2 =
this._y0 = this._y1 = this._y2 = null;
BasisClosed.prototype = {
lineStart: function() {
this._x0 = this._x1 = this._x2 = this._x3 = this._x4 =
this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = NaN;
this._state = 0;
},
lineEnd: function() {
switch (this._state) {
case 1: {
this._context.moveTo(this._x2, this._y2);
this._context.closePath();
break;
}
case 2: {
this._context.moveTo((this._x2 + 2 * this._x3) / 3, (this._y2 + 2 * this._y3) / 3);
this._context.lineTo((this._x3 + 2 * this._x2) / 3, (this._y3 + 2 * this._y2) / 3);
this._context.closePath();
break;
}
case 3: {
this.point(this._x2, this._y2);
this.point(this._x3, this._y3);
this.point(this._x4, this._y4);
break;
}
}
},
point: function(x, y) {
x = +x, y = +y;
switch (this._state) {
case 0: this._state = 1; this._x2 = x, this._y2 = y; break;
case 1: this._state = 2; this._x3 = x, this._y3 = y; break;
case 2: this._state = 3; this._x4 = x, this._y4 = y; this._context.moveTo((this._x0 + 4 * this._x1 + x) / 6, (this._y0 + 4 * this._y1 + y) / 6); break;
default: point(this, x, y); break;
}
this._x0 = this._x1, this._x1 = x;
this._y0 = this._y1, this._y1 = y;
}
};
CardinalOpen.prototype.lineEnd = function() {};
function basisOpen(context) {
return new BasisOpen(context);
}
CardinalOpen.prototype.point = function(x, y) {
x = +x, y = +y;
if (this._x0 != null) {
this._context.bezierCurveTo(
this._x1 + this._k * (this._x2 - this._x0),
this._y1 + this._k * (this._y2 - this._y0),
this._x2 - this._k * (x - this._x1),
this._y2 - this._k * (y - this._y1),
this._x2,
this._y2
);
} else if (this._x1 == null && this._x2 != null) {
this._context.moveTo(x, y);
function BasisOpen(context) {
this._context = context;
}
BasisOpen.prototype = {
lineStart: function() {
this._x0 = this._x1 =
this._y0 = this._y1 = NaN;
this._state = 0;
},
lineEnd: function() {
if (this._state === 3) this._context.closePath();
},
point: function(x, y) {
x = +x, y = +y;
switch (this._state) {
case 0: this._state = 1; break;
case 1: this._state = 2; break;
case 2: this._state = 3; this._context.moveTo((this._x0 + 4 * this._x1 + x) / 6, (this._y0 + 4 * this._y1 + y) / 6); break; // TODO
case 3: this._state = 4; // proceed
default: point(this, x, y); break;
}
this._x0 = this._x1, this._x1 = x;
this._y0 = this._y1, this._y1 = y;
}
this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
};
// function cardinalTangents(points, tension) {
// var tangents = [],
// a = (1 - tension) / 2,
// p0,
// p1 = points[0],
// p2 = points[1],
// i = 1,
// n = points.length;
function cardinal(tension) {
return function(context) {
return new Cardinal(context, tension);
};
}
// while (++i < n) {
// p0 = p1;
// p1 = p2;
// p2 = points[i];
// tangents.push([a * (p2[0] - p0[0]), a * (p2[1] - p0[1])]);
// }
function Cardinal(context, tension) {
this._context = context;
this._k = (tension == null ? 1 : 1 - tension) / 6;
}
// return tangents;
// }
Cardinal.prototype = {
lineStart: function() {
this._x0 = this._x1 = this._x2 =
this._y0 = this._y1 = this._y2 = NaN;
this._state = 0;
},
lineEnd: function() {
switch (this._state) {
case 1: this._context.closePath(); break;
case 2: this._context.lineTo(this._x2, this._y2); break;
case 3: {
this._context.bezierCurveTo(
this._x1 + this._k * (this._x2 - this._x0),
this._y1 + this._k * (this._y2 - this._y0),
this._x2,
this._y2,
this._x2,
this._y2
);
break;
}
}
},
point: function(x, y) {
x = +x, y = +y;
switch (this._state) {
case 0: this._state = 1; this._context.moveTo(x, y); break;
case 1: this._state = 2; break;
case 2: {
this._state = 3;
this._context.bezierCurveTo(
this._x1,
this._y1,
this._x2 + this._k * (this._x1 - x),
this._y2 + this._k * (this._y1 - y),
this._x2,
this._y2
);
break;
}
default: {
this._context.bezierCurveTo(
this._x1 + this._k * (this._x2 - this._x0),
this._y1 + this._k * (this._y2 - this._y0),
this._x2 + this._k * (this._x1 - x),
this._y2 + this._k * (this._y1 - y),
this._x2,
this._y2
);
break;
}
}
this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
}
};
// export function interpolateCardinalOpen(points, tension) {
// return points.length < 4
// ? interpolateLinear(points)
// : points[1] + interpolateHermit(points.slice(1, -1), cardinalTangents(points, tension));
// };
// export function interpolateCardinalClosed(points, tension) {
// return points.length < 3
// ? interpolateLinear(points)
// : points[0] + interpolateHermit((points.push(points[0]), points), cardinalTangents([points[points.length - 2]].concat(points, [points[1]]), tension));
// };
// export function interpolateCardinal(points, tension) {
// return points.length < 3
// ? interpolateLinear(points)
// : points[0] + interpolateHermit(points, cardinalTangents(points, tension));
// };
function basisPoint(basis, x, y) {
basis._context.bezierCurveTo(
(2 * basis._x0 + basis._x1) / 3,
(2 * basis._y0 + basis._y1) / 3,
(basis._x0 + 2 * basis._x1) / 3,
(basis._y0 + 2 * basis._y1) / 3,
(basis._x0 + 4 * basis._x1 + x) / 6,
(basis._y0 + 4 * basis._y1 + y) / 6
);
function cardinalClosed(tension) {
return function(context) {
return new CardinalClosed(context, tension);
};
}
function Basis(context) {
function CardinalClosed(context, tension) {
this._context = context;
};
this._k = (tension == null ? 1 : 1 - tension) / 6;
}
Basis.prototype.lineStart = function() {
this._x0 = this._x1 =
this._y0 = this._y1 = null;
};
Basis.prototype.lineEnd = function() {
if (this._x0 != null) {
this.point(this._x1, this._y1);
this._context.lineTo(this._x1, this._y1);
CardinalClosed.prototype = {
lineStart: function() {
this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = this._x5 =
this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = this._y5 = NaN;
this._state = 0;
},
lineEnd: function() {
switch (this._state) {
case 1: {
this._context.moveTo(this._x3, this._y3);
this._context.closePath();
break;
}
case 2: {
this._context.lineTo(this._x3, this._y3);
this._context.closePath();
break;
}
case 3: {
this.point(this._x3, this._y3);
this.point(this._x4, this._y4);
this.point(this._x5, this._y5);
break;
}
}
},
point: function(x, y) {
x = +x, y = +y;
switch (this._state) {
case 0: this._state = 1; this._x3 = x, this._y3 = y; break;
case 1: this._state = 2; this._context.moveTo(this._x4 = x, this._y4 = y); break;
case 2: this._state = 3; this._x5 = x, this._y5 = y; break;
default: {
this._context.bezierCurveTo(
this._x1 + this._k * (this._x2 - this._x0),
this._y1 + this._k * (this._y2 - this._y0),
this._x2 + this._k * (this._x1 - x),
this._y2 + this._k * (this._y1 - y),
this._x2,
this._y2
);
break;
}
}
this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
}
};
Basis.prototype.point = function(x, y) {
x = +x, y = +y;
if (this._x0 != null) basisPoint(this, x, y);
else if (this._x1 != null) this._context.lineTo((5 * this._x1 + x) / 6, (5 * this._y1 + y) / 6);
else this._context.moveTo(x, y);
this._x0 = this._x1, this._x1 = x;
this._y0 = this._y1, this._y1 = y;
};
function cardinalOpen(tension) {
return function(context) {
return new CardinalOpen(context, tension);
};
}
function BasisOpen(context) {
function CardinalOpen(context, tension) {
this._context = context;
};
this._k = (tension == null ? 1 : 1 - tension) / 6;
}
BasisOpen.prototype.lineStart = function() {
this._x0 = this._x1 =
this._y0 = this._y1 = null;
this._moved = false;
CardinalOpen.prototype = {
lineStart: function() {
this._x0 = this._x1 = this._x2 =
this._y0 = this._y1 = this._y2 = NaN;
this._state = 0;
},
lineEnd: function() {
switch (this._state) {
case 2:
case 3: this._context.closePath(); break;
}
},
point: function(x, y) {
x = +x, y = +y;
switch (this._state) {
case 0: this._state = 1; break;
case 1: this._state = 2; this._context.moveTo(x, y); break;
case 2: this._state = 3; break;
case 3: this._state = 4; // proceed
default: {
this._context.bezierCurveTo(
this._x1 + this._k * (this._x2 - this._x0),
this._y1 + this._k * (this._y2 - this._y0),
this._x2 + this._k * (this._x1 - x),
this._y2 + this._k * (this._y1 - y),
this._x2,
this._y2
);
break;
}
}
this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
}
};
BasisOpen.prototype.lineEnd = function() {};
// TODO Check if n or m is zero, and avoid NaN.
// n is zero if (x0,y0) and (x1,y1) are coincident.
// m is zero if (x2,y2) and (x3,y3) are coincident.
BasisOpen.prototype.point = function(x, y) {
x = +x, y = +y;
if (this._moved) basisPoint(this, x, y);
else if (this._x0 != null) this._moved = true, this._context.moveTo((this._x0 + 4 * this._x1 + x) / 6, (this._y0 + 4 * this._y1 + y) / 6);
this._x0 = this._x1, this._x1 = x;
this._y0 = this._y1, this._y1 = y;
};
function catmullRom(alpha) {
return function(context) {
return new CatmullRom(context, alpha);
};
}
function BasisClosed(context) {
function CatmullRom(context, alpha) {
this._context = context;
};
this._alpha2 = (this._alpha = alpha == null ? 0 : +alpha) / 2;
}
BasisClosed.prototype.lineStart = function() {
this._x0 = this._x1 = this._x2 = this._x3 = this._x4 =
this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = null;
};
CatmullRom.prototype = {
lineStart: function() {
this._x0 = this._x1 = this._x2 =
this._y0 = this._y1 = this._y2 =
this._l01_a = this._l12_a = this._l23_a =
this._l01_2a = this._l12_2a = this._l23_2a = NaN;
this._state = 0;
},
lineEnd: function() {
switch (this._state) {
case 1: this._context.closePath(); break;
case 2: this._context.lineTo(this._x2, this._y2); break;
case 3: {
var a = 2 * this._l01_2a + 3 * this._l01_a * this._l12_a + this._l12_2a,
n = 3 * this._l01_a * (this._l01_a + this._l12_a);
this._context.bezierCurveTo(
(this._x1 * a - this._x0 * this._l12_2a + this._x2 * this._l01_2a) / n,
(this._y1 * a - this._y0 * this._l12_2a + this._y2 * this._l01_2a) / n,
this._x2,
this._y2,
this._x2,
this._y2
);
break;
}
}
},
point: function(x, y) {
x = +x, y = +y;
BasisClosed.prototype.lineEnd = function() {
if (this._x4 != null) {
this.point(this._x2, this._y2);
this.point(this._x3, this._y3);
this.point(this._x4, this._y4);
} else if (this._x3 != null) {
this._context.moveTo((this._x2 + 2 * this._x3) / 3, (this._y2 + 2 * this._y3) / 3);
this._context.lineTo((this._x3 + 2 * this._x2) / 3, (this._y3 + 2 * this._y2) / 3);
this._context.closePath();
} else if (this._x2 != null) {
this._context.moveTo(this._x2, this._y2);
this._context.closePath();
if (this._state) {
var x23 = this._x2 - x,
y23 = this._y2 - y,
l23_2 = x23 * x23 + y23 * y23;
this._l23_a = Math.pow(l23_2, this._alpha2);
this._l23_2a = Math.pow(l23_2, this._alpha);
}
switch (this._state) {
case 0: this._state = 1; this._context.moveTo(x, y); break;
case 1: this._state = 2; break;
case 2: {
var b = 2 * this._l23_2a + 3 * this._l23_a * this._l12_a + this._l12_2a,
m = 3 * this._l23_a * (this._l23_a + this._l12_a);
this._state = 3;
this._context.bezierCurveTo(
this._x1,
this._y1,
(this._x2 * b + this._x1 * this._l23_2a - x * this._l12_2a) / m,
(this._y2 * b + this._y1 * this._l23_2a - y * this._l12_2a) / m,
this._x2,
this._y2
);
break;
}
default: {
var a = 2 * this._l01_2a + 3 * this._l01_a * this._l12_a + this._l12_2a,
b = 2 * this._l23_2a + 3 * this._l23_a * this._l12_a + this._l12_2a,
n = 3 * this._l01_a * (this._l01_a + this._l12_a),
m = 3 * this._l23_a * (this._l23_a + this._l12_a);
this._context.bezierCurveTo(
(this._x1 * a - this._x0 * this._l12_2a + this._x2 * this._l01_2a) / n,
(this._y1 * a - this._y0 * this._l12_2a + this._y2 * this._l01_2a) / n,
(this._x2 * b + this._x1 * this._l23_2a - x * this._l12_2a) / m,
(this._y2 * b + this._y1 * this._l23_2a - y * this._l12_2a) / m,
this._x2,
this._y2
);
break;
}
}
this._l01_a = this._l12_a, this._l12_a = this._l23_a;
this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
}
};
BasisClosed.prototype.point = function(x, y) {
x = +x, y = +y;
if (this._x4 != null) basisPoint(this, x, y);
else if (this._x3 != null) this._x4 = x, this._y4 = y, this._context.moveTo((this._x0 + 4 * this._x1 + x) / 6, (this._y0 + 4 * this._y1 + y) / 6);
else if (this._x2 != null) this._x3 = x, this._y3 = y;
else this._x2 = x, this._y2 = y;
this._x0 = this._x1, this._x1 = x;
this._y0 = this._y1, this._y1 = y;
};
function cubic(context) {
return new Cubic(context);
}
function Step(context) {
function Cubic(context) {
this._context = context;
};
}
Step.prototype.lineStart = function() {
this._x = this._y = null;
};
Step.prototype.lineEnd = function() {
if (this._x != null) {
this._context.lineTo(this._x, this._y);
Cubic.prototype = {
lineStart: function() {
this._x = [];
this._y = [];
},
lineEnd: function() {
var x = this._x,
y = this._y,
n = x.length;
switch (n) {
case 0: break;
case 1: this._context.moveTo(x[0], y[0]); this._context.closePath(); break;
case 2: this._context.moveTo(x[0], y[0]); this._context.lineTo(x[1], y[1]); break;
default: {
var px = controlPoints(x),
py = controlPoints(y);
this._context.moveTo(x[0], y[0]);
for (var i = 0, n = x.length; i < n - 1; ++i) {
this._context.bezierCurveTo(px[0][i], py[0][i], px[1][i], py[1][i], x[i + 1], y[i + 1]);
}
break;
}
}
this._x = this._y = null;
},
point: function(x, y) {
this._x.push(+x);
this._y.push(+y);
}
};
Step.prototype.point = function(x, y) {
x = +x, y = +y;
if (this._x == null) {
this._context.moveTo(x, y);
} else {
var x1 = (this._x + x) / 2;
this._context.lineTo(x1, this._y);
this._context.lineTo(x1, y);
}
this._x = x, this._y = y;
};
// See https://www.particleincell.com/2012/bezier-splines/ for derivation.
function controlPoints(x) {
var i,
n = x.length - 1,
m,
a = new Array(n),
b = new Array(n),
r = new Array(n);
a[0] = 0, b[0] = 2, r[0] = x[0] + 2 * x[1];
for (i = 1; i < n - 1; ++i) a[i] = 1, b[i] = 4, r[i] = 4 * x[i] + 2 * x[i + 1];
a[n - 1] = 2, b[n - 1] = 7, r[n - 1] = 8 * x[n - 1] + x[n];
for (i = 1; i < n; ++i) m = a[i] / b[i - 1], b[i] -= m, r[i] -= m * r[i - 1];
a[n - 1] = r[n - 1] / b[n - 1];
for (i = n - 2; i >= 0; --i) a[i] = (r[i] - a[i + 1]) / b[i];
b[n - 1] = (x[n] + a[n - 1]) / 2;
for (i = 0; i < n - 1; ++i) b[i] = 2 * x[i + 1] - a[i + 1];
return [a, b];
}
function StepAfter(context) {
function linear(context) {
return new Linear(context);
}
function Linear(context) {
this._context = context;
};
}
StepAfter.prototype.lineStart = function() {
this._y = null;
Linear.prototype = {
lineStart: function() {
this._state = 0;
},
lineEnd: function() {
if (this._state === 1) this._context.closePath();
},
point: function(x, y) {
x = +x, y = +y;
switch (this._state) {
case 0: this._state = 1; this._context.moveTo(x, y); break;
case 1: this._state = 2; // proceed
default: this._context.lineTo(x, y); break;
}
}
};
StepAfter.prototype.lineEnd = function() {};
function linearClosed(context) {
return new LinearClosed(context);
}
StepAfter.prototype.point = function(x, y) {
x = +x, y = +y;
if (this._y == null) {
this._context.moveTo(x, y);
} else {
this._context.lineTo(x, this._y);
this._context.lineTo(x, y);
function LinearClosed(context) {
this._context = context;
}
LinearClosed.prototype = {
lineStart: function() {
this._state = 0;
},
lineEnd: function() {
this._context.closePath();
},
point: function(x, y) {
x = +x, y = +y;
if (this._state) this._context.lineTo(x, y);
else this._state = 1, this._context.moveTo(x, y);
}
this._y = y;
};
function StepBefore(context) {
function step(context) {
return new Step(context);
}
function Step(context) {
this._context = context;
};
}
StepBefore.prototype.lineStart = function() {
this._x = null;
Step.prototype = {
lineStart: function() {
this._x = this._y = NaN;
this._state = 0;
},
lineEnd: function() {
switch (this._state) {
case 1: this._context.closePath(); break;
case 2: this._context.lineTo(this._x, this._y); break;
}
},
point: function(x, y) {
x = +x, y = +y;
switch (this._state) {
case 0: this._state = 1; this._context.moveTo(x, y); break;
case 1: this._state = 2; // proceed
default: {
var x1 = (this._x + x) / 2;
this._context.lineTo(x1, this._y);
this._context.lineTo(x1, y);
break;
}
}
this._x = x, this._y = y;
}
};
StepBefore.prototype.lineEnd = function() {};
function stepAfter(context) {
return new StepAfter(context);
}
StepBefore.prototype.point = function(x, y) {
x = +x, y = +y;
if (this._x == null) {
this._context.moveTo(x, y);
} else {
this._context.lineTo(this._x, y);
this._context.lineTo(x, y);
}
this._x = x;
};
function Linear(context) {
function StepAfter(context) {
this._context = context;
};
}
Linear.prototype.lineStart = function() {
this._move = true;
StepAfter.prototype = {
lineStart: function() {
this._y = NaN;
this._state = 0;
},
lineEnd: function() {
if (this._state === 1) this._context.closePath();
},
point: function(x, y) {
x = +x, y = +y;
switch (this._state) {
case 0: this._state = 1; this._context.moveTo(x, y); break;
case 1: this._state = 2; // proceed
default: {
this._context.lineTo(x, this._y);
this._context.lineTo(x, y);
break;
}
}
this._y = y;
}
};
Linear.prototype.lineEnd = function() {};
function stepBefore(context) {
return new StepBefore(context);
}
Linear.prototype.point = function(x, y) {
if (this._move) this._move = false, this._context.moveTo(x, y);
else this._context.lineTo(x, y);
};
function StepBefore(context) {
this._context = context;
}
function LinearClosed(context) {
Linear.call(this, context); // https://github.com/rollup/rollup/issues/34
StepBefore.prototype = {
lineStart: function() {
this._x = NaN;
this._state = 0;
},
lineEnd: function() {
if (this._state === 1) this._context.closePath();
},
point: function(x, y) {
x = +x, y = +y;
switch (this._state) {
case 0: this._state = 1; this._context.moveTo(x, y); break;
case 1: this._state = 2; // proceed
default: {
this._context.lineTo(this._x, y);
this._context.lineTo(x, y);
break;
}
}
this._x = x;
}
};
LinearClosed.prototype = Object.create(Linear.prototype);
LinearClosed.prototype.lineEnd = function() {
this._context.closePath();
};
function pointX(p) {

@@ -315,3 +611,3 @@ return p[0];

function functor(x) {
function constant(x) {
return function() {

@@ -326,17 +622,2 @@ return x;

var interpolates = (new Map)
.set("linear", Linear)
.set("linear-closed", LinearClosed)
.set("step", Step)
.set("step-before", StepBefore)
.set("step-after", StepAfter)
.set("basis", Basis)
.set("basis-open", BasisOpen)
.set("basis-closed", BasisClosed)
// .set("bundle", Bundle)
.set("cardinal", Cardinal)
.set("cardinal-open", CardinalOpen)
// .set("cardinal-closed", CardinalClosed)
// .set("monotone", Monotone);
function line() {

@@ -346,3 +627,3 @@ var x = pointX, _x = x,

defined = true, _defined = _true,
interpolate = Linear,
interpolate = linear,
context = null,

@@ -353,16 +634,16 @@ stream = null;

var defined = false,
result;
buffer;
if (!stream) stream = new interpolate(result = d3Path.path()); // TODO tension?
if (!context) stream = interpolate(buffer = d3Path.path());
for (var i = 0, n = data.length, d; i < n; ++i) {
if (!_defined.call(this, d = data[i], i) === defined) {
if (!_defined(d = data[i], i) === defined) {
if (defined = !defined) stream.lineStart();
else stream.lineEnd();
}
if (defined) stream.point(+_x.call(this, d, i), +_y.call(this, d, i));
if (defined) stream.point(+_x(d, i), +_y(d, i));
}
if (defined) stream.lineEnd();
if (result) return stream = null, result += "";
if (!context) return stream = null, buffer + "" || null;
}

@@ -372,3 +653,3 @@

if (!arguments.length) return x;
x = _, _x = typeof _ === "function" ? x : functor(x);
x = _, _x = typeof _ === "function" ? x : constant(x);
return line;

@@ -379,3 +660,3 @@ };

if (!arguments.length) return y;
y = _, _y = typeof _ === "function" ? y : functor(y);
y = _, _y = typeof _ === "function" ? y : constant(y);
return line;

@@ -386,10 +667,25 @@ };

if (!arguments.length) return defined;
defined = _, _defined = typeof _ === "function" ? defined : functor(defined);
defined = _, _defined = typeof _ === "function" ? defined : constant(defined);
return line;
};
line.interpolate = function(_, tension) {
line.interpolate = function(_, a) {
if (!arguments.length) return interpolate;
if (!(interpolate = interpolates.get(_ + ""))) interpolate = Linear;
if (context != null) stream = new interpolate(context); // TODO tension?
if (typeof _ === "function") interpolate = _;
else switch (_ + "") {
case "linear-closed": interpolate = linearClosed; break;
case "step": interpolate = step; break;
case "step-before": interpolate = stepBefore; break;
case "step-after": interpolate = stepAfter; break;
case "basis": interpolate = basis; break;
case "basis-open": interpolate = basisOpen; break;
case "basis-closed": interpolate = basisClosed; break;
case "cardinal": interpolate = cardinal(a); break;
case "cardinal-open": interpolate = cardinalOpen(a); break;
case "cardinal-closed": interpolate = cardinalClosed(a); break;
case "catmull-rom": interpolate = catmullRom(a); break;
case "cubic": interpolate = cubic; break;
default: interpolate = linear; break;
}
if (context != null) stream = interpolate(context);
return line;

@@ -401,3 +697,3 @@ };

if (_ == null) context = stream = null;
else stream = new interpolate(context = _); // TODO tension?
else stream = interpolate(context = _);
return line;

@@ -409,3 +705,3 @@ };

var version = "0.0.1";
var version = "0.0.2";

@@ -412,0 +708,0 @@ exports.version = version;

@@ -1,1 +0,1 @@

!function(t,i){"object"==typeof exports&&"undefined"!=typeof module?i(exports,require("d3-path")):"function"==typeof define&&define.amd?define("d3-shape",["exports","d3-path"],i):i(t.d3_shape={},t.d3_path)}(this,function(t,i){"use strict";function n(t,i){this._context=t,this._k=(1-(null==i?.7:i))/2}function s(t,i){this._context=t,this._k=(1-(null==i?.7:i))/2}function h(t,i,n){t._context.bezierCurveTo((2*t._x0+t._x1)/3,(2*t._y0+t._y1)/3,(t._x0+2*t._x1)/3,(t._y0+2*t._y1)/3,(t._x0+4*t._x1+i)/6,(t._y0+4*t._y1+n)/6)}function _(t){this._context=t}function o(t){this._context=t}function e(t){this._context=t}function x(t){this._context=t}function l(t){this._context=t}function u(t){this._context=t}function y(t){this._context=t}function c(t){y.call(this,t)}function r(t){return t[0]}function p(t){return t[1]}function f(t){return function(){return t}}function a(){return!0}function d(){function t(t){var n,h=!1;u||(u=new x(n=i.path()));for(var o,l=0,y=t.length;y>l;++l)!e.call(this,o=t[l],l)===h&&((h=!h)?u.lineStart():u.lineEnd()),h&&u.point(+s.call(this,o,l),+_.call(this,o,l));return h&&u.lineEnd(),n?(u=null,n+=""):void 0}var n=r,s=n,h=p,_=h,o=!0,e=a,x=y,l=null,u=null;return t.x=function(i){return arguments.length?(n=i,s="function"==typeof i?n:f(n),t):n},t.y=function(i){return arguments.length?(h=i,_="function"==typeof i?h:f(h),t):h},t.defined=function(i){return arguments.length?(o=i,e="function"==typeof i?o:f(o),t):o},t.interpolate=function(i,n){return arguments.length?((x=v.get(i+""))||(x=y),null!=l&&(u=new x(l)),t):x},t.context=function(i){return arguments.length?(null==i?l=u=null:u=new x(l=i),t):l},t}n.prototype.lineStart=function(){this._x0=this._x1=this._x2=this._y0=this._y1=this._y2=null},n.prototype.lineEnd=function(){null!=this._x0?this._context.quadraticCurveTo(this._x1+this._k*(this._x2-this._x0)*2/3,this._y1+this._k*(this._y2-this._y0)*2/3,this._x2,this._y2):null!=this._x1&&this._context.lineTo(this._x2,this._y2)},n.prototype.point=function(t,i){t=+t,i=+i,null!=this._x0?this._context.bezierCurveTo(this._x1+this._k*(this._x2-this._x0),this._y1+this._k*(this._y2-this._y0),this._x2-this._k*(t-this._x1),this._y2-this._k*(i-this._y1),this._x2,this._y2):null!=this._x1?this._context.quadraticCurveTo(this._x2-this._k*(t-this._x1)*2/3,this._y2-this._k*(i-this._y1)*2/3,this._x2,this._y2):null==this._x2&&this._context.moveTo(t,i),this._x0=this._x1,this._x1=this._x2,this._x2=t,this._y0=this._y1,this._y1=this._y2,this._y2=i},s.prototype.lineStart=function(){this._x0=this._x1=this._x2=this._y0=this._y1=this._y2=null},s.prototype.lineEnd=function(){},s.prototype.point=function(t,i){t=+t,i=+i,null!=this._x0?this._context.bezierCurveTo(this._x1+this._k*(this._x2-this._x0),this._y1+this._k*(this._y2-this._y0),this._x2-this._k*(t-this._x1),this._y2-this._k*(i-this._y1),this._x2,this._y2):null==this._x1&&null!=this._x2&&this._context.moveTo(t,i),this._x0=this._x1,this._x1=this._x2,this._x2=t,this._y0=this._y1,this._y1=this._y2,this._y2=i},_.prototype.lineStart=function(){this._x0=this._x1=this._y0=this._y1=null},_.prototype.lineEnd=function(){null!=this._x0&&(this.point(this._x1,this._y1),this._context.lineTo(this._x1,this._y1))},_.prototype.point=function(t,i){t=+t,i=+i,null!=this._x0?h(this,t,i):null!=this._x1?this._context.lineTo((5*this._x1+t)/6,(5*this._y1+i)/6):this._context.moveTo(t,i),this._x0=this._x1,this._x1=t,this._y0=this._y1,this._y1=i},o.prototype.lineStart=function(){this._x0=this._x1=this._y0=this._y1=null,this._moved=!1},o.prototype.lineEnd=function(){},o.prototype.point=function(t,i){t=+t,i=+i,this._moved?h(this,t,i):null!=this._x0&&(this._moved=!0,this._context.moveTo((this._x0+4*this._x1+t)/6,(this._y0+4*this._y1+i)/6)),this._x0=this._x1,this._x1=t,this._y0=this._y1,this._y1=i},e.prototype.lineStart=function(){this._x0=this._x1=this._x2=this._x3=this._x4=this._y0=this._y1=this._y2=this._y3=this._y4=null},e.prototype.lineEnd=function(){null!=this._x4?(this.point(this._x2,this._y2),this.point(this._x3,this._y3),this.point(this._x4,this._y4)):null!=this._x3?(this._context.moveTo((this._x2+2*this._x3)/3,(this._y2+2*this._y3)/3),this._context.lineTo((this._x3+2*this._x2)/3,(this._y3+2*this._y2)/3),this._context.closePath()):null!=this._x2&&(this._context.moveTo(this._x2,this._y2),this._context.closePath())},e.prototype.point=function(t,i){t=+t,i=+i,null!=this._x4?h(this,t,i):null!=this._x3?(this._x4=t,this._y4=i,this._context.moveTo((this._x0+4*this._x1+t)/6,(this._y0+4*this._y1+i)/6)):null!=this._x2?(this._x3=t,this._y3=i):(this._x2=t,this._y2=i),this._x0=this._x1,this._x1=t,this._y0=this._y1,this._y1=i},x.prototype.lineStart=function(){this._x=this._y=null},x.prototype.lineEnd=function(){null!=this._x&&(this._context.lineTo(this._x,this._y),this._x=this._y=null)},x.prototype.point=function(t,i){if(t=+t,i=+i,null==this._x)this._context.moveTo(t,i);else{var n=(this._x+t)/2;this._context.lineTo(n,this._y),this._context.lineTo(n,i)}this._x=t,this._y=i},l.prototype.lineStart=function(){this._y=null},l.prototype.lineEnd=function(){},l.prototype.point=function(t,i){t=+t,i=+i,null==this._y?this._context.moveTo(t,i):(this._context.lineTo(t,this._y),this._context.lineTo(t,i)),this._y=i},u.prototype.lineStart=function(){this._x=null},u.prototype.lineEnd=function(){},u.prototype.point=function(t,i){t=+t,i=+i,null==this._x?this._context.moveTo(t,i):(this._context.lineTo(this._x,i),this._context.lineTo(t,i)),this._x=t},y.prototype.lineStart=function(){this._move=!0},y.prototype.lineEnd=function(){},y.prototype.point=function(t,i){this._move?(this._move=!1,this._context.moveTo(t,i)):this._context.lineTo(t,i)},c.prototype=Object.create(y.prototype),c.prototype.lineEnd=function(){this._context.closePath()};var v=(new Map).set("linear",y).set("linear-closed",c).set("step",x).set("step-before",u).set("step-after",l).set("basis",_).set("basis-open",o).set("basis-closed",e).set("cardinal",n).set("cardinal-open",s),T="0.0.1";t.version=T,t.line=d});
!function(t,i){"object"==typeof exports&&"undefined"!=typeof module?i(exports,require("d3-path")):"function"==typeof define&&define.amd?define("d3-shape",["exports","d3-path"],i):i(t.d3_shape={},t.d3_path)}(this,function(t,i){"use strict";function s(t,i,s){t._context.bezierCurveTo((2*t._x0+t._x1)/3,(2*t._y0+t._y1)/3,(t._x0+2*t._x1)/3,(t._y0+2*t._y1)/3,(t._x0+4*t._x1+i)/6,(t._y0+4*t._y1+s)/6)}function _(t){return new h(t)}function h(t){this._context=t}function e(t){return new n(t)}function n(t){this._context=t}function a(t){return new o(t)}function o(t){this._context=t}function c(t){return function(i){return new x(i,t)}}function x(t,i){this._context=t,this._k=(null==i?1:1-i)/6}function r(t){return function(i){return new l(i,t)}}function l(t,i){this._context=t,this._k=(null==i?1:1-i)/6}function u(t){return function(i){return new y(i,t)}}function y(t,i){this._context=t,this._k=(null==i?1:1-i)/6}function f(t){return function(i){return new p(i,t)}}function p(t,i){this._context=t,this._alpha2=(this._alpha=null==i?0:+i)/2}function k(t){return new b(t)}function b(t){this._context=t}function d(t){var i,s,_=t.length-1,h=new Array(_),e=new Array(_),n=new Array(_);for(h[0]=0,e[0]=2,n[0]=t[0]+2*t[1],i=1;_-1>i;++i)h[i]=1,e[i]=4,n[i]=4*t[i]+2*t[i+1];for(h[_-1]=2,e[_-1]=7,n[_-1]=8*t[_-1]+t[_],i=1;_>i;++i)s=h[i]/e[i-1],e[i]-=s,n[i]-=s*n[i-1];for(h[_-1]=n[_-1]/e[_-1],i=_-2;i>=0;--i)h[i]=(n[i]-h[i+1])/e[i];for(e[_-1]=(t[_]+h[_-1])/2,i=0;_-1>i;++i)e[i]=2*t[i+1]-h[i+1];return[h,e]}function T(t){return new v(t)}function v(t){this._context=t}function w(t){return new m(t)}function m(t){this._context=t}function N(t){return new E(t)}function E(t){this._context=t}function P(t){return new g(t)}function g(t){this._context=t}function S(t){return new z(t)}function z(t){this._context=t}function C(t){return t[0]}function A(t){return t[1]}function M(t){return function(){return t}}function j(){return!0}function q(){function t(t){var s,_=!1;p||(b=y(s=i.path()));for(var e,n=0,a=t.length;a>n;++n)!l(e=t[n],n)===_&&((_=!_)?b.lineStart():b.lineEnd()),_&&b.point(+h(e,n),+o(e,n));return _&&b.lineEnd(),p?void 0:(b=null,s+""||null)}var s=C,h=s,n=A,o=n,x=!0,l=j,y=T,p=null,b=null;return t.x=function(i){return arguments.length?(s=i,h="function"==typeof i?s:M(s),t):s},t.y=function(i){return arguments.length?(n=i,o="function"==typeof i?n:M(n),t):n},t.defined=function(i){return arguments.length?(x=i,l="function"==typeof i?x:M(x),t):x},t.interpolate=function(i,s){if(!arguments.length)return y;if("function"==typeof i)y=i;else switch(i+""){case"linear-closed":y=w;break;case"step":y=N;break;case"step-before":y=S;break;case"step-after":y=P;break;case"basis":y=_;break;case"basis-open":y=a;break;case"basis-closed":y=e;break;case"cardinal":y=c(s);break;case"cardinal-open":y=u(s);break;case"cardinal-closed":y=r(s);break;case"catmull-rom":y=f(s);break;case"cubic":y=k;break;default:y=T}return null!=p&&(b=y(p)),t},t.context=function(i){return arguments.length?(null==i?p=b=null:b=y(p=i),t):p},t}h.prototype={lineStart:function(){this._x0=this._x1=this._y0=this._y1=NaN,this._state=0},lineEnd:function(){switch(this._state){case 1:this._context.closePath();break;case 3:s(this,this._x1,this._y1);case 2:this._context.lineTo(this._x1,this._y1)}},point:function(t,i){switch(t=+t,i=+i,this._state){case 0:this._state=1,this._context.moveTo(t,i);break;case 1:this._state=2,this._context.lineTo((5*this._x1+t)/6,(5*this._y1+i)/6);break;case 2:this._state=3;default:s(this,t,i)}this._x0=this._x1,this._x1=t,this._y0=this._y1,this._y1=i}},n.prototype={lineStart:function(){this._x0=this._x1=this._x2=this._x3=this._x4=this._y0=this._y1=this._y2=this._y3=this._y4=NaN,this._state=0},lineEnd:function(){switch(this._state){case 1:this._context.moveTo(this._x2,this._y2),this._context.closePath();break;case 2:this._context.moveTo((this._x2+2*this._x3)/3,(this._y2+2*this._y3)/3),this._context.lineTo((this._x3+2*this._x2)/3,(this._y3+2*this._y2)/3),this._context.closePath();break;case 3:this.point(this._x2,this._y2),this.point(this._x3,this._y3),this.point(this._x4,this._y4)}},point:function(t,i){switch(t=+t,i=+i,this._state){case 0:this._state=1,this._x2=t,this._y2=i;break;case 1:this._state=2,this._x3=t,this._y3=i;break;case 2:this._state=3,this._x4=t,this._y4=i,this._context.moveTo((this._x0+4*this._x1+t)/6,(this._y0+4*this._y1+i)/6);break;default:s(this,t,i)}this._x0=this._x1,this._x1=t,this._y0=this._y1,this._y1=i}},o.prototype={lineStart:function(){this._x0=this._x1=this._y0=this._y1=NaN,this._state=0},lineEnd:function(){3===this._state&&this._context.closePath()},point:function(t,i){switch(t=+t,i=+i,this._state){case 0:this._state=1;break;case 1:this._state=2;break;case 2:this._state=3,this._context.moveTo((this._x0+4*this._x1+t)/6,(this._y0+4*this._y1+i)/6);break;case 3:this._state=4;default:s(this,t,i)}this._x0=this._x1,this._x1=t,this._y0=this._y1,this._y1=i}},x.prototype={lineStart:function(){this._x0=this._x1=this._x2=this._y0=this._y1=this._y2=NaN,this._state=0},lineEnd:function(){switch(this._state){case 1:this._context.closePath();break;case 2:this._context.lineTo(this._x2,this._y2);break;case 3:this._context.bezierCurveTo(this._x1+this._k*(this._x2-this._x0),this._y1+this._k*(this._y2-this._y0),this._x2,this._y2,this._x2,this._y2)}},point:function(t,i){switch(t=+t,i=+i,this._state){case 0:this._state=1,this._context.moveTo(t,i);break;case 1:this._state=2;break;case 2:this._state=3,this._context.bezierCurveTo(this._x1,this._y1,this._x2+this._k*(this._x1-t),this._y2+this._k*(this._y1-i),this._x2,this._y2);break;default:this._context.bezierCurveTo(this._x1+this._k*(this._x2-this._x0),this._y1+this._k*(this._y2-this._y0),this._x2+this._k*(this._x1-t),this._y2+this._k*(this._y1-i),this._x2,this._y2)}this._x0=this._x1,this._x1=this._x2,this._x2=t,this._y0=this._y1,this._y1=this._y2,this._y2=i}},l.prototype={lineStart:function(){this._x0=this._x1=this._x2=this._x3=this._x4=this._x5=this._y0=this._y1=this._y2=this._y3=this._y4=this._y5=NaN,this._state=0},lineEnd:function(){switch(this._state){case 1:this._context.moveTo(this._x3,this._y3),this._context.closePath();break;case 2:this._context.lineTo(this._x3,this._y3),this._context.closePath();break;case 3:this.point(this._x3,this._y3),this.point(this._x4,this._y4),this.point(this._x5,this._y5)}},point:function(t,i){switch(t=+t,i=+i,this._state){case 0:this._state=1,this._x3=t,this._y3=i;break;case 1:this._state=2,this._context.moveTo(this._x4=t,this._y4=i);break;case 2:this._state=3,this._x5=t,this._y5=i;break;default:this._context.bezierCurveTo(this._x1+this._k*(this._x2-this._x0),this._y1+this._k*(this._y2-this._y0),this._x2+this._k*(this._x1-t),this._y2+this._k*(this._y1-i),this._x2,this._y2)}this._x0=this._x1,this._x1=this._x2,this._x2=t,this._y0=this._y1,this._y1=this._y2,this._y2=i}},y.prototype={lineStart:function(){this._x0=this._x1=this._x2=this._y0=this._y1=this._y2=NaN,this._state=0},lineEnd:function(){switch(this._state){case 2:case 3:this._context.closePath()}},point:function(t,i){switch(t=+t,i=+i,this._state){case 0:this._state=1;break;case 1:this._state=2,this._context.moveTo(t,i);break;case 2:this._state=3;break;case 3:this._state=4;default:this._context.bezierCurveTo(this._x1+this._k*(this._x2-this._x0),this._y1+this._k*(this._y2-this._y0),this._x2+this._k*(this._x1-t),this._y2+this._k*(this._y1-i),this._x2,this._y2)}this._x0=this._x1,this._x1=this._x2,this._x2=t,this._y0=this._y1,this._y1=this._y2,this._y2=i}},p.prototype={lineStart:function(){this._x0=this._x1=this._x2=this._y0=this._y1=this._y2=this._l01_a=this._l12_a=this._l23_a=this._l01_2a=this._l12_2a=this._l23_2a=NaN,this._state=0},lineEnd:function(){switch(this._state){case 1:this._context.closePath();break;case 2:this._context.lineTo(this._x2,this._y2);break;case 3:var t=2*this._l01_2a+3*this._l01_a*this._l12_a+this._l12_2a,i=3*this._l01_a*(this._l01_a+this._l12_a);this._context.bezierCurveTo((this._x1*t-this._x0*this._l12_2a+this._x2*this._l01_2a)/i,(this._y1*t-this._y0*this._l12_2a+this._y2*this._l01_2a)/i,this._x2,this._y2,this._x2,this._y2)}},point:function(t,i){if(t=+t,i=+i,this._state){var s=this._x2-t,_=this._y2-i,h=s*s+_*_;this._l23_a=Math.pow(h,this._alpha2),this._l23_2a=Math.pow(h,this._alpha)}switch(this._state){case 0:this._state=1,this._context.moveTo(t,i);break;case 1:this._state=2;break;case 2:var e=2*this._l23_2a+3*this._l23_a*this._l12_a+this._l12_2a,n=3*this._l23_a*(this._l23_a+this._l12_a);this._state=3,this._context.bezierCurveTo(this._x1,this._y1,(this._x2*e+this._x1*this._l23_2a-t*this._l12_2a)/n,(this._y2*e+this._y1*this._l23_2a-i*this._l12_2a)/n,this._x2,this._y2);break;default:var a=2*this._l01_2a+3*this._l01_a*this._l12_a+this._l12_2a,e=2*this._l23_2a+3*this._l23_a*this._l12_a+this._l12_2a,o=3*this._l01_a*(this._l01_a+this._l12_a),n=3*this._l23_a*(this._l23_a+this._l12_a);this._context.bezierCurveTo((this._x1*a-this._x0*this._l12_2a+this._x2*this._l01_2a)/o,(this._y1*a-this._y0*this._l12_2a+this._y2*this._l01_2a)/o,(this._x2*e+this._x1*this._l23_2a-t*this._l12_2a)/n,(this._y2*e+this._y1*this._l23_2a-i*this._l12_2a)/n,this._x2,this._y2)}this._l01_a=this._l12_a,this._l12_a=this._l23_a,this._l01_2a=this._l12_2a,this._l12_2a=this._l23_2a,this._x0=this._x1,this._x1=this._x2,this._x2=t,this._y0=this._y1,this._y1=this._y2,this._y2=i}},b.prototype={lineStart:function(){this._x=[],this._y=[]},lineEnd:function(){var t=this._x,i=this._y,s=t.length;switch(s){case 0:break;case 1:this._context.moveTo(t[0],i[0]),this._context.closePath();break;case 2:this._context.moveTo(t[0],i[0]),this._context.lineTo(t[1],i[1]);break;default:var _=d(t),h=d(i);this._context.moveTo(t[0],i[0]);for(var e=0,s=t.length;s-1>e;++e)this._context.bezierCurveTo(_[0][e],h[0][e],_[1][e],h[1][e],t[e+1],i[e+1])}this._x=this._y=null},point:function(t,i){this._x.push(+t),this._y.push(+i)}},v.prototype={lineStart:function(){this._state=0},lineEnd:function(){1===this._state&&this._context.closePath()},point:function(t,i){switch(t=+t,i=+i,this._state){case 0:this._state=1,this._context.moveTo(t,i);break;case 1:this._state=2;default:this._context.lineTo(t,i)}}},m.prototype={lineStart:function(){this._state=0},lineEnd:function(){this._context.closePath()},point:function(t,i){t=+t,i=+i,this._state?this._context.lineTo(t,i):(this._state=1,this._context.moveTo(t,i))}},E.prototype={lineStart:function(){this._x=this._y=NaN,this._state=0},lineEnd:function(){switch(this._state){case 1:this._context.closePath();break;case 2:this._context.lineTo(this._x,this._y)}},point:function(t,i){switch(t=+t,i=+i,this._state){case 0:this._state=1,this._context.moveTo(t,i);break;case 1:this._state=2;default:var s=(this._x+t)/2;this._context.lineTo(s,this._y),this._context.lineTo(s,i)}this._x=t,this._y=i}},g.prototype={lineStart:function(){this._y=NaN,this._state=0},lineEnd:function(){1===this._state&&this._context.closePath()},point:function(t,i){switch(t=+t,i=+i,this._state){case 0:this._state=1,this._context.moveTo(t,i);break;case 1:this._state=2;default:this._context.lineTo(t,this._y),this._context.lineTo(t,i)}this._y=i}},z.prototype={lineStart:function(){this._x=NaN,this._state=0},lineEnd:function(){1===this._state&&this._context.closePath()},point:function(t,i){switch(t=+t,i=+i,this._state){case 0:this._state=1,this._context.moveTo(t,i);break;case 1:this._state=2;default:this._context.lineTo(this._x,i),this._context.lineTo(t,i)}this._x=t}};var B="0.0.2";t.version=B,t.line=q});
{
"name": "d3-shape",
"version": "0.0.1",
"version": "0.0.2",
"description": "Graphical primitives for visualization, such as lines and areas.",

@@ -30,3 +30,3 @@ "keywords": [

"dependencies": {
"d3-path": "~0.0.1"
"d3-path": "~0.0.2"
},

@@ -33,0 +33,0 @@ "devDependencies": {

@@ -15,2 +15,4 @@ # d3-shape

* The behavior of Cardinal interpolation tension has been fixed. The default tension is now 0 (corresponding to a uniform Catmull–Rom spline), not 0.7; the new value of 0 is equivalent to an old value of 2 / 3, so the default behavior is only slightly changed.
* To specify a Cardinal interpolation tension of *t*, use `line.interpolate("cardinal", t)` instead of `line.interpolate("cardinal").tension(t)`.

@@ -1,2 +0,2 @@

function basisPoint(basis, x, y) {
export function point(basis, x, y) {
basis._context.bezierCurveTo(

@@ -10,81 +10,38 @@ (2 * basis._x0 + basis._x1) / 3,

);
}
export function Basis(context) {
this._context = context;
};
Basis.prototype.lineStart = function() {
this._x0 = this._x1 =
this._y0 = this._y1 = null;
};
function basis(context) {
return new Basis(context);
}
Basis.prototype.lineEnd = function() {
if (this._x0 != null) {
this.point(this._x1, this._y1);
this._context.lineTo(this._x1, this._y1);
}
};
Basis.prototype.point = function(x, y) {
x = +x, y = +y;
if (this._x0 != null) basisPoint(this, x, y);
else if (this._x1 != null) this._context.lineTo((5 * this._x1 + x) / 6, (5 * this._y1 + y) / 6);
else this._context.moveTo(x, y);
this._x0 = this._x1, this._x1 = x;
this._y0 = this._y1, this._y1 = y;
};
export function BasisOpen(context) {
function Basis(context) {
this._context = context;
};
}
BasisOpen.prototype.lineStart = function() {
this._x0 = this._x1 =
this._y0 = this._y1 = null;
this._moved = false;
};
BasisOpen.prototype.lineEnd = function() {};
BasisOpen.prototype.point = function(x, y) {
x = +x, y = +y;
if (this._moved) basisPoint(this, x, y);
else if (this._x0 != null) this._moved = true, this._context.moveTo((this._x0 + 4 * this._x1 + x) / 6, (this._y0 + 4 * this._y1 + y) / 6);
this._x0 = this._x1, this._x1 = x;
this._y0 = this._y1, this._y1 = y;
};
export function BasisClosed(context) {
this._context = context;
};
BasisClosed.prototype.lineStart = function() {
this._x0 = this._x1 = this._x2 = this._x3 = this._x4 =
this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = null;
};
BasisClosed.prototype.lineEnd = function() {
if (this._x4 != null) {
this.point(this._x2, this._y2);
this.point(this._x3, this._y3);
this.point(this._x4, this._y4);
} else if (this._x3 != null) {
this._context.moveTo((this._x2 + 2 * this._x3) / 3, (this._y2 + 2 * this._y3) / 3);
this._context.lineTo((this._x3 + 2 * this._x2) / 3, (this._y3 + 2 * this._y2) / 3);
this._context.closePath();
} else if (this._x2 != null) {
this._context.moveTo(this._x2, this._y2);
this._context.closePath();
Basis.prototype = {
lineStart: function() {
this._x0 = this._x1 =
this._y0 = this._y1 = NaN;
this._state = 0;
},
lineEnd: function() {
switch (this._state) {
case 1: this._context.closePath(); break;
case 3: point(this, this._x1, this._y1); // proceed
case 2: this._context.lineTo(this._x1, this._y1); break;
}
},
point: function(x, y) {
x = +x, y = +y;
switch (this._state) {
case 0: this._state = 1; this._context.moveTo(x, y); break;
case 1: this._state = 2; this._context.lineTo((5 * this._x1 + x) / 6, (5 * this._y1 + y) / 6); break;
case 2: this._state = 3; // proceed
default: point(this, x, y); break;
}
this._x0 = this._x1, this._x1 = x;
this._y0 = this._y1, this._y1 = y;
}
};
BasisClosed.prototype.point = function(x, y) {
x = +x, y = +y;
if (this._x4 != null) basisPoint(this, x, y);
else if (this._x3 != null) this._x4 = x, this._y4 = y, this._context.moveTo((this._x0 + 4 * this._x1 + x) / 6, (this._y0 + 4 * this._y1 + y) / 6);
else if (this._x2 != null) this._x3 = x, this._y3 = y;
else this._x2 = x, this._y2 = y;
this._x0 = this._x1, this._x1 = x;
this._y0 = this._y1, this._y1 = y;
};
export default basis;

@@ -1,114 +0,69 @@

export function Cardinal(context, tension) {
this._context = context;
this._k = (1 - (tension == null ? .7 : tension)) / 2; // TODO
};
function cardinal(tension) {
return function(context) {
return new Cardinal(context, tension);
};
}
Cardinal.prototype.lineStart = function() {
this._x0 = this._x1 = this._x2 =
this._y0 = this._y1 = this._y2 = null;
};
Cardinal.prototype.lineEnd = function() {
if (this._x0 != null) {
this._context.quadraticCurveTo(
this._x1 + this._k * (this._x2 - this._x0) * 2 / 3,
this._y1 + this._k * (this._y2 - this._y0) * 2 / 3,
this._x2,
this._y2
);
} else if (this._x1 != null) {
this._context.lineTo(this._x2, this._y2);
}
};
Cardinal.prototype.point = function(x, y) {
x = +x, y = +y;
if (this._x0 != null) {
this._context.bezierCurveTo(
this._x1 + this._k * (this._x2 - this._x0),
this._y1 + this._k * (this._y2 - this._y0),
this._x2 - this._k * (x - this._x1),
this._y2 - this._k * (y - this._y1),
this._x2,
this._y2
);
} else if (this._x1 != null) {
this._context.quadraticCurveTo(
this._x2 - this._k * (x - this._x1) * 2 / 3,
this._y2 - this._k * (y - this._y1) * 2 / 3,
this._x2,
this._y2
);
} else if (this._x2 == null) {
this._context.moveTo(x, y);
}
this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
};
export function CardinalOpen(context, tension) {
function Cardinal(context, tension) {
this._context = context;
this._k = (1 - (tension == null ? .7 : tension)) / 2; // TODO
};
this._k = (tension == null ? 1 : 1 - tension) / 6;
}
CardinalOpen.prototype.lineStart = function() {
this._x0 = this._x1 = this._x2 =
this._y0 = this._y1 = this._y2 = null;
};
CardinalOpen.prototype.lineEnd = function() {};
CardinalOpen.prototype.point = function(x, y) {
x = +x, y = +y;
if (this._x0 != null) {
this._context.bezierCurveTo(
this._x1 + this._k * (this._x2 - this._x0),
this._y1 + this._k * (this._y2 - this._y0),
this._x2 - this._k * (x - this._x1),
this._y2 - this._k * (y - this._y1),
this._x2,
this._y2
);
} else if (this._x1 == null && this._x2 != null) {
this._context.moveTo(x, y);
Cardinal.prototype = {
lineStart: function() {
this._x0 = this._x1 = this._x2 =
this._y0 = this._y1 = this._y2 = NaN;
this._state = 0;
},
lineEnd: function() {
switch (this._state) {
case 1: this._context.closePath(); break;
case 2: this._context.lineTo(this._x2, this._y2); break;
case 3: {
this._context.bezierCurveTo(
this._x1 + this._k * (this._x2 - this._x0),
this._y1 + this._k * (this._y2 - this._y0),
this._x2,
this._y2,
this._x2,
this._y2
);
break;
}
}
},
point: function(x, y) {
x = +x, y = +y;
switch (this._state) {
case 0: this._state = 1; this._context.moveTo(x, y); break;
case 1: this._state = 2; break;
case 2: {
this._state = 3;
this._context.bezierCurveTo(
this._x1,
this._y1,
this._x2 + this._k * (this._x1 - x),
this._y2 + this._k * (this._y1 - y),
this._x2,
this._y2
);
break;
}
default: {
this._context.bezierCurveTo(
this._x1 + this._k * (this._x2 - this._x0),
this._y1 + this._k * (this._y2 - this._y0),
this._x2 + this._k * (this._x1 - x),
this._y2 + this._k * (this._y1 - y),
this._x2,
this._y2
);
break;
}
}
this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
}
this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
};
// function cardinalTangents(points, tension) {
// var tangents = [],
// a = (1 - tension) / 2,
// p0,
// p1 = points[0],
// p2 = points[1],
// i = 1,
// n = points.length;
// while (++i < n) {
// p0 = p1;
// p1 = p2;
// p2 = points[i];
// tangents.push([a * (p2[0] - p0[0]), a * (p2[1] - p0[1])]);
// }
// return tangents;
// }
// export function interpolateCardinalOpen(points, tension) {
// return points.length < 4
// ? interpolateLinear(points)
// : points[1] + interpolateHermit(points.slice(1, -1), cardinalTangents(points, tension));
// };
// export function interpolateCardinalClosed(points, tension) {
// return points.length < 3
// ? interpolateLinear(points)
// : points[0] + interpolateHermit((points.push(points[0]), points), cardinalTangents([points[points.length - 2]].concat(points, [points[1]]), tension));
// };
// export function interpolateCardinal(points, tension) {
// return points.length < 3
// ? interpolateLinear(points)
// : points[0] + interpolateHermit(points, cardinalTangents(points, tension));
// };
export default cardinal;

@@ -1,24 +0,26 @@

export function Linear(context) {
function linear(context) {
return new Linear(context);
}
function Linear(context) {
this._context = context;
};
}
Linear.prototype.lineStart = function() {
this._move = true;
Linear.prototype = {
lineStart: function() {
this._state = 0;
},
lineEnd: function() {
if (this._state === 1) this._context.closePath();
},
point: function(x, y) {
x = +x, y = +y;
switch (this._state) {
case 0: this._state = 1; this._context.moveTo(x, y); break;
case 1: this._state = 2; // proceed
default: this._context.lineTo(x, y); break;
}
}
};
Linear.prototype.lineEnd = function() {};
Linear.prototype.point = function(x, y) {
if (this._move) this._move = false, this._context.moveTo(x, y);
else this._context.lineTo(x, y);
};
export function LinearClosed(context) {
Linear.call(this, context); // https://github.com/rollup/rollup/issues/34
};
LinearClosed.prototype = Object.create(Linear.prototype);
LinearClosed.prototype.lineEnd = function() {
this._context.closePath();
};
export default linear;

@@ -1,68 +0,36 @@

export function Step(context) {
this._context = context;
};
function step(context) {
return new Step(context);
}
Step.prototype.lineStart = function() {
this._x = this._y = null;
};
Step.prototype.lineEnd = function() {
if (this._x != null) {
this._context.lineTo(this._x, this._y);
this._x = this._y = null;
}
};
Step.prototype.point = function(x, y) {
x = +x, y = +y;
if (this._x == null) {
this._context.moveTo(x, y);
} else {
var x1 = (this._x + x) / 2;
this._context.lineTo(x1, this._y);
this._context.lineTo(x1, y);
}
this._x = x, this._y = y;
};
export function StepAfter(context) {
function Step(context) {
this._context = context;
};
}
StepAfter.prototype.lineStart = function() {
this._y = null;
};
StepAfter.prototype.lineEnd = function() {};
StepAfter.prototype.point = function(x, y) {
x = +x, y = +y;
if (this._y == null) {
this._context.moveTo(x, y);
} else {
this._context.lineTo(x, this._y);
this._context.lineTo(x, y);
Step.prototype = {
lineStart: function() {
this._x = this._y = NaN;
this._state = 0;
},
lineEnd: function() {
switch (this._state) {
case 1: this._context.closePath(); break;
case 2: this._context.lineTo(this._x, this._y); break;
}
},
point: function(x, y) {
x = +x, y = +y;
switch (this._state) {
case 0: this._state = 1; this._context.moveTo(x, y); break;
case 1: this._state = 2; // proceed
default: {
var x1 = (this._x + x) / 2;
this._context.lineTo(x1, this._y);
this._context.lineTo(x1, y);
break;
}
}
this._x = x, this._y = y;
}
this._y = y;
};
export function StepBefore(context) {
this._context = context;
};
StepBefore.prototype.lineStart = function() {
this._x = null;
};
StepBefore.prototype.lineEnd = function() {};
StepBefore.prototype.point = function(x, y) {
x = +x, y = +y;
if (this._x == null) {
this._context.moveTo(x, y);
} else {
this._context.lineTo(this._x, y);
this._context.lineTo(x, y);
}
this._x = x;
};
export default step;

@@ -1,5 +0,14 @@

import {Basis, BasisOpen, BasisClosed} from "./interpolate/basis";
import {Cardinal, CardinalOpen} from "./interpolate/cardinal";
import {Linear, LinearClosed} from "./interpolate/linear";
import {Step, StepBefore, StepAfter} from "./interpolate/step";
import basis from "./interpolate/basis";
import basisClosed from "./interpolate/basis-closed";
import basisOpen from "./interpolate/basis-open";
import cardinal from "./interpolate/cardinal";
import cardinalClosed from "./interpolate/cardinal-closed";
import cardinalOpen from "./interpolate/cardinal-open";
import catmullRom from "./interpolate/catmull-rom";
import cubic from "./interpolate/cubic";
import linear from "./interpolate/linear";
import linearClosed from "./interpolate/linear-closed";
import step from "./interpolate/step";
import stepAfter from "./interpolate/step-after";
import stepBefore from "./interpolate/step-before";
import {path} from "d3-path";

@@ -15,3 +24,3 @@

function functor(x) {
function constant(x) {
return function() {

@@ -26,17 +35,2 @@ return x;

var interpolates = (new Map)
.set("linear", Linear)
.set("linear-closed", LinearClosed)
.set("step", Step)
.set("step-before", StepBefore)
.set("step-after", StepAfter)
.set("basis", Basis)
.set("basis-open", BasisOpen)
.set("basis-closed", BasisClosed)
// .set("bundle", Bundle)
.set("cardinal", Cardinal)
.set("cardinal-open", CardinalOpen)
// .set("cardinal-closed", CardinalClosed)
// .set("monotone", Monotone);
export default function() {

@@ -46,3 +40,3 @@ var x = pointX, _x = x,

defined = true, _defined = _true,
interpolate = Linear,
interpolate = linear,
context = null,

@@ -53,16 +47,16 @@ stream = null;

var defined = false,
result;
buffer;
if (!stream) stream = new interpolate(result = path()); // TODO tension?
if (!context) stream = interpolate(buffer = path());
for (var i = 0, n = data.length, d; i < n; ++i) {
if (!_defined.call(this, d = data[i], i) === defined) {
if (!_defined(d = data[i], i) === defined) {
if (defined = !defined) stream.lineStart();
else stream.lineEnd();
}
if (defined) stream.point(+_x.call(this, d, i), +_y.call(this, d, i));
if (defined) stream.point(+_x(d, i), +_y(d, i));
}
if (defined) stream.lineEnd();
if (result) return stream = null, result += "";
if (!context) return stream = null, buffer + "" || null;
}

@@ -72,3 +66,3 @@

if (!arguments.length) return x;
x = _, _x = typeof _ === "function" ? x : functor(x);
x = _, _x = typeof _ === "function" ? x : constant(x);
return line;

@@ -79,3 +73,3 @@ };

if (!arguments.length) return y;
y = _, _y = typeof _ === "function" ? y : functor(y);
y = _, _y = typeof _ === "function" ? y : constant(y);
return line;

@@ -86,10 +80,25 @@ };

if (!arguments.length) return defined;
defined = _, _defined = typeof _ === "function" ? defined : functor(defined);
defined = _, _defined = typeof _ === "function" ? defined : constant(defined);
return line;
};
line.interpolate = function(_, tension) {
line.interpolate = function(_, a) {
if (!arguments.length) return interpolate;
if (!(interpolate = interpolates.get(_ + ""))) interpolate = Linear;
if (context != null) stream = new interpolate(context); // TODO tension?
if (typeof _ === "function") interpolate = _;
else switch (_ + "") {
case "linear-closed": interpolate = linearClosed; break;
case "step": interpolate = step; break;
case "step-before": interpolate = stepBefore; break;
case "step-after": interpolate = stepAfter; break;
case "basis": interpolate = basis; break;
case "basis-open": interpolate = basisOpen; break;
case "basis-closed": interpolate = basisClosed; break;
case "cardinal": interpolate = cardinal(a); break;
case "cardinal-open": interpolate = cardinalOpen(a); break;
case "cardinal-closed": interpolate = cardinalClosed(a); break;
case "catmull-rom": interpolate = catmullRom(a); break;
case "cubic": interpolate = cubic; break;
default: interpolate = linear; break;
}
if (context != null) stream = interpolate(context);
return line;

@@ -101,3 +110,3 @@ };

if (_ == null) context = stream = null;
else stream = new interpolate(context = _); // TODO tension?
else stream = interpolate(context = _);
return line;

@@ -104,0 +113,0 @@ };

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc