d3.js - Javascript - function argument -
i learning javascript, , bit confused below usage. these question may more javascript d3 specific.
http://mbostock.github.com/d3/ex/sunburst.html
var arc = d3.svg.arc() .startangle(function(d) { return d.x; }) .endangle(function(d) { return d.x + d.dx; }) .innerradius(function(d) { return math.sqrt(d.y); }) .outerradius(function(d) { return math.sqrt(d.y + d.dy); }); so,
- startangle, endangle etc takes function argument. rationale being argument function rather number?
- in full code, no "d" defined.i see in of d3 programs. "d" for? how set or passed?
thanks.
to first question:
the d3.svg.arc object used create slices inside pie diagram. each of these slices needs different start- , end-angle displayed properly.
in d3.js not pass in both angles each slice, provide function, takes 1 argument d, corresponding data element slice , returns angles. same holds other parameters set here.
another advantage is, datum can consist of multiple properties , can decide property takes part respect visualization.
your second question
when using function parameter function, common use function expression of given form. in d3.js functions, serve parameters, passed in 1 or 2 parameters (most of time part of data, needs transformed). in function expression need (or @ least should) name parameters in order address them. of time in example d used parametername parameter holding specific data item.
it doesn't need defined elsewhere normal function parameter. if wish, rewrite in following way:
function startangleparam( d ) { return d.x; } var arc = d3.svg.arc() .startangle( startangleparam ) ...
Comments
Post a Comment