在D3中是否可以转换组?
使用方形或圆形,它可以这样工作:
mySquare
.transition()
.attr("x",320);
Run Code Online (Sandbox Code Playgroud)
但是,如果mySquare例如是对组("<g>")的引用,则它不起作用,可能是因为D3查找了我无法检索的组的x属性.
你能帮助我吗?我找不到任何关于这个主题的文档.
随着D3.js我要改造x一个的group多次(例如,通过点击一个按钮引起对每次点击的变换),从该组的当前位置开始.问题是我无法检索组中的x,即使我找到它,我也找不到任何内置函数,可以让我x从当前开始更改组x.我错过了重要的事吗?很奇怪我无法将x一个元素添加到SVG"舞台"中.
我的代码如下(为Lars编辑):我按照你昨天建议我的方式创建节点(克隆它们).
var m=[5,10,15,20,25,30];
var count=0;
d3.select('svg').on("mouseup", function(d, i){
count+=0.5;
var n = d3.selectAll(".myGroup");
n.each(function(d,i) {
if(i!=0){
// here I need to know the current x of the current n element but I
// can't get it
// this causes error "Uncaught TypeError: undefined is not a function"
// var currentx = d3.transform(this.attr("transform")).translate[0];
this.setAttribute("transform", "translate("+((100/m[i])*count)+",10)");
}
});
});
Run Code Online (Sandbox Code Playgroud)