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

d3-interpolate

Package Overview
Dependencies
Maintainers
1
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

d3-interpolate - npm Package Compare versions

Comparing version 0.1.4 to 0.2.0

src/array.js

2

build/bundle.js

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

var version = "0.1.4"; export * from "../index"; export {version};
var version = "0.2.0"; export * from "../index"; export {version};

@@ -7,22 +7,65 @@ (function (global, factory) {

// TODO sparse arrays?
function interpolateArray(a, b) {
var x = [],
c = [],
na = a.length,
nb = b.length,
n0 = Math.min(a.length, b.length),
i;
function deltaHue(h1, h0) {
var delta = h1 - h0;
return delta > 180 || delta < -180
? delta - 360 * Math.round(delta / 360)
: delta;
};
for (i = 0; i < n0; ++i) x.push(interpolate(a[i], b[i]));
for (; i < na; ++i) c[i] = a[i];
for (; i < nb; ++i) c[i] = b[i];
function cubehelixGamma(gamma) {
return function(a, b) {
a = d3Color.cubehelix(a);
b = d3Color.cubehelix(b);
var ah = isNaN(a.h) ? b.h : a.h,
as = isNaN(a.s) ? b.s : a.s,
al = a.l,
bh = isNaN(b.h) ? 0 : deltaHue(b.h, ah),
bs = isNaN(b.s) ? 0 : b.s - as,
bl = b.l - al;
return function(t) {
a.h = ah + bh * t;
a.s = as + bs * t;
a.l = al + bl * Math.pow(t, gamma);
return a + "";
};
};
};
function cubehelixGammaLong(gamma) {
return function(a, b) {
a = d3Color.cubehelix(a);
b = d3Color.cubehelix(b);
var ah = isNaN(a.h) ? b.h : a.h,
as = isNaN(a.s) ? b.s : a.s,
al = a.l,
bh = isNaN(b.h) ? 0 : b.h - ah,
bs = isNaN(b.s) ? 0 : b.s - as,
bl = b.l - al;
return function(t) {
a.h = ah + bh * t;
a.s = as + bs * t;
a.l = al + bl * Math.pow(t, gamma);
return a + "";
};
};
};
function rgb(a, b) {
a = d3Color.rgb(a);
b = d3Color.rgb(b);
var ar = a.r,
ag = a.g,
ab = a.b,
br = b.r - ar,
bg = b.g - ag,
bb = b.b - ab;
return function(t) {
for (i = 0; i < n0; ++i) c[i] = x[i](t);
return c;
a.r = ar + br * t;
a.g = ag + bg * t;
a.b = ab + bb * t;
return a + "";
};
};
function interpolateNumber(a, b) {
function number(a, b) {
return a = +a, b -= a, function(t) {

@@ -33,3 +76,3 @@ return a + b * t;

function interpolateObject(a, b) {
function object(a, b) {
var i = {},

@@ -41,3 +84,3 @@ c = {},

if (k in b) {
i[k] = interpolate(a[k], b[k]);
i[k] = value(a[k], b[k]);
} else {

@@ -62,3 +105,3 @@ c[k] = a[k];

var reB = new RegExp(reA.source, "g");
function interpolate0(b) {
function zero(b) {
return function() {

@@ -69,3 +112,3 @@ return b;

function interpolate1(b) {
function one(b) {
return function(t) {

@@ -76,3 +119,3 @@ return b(t) + "";

function interpolateString(a, b) {
function string(a, b) {
var bi = reA.lastIndex = reB.lastIndex = 0, // scan index for next number in b

@@ -102,3 +145,3 @@ am, // current match in a

s[++i] = null;
q.push({i: i, x: interpolateNumber(am, bm)});
q.push({i: i, x: number(am, bm)});
}

@@ -118,4 +161,4 @@ bi = reB.lastIndex;

return s.length < 2 ? (q[0]
? interpolate1(q[0].x)
: interpolate0(b))
? one(q[0].x)
: zero(b))
: (b = q.length, function(t) {

@@ -127,20 +170,39 @@ for (var i = 0, o; i < b; ++i) s[(o = q[i]).i] = o.x(t);

var interpolators = [
var values = [
function(a, b) {
var t = typeof b, c;
return (t === "string" ? ((c = d3Color.color(b)) ? (b = c, d3Color.interpolateRgb) : interpolateString)
: b instanceof d3Color.color ? d3Color.interpolateRgb
: Array.isArray(b) ? interpolateArray
: t === "object" && isNaN(b) ? interpolateObject
: interpolateNumber)(a, b);
return (t === "string" ? ((c = d3Color.color(b)) ? (b = c, rgb) : string)
: b instanceof d3Color.color ? rgb
: Array.isArray(b) ? array
: t === "object" && isNaN(b) ? object
: number)(a, b);
}
];
function interpolate(a, b) {
var i = interpolators.length, f;
while (--i >= 0 && !(f = interpolators[i](a, b)));
function value(a, b) {
var i = values.length, f;
while (--i >= 0 && !(f = values[i](a, b)));
return f;
};
function interpolateRound(a, b) {
// TODO sparse arrays?
function array(a, b) {
var x = [],
c = [],
na = a.length,
nb = b.length,
n0 = Math.min(a.length, b.length),
i;
for (i = 0; i < n0; ++i) x.push(value(a[i], b[i]));
for (; i < na; ++i) c[i] = a[i];
for (; i < nb; ++i) c[i] = b[i];
return function(t) {
for (i = 0; i < n0; ++i) c[i] = x[i](t);
return c;
};
};
function round(a, b) {
return a = +a, b -= a, function(t) {

@@ -203,6 +265,6 @@ return Math.round(a + b * t);

function interpolateTranslate(ta, tb, s, q) {
function translate(ta, tb, s, q) {
if (ta[0] !== tb[0] || ta[1] !== tb[1]) {
var i = s.push("translate(", null, ",", null, ")");
q.push({i: i - 4, x: interpolateNumber(ta[0], tb[0])}, {i: i - 2, x: interpolateNumber(ta[1], tb[1])});
q.push({i: i - 4, x: number(ta[0], tb[0])}, {i: i - 2, x: number(ta[1], tb[1])});
} else if (tb[0] || tb[1]) {

@@ -213,6 +275,6 @@ s.push("translate(" + tb + ")");

function interpolateRotate(ra, rb, s, q) {
function rotate(ra, rb, s, q) {
if (ra !== rb) {
if (ra - rb > 180) rb += 360; else if (rb - ra > 180) ra += 360; // shortest path
q.push({i: s.push(pop(s) + "rotate(", null, ")") - 2, x: interpolateNumber(ra, rb)});
q.push({i: s.push(pop(s) + "rotate(", null, ")") - 2, x: number(ra, rb)});
} else if (rb) {

@@ -223,5 +285,5 @@ s.push(pop(s) + "rotate(" + rb + ")");

function interpolateSkew(wa, wb, s, q) {
function skew(wa, wb, s, q) {
if (wa !== wb) {
q.push({i: s.push(pop(s) + "skewX(", null, ")") - 2, x: interpolateNumber(wa, wb)});
q.push({i: s.push(pop(s) + "skewX(", null, ")") - 2, x: number(wa, wb)});
} else if (wb) {

@@ -232,6 +294,6 @@ s.push(pop(s) + "skewX(" + wb + ")");

function interpolateScale(ka, kb, s, q) {
function scale(ka, kb, s, q) {
if (ka[0] !== kb[0] || ka[1] !== kb[1]) {
var i = s.push(pop(s) + "scale(", null, ",", null, ")");
q.push({i: i - 4, x: interpolateNumber(ka[0], kb[0])}, {i: i - 2, x: interpolateNumber(ka[1], kb[1])});
q.push({i: i - 4, x: number(ka[0], kb[0])}, {i: i - 2, x: number(ka[1], kb[1])});
} else if (kb[0] !== 1 || kb[1] !== 1) {

@@ -242,10 +304,10 @@ s.push(pop(s) + "scale(" + kb + ")");

function interpolateTransform(a, b) {
function transform(a, b) {
var s = [], // string constants and placeholders
q = []; // number interpolators
a = new Transform(a), b = new Transform(b);
interpolateTranslate(a.translate, b.translate, s, q);
interpolateRotate(a.rotate, b.rotate, s, q);
interpolateSkew(a.skew, b.skew, s, q);
interpolateScale(a.scale, b.scale, s, q);
translate(a.translate, b.translate, s, q);
rotate(a.rotate, b.rotate, s, q);
skew(a.skew, b.skew, s, q);
scale(a.scale, b.scale, s, q);
a = b = null; // gc

@@ -277,3 +339,3 @@ return function(t) {

// p1 = [ux1, uy1, w1]
function interpolateZoom(p0, p1) {
function zoom(p0, p1) {
var ux0 = p0[0], uy0 = p0[1], w0 = p0[2],

@@ -324,15 +386,113 @@ ux1 = p1[0], uy1 = p1[1], w1 = p1[2],

var version = "0.1.4";
function hsl(a, b) {
a = d3Color.hsl(a);
b = d3Color.hsl(b);
var ah = isNaN(a.h) ? b.h : a.h,
as = isNaN(a.s) ? b.s : a.s,
al = a.l,
bh = isNaN(b.h) ? 0 : deltaHue(b.h, ah),
bs = isNaN(b.s) ? 0 : b.s - as,
bl = b.l - al;
return function(t) {
a.h = ah + bh * t;
a.s = as + bs * t;
a.l = al + bl * t;
return a + "";
};
};
function hslLong(a, b) {
a = d3Color.hsl(a);
b = d3Color.hsl(b);
var ah = isNaN(a.h) ? b.h : a.h,
as = isNaN(a.s) ? b.s : a.s,
al = a.l,
bh = isNaN(b.h) ? 0 : b.h - ah,
bs = isNaN(b.s) ? 0 : b.s - as,
bl = b.l - al;
return function(t) {
a.h = ah + bh * t;
a.s = as + bs * t;
a.l = al + bl * t;
return a + "";
};
};
function lab(a, b) {
a = d3Color.lab(a);
b = d3Color.lab(b);
var al = a.l,
aa = a.a,
ab = a.b,
bl = b.l - al,
ba = b.a - aa,
bb = b.b - ab;
return function(t) {
a.l = al + bl * t;
a.a = aa + ba * t;
a.b = ab + bb * t;
return a + "";
};
};
function hcl(a, b) {
a = d3Color.hcl(a);
b = d3Color.hcl(b);
var ah = isNaN(a.h) ? b.h : a.h,
ac = isNaN(a.c) ? b.c : a.c,
al = a.l,
bh = isNaN(b.h) ? 0 : deltaHue(b.h, ah),
bc = isNaN(b.c) ? 0 : b.c - ac,
bl = b.l - al;
return function(t) {
a.h = ah + bh * t;
a.c = ac + bc * t;
a.l = al + bl * t;
return a + "";
};
};
function hclLong(a, b) {
a = d3Color.hcl(a);
b = d3Color.hcl(b);
var ah = isNaN(a.h) ? b.h : a.h,
ac = isNaN(a.c) ? b.c : a.c,
al = a.l,
bh = isNaN(b.h) ? 0 : b.h - ah,
bc = isNaN(b.c) ? 0 : b.c - ac,
bl = b.l - al;
return function(t) {
a.h = ah + bh * t;
a.c = ac + bc * t;
a.l = al + bl * t;
return a + "";
};
};
var cubehelix = cubehelixGamma(1);
var cubehelixLong = cubehelixGammaLong(1);
var version = "0.2.0";
exports.version = version;
exports.interpolate = interpolate;
exports.interpolateArray = interpolateArray;
exports.interpolateNumber = interpolateNumber;
exports.interpolateObject = interpolateObject;
exports.interpolateRound = interpolateRound;
exports.interpolateString = interpolateString;
exports.interpolateTransform = interpolateTransform;
exports.interpolateZoom = interpolateZoom;
exports.interpolators = interpolators;
exports.cubehelix = cubehelix;
exports.cubehelixLong = cubehelixLong;
exports.cubehelixGamma = cubehelixGamma;
exports.cubehelixGammaLong = cubehelixGammaLong;
exports.array = array;
exports.number = number;
exports.object = object;
exports.round = round;
exports.string = string;
exports.transform = transform;
exports.values = values;
exports.value = value;
exports.zoom = zoom;
exports.rgb = rgb;
exports.hsl = hsl;
exports.hslLong = hslLong;
exports.lab = lab;
exports.hcl = hcl;
exports.hclLong = hclLong;
}));

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

!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("d3-color")):"function"==typeof define&&define.amd?define("d3-interpolate",["exports","d3-color"],n):n(t.d3_interpolate={},t.d3_color)}(this,function(t,n){"use strict";function e(t,n){var e,r=[],o=[],u=t.length,a=n.length,i=Math.min(t.length,n.length);for(e=0;i>e;++e)r.push(l(t[e],n[e]));for(;u>e;++e)o[e]=t[e];for(;a>e;++e)o[e]=n[e];return function(t){for(e=0;i>e;++e)o[e]=r[e](t);return o}}function r(t,n){return t=+t,n-=t,function(e){return t+n*e}}function o(t,n){var e,r={},o={};for(e in t)e in n?r[e]=l(t[e],n[e]):o[e]=t[e];for(e in n)e in t||(o[e]=n[e]);return function(t){for(e in r)o[e]=r[e](t);return o}}function u(t){return function(){return t}}function a(t){return function(n){return t(n)+""}}function i(t,n){var e,o,i,l=q.lastIndex=R.lastIndex=0,s=-1,f=[],c=[];for(t+="",n+="";(e=q.exec(t))&&(o=R.exec(n));)(i=o.index)>l&&(i=n.slice(l,i),f[s]?f[s]+=i:f[++s]=i),(e=e[0])===(o=o[0])?f[s]?f[s]+=o:f[++s]=o:(f[++s]=null,c.push({i:s,x:r(e,o)})),l=R.lastIndex;return l<n.length&&(i=n.slice(l),f[s]?f[s]+=i:f[++s]=i),f.length<2?c[0]?a(c[0].x):u(n):(n=c.length,function(t){for(var e,r=0;n>r;++r)f[(e=c[r]).i]=e.x(t);return f.join("")})}function l(t,n){for(var e,r=A.length;--r>=0&&!(e=A[r](t,n)););return e}function s(t,n){return t=+t,n-=t,function(e){return Math.round(t+n*e)}}function f(t){k||(k=document.createElementNS("http://www.w3.org/2000/svg","g")),t&&(k.setAttribute("transform",t),n=k.transform.baseVal.consolidate());var n,e=n?n.matrix:N,r=[e.a,e.b],o=[e.c,e.d],u=h(r),a=c(r,o),i=h(p(o,r,-a))||0;r[0]*o[1]<o[0]*r[1]&&(r[0]*=-1,r[1]*=-1,u*=-1,a*=-1),this.rotate=(u?Math.atan2(r[1],r[0]):Math.atan2(-o[0],o[1]))*I,this.translate=[e.e,e.f],this.scale=[u,i],this.skew=i?Math.atan2(a,i)*I:0}function c(t,n){return t[0]*n[0]+t[1]*n[1]}function h(t){var n=Math.sqrt(c(t,t));return n&&(t[0]/=n,t[1]/=n),n}function p(t,n,e){return t[0]+=e*n[0],t[1]+=e*n[1],t}function d(t){return t.length?t.pop()+",":""}function x(t,n,e,o){if(t[0]!==n[0]||t[1]!==n[1]){var u=e.push("translate(",null,",",null,")");o.push({i:u-4,x:r(t[0],n[0])},{i:u-2,x:r(t[1],n[1])})}else(n[0]||n[1])&&e.push("translate("+n+")")}function g(t,n,e,o){t!==n?(t-n>180?n+=360:n-t>180&&(t+=360),o.push({i:e.push(d(e)+"rotate(",null,")")-2,x:r(t,n)})):n&&e.push(d(e)+"rotate("+n+")")}function v(t,n,e,o){t!==n?o.push({i:e.push(d(e)+"skewX(",null,")")-2,x:r(t,n)}):n&&e.push(d(e)+"skewX("+n+")")}function M(t,n,e,o){if(t[0]!==n[0]||t[1]!==n[1]){var u=e.push(d(e)+"scale(",null,",",null,")");o.push({i:u-4,x:r(t[0],n[0])},{i:u-2,x:r(t[1],n[1])})}else(1!==n[0]||1!==n[1])&&e.push(d(e)+"scale("+n+")")}function w(t,n){var e=[],r=[];return t=new f(t),n=new f(n),x(t.translate,n.translate,e,r),g(t.rotate,n.rotate,e,r),v(t.skew,n.skew,e,r),M(t.scale,n.scale,e,r),t=n=null,function(t){for(var n,o=-1,u=r.length;++o<u;)e[(n=r[o]).i]=n.x(t);return e.join("")}}function m(t){return((t=Math.exp(t))+1/t)/2}function b(t){return((t=Math.exp(t))-1/t)/2}function y(t){return((t=Math.exp(2*t))-1)/(t+1)}function j(t,n){var e,r,o=t[0],u=t[1],a=t[2],i=n[0],l=n[1],s=n[2],f=i-o,c=l-u,h=f*f+c*c;if(X>h)r=Math.log(s/a)/E,e=function(t){return[o+t*f,u+t*c,a*Math.exp(E*t*r)]};else{var p=Math.sqrt(h),d=(s*s-a*a+T*h)/(2*a*S*p),x=(s*s-a*a-T*h)/(2*s*S*p),g=Math.log(Math.sqrt(d*d+1)-d),v=Math.log(Math.sqrt(x*x+1)-x);r=(v-g)/E,e=function(t){var n=t*r,e=m(g),i=a/(S*p)*(e*y(E*n+g)-b(g));return[o+i*f,u+i*c,a*e/m(E*n+g)]}}return e.duration=1e3*r,e}var k,q=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,R=new RegExp(q.source,"g"),A=[function(t,u){var a,l=typeof u;return("string"===l?(a=n.color(u))?(u=a,n.interpolateRgb):i:u instanceof n.color?n.interpolateRgb:Array.isArray(u)?e:"object"===l&&isNaN(u)?o:r)(t,u)}],I=180/Math.PI,N={a:1,b:0,c:0,d:1,e:0,f:0},E=Math.SQRT2,S=2,T=4,X=1e-12,_="0.1.4";t.version=_,t.interpolate=l,t.interpolateArray=e,t.interpolateNumber=r,t.interpolateObject=o,t.interpolateRound=s,t.interpolateString=i,t.interpolateTransform=w,t.interpolateZoom=j,t.interpolators=A});
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("d3-color")):"function"==typeof define&&define.amd?define("d3-interpolate",["exports","d3-color"],t):t(n.d3_interpolate={},n.d3_color)}(this,function(n,t){"use strict";function r(n,t){var r=n-t;return r>180||-180>r?r-360*Math.round(r/360):r}function e(n){return function(e,u){e=t.cubehelix(e),u=t.cubehelix(u);var i=isNaN(e.h)?u.h:e.h,a=isNaN(e.s)?u.s:e.s,o=e.l,s=isNaN(u.h)?0:r(u.h,i),h=isNaN(u.s)?0:u.s-a,c=u.l-o;return function(t){return e.h=i+s*t,e.s=a+h*t,e.l=o+c*Math.pow(t,n),e+""}}}function u(n){return function(r,e){r=t.cubehelix(r),e=t.cubehelix(e);var u=isNaN(r.h)?e.h:r.h,i=isNaN(r.s)?e.s:r.s,a=r.l,o=isNaN(e.h)?0:e.h-u,s=isNaN(e.s)?0:e.s-i,h=e.l-a;return function(t){return r.h=u+o*t,r.s=i+s*t,r.l=a+h*Math.pow(t,n),r+""}}}function i(n,r){n=t.rgb(n),r=t.rgb(r);var e=n.r,u=n.g,i=n.b,a=r.r-e,o=r.g-u,s=r.b-i;return function(t){return n.r=e+a*t,n.g=u+o*t,n.b=i+s*t,n+""}}function a(n,t){return n=+n,t-=n,function(r){return n+t*r}}function o(n,t){var r,e={},u={};for(r in n)r in t?e[r]=l(n[r],t[r]):u[r]=n[r];for(r in t)r in n||(u[r]=t[r]);return function(n){for(r in e)u[r]=e[r](n);return u}}function s(n){return function(){return n}}function h(n){return function(t){return n(t)+""}}function c(n,t){var r,e,u,i=X.lastIndex=_.lastIndex=0,o=-1,c=[],l=[];for(n+="",t+="";(r=X.exec(n))&&(e=_.exec(t));)(u=e.index)>i&&(u=t.slice(i,u),c[o]?c[o]+=u:c[++o]=u),(r=r[0])===(e=e[0])?c[o]?c[o]+=e:c[++o]=e:(c[++o]=null,l.push({i:o,x:a(r,e)})),i=_.lastIndex;return i<t.length&&(u=t.slice(i),c[o]?c[o]+=u:c[++o]=u),c.length<2?l[0]?h(l[0].x):s(t):(t=l.length,function(n){for(var r,e=0;t>e;++e)c[(r=l[e]).i]=r.x(n);return c.join("")})}function l(n,t){for(var r,e=z.length;--e>=0&&!(r=z[e](n,t)););return r}function f(n,t){var r,e=[],u=[],i=n.length,a=t.length,o=Math.min(n.length,t.length);for(r=0;o>r;++r)e.push(l(n[r],t[r]));for(;i>r;++r)u[r]=n[r];for(;a>r;++r)u[r]=t[r];return function(n){for(r=0;o>r;++r)u[r]=e[r](n);return u}}function N(n,t){return n=+n,t-=n,function(r){return Math.round(n+t*r)}}function p(n){S||(S=document.createElementNS("http://www.w3.org/2000/svg","g")),n&&(S.setAttribute("transform",n),t=S.transform.baseVal.consolidate());var t,r=t?t.matrix:Q,e=[r.a,r.b],u=[r.c,r.d],i=g(e),a=x(e,u),o=g(v(u,e,-a))||0;e[0]*u[1]<u[0]*e[1]&&(e[0]*=-1,e[1]*=-1,i*=-1,a*=-1),this.rotate=(i?Math.atan2(e[1],e[0]):Math.atan2(-u[0],u[1]))*P,this.translate=[r.e,r.f],this.scale=[i,o],this.skew=o?Math.atan2(a,o)*P:0}function x(n,t){return n[0]*t[0]+n[1]*t[1]}function g(n){var t=Math.sqrt(x(n,n));return t&&(n[0]/=t,n[1]/=t),t}function v(n,t,r){return n[0]+=r*t[0],n[1]+=r*t[1],n}function b(n){return n.length?n.pop()+",":""}function d(n,t,r,e){if(n[0]!==t[0]||n[1]!==t[1]){var u=r.push("translate(",null,",",null,")");e.push({i:u-4,x:a(n[0],t[0])},{i:u-2,x:a(n[1],t[1])})}else(t[0]||t[1])&&r.push("translate("+t+")")}function M(n,t,r,e){n!==t?(n-t>180?t+=360:t-n>180&&(n+=360),e.push({i:r.push(b(r)+"rotate(",null,")")-2,x:a(n,t)})):t&&r.push(b(r)+"rotate("+t+")")}function m(n,t,r,e){n!==t?e.push({i:r.push(b(r)+"skewX(",null,")")-2,x:a(n,t)}):t&&r.push(b(r)+"skewX("+t+")")}function w(n,t,r,e){if(n[0]!==t[0]||n[1]!==t[1]){var u=r.push(b(r)+"scale(",null,",",null,")");e.push({i:u-4,x:a(n[0],t[0])},{i:u-2,x:a(n[1],t[1])})}else(1!==t[0]||1!==t[1])&&r.push(b(r)+"scale("+t+")")}function y(n,t){var r=[],e=[];return n=new p(n),t=new p(t),d(n.translate,t.translate,r,e),M(n.rotate,t.rotate,r,e),m(n.skew,t.skew,r,e),w(n.scale,t.scale,r,e),n=t=null,function(n){for(var t,u=-1,i=e.length;++u<i;)r[(t=e[u]).i]=t.x(n);return r.join("")}}function j(n){return((n=Math.exp(n))+1/n)/2}function k(n){return((n=Math.exp(n))-1/n)/2}function q(n){return((n=Math.exp(2*n))-1)/(n+1)}function I(n,t){var r,e,u=n[0],i=n[1],a=n[2],o=t[0],s=t[1],h=t[2],c=o-u,l=s-i,f=c*c+l*l;if(C>f)e=Math.log(h/a)/T,r=function(n){return[u+n*c,i+n*l,a*Math.exp(T*n*e)]};else{var N=Math.sqrt(f),p=(h*h-a*a+B*f)/(2*a*V*N),x=(h*h-a*a-B*f)/(2*h*V*N),g=Math.log(Math.sqrt(p*p+1)-p),v=Math.log(Math.sqrt(x*x+1)-x);e=(v-g)/T,r=function(n){var t=n*e,r=j(g),o=a/(V*N)*(r*q(T*t+g)-k(g));return[u+o*c,i+o*l,a*r/j(T*t+g)]}}return r.duration=1e3*e,r}function L(n,e){n=t.hsl(n),e=t.hsl(e);var u=isNaN(n.h)?e.h:n.h,i=isNaN(n.s)?e.s:n.s,a=n.l,o=isNaN(e.h)?0:r(e.h,u),s=isNaN(e.s)?0:e.s-i,h=e.l-a;return function(t){return n.h=u+o*t,n.s=i+s*t,n.l=a+h*t,n+""}}function A(n,r){n=t.hsl(n),r=t.hsl(r);var e=isNaN(n.h)?r.h:n.h,u=isNaN(n.s)?r.s:n.s,i=n.l,a=isNaN(r.h)?0:r.h-e,o=isNaN(r.s)?0:r.s-u,s=r.l-i;return function(t){return n.h=e+a*t,n.s=u+o*t,n.l=i+s*t,n+""}}function E(n,r){n=t.lab(n),r=t.lab(r);var e=n.l,u=n.a,i=n.b,a=r.l-e,o=r.a-u,s=r.b-i;return function(t){return n.l=e+a*t,n.a=u+o*t,n.b=i+s*t,n+""}}function G(n,e){n=t.hcl(n),e=t.hcl(e);var u=isNaN(n.h)?e.h:n.h,i=isNaN(n.c)?e.c:n.c,a=n.l,o=isNaN(e.h)?0:r(e.h,u),s=isNaN(e.c)?0:e.c-i,h=e.l-a;return function(t){return n.h=u+o*t,n.c=i+s*t,n.l=a+h*t,n+""}}function R(n,r){n=t.hcl(n),r=t.hcl(r);var e=isNaN(n.h)?r.h:n.h,u=isNaN(n.c)?r.c:n.c,i=n.l,a=isNaN(r.h)?0:r.h-e,o=isNaN(r.c)?0:r.c-u,s=r.l-i;return function(t){return n.h=e+a*t,n.c=u+o*t,n.l=i+s*t,n+""}}var S,X=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,_=new RegExp(X.source,"g"),z=[function(n,r){var e,u=typeof r;return("string"===u?(e=t.color(r))?(r=e,i):c:r instanceof t.color?i:Array.isArray(r)?f:"object"===u&&isNaN(r)?o:a)(n,r)}],P=180/Math.PI,Q={a:1,b:0,c:0,d:1,e:0,f:0},T=Math.SQRT2,V=2,B=4,C=1e-12,D=e(1),F=u(1),H="0.2.0";n.version=H,n.cubehelix=D,n.cubehelixLong=F,n.cubehelixGamma=e,n.cubehelixGammaLong=u,n.array=f,n.number=a,n.object=o,n.round=N,n.string=c,n.transform=y,n.values=z,n.value=l,n.zoom=I,n.rgb=i,n.hsl=L,n.hslLong=A,n.lab=E,n.hcl=G,n.hclLong=R});

@@ -1,9 +0,21 @@

export {default as interpolate} from "./src/interpolate";
export {default as interpolateArray} from "./src/interpolateArray";
export {default as interpolateNumber} from "./src/interpolateNumber";
export {default as interpolateObject} from "./src/interpolateObject";
export {default as interpolateRound} from "./src/interpolateRound";
export {default as interpolateString} from "./src/interpolateString";
export {default as interpolateTransform} from "./src/interpolateTransform";
export {default as interpolateZoom} from "./src/interpolateZoom";
export {default as interpolators} from "./src/interpolators";
export {default as array} from "./src/array";
export {default as number} from "./src/number";
export {default as object} from "./src/object";
export {default as round} from "./src/round";
export {default as string} from "./src/string";
export {default as transform} from "./src/transform";
export {default as values} from "./src/values";
export {default as value} from "./src/value";
export {default as zoom} from "./src/zoom";
export {default as rgb} from "./src/rgb";
export {default as hsl} from "./src/hsl";
export {default as hslLong} from "./src/hslLong";
export {default as lab} from "./src/lab";
export {default as hcl} from "./src/hcl";
export {default as hclLong} from "./src/hclLong";
import cubehelixGamma from "./src/cubehelixGamma";
import cubehelixGammaLong from "./src/cubehelixGammaLong";
export var cubehelix = cubehelixGamma(1);
export var cubehelixLong = cubehelixGammaLong(1);
export {cubehelixGamma, cubehelixGammaLong};
{
"name": "d3-interpolate",
"version": "0.1.4",
"version": "0.2.0",
"description": "Interpolate numbers, colors, strings, arrays, objects, whatever!",

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

"dependencies": {
"d3-color": "~0.2.8"
"d3-color": "~0.3.1"
},

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

@@ -6,3 +6,3 @@ # d3-interpolate

```js
var i = interpolateNumber(10, 20);
var i = number(10, 20);
i(0.0); // 10

@@ -16,6 +16,12 @@ i(0.2); // 12

Here’s a more elaborate example demonstrating type inference used by [interpolate](#interpolate):
You can interpolate more than just numbers. To find the perceptual halfway point between steelblue and brown:
```js
var i = interpolate({colors: ["red", "blue"]}, {colors: ["white", "black"]});
lab("steelblue", "brown")(0.5); // #8e5c6d
```
Here’s a more elaborate example demonstrating type inference used by [value](#value):
```js
var i = value({colors: ["red", "blue"]}, {colors: ["white", "black"]});
i(0.0); // {colors: ["#ff0000", "#0000ff"]}

@@ -26,3 +32,3 @@ i(0.5); // {colors: ["#ff8080", "#000080"]}

Note that the generic interpolate method detects not only nested objects and arrays, but also color strings and numbers embedded in strings!
Note that the generic value interpolator detects not only nested objects and arrays, but also color strings and numbers embedded in strings!

@@ -35,15 +41,15 @@ ## Installing

<a name="interpolate" href="#interpolate">#</a> <b>interpolate</b>(<i>a</i>, <i>b</i>)
<a name="value" href="#value">#</a> <b>value</b>(<i>a</i>, <i>b</i>)
Returns an interpolator between the two values *a* and *b*. The type of interpolator is based on the type of the end value *b*, using the following algorithm:
Returns an interpolator between the two arbitrary values *a* and *b*. The interpolator implementation is based on the type of the end value *b*, using the following algorithm:
1. If *b* is a [color](https://github.com/d3/d3-color#color), [interpolateRgb](https://github.com/d3/d3-color#interpolateRgb) is used.
2. If *b* is a string, [interpolateString](#interpolateString) is used.
3. If *b* is an array, [interpolateArray](#interpolateArray) is used.
4. If *b* is an object and not coercible to a number, [interpolateObject](#interpolateObject) is used.
5. Otherwise, [interpolateNumber](#interpolateNumber) is used.
1. If *b* is a [color](https://github.com/d3/d3-color#color), [rgb](#rgb) is used.
2. If *b* is a string, [string](#string) is used.
3. If *b* is an array, [array](#array) is used.
4. If *b* is an object and not coercible to a number, [object](#object) is used.
5. Otherwise, [number](#number) is used.
Based on the chosen interpolator, *a* is coerced to a suitable corresponding type. The behavior of this method may be augmented to support additional types by pushing custom interpolator factories onto the [interpolators](#interpolators) array.
Based on the chosen interpolator, *a* is coerced to a suitable corresponding type. The behavior of this method may be augmented to support additional types by pushing custom interpolator factories onto the [values](#values) array.
<a name="interpolateNumber" href="#interpolateNumber">#</a> <b>interpolateNumber</b>(<i>a</i>, <i>b</i>)
<a name="number" href="#number">#</a> <b>number</b>(<i>a</i>, <i>b</i>)

@@ -60,17 +66,17 @@ Returns an interpolator between the two numbers *a* and *b*. The returned interpolator is equivalent to:

<a name="interpolateRound" href="#interpolateRound">#</a> <b>interpolateRound</b>(<i>a</i>, <i>b</i>)
<a name="round" href="#round">#</a> <b>round</b>(<i>a</i>, <i>b</i>)
Returns an interpolator between the two numbers *a* and *b*; the interpolator is similar to [interpolateNumber](#interpolateNumber), except it will round the resulting value to the nearest integer.
Returns an interpolator between the two numbers *a* and *b*; the interpolator is similar to [number](#number), except it will round the resulting value to the nearest integer.
<a name="interpolateString" href="#interpolateString">#</a> <b>interpolateString</b>(<i>a</i>, <i>b</i>)
<a name="string" href="#string">#</a> <b>string</b>(<i>a</i>, <i>b</i>)
Returns an interpolator between the two strings *a* and *b*. The string interpolator finds numbers embedded in *a* and *b*, where each number is of the form understood by JavaScript. A few examples of numbers that will be detected within a string: `-1`, `42`, `3.14159`, and `6.0221413e+23`.
For each number embedded in *b*, the interpolator will attempt to find a corresponding number in *a*. If a corresponding number is found, a numeric interpolator is created using [interpolateNumber](#interpolateNumber). The remaining parts of the string *b* are used as a template: the static parts of the string *b* remain constant for the interpolation, with the interpolated numeric values embedded in the template.
For each number embedded in *b*, the interpolator will attempt to find a corresponding number in *a*. If a corresponding number is found, a numeric interpolator is created using [number](#number). The remaining parts of the string *b* are used as a template: the static parts of the string *b* remain constant for the interpolation, with the interpolated numeric values embedded in the template.
For example, if *a* is `"300 12px sans-serif"`, and *b* is `"500 36px Comic-Sans"`, two embedded numbers are found. The remaining static parts of the string are a space between the two numbers (`" "`), and the suffix (`"px Comic-Sans"`). The result of the interpolator at *t* = .5 is `"400 24px Comic-Sans"`.
<a name="interpolateArray" href="#interpolateArray">#</a> <b>interpolateArray</b>(<i>a</i>, <i>b</i>)
<a name="array" href="#array">#</a> <b>array</b>(<i>a</i>, <i>b</i>)
Returns an interpolator between the two arrays *a* and *b*. Internally, an array template is created that is the same length in *b*. For each element in *b*, if there exists a corresponding element in *a*, a generic interpolator is created for the two elements using [interpolate](#interpolate). If there is no such element, the static value from *b* is used in the template. Then, for the given parameter *t*, the template’s embedded interpolators are evaluated. The updated array template is then returned.
Returns an interpolator between the two arrays *a* and *b*. Internally, an array template is created that is the same length in *b*. For each element in *b*, if there exists a corresponding element in *a*, a generic interpolator is created for the two elements using [value](#value). If there is no such element, the static value from *b* is used in the template. Then, for the given parameter *t*, the template’s embedded interpolators are evaluated. The updated array template is then returned.

@@ -81,5 +87,5 @@ For example, if *a* is the array `[0, 1]` and *b* is the array `[1, 10, 100]`, then the result of the interpolator for *t* = .5 is the array `[.5, 5.5, 100]`.

<a name="interpolateObject" href="#interpolateObject">#</a> <b>interpolateObject</b>(<i>a</i>, <i>b</i>)
<a name="object" href="#object">#</a> <b>object</b>(<i>a</i>, <i>b</i>)
Returns an interpolator between the two objects *a* and *b*. Internally, an object template is created that has the same properties as *b*. For each property in *b*, if there exists a corresponding property in *a*, a generic interpolator is created for the two elements using [interpolate](#interpolate). If there is no such property, the static value from *b* is used in the template. Then, for the given parameter *t*, the template's embedded interpolators are evaluated and the updated object template is then returned.
Returns an interpolator between the two objects *a* and *b*. Internally, an object template is created that has the same properties as *b*. For each property in *b*, if there exists a corresponding property in *a*, a generic interpolator is created for the two elements using [value](#value). If there is no such property, the static value from *b* is used in the template. Then, for the given parameter *t*, the template's embedded interpolators are evaluated and the updated object template is then returned.

@@ -92,7 +98,7 @@ For example, if *a* is the object `{x: 0, y: 1}` and *b* is the object `{x: 1, y: 10, z: 100}`, the result of the interpolator for *t* = .5 is the object `{x: .5, y: 5.5, z: 100}`.

<a name="interpolateTransform" href="#interpolateTransform">#</a> <b>interpolateTransform</b>(<i>a</i>, <i>b</i>)
<a name="transform" href="#transform">#</a> <b>transform</b>(<i>a</i>, <i>b</i>)
Returns an interpolator between the two 2D affine transforms represented by *a* and *b*. Each transform is decomposed to a standard representation of translate, rotate, *x*-skew and scale; these component transformations are then interpolated. This behavior is standardized by CSS: see [matrix decomposition for animation](http://www.w3.org/TR/css3-2d-transforms/#matrix-decomposition).
<a name="interpolateZoom" href="#interpolateZoom">#</a> <b>interpolateZoom</b>(<i>a</i>, <i>b</i>)
<a name="zoom" href="#zoom">#</a> <b>zoom</b>(<i>a</i>, <i>b</i>)

@@ -103,5 +109,5 @@ Returns an interpolator between the two views *a* and *b* of a two-dimensional plane, based on [“Smooth and efficient zooming and panning”](https://www.google.com/search?q=Smooth+and+efficient+zooming+and+panning) by Jarke J. van Wijk and Wim A.A. Nuij. Each view is defined as an array of three numbers: *cx*, *cy* and *width*. The first two coordinates *cx*, *cy* represent the center of the viewport; the last coordinate *width* represents the size of the viewport.

<a name="interpolators" href="#interpolators">#</a> <b>interpolators</b>
<a name="values" href="#values">#</a> <b>values</b>
The array of built-in interpolator factories, as used by [interpolate](#interpolate). Additional interpolator factories may be pushed onto the end of this array. Each factory should return an interpolator if it supports interpolating the two specified input values; otherwise, the factory should return a falsey value and other interpolators will be tried.
The array of built-in interpolator factories, as used by [value](#value). Additional interpolator factories may be pushed onto the end of this array. Each factory should return an interpolator if it supports interpolating the two specified input values; otherwise, the factory should return a falsey value and other interpolators will be tried.

@@ -111,3 +117,3 @@ For example, to register a custom interpolator that formats dollars and cents, you might say:

```js
interpolators.push(function(a, b) {
values.push(function(a, b) {
var re = /^\$([0-9,.]+)$/, ma, mb, f = d3.format(",.02f");

@@ -124,2 +130,70 @@ if ((ma = re.exec(a)) && (mb = re.exec(b))) {

Subsequently, `interpolate("$20", "$10")(1/3)` returns `$16.67`.
Subsequently, `value("$20", "$10")(1/3)` returns `$16.67`.
<a name="rgb" href="#rgb">#</a> <b>rgb</b>(<i>a</i>, <i>b</i>)
![rgb](https://cloud.githubusercontent.com/assets/230541/8027976/07e91580-0d58-11e5-8d3f-4c50f152a2e3.png)
Returns an RGB color space interpolator between the two colors *a* and *b*. The colors *a* and *b* need not be in RGB; they will be converted to RGB using [rgb](#rgb). The return value of the interpolator is a hexadecimal RGB string.
<a name="hsl" href="#hsl">#</a> <b>hsl</b>(<i>a</i>, <i>b</i>)
![hsl](https://cloud.githubusercontent.com/assets/230541/8027979/07fec100-0d58-11e5-90df-dc458ae7af10.png)
Returns an HSL color space interpolator between the two colors *a* and *b*. The colors *a* and *b* need not be in HSL; they will be converted to HSL using [hsl](#hsl). If either color’s hue or saturation is NaN, the opposing color’s channel value is used. The shortest path between hues is used. The return value of the interpolator is a hexadecimal RGB string.
<a name="hslLong" href="#hslLong">#</a> <b>hslLong</b>(<i>a</i>, <i>b</i>)
![hsllong](https://cloud.githubusercontent.com/assets/230541/8028057/bae888b8-0d59-11e5-983a-a460a59ae4ab.png)
Like [hsl](#hsl), but does not use the shortest path between hues.
<a name="lab" href="#lab">#</a> <b>lab</b>(<i>a</i>, <i>b</i>)
![lab](https://cloud.githubusercontent.com/assets/230541/8027977/07eaea04-0d58-11e5-8f4f-b739eb842549.png)
Returns a Lab color space interpolator between the two colors *a* and *b*. The colors *a* and *b* need not be in Lab; they will be converted to Lab using [lab](#lab). The return value of the interpolator is a hexadecimal RGB string.
<a name="hcl" href="#hcl">#</a> <b>hcl</b>(<i>a</i>, <i>b</i>)
![hcl](https://cloud.githubusercontent.com/assets/230541/8027978/07f91002-0d58-11e5-92f0-f06899907c6a.png)
Returns an HCL color space interpolator between the two colors *a* and *b*. The colors *a* and *b* need not be in HCL; they will be converted to HCL using [hcl](#hcl). If either color’s hue or chroma is NaN, the opposing color’s channel value is used. The shortest path between hues is used. The return value of the interpolator is a hexadecimal RGB string.
<a name="hclLong" href="#hclLong">#</a> <b>hclLong</b>(<i>a</i>, <i>b</i>)
![hcllong](https://cloud.githubusercontent.com/assets/230541/8028056/bad85786-0d59-11e5-9c22-6c23215779fa.png)
Like [hcl](#hcl), but does not use the shortest path between hues.
<a name="cubehelix" href="#cubehelix">#</a> <b>cubehelix</b>(<i>a</i>, <i>b</i>)
![cubehelix](https://cloud.githubusercontent.com/assets/230541/8027999/737cde08-0d58-11e5-8130-36e2437996ee.png)
Returns a Cubehelix color space interpolator between the two colors *a* and *b* using the default *gamma* of 1.0. The colors *a* and *b* need not be in Cubehelix; they will be converted to Cubehelix using [cubehelix](https://github.com/d3/d3-color#cubehelix). If either color’s hue or saturation is NaN, the opposing color’s channel value is used. The shortest path between hues is used. The return value of the interpolator is a hexadecimal RGB string.
<a name="cubehelixLong" href="#cubehelixLong">#</a> <b>cubehelixLong</b>(<i>a</i>, <i>b</i>)
![cubehelixlong](https://cloud.githubusercontent.com/assets/230541/8028055/bad68424-0d59-11e5-8f0f-1ecdbd8e46c8.png)
Like [cubehelix](#cubehelix), but does not use the shortest path between hues.
<a name="cubehelixGamma" href="#cubehelixGamma">#</a> <b>cubehelixGamma</b>(<i>gamma</i>)
Returns a Cubehelix color space interpolator factory using the specified *gamma*. A gamma value less than one emphasizes low intensity values, while a gamma value greater than one emphasizes high intensity values. For example:
```js
var i = cubehelixGamma(1.5)("red", "blue");
```
<a name="cubehelixGammaLong" href="#cubehelixGammaLong">#</a> <b>cubehelixGammaLong</b>(<i>gamma</i>)
Like [cubehelixGamma](#cubehelixGamma), but does not use the shortest path between hues.
## Changes from D3 3.x:
* A new [cubehelix](#cubehelix) color space!
* New “long” methods for hue interpolation in [HSL](#hslLong), [HCL](#hclLong) and [Cubehelix](#cubehelixLong).
* Renamed the generic interpolate method and interpolators array to [value](#value) and [values](#values), respectively.
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