Skip to content

Commit

Permalink
Add test for registering custom interpolator.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Jun 11, 2011
1 parent 40ba791 commit 093089f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tests/test-interpolate.js
Expand Up @@ -63,3 +63,25 @@ console.log(" 0.5 -> ", x(0.5));
console.log(" 1.0 -> ", x(1.0));
console.log(" 1.5 -> ", x(1.5));
console.log("");

d3.interpolators.push(function(a, b) {
return a == "one" && b == "two" && d3.interpolateNumber(1, 2);
});

var x = d3.interpolate("one", "two");
console.log("interpolateOneTwo(one, two):");
console.log(" -0.5 -> ", x(-0.5));
console.log(" 0.0 -> ", x(0.0));
console.log(" 0.5 -> ", x(0.5));
console.log(" 1.0 -> ", x(1.0));
console.log(" 1.5 -> ", x(1.5));
console.log("");

var x = d3.interpolate("one", "three");
console.log("interpolate(one, three):");
console.log(" -0.5 -> ", x(-0.5));
console.log(" 0.0 -> ", x(0.0));
console.log(" 0.5 -> ", x(0.5));
console.log(" 1.0 -> ", x(1.0));
console.log(" 1.5 -> ", x(1.5));
console.log("");
14 changes: 14 additions & 0 deletions tests/test-interpolate.out
Expand Up @@ -47,3 +47,17 @@ interpolateHsl(red, blue):
1.0 -> #0000ff
1.5 -> #ff0000

interpolateOneTwo(one, two):
-0.5 -> 0.5
0.0 -> 1
0.5 -> 1.5
1.0 -> 2
1.5 -> 2.5

interpolate(one, three):
-0.5 -> three
0.0 -> three
0.5 -> three
1.0 -> three
1.5 -> three

0 comments on commit 093089f

Please sign in to comment.