javascript - Passing Object function into data() in d3 -
http://bl.ocks.org/mbostock/1134768
hey guys, i'm new javascript, , learning use d3 render data. i'm trying understand what's going on in code above, in particular, in snippet:
// add rect each date var rect = cause.selectall("rect") .data(object) // weird me.... .enter().append("svg:rect") .attr("x", function(d) { return x(d.x); }) .attr("y", function(d) { return -y(d.y0) - y(d.y); }) .attr("height", function(d) { return y(d.y); }) .attr("width", x.rangeband());
what's object constructor doing in .data()
? think data()
force evaluation of function, in effect object being created? why needed insert rectangle each element of each array in causes
?
see this answer.
it being used identity function - bound selection before, remains bound. pattern necessary because have call .data()
update selection.
personally dislike obfuscating code this; rather .data(function(d) { return d;})
obvious i'm doing there. ymmv.
Comments
Post a Comment