diff --git a/Project.toml b/Project.toml index 3e610c9..dd0f78c 100644 --- a/Project.toml +++ b/Project.toml @@ -1,17 +1,18 @@ name = "EcologicalNetworksPlots" uuid = "9f7a259d-73a7-556d-a7a2-3eb122d3865b" authors = ["Timothée Poisot "] -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" diff --git a/src/EcologicalNetworksPlots.jl b/src/EcologicalNetworksPlots.jl index 8528122..5ed1a60 100644 --- a/src/EcologicalNetworksPlots.jl +++ b/src/EcologicalNetworksPlots.jl @@ -4,6 +4,7 @@ using EcologicalNetworks using RecipesBase using StatsBase using Statistics +using SparseArrays # Various layout manipulation functions include(joinpath(".", "utilities.jl")) diff --git a/src/recipes.jl b/src/recipes.jl index 941fc9e..436490d 100644 --- a/src/recipes.jl +++ b/src/recipes.jl @@ -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; @@ -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 @@ -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 @@ -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 diff --git a/src/utilities.jl b/src/utilities.jl index 186ffee..dbdc3ff 100644 --- a/src/utilities.jl +++ b/src/utilities.jl @@ -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) @@ -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 diff --git a/test/runtests.jl b/test/runtests.jl index 383972c..a0d33f2 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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")) \ No newline at end of file