Skip to content

Comments

merge themes recursive#5515

Open
henrik-wolf wants to merge 1 commit intoMakieOrg:masterfrom
henrik-wolf:merge-themes-recursive
Open

merge themes recursive#5515
henrik-wolf wants to merge 1 commit intoMakieOrg:masterfrom
henrik-wolf:merge-themes-recursive

Conversation

@henrik-wolf
Copy link
Contributor

Merging themes was shallow, which lead to strange behaviour where overwriting nested attributes would lead to these changes leaking out of with_theme. This PR changes this behaviour by ensuring that all nested, incoming attributes are correctly and recursively copied/merged as well.

My original problem looked like this:

using CairoMakie

function my_general_theme()
    return Theme(backgroundcolor = :lightblue)
end

function inset_theme(fontsize)
    pt = 4 / 3 * fontsize
    return Makie.Theme(
        Axis = (
            xlabelsize = pt,
            ylabelsize = pt,
            xticklabelsize = pt,
            yticklabelsize = pt,
            titlesize = pt,
            backgroundcolor = :orange,
        ),
    )
end

with_theme(my_general_theme(), fontsize = 30) do
    f = Figure()
    ax = Axis(f[1, 1], xlabel = "time", ylabel = "space")
    lines!(ax, rand(100))

    with_theme(inset_theme(4)) do
        ax = Axis(
            f[1, 1],
            width = Relative(0.4),
            height = Relative(0.4),
            halign = 0.9,
            valign = 0.9,
        )
        translate!(ax.blockscene, 0, 0, 150)
        scatter!(ax, rand(20))
        ax
    end
    f
end

Which now repeatedly produces the expected result.

Fixes #5497

While this works, the story seems to be slightly more complicated, as something like this

with_theme(fontsize = 30) do
    f = Figure()
    ax = Axis(f[1, 1], xlabel = "time", ylabel = "space")
    lines!(ax, rand(100))

    with_theme(fontsize = 4) do
        ax = Axis(f[1, 1], width = Relative(0.4), height = Relative(0.4))
        translate!(ax.blockscene, 0, 0, 150)
        scatter!(ax, rand(20))
    end
    f
end

Does not correctly (at least for my understanding of correctly) make the inner axis inherit the fontsize from the new theme, but instead seems to take it from the figure? I guess the answer lies in

# first check scene theme
# then current_default_theme
# then default value
d = quote
if haskey($sceneattrsym, $key)
to_value($sceneattrsym[$key]) # only use value of theme entry
elseif haskey($curthemesym, $key)
to_value($curthemesym[$key]) # only use value of theme entry
else
$default
end

I think that ordering is reasonable enough and I can not really think of a reasonably easy way of making the full inheritance chains work for nested themes.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • Added unit tests for new algorithms, conversion methods, etc.

@github-project-automation github-project-automation bot moved this to Work in progress in PR review Jan 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Work in progress

Development

Successfully merging this pull request may close these issues.

Attributes set in with_theme leak out

1 participant