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?
1 Answer
Reset to default 7The 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
版权声明:本文标题:javascript - Display value of d3.interpolate - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745555474a2663160.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论