From 8d87ca7edc3474de1687e1c070362a732fd7405e Mon Sep 17 00:00:00 2001 From: SimonDanisch Date: Sat, 22 Jul 2023 11:30:09 +0200 Subject: [PATCH] fix most issues --- MakieCore/src/attributes.jl | 7 ++++ MakieCore/src/recipes.jl | 69 ++++++++++++++------------------- src/Makie.jl | 2 +- src/basic_recipes/axis.jl | 5 ++- src/figureplotting.jl | 12 +++++- src/interfaces.jl | 8 +++- src/makielayout/blocks/scene.jl | 16 +++----- 7 files changed, 62 insertions(+), 57 deletions(-) diff --git a/MakieCore/src/attributes.jl b/MakieCore/src/attributes.jl index 30f8d2cf5ad..a6163609a6f 100644 --- a/MakieCore/src/attributes.jl +++ b/MakieCore/src/attributes.jl @@ -77,6 +77,13 @@ function Base.getproperty(x::Union{Attributes, AbstractPlot}, key::Symbol) end end +function Base.setproperty!(x::Union{Attributes,AbstractPlot}, key::Symbol, value::NamedTuple) + x[key] = Attributes(value) +end +function Base.setindex!(x::Attributes, value::NamedTuple, key::Symbol) + return x[key] = Attributes(value) +end + function Base.setproperty!(x::Union{Attributes, AbstractPlot}, key::Symbol, value) if hasfield(typeof(x), key) setfield!(x, key, value) diff --git a/MakieCore/src/recipes.jl b/MakieCore/src/recipes.jl index a87d538e135..640bb0a872e 100644 --- a/MakieCore/src/recipes.jl +++ b/MakieCore/src/recipes.jl @@ -33,7 +33,6 @@ function create_plot(P::Type{<: Combined{F}}, args, kw) where F end function create_plot(P::Type{<:Any}, args, kw) - error("$args") if first(args) isa Attributes merge!(kw, attributes(popfirst!(args))) end @@ -47,41 +46,36 @@ end function create_figurelike end function create_figurelike! end function figurelike_return end +function figurelike_return! end + +function _create_plot(F, kw, args...) + P = Combined{F} + attributes = Dict{Symbol,Any}(kw) + figlike, plot_kw, plot_args = create_figurelike(P, attributes, args...) + plot = create_plot(P, Any[plot_args...], plot_kw) + plot!(figlike, plot) + return figurelike_return(figlike, plot) +end -""" - default_plot_signatures(funcname, funcname!, PlotType) -Creates all the different overloads for `funcname` that need to be supported for the plotting frontend! -Since we add all these signatures to different functions, we make it reusable with this function. -The `Core.@__doc__` macro transfers the docstring given to the Recipe into the functions. -""" -function default_plot_signatures(funcname, funcname!, PlotType) - quote - Core.@__doc__ function ($funcname)(args...; kw...) - attributes = Dict{Symbol,Any}(kw) - P = $(PlotType) - figlike, plot_kw, plot_args = create_figurelike(P, attributes, args...) - plot = create_plot(P, Any[plot_args...], plot_kw) - plot!(figlike, plot) - return figurelike_return(figlike, plot) - end - - Core.@__doc__ function ($funcname!)(args...; kw...) - attributes = Dict{Symbol,Any}(kw) - P = $(PlotType) - figlike, plot_kw, plot_args = create_figurelike!(P, attributes, args...) - plot = create_plot(P, Any[plot_args...], plot_kw) - plot!(figlike, plot) - return figurelike_return!(figlike, plot) - end - - function ($funcname!)(scene::SceneLike, args...; kw...) - plot = create_plot($(PlotType), Any[args...], Dict{Symbol,Any}(kw)) - plot!(scene, plot) - return plot - end - end +function _create_plot!(F, kw, args...) + P = Combined{F} + attributes = Dict{Symbol,Any}(kw) + figlike, plot_kw, plot_args = create_figurelike!(P, attributes, args...) + plot = create_plot(P, Any[plot_args...], plot_kw) + plot!(figlike, plot) + return figurelike_return!(figlike, plot) end +function _create_plot!(F, kw, scene::SceneLike, args...) + plot = create_plot(Combined{F}, Any[args...], Dict{Symbol,Any}(kw)) + plot!(scene, plot) + return plot +end + +plot(args...; kw...) = _create_plot(plot, kw, args...) +plot!(args...; kw...) = _create_plot!(plot, kw, args...) + + """ Each argument can be named for a certain plot type `P`. Falls back to `arg1`, `arg2`, etc. """ @@ -215,7 +209,8 @@ macro recipe(theme_func, Tsym::Symbol, args::Symbol...) $(funcname)() = not_implemented_for($funcname) const $(PlotType){$(esc(:ArgType))} = Combined{$funcname,$(esc(:ArgType))} $(MakieCore).plotsym(::Type{<:$(PlotType)}) = $(QuoteNode(Tsym)) - $(default_plot_signatures(funcname, funcname!, PlotType)) + Core.@__doc__ ($funcname)(args...; kw...) = _create_plot($funcname, kw, args...) + ($funcname!)(args...; kw...) = _create_plot!($funcname, kw, args...) $(MakieCore).default_theme(scene, ::Type{<:$PlotType}) = $(esc(theme_func))(scene) export $PlotType, $funcname, $funcname! end @@ -231,12 +226,6 @@ macro recipe(theme_func, Tsym::Symbol, args::Symbol...) expr end -# Register plot / plot! using the Any type as PlotType. -# This is done so that plot(args...) / plot!(args...) can by default go -# through a pipeline where the appropriate PlotType is determined -# from the input arguments themselves. -eval(default_plot_signatures(:plot, :plot!, :Any)) - """ Returns the Combined type that represents the signature of `args`. """ diff --git a/src/Makie.jl b/src/Makie.jl index 6630b54c0bc..a29d60d919e 100644 --- a/src/Makie.jl +++ b/src/Makie.jl @@ -79,7 +79,7 @@ using MakieCore: Pixel, px, Unit, Billboard using MakieCore: not_implemented_for import MakieCore: plot, plot!, theme, plotfunc, plottype, merge_attributes!, calculated_attributes!, get_attribute, plotsym, plotkey, attributes, used_attributes -import MakieCore: create_figurelike, create_figurelike!, figurelike_return +import MakieCore: create_figurelike, create_figurelike!, figurelike_return, figurelike_return! import MakieCore: arrows, heatmap, image, lines, linesegments, mesh, meshscatter, poly, scatter, surface, text, volume import MakieCore: arrows!, heatmap!, image!, lines!, linesegments!, mesh!, meshscatter!, poly!, scatter!, surface!, text!, volume! import MakieCore: convert_arguments, convert_attribute, default_theme, conversion_trait diff --git a/src/basic_recipes/axis.jl b/src/basic_recipes/axis.jl index f9744a8efb5..99134b5bf34 100644 --- a/src/basic_recipes/axis.jl +++ b/src/basic_recipes/axis.jl @@ -316,9 +316,10 @@ function draw_axis3d(textbuffer, linebuffer, scale, limits, ranges_labels, fonts end return end +plot!(plot::Axis3D) = nothing -function plot!(scene::SceneLike, ::Type{<: Axis3D}, attributes::Attributes, args...) - axis = Axis3D(scene, attributes, args) +function plot!(axis::Axis3D) + scene = parent_scene(axis) # Disable any non linear transform for the axis plot! axis.transformation.transform_func[] = identity textbuffer = TextBuffer(axis, Point3, transparency = true, markerspace = :data, diff --git a/src/figureplotting.jl b/src/figureplotting.jl index a0b8d21e5b1..1eb460eeecb 100644 --- a/src/figureplotting.jl +++ b/src/figureplotting.jl @@ -130,7 +130,6 @@ end function create_figurelike(PlotType, attributes::Dict, gp::GridPosition, args...) f = get_top_parent(gp) - layout = GridLayoutBase.get_layout_at!(gsp.parent; createmissing=true) c = contents(gp; exact=true) if !isempty(c) error(""" @@ -150,6 +149,14 @@ function create_figurelike!(PlotType, attributes::Dict, ax::Axis, args...) return ax, attributes, args end +function create_figurelike!(PlotType, attributes::Dict, ax::LScene, args...) + return ax, attributes, args +end + +function create_figurelike!(PlotType, attributes::Dict, ax::Axis3, args...) + return ax, attributes, args +end + function create_figurelike!(PlotType, attributes::Dict, gsp::GridSubposition, args...) layout = GridLayoutBase.get_layout_at!(gsp.parent; createmissing=false) gp = layout[gsp.rows, gsp.cols, gsp.side] @@ -164,7 +171,10 @@ end figurelike_return(fa::FigureAxis, plot) = FigureAxisPlot(fa.figure, fa.axis, plot) figurelike_return(ax::Axis, plot) = AxisPlot(ax, plot) figurelike_return(ax::LScene, plot) = AxisPlot(ax, plot) +figurelike_return(ax::Axis3, plot) = AxisPlot(ax, plot) figurelike_return!(ax::Axis, plot) = plot +figurelike_return!(ax::LScene, plot) = plot +figurelike_return!(ax::Axis3, plot) = plot plot!(fa::FigureAxis, plot) = plot!(fa.axis, plot) diff --git a/src/interfaces.jl b/src/interfaces.jl index 4a5c64cd99a..7907cc4124e 100644 --- a/src/interfaces.jl +++ b/src/interfaces.jl @@ -208,7 +208,7 @@ const PlotFunc = Union{Type{Any},Type{<:AbstractPlot}} function plot!(plot::Combined{F}) where {F} if !(F in atomic_functions) - error("No recipe!") + error("No recipe for $(F)") end end @@ -222,7 +222,11 @@ function apply_theme!(scene::Scene, plot::Combined{F}) where {F} theme = default_theme(scene, Combined{F, Any}) raw_attr = getfield(plot.attributes, :attributes) for (k, v) in plot.kw - raw_attr[k] = convert(Observable{Any}, v) + if v isa NamedTuple + raw_attr[k] = Attributes(v) + else + raw_attr[k] = convert(Observable{Any}, v) + end end return merge!(plot.attributes, theme) end diff --git a/src/makielayout/blocks/scene.jl b/src/makielayout/blocks/scene.jl index 8ecbad040c6..4bcff85ecc6 100644 --- a/src/makielayout/blocks/scene.jl +++ b/src/makielayout/blocks/scene.jl @@ -1,19 +1,13 @@ -function Makie.plot!( - lscene::LScene, P::Makie.PlotFunc, - attributes::Makie.Attributes, args...; - kw_attributes...) - - plot = Makie.plot!(lscene.scene, P, attributes, args...; kw_attributes...) +function Makie.plot!(lscene::LScene, plot::AbstractPlot) + Makie.plot!(lscene.scene, plot) notify(lscene.scene.theme.limits) center!(lscene.scene) - plot + return plot end -function Makie.plot!(P::Makie.PlotFunc, ls::LScene, args...; kw_attributes...) +function Makie.plot!(P::Makie.PlotFunc, ax::LScene, args...; kw_attributes...) attributes = Makie.Attributes(kw_attributes) - _disallow_keyword(:axis, attributes) - _disallow_keyword(:figure, attributes) - Makie.plot!(ls, P, attributes, args...) + return Makie.plot!(ax, P, attributes, args...) end function initialize_block!(ls::LScene; scenekw = NamedTuple())