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

Fix Makie issues #996

Merged
merged 10 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions examples/rabbit_fox_hawk.jl
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ function initialize_model(
end
for _ in 1:n_foxes
pos = random_walkable(model, model.landfinder)
add_agent!(pos, Rabbit, model, v0, rand(abmrng(model), Δe_rabbit:2Δe_rabbit))
add_agent!(pos, Fox, model, v0, rand(abmrng(model), Δe_rabbit:2Δe_rabbit))
Datseris marked this conversation as resolved.
Show resolved Hide resolved
end
for _ in 1:n_hawks
pos = random_walkable(model, model.airfinder)
Expand Down Expand Up @@ -371,24 +371,25 @@ model = initialize_model()
# ```

function animalcolor(a)
if kindof(a) == :rabbit
if kindof(a) === :Rabbit
:brown
elseif kindof(a) == :fox
elseif kindof(a) === :Fox
:orange
else
:blue
end
end

# We use `surface!` to plot the terrain as a mesh, and colour it using the `:terrain`
# colormap. Since the heightmap dimensions don't correspond to the dimensions of the space,
# we explicitly provide ranges to specify where the heightmap should be plotted.
function static_preplot!(ax, p)
const ABMPlot = Agents.get_ABMPlot_type()
function Agents.static_preplot!(ax::Axis3, p::ABMPlot)
surface!(
ax,
(100/205):(100/205):100,
(100/205):(100/205):100,
p.abmobs[].model.heightmap;
p.abmobs[].model[].heightmap;
colormap = :terrain
)
end
Expand All @@ -402,7 +403,6 @@ end
# framerate = 15,
# ac = animalcolor,
# as = 1.0,
# static_preplot!,
# title = "Rabbit Fox Hawk with pathfinding"
# )
# ```
Expand Down
8 changes: 7 additions & 1 deletion ext/AgentsVisualizations/src/abmplot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,13 @@ end
function Makie.plot!(p::_ABMPlot)
model = p.abmobs[].model[]
ax = p.ax[]
p.adjust_aspect[] && (ax.aspect = DataAspect())
if p.adjust_aspect[]
if ax isa Axis
ax.aspect = DataAspect()
elseif ax isa Axis3
ax.aspect = :data
end
end
set_axis_limits!(ax, model)

p.pos, p.color, p.marker, p.markersize =
Expand Down
8 changes: 5 additions & 3 deletions ext/AgentsVisualizations/src/spaces/abstract.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ Agents.agents_space_dimensionality(model::ABM) =

"Plot agents into a 2D space."
function Agents.agentsplot!(ax::Axis, p::ABMP)
if p._used_poly[]
poly!(p, p.marker; p.color, p.agentsplotkwargs...)
if user_used_polygons(p.am[], p.marker[])
poly!(p, p.marker; p.color, p.marker, p.markersize, p.agentsplotkwargs...)
else
scatter!(p, p.pos; p.color, p.marker, p.markersize, p.agentsplotkwargs...)
end
Expand All @@ -13,7 +13,9 @@ end

"Plot agents into a 3D space."
function Agents.agentsplot!(ax::Axis3, p::_ABMPlot)
p.marker[] == :circle && (p.marker[] = Sphere(Point3f(0), 1))
if p.am[] === :circle
p.am[], p.marker[] = :Sphere, Sphere(Point3f(0), 1)
end
meshscatter!(p, p.pos; p.color, p.marker, p.markersize, p.agentsplotkwargs...)
return p
end
Expand Down
Loading