Hi there! I have a Layered Digraph Layout with several layers of group nesting. Everything is working fine except that in some layouts, when all subgroups are expanded, some of the nodes are set very far apart from one another with very long links. I have tweaked various layout settings found in LayeredDigraphLayout but nothing seems to work.
let myDiagram =
$(go.Diagram,
{
layout: $(go.LayeredDigraphLayout,
{
// for layout options, see https://gojs.net/latest/api/symbols/LayeredDigraphLayout.html
layerSpacing: 5,
columnSpacing: 5,
direction: 90
}),
initialAutoScale: go.Diagram.UniformToFill,
allowCopy: false,
allowDelete: false,
// feedback that dropping in the background is not allowed
mouseDragOver: function (e) {
e.diagram.currentCursor = "not-allowed";
},
"undoManager.isEnabled": true,
maxSelectionCount: 1, // no more than 1 element can be selected at a time
contentAlignment: go.Spot.Center,
});
And here is my group:
return $(go.Group, "Auto",
{ // define the group's internal layout
layout: $(go.LayeredDigraphLayout,
{
layerSpacing: 30,
columnSpacing: 30,
direction: 90
}),
toolTip: nodeToolTip,
// the group begins unexpanded;
// upon expansion, a DiagramWrapper Listener will generate contents for the group
isSubGraphExpanded: false,
// when a group is expanded, if it contains no parts, generate a subGraph inside of it
subGraphExpandedChanged: function(group) {
// When group is expanded, hide the original group node; restore it upon collapse
var shp;
if (group.isSubGraphExpanded){
shp = group.findObject(NodeConstants.NODE_SHAPE);
if (shp != null) {
shp.opacity = 0;
}
shp = group.findObject(NodeConstants.NODE_TEXT);
if (shp != null) {
shp.opacity = 0;
}
} else {
shp = group.findObject(NodeConstants.NODE_SHAPE);
if (shp != null) {
shp.opacity = 1;
}
shp = group.findObject(NodeConstants.NODE_TEXT);
if (shp != null) {
shp.opacity = 1;
}
group.opacity = 1;
}
myDiagram.zoomToFit();
}
},
That doesn’t look too bad. The only obvious problem is that you are calling Diagram.zoomToFit repeatedly as groups are expanded. It would be better to put that in a “SubGraphExpanded” DiagramEvent listener, which will be called only once after one (or more) groups are expanded.
So I cannot explain the problem. How can I reproduce the problem?