1

I use dagre and d3 to display graphs. The graph elements and the viewport can be dragged, and zoomed. After dragging/zooming the viewport whenever I redraw the graph (or draw another graph) the viewport stays where it was set previously, but resets on first interaction (jumps to [0,0], and default zoom ratio).

How to reset position of the viewport in d3 with function call?

4spir
  • 1,174
  • 2
  • 15
  • 31

1 Answers1

2

Dagre author here - are you using the dagre demo or is this custom code? If you're using the dagre demo, I can confirm the behavior you're observing and the fix is to add this line:

svgGroup.attr("transform", "translate(5, 5)");

before this code block (dagre/demo.js, line 252 in my tree):

svg.call(d3.behavior.zoom().on("zoom", function redraw() {
    svgGroup.attr("transform",
          "translate(" + d3.event.translate + ")"
          + " scale(" + d3.event.scale + ")");
}));

I've updated the demo in the source code under this ticket: https://github.com/cpettitt/dagre/issues/56

Thanks!

Chris Pettitt
  • 814
  • 7
  • 9
  • hey Chris, can you take a peak on this question? I'd appreciate any help! http://stackoverflow.com/questions/26636878/position-of-a-custom-shape-using-dagre – pedrommuller Oct 29 '14 at 17:31