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

cannot add a colorbar to a WGLMakie 2d plot #2488

Closed
t-bltg opened this issue Dec 12, 2022 · 9 comments
Closed

cannot add a colorbar to a WGLMakie 2d plot #2488

t-bltg opened this issue Dec 12, 2022 · 9 comments

Comments

@t-bltg
Copy link
Collaborator

t-bltg commented Dec 12, 2022

MRE (also testing against #2428, errors out too), works in CairoMakie (untested GLMakie):

julia> using JSServe, Markdown, WGLMakie
julia> Page(exportable=true, offline=true)
julia> WGLMakie.activate!()
julia> fig, ax, plot = scatter(0:1)
julia> Colorbar(fig[1, 2]; label = "vertical cbar")
julia> display(fig)  # superfluous I guess
ERROR: TypeError: scene is undefined
Stacktrace:
  [1] error(s::String)
    @ Base ./error.jl:35
  [2] evaljs_value(session::Session, js::JSServe.JSCode; error_on_closed::Bool, time_out::Float64)
    @ JSServe ~/.julia/packages/JSServe/kIK9q/src/session.jl:238
  [3] evaljs_value
    @ ~/.julia/packages/JSServe/kIK9q/src/session.jl:206 [inlined]
  [4] insert!(td::WGLMakie.ThreeDisplay, scene::Scene, plot::Poly{Tuple{Vector{GeometryBasics.HyperRectangle{2, Float32}}}})
    @ WGLMakie ~/.julia/packages/WGLMakie/L5URO/src/three_plot.jl:24
  [5] insert!(td::WGLMakie.Screen, scene::Scene, plot::Poly{Tuple{Vector{GeometryBasics.HyperRectangle{2, Float32}}}})
    @ WGLMakie ~/.julia/packages/WGLMakie/L5URO/src/display.jl:173
  [6] push!(scene::Scene, plot::Poly{Tuple{Vector{GeometryBasics.HyperRectangle{2, Float32}}}})
    @ Makie ~/.julia/packages/Makie/Ggejq/src/scenes.jl:409
  [7] plot!(scene::Scene, P::Type{Poly{Tuple{Vector{GeometryBasics.HyperRectangle{2, Float32}}}}}, attributes::Attributes, input::Tuple{Observable{Vector{GeometryBasics.HyperRectangle{2, Float32}}}}, args::Observable{Tuple{Vector{GeometryBasics.HyperRectangle{2, Float32}}}})
    @ Makie ~/.julia/packages/Makie/Ggejq/src/interfaces.jl:421
  [8] plot!(scene::Scene, P::Type{Poly}, attributes::Attributes, args::Observable{Vector{GeometryBasics.HyperRectangle{2, Float32}}}; kw_attributes::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ Makie ~/.julia/packages/Makie/Ggejq/src/interfaces.jl:335
  [9] plot!
    @ ~/.julia/packages/Makie/Ggejq/src/interfaces.jl:302 [inlined]
 [10] #plot!#165
    @ ~/.julia/packages/Makie/Ggejq/src/interfaces.jl:286 [inlined]
 [11] poly!(::Scene, ::Vararg{Any}; attributes::Base.Pairs{Symbol, Any, Tuple{Symbol, Symbol, Symbol}, NamedTuple{(:color, :visible, :inspectable), Tuple{Observable{Vector{ColorTypes.RGBA{Float64}}}, Observable{Bool}, Bool}}})
    @ MakieCore ~/.julia/packages/MakieCore/JjXvr/src/recipes.jl:38
 [12] initialize_block!(cb::Colorbar)
    @ Makie ~/.julia/packages/Makie/Ggejq/src/makielayout/blocks/colorbar.jl:197
 [13] _block(::Type{Colorbar}, ::Figure; bbox::Nothing, kwargs::Base.Pairs{Symbol, String, Tuple{Symbol}, NamedTuple{(:label,), Tuple{String}}})
    @ Makie ~/.julia/packages/Makie/Ggejq/src/makielayout/blocks.jl:408
 [14] _block(::Type{Colorbar}, ::GridPosition; kwargs::Base.Pairs{Symbol, String, Tuple{Symbol}, NamedTuple{(:label,), Tuple{String}}})
    @ Makie ~/.julia/packages/Makie/Ggejq/src/makielayout/blocks.jl:294
 [15] #_#1077
    @ ~/.julia/packages/Makie/Ggejq/src/makielayout/blocks.jl:279 [inlined]
 [16] top-level scope
    @ REPL[9]:1

Encountered in #2478 and blocking.

@t-bltg t-bltg changed the title cannot add a colorbar to a WGLMakie plot cannot add a colorbar to a WGLMakie 2d plot Dec 12, 2022
@SimonDanisch
Copy link
Member

How do you execute this? Looks like you're using Page without executing it in an environment that needs a page?

@t-bltg
Copy link
Collaborator Author

t-bltg commented Dec 12, 2022

I just followed the mwe at https://docs.makie.org/stable/documentation/backends/wglmakie/#output (I don't know anything about this backend ... should I try something else ?), and opened http://localhost:9284/browser-display in my local browser (I think it's unrelated, but I'm using a ssh tunnel (port forwarding) since I'm working on a remote machine).

If I run the example without the colorbar line, the plot is displayed correctly in my browser.

(@v1.8) pkg> st Makie WGLMakie JSServe
Status `~.julia/environments/v1.8/Project.toml`
  [824d6782] JSServe v1.2.9
  [ee78f7c6] Makie v0.19.0
  [276b4fcb] WGLMakie v0.8.0

@SimonDanisch
Copy link
Member

SimonDanisch commented Dec 12, 2022

Yeah I think I found the problem...Inserting new scenes is buggy right now - only inserting new plots works correctly right now...
So you need to create all axes / legends / blocks, before displaying it.
While I'm working on a fix, you could also use that as a workaround for #2478
edit: Stepper(fig) displays the figure ;) So any block that creates new scenes needs to be created before that!

@jkrumbiegel
Copy link
Collaborator

The colorbars also don't need to be inserted live into the test figure. It's enough to have them there at all.

@t-bltg
Copy link
Collaborator Author

t-bltg commented Dec 12, 2022

While I'm working on a fix, you could also use that as a workaround for #2478
edit: Stepper(fig) displays the figure ;) So any block that creates new scenes needs to be created before that!

Thanks Simon for the workaround and the explanation it seems to work locally. I'm pushing a fix in #2478.

The colorbars also don't need to be inserted live into the test figure. It's enough to have them there at all.

That could work, but IMO adding a colorbar with a label rotation to an existing plot should be tested for the label bounding boxes interaction (a standalone colorbar is a somewhat less common scenario).

@jkrumbiegel
Copy link
Collaborator

It's ok to add it, it's just not supposed to be added after displaying it for the first time I think.

@t-bltg
Copy link
Collaborator Author

t-bltg commented Dec 12, 2022

Yeah, probably adding a semicolon after julia> fig, ax, plot = scatter(0:1); wouldn't have triggered display and would have worked.

@SimonDanisch
Copy link
Member

Fixed by #2856

@SimonDanisch
Copy link
Member

Actually, it seems it was fixed before that and should already be tagged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants