Center align goJs diagram on load

HI there. I would like to center align my goJs diagram upon load. Currently, the 1st load bottom-left aligns the diagram. Subsequent loads bring it to center of the canvas as expected. Below is the screenshot of the issue and expected behavior.
Please assist.

Set Diagram.initialContentAlignment.

I think you would be more productive if you read http://gojs.net/latest/learn/index.html and the pages of the Introduction, http://gojs.net/latest/intro.

Hi Walter, property Diagram.initialContentAlignment is already set to go.Spot.Center.
Still the initial load does not center align. Do we have any other property to be set ?

How wide is the HTML Div element that the Diagram is in?

Have you set Diagram.padding to unusual values? Or have you set Diagram.fixedBounds?

Can you tell us how to reproduce the problem?

Hi Walter,

Div size is 500 x 700px. There is not padding & fixedBounds set.
The implementation is simple. On html body load, I am calling the init function with below attributes set.

initialContentAlignment: go.Spot.Center,
layout: $(go.LayeredDigraphLayout, { isInitial: false, isOngoing: false, layerSpacing: 50 }),
allowDrop: true, // must be true to accept drops from the Palette
allowDragOut: true,
isReadOnly: true,
“LinkDrawn”: showLinkLabel, // this DiagramEvent listener is defined below
“LinkRelinked”: showLinkLabel,
“animationManager.duration”: 800, // slightly longer than default (600ms) animation
“undoManager.isEnabled”: true // enable undo & redo

I’m sorry, but how can we reproduce the problem? There are dozens of examples that initialize their Diagrams in the manner that you partially show, and they start off with their document centered in the viewport.

Maybe the HTML DIV element starts off zero-sized and then changes size later? Read http://gojs.net/latest/intro/resizing.html and then call Diagram.alignDocument with arguments (go.Spot.Center, go.Spot.Center).

Hi Walter, At present I do not have solid steps to reproduce this issue. I will try creating another project with same params and see if the issue persists.
Thank you for your input on this.

I updated my reply after I thought of one possibility.

Perfect. This fixed my issue. Thanks for all your support. :smile: