initialAutoScale only works when I have a diagram already open

for the first diagram i open, initialAutoScale set to go.Diagram.Uniform doesn’t work properly. this is true if i load the same diagram twice in my app. in the case where the initial scale is wrong, the diagram is zoomed out to its smallest possible size and put into the top left corner of the viewport. triggering the diagrams zoomToFit event after the diagram is loaded manually works, and the diagram is properly scaled.

i’m experiencing what appears to be a bug in how this functionality works in goJS, but I have no clue how to debug it. my stack trace is exactly the same in either case within my app. adding a diagram listener to DocumentBoundsChanged shows the exact same document bounds being changed. i can’t just trigger zoomToFit on the ‘InitialLayoutCompleted’ or ‘LayoutCompleted’ event or in angular’s AfterViewInit to workaround this instead of using initialAutoScale, it reproduces the issue (works for every diagram except the first).

i have to manually click zoom to fit. the confusing bit here is that the zooming happens after the diagram is loaded if i put my call to zoomtofit inside a settimeout in ngafterviewinit, but it still happens incorrectly. so i’m not sure what event I have to wait for and when the document is actually ready to be scaled.

My guess is that you are initializing the diagram before the HTMLDivElement has been sized correctly by the page layout. So at the time that the initial layout is completed, the viewport is not at its final size, so its rescaling is calculated correctly at that time but wrong for the ultimate size.

Try loading the model only after the Div has been given its laid-out size.

1 Like