MakieOrg / Makie.jl

Interactive data visualizations and plotting in Julia
https://docs.makie.org/stable
MIT License
2.41k stars 311 forks source link

Theme is not propagated into child scenes #2833

Open asinghvi17 opened 1 year ago

asinghvi17 commented 1 year ago

Scenes don't pass themes to children

Consider the following code:

sc1 = with_theme(Scene, theme_black())
lines!(sc1, rand(10), rand(10); space = :relative)
sc1

download-8

This produces a white line, as you'd expect.

However, if we plot to a child Scene,

sc2 = with_theme(Scene, theme_black())
sc2_c1 = Scene(sc2) # create a child Scene
lines!(sc2_c1, rand(10), rand(10)
sc2

download-10

is not visible. However, if we look at sc2_c1,

download-12

the line exists - but is black! Is this expected behaviour, that the child of a Scene will not inherit its theme? Do we want the toplevel Scene construct to be able to define the theme, or should we force users to set the same global theme for each scene?

This means that things like this don't work:

fig = with_theme(theme_black()) do; Figure(; palette = (; color = rand(RGBAf, 5))); end; ax = Axis(fig[1, 1], aspect = AxisAspect(96/71)); fig

julia> lines!(ax, rand(10))
Lines{Tuple{Vector{Point{2, Float32}}}}

julia> fig

Instead, you have to construct all axes within the same theme for the figure to do what you intend it to do. Somehow, the axes retain their themes, but don't pass them on to their own ax.scenes outside the with_theme block.

Old issue text Consider the following: ```julia using Makie, TernaryDiagrams fig, ax, plt = with_theme(theme_black()) do ternaryaxis(; axis = (; aspect = AxisAspect(96/71))) end ``` ![download-5](https://user-images.githubusercontent.com/32143268/229275218-d42c47ad-b739-4acb-82f8-0bf2e0a35820.png) This works fine. If I only construct the figure in `with_theme`, though, ```julia fig = with_theme(theme_black()) do; Figure(); end; ax = Axis(fig[1, 1], aspect = AxisAspect(96/71)); ta = ternaryaxis!(ax); fig ``` ![download-4](https://user-images.githubusercontent.com/32143268/229275184-e4e9ed07-9d5c-4c3f-9d31-80861a3a6f7c.png) When I set the background colors of `fig` and `ax.scene` to white, and then redisplay, ![download-6](https://user-images.githubusercontent.com/32143268/229275256-34611da8-1f68-4504-9636-5a1fb562f0a6.png) which clearly indicates that the axis's scene has a different default theme than the Figure's scene. This shouldn't be happening. These should have the same result, but don't. Might be because blocks are using `theme(parent_scene)`, which doesn't get the actual theme of the parent scene. Will add a more minimal example later.
ffreyer commented 2 months ago

I'm confused by this. Your example looks the same as

with_theme(theme_black()) do
    sc2 = Scene()
    sc2_c1 = Scene(sc2) # create a child Scene
    lines!(sc2_c1, rand(10), rand(10))
    sc2
end

which I assume should work, but doesn't produce a white line. Neither does just one scene. The theme has linecolor = :white in it... Is this more broken now?