Skip to content

Commit

Permalink
Merge pull request #22 from EcoJulia/prepare-sparse
Browse files Browse the repository at this point in the history
Compatibility with EcologicalNetworks.jl v0.4.0
  • Loading branch information
tpoisot authored Dec 1, 2020
2 parents a2209a9 + e5d9784 commit 307bb23
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 13 deletions.
5 changes: 3 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
name = "EcologicalNetworksPlots"
uuid = "9f7a259d-73a7-556d-a7a2-3eb122d3865b"
authors = ["Timothée Poisot <timothee.poisot@umontreal.ca>"]
version = "0.0.9"
version = "0.0.10"

[deps]
EcologicalNetworks = "f03a62fe-f8ab-5b77-a061-bb599b765229"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"

[compat]
EcologicalNetworks = "0.3"
EcologicalNetworks = "0.3, 0.4"
RecipesBase = "1.0"
StatsBase = "0.33"
julia = "1.3"
1 change: 1 addition & 0 deletions src/EcologicalNetworksPlots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ using EcologicalNetworks
using RecipesBase
using StatsBase
using Statistics
using SparseArrays

# Various layout manipulation functions
include(joinpath(".", "utilities.jl"))
Expand Down
22 changes: 15 additions & 7 deletions src/recipes.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
@recipe function f(network::T) where {T <: AbstractEcologicalNetwork}
if plotattributes[:seriestype] == :heatmap
network.A
end
if plotattributes[:seriestype] == :heatmap
if hasfield(T, :A)
network.A
else
network.edges
end
end
end

@recipe function f(layout::Dict{K,NodePosition}, network::T;
Expand All @@ -18,7 +22,11 @@ end
legend --> false

if typeof(network) <: QuantitativeNetwork
int_range = (minimum(filter(x -> x > 0.0, network.A)), maximum(network.A))
if hasfield(T, :A)
int_range = (minimum(filter(x -> x > 0.0, network.A)), maximum(network.A))
else
int_range = extrema(network.edges.nzval)
end
end

if get(plotattributes, :seriestype, :plot) == :plot
Expand All @@ -29,7 +37,7 @@ end
seriestype := :line
linecolor --> :darkgrey
if typeof(network) <: QuantitativeNetwork
linewidth --> EcologicalNetworksPlots.scale_value(interaction.strength, int_range, (0.5, 3.5))
linewidth --> EcologicalNetworksPlots._scale_value(interaction.strength, int_range, (0.5, 3.5))
end
if typeof(network) <: ProbabilisticNetwork
seriesalpha --> interaction.probability
Expand All @@ -44,12 +52,12 @@ end

if nodesize !== nothing
nsi_range = (minimum(values(nodesize)), maximum(values(nodesize)))
markersize := [EcologicalNetworksPlots.scale_value(nodesize[s], nsi_range, (2,8)) for s in species(network)]
markersize := [EcologicalNetworksPlots._scale_value(nodesize[s], nsi_range, (2,8)) for s in species(network)]
end

if nodefill !== nothing
nfi_range = (minimum(values(nodefill)), maximum(values(nodefill)))
marker_z := [EcologicalNetworksPlots.scale_value(nodefill[s], nfi_range, (0,1)) for s in species(network)]
marker_z := [EcologicalNetworksPlots._scale_value(nodefill[s], nfi_range, (0,1)) for s in species(network)]
end

if bipartite
Expand Down
8 changes: 4 additions & 4 deletions src/utilities.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function scale_value(k::T1, from::NTuple{2,T2}, to::NTuple{2,T3}) where {T1 <: Number, T2 <: Number, T3 <: Number}
function _scale_value(k::T1, from::NTuple{2,T2}, to::NTuple{2,T3}) where {T1 <: Number, T2 <: Number, T3 <: Number}
m, M = from
l, U = to
inter = (k-m)/(M-m)
Expand All @@ -24,12 +24,12 @@ function distribute_layout!(L, X::NTuple{2,T}, Y::NTuple{2,T}) where {T <: Numbe
range_x = (minimum(x), maximum(x))
range_y = (minimum(y), maximum(y))
for k in keys(L)
L[k].x = EcologicalNetworksPlots.scale_value(L[k].x, range_x, X)
L[k].y = EcologicalNetworksPlots.scale_value(L[k].y, range_y, Y)
L[k].x = EcologicalNetworksPlots._scale_value(L[k].x, range_x, X)
L[k].y = EcologicalNetworksPlots._scale_value(L[k].y, range_y, Y)
end
end

function spread_levels!(L; ratio::Float64=1.0)
function _spread_levels!(L; ratio::Float64=1.0)
for s in keys(L)
L[s].y *= ratio
end
Expand Down
4 changes: 4 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,7 @@ for s in species(Fweb)
end
plot(I, Fweb)
scatter!(I, Fweb)

heatmap(Unes)
savefig(joinpath(figpath, "heatmap.png"))
@test isfile(joinpath(figpath, "heatmap.png"))

2 comments on commit 307bb23

@tpoisot
Copy link
Member Author

@tpoisot tpoisot commented on 307bb23 Dec 1, 2020

Choose a reason for hiding this comment

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

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/25590

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.0.10 -m "<description of version>" 307bb23f20cc60cec5d8c46fce0fd8df460405d4
git push origin v0.0.10

Please sign in to comment.