-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reducing edge crossings #199
Comments
Hey, do you have an MWE for this? There are a bunch of layout algorithms in NetworkLayout.jl as you might have seen...maybe you want https://juliagraphs.org/NetworkLayout.jl/dev/#Buchheim-Tree-Drawing instead if your graph is hierarchical in some way? |
I don't, but could try to make one if that'd help - what would an MWE look like for this? Just a simple graph that has crossings? |
A graph that replicates all the properties you mention in the issue:
would be a good first MWE, I think. Maybe just export the data you use to plot this somehow (could use JLD2 if the types aren't too esoteric/custom, otherwise just CSV for the attributes + some graph? See https://juliagraphs.org/Graphs.jl/stable/first_steps/persistence/ for info on how to save graphs. |
Hopefully this works, this is the basic graph. To get this plot the code I used is here (basically it is wrapped in a type that allows plotting multiple edges, but that's not needed for this one). |
Not on my computer so I cannot check your code right now. But did you try 'Stress' Layout? In my experience it is much better at entangeling, should probably replace spring as the default in the next breaking release. Also, if your graph does not change, check out the pin and startpos keyword arguments for finetuning of layouts as well as trying random seeds. |
EDIT: Nevermind, you Graph isn't a DAG. Dot from GraphViz seems to be some optimization algo. The closest to that in Julia might be LayeredLayouts.jl with the zarate layout. Here is an example in the GraphMakie docs which uses this solver. This algorithm actually minimizes the Crossings but gets very slow for large graphs. |
When I tried The pin and startpos tips are very helpful, thank you very much.
|
Stress throwing an AssertionError is not good, I'd like to check on the graph and try to fix it in NetworkLayout.
|
Though come to think of it, is there a way to implement |
Hm in some sense the layout tries to keep neighbors close. If you have a disconnected graph, this logic does not work anymore because it would "blow away" the different parts. I think you'd need to build your own layout function function mylayout(g::SimpleGraph)
# do something with g, might call `Stress()(g_sub)` on the connected subgraphs `g_sub`
return positions
end Two options come to mind:
|
Looking at the code for |
I created a PR which extends It adds pairwise "ideal" distances between the unconnected vertices (before those where
using CairoMakie,GraphMakie,NetworkLayout
sgkeys = [:bull, :chvatal, :cubical, :desargues,
:diamond, :dodecahedral, :frucht, :heawood,
:house, :housex, :icosahedral, :karate, :krackhardtkite,
:moebiuskantor, :octahedral, :pappus, :petersen,
:sedgewickmaze, :tetrahedral, :truncatedcube,
:truncatedtetrahedron, :truncatedtetrahedron_dir, :tutte]
gs = filter(!is_directed, smallgraph.(sgkeys))
absdim = mapreduce(nv, +, gs)
adj = zeros(Int, absdim, absdim);
let i = 1
for g in gs
r = i:i+nv(g)-1
adj[r, r] .= adjacency_matrix(g)
i += nv(g)
end
end
g = SimpleGraph(adj)
graphplot(g; layout=Stress())
|
Sorry for the very belated reply. The intergraph distances seem to work quite well to me, but for larger node labels the subgraphs themselves seem to tend to get somewhat crowded (though this seems to happen for some of the other network layouts too, not just |
Thanks for the feedback on the spacing! In theory, it is possible to build layouts which respect nodesize. I think some of them might actually have the option for that (buchheim tree drawing takes a |
[question/feature request]
Hi, thank you for making this package. I am wondering whether there is some way to reduce the number of edge crossings in generated graphs? I have the following graph which should be "disentanglable" but ends up having a lot of crossings when laid out using
Spring()
. Is there some option that would reduce it (something similar todot
in Graphviz maybe)? Or a recommended layout option that would reduce it?Basically I am wondering whether there is some generalizable approach here. The context is that this is a function that will produce a graph visualization for a reaction network, so I am hoping for something that would work for a wide range of graphs.
The text was updated successfully, but these errors were encountered: