Skip to content
This repository has been archived by the owner on Jun 21, 2024. It is now read-only.

Commit

Permalink
Fix step button in interactive app (#71)
Browse files Browse the repository at this point in the history
* Fix step button in interactive app

* Update collected data on step.clicks

* Bump patch version number
  • Loading branch information
fbanning committed Aug 6, 2021
1 parent 1e1f65c commit 54deb6e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "InteractiveDynamics"
uuid = "ec714cd0-5f51-11eb-0b6e-452e7367ff84"
repo = "https://github.com/JuliaDynamics/InteractiveDynamics.jl.git"
version = "0.17.1"
version = "0.17.2"

[deps]
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
Expand Down
31 changes: 22 additions & 9 deletions src/agents/interactive_parameters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ function abm_data_exploration(
Axis(figure)
end

# initialize the ABM plot stuff
# Initialize the ABM plot stuff
abmstepper = abm_init_stepper_and_plot!(abmax, figure, model; kwargs...)
speed, slep, run, reset, update = abm_controls_play!(figure, model, spu, true)
speed, slep, step, run, reset, update = abm_controls_play!(figure, model, spu, true)

# Initialize parameter controls & data plots
datalayout = figure[:, 2] = GridLayout(tellheight = false)
Expand All @@ -93,7 +93,20 @@ function abm_data_exploration(
)
end

# Running the simulation:
# Clicking the step button
on(step) do clicks
n = speed[]
Agents.step!(abmstepper, model, agent_step!, model_step!, n)
if L > 0
s += n
if L > 0 && Agents.should_we_collect(s, model, when) # update collected data
push!(N.val, s)
update_abm_data_plots!(data, axs, model, df_agent, df_model, adata, mdata, N)
end
end
end

# Clicking the run button
isrunning = Observable(false)
on(run) do clicks; isrunning[] = !isrunning[]; end
on(run) do clicks
Expand All @@ -113,19 +126,19 @@ function abm_data_exploration(
end
end

# Clicking the update button:
on(update) do clicks
model = modelobs[]
update_abm_properties!(model, slidervals)
end

# Clicking the reset button
on(reset) do clicks
modelobs[] = deepcopy(model0)
Agents.step!(abmstepper, model, agent_step!, model_step!, 0)
L > 0 && add_reset_line!(axs, s)
update[] = update[] + 1 # also trigger parameter updates
end

# Clicking the update button
on(update) do clicks
model = modelobs[]
update_abm_properties!(model, slidervals)
end

display(figure)
return figure, df_agent, df_model
Expand Down

0 comments on commit 54deb6e

Please sign in to comment.