Instead of adding methods to d3.selection
, make a transform its own object that you can define independently of a selection. So this...
d3.selectAll("g.label")
.translate(function(d) { return [20,d.x*10]})
.rotate(40)
.scale(function(d) {return [d.size,2]})
... would turn into this: