在D3.js中绑定到Object的内容是什么 [英] What does binding to Object do in D3.js

查看:123
本文介绍了在D3.js中绑定到Object的内容是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想了解 D3.js

var circle = interpolation.selectAll("circle")
    .data(Object);
circle.enter().append("circle")
    .attr("r", 4)
    .attr("fill","yellow");
circle
    .attr("cx", function y(d) { console.log(d.attr("class")); return d.x; })
    .attr("cy", function(d) { return d.y; });

这段代码的第二行是什么?它绑定到什么数据?

What does the second line of this code actually do? What data does it bind to?

推荐答案

上面的元素绑定的数据由函数 getLevels(d,t),其中 d 是范围2-4的数字, t 是从当前时间导出的数字。

The data bound in the element above that is given by the function getLevels(d, t), where d is a number of range 2 - 4 and t is a number derived from the current time.

这只会返回一个数组数组。由于数组已经是类型为Object ,因此数组上的调用对象()会返回原始数组。因此,从我可以看到,作者只是使用Object作为一种身份函数,类似于:

This only ever returns an array of arrays. Because an array is already of type Object, Calling Object() on an Array returns the original array.. Therefore, from what I can see, the author is simply using Object as a kind of identity function, similar to:

var identity = function(d){
  return d;
}

var circle = interpolation.selectAll("circle")
    .data(identity);
circle.enter().append("circle")
    .attr("r", 4)
    .attr("fill","yellow");
circle
    .attr("cx", function y(d) { console.log(d.attr("class")); return d.x; })
    .attr("cy", function(d) { return d.y; });

这篇关于在D3.js中绑定到Object的内容是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆