Skip to content

Commit

Permalink
Merge branch 'fix-interpolate-number' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Nov 30, 2011
2 parents 4972113 + 2be4efd commit 33ab885
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
6 changes: 3 additions & 3 deletions d3.js
Original file line number Diff line number Diff line change
Expand Up @@ -977,9 +977,9 @@ function d3_interpolateByName(n) {
d3.interpolators = [
d3.interpolateObject,
function(a, b) { return (b instanceof Array) && d3.interpolateArray(a, b); },
function(a, b) { return (typeof b === "string") && d3.interpolateString(a + "", b); },
function(a, b) { return (typeof b === "string" ? b in d3_rgb_names || /^(#|rgb\(|hsl\()/.test(b) : b instanceof d3_Rgb || b instanceof d3_Hsl) && d3.interpolateRgb(a + "", b); },
function(a, b) { return (typeof b === "number") && d3.interpolateNumber(+a, b); }
function(a, b) { return (typeof a === "string" || typeof b === "string") && d3.interpolateString(a + "", b + ""); },
function(a, b) { return (typeof b === "string" ? b in d3_rgb_names || /^(#|rgb\(|hsl\()/.test(b) : b instanceof d3_Rgb || b instanceof d3_Hsl) && d3.interpolateRgb(a, b); },
function(a, b) { return !isNaN(a = +a) && !isNaN(b = +b) && d3.interpolateNumber(a, b); }
];
function d3_uninterpolateNumber(a, b) {
b = b - (a = +a) ? 1 / (b - a) : 0;
Expand Down
4 changes: 2 additions & 2 deletions d3.min.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/core/interpolate.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ function d3_interpolateByName(n) {
d3.interpolators = [
d3.interpolateObject,
function(a, b) { return (b instanceof Array) && d3.interpolateArray(a, b); },
function(a, b) { return (typeof b === "string") && d3.interpolateString(a + "", b); },
function(a, b) { return (typeof b === "string" ? b in d3_rgb_names || /^(#|rgb\(|hsl\()/.test(b) : b instanceof d3_Rgb || b instanceof d3_Hsl) && d3.interpolateRgb(a + "", b); },
function(a, b) { return (typeof b === "number") && d3.interpolateNumber(+a, b); }
function(a, b) { return (typeof a === "string" || typeof b === "string") && d3.interpolateString(a + "", b + ""); },
function(a, b) { return (typeof b === "string" ? b in d3_rgb_names || /^(#|rgb\(|hsl\()/.test(b) : b instanceof d3_Rgb || b instanceof d3_Hsl) && d3.interpolateRgb(a, b); },
function(a, b) { return !isNaN(a = +a) && !isNaN(b = +b) && d3.interpolateNumber(a, b); }
];
2 changes: 2 additions & 0 deletions test/core/interpolate-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ suite.addBatch({
},
"interpolates numbers": function(interpolate) {
assert.equal(interpolate(2, 12)(.4), 6);
assert.equal(interpolate("2px", 12)(.4), 6);
},
"interpolates colors": function(interpolate) {
assert.equal(interpolate("#abcdef", "#fedcba")(.4), "#ccd3da");
},
"interpolates strings": function(interpolate) {
assert.equal(interpolate("width:10px;", "width:50px;")(.2), "width:18px;");
assert.equal(interpolate(2, "12px")(.4), "6px");
},
"interpolates arrays": function(interpolate) {
assert.deepEqual(interpolate([2, 4], [12, 24])(.4), [6, 12]);
Expand Down

0 comments on commit 33ab885

Please sign in to comment.