Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrap tutorial doesn't work anymore #3901

Closed
Moelf opened this issue May 28, 2024 · 10 comments
Closed

Wrap tutorial doesn't work anymore #3901

Moelf opened this issue May 28, 2024 · 10 comments
Labels

Comments

@Moelf
Copy link
Contributor

Moelf commented May 28, 2024

in #3736 and #3816 we added https://docs.makie.org/v0.21/tutorials/wrap-existing-recipe

but it actually doesn't work anymore:

julia> using MakieCore, CairoMakie

julia> struct MyHist
           bincounts
           bincenters
       end

julia> function Makie.plot!(plot::Hist{<:Tuple{<:MyHist}})
           barplot!(plot, plot[1])
           plot
       end

julia> hist(h; color=:red, direction=:x)
ERROR: ArgumentError:     Conversion failed for Plot{Makie.barplot} (With conversion trait PointBased()) with args: Tuple{MyHist} .
    Plot{Makie.barplot} requires to convert to argument types Tuple{AbstractVector{<:Union{Point2, Point3}}}, which convert_arguments didn't succeed in.
    To fix this overload convert_arguments(P, args...) for Plot{Makie.barplot} or PointBased() and return an object of type Tuple{AbstractVector{<:Union{Point2, Point3}}}.`

@SimonDanisch @asinghvi17

@asinghvi17
Copy link
Member

asinghvi17 commented May 28, 2024

I don't think the specific example you showed should ever work - the error message is correct in this case, barplot doesn't have an overload defined for MyHist.

You would want either barplot!(plot, @lift($(plot[1]).bincenters), @lift($(plot[1]).bincounts)) which does work (though it doesn't pass attributes down), or to define a specific convert_arguments for barplot.

Plus, the examples are all rendered in the documentation ;) which means they do work there at least!

@Moelf
Copy link
Contributor Author

Moelf commented May 28, 2024

Good point 🤔. Works in the docs because we have the convert arguments.

In this case I want to add extra keyword arguments to errorbar(MyHist), they change how the errorbars are calculated. I think in this case I have to defer these into the convert arguments, but how? Can I just add extra arguments to convert_arguments?

@asinghvi17
Copy link
Member

asinghvi17 commented May 28, 2024

used_attributes(::Type{PlotType}, args...) = (:mykw1, :mykw2) should do it, you can then access those kwargs in convert_arguments! You will have to specify the argument types though.

@asinghvi17
Copy link
Member

See e.g. SciMLBase's Makie ext for an example.

@Moelf Moelf closed this as completed May 28, 2024
@Moelf
Copy link
Contributor Author

Moelf commented May 28, 2024

You mean I have to specify plot type?

Btw just as an FYI, this approach did work before 0.21, maybe by mistake?

@asinghvi17
Copy link
Member

Both plot type and argument types for dispatch purposes. So for example

Makie.used_attributes(::Type{<: Errorbars}, h::Hist1D) = (:error_function,)
Makie.convert_attributes(::Type{<: Errorbars}, h::Hist1D; error_function = nothing) = do_something(h, error_function)

As for this working before 0.21: did the plot turn out correct?! That would definitely be a mistake IMO :D

@Moelf
Copy link
Contributor Author

Moelf commented May 29, 2024

plot looks correct: Moelf/FHist.jl#118

@Moelf
Copy link
Contributor Author

Moelf commented May 29, 2024

Makie.convert_attributes(::Type{<: Errorbars}, h::Hist1D; error_function = nothing) = do_something(h, error_function)

you meant convert_arguments?

@asinghvi17
Copy link
Member

ah yes, my bad

@Moelf
Copy link
Contributor Author

Moelf commented May 29, 2024

worked like a charm: Moelf/FHist.jl#118 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants