Skip to content

Commit

Permalink
fix most issues
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonDanisch committed Jul 22, 2023
1 parent eb4a42d commit 8d87ca7
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 57 deletions.
7 changes: 7 additions & 0 deletions MakieCore/src/attributes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
69 changes: 29 additions & 40 deletions MakieCore/src/recipes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
"""
Expand Down Expand Up @@ -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
Expand All @@ -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`.
"""
Expand Down
2 changes: 1 addition & 1 deletion src/Makie.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions src/basic_recipes/axis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 11 additions & 1 deletion src/figureplotting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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("""
Expand All @@ -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]
Expand All @@ -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)

Expand Down
8 changes: 6 additions & 2 deletions src/interfaces.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
16 changes: 5 additions & 11 deletions src/makielayout/blocks/scene.jl
Original file line number Diff line number Diff line change
@@ -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())
Expand Down

0 comments on commit 8d87ca7

Please sign in to comment.