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

add backend and update_state kwargs to show #4558

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## [Unreleased]

- Added `backend` and `update_state` kwargs to `show` [#4558](https://github.com/MakieOrg/Makie.jl/pull/4558)
- Fix uint16 overflow for over ~65k elements in WGLMakie picking [#4604](https://github.com/MakieOrg/Makie.jl/pull/4604).
- Improve performance for line plot in CairoMakie [#4601](https://github.com/MakieOrg/Makie.jl/pull/4601).
- Prevent more default actions when canvas has focus [#4602](https://github.com/MakieOrg/Makie.jl/pull/4602).
Expand Down
5 changes: 2 additions & 3 deletions src/display.jl
Original file line number Diff line number Diff line change
Expand Up @@ -244,17 +244,16 @@ function Base.show(io::IO, m::MIME"text/markdown", fig::FigureLike)
throw(MethodError(show, io, m, fig))
end

function Base.show(io::IO, m::MIME, figlike::FigureLike)
function Base.show(io::IO, m::MIME, figlike::FigureLike; backend = current_backend(), update_state=true)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think just update would be better since that's what we use in display()

if ALWAYS_INLINE_PLOTS[] == false && m isa MIME_TO_TRICK_VSCODE
# We use this mime to display the figure in a window here.
# See declaration of MIME_TO_TRICK_VSCODE for more info
display(figlike)
return () # this is a diagnostic vscode mime, so we can just return nothing
end
scene = get_scene(figlike)
backend = current_backend()
# get current screen the scene is already displayed on, or create a new screen
update_state_before_display!(figlike)
update_state && update_state_before_display!(figlike)
screen = getscreen(backend, scene, Dict(:visible=>false), io, m)
backend_show(screen, io, m, scene)
return screen
Expand Down
7 changes: 7 additions & 0 deletions test/figures.jl
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,10 @@ end
@test_throws ArgumentError lines(f[1, 1], 1:10, axis = (aspect = DataAspect()))
@test_throws ArgumentError lines(f[1, 1][2, 2], 1:10, axis = (aspect = DataAspect()))
end

@testset "show with a backend" begin
fig = Figure()
io = IOBuffer()
# if there were no show method with backend and update_state kwargs then MethodError would be thrown instead
@test_throws ErrorException show(io, MIME"text/plain"(), fig, backend=missing, update_state=missing)
end
Loading