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

Improve arg syntax for gplot and cleanup repo #180

Open
wants to merge 19 commits into
base: master
Choose a base branch
from

Conversation

hdavid16
Copy link
Contributor

@hdavid16 hdavid16 commented Jul 27, 2022

-breaking change: linetype changed from String to Symbol
-breaking change: default for edgelabel is nothing (not []) to make consistent with nodelabel default
-remove all caps args (Fix #177)
-improve some of the code in gplot (use isnothing, etc.)
-move layouts to layouts.jl
-add community_layout to readme
-remove deprecations
-remove shape.jl and pienode.jl (not used anywhere)

-distinguish args, kwargs
-add missing kwargs
clarify that Cairo is required to visualize in vscode
Checking for System OS was outdated
-allow gplothtml to accept same arguments as gplot
-allow x/y-locs to be of different type (<: Real)
and minor changes to plots.jl
update README
-breaking change: linetype changed from String to Symbol
-breaking change: default for edgelabel is nothing (not []) to make consistent with nodelabel default
-remove all caps args
-improve some of the code in gplot (use isnothing, etc.)
@codecov
Copy link

codecov bot commented Jul 27, 2022

Codecov Report

Merging #180 (1a945c4) into master (52f4aae) will increase coverage by 3.81%.
The diff coverage is 8.75%.

@@            Coverage Diff             @@
##           master     #180      +/-   ##
==========================================
+ Coverage   32.92%   36.73%   +3.81%     
==========================================
  Files           9        4       -5     
  Lines         565      471      -94     
==========================================
- Hits          186      173      -13     
+ Misses        379      298      -81     
Impacted Files Coverage Δ
src/GraphPlot.jl 100.00% <ø> (ø)
src/layout.jl 19.32% <0.00%> (-29.10%) ⬇️
src/plot.jl 58.66% <81.25%> (-3.98%) ⬇️
src/lines.jl 52.22% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us.

fix background color
-use `iszero`
-remove `stroke(nothing)` or `fill(nothing` as `nothing` is already the default for these functions in Compose.jl
-move layouts to layouts.jl
-add community_layout to readme
-remove deprecations
-remove shape.jl and pienode.jl (not used anywhere)
@hdavid16 hdavid16 changed the title Improve arg syntax for gplot Improve arg syntax for gplot and cleanup repo Jul 27, 2022
Multiple dispatch was messing up because types were not specified for spring layout and `kws` not preceeded by `;`
@@ -284,3 +284,288 @@ function _spectral(A::SparseMatrixCSC)
index = sortperm(real(eigenvalues))[2:3]
return real(eigenvectors[:, index[1]]), real(eigenvectors[:, index[2]])
end

# This layout algorithm is copy from [IainNZ](https://github.com/IainNZ)'s [GraphLayout.jl](https://github.com/IainNZ/GraphLayout.jl)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any advantage in moving this function? Maybe it would be easier to read if we keep it in a separate file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I figured that since we had a layout.jl file with several layouts, I'd just add it there. However, we could have a layout folder and have a separate file for each layout. What are your thoughts?

src/plot.jl Outdated
end
linetype = :straight,
outangle = π / 5,
backgroundc = nothing) where {T <:Integer, R1 <: Real, R2 <: Real}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be easier to review/write tests, if new features where in a separte PR

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I put it in a PR, but then built further from that one...oops. I'll wait for the background color PR to get merged.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed since this is done in a separate PR

"""
function gplot(g::AbstractGraph{T},
locs_x_in::Vector{R1}, locs_y_in::Vector{R2};
nodelabel = nothing,
nodelabelc = colorant"black",
nodelabelsize = 1.0,
NODELABELSIZE = 4.0,
max_nodelabelsize = 4.0,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally agree, that we should change this, but I think we should add deprecation warnings for the older functions (that we can eventually remove), or at least produce a meaningful error message.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok. will do

outangle = π / 5,
backgroundc = nothing) where {T <:Integer, R1 <: Real, R2 <: Real}

@assert length(locs_x_in) == length(locs_y_in) == nv(g) "Position vectors must be of the same length as the number of nodes"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should only use @assert in situations that we expect that they are always true, as it might be removed by a compiler optimization: https://docs.julialang.org/en/v1/base/base/#Base.@assert

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. I'll use the if -> error form for these.

if max_nodestrokelw > 0.0
max_nodestrokelw = EDGELINEWIDTH / max_nodestrokelw
nodestrokelw *= max_nodestrokelw
if !iszero(max_nodestrokelw)
Copy link
Contributor

@simonschoelly simonschoelly Jul 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would testing for max_nodestrokelw not make more sense in case that max_nodestrokelw is negative?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are just catching for divide by 0 errors here I think. Passing negative values should work, they just don't get displayed. However, we can check for all inputs being positive when we do the other checks at the beginning of the function if that would be better.

if !isempty(edgelabel) && length(edgelabel) != NE
error("Must have one label per edge (or none)")
end
linetype = :straight,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also here we should add a deprecation warning, if one uses a String

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes. will do

@hdavid16
Copy link
Contributor Author

This PR also fixes #148

This reverts commit 67bd950.
Remove commits that are in separate PRs
This reverts commit d4a2ae4ba42a701ebe49865d2addf212c54f7bd7.
Remove commits that are in separate PRs

This reverts commit d4a2ae4ba42a701ebe49865d2addf212c54f7bd7.
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

Successfully merging this pull request may close these issues.

Question: What is the point of NODELABELSIZE and other capitalized kwargs?
2 participants