显示d3.interpolate的值

use*_*666 2 html javascript jquery transition d3.js

我很新d3.js.我想了解以下代码:

   .tween("text", function(d) {
       var i = d3.interpolate(this.textContent, d),
           prec = (d + "").split("."),
           round = (prec.length > 1) ? Math.pow(10, prec[1].length) : 1;

       console.log(i);

       return function(t) {
           this.textContent = Math.round(i(t) * round) / round;
       };
   });?
Run Code Online (Sandbox Code Playgroud)

我希望看到它的价值var i,所以如果我这样做console.log(i),我会得到一些等式返回.如何查看插值?

Pab*_*rro 7

d3.interpolate方法接收的过渡的开始和结束时的值,并返回一个内插器的功能.内插器函数接收0到1之间的值,并返回内插值.例如:

// Create an interpolator function to compute intermediate colors between blue and red
var i = d3.interpolate('blue', 'red');

// Evaluate the interpolator
console.log(i(0.0));  // #0000ff - blue
console.log(i(0.4));  // #cc0033 - purple
console.log(i(1.0));  // #ff0000 - red
Run Code Online (Sandbox Code Playgroud)