How to zoom the viewport to fit the nodes so they are placed in Spot.TopLeft instead of center?

I am trying to fit all my nodes into the top left position of the page when clicking a button.

I know I can do this:

function fitDiagram() {
  diagram.zoomToRect(diagram.documentBounds)
  diagram.centerRect(diagram.documentBounds)
}

But that will center my diagram, I want the end position to bring all my items into the top left position instead of the center.

Is there a method that can do that?

Try calling alignDocument, Diagram | GoJS API , instead of centerRect.