https://github.com/mbostock/d3/pull/277
Mike
function myStyles(selection) {
selection
.style("stroke", "#000")
.style("fill", "#fff")
…
}
Then:
chart.selectAll("rect")
.data(data)
.enter().append("svg:rect")
.call(myStyles)
…
This lets you reuse attr and other operators too, of course.
Mike
function styles(styles) {
return function(selection) {
for (var property in styles) {
selection.style(property, styles[property]);
}
};
}
Which you can then use as:
d3.selectAll(".something").call(styles({fill: "red", stroke: 2}));
Mike