Given a datum containing multiple data elements, such as an object or array, is it possible to set multiple attributes on a selection with a single value function?
E.g. something like:
var data = [{ 'x': 10, 'y': 20, 'r': 5 }];
d3.select('body').append('svg').selectAll('circle')
.data(data)
.enter().append('circle')
.attr('cx cy r', function (d) {
return [d.x, d.y, d.r];
});
instead of:
var data = [{ 'x': 10, 'y': 20, 'r': 5 }];
d3.select('body').append('svg').selectAll('circle')
.data(data)
.enter().append('circle')
.attr('cx', function (d) {
return d.x;
});
.attr('cy', function (d) {
return d.y;
});
.attr('r', function (d) {
return d.r;
});
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…