You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The various layout algorithms usually do not have any preference with regard to the final "orientation" or "rotation" of the graph - on the other hand, it is often desirable to orient a graph layout to be primarily horizontal or vertical.
Arguably the simplest and cheapest approach(*) for this would be to compute the dipole moment of a vertex layout (i.e., p = ∑i (ri - rcom) with center of mass rcom = ∑iri and vertex positions ri). Recentering to rcom and rotating by -θ = -tan⁻¹(py/px) of ri then achieves alignment to e.g., the horizontal axis. This wouldn't work for symmetric graphs where p = 0 though.
Another option would be to compute the dipole moment based on edges rather than vertices, using p = ∑⟨ij⟩ (ri - rj) with ⟨ij⟩ denoting edges.
The dipole approach is simple to implement, but it's not clear to me what a good interface for this would be: if desired, should it be a keyword argument to existing layouts or should it be possible to nest layouts (e.g., Align(Stress(...), ...))?
(*) There's probably more sophisticated things that could be done. E.g., principle component analysis (PCA) would probably be better in case the layout has any significant "outlier" vertices. The principal axis would then correspond to the eigenvector associated with the largest eigenvalue of the covariance matrix C = ∑i (ri - rcom) (ri - rcom)T. This eigenvector could be computed by e.g., power iteration or the Lanczos method. The covariance matrix is 2×2 in 2D, so the eigendecomposition is cheap.
Aside from a better "global" view of the orientation of a layout, a benefit of a PCA approach is that it would treat symmetric graphs (zero dipole moment) properly. It's more expensive though - but maybeProbably worth it for generality.
The text was updated successfully, but these errors were encountered:
I like the feature idea! As I just wrote in #80 , I think nested layouts might be a good idea. Its easy to implement and works with all layouts then. On the negative side, this means it is and will be always "opt in" and might be harder to discover. But maybe still a good tradeoff?
thchr
added a commit
to thchr/NetworkLayout.jl
that referenced
this issue
Mar 28, 2025
The various layout algorithms usually do not have any preference with regard to the final "orientation" or "rotation" of the graph - on the other hand, it is often desirable to orient a graph layout to be primarily horizontal or vertical.
Arguably the simplest and cheapest approach(*) for this would be to compute the dipole moment of a vertex layout (i.e., p = ∑i (ri - rcom) with center of mass rcom = ∑i ri and vertex positions ri). Recentering to rcom and rotating by -θ = -tan⁻¹(py/px) of ri then achieves alignment to e.g., the horizontal axis. This wouldn't work for symmetric graphs where p = 0 though.
Another option would be to compute the dipole moment based on edges rather than vertices, using p = ∑⟨ij⟩ (ri - rj) with ⟨ij⟩ denoting edges.
The dipole approach is simple to implement, but it's not clear to me what a good interface for this would be: if desired, should it be a keyword argument to existing layouts or should it be possible to nest layouts (e.g.,
Align(Stress(...), ...)
)?(*) There's probably more sophisticated things that could be done. E.g., principle component analysis (PCA) would probably be better in case the layout has any significant "outlier" vertices. The principal axis would then correspond to the eigenvector associated with the largest eigenvalue of the covariance matrix C = ∑i (ri - rcom) (ri - rcom)T.
This eigenvector could be computed by e.g., power iteration or the Lanczos method.The covariance matrix is 2×2 in 2D, so the eigendecomposition is cheap.Aside from a better "global" view of the orientation of a layout, a benefit of a PCA approach is that it would treat symmetric graphs (zero dipole moment) properly.
It's more expensive though - but maybeProbably worth it for generality.The text was updated successfully, but these errors were encountered: