gpt4 book ai didi

javascript - 在 D3.js 中绑定(bind)到对象有什么作用

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:25:59 24 4
gpt4 key购买 nike

我正在尝试理解 this exampleD3.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; });

这段代码的第二行实际上做了什么?它绑定(bind)到什么数据?

最佳答案

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

这只会返回一个数组数组。因为数组是 already of type 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; });

关于javascript - 在 D3.js 中绑定(bind)到对象有什么作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16555857/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com