Search code examples
javascriptcanvasgojs

Drag canvas without content restriction


In a simple GoJS diagram, dragging the canvas allows us to move the entire graph. By default, you can only drag the canvas until the graph collides with the sides, so that the graph will never leave the canvas window.

How do I change the code to remove that restriction (ie, I can drag the canvas and the graph does not collide with the sides and exit the canvas window)?


Solution

  • One easy answer is to set https://gojs.net/latest/api/symbols/Diagram.html#scrollMode to go.Diagram.InfiniteScroll.

    $(go.Diagram, ..., {
        scrollMode: go.Diagram.InfiniteScroll,
        ...
      })
    

    Read more at https://gojs.net/latest/intro/viewport.html. Play at https://gojs.net/latest/samples/scrollModes.html.