0

My force layout graph is construct by d3.js. I want add zoom and pan to my force graph. I have access to relevant information,and the zoom and pan works.But it bring new problem when I try to drag the node to somewhere only make the whole graph panning,the before node drag function is does not works. The approach I taken is Here

I find the key point is the

.call(d3.behavior.zoom().on("zoom", redraw))
.append('svg:g');

but when I delete .append('svg:g'); the zoom and pan not working again. So how can I keep these functions(zoom and pan,node drag) at the same time.

I need the effort like this jsFiddle,I follow this method to my own project but it does not works,I don't konw if I missing something.

Community
  • 1
  • 1
lazybios
  • 479
  • 8
  • 15
  • Your jsfiddle works fine for me. – Lars Kotthoff May 24 '14 at 11:40
  • Define "does not work", it works for me. What browser is affected? Are you using the latest D3.js library? – Lekensteyn May 24 '14 at 13:18
  • @Lekensteyn Yes,it works fine ,but that not mine.I find it in the other stackoverflow anwser [Here](http://stackoverflow.com/questions/7871425/is-there-a-way-to-zoom-into-a-d3-force-layout-graph) But in my project it does not work. I want to know Why? and what decide the drag function? – lazybios May 24 '14 at 14:30
  • @lazybios Could you provide a minimal example that exposes the problem? Be aware that in d3.js, `foo.call(bar)` is equivalent to `bar(foo)` and that drag and zoom/pan cannot be applied to the same element. You probably want to make just the nodes draggable while allowing pan/zoom on the svg element. – Lekensteyn May 24 '14 at 15:42

1 Answers1

0

This seems to work only on older versions. E.g. http://d3js.org/d3.v2.js works but dragging does not work properly on http://d3js.org/d3.v3.js.

Matthias
  • 178
  • 2
  • 6