Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix missing string coercion for d3.tween.

  • Loading branch information...
commit 428ea4ff924180768b138961f438c036f8ca99df 1 parent 78a0284
@mbostock authored
View
2  d3.v2.js
@@ -4055,7 +4055,7 @@
d3.tween = function(b, interpolate) {
function tweenFunction(d, i, a) {
var v = b.call(this, d, i);
- return v == null ? a != "" && d3_tweenRemove : a != v && interpolate(a, v);
+ return v == null ? a != "" && d3_tweenRemove : a != v && interpolate(a, v + "");
}
function tweenString(d, i, a) {
return a != b && interpolate(a, b);
View
2  d3.v2.min.js
1 addition, 1 deletion not shown
View
2  src/core/tween.js
@@ -4,7 +4,7 @@ d3.tween = function(b, interpolate) {
var v = b.call(this, d, i);
return v == null
? a != "" && d3_tweenRemove
- : a != v && interpolate(a, v);
+ : a != v && interpolate(a, v + "");
}
function tweenString(d, i, a) {
View
27 test/core/tween-test.js
@@ -0,0 +1,27 @@
+require("../env");
+
+var vows = require("vows"),
+ assert = require("assert");
+
+var suite = vows.describe("d3.tween");
+
+suite.addBatch({
+ "tween": {
+ "coerces constants to strings before interpolating": function() {
+ var t = d3.tween({toString: function() { return "#fff"; }}, d3.interpolate),
+ i = t(null, 0, "red");
+ assert.strictEqual(i(0), "#ff0000");
+ assert.strictEqual(i(.5), "#ff8080");
+ assert.strictEqual(i(1), "#ffffff");
+ },
+ "coerces function return values to strings before interpolating": function() {
+ var t = d3.tween(function(d) { return {toString: function() { return d; }}; }, d3.interpolate),
+ i = t("#fff", 0, "red");
+ assert.strictEqual(i(0), "#ff0000");
+ assert.strictEqual(i(.5), "#ff8080");
+ assert.strictEqual(i(1), "#ffffff");
+ }
+ }
+});
+
+suite.export(module);
Please sign in to comment.
Something went wrong with that request. Please try again.