I am trying to understand the D3.js
code for this example and am confused by this code:
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?
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.
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; });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With