When I browse from one page of my application to the page that contains my diagram, the diagram is not centered.
However if I’m already on the page that contains the diagram and I hit F5, the diagram is centered just fine.
This gif illustrate the issue :
I’ve tried to add the following code in my digram init function but it does not change anything :
Browser : Chrome
GoJS version 2.1.30
GoJS-Angular version : 1.0.13
I understand what you are saying but I don’t see any reason why it ould resize on a page navigation and not on a page refresh as demonstrated in the GIF above.
The documentation you have linked mentions Internet Explore and older browsers, which is not my case though
If you are doing so before the Div has its final size, you could still run into this problem. Try adding an “InitialLayoutCompleted” DiagramEvent listener that logs the size of the Div – is that actually the size that you see in the page?
What happens if you set contentAlignment, instead of initialContentAlignment?
I suspect the issue is that the Diagram DIV is getting setup at a zero size (display hidden) or 1x1 size and then expanded, so any “initial” centering is insufficient, because it is centering to a small or nonexistent size instead of the expected expanded size.
This actually happens with our jQuery Tabs sample, and we ameliorate it by calling Diagram.delayInitialization after the tab has been clicked (after the Diagram DIV is the size it is going to be), like this:
$("#tabs").tabs({
activate: function(event, ui) {
// Needed the first time you tab to a tab with a Diagram in it,
// because the diagram in the tab had zero size while initializing:
if (ui.newTab[0].innerText === "GoJS Tab") { // The first tab with a Diagram in it
if (firstTime) {
myDiagram.delayInitialization(function() { myDiagram.requestUpdate(); });
firstTime = false;
}
myDiagram.requestUpdate();
} else if (ui.newTab[0].innerText === "GoJS 2") { // The second tab with a Diagram
if (firstTime2) {
myDiagram2.delayInitialization(function() { myDiagram.requestUpdate(); });
firstTime2 = false;
}
myDiagram2.requestUpdate();
}
}
});
Should you not wish to do that, you could also ask the Diagram to re-center when you click the button in your app that displays it, by calling,
I cannot do it on the button click because this button is on another page. It routes to the page that contains my diagram.
Again, the fact that it is centered when hitting F5 but not when coming from a different page of the app is strange.
I thought maybe it has to do with the Angular page init sequence. I’ve added the following code inside ngAfterViewInit :