microsoft / automatic-graph-layout

A set of tools for graph layout and viewing
Other
1.34k stars 301 forks source link

Some nodes with no edges are not being grouped with others. #367

Open HaroldTexas opened 2 months ago

HaroldTexas commented 2 months ago

I'm using the MDS layout. Some but not all nodes with zero edges are being aligned to the right of the graph. Is this an known issue? NodesWithZeroEdges

levnach commented 2 months ago

No, it is not a known issue. It is really not clear where to put the isolated nodes. For other nodes their neighbors help in positioning. The only constraint for the disjoint nodes is to avoid the overlaps. Do you have a suggestion? I looked more carefully at the drawing and noticed the node in the left upper corner. If you lamp this not together with all other isolated nodes then the aspect ratio of the graph bounding box will be more than the current one. There's a packing algorithm that packs all connected components into a box, and tries to create this box with golden ratio. Every isolated node is a connected component: this explains the layout I believe.

HaroldTexas commented 2 months ago

If I leave off all the nodes that do not have an edge the bounding box is much smaller and the box sides are close to the nodes (small margin). So, there appears to be logic to increase the size of the bounding box so the edgeless nodes can be placed along the side. I'm thinking that logic could use the largest width of edgeless nodes (the height would be adjusted to keep the golden ratio). This would allow all the edgeless nodes to fit along the side. However, the sheer number of those nodes could run into a height issue. So, the height may have to be increased to handle the number of nodes. Although, there appears to be current logic that combines smaller nodes on the same line to prevent so many lines. Definitely not a simple problem.

levnach commented 1 month ago

Please try the following : shorten the labels of the isolated nodes in the left top corner. You can modify them as "First string\nSecond string". It will improve the layout I believe.

HaroldTexas commented 1 month ago

The layout is not always the same. Sometimes the nodes in the top left are shorter then ones along the right edge. I changed the layout packing method to columns. This prevented edgeless nodes from being placed on the same line. I'm not sure why the packing algorithm is creating 2 packages. There appears to be plenty of room along the right edge.

image