At what time are you calling Diagram.alignDocument? If you are doing it immediately after setting Diagram.model with a model holding your node and link data, then I am guessing it is too early because the diagram hasn’t had time to finish measuring and arranging each node, perform layouts, route links, compute the document bounds, and scroll and zoom according to the various “initial…” Diagram properties.
Or are you setting Diagram.initialDocumentSpot and initialViewportSpot before setting the model? https://gojs.net/latest/intro/initialView.html That should work to do what I think you want.
Or did you have some more specific initial alignment criteria with respect to the viewport? In that case you should implement an “InitialLayoutCompleted” DiagramEvent listener that sets the Diagram.position the way that you want. This is when you can call Diagram.alignDocument, which is called automatically for you if you had set Diagram.initialDocumentSpot and Diagram.initialViewportSpot.