Fixed Bugs and styling
parent
f0991fdf56
commit
8ba1898656
|
|
@ -44,9 +44,11 @@ function reset!(U, V, heat_obs)
|
|||
heat_obs[] = copy(U)
|
||||
end
|
||||
|
||||
function param_box!(grid, row, labeltxt, observable::Observable)
|
||||
Label(grid[row, 1], labeltxt)
|
||||
box = Textbox(grid[row, 2], validator=Float64, width=50, placeholder=labeltxt, stored_string="$(observable[])")
|
||||
function param_box!(grid, row, labeltxt, observable::Observable; col=1)
|
||||
label_cell = 2 * col - 1
|
||||
textbox_cell = 2 * col
|
||||
Label(grid[row, label_cell], labeltxt)
|
||||
box = Textbox(grid[row, textbox_cell], validator=Float64, width=50, placeholder=labeltxt, stored_string="$(observable[])")
|
||||
on(box.stored_string) do s
|
||||
try
|
||||
observable[] = parse(Float64, s)
|
||||
|
|
@ -58,13 +60,6 @@ function param_box!(grid, row, labeltxt, observable::Observable)
|
|||
end
|
||||
|
||||
function rebuild_param_boxes!(grid, model_type::Symbol, param_obs_map::NamedTuple)
|
||||
for pos in keys(grid.content)
|
||||
if isa(pos, Tuple) && length(pos) == 2
|
||||
i, j = pos
|
||||
grid[i, j] = nothing
|
||||
end
|
||||
end
|
||||
|
||||
param_box!(grid, 1, "Du", param_obs_map.Du)
|
||||
param_box!(grid, 2, "Dv", param_obs_map.Dv)
|
||||
|
||||
|
|
@ -90,8 +85,12 @@ function build_ui(U, V, param_obs_map::NamedTuple, params_obs, heat_obs)
|
|||
|
||||
reset!(U, V, heat_obs)
|
||||
fig = Figure(size=(800, 800))
|
||||
|
||||
gh = GridLayout(fig[1, 1])
|
||||
ax = Axis(gh[1, 1])
|
||||
dropdown = Menu(fig, options=collect(zip(["Gray-Scott", "FHN"], [:gray_scott, :fhn])))
|
||||
gh[1, 1] = dropdown
|
||||
ax = Axis(gh[2, 1])
|
||||
|
||||
hm = Makie.heatmap!(ax, heat_obs, colormap=:viridis)
|
||||
deactivate_interaction!(ax, :rectanglezoom)
|
||||
ax.aspect = DataAspect()
|
||||
|
|
@ -102,7 +101,6 @@ function build_ui(U, V, param_obs_map::NamedTuple, params_obs, heat_obs)
|
|||
step_method = Observable{Function}(step_gray_scott!)
|
||||
|
||||
# Controls
|
||||
dropdown = Menu(fig, options=["Gray-Scott" => :gray_scott, "FHN" => :fhn])
|
||||
fig[2, 1] = buttongrid = GridLayout(ax.scene, tellwidth=false)
|
||||
btn_step = Button(buttongrid[1, 1], width=50, label="Step")
|
||||
btn_start = Button(buttongrid[1, 2], width=50, label=run_label)
|
||||
|
|
@ -111,10 +109,28 @@ function build_ui(U, V, param_obs_map::NamedTuple, params_obs, heat_obs)
|
|||
|
||||
speed_slider = slidergrid.sliders[1].value
|
||||
|
||||
gh[1, 2] = textboxgrid = GridLayout(ax.scene, tellwidth=false)
|
||||
rowsize!(gh, 1, Relative(1.0))
|
||||
rebuild_param_boxes!(textboxgrid, :gray_scott, param_obs_map)
|
||||
# place all the parameter boxes
|
||||
gh[2, 2] = textboxgrid = GridLayout(ax.scene, tellwidth=false)
|
||||
|
||||
param_box!(textboxgrid, 1, "Du", param_obs_map.Du, col=1)
|
||||
param_box!(textboxgrid, 2, "Dv", param_obs_map.Dv, col=1)
|
||||
param_box!(textboxgrid, 3, "Feed", param_obs_map.F, col=1)
|
||||
param_box!(textboxgrid, 4, "Kill", param_obs_map.k, col=1)
|
||||
|
||||
# FHN column (col 2)
|
||||
param_box!(textboxgrid, 1, "Du", param_obs_map.Du, col=2)
|
||||
param_box!(textboxgrid, 2, "Dv", param_obs_map.Dv, col=2)
|
||||
param_box!(textboxgrid, 3, "ϵ", param_obs_map.ϵ, col=2)
|
||||
param_box!(textboxgrid, 4, "a", param_obs_map.a, col=2)
|
||||
param_box!(textboxgrid, 5, "b", param_obs_map.b, col=2)
|
||||
|
||||
rowsize!(gh, 1, Fixed(50)) # small row for the menu
|
||||
rowsize!(gh, 2, Relative(1.0))
|
||||
for c in 1:4
|
||||
colsize!(textboxgrid, c, Relative(1.0 / 4.0))
|
||||
end
|
||||
|
||||
# Events ##############################################################
|
||||
# Timer and state for animation
|
||||
running = Observable(false)
|
||||
|
||||
|
|
@ -172,21 +188,21 @@ function build_ui(U, V, param_obs_map::NamedTuple, params_obs, heat_obs)
|
|||
heat_obs[] = copy(U)
|
||||
end
|
||||
|
||||
on(dropdown.selection) do sel_pair
|
||||
selected_model = sel_pair[2] # get :gray_scott or :fhn from ("Gray-Scott" => :gray_scott)
|
||||
on(dropdown.selection) do sel
|
||||
if sel isa Tuple
|
||||
label, selected_model = sel
|
||||
else
|
||||
selected_model = sel
|
||||
label = string(sel)
|
||||
end
|
||||
|
||||
@info "Selected model: $label → $selected_model"
|
||||
|
||||
# Safely assign correct function to step_method
|
||||
if haskey(STEP_FUNCTIONS, selected_model)
|
||||
step_method[] = STEP_FUNCTIONS[selected_model]
|
||||
else
|
||||
@warn "Unknown model selected: $selected_model"
|
||||
end
|
||||
|
||||
# Update param bindings and input fields
|
||||
lift(param_obs_map.N, param_obs_map.dx, param_obs_map.Du, param_obs_map.Dv, param_obs_map.F, param_obs_map.k, param_obs_map.ϵ, param_obs_map.a, param_obs_map.b) do N, dx, Du, Dv, F, k, ϵ, a, b
|
||||
params_obs[] = Constants.CombinedPDEParams(N, dx, Du, Dv, F, k, ϵ, a, b)
|
||||
end
|
||||
rebuild_param_boxes!(textboxgrid, selected_model, param_obs_map)
|
||||
end
|
||||
|
||||
return fig
|
||||
|
|
|
|||
Loading…
Reference in New Issue