0
我有這個問題之前&這是由於我的d3.select不符合我的attr。不過,我不從這個當前的bug收到任何錯誤,我也多少有些失落在我做了什麼錯條款:D3.Drag行爲與嵌套數據
var drag = d3.behavior.drag()
.origin(Object)
.on("drag", function(d, i) {
d.x = d3.event.x;
d.y = d3.event.y;
d3.select(this).attr("transform", "translate("+nodes[i].locations[0].x+","+nodes[i].locations[0].y+")");
});
正如你看到的,我要通過我的索引來查找所有的位置。這會影響拖動功能嗎?
var node = svg.selectAll("g.node")
.data(nodes)
node.enter().append("g")
.call(drag)
.attr('class', 'node');
node.attr("transform", function(d,i) { return"translate("+nodes[i].locations[0].x+","+nodes[i].locations[0].y+")"; })
我很困惑,爲什麼這不會工作
我也試圖改變我的ondrag當功能,但是當我試圖拖動它只能移動到中心
.on("drag", function(d, i) {
nodes[i].locations[0].x = d3.event.x;
nodes[i].locations[0].y = d3.event.y;
d3.select(this).attr("transform", "translate ("translate("+nodes[i].locations[0].x+","+nodes[i].locations[0].y+")");
// draw();
});
感謝節點。
好像你沒有在任何地方調用拖動行爲。你想做什麼? – 2013-04-29 10:30:26
Hi @Lars Kotthoff我以爲我在調用var節點上的拖動 - .call(拖動)。我只是試圖拖動我的對象在頁面周圍 – Jose 2013-04-29 14:56:56