Code Monkey home page Code Monkey logo

Comments (7)

jw3126 avatar jw3126 commented on May 22, 2024

What are you trying to do? Replace all these?

# (index, y)
@recipe f(ys::UA) = recipe!(plotattributes, ys)
@recipe f(ys::V{<:UV}) = recipe!(plotattributes, ys)
# (x, y)
@recipe f(xs::A, ys::UA) = recipe!(plotattributes, xs, ys)
@recipe f(xs::UA, ys::A) = recipe!(plotattributes, xs, ys)
@recipe f(xs::UA, ys::UA) = recipe!(plotattributes, xs, ys)
# (x, y) where x or y is a vector of vectors
@recipe f(xs::A, ys::V{<:UV}) = recipe!(plotattributes, xs, ys)
@recipe f(xs::UV, ys::V{<:UV}) = recipe!(plotattributes, xs, ys)
@recipe f(xs::V{<:UV}, ys::A) = recipe!(plotattributes, xs, ys)
@recipe f(xs::V{<:UV}, ys::UV) = recipe!(plotattributes, xs, ys)
@recipe f(xs::V{<:UV}, ys::V{<:UV}) = recipe!(plotattributes, xs, ys)
# (x, f(x))
@recipe f(fun::Function, xs::UA) = recipe!(plotattributes, xs, fun.(xs))
@recipe f(fun::Function, xs::V{<:UV}) = recipe!(plotattributes, xs, [fun.(x) for x in xs])
# (x, y, f(x,y))
@recipe f(xs::UV, ys::UV, fun::Function) = recipe!(plotattributes, xs, ys, fun.(xs',ys))

That would be cool. If so I guess your suggestion involves touching Plots.jl / the recipe system?

from unitfulrecipes.jl.

briochemc avatar briochemc commented on May 22, 2024

Yes! I am trying but failing so far... 😅 But maybe with some help we'll get to this 😄

from unitfulrecipes.jl.

briochemc avatar briochemc commented on May 22, 2024

For the record this is what I have replaced those lines with:

#traits
struct HasUnits end
struct HasNoUnits end
unitfultrait(::T) where {T<:Tuple} = any(t <: Quantity for t in eltype.(T.parameters)) ? HasUnits() : HasNoUnits()

# dispatch using traits
(RecipesBase.RecipesBase).apply_recipe(attr::AbstractDict{Symbol, Any}, arrs::Array...) = (RecipesBase.RecipesBase).apply_recipe(attr, unitfultrait(arrs), arrs...)

# Apply the recipe if has units
function (RecipesBase.RecipesBase).apply_recipe(attr::AbstractDict{Symbol, Any}, ::HasUnits, arrs::Array...)
    series_list = RecipesBase.RecipeData[]
    func_return = begin
        println("unitful traitrecipe")
        #recipe!(attr, arrs...) # <- This line is uncommented in UnitfulRecipes
        ([ustrip.(arr) for arr in arrs]...,)
    end
    if func_return != nothing
        push!(series_list, RecipesBase.RecipeData(attr, RecipesBase.wrap_tuple(func_return)))
    end
    @show series_list
    series_list
end
#don't apply it otherwise
function (RecipesBase.RecipesBase).apply_recipe(attr::AbstractDict{Symbol, Any}, ::HasNoUnits, arrs::Array...)
    series_list = RecipesBase.RecipeData[]
    func_return = begin
        print("should be called once only")
        arrs
    end
    push!(series_list, RecipesBase.RecipeData(attr, RecipesBase.wrap_tuple(arrs)))
    @show series_list
    series_list
end

but this fails and enters endless loops, so needs fixing :)

from unitfulrecipes.jl.

briochemc avatar briochemc commented on May 22, 2024

Also, Simon Christ mentioned this relevant PR: JuliaPlots/Plots.jl#2503

from unitfulrecipes.jl.

jw3126 avatar jw3126 commented on May 22, 2024

I guess #25 resolves this issue?

from unitfulrecipes.jl.

briochemc avatar briochemc commented on May 22, 2024

Well, I think indirectly it does... sort of :) In the sense that if the point here was to make the code cleaner then I think #25 achieves that

from unitfulrecipes.jl.

briochemc avatar briochemc commented on May 22, 2024

Either way, I don't think I'll work on this traits approach any time soon, so I'll close this 🙂 and we can always reopen in the future in case.

from unitfulrecipes.jl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.