diff --git a/Manifest.toml b/Manifest.toml index 7706479ff4fb185d0d95e71ec6333aa3d3b85684..8e99c921d51092c3f3cc1b2dc7ce64f5dadb6899 100644 --- a/Manifest.toml +++ b/Manifest.toml @@ -1411,11 +1411,11 @@ version = "2.7.2" [[deps.Persefone]] deps = ["Agents", "ArgParse", "CSV", "CairoMakie", "DataFrames", "DataFramesMeta", "Dates", "Distributed", "FileIO", "GeoArrays", "ImageMagick", "Logging", "LoggingExtras", "Pkg", "Random", "Serialization", "StableRNGs", "StatsBase", "TOML", "Test", "TiffImages"] -git-tree-sha1 = "88ace44808fa1050135c13c31baec6c94ba14f38" +git-tree-sha1 = "80a1b800473aff48d57c321505d77846fa04f66e" repo-rev = "master" repo-url = "../model" uuid = "039acd1d-2a07-4b33-b082-83a1ff0fd136" -version = "0.3.5" +version = "0.3.6" [[deps.Pixman_jll]] deps = ["Artifacts", "CompilerSupportLibraries_jll", "JLLWrappers", "LLVMOpenMP_jll", "Libdl"] diff --git a/src/GUI.jl b/src/GUI.jl index 4cab0ca966c5f85428add16eb6447828b4885382..89fed748580b488744e32e3558d61077b98c23a0 100644 --- a/src/GUI.jl +++ b/src/GUI.jl @@ -48,15 +48,16 @@ function saveoutput() visualiseoutput(model) GLMakie.activate!() # visualiseoutput() switches to Cairo end - + +# I'm reimplementing `visualisemap()` and populationtrends() here, because I need +# to use Observables to keep the figure updated (if I use multiple plots, I get a +# memory leak, see here: https://github.com/MakieOrg/Makie.jl/issues/795) + function render_map(screen) global model, mapimage launching[] && return display(screen, Figure().scene) # blank screen at launch println("Updating map") if isnothing(mapimage) - # I'm reimplementing `visualisemap()` here, because I need to use Observables - # to keep the figure updated (if I use multiple plots, I get a memory leak, - # see here: https://github.com/MakieOrg/Makie.jl/issues/795) landcover = rotr90(load(@param(world.landcovermap))) mapimage = Figure() ax = Axis(mapimage[1,1]) @@ -66,9 +67,6 @@ function render_map(screen) inds = @lift(@transform!(@subset(model.datatables["individuals"], :Date .== $date-Day(1)), :Y = size(landcover)[2] .- :Y)) - on(inds) do i - println("Updated `inds`, length $(size(inds[])[1])") - end if size(inds[])[1] > 0 update_theme!(palette=(color=cgrad(:seaborn_bright, length(@param(nature.targetspecies))),), @@ -76,9 +74,6 @@ function render_map(screen) for s in @param(nature.targetspecies) points = @lift(Matrix{Float32}( @select!(@subset($inds, :Species .== s), :X, :Y))) - on(points) do i - println("Updated `points` of species $s") - end scatter!(mapimage[1,1], points, markersize=8) end end @@ -87,12 +82,33 @@ function render_map(screen) end function render_plot(screen) - #FIXME Y axis is too small -> lines not shown? - global model + global model, plotimage launching[] && return display(screen, Figure().scene) # blank screen at launch println("Updating plot") - figure = populationtrends(model) - display(screen, figure.scene) + if isnothing(plotimage) + pops = @lift begin + $date #needed to activate the lift, doesn't do anything + model.datatables["populations"] + end + #XXX other colour schemes: :tab10, :Accent_8, :Dark2_8, :Paired_12, :Set1_9 + # https://juliagraphics.github.io/ColorSchemes.jl/stable/catalogue/ + update_theme!(palette=(color=cgrad(:seaborn_bright, + length(@param(nature.targetspecies))),), + cycle=[:color]) + plotimage = Figure() + dates = @param(core.startdate):@param(core.enddate) + axlimits = @lift((1, length(dates), 0, maximum($pops[!,:Abundance]))) + ax = Axis(plotimage[1,1], xlabel="Date", ylabel="Population size", + limits=axlimits, xticks=Persefone.gettickmarks(dates)) + for s in @param(nature.targetspecies) + points = @lift(Vector{Float32}(@subset($pops, :Species .== s).Abundance)) + iszero(size(points[])[1]) && continue + lines!(plotimage[1,1], points, linewidth=3, label=s) + end + #FIXME the legend does something weird when run live + size(pops[])[1] > 0 && axislegend("Species"; position=:lt) + end + display(screen, plotimage.scene) end on(delay) do d