Skip to content
Open
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
3 changes: 3 additions & 0 deletions changelog.d/398-plot-functions-throw-under-glmakie-when-.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Fixed

- Under GLMakie, a plot function called with `is_save=true, is_show=true` no longer throws `GLMakie can not display a scene in multiple Screens`: `save_plot` closes the hidden screen the save opened.
4 changes: 4 additions & 0 deletions ext/VortexStepMethodMakieExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ function VortexStepMethod.save_plot(fig::Makie.Figure, save_path, title; data_ty
@debug "Attempting to save figure to: $full_path"
@debug "Current working directory: $(pwd())"

screens_before_save = copy(fig.scene.current_screens)
try
save(full_path, fig)
@debug "Figure saved as $data_type"
Expand All @@ -508,6 +509,9 @@ function VortexStepMethod.save_plot(fig::Makie.Figure, save_path, title; data_ty
@error "Error saving figure: $e"
@error "Error type: $(typeof(e))"
rethrow(e)
finally
# GLMakie refuses to show a figure still held by the hidden screen `save` opened.
foreach(close, setdiff(fig.scene.current_screens, screens_before_save))
end
end

Expand Down
16 changes: 16 additions & 0 deletions test/plotting/test_plotting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,22 @@ end
@test isfile(joinpath(save_dir, "Hidden_combined.png"))
end

@testset "a plot saved under GLMakie can then be shown" begin
MakieControlPlots.GLMakie.activate!()
try
fig = plot_distribution([y_coordinates], [results_vsm], ["VSM"];
title="Saved then shown", data_type=".png", save_path=save_dir,
is_save=true, is_show=false)
@test isfile(joinpath(save_dir, "Saved_then_shown.png"))
makie_ext.display_named(fig, "Saved then shown")
@test fig.scene.current_screens == [makie_ext.SCREENS["Saved then shown"]]
finally
screen = pop!(makie_ext.SCREENS, "Saved then shown", nothing)
isnothing(screen) || close(screen)
CairoMakie.activate!()
end
end

@testset "round-off CS plots flat, a varying CS keeps its autoscale" begin
fig = Figure()
ax_noise = Axis(fig[1, 1])
Expand Down
Loading