Skip to content

Commit

Permalink
Merge branch 'master' into breaking-0.22
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonDanisch authored Dec 12, 2024
2 parents 2c00afb + d9e786f commit 5162a26
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 22 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@

## [Unreleased]

## [0.21.18] - 2024-12-12

- Allow for user defined recipes to be used in SpecApi [#4655](https://github.com/MakieOrg/Makie.jl/pull/4655).

## [0.21.17] - 2024-12-05

- Added `backend` and `update` kwargs to `show` [#4558](https://github.com/MakieOrg/Makie.jl/pull/4558)
Expand Down Expand Up @@ -702,7 +706,8 @@ All other changes are collected [in this PR](https://github.com/MakieOrg/Makie.j
- Fixed rendering of `heatmap`s with one or more reversed ranges in CairoMakie, as in `heatmap(1:10, 10:-1:1, rand(10, 10))` [#1100](https://github.com/MakieOrg/Makie.jl/pull/1100).
- Fixed volume slice recipe and added docs for it [#1123](https://github.com/MakieOrg/Makie.jl/pull/1123).

[Unreleased]: https://github.com/MakieOrg/Makie.jl/compare/v0.21.17...HEAD
[Unreleased]: https://github.com/MakieOrg/Makie.jl/compare/v0.21.18...HEAD
[0.21.18]: https://github.com/MakieOrg/Makie.jl/compare/v0.21.17...v0.21.18
[0.21.17]: https://github.com/MakieOrg/Makie.jl/compare/v0.21.16...v0.21.17
[0.21.16]: https://github.com/MakieOrg/Makie.jl/compare/v0.21.15...v0.21.16
[0.21.15]: https://github.com/MakieOrg/Makie.jl/compare/v0.21.14...v0.21.15
Expand Down
1 change: 0 additions & 1 deletion CairoMakie/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ uuid = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
author = ["Simon Danisch <[email protected]>"]
version = "0.13.0"


[deps]
CRC32c = "8bf52ea8-c179-5cab-976a-9e18b702a9bc"
Cairo = "159f3aea-2a34-519c-b102-8c37f9878175"
Expand Down
1 change: 0 additions & 1 deletion MakieCore/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ uuid = "20f20a25-4f0e-4fdf-b5d1-57303727442b"
authors = ["Simon Danisch"]
version = "0.9.0"


[deps]
ColorTypes = "3da002f7-5984-5a60-b8a6-cbb66c0b333f"
GeometryBasics = "5c1252a2-5f33-56bf-86c9-59e7332b4326"
Expand Down
9 changes: 9 additions & 0 deletions MakieCore/src/recipes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ function plotfunc(f::Function)
end
end

symbol_to_plot(x::Symbol) = symbol_to_plot(Val(x))
function symbol_to_plot(::Val{Sym}) where {Sym}
return nothing
end


function plotfunc!(x)
F = plotfunc(x)::Function
name = Symbol(nameof(F), :!)
Expand Down Expand Up @@ -188,6 +194,7 @@ macro recipe(theme_func, Tsym::Symbol, args::Symbol...)
Core.@__doc__ ($funcname)(args...; kw...) = _create_plot($funcname, Dict{Symbol, Any}(kw), args...)
($funcname!)(args...; kw...) = _create_plot!($funcname, Dict{Symbol, Any}(kw), args...)
$(MakieCore).default_theme(scene, ::Type{<:$PlotType}) = $(esc(theme_func))(scene)
$(MakieCore).symbol_to_plot(::Val{$(QuoteNode(Tsym))}) = $PlotType
export $PlotType, $funcname, $funcname!
end
if !isempty(args)
Expand Down Expand Up @@ -496,6 +503,8 @@ function create_recipe_expr(Tsym, args, attrblock)
$(MakieCore).documented_attributes(::Type{<:$(PlotType)}) = $attr_placeholder

$(MakieCore).plotsym(::Type{<:$(PlotType)}) = $(QuoteNode(Tsym))
$(MakieCore).symbol_to_plot(::Val{$(QuoteNode(Tsym))}) = $PlotType

function ($funcname)(args...; kw...)
kwdict = Dict{Symbol, Any}(kw)
_create_plot($funcname, kwdict, args...)
Expand Down
1 change: 0 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ uuid = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
authors = ["Simon Danisch", "Julius Krumbiegel"]
version = "0.22.0"


[deps]
Animations = "27a7e980-b3e6-11e9-2bcd-0b925532e340"
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
Expand Down
17 changes: 10 additions & 7 deletions src/makielayout/blocks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ function attribute_default_expressions end
function _attribute_docs end
function has_forwarded_layout end

symbol_to_block(symbol::Symbol) = symbol_to_block(Val(symbol))
symbol_to_block(::Val) = nothing

macro Block(_name::Union{Expr, Symbol}, body::Expr = Expr(:block))

body.head === :block || error("A Block needs to be defined within a `begin end` block")
Expand Down Expand Up @@ -78,18 +81,18 @@ macro Block(_name::Union{Expr, Symbol}, body::Expr = Expr(:block))
$structdef

export $name

function Makie.is_attribute(::Type{$(name)}, sym::Symbol)
$(Makie).symbol_to_block(::Val{$(QuoteNode(name))}) = $name
function $(Makie).is_attribute(::Type{$(name)}, sym::Symbol)
sym in ($((attrs !== nothing ? [QuoteNode(a.symbol) for a in attrs] : [])...),)
end

function Makie.default_attribute_values(::Type{$(name)}, scene::Union{Scene, Nothing})
function $(Makie).default_attribute_values(::Type{$(name)}, scene::Union{Scene, Nothing})
sceneattrs = scene === nothing ? Attributes() : theme(scene)
curdeftheme = Makie.fast_deepcopy($(Makie).CURRENT_DEFAULT_THEME)
curdeftheme = $(Makie).fast_deepcopy($(Makie).CURRENT_DEFAULT_THEME)
$(make_attr_dict_expr(attrs, :sceneattrs, :curdeftheme))
end

function Makie.attribute_default_expressions(::Type{$name})
function $(Makie).attribute_default_expressions(::Type{$name})
$(
if attrs === nothing
Dict{Symbol, String}()
Expand All @@ -99,7 +102,7 @@ macro Block(_name::Union{Expr, Symbol}, body::Expr = Expr(:block))
)
end

function Makie._attribute_docs(::Type{$(name)})
function $(Makie)._attribute_docs(::Type{$(name)})
Dict(
$(
(attrs !== nothing ?
Expand All @@ -109,7 +112,7 @@ macro Block(_name::Union{Expr, Symbol}, body::Expr = Expr(:block))
)
end

Makie.has_forwarded_layout(::Type{$name}) = $has_forwarded_layout
$(Makie).has_forwarded_layout(::Type{$name}) = $has_forwarded_layout

docstring_modified = make_block_docstring($name, user_docstring)
@doc docstring_modified $name
Expand Down
18 changes: 8 additions & 10 deletions src/specapi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ using GridLayoutBase: GridLayoutBase

import GridLayoutBase: GridPosition, Side, ContentSize, GapSize, AlignMode, Inner, GridLayout, GridSubposition

function get_recipe_function(name::Symbol)
if hasproperty(Makie, name)
return getfield(Makie, name)
else
return nothing
end
function symbol_to_specable(sym::Symbol)
block = symbol_to_block(sym)
isnothing(block) || return block
return MakieCore.symbol_to_plot(sym)
end

"""
Expand All @@ -27,7 +25,7 @@ struct PlotSpec
error("PlotSpec objects are supposed to be used without !, unless when using `S.$(type)(axis::P.Axis, args...; kwargs...)`")
end
if !isuppercase(type_str[1])
func = get_recipe_function(type)
func = hasproperty(Makie, type) ? getproperty(Makie, type) : nothing
func === nothing && error("PlotSpec need to be existing recipes or Makie plot objects. Found: $(type_str)")
plot_type = Plot{func}
type = plotsym(plot_type)
Expand Down Expand Up @@ -169,7 +167,7 @@ function to_plotspec(::Type{P}, p::PlotSpec; kwargs...) where {P}
return PlotSpec(plotsym(plottype(P, S)), p.args...; p.kwargs..., kwargs...)
end

plottype(p::PlotSpec) = getfield(Makie, p.type)
plottype(p::PlotSpec) = MakieCore.symbol_to_plot(p.type)

function Base.show(io::IO, ::MIME"text/plain", spec::PlotSpec)
args = join(map(x -> string("::", typeof(x)), spec.args), ", ")
Expand Down Expand Up @@ -403,7 +401,7 @@ function Base.getproperty(::_SpecApi, field::Symbol)
# Since precompilation will cache only MakieCore's state
# And once everything is compiled, and MakieCore is loaded into a package
# The names are loaded from cache and dont contain anything after MakieCore.
func = get_recipe_function(field)
func = symbol_to_specable(field)
if isnothing(func)
error("$(field) neither a recipe, Makie plotting object or a Block (like Axis, Legend, etc).")
elseif func isa Function
Expand Down Expand Up @@ -744,7 +742,7 @@ function extract_colorbar_kw(legend::BlockSpec, scene::Scene)
end

function to_layoutable(parent, position::GridLayoutPosition, spec::BlockSpec)
BType = getfield(Makie, spec.type)
BType = symbol_to_block(spec.type)
fig = get_top_parent(parent)

block = if spec.type === :Colorbar
Expand Down
11 changes: 10 additions & 1 deletion test/specapi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,18 @@ end
# This is too internal and fragile, so we won't actually test this
# @test leg.scene.plots[2].marker[] == :circle
# @test leg.scene.plots[3].marker[] == :rect

# Test that the legend has the correct labels.
# Again, I consider this too fragile to work with!
# @test contents(contents(leg.grid)[1])[2].text[] == "A"
# @test contents(contents(leg.grid)[2])[4].text[] == "B"
end

@recipe(TestRecipeForSpecApi) do scene
return Attributes()
end

@testset "External Recipe compatibility (#4295)" begin
@test_nowarn S.TestRecipeForSpecApi
@test_nowarn S.TestRecipeForSpecApi(1, 2, 3; a = 4, b = 5)
end

0 comments on commit 5162a26

Please sign in to comment.