admin管理员组文章数量:1421009
I am trying to make a circle draggable.
var drag = d3.behavior.drag();
drag.on("drag", function(d,i) {
console.log(d);
d.x += d3.event.dx;
d.y += d3.event.dy;
//This will change the center coordinates by the delta
d3.select(this).attr("x", d.x).attr("y", d.y);
//This should change the upper left x and y values by the delta
d3.select(this).attr("transform", function(d,i){
return "translate(" + [ x,y ] + ")"
})
})
Here is the fiddle
It throws errors for every move on the right red circle, but how e it is saying that d
is undefined in lines 3, 4, and 5?
I am trying to make a circle draggable.
var drag = d3.behavior.drag();
drag.on("drag", function(d,i) {
console.log(d);
d.x += d3.event.dx;
d.y += d3.event.dy;
//This will change the center coordinates by the delta
d3.select(this).attr("x", d.x).attr("y", d.y);
//This should change the upper left x and y values by the delta
d3.select(this).attr("transform", function(d,i){
return "translate(" + [ x,y ] + ")"
})
})
Here is the fiddle
It throws errors for every move on the right red circle, but how e it is saying that d
is undefined in lines 3, 4, and 5?
2 Answers
Reset to default 5Working fiddle: http://jsfiddle/6a6da/33/
The d,i
arguments would usually refer to bound data, but you're not binding any data. In your case it's sufficient to work with only the event.
drag.on("drag", function() {
d3.select(this).attr("cx", +d3.select(this).attr("cx") + d3.event.dx);
d3.select(this).attr("cy", +d3.select(this).attr("cy") + d3.event.dy);
})l
Updated: http://jsfiddle/6a6da/32/
define d
as var d = d3.event;
.
Later on, though, x and y are undefined here: return "translate(" + [ x,y ] + ")"
. I'm not sure what you want to do there.
本文标签: javascriptWhy isnt d defined in d3behaviordrag()Stack Overflow
版权声明:本文标题:javascript - Why isnt `d` defined in d3.behavior.drag() - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745338615a2654157.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论