2

我正在尝试绘制点并添加它们的抖动。这些点有文本标签,所以一旦我计算出抖动的点位置,我想保存它并将其用作文本标签。我正在考虑为每个点添加一个新的 jitter 属性,然后使用它来设置 cx(点)和 x(标签):

# compute the jittered positions
points.attr("x_jitter", function (d){
    return x_scale(d.x) + my_random_jitter_function()
});    
# set them to the points and the labels
points.attr("cx", function (d, i){
    return points.attr("x_jitter")
});
text_labels.attr("x", function(d, i){
    return points.attr("x_jitter")
});

有没有更好的办法?

4

1 回答 1

3

我会做

points.each(function(d,i) {
  d.jitter = xscale(d.x) + random_jitter();
})
points.attr("cx", function(d,i) { return d.jitter });
text_labels.attr("x", function(d,i) { return d.jitter });
于 2013-06-13T18:48:21.863 回答