在D3.js中绑定到Object的内容是什么

Bru*_*ill 4 javascript d3.js

我试图理解这个例子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; });
Run Code Online (Sandbox Code Playgroud)

这段代码的第二行实际上做了什么?它绑定了哪些数据?

min*_*omi 6

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

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

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; });
Run Code Online (Sandbox Code Playgroud)