Skip to content
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

error when trying to visualize disjoint graphs #14

Closed
mantzaris opened this issue Aug 21, 2023 · 4 comments
Closed

error when trying to visualize disjoint graphs #14

mantzaris opened this issue Aug 21, 2023 · 4 comments

Comments

@mantzaris
Copy link

Whenever I try to visualize a graph that is disjoint (not every vertex is reachable from every other vertex), an error appears. Are such graphs supported?

g = star_graph(20);
rem_vertex!(g, 1)
@drawsvg begin
    background("black")
    sethue("white")
    drawgraph(g, layout=stress)
end
AssertionError: isfinite(s)

Stacktrace:
 [1] stress(positions::Vector{Point2{Float64}}, d::Matrix{Float64}, weights::Matrix{Float64})
   @ NetworkLayout ~/.julia/packages/NetworkLayout/bV9ek/src/stress.jl:191
 [2] iterate(iter::LayoutIterator{Stress{2, Float64, Symbol, Float64, Matrix{Float64}}, SparseArrays.SparseMatrixCSC{Int64, Int64}})
   @ NetworkLayout ~/.julia/packages/NetworkLayout/bV9ek/src/stress.jl:136
 [3] layout(alg::Stress{2, Float64, Symbol, Float64, Matrix{Float64}}, adj_matrix::SparseArrays.SparseMatrixCSC{Int64, Int64})
   @ NetworkLayout ~/.julia/packages/NetworkLayout/bV9ek/src/NetworkLayout.jl:79
 [4] layout(l::Stress{2, Float64, Symbol, Float64, Matrix{Float64}}, g::SimpleGraph{Int64})
   @ NetworkLayout ~/.julia/packages/NetworkLayout/bV9ek/src/NetworkLayout.jl:100
 [5] stress(g::SimpleGraph{Int64}; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
   @ NetworkLayout ~/.julia/packages/NetworkLayout/bV9ek/src/NetworkLayout.jl:234
 [6] stress
   @ ~/.julia/packages/NetworkLayout/bV9ek/src/NetworkLayout.jl:234 [inlined]
 [7] drawgraph(g::SimpleGraph{Int64}; boundingbox::Luxor.BoundingBox, layout::typeof(stress), margin::Int64, vertexfunction::Nothing, vertexlabels::Nothing, vertexshapes::Nothing, vertexshapesizes::Nothing, vertexshaperotations::Nothing, vertexstrokecolors::Nothing, vertexstrokeweights::Nothing, vertexfillcolors::Nothing, vertexlabeltextcolors::Nothing, vertexlabelfontsizes::Nothing, vertexlabelfontfaces::Nothing, vertexlabelrotations::Nothing, vertexlabeloffsetangles::Nothing, vertexlabeloffsetdistances::Nothing, edgelist::Nothing, edgefunction::Nothing, edgelabels::Nothing, edgelines::Nothing, edgecurvature::Float64, edgestrokecolors::Nothing, edgelabelcolors::Nothing, edgelabelfontsizes::Nothing, edgelabelfontfaces::Nothing, edgestrokeweights::Nothing, edgedashpatterns::Nothing, edgegaps::Nothing, edgelabelrotations::Nothing)
   @ Karnak ~/.julia/packages/Karnak/QQChO/src/drawgraph.jl:1042
 [8] macro expansion
   @ In[90]:4 [inlined]
 [9] top-level scope
   @ ~/.julia/packages/Luxor/tNuXK/src/drawings.jl:1593
@cormullion
Copy link
Owner

HI! I'm fairly sure this is a limitation of NetworkLayout.jl - it won't lay out certain graphs with certain algorithms. I think you could trigger this error with:

using Graphs, NetworkLayout
g = star_graph(20)
rem_vertex!(g, 1)
NetworkLayout.stress(g)

without Karnak.jl loaded.

@JackieChenYH
Copy link

Hello! I adjusted the example from the NetworkLayout.jl doc.
I can still plot the graph even having a node without connection to others.

using Graphs, GraphMakie.NetworkLayout

g = star_graph(20);
rem_edge!(g, 1, 6)
rem_vertex!(g, 19)
f, ax, p = graphplot(g)

Then I tried to use the

@drawsvg begin
    drawgraph(g)
end

It gives the same error code:

AssertionError: isfinite(s)

Is Karnak,jl support for graph that has disjoint node?

Thank you!

I've attached some screenshots for your reference.

Screenshot 2023-08-21 231803 Screenshot 2023-08-21 184814

The screenshot for the graph I am trying to visualize by using Karnak.jl:
Screenshot 2023-08-21 184157

@cormullion
Copy link
Owner

Hi Jackie!

Your code doesn't error:

Screenshot 2023-08-22 at 08 36 13

It can't emit that particular AssertionError, because nothing is calling NetworkLayout.stress().

If you ask for a spring layout, the call to NetworkLayout.spring works fine:

@drawsvg begin
    background("white")
    drawgraph(g, layout=spring)
end 400 400
Screenshot 2023-08-22 at 08 39 14

squaregrid will also work, as will drawgraph(g, layout=SFDP(Ptype=Float32)), but the stress layout won't, as far as I can tell.

I'm not a graph theorist, so I don't know whether "stress layouts" are not available for disjoint graphs, or whether it's a restriction of NetworkLayout.jl.

@mantzaris
Copy link
Author

Works great! thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants