Permalink
Browse files

Fix missing string coercion for d3.tween.

  • Loading branch information...
1 parent 78a0284 commit 428ea4ff924180768b138961f438c036f8ca99df @mbostock mbostock committed Sep 28, 2012
Showing with 30 additions and 3 deletions.
  1. +1 −1 d3.v2.js
  2. +1 −1 d3.v2.min.js
  3. +1 −1 src/core/tween.js
  4. +27 −0 test/core/tween-test.js
View
@@ -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

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -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
@@ -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);

0 comments on commit 428ea4f

Please sign in to comment.