function aFunction(d,i) {alert(d.data.key);}
cell.append("svg:text").attr("x", function(d) { return d.dx / 2; }).attr("y", function(d) { return d.dy / 2; }).attr("dy", ".35em").attr("text-anchor", "middle").text(function(d) { return d.children ? null : d.data.key; }).call(aFunction);
The `each` operator is the generic operator. It doesn't do anything by
default except call your function with the same arguments as other
operators. So, your `aFunction` will get called for each non-null
element in your selection, being passed the data `d` and index `i`.
The `this` context of your function will be the selected element (an
SVGTextElement).
The `call` operator is a way of grouping your code into reusable
blocks, in the same fashion as you calling a function yourself,
passing in the selection. The only difference is that you can use the
`call` operator with method chaining. Say for example I want to have a
reusable block of code which sets the "x" and "y" attributes:
function center(selection) {
selection
.attr("x", function(d) { return d.dx / 2; })
.attr("y", function(d) { return d.dy / 2; })
.attr("dy", ".35em")
.attr("text-anchor", "middle");
}
You can now call this function, passing in your selection:
cell.append("svg:text")
.call(center);
You can even pass in additional arguments to the `call` function (such
as `call(center, .5)`). And, you can use `call` with transitions as
well, which can be very convenient if you need to set a bunch of
attributes or styles on both selections and transitions.
Mike