Comments (7)
What are you trying to do? Replace all these?
UnitfulRecipes.jl/src/UnitfulRecipes.jl
Lines 158 to 179 in 895451d
That would be cool. If so I guess your suggestion involves touching Plots.jl / the recipe system?
from unitfulrecipes.jl.
Yes! I am trying but failing so far... 😅 But maybe with some help we'll get to this 😄
from unitfulrecipes.jl.
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.
Also, Simon Christ mentioned this relevant PR: JuliaPlots/Plots.jl#2503
from unitfulrecipes.jl.
I guess #25 resolves this issue?
from unitfulrecipes.jl.
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.
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)
- Compatibility when using two user recipes together HOT 8
- Recipe for parametric with units? HOT 14
- TagBot trigger issue HOT 16
- unitful yerr seems to break HOT 6
- Recipe request for logarithmic units HOT 6
- Vector{Any} doesn't plot HOT 4
- Shape() fails on conversion HOT 4
- `vline` and `hline` not supporting both `xunit` and `yunit` HOT 3
- Support Unitful xticks and yticks? HOT 1
- Units in colorbar clim
- No units on colorbar for 1-argument version of heatmap HOT 1
- axis labels for `plot!`
- Recipe request for Plots with ribbon keyword HOT 1
- Units from 3rd axis applied to 4th plot HOT 8
- Tuple vs Vector behavior HOT 1
- Is it neccessary that UnitfulStrings outlive the recipe? HOT 4
- The `aspect_ratio` controls the digit spacing, ignoring the units HOT 6
- New Recipes to support StatsPlots.jl HOT 5
- Crash on annotate HOT 1
- Error with `plot!(xticks)` HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from unitfulrecipes.jl.