JuliaGraphs / NetworkLayout.jl

Layout algorithms for graphs and trees in pure Julia.
Other
97 stars 22 forks source link

Feature request: layouts for weighted graphs #63

Open vandenman opened 8 months ago

vandenman commented 8 months ago

If one has a weighted graph, would it make sense for the layout algorithm to account for the weights?

This is done in, for instance, the R package qgraph.

Perhaps I'm viewing this too simplistically, but I think that all that needs to be done is multiply by the weights at some point. For example, in the Spring layout, there is now

https://github.com/JuliaGraphs/NetworkLayout.jl/blob/6574223d3c915c82695761a7c1318779f498f155/src/spring.jl#L95-L102

where, if I understand the code correctly, this line F_d = d / K - K^2 / d^2 could be changed to account for the weight of the edge. One option is to simply weigh the attraction by the (normalized) edge strength, which is I think what qgraph does (see https://github.com/cran/qgraph/blob/57d588ee05a554f9d1078914e05ce03662c610b2/src/layout_rcpp.cpp#L111).

Any thoughts? I'd be happy to open a draft PR for a single layout (e.g., spring).

hexaeder commented 8 months ago

Sounds reasonable! I think what you say is exactly right, you probably only need to add edgewights and nodeweights to the struct field and to the constructor, normalize and weight the forced accordingly. PRs welcome!