Skip to content

Commit

Permalink
Adopt the “interpolate” prefix.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Jan 7, 2016
1 parent a9d5aa5 commit edc6c68
Show file tree
Hide file tree
Showing 16 changed files with 261 additions and 261 deletions.
116 changes: 58 additions & 58 deletions README.md

Large diffs are not rendered by default.

36 changes: 18 additions & 18 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
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";
export {default as cubehelix} from "./src/cubehelix";
export {default as cubehelixLong} from "./src/cubehelixLong";
export {default as bind} from "./src/bind";
export {default as interpolate} from "./src/value";
export {default as interpolators} from "./src/values";
export {default as interpolateArray} from "./src/array";
export {default as interpolateNumber} from "./src/number";
export {default as interpolateObject} from "./src/object";
export {default as interpolateRound} from "./src/round";
export {default as interpolateString} from "./src/string";
export {default as interpolateTransform} from "./src/transform";
export {default as interpolateZoom} from "./src/zoom";
export {default as interpolateRgb} from "./src/rgb";
export {default as interpolateHsl} from "./src/hsl";
export {default as interpolateHslLong} from "./src/hslLong";
export {default as interpolateLab} from "./src/lab";
export {default as interpolateHcl} from "./src/hcl";
export {default as interpolateHclLong} from "./src/hclLong";
export {default as interpolateCubehelix} from "./src/cubehelix";
export {default as interpolateCubehelixLong} from "./src/cubehelixLong";
export {default as interpolateBind} from "./src/bind";
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "d3-interpolate",
"version": "0.3.0",
"version": "0.4.0",
"description": "Interpolate numbers, colors, strings, arrays, objects, whatever!",
"keywords": [
"d3",
Expand All @@ -26,7 +26,7 @@
"prepublish": "npm run test && uglifyjs build/d3-interpolate.js -c -m -o build/d3-interpolate.min.js && rm -f build/d3-interpolate.zip && zip -j build/d3-interpolate.zip -- LICENSE README.md build/d3-interpolate.js build/d3-interpolate.min.js"
},
"dependencies": {
"d3-color": "~0.3.2"
"d3-color": "~0.3.3"
},
"devDependencies": {
"faucet": "0.0",
Expand Down
30 changes: 15 additions & 15 deletions test/array-test.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
var tape = require("tape"),
interpolate = require("../");

tape("array(a, b) interpolates defined elements in a and b", function(test) {
test.deepEqual(interpolate.array([2, 12], [4, 24])(.5), [3, 18]);
tape("interpolateArray(a, b) interpolates defined elements in a and b", function(test) {
test.deepEqual(interpolate.interpolateArray([2, 12], [4, 24])(.5), [3, 18]);
test.end();
});

tape("array(a, b) interpolates nested objects and arrays", function(test) {
test.deepEqual(interpolate.array([[2, 12]], [[4, 24]])(.5), [[3, 18]]);
test.deepEqual(interpolate.array([{foo: [2, 12]}], [{foo: [4, 24]}])(.5), [{foo: [3, 18]}]);
tape("interpolateArray(a, b) interpolates nested objects and arrays", function(test) {
test.deepEqual(interpolate.interpolateArray([[2, 12]], [[4, 24]])(.5), [[3, 18]]);
test.deepEqual(interpolate.interpolateArray([{foo: [2, 12]}], [{foo: [4, 24]}])(.5), [{foo: [3, 18]}]);
test.end();
});

tape("array(a, b) merges non-shared elements", function(test) {
test.deepEqual(interpolate.array([2, 12], [4, 24, 12])(.5), [3, 18, 12]);
test.deepEqual(interpolate.array([2, 12, 12], [4, 24])(.5), [3, 18, 12]);
tape("interpolateArray(a, b) merges non-shared elements", function(test) {
test.deepEqual(interpolate.interpolateArray([2, 12], [4, 24, 12])(.5), [3, 18, 12]);
test.deepEqual(interpolate.interpolateArray([2, 12, 12], [4, 24])(.5), [3, 18, 12]);
test.end();
});

tape("array(a, b) treats undefined as an empty array", function(test) {
test.deepEqual(interpolate.array(undefined, [2, 12])(.5), [2, 12]);
test.deepEqual(interpolate.array([2, 12], undefined)(.5), [2, 12]);
test.deepEqual(interpolate.array(undefined, undefined)(.5), []);
tape("interpolateArray(a, b) treats undefined as an empty array", function(test) {
test.deepEqual(interpolate.interpolateArray(undefined, [2, 12])(.5), [2, 12]);
test.deepEqual(interpolate.interpolateArray([2, 12], undefined)(.5), [2, 12]);
test.deepEqual(interpolate.interpolateArray(undefined, undefined)(.5), []);
test.end();
});

tape("array(a, b) interpolates array-like objects", function(test) {
tape("interpolateArray(a, b) interpolates array-like objects", function(test) {
var array = new Float64Array(2),
args = (function() { return arguments; })(2, 12);
array[0] = 2;
array[1] = 12;
test.deepEqual(interpolate.array(array, [4, 24])(.5), [3, 18]);
test.deepEqual(interpolate.array(args, [4, 24])(.5), [3, 18]);
test.deepEqual(interpolate.interpolateArray(array, [4, 24])(.5), [3, 18]);
test.deepEqual(interpolate.interpolateArray(args, [4, 24])(.5), [3, 18]);
test.end();
});
14 changes: 7 additions & 7 deletions test/bind-test.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
var tape = require("tape"),
interpolate = require("../");

tape("bind(type) returns type", function(test) {
test.equal(interpolate.bind(interpolate.cubehelix), interpolate.cubehelix);
test.equal(interpolate.bind(interpolate.rgb), interpolate.rgb);
tape("interpolateBind(type) returns type", function(test) {
test.equal(interpolate.interpolateBind(interpolate.interpolateCubehelix), interpolate.interpolateCubehelix);
test.equal(interpolate.interpolateBind(interpolate.interpolateRgb), interpolate.interpolateRgb);
test.end();
});

tape("bind(type, parameter) binds the specified parameter to the given type", function(test) {
test.equal(interpolate.bind(interpolate.cubehelix, 3)("purple", "orange")(0.5), interpolate.cubehelix("purple", "orange", 3)(0.5));
test.equal(interpolate.bind(interpolate.cubehelixLong, 3)("purple", "orange")(0.5), interpolate.cubehelixLong("purple", "orange", 3)(0.5));
test.equal(interpolate.bind(interpolate.rgb, 3)("purple", "orange")(0.5), interpolate.rgb("purple", "orange", 3)(0.5)); // ignored
tape("interpolateBind(type, parameter) binds the specified parameter to the given type", function(test) {
test.equal(interpolate.interpolateBind(interpolate.interpolateCubehelix, 3)("purple", "orange")(0.5), interpolate.interpolateCubehelix("purple", "orange", 3)(0.5));
test.equal(interpolate.interpolateBind(interpolate.interpolateCubehelixLong, 3)("purple", "orange")(0.5), interpolate.interpolateCubehelixLong("purple", "orange", 3)(0.5));
test.equal(interpolate.interpolateBind(interpolate.interpolateRgb, 3)("purple", "orange")(0.5), interpolate.interpolateRgb("purple", "orange", 3)(0.5)); // ignored
test.end();
});
52 changes: 26 additions & 26 deletions test/hcl-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ var tape = require("tape"),
color = require("d3-color"),
interpolate = require("../");

tape("hcl(a, b) converts a and b to HCL colors", function(test) {
test.equal(interpolate.hcl("steelblue", "brown")(0), color.rgb("steelblue") + "");
test.equal(interpolate.hcl("steelblue", color.hcl("brown"))(1), color.rgb("brown") + "");
test.equal(interpolate.hcl("steelblue", color.rgb("brown"))(1), color.rgb("brown") + "");
tape("interpolateHcl(a, b) converts a and b to HCL colors", function(test) {
test.equal(interpolate.interpolateHcl("steelblue", "brown")(0), color.rgb("steelblue") + "");
test.equal(interpolate.interpolateHcl("steelblue", color.hcl("brown"))(1), color.rgb("brown") + "");
test.equal(interpolate.interpolateHcl("steelblue", color.rgb("brown"))(1), color.rgb("brown") + "");
test.end();
});

tape("hcl(a, b) interpolates in HCL and returns an RGB hexadecimal string", function(test) {
test.equal(interpolate.hcl("steelblue", "#f00")(.2), "#6978c9");
tape("interpolateHcl(a, b) interpolates in HCL and returns an RGB hexadecimal string", function(test) {
test.equal(interpolate.interpolateHcl("steelblue", "#f00")(.2), "#6978c9");
test.end();
});

tape("hcl(a, b) uses the shortest path when interpolating hue difference greater than 180°", function(test) {
var i = interpolate.hcl(color.hcl(10, 50, 50), color.hcl(350, 50, 50));
tape("interpolateHcl(a, b) uses the shortest path when interpolating hue difference greater than 180°", function(test) {
var i = interpolate.interpolateHcl(color.hcl(10, 50, 50), color.hcl(350, 50, 50));
test.equal(i(0.0), "#c44f6a");
test.equal(i(0.2), "#c44f70");
test.equal(i(0.4), "#c34f76");
Expand All @@ -25,8 +25,8 @@ tape("hcl(a, b) uses the shortest path when interpolating hue difference greater
test.end();
});

tape("hcl(a, b) uses the shortest path when interpolating hue difference greater than 360°", function(test) {
var i = interpolate.hcl(color.hcl(10, 50, 50), color.hcl(380, 50, 50));
tape("interpolateHcl(a, b) uses the shortest path when interpolating hue difference greater than 360°", function(test) {
var i = interpolate.interpolateHcl(color.hcl(10, 50, 50), color.hcl(380, 50, 50));
test.equal(i(0.0), "#c44f6a");
test.equal(i(0.2), "#c44f68");
test.equal(i(0.4), "#c55065");
Expand All @@ -36,8 +36,8 @@ tape("hcl(a, b) uses the shortest path when interpolating hue difference greater
test.end();
});

tape("hcl(a, b) uses the shortest path when interpolating hue difference greater than 540°", function(test) {
var i = interpolate.hcl(color.hcl(10, 50, 50), color.hcl(710, 50, 50));
tape("interpolateHcl(a, b) uses the shortest path when interpolating hue difference greater than 540°", function(test) {
var i = interpolate.interpolateHcl(color.hcl(10, 50, 50), color.hcl(710, 50, 50));
test.equal(i(0.0), "#c44f6a");
test.equal(i(0.2), "#c44f70");
test.equal(i(0.4), "#c34f76");
Expand All @@ -47,8 +47,8 @@ tape("hcl(a, b) uses the shortest path when interpolating hue difference greater
test.end();
});

tape("hcl(a, b) uses the shortest path when interpolating hue difference greater than 720°", function(test) {
var i = interpolate.hcl(color.hcl(10, 50, 50), color.hcl(740, 50, 50));
tape("interpolateHcl(a, b) uses the shortest path when interpolating hue difference greater than 720°", function(test) {
var i = interpolate.interpolateHcl(color.hcl(10, 50, 50), color.hcl(740, 50, 50));
test.equal(i(0.0), "#c44f6a");
test.equal(i(0.2), "#c44f68");
test.equal(i(0.4), "#c55065");
Expand All @@ -58,26 +58,26 @@ tape("hcl(a, b) uses the shortest path when interpolating hue difference greater
test.end();
});

tape("hcl(a, b) uses a’s hue when b’s hue is undefined", function(test) {
test.equal(interpolate.hcl("#f60", color.hcl(NaN, NaN, 0))(.5), "#9b0000");
test.equal(interpolate.hcl("#6f0", color.hcl(NaN, NaN, 0))(.5), "#008100");
tape("interpolateHcl(a, b) uses a’s hue when b’s hue is undefined", function(test) {
test.equal(interpolate.interpolateHcl("#f60", color.hcl(NaN, NaN, 0))(.5), "#9b0000");
test.equal(interpolate.interpolateHcl("#6f0", color.hcl(NaN, NaN, 0))(.5), "#008100");
test.end();
});

tape("hcl(a, b) uses b’s hue when a’s hue is undefined", function(test) {
test.equal(interpolate.hcl(color.hcl(NaN, NaN, 0), "#f60")(.5), "#9b0000");
test.equal(interpolate.hcl(color.hcl(NaN, NaN, 0), "#6f0")(.5), "#008100");
tape("interpolateHcl(a, b) uses b’s hue when a’s hue is undefined", function(test) {
test.equal(interpolate.interpolateHcl(color.hcl(NaN, NaN, 0), "#f60")(.5), "#9b0000");
test.equal(interpolate.interpolateHcl(color.hcl(NaN, NaN, 0), "#6f0")(.5), "#008100");
test.end();
});

tape("hcl(a, b) uses a’s chroma when b’s chroma is undefined", function(test) {
test.equal(interpolate.hcl("#ccc", color.hcl(NaN, NaN, 0))(.5), "#616161");
test.equal(interpolate.hcl("#f00", color.hcl(NaN, NaN, 0))(.5), "#a60000");
tape("interpolateHcl(a, b) uses a’s chroma when b’s chroma is undefined", function(test) {
test.equal(interpolate.interpolateHcl("#ccc", color.hcl(NaN, NaN, 0))(.5), "#616161");
test.equal(interpolate.interpolateHcl("#f00", color.hcl(NaN, NaN, 0))(.5), "#a60000");
test.end();
});

tape("hcl(a, b) uses b’s chroma when a’s chroma is undefined", function(test) {
test.equal(interpolate.hcl(color.hcl(NaN, NaN, 0), "#ccc")(.5), "#616161");
test.equal(interpolate.hcl(color.hcl(NaN, NaN, 0), "#f00")(.5), "#a60000");
tape("interpolateHcl(a, b) uses b’s chroma when a’s chroma is undefined", function(test) {
test.equal(interpolate.interpolateHcl(color.hcl(NaN, NaN, 0), "#ccc")(.5), "#616161");
test.equal(interpolate.interpolateHcl(color.hcl(NaN, NaN, 0), "#f00")(.5), "#a60000");
test.end();
});
40 changes: 20 additions & 20 deletions test/hclLong-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ var tape = require("tape"),
color = require("d3-color"),
interpolate = require("../");

tape("hclLong(a, b) converts a and b to HCL colors", function(test) {
test.equal(interpolate.hclLong("steelblue", "brown")(0), color.rgb("steelblue") + "");
test.equal(interpolate.hclLong("steelblue", color.hcl("brown"))(1), color.rgb("brown") + "");
test.equal(interpolate.hclLong("steelblue", color.rgb("brown"))(1), color.rgb("brown") + "");
tape("interpolateHclLong(a, b) converts a and b to HCL colors", function(test) {
test.equal(interpolate.interpolateHclLong("steelblue", "brown")(0), color.rgb("steelblue") + "");
test.equal(interpolate.interpolateHclLong("steelblue", color.hcl("brown"))(1), color.rgb("brown") + "");
test.equal(interpolate.interpolateHclLong("steelblue", color.rgb("brown"))(1), color.rgb("brown") + "");
test.end();
});

tape("hclLong(a, b) interpolates in HCL and returns an RGB hexadecimal string", function(test) {
test.equal(interpolate.hclLong("steelblue", "#f00")(.2), "#0090ae");
tape("interpolateHclLong(a, b) interpolates in HCL and returns an RGB hexadecimal string", function(test) {
test.equal(interpolate.interpolateHclLong("steelblue", "#f00")(.2), "#0090ae");
test.end();
});

tape("hclLong(a, b) does not use the shortest path when interpolating hue", function(test) {
var i = interpolate.hclLong(color.hcl(10, 50, 50), color.hcl(350, 50, 50));
tape("interpolateHclLong(a, b) does not use the shortest path when interpolating hue", function(test) {
var i = interpolate.interpolateHclLong(color.hcl(10, 50, 50), color.hcl(350, 50, 50));
test.equal(i(0.0), "#c44f6a");
test.equal(i(0.2), "#9c6f1d");
test.equal(i(0.4), "#2e8745");
Expand All @@ -25,26 +25,26 @@ tape("hclLong(a, b) does not use the shortest path when interpolating hue", func
test.end();
});

tape("hclLong(a, b) uses a’s hue when b’s hue is undefined", function(test) {
test.equal(interpolate.hclLong("#f60", color.hcl(NaN, NaN, 0))(.5), "#9b0000");
test.equal(interpolate.hclLong("#6f0", color.hcl(NaN, NaN, 0))(.5), "#008100");
tape("interpolateHclLong(a, b) uses a’s hue when b’s hue is undefined", function(test) {
test.equal(interpolate.interpolateHclLong("#f60", color.hcl(NaN, NaN, 0))(.5), "#9b0000");
test.equal(interpolate.interpolateHclLong("#6f0", color.hcl(NaN, NaN, 0))(.5), "#008100");
test.end();
});

tape("hclLong(a, b) uses b’s hue when a’s hue is undefined", function(test) {
test.equal(interpolate.hclLong(color.hcl(NaN, NaN, 0), "#f60")(.5), "#9b0000");
test.equal(interpolate.hclLong(color.hcl(NaN, NaN, 0), "#6f0")(.5), "#008100");
tape("interpolateHclLong(a, b) uses b’s hue when a’s hue is undefined", function(test) {
test.equal(interpolate.interpolateHclLong(color.hcl(NaN, NaN, 0), "#f60")(.5), "#9b0000");
test.equal(interpolate.interpolateHclLong(color.hcl(NaN, NaN, 0), "#6f0")(.5), "#008100");
test.end();
});

tape("hclLong(a, b) uses a’s chroma when b’s chroma is undefined", function(test) {
test.equal(interpolate.hclLong("#ccc", color.hcl(NaN, NaN, 0))(.5), "#616161");
test.equal(interpolate.hclLong("#f00", color.hcl(NaN, NaN, 0))(.5), "#a60000");
tape("interpolateHclLong(a, b) uses a’s chroma when b’s chroma is undefined", function(test) {
test.equal(interpolate.interpolateHclLong("#ccc", color.hcl(NaN, NaN, 0))(.5), "#616161");
test.equal(interpolate.interpolateHclLong("#f00", color.hcl(NaN, NaN, 0))(.5), "#a60000");
test.end();
});

tape("hclLong(a, b) uses b’s chroma when a’s chroma is undefined", function(test) {
test.equal(interpolate.hclLong(color.hcl(NaN, NaN, 0), "#ccc")(.5), "#616161");
test.equal(interpolate.hclLong(color.hcl(NaN, NaN, 0), "#f00")(.5), "#a60000");
tape("interpolateHclLong(a, b) uses b’s chroma when a’s chroma is undefined", function(test) {
test.equal(interpolate.interpolateHclLong(color.hcl(NaN, NaN, 0), "#ccc")(.5), "#616161");
test.equal(interpolate.interpolateHclLong(color.hcl(NaN, NaN, 0), "#f00")(.5), "#a60000");
test.end();
});

0 comments on commit edc6c68

Please sign in to comment.