admin管理员组

文章数量:1430358

I am quite new to d3.js. I am trying to understand the following code:

   .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;
       };
   });​

I want to see the value of var i, so if I am doing console.log(i), I am getting some equation returned. How can I see the interpolated value?

I am quite new to d3.js. I am trying to understand the following code:

   .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;
       };
   });​

I want to see the value of var i, so if I am doing console.log(i), I am getting some equation returned. How can I see the interpolated value?

Share Improve this question edited Jan 22, 2014 at 11:05 VividD 10.5k8 gold badges66 silver badges112 bronze badges asked Jan 14, 2014 at 12:48 user227666user227666 7844 gold badges18 silver badges34 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

The d3.interpolate method receives the beginning and end values of the transition, and returns an interpolator function. An interpolator function receives a value between 0 and 1, and returns the interpolated value. For instance:

// Create an interpolator function to pute 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

本文标签: javascriptDisplay value of d3interpolateStack Overflow